opencl-bindings 1.0.0pre → 1.0.0pre2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6a2a39de40dd57f9441d6da9894bc715a9c18718
4
- data.tar.gz: 1c2df968aa6128ffa56e8cdaa579cf8a7a4c481f
3
+ metadata.gz: aea7dd9c7cc8149f8f2fc81b86edb83da2d71343
4
+ data.tar.gz: 1a14cd6169148349dd56c1fba9f9322fea6b924a
5
5
  SHA512:
6
- metadata.gz: 1bc4c3f5d0cac798970453ce8af577e950073884dfd98c94d21ccd2fa0df4e1f1d9bc8a90b86c9439966f80439bfb7213753d2330b65fbd303419fc638ef3734
7
- data.tar.gz: ed0e08663cde64ca257b9eb26513329e25456f88fdbc37094e10cfff2d57366d29f8d904471d6427be68e7a88da0e7832a662e1e73ba4bfd514abe817b298545
6
+ metadata.gz: fb1debe697a01f8c984c79abaf8f7d6a03d28d35b08ba857f1443aecff055ac2ec2628c8495f764ee84086d9c4e6aba2078ab10a925048045cd6eceb90cd7a0c
7
+ data.tar.gz: b350bd39fa361a6e54438e7a60365786a9b4c8deac95cc5b63dfa62ab862d3ec85b680fab290175c78b7f97c60b7496df5e5118ebf05d49180cc21ddb7a5fc80
data/ChangeLog CHANGED
@@ -1,3 +1,11 @@
1
+ 2015-11-23 vaiorabbit <http://twitter.com/vaiorabbit>
2
+
3
+ * sample/report_env.rb: Added.
4
+
5
+ 2015-11-22 vaiorabbit <http://twitter.com/vaiorabbit>
6
+
7
+ * sample/Mandelbrot: Added.
8
+
1
9
  2015-11-21 vaiorabbit <http://twitter.com/vaiorabbit>
2
10
 
3
11
  * sample/QJulia/qjulia_clu.rb: Added.
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  A Ruby binding for OpenCL 1.2
6
6
 
7
7
  * Created : 2015-10-25
8
- * Last modified : 2015-11-21
8
+ * Last modified : 2015-11-23
9
9
 
10
10
 
11
11
  ## Features ##
data/sample/hello.rb CHANGED
@@ -33,7 +33,7 @@ cl_device_ids = cl_devices_buf.unpack("Q#{cl_devices_entry_count}")
33
33
 
34
34
  # Context
35
35
  errcode_ret_buf = ' ' * 4
36
- cl_ctx = OpenCL.clCreateContext(nil, 1, cl_devices_buf, nil, nil, errcode_ret_buf)
36
+ cl_ctx = clCreateContext(nil, 1, cl_devices_buf, nil, nil, errcode_ret_buf)
37
37
 
38
38
  # Command Queues
39
39
  cl_cq = clCreateCommandQueue(cl_ctx, cl_device_ids[0], 0, errcode_ret_buf)
data/sample/hello_clu.rb CHANGED
@@ -23,37 +23,36 @@ clu_platform = CLUPlatform.new
23
23
  clu_device = CLUDevice.new(clu_platform.platforms[0], CL_DEVICE_TYPE_DEFAULT)
24
24
 
25
25
  # Context
26
- clu_ctx = CLUContext.newContext(nil, clu_device.devices)
26
+ clu_ctx = CLUContext.newContext(nil, [clu_device[0]])
27
27
 
28
28
  # Command Queues
29
- clu_cq = CLUCommandQueue.newCommandQueue(clu_ctx.context, clu_device.devices[0])
29
+ clu_cq = CLUCommandQueue.newCommandQueue(clu_ctx, clu_device[0])
30
30
 
31
31
  # Memory Buffer
32
32
  MEM_SIZE = 128
33
33
  clu_memobj = CLUMemory.newBuffer(clu_ctx.context, CL_MEM_READ_WRITE, MEM_SIZE * Fiddle:: SIZEOF_CHAR)
34
34
 
35
35
  # Program
36
- source_str = File.read("hello.cl")
37
- clu_prog = CLUProgram.newProgramWithSource(clu_ctx.context, [source_str])
38
- clu_prog.buildProgram(clu_device.devices)
36
+ clu_prog = CLUProgram.newProgramWithSource(clu_ctx, [File.read("hello.cl")])
37
+ clu_prog.buildProgram([clu_device[0]])
39
38
 
40
39
  # Kernel
41
- clu_kern = CLUKernel.newKernel(clu_prog.program, "hello")
40
+ clu_kern = CLUKernel.newKernel(clu_prog, "hello")
42
41
 
43
42
  # Execute
44
- clu_kern.setKernelArg(0, Fiddle::TYPE_VOIDP, [clu_memobj.mem.to_i])
45
- clu_cq.enqueueTask(clu_kern.kernel)
43
+ clu_kern.setKernelArg(0, Fiddle::TYPE_VOIDP, [clu_memobj.handle.to_i])
44
+ clu_cq.enqueueTask(clu_kern)
46
45
 
47
46
  # Result
48
47
  result_buf = ' ' * MEM_SIZE
49
- clu_cq.enqueueReadBuffer(clu_memobj.mem, CL_TRUE, 0, MEM_SIZE * Fiddle::SIZEOF_CHAR, result_buf)
48
+ clu_cq.enqueueReadBuffer(clu_memobj, CL_TRUE, 0, MEM_SIZE * Fiddle::SIZEOF_CHAR, result_buf)
50
49
  puts result_buf # => Hello, World!
51
50
 
52
51
  # End
53
52
  clu_cq.flush
54
53
  clu_cq.finish
55
- clu_kern.releaseKernel
56
- clu_prog.releaseProgram
57
- clu_memobj.releaseMemObject
58
- clu_cq.releaseCommandQueue
59
- clu_ctx.releaseContext
54
+ clu_kern.release
55
+ clu_prog.release
56
+ clu_memobj.release
57
+ clu_cq.release
58
+ clu_ctx.release
@@ -0,0 +1,431 @@
1
+ require_relative '../lib/opencl'
2
+ require_relative '../lib/opencl_ext'
3
+
4
+ # Load DLL
5
+ begin
6
+ OpenCL.load_lib('c:/Windows/System32/OpenCL.dll') # For Windows
7
+ rescue
8
+ OpenCL.load_lib('/System/Library/Frameworks/OpenCL.framework/OpenCL') # For Mac OS X
9
+ end
10
+ include OpenCL
11
+
12
+ ################################################################################
13
+
14
+ $enum2name = {
15
+ OpenCL::CL_DEVICE_TYPE => "CL_DEVICE_TYPE",
16
+ OpenCL::CL_DEVICE_VENDOR_ID => "CL_DEVICE_VENDOR_ID",
17
+ OpenCL::CL_DEVICE_MAX_COMPUTE_UNITS => "CL_DEVICE_MAX_COMPUTE_UNITS",
18
+ OpenCL::CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS => "CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS",
19
+ OpenCL::CL_DEVICE_MAX_WORK_GROUP_SIZE => "CL_DEVICE_MAX_WORK_GROUP_SIZE",
20
+ OpenCL::CL_DEVICE_MAX_WORK_ITEM_SIZES => "CL_DEVICE_MAX_WORK_ITEM_SIZES",
21
+ OpenCL::CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR => "CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR",
22
+ OpenCL::CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT => "CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT",
23
+ OpenCL::CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT => "CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT",
24
+ OpenCL::CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG => "CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG",
25
+ OpenCL::CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT => "CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT",
26
+ OpenCL::CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE => "CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE",
27
+ OpenCL::CL_DEVICE_MAX_CLOCK_FREQUENCY => "CL_DEVICE_MAX_CLOCK_FREQUENCY",
28
+ OpenCL::CL_DEVICE_ADDRESS_BITS => "CL_DEVICE_ADDRESS_BITS",
29
+ OpenCL::CL_DEVICE_MAX_READ_IMAGE_ARGS => "CL_DEVICE_MAX_READ_IMAGE_ARGS",
30
+ OpenCL::CL_DEVICE_MAX_WRITE_IMAGE_ARGS => "CL_DEVICE_MAX_WRITE_IMAGE_ARGS",
31
+ OpenCL::CL_DEVICE_MAX_MEM_ALLOC_SIZE => "CL_DEVICE_MAX_MEM_ALLOC_SIZE",
32
+ OpenCL::CL_DEVICE_IMAGE2D_MAX_WIDTH => "CL_DEVICE_IMAGE2D_MAX_WIDTH",
33
+ OpenCL::CL_DEVICE_IMAGE2D_MAX_HEIGHT => "CL_DEVICE_IMAGE2D_MAX_HEIGHT",
34
+ OpenCL::CL_DEVICE_IMAGE3D_MAX_WIDTH => "CL_DEVICE_IMAGE3D_MAX_WIDTH",
35
+ OpenCL::CL_DEVICE_IMAGE3D_MAX_HEIGHT => "CL_DEVICE_IMAGE3D_MAX_HEIGHT",
36
+ OpenCL::CL_DEVICE_IMAGE3D_MAX_DEPTH => "CL_DEVICE_IMAGE3D_MAX_DEPTH",
37
+ OpenCL::CL_DEVICE_IMAGE_SUPPORT => "CL_DEVICE_IMAGE_SUPPORT",
38
+ OpenCL::CL_DEVICE_MAX_PARAMETER_SIZE => "CL_DEVICE_MAX_PARAMETER_SIZE",
39
+ OpenCL::CL_DEVICE_MAX_SAMPLERS => "CL_DEVICE_MAX_SAMPLERS",
40
+ OpenCL::CL_DEVICE_MEM_BASE_ADDR_ALIGN => "CL_DEVICE_MEM_BASE_ADDR_ALIGN",
41
+ OpenCL::CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE => "CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE",
42
+ OpenCL::CL_DEVICE_SINGLE_FP_CONFIG => "CL_DEVICE_SINGLE_FP_CONFIG",
43
+ OpenCL::CL_DEVICE_GLOBAL_MEM_CACHE_TYPE => "CL_DEVICE_GLOBAL_MEM_CACHE_TYPE",
44
+ OpenCL::CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE => "CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE",
45
+ OpenCL::CL_DEVICE_GLOBAL_MEM_CACHE_SIZE => "CL_DEVICE_GLOBAL_MEM_CACHE_SIZE",
46
+ OpenCL::CL_DEVICE_GLOBAL_MEM_SIZE => "CL_DEVICE_GLOBAL_MEM_SIZE",
47
+ OpenCL::CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE => "CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE",
48
+ OpenCL::CL_DEVICE_MAX_CONSTANT_ARGS => "CL_DEVICE_MAX_CONSTANT_ARGS",
49
+ OpenCL::CL_DEVICE_LOCAL_MEM_TYPE => "CL_DEVICE_LOCAL_MEM_TYPE",
50
+ OpenCL::CL_DEVICE_LOCAL_MEM_SIZE => "CL_DEVICE_LOCAL_MEM_SIZE",
51
+ OpenCL::CL_DEVICE_ERROR_CORRECTION_SUPPORT => "CL_DEVICE_ERROR_CORRECTION_SUPPORT",
52
+ OpenCL::CL_DEVICE_PROFILING_TIMER_RESOLUTION => "CL_DEVICE_PROFILING_TIMER_RESOLUTION",
53
+ OpenCL::CL_DEVICE_ENDIAN_LITTLE => "CL_DEVICE_ENDIAN_LITTLE",
54
+ OpenCL::CL_DEVICE_AVAILABLE => "CL_DEVICE_AVAILABLE",
55
+ OpenCL::CL_DEVICE_COMPILER_AVAILABLE => "CL_DEVICE_COMPILER_AVAILABLE",
56
+ OpenCL::CL_DEVICE_EXECUTION_CAPABILITIES => "CL_DEVICE_EXECUTION_CAPABILITIES",
57
+ OpenCL::CL_DEVICE_QUEUE_PROPERTIES => "CL_DEVICE_QUEUE_PROPERTIES",
58
+ OpenCL::CL_DEVICE_NAME => "CL_DEVICE_NAME",
59
+ OpenCL::CL_DEVICE_VENDOR => "CL_DEVICE_VENDOR",
60
+ OpenCL::CL_DRIVER_VERSION => "CL_DRIVER_VERSION",
61
+ OpenCL::CL_DEVICE_PROFILE => "CL_DEVICE_PROFILE",
62
+ OpenCL::CL_DEVICE_VERSION => "CL_DEVICE_VERSION",
63
+ OpenCL::CL_DEVICE_EXTENSIONS => "CL_DEVICE_EXTENSIONS",
64
+ OpenCL::CL_DEVICE_PLATFORM => "CL_DEVICE_PLATFORM",
65
+ OpenCL::CL_DEVICE_DOUBLE_FP_CONFIG => "CL_DEVICE_DOUBLE_FP_CONFIG",
66
+ OpenCL::CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF => "CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF",
67
+ OpenCL::CL_DEVICE_HOST_UNIFIED_MEMORY => "CL_DEVICE_HOST_UNIFIED_MEMORY",
68
+ OpenCL::CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR => "CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR",
69
+ OpenCL::CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT => "CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT",
70
+ OpenCL::CL_DEVICE_NATIVE_VECTOR_WIDTH_INT => "CL_DEVICE_NATIVE_VECTOR_WIDTH_INT",
71
+ OpenCL::CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG => "CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG",
72
+ OpenCL::CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT => "CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT",
73
+ OpenCL::CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE => "CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE",
74
+ OpenCL::CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF => "CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF",
75
+ OpenCL::CL_DEVICE_OPENCL_C_VERSION => "CL_DEVICE_OPENCL_C_VERSION",
76
+ OpenCL::CL_DEVICE_LINKER_AVAILABLE => "CL_DEVICE_LINKER_AVAILABLE",
77
+ OpenCL::CL_DEVICE_BUILT_IN_KERNELS => "CL_DEVICE_BUILT_IN_KERNELS",
78
+ OpenCL::CL_DEVICE_IMAGE_MAX_BUFFER_SIZE => "CL_DEVICE_IMAGE_MAX_BUFFER_SIZE",
79
+ OpenCL::CL_DEVICE_IMAGE_MAX_ARRAY_SIZE => "CL_DEVICE_IMAGE_MAX_ARRAY_SIZE",
80
+ OpenCL::CL_DEVICE_PARENT_DEVICE => "CL_DEVICE_PARENT_DEVICE",
81
+ OpenCL::CL_DEVICE_PARTITION_MAX_SUB_DEVICES => "CL_DEVICE_PARTITION_MAX_SUB_DEVICES",
82
+ OpenCL::CL_DEVICE_PARTITION_PROPERTIES => "CL_DEVICE_PARTITION_PROPERTIES",
83
+ OpenCL::CL_DEVICE_PARTITION_AFFINITY_DOMAIN => "CL_DEVICE_PARTITION_AFFINITY_DOMAIN",
84
+ OpenCL::CL_DEVICE_PARTITION_TYPE => "CL_DEVICE_PARTITION_TYPE",
85
+ OpenCL::CL_DEVICE_REFERENCE_COUNT => "CL_DEVICE_REFERENCE_COUNT",
86
+ OpenCL::CL_DEVICE_PREFERRED_INTEROP_USER_SYNC => "CL_DEVICE_PREFERRED_INTEROP_USER_SYNC",
87
+ OpenCL::CL_DEVICE_PRINTF_BUFFER_SIZE => "CL_DEVICE_PRINTF_BUFFER_SIZE",
88
+ OpenCL::CL_DEVICE_IMAGE_PITCH_ALIGNMENT => "CL_DEVICE_IMAGE_PITCH_ALIGNMENT",
89
+ OpenCL::CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT => "CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT"
90
+ }
91
+
92
+ $enum2pack = {
93
+ OpenCL::CL_DEVICE_TYPE => "L",
94
+ OpenCL::CL_DEVICE_VENDOR_ID => "L",
95
+ OpenCL::CL_DEVICE_MAX_COMPUTE_UNITS => "L",
96
+ OpenCL::CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS => "L",
97
+ OpenCL::CL_DEVICE_MAX_WORK_GROUP_SIZE => "L",
98
+ OpenCL::CL_DEVICE_MAX_WORK_ITEM_SIZES => "L3",
99
+ OpenCL::CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR => "L",
100
+ OpenCL::CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT => "L",
101
+ OpenCL::CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT => "L",
102
+ OpenCL::CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG => "L",
103
+ OpenCL::CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT => "L",
104
+ OpenCL::CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE => "L",
105
+ OpenCL::CL_DEVICE_MAX_CLOCK_FREQUENCY => "L",
106
+ OpenCL::CL_DEVICE_ADDRESS_BITS => "L",
107
+ OpenCL::CL_DEVICE_MAX_READ_IMAGE_ARGS => "L",
108
+ OpenCL::CL_DEVICE_MAX_WRITE_IMAGE_ARGS => "L",
109
+ OpenCL::CL_DEVICE_MAX_MEM_ALLOC_SIZE => "L",
110
+ OpenCL::CL_DEVICE_IMAGE2D_MAX_WIDTH => "L",
111
+ OpenCL::CL_DEVICE_IMAGE2D_MAX_HEIGHT => "L",
112
+ OpenCL::CL_DEVICE_IMAGE3D_MAX_WIDTH => "L",
113
+ OpenCL::CL_DEVICE_IMAGE3D_MAX_HEIGHT => "L",
114
+ OpenCL::CL_DEVICE_IMAGE3D_MAX_DEPTH => "L",
115
+ OpenCL::CL_DEVICE_IMAGE_SUPPORT => "cl_bool",
116
+ OpenCL::CL_DEVICE_MAX_PARAMETER_SIZE => "L",
117
+ OpenCL::CL_DEVICE_MAX_SAMPLERS => "L",
118
+ OpenCL::CL_DEVICE_MEM_BASE_ADDR_ALIGN => "L",
119
+ OpenCL::CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE => "L",
120
+ OpenCL::CL_DEVICE_SINGLE_FP_CONFIG => "cl_bitfield",
121
+ OpenCL::CL_DEVICE_GLOBAL_MEM_CACHE_TYPE => "L",
122
+ OpenCL::CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE => "L",
123
+ OpenCL::CL_DEVICE_GLOBAL_MEM_CACHE_SIZE => "L",
124
+ OpenCL::CL_DEVICE_GLOBAL_MEM_SIZE => "L",
125
+ OpenCL::CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE => "L",
126
+ OpenCL::CL_DEVICE_MAX_CONSTANT_ARGS => "L",
127
+ OpenCL::CL_DEVICE_LOCAL_MEM_TYPE => "L",
128
+ OpenCL::CL_DEVICE_LOCAL_MEM_SIZE => "L",
129
+ OpenCL::CL_DEVICE_ERROR_CORRECTION_SUPPORT => "cl_bool",
130
+ OpenCL::CL_DEVICE_PROFILING_TIMER_RESOLUTION => "L",
131
+ OpenCL::CL_DEVICE_ENDIAN_LITTLE => "cl_bool",
132
+ OpenCL::CL_DEVICE_AVAILABLE => "cl_bool",
133
+ OpenCL::CL_DEVICE_COMPILER_AVAILABLE => "cl_bool",
134
+ OpenCL::CL_DEVICE_EXECUTION_CAPABILITIES => "L",
135
+ OpenCL::CL_DEVICE_QUEUE_PROPERTIES => "cl_bitfield",
136
+ OpenCL::CL_DEVICE_NAME => "Z*",
137
+ OpenCL::CL_DEVICE_VENDOR => "Z*",
138
+ OpenCL::CL_DRIVER_VERSION => "Z*",
139
+ OpenCL::CL_DEVICE_PROFILE => "Z*",
140
+ OpenCL::CL_DEVICE_VERSION => "Z*",
141
+ OpenCL::CL_DEVICE_EXTENSIONS => "Z*",
142
+ OpenCL::CL_DEVICE_PLATFORM => "Q",
143
+ OpenCL::CL_DEVICE_DOUBLE_FP_CONFIG => "cl_bitfield",
144
+ OpenCL::CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF => "L",
145
+ OpenCL::CL_DEVICE_HOST_UNIFIED_MEMORY => "cl_bool",
146
+ OpenCL::CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR => "L",
147
+ OpenCL::CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT => "L",
148
+ OpenCL::CL_DEVICE_NATIVE_VECTOR_WIDTH_INT => "L",
149
+ OpenCL::CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG => "L",
150
+ OpenCL::CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT => "L",
151
+ OpenCL::CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE => "L",
152
+ OpenCL::CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF => "L",
153
+ OpenCL::CL_DEVICE_OPENCL_C_VERSION => "Z*",
154
+ OpenCL::CL_DEVICE_LINKER_AVAILABLE => "cl_bool",
155
+ OpenCL::CL_DEVICE_BUILT_IN_KERNELS => "Z*",
156
+ OpenCL::CL_DEVICE_IMAGE_MAX_BUFFER_SIZE => "L",
157
+ OpenCL::CL_DEVICE_IMAGE_MAX_ARRAY_SIZE => "L",
158
+ OpenCL::CL_DEVICE_PARENT_DEVICE => "Q",
159
+ OpenCL::CL_DEVICE_PARTITION_MAX_SUB_DEVICES => "L",
160
+ OpenCL::CL_DEVICE_PARTITION_PROPERTIES => "L",
161
+ OpenCL::CL_DEVICE_PARTITION_AFFINITY_DOMAIN => "cl_bitfield",
162
+ OpenCL::CL_DEVICE_PARTITION_TYPE => "L",
163
+ OpenCL::CL_DEVICE_REFERENCE_COUNT => "L",
164
+ OpenCL::CL_DEVICE_PREFERRED_INTEROP_USER_SYNC => "L",
165
+ OpenCL::CL_DEVICE_PRINTF_BUFFER_SIZE => "L",
166
+ OpenCL::CL_DEVICE_IMAGE_PITCH_ALIGNMENT => "L",
167
+ OpenCL::CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT => "L"
168
+ }
169
+
170
+ def print_device_info(device_id)
171
+ err = 0
172
+ errcode_ret_buf = ' ' * 4
173
+ info_buf = ' ' * 1024
174
+
175
+ enums = [
176
+ OpenCL::CL_DEVICE_TYPE,
177
+ OpenCL::CL_DEVICE_VENDOR_ID,
178
+ OpenCL::CL_DEVICE_MAX_COMPUTE_UNITS,
179
+ OpenCL::CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS,
180
+ OpenCL::CL_DEVICE_MAX_WORK_GROUP_SIZE,
181
+ OpenCL::CL_DEVICE_MAX_WORK_ITEM_SIZES,
182
+ OpenCL::CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR,
183
+ OpenCL::CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT,
184
+ OpenCL::CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT,
185
+ OpenCL::CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG,
186
+ OpenCL::CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT,
187
+ OpenCL::CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE,
188
+ OpenCL::CL_DEVICE_MAX_CLOCK_FREQUENCY,
189
+ OpenCL::CL_DEVICE_ADDRESS_BITS,
190
+ OpenCL::CL_DEVICE_MAX_READ_IMAGE_ARGS,
191
+ OpenCL::CL_DEVICE_MAX_WRITE_IMAGE_ARGS,
192
+ OpenCL::CL_DEVICE_MAX_MEM_ALLOC_SIZE,
193
+ OpenCL::CL_DEVICE_IMAGE2D_MAX_WIDTH,
194
+ OpenCL::CL_DEVICE_IMAGE2D_MAX_HEIGHT,
195
+ OpenCL::CL_DEVICE_IMAGE3D_MAX_WIDTH,
196
+ OpenCL::CL_DEVICE_IMAGE3D_MAX_HEIGHT,
197
+ OpenCL::CL_DEVICE_IMAGE3D_MAX_DEPTH,
198
+ OpenCL::CL_DEVICE_IMAGE_SUPPORT,
199
+ OpenCL::CL_DEVICE_MAX_PARAMETER_SIZE,
200
+ OpenCL::CL_DEVICE_MAX_SAMPLERS,
201
+ OpenCL::CL_DEVICE_MEM_BASE_ADDR_ALIGN,
202
+ OpenCL::CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE,
203
+ OpenCL::CL_DEVICE_SINGLE_FP_CONFIG,
204
+ OpenCL::CL_DEVICE_GLOBAL_MEM_CACHE_TYPE,
205
+ OpenCL::CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE,
206
+ OpenCL::CL_DEVICE_GLOBAL_MEM_CACHE_SIZE,
207
+ OpenCL::CL_DEVICE_GLOBAL_MEM_SIZE,
208
+ OpenCL::CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE,
209
+ OpenCL::CL_DEVICE_MAX_CONSTANT_ARGS,
210
+ OpenCL::CL_DEVICE_LOCAL_MEM_TYPE,
211
+ OpenCL::CL_DEVICE_LOCAL_MEM_SIZE,
212
+ OpenCL::CL_DEVICE_ERROR_CORRECTION_SUPPORT,
213
+ OpenCL::CL_DEVICE_PROFILING_TIMER_RESOLUTION,
214
+ OpenCL::CL_DEVICE_ENDIAN_LITTLE,
215
+ OpenCL::CL_DEVICE_AVAILABLE,
216
+ OpenCL::CL_DEVICE_COMPILER_AVAILABLE,
217
+ OpenCL::CL_DEVICE_EXECUTION_CAPABILITIES,
218
+ OpenCL::CL_DEVICE_QUEUE_PROPERTIES,
219
+ OpenCL::CL_DEVICE_NAME,
220
+ OpenCL::CL_DEVICE_VENDOR,
221
+ OpenCL::CL_DRIVER_VERSION,
222
+ OpenCL::CL_DEVICE_PROFILE,
223
+ OpenCL::CL_DEVICE_VERSION,
224
+ OpenCL::CL_DEVICE_EXTENSIONS,
225
+ OpenCL::CL_DEVICE_PLATFORM,
226
+ OpenCL::CL_DEVICE_DOUBLE_FP_CONFIG,
227
+ OpenCL::CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF,
228
+ OpenCL::CL_DEVICE_HOST_UNIFIED_MEMORY,
229
+ OpenCL::CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR,
230
+ OpenCL::CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT,
231
+ OpenCL::CL_DEVICE_NATIVE_VECTOR_WIDTH_INT,
232
+ OpenCL::CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG,
233
+ OpenCL::CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT,
234
+ OpenCL::CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE,
235
+ OpenCL::CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF,
236
+ OpenCL::CL_DEVICE_OPENCL_C_VERSION,
237
+ OpenCL::CL_DEVICE_LINKER_AVAILABLE,
238
+ OpenCL::CL_DEVICE_BUILT_IN_KERNELS,
239
+ OpenCL::CL_DEVICE_IMAGE_MAX_BUFFER_SIZE,
240
+ OpenCL::CL_DEVICE_IMAGE_MAX_ARRAY_SIZE,
241
+ OpenCL::CL_DEVICE_PARENT_DEVICE,
242
+ OpenCL::CL_DEVICE_PARTITION_MAX_SUB_DEVICES,
243
+ OpenCL::CL_DEVICE_PARTITION_PROPERTIES,
244
+ OpenCL::CL_DEVICE_PARTITION_AFFINITY_DOMAIN,
245
+ OpenCL::CL_DEVICE_PARTITION_TYPE,
246
+ OpenCL::CL_DEVICE_REFERENCE_COUNT,
247
+ OpenCL::CL_DEVICE_PREFERRED_INTEROP_USER_SYNC,
248
+ OpenCL::CL_DEVICE_PRINTF_BUFFER_SIZE,
249
+ OpenCL::CL_DEVICE_IMAGE_PITCH_ALIGNMENT,
250
+ OpenCL::CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT,
251
+ ]
252
+
253
+ enums.each do |e|
254
+ err = clGetDeviceInfo(device_id, e, info_buf.length, info_buf, nil)
255
+
256
+ if $enum2pack[e] == "cl_bool"
257
+ info = info_buf.unpack($enum2pack[e])
258
+ info = "#{info == 0 ? 'false' : 'true'}"
259
+ elsif $enum2pack[e] == "cl_bitfield"
260
+ info = info_buf.unpack("L")[0]
261
+ info = "#{info} (0b#{info.to_s(2)})"
262
+ else
263
+ info = info_buf.unpack($enum2pack[e])
264
+ end
265
+
266
+ if e == OpenCL::CL_DEVICE_EXTENSIONS
267
+ extensions = info[0].split
268
+ puts "CL_DEVICE_EXTENSIONS: "
269
+ extensions.each do |extension|
270
+ puts "\t#{extension}"
271
+ end
272
+ else
273
+ puts "#{$enum2name[e]}: \t#{info}"
274
+ end
275
+ end
276
+ end
277
+
278
+ ################################################################################
279
+
280
+ $imageformat2name = {
281
+ # cl_channel_order
282
+ OpenCL::CL_R => "CL_R",
283
+ OpenCL::CL_A => "CL_A",
284
+ OpenCL::CL_RG => "CL_RG",
285
+ OpenCL::CL_RA => "CL_RA",
286
+ OpenCL::CL_RGB => "CL_RGB",
287
+ OpenCL::CL_RGBA => "CL_RGBA",
288
+ OpenCL::CL_BGRA => "CL_BGRA",
289
+ OpenCL::CL_ARGB => "CL_ARGB",
290
+ OpenCL::CL_INTENSITY => "CL_INTENSITY",
291
+ OpenCL::CL_LUMINANCE => "CL_LUMINANCE",
292
+ OpenCL::CL_Rx => "CL_Rx",
293
+ OpenCL::CL_RGx => "CL_RGx",
294
+ OpenCL::CL_RGBx => "CL_RGBx",
295
+ OpenCL::CL_DEPTH => "CL_DEPTH",
296
+ OpenCL::CL_DEPTH_STENCIL => "CL_DEPTH_STENCIL",
297
+
298
+ # cl_channel_type
299
+ OpenCL::CL_SNORM_INT8 => "CL_SNORM_INT8",
300
+ OpenCL::CL_SNORM_INT16 => "CL_SNORM_INT16",
301
+ OpenCL::CL_UNORM_INT8 => "CL_UNORM_INT8",
302
+ OpenCL::CL_UNORM_INT16 => "CL_UNORM_INT16",
303
+ OpenCL::CL_UNORM_SHORT_565 => "CL_UNORM_SHORT_565",
304
+ OpenCL::CL_UNORM_SHORT_555 => "CL_UNORM_SHORT_555",
305
+ OpenCL::CL_UNORM_INT_101010 => "CL_UNORM_INT_101010",
306
+ OpenCL::CL_SIGNED_INT8 => "CL_SIGNED_INT8",
307
+ OpenCL::CL_SIGNED_INT16 => "CL_SIGNED_INT16",
308
+ OpenCL::CL_SIGNED_INT32 => "CL_SIGNED_INT32",
309
+ OpenCL::CL_UNSIGNED_INT8 => "CL_UNSIGNED_INT8",
310
+ OpenCL::CL_UNSIGNED_INT16 => "CL_UNSIGNED_INT16",
311
+ OpenCL::CL_UNSIGNED_INT32 => "CL_UNSIGNED_INT32",
312
+ OpenCL::CL_HALF_FLOAT => "CL_HALF_FLOAT",
313
+ OpenCL::CL_FLOAT => "CL_FLOAT",
314
+ OpenCL::CL_UNORM_INT24 => "CL_UNORM_INT24",
315
+
316
+ # 0x10000012 : ABGR and xBGR formats for CoreImage CL-GPU support (from /OpenCL.framework/Headers/cl_ext.h)
317
+ OpenCL::CL_ABGR_APPLE => "CL_ABGR_APPLE",
318
+
319
+ # cl_APPLE_fixed_alpha_channel_orders (from /OpenCL.framework/Headers/cl_ext.h)
320
+
321
+ # 0x10000006
322
+ OpenCL::CL_1RGB_APPLE => "CL_1RGB_APPLE",
323
+ # 0x10000007
324
+ OpenCL::CL_BGR1_APPLE => "CL_BGR1_APPLE",
325
+
326
+ # cl_APPLE_biased_fixed_point_image_formats (from /OpenCL.framework/Headers/cl_ext.h)
327
+
328
+ # 0x10000008
329
+ CL_SFIXED14_APPLE => "CL_SFIXED14_APPLE",
330
+ # 0x10000009
331
+ CL_BIASED_HALF_APPLE => "CL_BIASED_HALF_APPLE",
332
+
333
+ # YUV image support (from /OpenCL.framework/Headers/cl_ext.h)
334
+
335
+ # 0x10000010
336
+ OpenCL::CL_YCbYCr_APPLE => "OpenCL::CL_YCbYCr_APPLE",
337
+ # 0x10000011
338
+ OpenCL::CL_CbYCrY_APPLE => "OpenCL::CL_CbYCrY_APPLE",
339
+ }
340
+
341
+ def print_supported_image_formats(cl_ctx, image_type = OpenCL::CL_MEM_OBJECT_IMAGE2D)
342
+ return unless (image_type == CL_MEM_OBJECT_IMAGE2D || image_type == CL_MEM_OBJECT_IMAGE3D)
343
+ err = 0
344
+
345
+ image_formats = []
346
+
347
+ num_image_formamts_buf = ' ' * 4
348
+ err = clGetSupportedImageFormats(cl_ctx, CL_MEM_READ_ONLY, image_type, 0, nil, num_image_formamts_buf)
349
+ num_image_formamts = num_image_formamts_buf.unpack("L")[0]
350
+ image_formats_buf = Fiddle::Pointer.malloc(num_image_formamts * OpenCL::CL_STRUCT_IMAGE_FORMAT.size)
351
+ err = clGetSupportedImageFormats(cl_ctx, CL_MEM_READ_ONLY, image_type, num_image_formamts, image_formats_buf, nil)
352
+
353
+ num_image_formamts.times do |i|
354
+ fmt = OpenCL::CL_STRUCT_IMAGE_FORMAT.new(image_formats_buf.to_i + i * OpenCL::CL_STRUCT_IMAGE_FORMAT.size)
355
+ image_formats << fmt
356
+ end
357
+
358
+ puts "Supported Image Formats (#{image_type == CL_MEM_OBJECT_IMAGE2D ? '2D' : '3D'})"
359
+ image_formats.each_with_index do |fmt, i|
360
+ puts "\t#{i}:\t#{$imageformat2name[fmt.image_channel_order]} - #{$imageformat2name[fmt.image_channel_data_type]}"
361
+ end
362
+ end
363
+
364
+ ################################################################################
365
+
366
+ if __FILE__ == $0
367
+
368
+ err = 0
369
+ errcode_ret_buf = ' ' * 4
370
+ info_buf = ' ' * 1024
371
+
372
+ # Platform
373
+ cl_platforms_count_buf = ' ' * 4
374
+ err = clGetPlatformIDs(0, nil, cl_platforms_count_buf)
375
+ cl_platforms_count = cl_platforms_count_buf.unpack("L")[0]
376
+
377
+ cl_platforms_buf = ' ' * 8 * cl_platforms_count
378
+ err = clGetPlatformIDs(cl_platforms_count, cl_platforms_buf, nil)
379
+ cl_platforms = cl_platforms_buf.unpack("Q#{cl_platforms_count}")
380
+
381
+ platform_info_params = {
382
+ CL_PLATFORM_PROFILE => "CL_PLATFORM_PROFILE",
383
+ CL_PLATFORM_VERSION => "CL_PLATFORM_VERSION",
384
+ CL_PLATFORM_NAME => "CL_PLATFORM_NAME",
385
+ CL_PLATFORM_VENDOR => "CL_PLATFORM_VENDOR",
386
+ }
387
+ platform_info_params.each do |k, v|
388
+ err = clGetPlatformInfo(cl_platforms[0], k, info_buf.length, info_buf, nil)
389
+ puts "#{v}: \t#{info_buf.unpack("Z*")[0]}"
390
+ end
391
+
392
+ err = clGetPlatformInfo(cl_platforms[0], CL_PLATFORM_EXTENSIONS, info_buf.length, info_buf, nil)
393
+ extensions = info_buf.unpack("Z*")[0].split
394
+ puts "CL_PLATFORM_EXTENSIONS: "
395
+ extensions.each do |extension|
396
+ puts "\t#{extension}"
397
+ end
398
+ puts ""
399
+
400
+ # Devices
401
+ cl_devices_count_buf = ' ' * 4
402
+
403
+ err = clGetDeviceIDs(cl_platforms[0], CL_DEVICE_TYPE_ALL, 0, nil, cl_devices_count_buf)
404
+ cl_devices_count = cl_devices_count_buf.unpack("L")[0]
405
+
406
+ exit if cl_devices_count == 0
407
+
408
+ cl_devices_buf = ' ' * 8 * cl_devices_count
409
+ err = clGetDeviceIDs(cl_platforms[0], CL_DEVICE_TYPE_ALL, cl_devices_count, cl_devices_buf, nil)
410
+ cl_devices = cl_devices_buf.unpack("Q#{cl_devices_count}")
411
+
412
+ cl_devices_count.times do |i|
413
+ err = clGetDeviceInfo(cl_devices[i], CL_DEVICE_NAME, info_buf.length, info_buf, nil)
414
+ puts "================================================================================"
415
+ puts "CL_DEVICE_NAME: #{info_buf.unpack("Z*")[0]}"
416
+ puts "================================================================================"
417
+ print_device_info(cl_devices[i])
418
+ puts ""
419
+ end
420
+
421
+ # Supported Image Formats
422
+ cl_ctx = clCreateContext(nil, cl_devices_count, cl_devices.pack("Q*"), nil, nil, nil)
423
+
424
+ # 2D
425
+ print_supported_image_formats(cl_ctx, CL_MEM_OBJECT_IMAGE2D)
426
+
427
+ puts ""
428
+
429
+ # 3D
430
+ print_supported_image_formats(cl_ctx, CL_MEM_OBJECT_IMAGE3D)
431
+ end
data/sample/util/clu.rb CHANGED
@@ -18,6 +18,10 @@ class CLUPlatform
18
18
  return @platforms
19
19
  end
20
20
 
21
+ def [](index)
22
+ platforms[index]
23
+ end
24
+
21
25
  def getPlatformIDs(error_info: nil)
22
26
  # cl_uint : num_entries
23
27
  # cl_platform_id* : platforms
@@ -65,6 +69,10 @@ class CLUDevice
65
69
  end
66
70
  end
67
71
 
72
+ def [](index)
73
+ @devices[index]
74
+ end
75
+
68
76
  # cl_platform_id : platform
69
77
  # cl_device_type : device_type
70
78
  def getDeviceIDs(platform, device_type, error_info: nil)
@@ -96,6 +104,8 @@ class CLUDevice
96
104
  end
97
105
  end
98
106
 
107
+ alias_method :retain, :retainDevices
108
+
99
109
  # cl_device_id : device
100
110
  def releaseDevice(device: @devices[0], error_info: nil)
101
111
  return OpenCL.clReleaseDevice(device)
@@ -108,6 +118,8 @@ class CLUDevice
108
118
  end
109
119
  end
110
120
 
121
+ alias_method :release, :releaseDevices
122
+
111
123
  # cl_device_id : device
112
124
  # cl_device_info : param_name
113
125
  def getDeviceInfo(param_name, device: @devices[0], error_info: nil)
@@ -247,11 +259,16 @@ class CLUContext
247
259
  @context = nil # cl_context
248
260
  end
249
261
 
262
+ def handle
263
+ @context
264
+ end
265
+
250
266
  # cl_context_properties * : properties
251
267
  # cl_device_id * : devices
252
268
  # void * : pfn_notify(char *, void *, size_t, void *),
253
269
  # void * : user_data
254
270
  def createContext(properties, devices, pfn_notify: nil, user_data: nil, error_info: nil)
271
+ devices = devices.devices if devices.kind_of? CLUDevice
255
272
  packed_properties = properties == nil ? nil : properties.pack("Q*")
256
273
  num_devices = devices.length
257
274
  errcode_ret_buf = ' ' * 4
@@ -328,11 +345,15 @@ class CLUContext
328
345
  return OpenCL.clRetainContext(context)
329
346
  end
330
347
 
348
+ alias_method :retain, :retainContext
349
+
331
350
  # cl_context : context
332
351
  def releaseContext(context: @context)
333
352
  return OpenCL.clReleaseContext(context)
334
353
  end
335
354
 
355
+ alias_method :release, :releaseContext
356
+
336
357
  # cl_context : context
337
358
  # cl_context_info : param_name
338
359
  def getContextInfo(param_name, context: @context, error_info: nil)
@@ -394,11 +415,16 @@ class CLUMemory
394
415
  @mem = nil
395
416
  end
396
417
 
418
+ def handle
419
+ @mem
420
+ end
421
+
397
422
  # cl_context : context
398
423
  # cl_mem_flags : flags
399
424
  # size_t : size
400
425
  # void * : host_ptr
401
426
  def createBuffer(context, flags, size, host_ptr = nil, error_info: nil)
427
+ context = context.handle if context.kind_of? CLUContext
402
428
  errcode_ret_buf = ' ' * 4
403
429
 
404
430
  mem = OpenCL.clCreateBuffer(context, flags, size, host_ptr, errcode_ret_buf)
@@ -425,6 +451,7 @@ class CLUMemory
425
451
  # const cl_image_desc * : image_desc
426
452
  # void * : host_ptr
427
453
  def createImage(context, flags, image_format, image_desc, host_ptr = nil, error_info: nil)
454
+ context = context.handle if context.kind_of? CLUContext
428
455
  errcode_ret_buf = ' ' * 4
429
456
 
430
457
  mem = OpenCL.clCreateImage(context, flags, image_format, image_desc, host_ptr, errcode_ret_buf)
@@ -449,6 +476,7 @@ class CLUMemory
449
476
  # cl_mem_flags : flags
450
477
  # cl_GLuint : bufobj
451
478
  def createFromGLBuffer(context, flags, bufobj, error_info: nil)
479
+ context = context.handle if context.kind_of? CLUContext
452
480
  errcode_ret_buf = ' ' * 4
453
481
 
454
482
  mem = OpenCL.clCreateFromGLBuffer(context, flags, bufobj, errcode_ret_buf)
@@ -475,6 +503,7 @@ class CLUMemory
475
503
  # cl_GLint : miplevel
476
504
  # cl_GLuint : texture
477
505
  def createFromGLTexture(context, flags, target, miplevel, texture, error_info: nil)
506
+ context = context.handle if context.kind_of? CLUContext
478
507
  errcode_ret_buf = ' ' * 4
479
508
 
480
509
  mem = OpenCL.clCreateFromGLTexture(context, flags, target, miplevel, texture, errcode_ret_buf)
@@ -499,6 +528,7 @@ class CLUMemory
499
528
  # cl_mem_flags : flags
500
529
  # cl_GLuint : renderbuffer
501
530
  def createFromGLRenderBuffer(context, flags, renderbuffer, error_info: nil)
531
+ context = context.handle if context.kind_of? CLUContext
502
532
  errcode_ret_buf = ' ' * 4
503
533
 
504
534
  mem = OpenCL.clCreateFromGLRenderBuffer(context, flags, renderbuffer, errcode_ret_buf)
@@ -524,11 +554,15 @@ class CLUMemory
524
554
  return OpenCL.clRetainMemObject(mem)
525
555
  end
526
556
 
557
+ alias_method :retain, :retainMemObject
558
+
527
559
  # cl_mem : mem
528
560
  def releaseMemObject(mem: @mem)
529
561
  return OpenCL.clReleaseMemObject(mem)
530
562
  end
531
563
 
564
+ alias_method :release, :releaseMemObject
565
+
532
566
  # cl_mem : memobj
533
567
  # cl_mem_info : param_name
534
568
  def getMemObjectInfo(param_name, memobj: @mem, error_info: nil)
@@ -661,10 +695,15 @@ class CLUCommandQueue
661
695
  @command_queue = nil # cl_command_queue
662
696
  end
663
697
 
698
+ def handle
699
+ @command_queue
700
+ end
701
+
664
702
  # cl_context : context
665
703
  # cl_device_id : device
666
704
  # cl_command_queue_properties : properties
667
705
  def createCommandQueue(context, device, properties = 0, error_info: nil)
706
+ context = context.handle if context.kind_of? CLUContext
668
707
  errcode_ret_buf = ' ' * 4
669
708
 
670
709
  cl_cq = OpenCL.clCreateCommandQueue(context, device, properties, errcode_ret_buf)
@@ -690,11 +729,15 @@ class CLUCommandQueue
690
729
  return OpenCL.clRetainCommandQueue(command_queue)
691
730
  end
692
731
 
732
+ alias_method :retain, :retainCommandQueue
733
+
693
734
  # cl_command_queue : command_queue
694
735
  def releaseCommandQueue(command_queue: @command_queue)
695
736
  return OpenCL.clReleaseCommandQueue(command_queue)
696
737
  end
697
738
 
739
+ alias_method :release, :releaseCommandQueue
740
+
698
741
  # cl_command_queue : command_queue
699
742
  def flush(command_queue: @command_queue)
700
743
  return OpenCL.clFlush(command_queue)
@@ -740,6 +783,7 @@ class CLUCommandQueue
740
783
  # const cl_event * : event_wait_list
741
784
  # cl_event * : event
742
785
  def enqueueReadBuffer(buffer, blocking_read, offset, size, ptr, command_queue: @command_queue, event_wait_list: nil, event: nil, error_info: nil)
786
+ buffer = buffer.handle if buffer.kind_of? CLUMemory
743
787
  event_buf = event == nil ? nil : ' ' * 8
744
788
  num_events_in_wait_list = event_wait_list == nil ? 0 : event_wait_list.length
745
789
 
@@ -759,6 +803,7 @@ class CLUCommandQueue
759
803
  # const cl_event * : event_wait_list
760
804
  # cl_event * : event
761
805
  def enqueueWriteBuffer(buffer, blocking_write, offset, size, ptr, command_queue: @command_queue, event_wait_list: nil, event: nil, error_info: nil)
806
+ buffer = buffer.handle if buffer.kind_of? CLUMemory
762
807
  event_buf = event == nil ? nil : ' ' * 8
763
808
  num_events_in_wait_list = event_wait_list == nil ? 0 : event_wait_list.length
764
809
 
@@ -777,6 +822,7 @@ class CLUCommandQueue
777
822
  # const cl_event * : event_wait_list
778
823
  # cl_event * : event
779
824
  def enqueueFillBuffer(buffer, pattern, offset, size, command_queue: @command_queue, event_wait_list: nil, event: nil, error_info: nil)
825
+ buffer = buffer.handle if buffer.kind_of? CLUMemory
780
826
  event_buf = event == nil ? nil : ' ' * 8
781
827
  num_events_in_wait_list = event_wait_list == nil ? 0 : event_wait_list.length
782
828
  # size_t : pattern_size
@@ -798,6 +844,8 @@ class CLUCommandQueue
798
844
  # const cl_event * : event_wait_list
799
845
  # cl_event * : event
800
846
  def enqueueCopyBuffer(src_buffer, dst_buffer, src_offset, dst_offset, size, command_queue: @command_queue, event_wait_list: nil, event: nil, error_info: nil)
847
+ src_buffer = src_buffer.handle if src_buffer.kind_of? CLUMemory
848
+ dst_buffer = dst_buffer.handle if dst_buffer.kind_of? CLUMemory
801
849
  event_buf = event == nil ? nil : ' ' * 8
802
850
  num_events_in_wait_list = event_wait_list == nil ? 0 : event_wait_list.length
803
851
 
@@ -819,6 +867,7 @@ class CLUCommandQueue
819
867
  # const cl_event * : event_wait_list
820
868
  # cl_event * : event
821
869
  def enqueueReadImage(image, blocking_read, origin, region, row_pitch, slice_pitch, ptr, command_queue: @command_queue, event_wait_list: nil, event: nil, error_info: nil)
870
+ image = image.handle if image.kind_of? CLUMemory
822
871
  event_buf = event == nil ? nil : ' ' * 8
823
872
  num_events_in_wait_list = event_wait_list == nil ? 0 : event_wait_list.length
824
873
 
@@ -840,6 +889,7 @@ class CLUCommandQueue
840
889
  # const cl_event * : event_wait_list
841
890
  # cl_event * : event
842
891
  def enqueueWriteImage(image, blocking_write, origin, region, row_pitch, slice_pitch, ptr, command_queue: @command_queue, event_wait_list: nil, event: nil, error_info: nil)
892
+ image = image.handle if image.kind_of? CLUMemory
843
893
  event_buf = event == nil ? nil : ' ' * 8
844
894
  num_events_in_wait_list = event_wait_list == nil ? 0 : event_wait_list.length
845
895
 
@@ -858,6 +908,7 @@ class CLUCommandQueue
858
908
  # const cl_event * : event_wait_list
859
909
  # cl_event * : event
860
910
  def enqueueFillImage(image, fill_color, origin, region, command_queue: @command_queue, event_wait_list: nil, event: nil, error_info: nil)
911
+ image = image.handle if image.kind_of? CLUMemory
861
912
  event_buf = event == nil ? nil : ' ' * 8
862
913
  num_events_in_wait_list = event_wait_list == nil ? 0 : event_wait_list.length
863
914
 
@@ -877,6 +928,8 @@ class CLUCommandQueue
877
928
  # const cl_event * : event_wait_list
878
929
  # cl_event * : event
879
930
  def enqueueCopyImage(src_image, dst_image, src_origin, dst_origin, region, command_queue: @command_queue, event_wait_list: nil, event: nil, error_info: nil)
931
+ src_image = src_image.handle if src_image.kind_of? CLUMemory
932
+ dst_image = dst_image.handle if dst_image.kind_of? CLUMemory
880
933
  event_buf = event == nil ? nil : ' ' * 8
881
934
  num_events_in_wait_list = event_wait_list == nil ? 0 : event_wait_list.length
882
935
 
@@ -896,6 +949,8 @@ class CLUCommandQueue
896
949
  # const cl_event * : event_wait_list
897
950
  # cl_event * : event
898
951
  def enqueueCopyImageToBuffer(src_image, dst_buffer, src_origin, region, dst_offset, command_queue: @command_queue, event_wait_list: nil, event: nil, error_info: nil)
952
+ src_image = src_image.handle if src_image.kind_of? CLUMemory
953
+ dst_buffer = dst_buffer.handle if dst_buffer.kind_of? CLUMemory
899
954
  event_buf = event == nil ? nil : ' ' * 8
900
955
  num_events_in_wait_list = event_wait_list == nil ? 0 : event_wait_list.length
901
956
 
@@ -915,6 +970,8 @@ class CLUCommandQueue
915
970
  # const cl_event * : event_wait_list
916
971
  # cl_event * : event
917
972
  def enqueueCopyBufferToImage(src_buffer, dst_image, src_offset, dst_origin, region, command_queue: @command_queue, event_wait_list: nil, event: nil, error_info: nil)
973
+ src_buffer = src_buffer.handle if src_buffer.kind_of? CLUMemory
974
+ dst_image = dst_image.handle if dst_image.kind_of? CLUMemory
918
975
  event_buf = event == nil ? nil : ' ' * 8
919
976
  num_events_in_wait_list = event_wait_list == nil ? 0 : event_wait_list.length
920
977
 
@@ -934,6 +991,7 @@ class CLUCommandQueue
934
991
  # const cl_event * : event_wait_list
935
992
  # cl_event * : event
936
993
  def enqueueMapBuffer(buffer, blocking_map, map_flags, offset, size, command_queue: @command_queue, event_wait_list: nil, event: nil, error_info: nil)
994
+ buffer = buffer.handle if buffer.kind_of? CLUMemory
937
995
  event_buf = event == nil ? nil : ' ' * 8
938
996
  num_events_in_wait_list = event_wait_list == nil ? 0 : event_wait_list.length
939
997
  errcode_ret_buf = ' ' * 4
@@ -959,6 +1017,7 @@ class CLUCommandQueue
959
1017
  # const cl_event * : event_wait_list
960
1018
  # cl_event * : event
961
1019
  def enqueueMapImage(buffer, blocking_map, map_flags, origin, region, command_queue: @command_queue, event_wait_list: nil, event: nil, error_info: nil)
1020
+ buffer = buffer.handle if buffer.kind_of? CLUMemory
962
1021
  event_buf = event == nil ? nil : ' ' * 8
963
1022
  num_events_in_wait_list = event_wait_list == nil ? 0 : event_wait_list.length
964
1023
  errcode_ret_buf = ' ' * 4
@@ -987,6 +1046,7 @@ class CLUCommandQueue
987
1046
  # const cl_event * : event_wait_list
988
1047
  # cl_event * : event
989
1048
  def enqueueUnmapMemObject(memobj, mapped_ptr, command_queue: @command_queue, event_wait_list: nil, event: nil, error_info: nil)
1049
+ memobj = memobj.handle if memobj.kind_of? CLUMemory
990
1050
  event_buf = event == nil ? nil : ' ' * 8
991
1051
  num_events_in_wait_list = event_wait_list == nil ? 0 : event_wait_list.length
992
1052
 
@@ -1006,6 +1066,7 @@ class CLUCommandQueue
1006
1066
  # const cl_event * : event_wait_list
1007
1067
  # cl_event * : event
1008
1068
  def enqueueNDRangeKernel(kernel, work_dim, global_work_offset, global_work_size, local_work_size, command_queue: @command_queue, event_wait_list: nil, event: nil, error_info: nil)
1069
+ kernel = kernel.handle if kernel.kind_of? CLUKernel
1009
1070
  event_buf = event == nil ? nil : ' ' * 8
1010
1071
  num_events_in_wait_list = event_wait_list == nil ? 0 : event_wait_list.length
1011
1072
 
@@ -1024,6 +1085,7 @@ class CLUCommandQueue
1024
1085
  # const cl_event * : event_wait_list
1025
1086
  # cl_event * : event
1026
1087
  def enqueueTask(kernel, command_queue: @command_queue, event_wait_list: nil, event: nil, error_info: nil)
1088
+ kernel = kernel.handle if kernel.kind_of? CLUKernel
1027
1089
  event_buf = event == nil ? nil : ' ' * 8
1028
1090
  num_events_in_wait_list = event_wait_list == nil ? 0 : event_wait_list.length
1029
1091
 
@@ -1039,6 +1101,7 @@ class CLUCommandQueue
1039
1101
  # const cl_event * : event_wait_list
1040
1102
  # cl_event * : event
1041
1103
  def enqueueAcquireGLObjects(mem_objects, command_queue: @command_queue, event_wait_list: nil, event: nil, error_info: nil)
1104
+ mem_objects.collect! {|mem_object| mem_object.kind_of?(CLUMemory) ? mem_object.mem.to_i : mem_object}
1042
1105
  event_buf = event == nil ? nil : ' ' * 8
1043
1106
  num_events_in_wait_list = event_wait_list == nil ? 0 : event_wait_list.length
1044
1107
 
@@ -1054,6 +1117,7 @@ class CLUCommandQueue
1054
1117
  # const cl_event * : event_wait_list
1055
1118
  # cl_event * : event
1056
1119
  def enqueueReleaseGLObjects(mem_objects, command_queue: @command_queue, event_wait_list: nil, event: nil, error_info: nil)
1120
+ mem_objects.collect! {|mem_object| mem_object.kind_of?(CLUMemory) ? mem_object.mem.to_i : mem_object}
1057
1121
  event_buf = event == nil ? nil : ' ' * 8
1058
1122
  num_events_in_wait_list = event_wait_list == nil ? 0 : event_wait_list.length
1059
1123
 
@@ -1074,9 +1138,15 @@ class CLUProgram
1074
1138
  @program = nil
1075
1139
  end
1076
1140
 
1141
+ def handle
1142
+ @program
1143
+ end
1144
+
1077
1145
  # cl_context : context
1078
1146
  # const char ** : strings
1079
1147
  def createProgramWithSource(context, strings, error_info: nil)
1148
+ context = context.handle if context.kind_of? CLUContext
1149
+
1080
1150
  # cl_uint : count
1081
1151
  # const size_t * : lengths
1082
1152
  # cl_int * : errcode_ret
@@ -1107,11 +1177,15 @@ class CLUProgram
1107
1177
  return OpenCL.clRetainProgram(program)
1108
1178
  end
1109
1179
 
1180
+ alias_method :retain, :retainProgram
1181
+
1110
1182
  # cl_program : program
1111
1183
  def releaseProgram(program: @program)
1112
1184
  return OpenCL.clReleaseProgram(program)
1113
1185
  end
1114
1186
 
1187
+ alias_method :release, :releaseProgram
1188
+
1115
1189
  # cl_program : program
1116
1190
  # const cl_device_id * : device_list
1117
1191
  # const char * : options
@@ -1122,13 +1196,15 @@ class CLUProgram
1122
1196
  err = OpenCL.clBuildProgram(program, num_devices, device_list.pack("Q*"), options, pfn_notify, user_data)
1123
1197
 
1124
1198
  if err < 0 && error_info != nil
1125
- log_size_buf = ' ' * 4
1126
- OpenCL.clGetProgramBuildInfo(program, device_list[0], OpenCL::CL_PROGRAM_BUILD_LOG, 0, nil, log_size_buf)
1127
- log_size = log_size_buf.unpack("L")[0]
1128
- program_log = ' ' * log_size
1129
- OpenCL.clGetProgramBuildInfo(program, device_list[0], OpenCL::CL_PROGRAM_BUILD_LOG, log_size, program_log, nil)
1130
-
1131
- error_info << program_log
1199
+ num_devices.times do |i|
1200
+ log_size_buf = ' ' * 4
1201
+ OpenCL.clGetProgramBuildInfo(program, device_list[0], OpenCL::CL_PROGRAM_BUILD_LOG, 0, nil, log_size_buf)
1202
+ log_size = log_size_buf.unpack("L")[0]
1203
+ program_log = ' ' * log_size
1204
+ OpenCL.clGetProgramBuildInfo(program, device_list[0], OpenCL::CL_PROGRAM_BUILD_LOG, log_size, program_log, nil)
1205
+
1206
+ error_info << program_log
1207
+ end
1132
1208
  end
1133
1209
 
1134
1210
  return err
@@ -1145,9 +1221,14 @@ class CLUKernel
1145
1221
  @name = nil
1146
1222
  end
1147
1223
 
1224
+ def handle
1225
+ @kernel
1226
+ end
1227
+
1148
1228
  # cl_program : program
1149
1229
  # const char * : kernel_name
1150
1230
  def createKernel(program, kernel_name, error_info: nil)
1231
+ program = program.handle if program.kind_of? CLUProgram
1151
1232
  errcode_ret_buf = ' ' * 4
1152
1233
  kernel = OpenCL.clCreateKernel(program, kernel_name, errcode_ret_buf)
1153
1234
  errcode_ret = errcode_ret_buf.unpack("l")[0]
@@ -1206,11 +1287,15 @@ class CLUKernel
1206
1287
  return OpenCL.clRetainKernel(kernel)
1207
1288
  end
1208
1289
 
1290
+ alias_method :retain, :retainKernel
1291
+
1209
1292
  # cl_kernel : kernel
1210
1293
  def releaseKernel(kernel: @kernel)
1211
1294
  return OpenCL.clReleaseKernel(kernel)
1212
1295
  end
1213
1296
 
1297
+ alias_method :release, :releaseKernel
1298
+
1214
1299
  def sizeof_type(fiddle_type)
1215
1300
  size = 0
1216
1301
 
@@ -1316,9 +1401,19 @@ class CLUKernel
1316
1401
  def setKernelArg(arg_index, arg_type, arg_value, kernel: @kernel)
1317
1402
  num_elements = arg_value.length
1318
1403
  arg_size = sizeof_type(arg_type) * num_elements
1319
- pack_arg = pack_format(arg_type) + num_elements.to_s
1404
+ packed_arg_value = nil
1405
+ if arg_value != nil
1406
+ pack_arg = pack_format(arg_type) + num_elements.to_s
1407
+ packed_arg_value = arg_value.pack(pack_arg)
1408
+ end
1409
+ return OpenCL.clSetKernelArg(kernel, arg_index, arg_size, packed_arg_value)
1410
+ end
1320
1411
 
1321
- return OpenCL.clSetKernelArg(kernel, arg_index, arg_size, arg_value.pack(pack_arg))
1412
+ # cl_kernel : kernel
1413
+ # cl_uint : arg_index
1414
+ # size_t : arg_size
1415
+ def setLocalKernelArg(arg_index, arg_size, kernel: @kernel)
1416
+ return OpenCL.clSetKernelArg(kernel, arg_index, arg_size, nil)
1322
1417
  end
1323
1418
 
1324
1419
  # cl_kernel : kernel
@@ -1332,6 +1427,12 @@ class CLUKernel
1332
1427
  param_value_buf = ' ' * param_value_buf_length
1333
1428
  param_value_size_ret_buf = ' ' * 4
1334
1429
 
1430
+ # Ref.: https://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clGetKernelArgInfo.html
1431
+ #
1432
+ # Notes : Kernel argument information is only available if the program
1433
+ # object associated with kernel is created with clCreateProgramWithSource
1434
+ # and the program executable is built with the -cl-kernel-arg-info option
1435
+ # specified in options argument to clBuildProgram or clCompileProgram.
1335
1436
  err = OpenCL.clGetKernelArgInfo(kernel, arg_index, param_name, param_value_buf_length, param_value_buf, param_value_size_ret_buf)
1336
1437
  error_info << err if error_info != nil
1337
1438
  param_value_size_ret = param_value_size_ret_buf.unpack("L")[0]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opencl-bindings
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0pre
4
+ version: 1.0.0pre2
5
5
  platform: ruby
6
6
  authors:
7
7
  - vaiorabbit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-21 00:00:00.000000000 Z
11
+ date: 2015-11-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  Ruby bindings for OpenCL 1.2 using Fiddle (For MRI >= 2.0.0).
@@ -28,6 +28,7 @@ files:
28
28
  - sample/hello.cl
29
29
  - sample/hello.rb
30
30
  - sample/hello_clu.rb
31
+ - sample/report_env.rb
31
32
  - sample/util/clu.rb
32
33
  homepage: https://github.com/vaiorabbit/ruby-opencl
33
34
  licenses: