Skip to content

Commit

Permalink
setup.py compiling _libsdm.so and installing sucessfully in OSX
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcelo Salhab Brogliato committed Feb 10, 2016
1 parent 3a84472 commit d0ce42f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 7 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
recursive-include src *.c *.h *.cl
21 changes: 17 additions & 4 deletions sdm.py → sdm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@
from ctypes import cdll, cast, sizeof
from ctypes import Structure, POINTER, pointer, create_string_buffer
from ctypes import c_uint, c_uint64, c_char_p, c_int, c_void_p
import os

bitstring_t = c_uint64
counter_t = c_int

libsdm = cdll.LoadLibrary('src/libsdm.so')
basedir = os.path.dirname(__file__)
libsdm = cdll.LoadLibrary(os.path.join(basedir, '_libsdm.so'))
libsdm.bs_alloc.restype = POINTER(bitstring_t)
libsdm.bs_init_bitcount_table()

opencl_source_code = os.path.join(basedir, 'scanner_opencl.cl')
if not os.path.exists(opencl_source_code):
print "Ops!", opencl_source_code

class AddressSpace(Structure):
_fields_ = [
('bits', c_uint),
Expand Down Expand Up @@ -37,8 +43,15 @@ def print_summary(self):

def scan_linear(self, bs, radius):
buf = create_string_buffer(self.bits)
libsdm.as_scan_linear(pointer(self), bs, c_uint(radius), buf)
return buf
return libsdm.as_scan_linear(pointer(self), bs.bs_data, c_uint(radius), buf)

def scan_threads(self, bs, radius, thread_count):
buf = create_string_buffer(self.bits)
return libsdm.as_scan_threads(pointer(self), bs.bs_data, c_uint(radius), buf, c_uint(thread_count))

#def scan_opencl(self, bs, radius):
# buf = create_string_buffer(self.bits)
# return libsdm.as_scan_threads(pointer(self), bs.bs_data, c_uint(radius), buf, c_uint(thread_count))


class Counter(Structure):
Expand Down Expand Up @@ -171,7 +184,7 @@ def __init__(self, address_space, counter, radius, scanner_type, thread_count=8)
elif scanner_type == SDM_SCANNER_THREAD:
libsdm.sdm_init_thread(pointer(self), pointer(address_space), pointer(counter), thread_count)
elif scanner_type == SDM_SCANNER_OPENCL:
libsdm.sdm_init_opencl(pointer(self), pointer(address_space), pointer(counter), c_char_p("src/scanner_opencl.cl"))
libsdm.sdm_init_opencl(pointer(self), pointer(address_space), pointer(counter), c_char_p(opencl_source_code))

self.address_space = address_space
self.counter = counter
Expand Down
1 change: 1 addition & 0 deletions sdm/scanner_opencl.cl
38 changes: 35 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,44 @@
from distutils.core import setup
from distutils.core import setup, Extension

# Classifiers: https://pypi.python.org/pypi?%3Aaction=list_classifiers

macros = [
('OS_OSX', None),
('SDM_USE_BITCOUNT_TABLE', None),
('SDM_ENABLE_OPENCL', None),
]
extra_compile_args = None
extra_link_args=['-framework', 'OpenCL']
libraries = None

libsdm_ext = Extension('sdm/_libsdm', [
'src/bitstring.c', 'src/address_space.c', 'src/counter.c',
'src/scanner_thread.c', 'src/scanner_opencl.c',
'src/operations.c', 'src/lib/base64.c',
], libraries=libraries, define_macros=macros, extra_compile_args=extra_compile_args, extra_link_args=extra_link_args)

setup(name='sdm',
version='0.0.1',
license='GPL',
version='1.0.0',
license='GPLv2',
author='Marcelo Salhab Brogliato',
author_email='[email protected]',
description='Sparse Distributed Memory Framework',
long_description='',
ext_modules=[libsdm_ext],
packages=['sdm'],
package_data={'sdm': ['scanner_opencl.cl']},
url='https://github.com/msbrogli/sdm-framework',
classifiers=[
'Development Status :: 4 - Beta',
'Framework :: Sparse Distributed Memory',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: GNU General Public License v2 (GPLv2)',
'Natural Language :: English',
'Topic :: Scientific/Engineering',
'Programming Language :: C',
'Programming Language :: Python'
'Operating System :: MacOS :: MacOS X',
'Operating System :: POSIX',
]
)

0 comments on commit d0ce42f

Please sign in to comment.