Skip to content

V3.2.20151214 #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Dec 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
### v3.2.20151214
- Bug fixes:
- `get_version()` now returns ints instead of `c_int`
- Fixed bug in `tests/simple/device.py`

- The module now looks at additional paths when loading ArrayFire libraries.
- Link to the wiki is provided when `ctypes.cdll.LoadLibrary` fails.

- New function:
- `info_str()` returns information similar to `info()` as a string.

- Updated README.md with latest instructions

### v3.2.20151211
- Feature parity with ArrayFire 3.2 libs
- New computer vision functions: `sift`, `gloh`, `homography`
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pip install arrayfire
**Install the development version:**

```
pip install git+git://github.com/arrayfire/arrayfire.git@master
pip install git+git://github.com/arrayfire/arrayfire.git@devel
```

**Installing offline**
Expand All @@ -112,6 +112,8 @@ cd path/to/arrayfire-python
python setup.py install
```

**Post Installation**

Please follow [these instructions](https://github.com/arrayfire/arrayfire-python/wiki) to ensure the arrayfire-python can find the arrayfire libraries.

## Acknowledgements
Expand Down
51 changes: 50 additions & 1 deletion arrayfire/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"""

from .library import *
from .util import (safe_call, to_str)
from .util import (safe_call, to_str, get_version)

def init():
"""
Expand Down Expand Up @@ -82,6 +82,55 @@ def set_device(num):
"""
safe_call(backend.get().af_set_device(num))

def info_str(verbose = False):
"""
Returns information about the following as a string:
- ArrayFire version number.
- The number of devices available.
- The names of the devices.
- The current device being used.
"""
import platform
res_str = 'ArrayFire'

major, minor, patch = get_version()
dev_info = device_info()
backend_str = dev_info['backend']

res_str += ' v' + str(major) + '.' + str(minor) + '.' + str(patch)
res_str += ' (' + backend_str + ' ' + platform.architecture()[0] + ')\n'

num_devices = get_device_count()
curr_device_id = get_device()

for n in range(num_devices):
# To suppress warnings on CPU
if (n != curr_device_id):
set_device(n)

if (n == curr_device_id):
res_str += '[%d] ' % n
else:
res_str += '-%d- ' % n

dev_info = device_info()

if (backend_str.lower() == 'opencl'):
res_str += dev_info['toolkit']

res_str += ': ' + dev_info['device']

if (backend_str.lower() != 'cpu'):
res_str += ' (Compute ' + dev_info['compute'] + ')'

res_str += '\n'

# To suppress warnings on CPU
if (curr_device_id != get_device()):
set_device(curr_device_id)

return res_str

def is_dbl_supported(device=None):
"""
Check if double precision is supported on specified device.
Expand Down
130 changes: 102 additions & 28 deletions arrayfire/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,31 +315,85 @@ class BACKEND(_Enum):
CUDA = _Enum_Type(2)
OPENCL = _Enum_Type(4)

class _clibrary(object):
def _setup():
import platform
import os

platform_name = platform.system()

try:
AF_SEARCH_PATH = os.environ['AF_PATH']
except:
AF_SEARCH_PATH = None
pass

try:
CUDA_PATH = os.environ['CUDA_PATH']
except:
CUDA_PATH= None
pass

CUDA_EXISTS = False

assert(len(platform_name) >= 3)
if platform_name == 'Windows' or platform_name[:3] == 'CYG':

## Windows specific setup
pre = ''
post = '.dll'
if platform_name == "Windows":
'''
Supressing crashes caused by missing dlls
http://stackoverflow.com/questions/8347266/missing-dll-print-message-instead-of-launching-a-popup
https://msdn.microsoft.com/en-us/library/windows/desktop/ms680621.aspx
'''
ct.windll.kernel32.SetErrorMode(0x0001 | 0x0002)

if AF_SEARCH_PATH is None:
AF_SEARCH_PATH="C:/Program Files/ArrayFire/v3/"

if CUDA_PATH is not None:
CUDA_EXISTS = os.path.isdir(CUDA_PATH + '/bin') and os.path.isdir(CUDA_PATH + '/nvvm/bin/')

elif platform_name == 'Darwin':

## OSX specific setup
pre = 'lib'
post = '.dylib'

if AF_SEARCH_PATH is None:
AF_SEARCH_PATH='/usr/local/'

if CUDA_PATH is None:
CUDA_PATH='/usr/local/cuda/'

CUDA_EXISTS = os.path.isdir(CUDA_PATH + '/lib') and os.path.isdir(CUDA_PATH + '/nvvm/lib')

def __libname(self, name):
platform_name = platform.system()
assert(len(platform_name) >= 3)

libname = 'libaf' + name
if platform_name == 'Linux':
libname += '.so'
elif platform_name == 'Darwin':
libname += '.dylib'
elif platform_name == "Windows" or platform_name[:3] == "CYG":
libname += '.dll'
libname = libname[3:] # remove 'lib'
if platform_name == "Windows":
'''
Supressing crashes caused by missing dlls
http://stackoverflow.com/questions/8347266/missing-dll-print-message-instead-of-launching-a-popup
https://msdn.microsoft.com/en-us/library/windows/desktop/ms680621.aspx
'''
ct.windll.kernel32.SetErrorMode(0x0001 | 0x0002);
elif platform_name == 'Linux':
pre = 'lib'
post = '.so'

if AF_SEARCH_PATH is None:
AF_SEARCH_PATH='/opt/arrayfire-3/'

if CUDA_PATH is None:
CUDA_PATH='/usr/local/cuda/'

if platform.architecture()[0][:2] == 64:
CUDA_EXISTS = os.path.isdir(CUDA_PATH + '/lib64') and os.path.isdir(CUDA_PATH + '/nvvm/lib64')
else:
raise OSError(platform_name + ' not supported')
CUDA_EXISTS = os.path.isdir(CUDA_PATH + '/lib') and os.path.isdir(CUDA_PATH + '/nvvm/lib')
else:
raise OSError(platform_name + ' not supported')

return libname
return pre, post, AF_SEARCH_PATH, CUDA_EXISTS

class _clibrary(object):

def __libname(self, name, head='af'):
libname = self.__pre + head + name + self.__post
libname_full = self.AF_SEARCH_PATH + '/lib/' + libname
return (libname, libname_full)

def set_unsafe(self, name):
lib = self.__clibs[name]
Expand All @@ -348,6 +402,15 @@ def set_unsafe(self, name):
self.__name = name

def __init__(self):

more_info_str = "Please look at https://github.com/arrayfire/arrayfire-python/wiki for more information."

pre, post, AF_SEARCH_PATH, CUDA_EXISTS = _setup()

self.__pre = pre
self.__post = post
self.AF_SEARCH_PATH = AF_SEARCH_PATH

self.__name = None

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

# Iterate in reverse order of preference
for name in ('cpu', 'opencl', 'cuda', ''):
# Try to pre-load forge library if it exists
libnames = self.__libname('forge', '')
for libname in libnames:
try:
libname = self.__libname(name)
ct.cdll.LoadLibrary(libname)
self.__clibs[name] = ct.CDLL(libname)
self.__name = name
except:
pass

# Iterate in reverse order of preference
for name in ('cpu', 'opencl', 'cuda', ''):
libnames = self.__libname(name)
for libname in libnames:
try:
ct.cdll.LoadLibrary(libname)
self.__clibs[name] = ct.CDLL(libname)
self.__name = name
break;
except:
pass

if (self.__name is None):
raise RuntimeError("Could not load any ArrayFire libraries")
raise RuntimeError("Could not load any ArrayFire libraries.\n" +
more_info_str)

def get_id(self, name):
return self.__backend_name_map[name]
Expand Down
2 changes: 1 addition & 1 deletion arrayfire/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def get_version():
minor=ct.c_int(0)
patch=ct.c_int(0)
safe_call(backend.get().af_get_version(ct.pointer(major), ct.pointer(minor), ct.pointer(patch)))
return major,minor,patch
return major.value,minor.value,patch.value

to_dtype = {'f' : Dtype.f32,
'd' : Dtype.f64,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
author="Pavan Yalamanchili",
author_email="[email protected]",
name="arrayfire",
version="3.2.20151211",
version="3.2.20151214",
description="Python bindings for ArrayFire",
license="BSD",
url="http://arrayfire.com",
Expand Down
6 changes: 3 additions & 3 deletions tests/simple/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def simple_device(verbose=False):
print_func(af.is_dbl_supported())
af.sync()

dev = af.get_device()
print_func(dev)
curr_dev = af.get_device()
print_func(curr_dev)
for k in range(af.get_device_count()):
af.set_device(k)
dev = af.get_device()
Expand All @@ -38,7 +38,7 @@ def simple_device(verbose=False):
assert(mem_info['alloc']['buffers'] == 1 + mem_info_old['alloc']['buffers'])
assert(mem_info[ 'lock']['buffers'] == 1 + mem_info_old[ 'lock']['buffers'])

af.set_device(dev)
af.set_device(curr_dev)

a = af.randu(10,10)
display_func(a)
Expand Down