forked from arrayfire/arrayfire-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopencl.py
More file actions
109 lines (81 loc) · 2.66 KB
/
Copy pathopencl.py
File metadata and controls
109 lines (81 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#######################################################
# Copyright (c) 2015, ArrayFire
# All rights reserved.
#
# This file is distributed under 3-clause BSD license.
# The complete license agreement can be obtained at:
# http://arrayfire.com/licenses/BSD-3-Clause
########################################################
"""
Functions specific to OpenCL backend.
This module provides interoperability with other OpenCL libraries.
"""
def get_context(retain=False):
"""
Get the current OpenCL context being used by ArrayFire.
Parameters
----------
retain : bool. optional. Default: False.
Specifies if the context needs to be retained by arrayfire before returning.
Returns
-----------
context : integer denoting the context id.
"""
import ctypes as ct
from .util import safe_call as safe_call
from .library import backend as backend
if (backend.name() != "opencl"):
raise RuntimeError("Invalid backend loaded")
context = ct.c_void_p(0)
safe_call(backend.get().afcl_get_context(ct.pointer(context), retain))
return context.value
def get_queue(retain):
"""
Get the current OpenCL command queue being used by ArrayFire.
Parameters
----------
retain : bool. optional. Default: False.
Specifies if the context needs to be retained by arrayfire before returning.
Returns
-----------
queue : integer denoting the queue id.
"""
import ctypes as ct
from .util import safe_call as safe_call
from .library import backend as backend
if (backend.name() != "opencl"):
raise RuntimeError("Invalid backend loaded")
queue = ct.c_int(0)
safe_call(backend.get().afcl_get_queue(ct.pointer(queue), retain))
return queue.value
def get_device_id():
"""
Get native (unsorted) OpenCL device ID
Returns
--------
idx : int.
Specifies the `cl_device_id` of the device.
"""
import ctypes as ct
from .util import safe_call as safe_call
from .library import backend as backend
if (backend.name() != "opencl"):
raise RuntimeError("Invalid backend loaded")
idx = ct.c_int(0)
safe_call(backend.get().afcl_get_device_id(ct.pointer(idx)))
return idx.value
def set_device_id(idx):
"""
Set native (unsorted) OpenCL device ID
Parameters
----------
idx : int.
Specifies the `cl_device_id` of the device.
"""
import ctypes as ct
from .util import safe_call as safe_call
from .library import backend as backend
if (backend.name() != "opencl"):
raise RuntimeError("Invalid backend loaded")
safe_call(backend.get().afcl_set_device_id(idx))
return