[python-arrayfire] 235/250: FEAT: Adding functions to interact with other opencl libraries

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Mar 28 22:59:52 UTC 2016


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch debian/master
in repository python-arrayfire.

commit ced0322386f1ad46dcf7d8ebef39258312eaa737
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date:   Sun Mar 20 02:25:05 2016 -0400

    FEAT: Adding functions to interact with other opencl libraries
---
 arrayfire/opencl.py | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 108 insertions(+)

diff --git a/arrayfire/opencl.py b/arrayfire/opencl.py
index 5c075df..d41be1d 100644
--- a/arrayfire/opencl.py
+++ b/arrayfire/opencl.py
@@ -13,6 +13,30 @@ Functions specific to OpenCL backend.
 This module provides interoperability with other OpenCL libraries.
 """
 
+from .util import *
+from .library import (_Enum, _Enum_Type)
+
+class DEVICE_TYPE(_Enum):
+    """
+    ArrayFire wrapper for CL_DEVICE_TYPE
+    """
+    CPU = _Enum_Type(1<<1)
+    GPU = _Enum_Type(1<<2)
+    ACC = _Enum_Type(1<<3)
+    UNKNOWN = _Enum_Type(-1)
+
+class PLATFORM(_Enum):
+    """
+    ArrayFire enum for common platforms
+    """
+    AMD     = _Enum_Type(0)
+    APPLE   = _Enum_Type(1)
+    INTEL   = _Enum_Type(2)
+    NVIDIA  = _Enum_Type(3)
+    BEIGNET = _Enum_Type(4)
+    POCL    = _Enum_Type(5)
+    UNKNOWN = _Enum_Type(-1)
+
 def get_context(retain=False):
     """
     Get the current OpenCL context being used by ArrayFire.
@@ -107,3 +131,87 @@ def set_device_id(idx):
 
     safe_call(backend.get().afcl_set_device_id(idx))
     return
+
+def add_device_context(dev, ctx, que):
+    """
+    Add a new device to arrayfire opencl device manager
+
+    Parameters
+    ----------
+
+    dev : cl_device_id
+
+    ctx : cl_context
+
+    que : cl_command_queue
+
+    """
+    if (backend.name() != "opencl"):
+        raise RuntimeError("Invalid backend loaded")
+
+    safe_call(backend.get().afcl_add_device_context(dev, ctx, que))
+
+def set_device_context(dev, ctx):
+    """
+    Set a device as current active device
+
+    Parameters
+    ----------
+
+    dev  : cl_device_id
+
+    ctx  : cl_context
+
+    """
+    if (backend.name() != "opencl"):
+        raise RuntimeError("Invalid backend loaded")
+
+    safe_call(backend.get().afcl_set_device_context(dev, ctx))
+
+def delete_device_context(dev, ctx):
+    """
+    Delete a device
+
+    Parameters
+    ----------
+
+    dev  : cl_device_id
+
+    ctx  : cl_context
+
+    """
+    if (backend.name() != "opencl"):
+        raise RuntimeError("Invalid backend loaded")
+
+    safe_call(backend.get().afcl_delete_device_context(dev, ctx))
+
+
+_to_device_type = {DEVICE_TYPE.CPU.value     : DEVICE_TYPE.CPU,
+                   DEVICE_TYPE.GPU.value     : DEVICE_TYPE.GPU,
+                   DEVICE_TYPE.ACC.value     : DEVICE_TYPE.ACC,
+                   DEVICE_TYPE.UNKNOWN.value : DEVICE_TYPE.UNKNOWN}
+
+_to_platform    = {PLATFORM.AMD.value     : PLATFORM.AMD,
+                   PLATFORM.APPLE.value   : PLATFORM.APPLE,
+                   PLATFORM.INTEL.value   : PLATFORM.INTEL,
+                   PLATFORM.NVIDIA.value  : PLATFORM.NVIDIA,
+                   PLATFORM.BEIGNET.value : PLATFORM.BEIGNET,
+                   PLATFORM.POCL.value    : PLATFORM.POCL,
+                   PLATFORM.UNKNOWN.value : PLATFORM.UNKNOWN}
+
+
+def get_device_type():
+    """
+    Get opencl device type
+    """
+    res = ct.c_int(DEVICE_TYPE.UNKNOWN.value)
+    safe_call(backend.get().afcl_get_device_type(ct.pointer(res)))
+    return _to_device_type[res.value]
+
+def get_platform():
+    """
+    Get opencl platform
+    """
+    res = ct.c_int(PLATFORM.UNKNOWN.value)
+    safe_call(backend.get().afcl_get_platform(ct.pointer(res)))
+    return _to_platform[res.value]

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/python-arrayfire.git



More information about the debian-science-commits mailing list