Skip to content

Commit 81babf5

Browse files
committed
Merge pull request #53 from arrayfire/v3.2
V3.2.20151214
2 parents f9d6cb1 + 36fd392 commit 81babf5

File tree

7 files changed

+173
-35
lines changed

7 files changed

+173
-35
lines changed

CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
### v3.2.20151214
2+
- Bug fixes:
3+
- `get_version()` now returns ints instead of `c_int`
4+
- Fixed bug in `tests/simple/device.py`
5+
6+
- The module now looks at additional paths when loading ArrayFire libraries.
7+
- Link to the wiki is provided when `ctypes.cdll.LoadLibrary` fails.
8+
9+
- New function:
10+
- `info_str()` returns information similar to `info()` as a string.
11+
12+
- Updated README.md with latest instructions
13+
114
### v3.2.20151211
215
- Feature parity with ArrayFire 3.2 libs
316
- New computer vision functions: `sift`, `gloh`, `homography`

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pip install arrayfire
102102
**Install the development version:**
103103

104104
```
105-
pip install git+git://github.com/arrayfire/arrayfire.git@master
105+
pip install git+git://github.com/arrayfire/arrayfire.git@devel
106106
```
107107

108108
**Installing offline**
@@ -112,6 +112,8 @@ cd path/to/arrayfire-python
112112
python setup.py install
113113
```
114114

115+
**Post Installation**
116+
115117
Please follow [these instructions](https://github.com/arrayfire/arrayfire-python/wiki) to ensure the arrayfire-python can find the arrayfire libraries.
116118

117119
## Acknowledgements

arrayfire/device.py

+50-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"""
1212

1313
from .library import *
14-
from .util import (safe_call, to_str)
14+
from .util import (safe_call, to_str, get_version)
1515

1616
def init():
1717
"""
@@ -82,6 +82,55 @@ def set_device(num):
8282
"""
8383
safe_call(backend.get().af_set_device(num))
8484

85+
def info_str(verbose = False):
86+
"""
87+
Returns information about the following as a string:
88+
- ArrayFire version number.
89+
- The number of devices available.
90+
- The names of the devices.
91+
- The current device being used.
92+
"""
93+
import platform
94+
res_str = 'ArrayFire'
95+
96+
major, minor, patch = get_version()
97+
dev_info = device_info()
98+
backend_str = dev_info['backend']
99+
100+
res_str += ' v' + str(major) + '.' + str(minor) + '.' + str(patch)
101+
res_str += ' (' + backend_str + ' ' + platform.architecture()[0] + ')\n'
102+
103+
num_devices = get_device_count()
104+
curr_device_id = get_device()
105+
106+
for n in range(num_devices):
107+
# To suppress warnings on CPU
108+
if (n != curr_device_id):
109+
set_device(n)
110+
111+
if (n == curr_device_id):
112+
res_str += '[%d] ' % n
113+
else:
114+
res_str += '-%d- ' % n
115+
116+
dev_info = device_info()
117+
118+
if (backend_str.lower() == 'opencl'):
119+
res_str += dev_info['toolkit']
120+
121+
res_str += ': ' + dev_info['device']
122+
123+
if (backend_str.lower() != 'cpu'):
124+
res_str += ' (Compute ' + dev_info['compute'] + ')'
125+
126+
res_str += '\n'
127+
128+
# To suppress warnings on CPU
129+
if (curr_device_id != get_device()):
130+
set_device(curr_device_id)
131+
132+
return res_str
133+
85134
def is_dbl_supported(device=None):
86135
"""
87136
Check if double precision is supported on specified device.

arrayfire/library.py

+102-28
Original file line numberDiff line numberDiff line change
@@ -315,31 +315,85 @@ class BACKEND(_Enum):
315315
CUDA = _Enum_Type(2)
316316
OPENCL = _Enum_Type(4)
317317

318-
class _clibrary(object):
318+
def _setup():
319+
import platform
320+
import os
321+
322+
platform_name = platform.system()
323+
324+
try:
325+
AF_SEARCH_PATH = os.environ['AF_PATH']
326+
except:
327+
AF_SEARCH_PATH = None
328+
pass
329+
330+
try:
331+
CUDA_PATH = os.environ['CUDA_PATH']
332+
except:
333+
CUDA_PATH= None
334+
pass
335+
336+
CUDA_EXISTS = False
337+
338+
assert(len(platform_name) >= 3)
339+
if platform_name == 'Windows' or platform_name[:3] == 'CYG':
340+
341+
## Windows specific setup
342+
pre = ''
343+
post = '.dll'
344+
if platform_name == "Windows":
345+
'''
346+
Supressing crashes caused by missing dlls
347+
http://stackoverflow.com/questions/8347266/missing-dll-print-message-instead-of-launching-a-popup
348+
https://msdn.microsoft.com/en-us/library/windows/desktop/ms680621.aspx
349+
'''
350+
ct.windll.kernel32.SetErrorMode(0x0001 | 0x0002)
351+
352+
if AF_SEARCH_PATH is None:
353+
AF_SEARCH_PATH="C:/Program Files/ArrayFire/v3/"
354+
355+
if CUDA_PATH is not None:
356+
CUDA_EXISTS = os.path.isdir(CUDA_PATH + '/bin') and os.path.isdir(CUDA_PATH + '/nvvm/bin/')
357+
358+
elif platform_name == 'Darwin':
359+
360+
## OSX specific setup
361+
pre = 'lib'
362+
post = '.dylib'
363+
364+
if AF_SEARCH_PATH is None:
365+
AF_SEARCH_PATH='/usr/local/'
366+
367+
if CUDA_PATH is None:
368+
CUDA_PATH='/usr/local/cuda/'
369+
370+
CUDA_EXISTS = os.path.isdir(CUDA_PATH + '/lib') and os.path.isdir(CUDA_PATH + '/nvvm/lib')
319371

320-
def __libname(self, name):
321-
platform_name = platform.system()
322-
assert(len(platform_name) >= 3)
323-
324-
libname = 'libaf' + name
325-
if platform_name == 'Linux':
326-
libname += '.so'
327-
elif platform_name == 'Darwin':
328-
libname += '.dylib'
329-
elif platform_name == "Windows" or platform_name[:3] == "CYG":
330-
libname += '.dll'
331-
libname = libname[3:] # remove 'lib'
332-
if platform_name == "Windows":
333-
'''
334-
Supressing crashes caused by missing dlls
335-
http://stackoverflow.com/questions/8347266/missing-dll-print-message-instead-of-launching-a-popup
336-
https://msdn.microsoft.com/en-us/library/windows/desktop/ms680621.aspx
337-
'''
338-
ct.windll.kernel32.SetErrorMode(0x0001 | 0x0002);
372+
elif platform_name == 'Linux':
373+
pre = 'lib'
374+
post = '.so'
375+
376+
if AF_SEARCH_PATH is None:
377+
AF_SEARCH_PATH='/opt/arrayfire-3/'
378+
379+
if CUDA_PATH is None:
380+
CUDA_PATH='/usr/local/cuda/'
381+
382+
if platform.architecture()[0][:2] == 64:
383+
CUDA_EXISTS = os.path.isdir(CUDA_PATH + '/lib64') and os.path.isdir(CUDA_PATH + '/nvvm/lib64')
339384
else:
340-
raise OSError(platform_name + ' not supported')
385+
CUDA_EXISTS = os.path.isdir(CUDA_PATH + '/lib') and os.path.isdir(CUDA_PATH + '/nvvm/lib')
386+
else:
387+
raise OSError(platform_name + ' not supported')
341388

342-
return libname
389+
return pre, post, AF_SEARCH_PATH, CUDA_EXISTS
390+
391+
class _clibrary(object):
392+
393+
def __libname(self, name, head='af'):
394+
libname = self.__pre + head + name + self.__post
395+
libname_full = self.AF_SEARCH_PATH + '/lib/' + libname
396+
return (libname, libname_full)
343397

344398
def set_unsafe(self, name):
345399
lib = self.__clibs[name]
@@ -348,6 +402,15 @@ def set_unsafe(self, name):
348402
self.__name = name
349403

350404
def __init__(self):
405+
406+
more_info_str = "Please look at https://github.com/arrayfire/arrayfire-python/wiki for more information."
407+
408+
pre, post, AF_SEARCH_PATH, CUDA_EXISTS = _setup()
409+
410+
self.__pre = pre
411+
self.__post = post
412+
self.AF_SEARCH_PATH = AF_SEARCH_PATH
413+
351414
self.__name = None
352415

353416
self.__clibs = {'cuda' : None,
@@ -365,18 +428,29 @@ def __init__(self):
365428
'cuda' : 2,
366429
'opencl' : 4}
367430

368-
# Iterate in reverse order of preference
369-
for name in ('cpu', 'opencl', 'cuda', ''):
431+
# Try to pre-load forge library if it exists
432+
libnames = self.__libname('forge', '')
433+
for libname in libnames:
370434
try:
371-
libname = self.__libname(name)
372435
ct.cdll.LoadLibrary(libname)
373-
self.__clibs[name] = ct.CDLL(libname)
374-
self.__name = name
375436
except:
376437
pass
377438

439+
# Iterate in reverse order of preference
440+
for name in ('cpu', 'opencl', 'cuda', ''):
441+
libnames = self.__libname(name)
442+
for libname in libnames:
443+
try:
444+
ct.cdll.LoadLibrary(libname)
445+
self.__clibs[name] = ct.CDLL(libname)
446+
self.__name = name
447+
break;
448+
except:
449+
pass
450+
378451
if (self.__name is None):
379-
raise RuntimeError("Could not load any ArrayFire libraries")
452+
raise RuntimeError("Could not load any ArrayFire libraries.\n" +
453+
more_info_str)
380454

381455
def get_id(self, name):
382456
return self.__backend_name_map[name]

arrayfire/util.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def get_version():
7979
minor=ct.c_int(0)
8080
patch=ct.c_int(0)
8181
safe_call(backend.get().af_get_version(ct.pointer(major), ct.pointer(minor), ct.pointer(patch)))
82-
return major,minor,patch
82+
return major.value,minor.value,patch.value
8383

8484
to_dtype = {'f' : Dtype.f32,
8585
'd' : Dtype.f64,

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
author="Pavan Yalamanchili",
2020
author_email="[email protected]",
2121
name="arrayfire",
22-
version="3.2.20151211",
22+
version="3.2.20151214",
2323
description="Python bindings for ArrayFire",
2424
license="BSD",
2525
url="http://arrayfire.com",

tests/simple/device.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ def simple_device(verbose=False):
1919
print_func(af.is_dbl_supported())
2020
af.sync()
2121

22-
dev = af.get_device()
23-
print_func(dev)
22+
curr_dev = af.get_device()
23+
print_func(curr_dev)
2424
for k in range(af.get_device_count()):
2525
af.set_device(k)
2626
dev = af.get_device()
@@ -38,7 +38,7 @@ def simple_device(verbose=False):
3838
assert(mem_info['alloc']['buffers'] == 1 + mem_info_old['alloc']['buffers'])
3939
assert(mem_info[ 'lock']['buffers'] == 1 + mem_info_old[ 'lock']['buffers'])
4040

41-
af.set_device(dev)
41+
af.set_device(curr_dev)
4242

4343
a = af.randu(10,10)
4444
display_func(a)

0 commit comments

Comments
 (0)