Skip to content

Commit c169b17

Browse files
committed
abstract out arrayfire and forge major versions from library setup
This fixes #131, where arrayfire-python attempted to load the non-existant libforge.so.3
1 parent 32196a0 commit c169b17

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

arrayfire/library.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
c_char_ptr_t = ct.c_char_p
3131
c_size_t = ct.c_size_t
3232

33+
34+
AF_VER_MAJOR = '3'
35+
FORGE_VER_MAJOR = '0'
36+
3337
# Work around for unexpected architectures
3438
if 'c_dim_t_forced' in globals():
3539
global c_dim_t_forced
@@ -409,6 +413,8 @@ class STORAGE(_Enum):
409413
CSC = _Enum_Type(2)
410414
COO = _Enum_Type(3)
411415

416+
_VER_MAJOR_PLACEHOLDER = "__VER_MAJOR__"
417+
412418
def _setup():
413419
import platform
414420
import os
@@ -446,7 +452,7 @@ def _setup():
446452
ct.windll.kernel32.SetErrorMode(0x0001 | 0x0002)
447453

448454
if AF_SEARCH_PATH is None:
449-
AF_SEARCH_PATH="C:/Program Files/ArrayFire/v3/"
455+
AF_SEARCH_PATH="C:/Program Files/ArrayFire/v" + AF_VER_MAJOR +"/"
450456

451457
if CUDA_PATH is not None:
452458
CUDA_FOUND = os.path.isdir(CUDA_PATH + '/bin') and os.path.isdir(CUDA_PATH + '/nvvm/bin/')
@@ -455,7 +461,7 @@ def _setup():
455461

456462
## OSX specific setup
457463
pre = 'lib'
458-
post = '.3.dylib'
464+
post = '.' + _VER_MAJOR_PLACEHOLDER + '.dylib'
459465

460466
if AF_SEARCH_PATH is None:
461467
AF_SEARCH_PATH='/usr/local/'
@@ -467,10 +473,10 @@ def _setup():
467473

468474
elif platform_name == 'Linux':
469475
pre = 'lib'
470-
post = '.so.3'
476+
post = '.so.' + _VER_MAJOR_PLACEHOLDER
471477

472478
if AF_SEARCH_PATH is None:
473-
AF_SEARCH_PATH='/opt/arrayfire-3/'
479+
AF_SEARCH_PATH='/opt/arrayfire-' + AF_VER_MAJOR + '/'
474480

475481
if CUDA_PATH is None:
476482
CUDA_PATH='/usr/local/cuda/'
@@ -489,8 +495,9 @@ def _setup():
489495

490496
class _clibrary(object):
491497

492-
def __libname(self, name, head='af'):
493-
libname = self.__pre + head + name + self.__post
498+
def __libname(self, name, head='af', ver_major=AF_VER_MAJOR):
499+
post = self.__post.replace(_VER_MAJOR_PLACEHOLDER, ver_major)
500+
libname = self.__pre + head + name + post
494501
libname_full = self.AF_PATH + '/lib/' + libname
495502
return (libname, libname_full)
496503

@@ -530,7 +537,7 @@ def __init__(self):
530537
'opencl' : 4}
531538

532539
# Try to pre-load forge library if it exists
533-
libnames = self.__libname('forge', '')
540+
libnames = self.__libname('forge', head='', ver_major=FORGE_VER_MAJOR)
534541
for libname in libnames:
535542
try:
536543
ct.cdll.LoadLibrary(libname)

0 commit comments

Comments
 (0)