opencl_ruby_ffi 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +22 -0
- data/lib/opencl_ruby_ffi.rb +18 -0
- data/lib/opencl_ruby_ffi/Arithmetic_gen.rb +3566 -0
- data/lib/opencl_ruby_ffi/Buffer.rb +84 -0
- data/lib/opencl_ruby_ffi/CommandQueue.rb +1544 -0
- data/lib/opencl_ruby_ffi/Context.rb +326 -0
- data/lib/opencl_ruby_ffi/Device.rb +188 -0
- data/lib/opencl_ruby_ffi/Event.rb +152 -0
- data/lib/opencl_ruby_ffi/Image.rb +270 -0
- data/lib/opencl_ruby_ffi/Kernel.rb +183 -0
- data/lib/opencl_ruby_ffi/Mem.rb +131 -0
- data/lib/opencl_ruby_ffi/Platform.rb +119 -0
- data/lib/opencl_ruby_ffi/Program.rb +245 -0
- data/lib/opencl_ruby_ffi/Sampler.rb +51 -0
- data/lib/opencl_ruby_ffi/opencl_ruby_ffi_base.rb +320 -0
- data/lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb +1826 -0
- data/opencl_ruby_ffi.gemspec +16 -0
- metadata +110 -0
@@ -0,0 +1,326 @@
|
|
1
|
+
module OpenCL
|
2
|
+
|
3
|
+
# Creates an Context using the specified devices
|
4
|
+
#
|
5
|
+
# ==== Attributes
|
6
|
+
#
|
7
|
+
# * +devices+ - array of Device or a single Device
|
8
|
+
# * +options+ - a hash containing named options
|
9
|
+
# * +block+ - if provided, a callback invoked when error arise in the context. Signature of the callback is { |FFI::Pointer to null terminated c string, FFI::Pointer to binary data, :size_t number of bytes of binary data, FFI::Pointer to user_data| ... }
|
10
|
+
#
|
11
|
+
# ==== Options
|
12
|
+
#
|
13
|
+
# * +:properties+ - a list of :cl_context_properties
|
14
|
+
# * +:user_data+ - an FFI::Pointer or an object that can be converted into one using to_ptr. The pointer is passed to the callback.
|
15
|
+
def self.create_context(devices, options = {}, &block)
|
16
|
+
@@callbacks.push( block ) if block
|
17
|
+
pointer = FFI::MemoryPointer.new( Device, devices.size)
|
18
|
+
devices.size.times { |indx|
|
19
|
+
pointer.put_pointer(indx, devices[indx])
|
20
|
+
}
|
21
|
+
properties = OpenCL.get_context_properties( options )
|
22
|
+
user_data = options[:user_data]
|
23
|
+
error = FFI::MemoryPointer.new( :cl_int )
|
24
|
+
ptr = OpenCL.clCreateContext(properties, devices.size, pointer, block, user_data, error)
|
25
|
+
OpenCL.error_check(error.read_cl_int)
|
26
|
+
return OpenCL::Context::new(ptr, false)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Creates an Context using devices of the selected type
|
30
|
+
#
|
31
|
+
# ==== Attributes
|
32
|
+
#
|
33
|
+
# * +type+ - array of Device or a single Device
|
34
|
+
# * +options+ - a hash containing named options
|
35
|
+
# * +block+ - if provided, a callback invoked when error arise in the context. Signature of the callback is { |FFI::Pointer to null terminated c string, FFI::Pointer to binary data, :size_t number of bytes of binary data, FFI::Pointer to user_data| ... }
|
36
|
+
#
|
37
|
+
# ==== Options
|
38
|
+
#
|
39
|
+
# * +:properties+ - a list of :cl_context_properties
|
40
|
+
# * +:user_data+ - an FFI::Pointer or an object that can be converted into one using to_ptr. The pointer is passed to the callback.
|
41
|
+
def self.create_context_from_type(type, options = {}, &block)
|
42
|
+
@@callbacks.push( block ) if block
|
43
|
+
properties = OpenCL.get_context_properties( options )
|
44
|
+
user_data = options[:user_data]
|
45
|
+
error = FFI::MemoryPointer.new( :cl_int )
|
46
|
+
ptr = OpenCL.clCreateContextFromType(properties, type, block, user_data, error)
|
47
|
+
OpenCL.error_check(error.read_cl_int)
|
48
|
+
return OpenCL::Context::new(ptr, false)
|
49
|
+
end
|
50
|
+
|
51
|
+
#Maps the cl_context object of OpenCL
|
52
|
+
class Context
|
53
|
+
|
54
|
+
##
|
55
|
+
# :method: reference_count
|
56
|
+
# Returns the reference count of the Context
|
57
|
+
%w( REFERENCE_COUNT ).each { |prop|
|
58
|
+
eval OpenCL.get_info("Context", :cl_uint, prop)
|
59
|
+
}
|
60
|
+
|
61
|
+
##
|
62
|
+
# :method: properties
|
63
|
+
# the Array of :cl_context_properties used to create the Context
|
64
|
+
eval OpenCL.get_info_array("Context", :cl_context_properties, "PROPERTIES")
|
65
|
+
|
66
|
+
# Returns the platform associated to the Context
|
67
|
+
def platform
|
68
|
+
self.devices.first.platform
|
69
|
+
end
|
70
|
+
|
71
|
+
# Returns the number of devices associated to the Context
|
72
|
+
def num_devices
|
73
|
+
d_n = 0
|
74
|
+
ptr = FFI::MemoryPointer.new( :size_t )
|
75
|
+
error = OpenCL.clGetContextInfo(self, Context::DEVICES, 0, nil, ptr)
|
76
|
+
OpenCL.error_check(error)
|
77
|
+
d_n = ptr.read_size_t / Platform.size
|
78
|
+
# else
|
79
|
+
# ptr = FFI::MemoryPointer.new( :cl_uint )
|
80
|
+
# error = OpenCL.clGetContextInfo(self, Context::NUM_DEVICES, ptr.size, ptr, nil)
|
81
|
+
# OpenCL.error_check(error)
|
82
|
+
# d_n = ptr.read_cl_uint
|
83
|
+
# end
|
84
|
+
return d_n
|
85
|
+
end
|
86
|
+
|
87
|
+
# Returns an Array of Device associated to the Context
|
88
|
+
def devices
|
89
|
+
n = self.num_devices
|
90
|
+
ptr2 = FFI::MemoryPointer.new( Device, n )
|
91
|
+
error = OpenCL.clGetContextInfo(self, Context::DEVICES, Device.size*n, ptr2, nil)
|
92
|
+
OpenCL.error_check(error)
|
93
|
+
return ptr2.get_array_of_pointer(0, n).collect { |device_ptr|
|
94
|
+
OpenCL::Device.new(device_ptr)
|
95
|
+
}
|
96
|
+
end
|
97
|
+
|
98
|
+
# Returns an Array of ImageFormat that are supported for a given image type in the Context
|
99
|
+
#
|
100
|
+
# ==== Attributes
|
101
|
+
# * +image_type+ - a :cl_mem_object_type specifying the type of Image being queried
|
102
|
+
# * +options+ - a hash containing named options
|
103
|
+
#
|
104
|
+
# ==== Options
|
105
|
+
#
|
106
|
+
# * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Buffer
|
107
|
+
def supported_image_formats( image_type, options = {} )
|
108
|
+
flags = OpenCL.get_flags( options )
|
109
|
+
num_image_formats = FFI::MemoryPointer.new( :cl_uint )
|
110
|
+
error = OpenCL.clGetSupportedImageFormats( self, flags, image_type, 0, nil, num_image_formats )
|
111
|
+
OpenCL.error_check(error)
|
112
|
+
num_entries = num_image_formats.read_cl_uint
|
113
|
+
image_formats = FFI::MemoryPointer.new( ImageFormat, num_entries )
|
114
|
+
error = OpenCL.clGetSupportedImageFormats( self, flags, image_type, num_entries, image_formats, nil )
|
115
|
+
OpenCL.error_check(error)
|
116
|
+
return num_entries.times.collect { |i|
|
117
|
+
OpenCL::ImageFormat::from_pointer( image_formats + i * ImageFormat.size )
|
118
|
+
}
|
119
|
+
end
|
120
|
+
|
121
|
+
# Creates a CommandQueue in Context targeting the specified Device
|
122
|
+
#
|
123
|
+
# ==== Attributes
|
124
|
+
#
|
125
|
+
# * +device+ - the Device targetted by the CommandQueue being created
|
126
|
+
# * +options+ - a hash containing named options
|
127
|
+
#
|
128
|
+
# ==== Options
|
129
|
+
#
|
130
|
+
# * +:properties+ - a single or an Array of :cl_command_queue_properties
|
131
|
+
def create_command_queue( device, options = {} )
|
132
|
+
return OpenCL.create_command_queue( self, device, options )
|
133
|
+
end
|
134
|
+
|
135
|
+
# Creates a Buffer in the Context
|
136
|
+
#
|
137
|
+
# ==== Attributes
|
138
|
+
#
|
139
|
+
# * +size+ - size of the Buffer to be created
|
140
|
+
# * +options+ - a hash containing named options
|
141
|
+
#
|
142
|
+
# ==== Options
|
143
|
+
#
|
144
|
+
# * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Buffer
|
145
|
+
# * +:host_ptr+ - if provided, the Pointer (or convertible to Pointer using to_ptr) to the memory area to use
|
146
|
+
def create_buffer( size, options = {} )
|
147
|
+
return OpenCL.create_buffer( self, size, options )
|
148
|
+
end
|
149
|
+
|
150
|
+
# Creates a Buffer in the Context from an opengl buffer
|
151
|
+
#
|
152
|
+
# ==== Attributes
|
153
|
+
#
|
154
|
+
# * +bufobj+ - opengl buffer object
|
155
|
+
# * +options+ - a hash containing named options
|
156
|
+
#
|
157
|
+
# ==== Options
|
158
|
+
#
|
159
|
+
# * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Image
|
160
|
+
def create_from_GL_buffer( bufobj, options = {} )
|
161
|
+
return OpenCL.create_from_GL_buffer( self, bufobj, options )
|
162
|
+
end
|
163
|
+
|
164
|
+
# Creates an Image in the Context from an OpenGL render buffer
|
165
|
+
#
|
166
|
+
# ==== Attributes
|
167
|
+
#
|
168
|
+
# * +renderbuf+ - opengl render buffer
|
169
|
+
# * +options+ - a hash containing named options
|
170
|
+
#
|
171
|
+
# ==== Options
|
172
|
+
#
|
173
|
+
# * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Image
|
174
|
+
def create_from_GL_render_buffer( renderbuffer, options = {} )
|
175
|
+
return OpenCL.create_from_GL_render_buffer( self, renderbuffer, options )
|
176
|
+
end
|
177
|
+
|
178
|
+
# Creates an Image in the Context from an OpenGL texture
|
179
|
+
#
|
180
|
+
# ==== Attributes
|
181
|
+
#
|
182
|
+
# * +texture_target+ - a :GLenum defining the image type of texture
|
183
|
+
# * +texture+ - a :GLuint specifying the name of the texture
|
184
|
+
# * +options+ - a hash containing named options
|
185
|
+
#
|
186
|
+
# ==== Options
|
187
|
+
#
|
188
|
+
# * +:miplevel+ - a :GLint specifying the mipmap level to be used (default 0)
|
189
|
+
# * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Image
|
190
|
+
def create_from_GL_texture( texture_target, texture, options = {} )
|
191
|
+
return OpenCL.create_from_GL_texture( self, texture_target, texture, options )
|
192
|
+
end
|
193
|
+
|
194
|
+
# Creates an Image in the Context from an OpenGL 2D texture
|
195
|
+
#
|
196
|
+
# ==== Attributes
|
197
|
+
#
|
198
|
+
# * +texture_target+ - a :GLenum defining the image type of texture
|
199
|
+
# * +texture+ - a :GLuint specifying the name of the texture
|
200
|
+
# * +options+ - a hash containing named options
|
201
|
+
#
|
202
|
+
# ==== Options
|
203
|
+
#
|
204
|
+
# * +:miplevel+ - a :GLint specifying the mipmap level to be used (default 0)
|
205
|
+
# * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Image
|
206
|
+
def create_from_GL_texture_2D( texture_target, texture, options = {} )
|
207
|
+
return OpenCL.create_from_GL_texture_2D( self, texture_target, texture, options = {} )
|
208
|
+
end
|
209
|
+
|
210
|
+
# Creates an Image in the Context from an OpenGL 3D texture
|
211
|
+
#
|
212
|
+
# ==== Attributes
|
213
|
+
#
|
214
|
+
# * +texture_target+ - a :GLenum defining the image type of texture
|
215
|
+
# * +texture+ - a :GLuint specifying the name of the texture
|
216
|
+
# * +options+ - a hash containing named options
|
217
|
+
#
|
218
|
+
# ==== Options
|
219
|
+
#
|
220
|
+
# * +:miplevel+ - a :GLint specifying the mipmap level to be used (default 0)
|
221
|
+
# * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Image
|
222
|
+
def create_from_GL_texture_3D( texture_target, texture, options = {} )
|
223
|
+
return OpenCL.create_from_GL_texture_3D( self, texture_target, texture, options )
|
224
|
+
end
|
225
|
+
|
226
|
+
# Creates an Image in the Context
|
227
|
+
#
|
228
|
+
# ==== Attributes
|
229
|
+
#
|
230
|
+
# * +format+ - an ImageFormat
|
231
|
+
# * +options+ - an ImageDesc
|
232
|
+
#
|
233
|
+
# ==== Options
|
234
|
+
#
|
235
|
+
# * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Buffer
|
236
|
+
# * +:host_ptr+ - if provided, the Pointer (or convertible to Pointer using to_ptr) to the memory area to use
|
237
|
+
def create_image( format, desc, options = {} )
|
238
|
+
return OpenCL.create_image( self, format, desc, options )
|
239
|
+
end
|
240
|
+
|
241
|
+
# Creates a 1D Image in the Context
|
242
|
+
#
|
243
|
+
# ==== Attributes
|
244
|
+
#
|
245
|
+
# * +format+ - an ImageFormat
|
246
|
+
# * +width+ - width of the image
|
247
|
+
#
|
248
|
+
# ==== Options
|
249
|
+
#
|
250
|
+
# * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Buffer
|
251
|
+
# * +:host_ptr+ - if provided, the Pointer (or convertible to Pointer using to_ptr) to the memory area to use
|
252
|
+
def create_image_1D( format, width, options = {} )
|
253
|
+
return OpenCL.create_image_1D( self, format, width, options )
|
254
|
+
end
|
255
|
+
|
256
|
+
# Creates a 2D Image in the Context
|
257
|
+
#
|
258
|
+
# ==== Attributes
|
259
|
+
#
|
260
|
+
# * +format+ - an ImageFormat
|
261
|
+
# * +width+ - width of the image
|
262
|
+
#
|
263
|
+
# ==== Options
|
264
|
+
#
|
265
|
+
# * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Buffer
|
266
|
+
# * +:host_ptr+ - if provided, the Pointer (or convertible to Pointer using to_ptr) to the memory area to use
|
267
|
+
# * +:row_pitch+ - if provided the row_pitch of data in host_ptr
|
268
|
+
def create_image_2D( format, width, height, options = {} )
|
269
|
+
return OpenCL.create_image_2D( self, format, width, height, options )
|
270
|
+
end
|
271
|
+
|
272
|
+
# Creates a 3D Image in the Context
|
273
|
+
#
|
274
|
+
# ==== Attributes
|
275
|
+
#
|
276
|
+
# * +format+ - an ImageFormat
|
277
|
+
# * +width+ - width of the image
|
278
|
+
#
|
279
|
+
# ==== Options
|
280
|
+
#
|
281
|
+
# * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Buffer
|
282
|
+
# * +:host_ptr+ - if provided, the Pointer (or convertible to Pointer using to_ptr) to the memory area to use
|
283
|
+
# * +:row_pitch+ - if provided the row_pitch of data in host_ptr
|
284
|
+
# * +:slice_pitch+ - if provided the slice_pitch of data in host_ptr
|
285
|
+
def create_image_3D( format, width, height, depth, options = {} )
|
286
|
+
return OpenCL.create_image_3D( self, format, width, height, depth, options )
|
287
|
+
end
|
288
|
+
|
289
|
+
# Creates an Event in the Context from a GL sync
|
290
|
+
#
|
291
|
+
# ==== Attributes
|
292
|
+
#
|
293
|
+
# * +sync+ - a :GLsync representing the name of the sync object
|
294
|
+
def create_event_from_GL_sync_KHR( sync )
|
295
|
+
return OpenCL.create_event_from_GL_sync_KHR( self, sync )
|
296
|
+
end
|
297
|
+
|
298
|
+
|
299
|
+
# Creates a user Event in the Context
|
300
|
+
def create_user_event
|
301
|
+
return OpenCL.create_user_event(self)
|
302
|
+
end
|
303
|
+
|
304
|
+
# Creates a Program from sources in the Context
|
305
|
+
#
|
306
|
+
# ==== Attributes
|
307
|
+
#
|
308
|
+
# * +strings+ - a single or an Array of String repesenting the program source code
|
309
|
+
def create_program_with_source( strings )
|
310
|
+
return OpenCL.create_program_with_source(self, strings)
|
311
|
+
end
|
312
|
+
|
313
|
+
# Creates a Sampler in the Context
|
314
|
+
#
|
315
|
+
# ==== Attributes
|
316
|
+
#
|
317
|
+
# * +normalized_coords+ - a :cl_bool specifying if the image coordinates are normalized
|
318
|
+
# * +addressing_mode+ - a :cl_addressing_mode specifying how out-of-range image coordinates are handled when reading from an image
|
319
|
+
# * +filter_mode+ - a :cl_filter_mode specifying the type of filter that must be applied when reading an image
|
320
|
+
def create_sampler( normalized_coords, addressing_mode, filter_mode )
|
321
|
+
return OpenCL.create_sampler( self, normalized_coords, addressing_mode, filter_mode )
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
end
|
326
|
+
|
@@ -0,0 +1,188 @@
|
|
1
|
+
module OpenCL
|
2
|
+
|
3
|
+
# Splits a Device in serveral sub-devices
|
4
|
+
#
|
5
|
+
# ==== Attributes
|
6
|
+
#
|
7
|
+
# * +in_device+ - the Device to be partitioned
|
8
|
+
# * +properties+ - an Array of cl_device_partition_property
|
9
|
+
#
|
10
|
+
# ==== Returns
|
11
|
+
#
|
12
|
+
# an Array of Device
|
13
|
+
def self.create_sub_devices( in_device, properties = [OpenCL::Device::PARTITION_BY_AFFINITY_DOMAIN, OpenCL::Device::AFFINITY_DOMAIN_NEXT_PARTITIONABLE] )
|
14
|
+
OpenCL.error_check(OpenCL::INVALID_OPERATION) if in_device.platform.version_number < 1.2
|
15
|
+
props = FFI::MemoryPointer::new( :cl_device_partition_property, properties.length + 1 )
|
16
|
+
properties.each_with_index { |e,i|
|
17
|
+
props[i].write_cl_device_partition_property(e)
|
18
|
+
}
|
19
|
+
props[properties.length].write_cl_device_partition_property(0)
|
20
|
+
device_number_ptr = FFI::MemoryPointer::new( :cl_uint )
|
21
|
+
error = OpenCL.clCreateSubDevice( in_device, props, 0, nil, device_number_ptr )
|
22
|
+
OpenCL.error_check(error)
|
23
|
+
device_number = device_number_ptr.read_cl_uint
|
24
|
+
devices_ptr = FFI::MemoryPointer::new( OpenCL::Device, device_number )
|
25
|
+
error = OpenCL.clCreateSubDevice( in_device, props, device_number, devices_ptr, nil )
|
26
|
+
OpenCL.error_check(error)
|
27
|
+
devices_ptr.get_array_of_pointer(0, device_number).collect { |device_ptr|
|
28
|
+
OpenCL::Device.new(device_ptr, false)
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
# Maps the cl_device_id object of OpenCL
|
33
|
+
class Device
|
34
|
+
|
35
|
+
# :stopdoc:
|
36
|
+
DRIVER_VERSION = 0x102D
|
37
|
+
# :startdoc:
|
38
|
+
|
39
|
+
%w( BUILT_IN_KERNELS DRIVER_VERSION VERSION VENDOR PROFILE OPENCL_C_VERSION NAME EXTENSIONS ).each { |prop|
|
40
|
+
eval OpenCL.get_info("Device", :string, prop)
|
41
|
+
}
|
42
|
+
|
43
|
+
%w( MAX_MEM_ALLOC_SIZE MAX_CONSTANT_BUFFER_SIZE LOCAL_MEM_SIZE GLOBAL_MEM_CACHE_SIZE GLOBAL_MEM_SIZE ).each { |prop|
|
44
|
+
eval OpenCL.get_info("Device", :cl_ulong, prop)
|
45
|
+
}
|
46
|
+
|
47
|
+
%w( IMAGE_PITCH_ALIGNMENT IMAGE_BASE_ADDRESS_ALIGNMENT REFERENCE_COUNT PARTITION_MAX_SUB_DEVICES VENDOR_ID PREFERRED_VECTOR_WIDTH_HALF PREFERRED_VECTOR_WIDTH_CHAR PREFERRED_VECTOR_WIDTH_SHORT PREFERRED_VECTOR_WIDTH_INT PREFERRED_VECTOR_WIDTH_LONG PREFERRED_VECTOR_WIDTH_FLOAT PREFERRED_VECTOR_WIDTH_DOUBLE NATIVE_VECTOR_WIDTH_CHAR NATIVE_VECTOR_WIDTH_SHORT NATIVE_VECTOR_WIDTH_INT NATIVE_VECTOR_WIDTH_LONG NATIVE_VECTOR_WIDTH_FLOAT NATIVE_VECTOR_WIDTH_DOUBLE NATIVE_VECTOR_WIDTH_HALF MIN_DATA_TYPE_ALIGN_SIZE MEM_BASE_ADDR_ALIGN MAX_WRITE_IMAGE_ARGS MAX_WORK_ITEM_DIMENSIONS MAX_SAMPLERS MAX_READ_IMAGE_ARGS MAX_CONSTANT_ARGS MAX_COMPUTE_UNITS MAX_CLOCK_FREQUENCY ADDRESS_BITS GLOBAL_MEM_CACHELINE_SIZE ).each { |prop|
|
48
|
+
eval OpenCL.get_info("Device", :cl_uint, prop)
|
49
|
+
}
|
50
|
+
|
51
|
+
%w( PRINTF_BUFFER_SIZE IMAGE_MAX_BUFFER_SIZE IMAGE_MAX_ARRAY_SIZE PROFILING_TIMER_RESOLUTION MAX_WORK_GROUP_SIZE MAX_PARAMETER_SIZE IMAGE2D_MAX_WIDTH IMAGE2D_MAX_HEIGHT IMAGE3D_MAX_WIDTH IMAGE3D_MAX_HEIGHT IMAGE3D_MAX_DEPTH ).each { |prop|
|
52
|
+
eval OpenCL.get_info("Device", :size_t, prop)
|
53
|
+
}
|
54
|
+
|
55
|
+
%w( PREFERRED_INTEROP_USER_SYNC LINKER_AVAILABLE IMAGE_SUPPORT HOST_UNIFIED_MEMORY COMPILER_AVAILABLE AVAILABLE ENDIAN_LITTLE ERROR_CORRECTION_SUPPORT ).each { |prop|
|
56
|
+
eval OpenCL.get_info("Device", :cl_bool, prop)
|
57
|
+
}
|
58
|
+
|
59
|
+
%w( SINGLE_FP_CONFIG HALF_FP_CONFIG DOUBLE_FP_CONFIG ).each { |prop|
|
60
|
+
eval OpenCL.get_info("Device", :cl_device_fp_config, prop)
|
61
|
+
}
|
62
|
+
|
63
|
+
##
|
64
|
+
# :method: execution_capabilities()
|
65
|
+
# Returns an ExecCpabilities representing the execution capabilities corresponding to the Device
|
66
|
+
eval OpenCL.get_info("Device", :cl_device_exec_capabilities, "EXECUTION_CAPABILITIES")
|
67
|
+
|
68
|
+
##
|
69
|
+
# :method: global_mem_cache_type()
|
70
|
+
# Returns a MemCacheType representing the type of the global cache memory on the Device
|
71
|
+
eval OpenCL.get_info("Device", :cl_device_mem_cache_type, "GLOBAL_MEM_CACHE_TYPE")
|
72
|
+
|
73
|
+
##
|
74
|
+
# :method: local_mem_type()
|
75
|
+
# Returns a LocalMemType rpresenting the type of the local memory on the Device
|
76
|
+
eval OpenCL.get_info("Device", :cl_device_local_mem_type, "LOCAL_MEM_TYPE")
|
77
|
+
|
78
|
+
##
|
79
|
+
# :method: queue_properties()
|
80
|
+
# Returns a CommandQueue::Properties representing the properties supported by a CommandQueue targetting the Device
|
81
|
+
eval OpenCL.get_info("Device", :cl_command_queue_properties, "QUEUE_PROPERTIES")
|
82
|
+
|
83
|
+
##
|
84
|
+
# :method: type()
|
85
|
+
# Returns a Device::Type representing the type of the Device
|
86
|
+
eval OpenCL.get_info("Device", :cl_device_type, "TYPE")
|
87
|
+
|
88
|
+
##
|
89
|
+
# :method: partition_affinity_domain()
|
90
|
+
# Returns an AffinityDomain representing the list of supported affinity domains for partitioning the Device using OpenCL::Device::PARTITION_BY_AFFINITY_DOMAIN
|
91
|
+
eval OpenCL.get_info("Device", :cl_device_affinity_domain, "PARTITION_AFFINITY_DOMAIN")
|
92
|
+
|
93
|
+
##
|
94
|
+
# :method: max_work_item_sizes()
|
95
|
+
# Maximum number of work-items that can be specified in each dimension of the work-group to clEnqueueNDRangeKernel for the Device
|
96
|
+
eval OpenCL.get_info_array("Device", :size_t, "MAX_WORK_ITEM_SIZES")
|
97
|
+
|
98
|
+
##
|
99
|
+
# :method: partition_properties()
|
100
|
+
# Returns the list of partition types supported by the Device
|
101
|
+
eval OpenCL.get_info_array("Device", :cl_device_partition_property, "PARTITION_PROPERTIES")
|
102
|
+
|
103
|
+
# Return an Array of partition properties names representing the partition type supported by the device
|
104
|
+
def partition_properties_names
|
105
|
+
prop_names = []
|
106
|
+
props = self.partition_properties
|
107
|
+
%w( PARTITION_EQUALLY PARTITION_BY_COUNTS PARTITION_BY_AFFINITY_DOMAIN ).each { |prop|
|
108
|
+
prop_names.push(prop) if props.include?(OpenCL::Device.const_get(prop))
|
109
|
+
}
|
110
|
+
end
|
111
|
+
|
112
|
+
##
|
113
|
+
# :method: partition_type()
|
114
|
+
# Returns a list of :cl_device_partition_property used to create the Device
|
115
|
+
eval OpenCL.get_info_array("Device", :cl_device_partition_property, "PARTITION_TYPE")
|
116
|
+
|
117
|
+
# Returns the platform the Device belongs to
|
118
|
+
def platform
|
119
|
+
ptr = FFI::MemoryPointer.new( OpenCL::Platform )
|
120
|
+
error = OpenCL.clGetDeviceInfo(self, Device::PLATFORM, OpenCL::Platform.size, ptr, nil)
|
121
|
+
OpenCL.error_check(error)
|
122
|
+
return OpenCL::Platform.new(ptr.read_pointer)
|
123
|
+
end
|
124
|
+
|
125
|
+
# Returns the parent Device if it exists
|
126
|
+
def parent_device
|
127
|
+
ptr = FFI::MemoryPointer.new( OpenCL::Device )
|
128
|
+
error = OpenCL.clGetDeviceInfo(self, Device::PARENT_DEVICE, OpenCL::Device.size, ptr, nil)
|
129
|
+
OpenCL.error_check(error)
|
130
|
+
return nil if ptr.null?
|
131
|
+
return OpenCL::Device.new(ptr.read_pointer)
|
132
|
+
end
|
133
|
+
|
134
|
+
# Partitions the Device in serveral sub-devices
|
135
|
+
#
|
136
|
+
# ==== Attributes
|
137
|
+
#
|
138
|
+
# * +properties+ - an Array of :cl_device_partition_property
|
139
|
+
#
|
140
|
+
# ==== Returns
|
141
|
+
#
|
142
|
+
# an Array of Device
|
143
|
+
def create_sub_devices( properties )
|
144
|
+
return OpenCL.create_sub_devices( self, properties )
|
145
|
+
end
|
146
|
+
|
147
|
+
# Partitions the Device in serveral sub-devices by affinity domain
|
148
|
+
#
|
149
|
+
# ==== Attributes
|
150
|
+
#
|
151
|
+
# * +affinity_domain+ - the :cl_device_partition_property specifying the target affinity domain
|
152
|
+
#
|
153
|
+
# ==== Returns
|
154
|
+
#
|
155
|
+
# an Array of Device
|
156
|
+
def partition_by_affinity_domain( affinity_domain = OpenCL::Device::AFFINITY_DOMAIN_NEXT_PARTITIONABLE )
|
157
|
+
return OpenCL.create_sub_devices( self, [ OpenCL::Device::PARTITION_BY_AFFINITY_DOMAIN, affinity_domain ] )
|
158
|
+
end
|
159
|
+
|
160
|
+
# Partitions the Device in serveral sub-devices containing compute_unit_number compute units
|
161
|
+
#
|
162
|
+
# ==== Attributes
|
163
|
+
#
|
164
|
+
# * +compute_unit_number+ - the number of compute units in each sub-device
|
165
|
+
#
|
166
|
+
# ==== Returns
|
167
|
+
#
|
168
|
+
# an Array of Device
|
169
|
+
def partition_equally( compute_unit_number = 1 )
|
170
|
+
return OpenCL.create_sub_devices( self, [ OpenCL::Device::PARTITION_EQUALLY, compute_unit_number ] )
|
171
|
+
end
|
172
|
+
|
173
|
+
# Partitions the Device in serveral sub-devices each containing a specific number of compute units
|
174
|
+
#
|
175
|
+
# ==== Attributes
|
176
|
+
#
|
177
|
+
# * +compute_unit_number_list+ - an Array of compute unit number
|
178
|
+
#
|
179
|
+
# ==== Returns
|
180
|
+
#
|
181
|
+
# an Array of Device
|
182
|
+
def partition_by_count( compute_unit_number_list = [1] )
|
183
|
+
return OpenCL.create_sub_devices( self, [ OpenCL::Device::PARTITION_BY_COUNTS] + compute_unit_number_list + [ OpenCL::Device::PARTITION_BY_COUNTS_LIST_END ] )
|
184
|
+
end
|
185
|
+
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|