opencl_ruby_ffi 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,51 @@
1
+ module OpenCL
2
+
3
+ # Creates a Sampler
4
+ #
5
+ # ==== Attributes
6
+ #
7
+ # * +context+ - Context the created Sampler will be associated to
8
+ # * +normalized_coords+ - a :cl_bool specifying if the image coordinates are normalized
9
+ # * +addressing_mode+ - a :cl_addressing_mode specifying how out-of-range image coordinates are handled when reading from an image
10
+ # * +filter_mode+ - a :cl_filter_mode specifying the type of filter that must be applied when reading an image
11
+ def self.create_sampler( context, normalized_coords, addressing_mode, filter_mode )
12
+ error = FFI::MemoryPointer::new( :cl_int )
13
+ sampler_ptr = OpenCL.clCreateSampler( context, normalized_coords, addressing_mode, filter_mode, error )
14
+ OpenCL.error_check(error.read_cl_int)
15
+ OpenCL::Sampler::new(sampler_ptr, false)
16
+ end
17
+
18
+ # Maps the cl_smapler object of OpenCL
19
+ class Sampler
20
+
21
+ # Returns the context associated with the Sampler
22
+ def context
23
+ ptr = FFI::MemoryPointer.new( Context )
24
+ error = OpenCL.clGetSamplerInfo(self, Sampler::CONTEXT, Context.size, ptr, nil)
25
+ OpenCL.error_check(error)
26
+ return OpenCL::Context::new( ptr.read_pointer )
27
+ end
28
+
29
+ ##
30
+ # :method: reference_count()
31
+ # returns the reference counter of the Sampler
32
+ eval OpenCL.get_info("Sampler", :cl_uint, "REFERENCE_COUNT")
33
+
34
+ ##
35
+ # :method: normalized_coords()
36
+ # returns if the Sampler uses normalized coords
37
+ eval OpenCL.get_info("Sampler", :cl_bool, "NORMALIZED_COORDS")
38
+
39
+ ##
40
+ # :method: addressing_mode()
41
+ # returns an AddressingMode representing the addressing mode used by the Sampler
42
+ eval OpenCL.get_info("Sampler", :cl_addressing_mode, "ADDRESSING_MODE")
43
+
44
+ ##
45
+ # :method: filter_mode()
46
+ # returns a FilterMode representing the filtering mode used by the Sampler
47
+ eval OpenCL.get_info("Sampler", :cl_filter_mode, "FILTER_MODE")
48
+
49
+ end
50
+
51
+ end
@@ -0,0 +1,320 @@
1
+ module FFI
2
+ class Pointer
3
+ alias_method :orig_method_missing, :method_missing
4
+ # if a missing write_type, read_type, get_array_of_type can transitively get a replacement, an alias is created and the method is called
5
+ def method_missing(m, *a, &b)
6
+ if m.to_s.match("read_")
7
+ type = m.to_s.sub("read_","")
8
+ type = FFI.find_type(type.to_sym)
9
+ type, _ = FFI::TypeDefs.find do |(name, t)|
10
+ Pointer.method_defined?("read_#{name}") if t == type
11
+ end
12
+ eval "alias :#{m} :read_#{type}" if type
13
+ return eval "read_#{type}( *a, &b)" if type
14
+ elsif m.to_s.match ("write_")
15
+ type = m.to_s.sub("write_","")
16
+ type = FFI.find_type(type.to_sym)
17
+ type, _ = FFI::TypeDefs.find do |(name, t)|
18
+ Pointer.method_defined?("write_#{name}") if t == type
19
+ end
20
+ eval "alias :#{m} :write_#{type}" if type
21
+ return eval "write_#{type}( *a, &b)" if type
22
+ elsif m.to_s.match ("get_array_of_")
23
+ type = m.to_s.sub("get_array_of_","")
24
+ type = FFI.find_type(type.to_sym)
25
+ type, _ = FFI::TypeDefs.find do |(name, t)|
26
+ Pointer.method_defined?("get_array_of_#{name}") if t == type
27
+ end
28
+ eval "alias :#{m} :get_array_of_#{type}" if type
29
+ return eval "get_array_of_#{type}( *a, &b)" if type
30
+ end
31
+ orig_method_missing m, *a, &b
32
+
33
+ end
34
+ end
35
+ end
36
+
37
+ # Maps the OpenCL API using FFI.
38
+ module OpenCL
39
+ @@type_converter = {
40
+ :cl_device_type => OpenCL::Device::Type,
41
+ :cl_device_fp_config => OpenCL::Device::FPConfig,
42
+ :cl_device_mem_cache_type => OpenCL::Device::MemCacheType,
43
+ :cl_device_local_mem_type => OpenCL::Device::LocalMemType,
44
+ :cl_device_exec_capabilities => OpenCL::Device::ExecCapabilities,
45
+ :cl_command_queue_properties => OpenCL::CommandQueue::Properties,
46
+ :cl_device_affinity_domain => OpenCL::Device::AffinityDomain,
47
+ :cl_channel_order => OpenCL::ChannelOrder,
48
+ :cl_channel_type => OpenCL::ChannelType,
49
+ :cl_mem_flags => OpenCL::Mem::Flags,
50
+ :cl_mem_object_type => OpenCL::Mem::Type,
51
+ :cl_mem_migration_flags => OpenCL::Mem::MigrationFlags,
52
+ :cl_addressing_mode => OpenCL::AddressingMode,
53
+ :cl_filter_mode => OpenCL::FilterMode,
54
+ :cl_map_flags => OpenCL::MapFlags,
55
+ :cl_program_binary_type => OpenCL::Program::BinaryType,
56
+ :cl_kernel_arg_address_qualifier => OpenCL::Kernel::Arg::AddressQualifier,
57
+ :cl_kernel_arg_access_qualifier => OpenCL::Kernel::Arg::AccessQualifier,
58
+ :cl_kernel_arg_type_qualifier => OpenCL::Kernel::Arg::TypeQualifier,
59
+ :cl_command_type => OpenCL::CommandType,
60
+ :cl_build_status => OpenCL::BuildStatus
61
+ }
62
+ @@callbacks = []
63
+
64
+ # Converts a type from a symbol to an OpenCL class if a convertion is found
65
+ def self.convert_type(type)
66
+ return @@type_converter[type]
67
+ end
68
+
69
+ class FFI::Struct
70
+
71
+ # alias initialize in order to call it from another function from a child class
72
+ alias_method :parent_initialize, :initialize
73
+ end
74
+
75
+ # Maps the :cl_image_fomat type of OpenCL
76
+ class ImageFormat < FFI::Struct
77
+ layout :image_channel_order, :cl_channel_order,
78
+ :image_channel_data_type, :cl_channel_type
79
+
80
+ # Creates a new ImageFormat from an image channel order and data type
81
+ def initialize( image_channel_order, image_channel_data_type )
82
+ super()
83
+ self[:image_channel_order] = image_channel_order
84
+ self[:image_channel_data_type] = image_channel_data_type
85
+ end
86
+
87
+ # Returns a new ChannelOrder corresponding to the ImageFormat internal value
88
+ def channel_order
89
+ return OpenCL::ChannelOrder::new(self[:image_channel_order])
90
+ end
91
+
92
+ # Sets the ImageFormat internal value for the image channel order
93
+ def channel_order=(order)
94
+ return self[:image_channel_order] = order
95
+ end
96
+
97
+ # Returns a new ChannelType corresponding to the ImageFormat internal value
98
+ def channel_data_type
99
+ return OpenCL::convert_type(:cl_channel_type)::new(self[:image_channel_data_type])
100
+ end
101
+
102
+ # Sets the ImageFormat internal value for the image channel data type
103
+ def channel_data_type=(data_type)
104
+ return self[:image_channel_data_type] = data_type
105
+ end
106
+
107
+ # Returns a String containing a user friendly representation of the ImageFormat
108
+ def to_s
109
+ return "{ #{self.channel_order}, #{self.channel_data_type} }"
110
+ end
111
+
112
+ # A workaroud to call the parent initialize from another function (from_pointer)
113
+ def parent_initialize(ptr)
114
+ super(ptr)
115
+ end
116
+
117
+ # Creates a new ImageFormat using an FFI::Pointer, fonctionality was lost when initialize was defined
118
+ def self.from_pointer( ptr )
119
+ object = allocate
120
+ object.parent_initialize( ptr )
121
+ object
122
+ end
123
+ end
124
+
125
+ # Map the :cl_image_desc type of OpenCL
126
+ class ImageDesc < FFI::Struct
127
+ layout :image_type, :cl_mem_object_type,
128
+ :image_width, :size_t,
129
+ :image_height, :size_t,
130
+ :image_depth, :size_t,
131
+ :image_array_size, :size_t,
132
+ :image_row_pitch, :size_t,
133
+ :image_slice_pitch, :size_t,
134
+ :num_mip_levels, :cl_uint,
135
+ :num_samples, :cl_uint,
136
+ :buffer, Mem
137
+
138
+ # Creates anew ImageDesc using the values provided by the user
139
+ def initialize( image_type, image_width, image_height, image_depth, image_array_size, image_row_pitch, image_slice_pitch, num_mip_levels, num_samples, buffer )
140
+ super()
141
+ self[:image_type] = image_type
142
+ self[:image_width] = image_width
143
+ self[:image_height] = image_height
144
+ self[:image_depth] = image_depth
145
+ self[:image_array_size] = image_array_size
146
+ self[:image_row_pitch] = image_row_pitch
147
+ self[:image_slice_pitch] = image_slice_pitch
148
+ self[:num_mip_levels] = num_mip_levels
149
+ self[:num_samples] = num_samples
150
+ self[:buffer] = buffer
151
+ end
152
+ end
153
+
154
+ # Maps the :cl_buffer_region type of OpenCL
155
+ class BufferRegion < FFI::Struct
156
+ layout :origin, :size_t,
157
+ :size, :size_t
158
+
159
+ # Creates a new BufferRegion using the value provided by the user
160
+ def initialize( origin, sz )
161
+ super()
162
+ self[:origin] = origin
163
+ self[:size] = sz
164
+ end
165
+ end
166
+
167
+ # Extracts the :flags named option from the hash given and returns the flags value
168
+ def self.get_flags( options )
169
+ flags = 0
170
+ if options[:flags] then
171
+ if options[:flags].respond_to?(:each) then
172
+ options[:flags].each { |f| flags = flags | f }
173
+ else
174
+ flags = options[:flags]
175
+ end
176
+ end
177
+ return flags
178
+ end
179
+
180
+ # Extracts the :event_wait_list named option from the hash given and returns a tuple containing the number of events and a pointer to those events
181
+ def self.get_event_wait_list( options )
182
+ num_events = 0
183
+ events = nil
184
+ if options[:event_wait_list] then
185
+ num_events = options[:event_wait_list].length
186
+ if num_events > 0 then
187
+ events = FFI::MemoryPointer.new( Event, num_events )
188
+ options[:event_wait_list].each_with_index { |e, i|
189
+ events[i].write_pointer(e)
190
+ }
191
+ end
192
+ end
193
+ return [ num_events, events ]
194
+ end
195
+
196
+ # Extracts the :properties named option (for a CommandQueue) from the hash given and returns the properties values
197
+ def self.get_command_queue_properties( options )
198
+ properties = nil
199
+ if options[:properties] then
200
+ if options[:properties].respond_to?(:each) then
201
+ options[:properties].each { |f| properties = properties | f }
202
+ else
203
+ properties = options[:properties]
204
+ end
205
+ end
206
+ return properties
207
+ end
208
+
209
+ # Extracts the origin_symbol and region_symbol named options for image from the given hash. Returns the read (or detemined suitable) origin and region in a tuple
210
+ def self.get_origin_region( image, options, origin_symbol, region_symbol )
211
+ origin = FFI::MemoryPointer.new( :size_t, 3 )
212
+ (0..2).each { |i| origin[i].write_size_t(0) }
213
+ if options[origin_symbol] then
214
+ options[origin_symbol].each_with_index { |e, i|
215
+ origin[i].write_size_t(e)
216
+ }
217
+ end
218
+ region = FFI::MemoryPointer.new( :size_t, 3 )
219
+ (0..2).each { |i| region[i].write_size_t(1) }
220
+ if options[region_symbol] then
221
+ options[region_symbol].each_with_index { |e, i|
222
+ region[i].write_size_t(e)
223
+ }
224
+ else
225
+ region[0].write_size_t( image.width - origin[0].read_size_t )
226
+ if image.type == OpenCL::Mem::IMAGE1D_ARRAY then
227
+ region[1].write_size_t( image.array_size - origin[1].read_size_t )
228
+ else
229
+ region[1].write_size_t( image.height ? image.height - origin[1].read_size_t : 1 )
230
+ end
231
+ if image.type == OpenCL::Mem::IMAGE2D_ARRAY then
232
+ region[2].write_size_t( image.array_size - origin[2].read_size_t )
233
+ else
234
+ region[2].write_size_t( image.depth ? image.depth - origin[2].read_size_t : 1 )
235
+ end
236
+ end
237
+ return [origin, region]
238
+ end
239
+
240
+ # Extracts the :properties named option (for a Context) from the hash given and returns an FFI:Pointer to a 0 terminated list of properties
241
+ def self.get_context_properties( options )
242
+ properties = nil
243
+ if options[:properties] then
244
+ properties = FFI::MemoryPointer.new( :cl_context_properties, options[:properties].length + 1 )
245
+ options[:properties].each_with_index { |e,i|
246
+ properties[i].write_cl_context_properties(e)
247
+ }
248
+ properties[options[:properties].length].write_cl_context_properties(0)
249
+ end
250
+ return properties
251
+ end
252
+
253
+ # checks if a :cl_int corresponds to an Error code and raises the apropriate OpenCL::Error
254
+ def self.error_check(errcode)
255
+ raise OpenCL::Error::new(OpenCL::Error.get_error_string(errcode)) if errcode != SUCCESS
256
+ end
257
+
258
+ # Generates a new method for klass that use the apropriate clGetKlassInfo, to read an Array of element of the given type. The info queried is specified by name.
259
+ def self.get_info_array(klass, type, name)
260
+ klass_name = klass
261
+ klass_name = "MemObject" if klass == "Mem"
262
+ s = <<EOF
263
+ def #{name.downcase}
264
+ ptr1 = FFI::MemoryPointer.new( :size_t, 1)
265
+ error = OpenCL.clGet#{klass_name}Info(self, #{klass}::#{name}, 0, nil, ptr1)
266
+ OpenCL.error_check(error)
267
+ EOF
268
+ if ( klass == "Device" and name == "PARTITION_TYPE" ) or ( klass == "Context" and name == "PROPERTIES" ) then
269
+ s+= <<EOF
270
+ return [] if ptr1.read_size_t == 0
271
+ EOF
272
+ end
273
+ s += <<EOF
274
+ ptr2 = FFI::MemoryPointer.new( ptr1.read_size_t )
275
+ error = OpenCL.clGet#{klass_name}Info(self, #{klass}::#{name}, ptr1.read_size_t, ptr2, nil)
276
+ OpenCL.error_check(error)
277
+ arr = ptr2.get_array_of_#{type}(0, ptr1.read_size_t/ FFI.find_type(:#{type}).size)
278
+ EOF
279
+ if ( klass == "Device" and ( name == "PARTITION_TYPE" or name == "PARTITION_PROPERTIES" ) ) or ( klass == "Context" and name == "PROPERTIES" ) then
280
+ s+= <<EOF
281
+ return arr.reject! { |e| e == 0 }
282
+ end
283
+ EOF
284
+ else
285
+ s+= <<EOF
286
+ return arr
287
+ end
288
+ EOF
289
+ end
290
+ return s
291
+ end
292
+
293
+ # Generates a new method for klass that use the apropriate clGetKlassInfo, to read an element of the given type. The info queried is specified by name.
294
+ def self.get_info(klass, type, name)
295
+ klass_name = klass
296
+ klass_name = "MemObject" if klass == "Mem"
297
+ s = <<EOF
298
+ def #{name.downcase}
299
+ ptr1 = FFI::MemoryPointer.new( :size_t, 1)
300
+ error = OpenCL.clGet#{klass_name}Info(self, #{klass}::#{name}, 0, nil, ptr1)
301
+ OpenCL.error_check(error)
302
+ ptr2 = FFI::MemoryPointer.new( ptr1.read_size_t )
303
+ error = OpenCL.clGet#{klass_name}Info(self, #{klass}::#{name}, ptr1.read_size_t, ptr2, nil)
304
+ OpenCL.error_check(error)
305
+ EOF
306
+ if(OpenCL::convert_type(type)) then
307
+ s += <<EOF
308
+ return OpenCL::convert_type(:#{type})::new(ptr2.read_#{type})
309
+ end
310
+ EOF
311
+ else
312
+ s += <<EOF
313
+ return ptr2.read_#{type}
314
+ end
315
+ EOF
316
+ end
317
+ return s
318
+ end
319
+
320
+ end
@@ -0,0 +1,1826 @@
1
+ require 'ffi'
2
+
3
+ module OpenCL
4
+ extend FFI::Library
5
+ ffi_lib "libOpenCL.so"
6
+ #:stopdoc:
7
+ SUCCESS = 0
8
+ DEVICE_NOT_FOUND = -1
9
+ DEVICE_NOT_AVAILABLE = -2
10
+ COMPILER_NOT_AVAILABLE = -3
11
+ MEM_OBJECT_ALLOCATION_FAILURE = -4
12
+ OUT_OF_RESOURCES = -5
13
+ OUT_OF_HOST_MEMORY = -6
14
+ PROFILING_INFO_NOT_AVAILABLE = -7
15
+ MEM_COPY_OVERLAP = -8
16
+ IMAGE_FORMAT_MISMATCH = -9
17
+ IMAGE_FORMAT_NOT_SUPPORTED = -10
18
+ BUILD_PROGRAM_FAILURE = -11
19
+ MAP_FAILURE = -12
20
+ MISALIGNED_SUB_BUFFER_OFFSET = -13
21
+ EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST = -14
22
+ COMPILE_PROGRAM_FAILURE = -15
23
+ LINKER_NOT_AVAILABLE = -16
24
+ LINK_PROGRAM_FAILURE = -17
25
+ DEVICE_PARTITION_FAILED = -18
26
+ KERNEL_ARG_INFO_NOT_AVAILABLE = -19
27
+ INVALID_VALUE = -30
28
+ INVALID_DEVICE_TYPE = -31
29
+ INVALID_PLATFORM = -32
30
+ INVALID_DEVICE = -33
31
+ INVALID_CONTEXT = -34
32
+ INVALID_QUEUE_PROPERTIES = -35
33
+ INVALID_COMMAND_QUEUE = -36
34
+ INVALID_HOST_PTR = -37
35
+ INVALID_MEM_OBJECT = -38
36
+ INVALID_IMAGE_FORMAT_DESCRIPTOR = -39
37
+ INVALID_IMAGE_SIZE = -40
38
+ INVALID_SAMPLER = -41
39
+ INVALID_BINARY = -42
40
+ INVALID_BUILD_OPTIONS = -43
41
+ INVALID_PROGRAM = -44
42
+ INVALID_PROGRAM_EXECUTABLE = -45
43
+ INVALID_KERNEL_NAME = -46
44
+ INVALID_KERNEL_DEFINITION = -47
45
+ INVALID_KERNEL = -48
46
+ INVALID_ARG_INDEX = -49
47
+ INVALID_ARG_VALUE = -50
48
+ INVALID_ARG_SIZE = -51
49
+ INVALID_KERNEL_ARGS = -52
50
+ INVALID_WORK_DIMENSION = -53
51
+ INVALID_WORK_GROUP_SIZE = -54
52
+ INVALID_WORK_ITEM_SIZE = -55
53
+ INVALID_GLOBAL_OFFSET = -56
54
+ INVALID_EVENT_WAIT_LIST = -57
55
+ INVALID_EVENT = -58
56
+ INVALID_OPERATION = -59
57
+ INVALID_GL_OBJECT = -60
58
+ INVALID_BUFFER_SIZE = -61
59
+ INVALID_MIP_LEVEL = -62
60
+ INVALID_GLOBAL_WORK_SIZE = -63
61
+ INVALID_PROPERTY = -64
62
+ INVALID_IMAGE_DESCRIPTOR = -65
63
+ INVALID_COMPILER_OPTIONS = -66
64
+ INVALID_LINKER_OPTIONS = -67
65
+ INVALID_DEVICE_PARTITION_COUNT = -68
66
+ VERSION_1_0 = 1
67
+ VERSION_1_1 = 1
68
+ VERSION_1_2 = 1
69
+ FALSE = 0
70
+ TRUE = 1
71
+ BLOCKING = TRUE
72
+ NON_BLOCKING = FALSE
73
+ PLATFORM_PROFILE = 0x0900
74
+ PLATFORM_VERSION = 0x0901
75
+ PLATFORM_NAME = 0x0902
76
+ PLATFORM_VENDOR = 0x0903
77
+ PLATFORM_EXTENSIONS = 0x0904
78
+ DEVICE_TYPE_DEFAULT = (1 << 0)
79
+ DEVICE_TYPE_CPU = (1 << 1)
80
+ DEVICE_TYPE_GPU = (1 << 2)
81
+ DEVICE_TYPE_ACCELERATOR = (1 << 3)
82
+ DEVICE_TYPE_CUSTOM = (1 << 4)
83
+ DEVICE_TYPE_ALL = 0xFFFFFFFF
84
+ DEVICE_TYPE = 0x1000
85
+ DEVICE_VENDOR_ID = 0x1001
86
+ DEVICE_MAX_COMPUTE_UNITS = 0x1002
87
+ DEVICE_MAX_WORK_ITEM_DIMENSIONS = 0x1003
88
+ DEVICE_MAX_WORK_GROUP_SIZE = 0x1004
89
+ DEVICE_MAX_WORK_ITEM_SIZES = 0x1005
90
+ DEVICE_PREFERRED_VECTOR_WIDTH_CHAR = 0x1006
91
+ DEVICE_PREFERRED_VECTOR_WIDTH_SHORT = 0x1007
92
+ DEVICE_PREFERRED_VECTOR_WIDTH_INT = 0x1008
93
+ DEVICE_PREFERRED_VECTOR_WIDTH_LONG = 0x1009
94
+ DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT = 0x100A
95
+ DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE = 0x100B
96
+ DEVICE_MAX_CLOCK_FREQUENCY = 0x100C
97
+ DEVICE_ADDRESS_BITS = 0x100D
98
+ DEVICE_MAX_READ_IMAGE_ARGS = 0x100E
99
+ DEVICE_MAX_WRITE_IMAGE_ARGS = 0x100F
100
+ DEVICE_MAX_MEM_ALLOC_SIZE = 0x1010
101
+ DEVICE_IMAGE2D_MAX_WIDTH = 0x1011
102
+ DEVICE_IMAGE2D_MAX_HEIGHT = 0x1012
103
+ DEVICE_IMAGE3D_MAX_WIDTH = 0x1013
104
+ DEVICE_IMAGE3D_MAX_HEIGHT = 0x1014
105
+ DEVICE_IMAGE3D_MAX_DEPTH = 0x1015
106
+ DEVICE_IMAGE_SUPPORT = 0x1016
107
+ DEVICE_MAX_PARAMETER_SIZE = 0x1017
108
+ DEVICE_MAX_SAMPLERS = 0x1018
109
+ DEVICE_MEM_BASE_ADDR_ALIGN = 0x1019
110
+ DEVICE_MIN_DATA_TYPE_ALIGN_SIZE = 0x101A
111
+ DEVICE_SINGLE_FP_CONFIG = 0x101B
112
+ DEVICE_GLOBAL_MEM_CACHE_TYPE = 0x101C
113
+ DEVICE_GLOBAL_MEM_CACHELINE_SIZE = 0x101D
114
+ DEVICE_GLOBAL_MEM_CACHE_SIZE = 0x101E
115
+ DEVICE_GLOBAL_MEM_SIZE = 0x101F
116
+ DEVICE_MAX_CONSTANT_BUFFER_SIZE = 0x1020
117
+ DEVICE_MAX_CONSTANT_ARGS = 0x1021
118
+ DEVICE_LOCAL_MEM_TYPE = 0x1022
119
+ DEVICE_LOCAL_MEM_SIZE = 0x1023
120
+ DEVICE_ERROR_CORRECTION_SUPPORT = 0x1024
121
+ DEVICE_PROFILING_TIMER_RESOLUTION = 0x1025
122
+ DEVICE_ENDIAN_LITTLE = 0x1026
123
+ DEVICE_AVAILABLE = 0x1027
124
+ DEVICE_COMPILER_AVAILABLE = 0x1028
125
+ DEVICE_EXECUTION_CAPABILITIES = 0x1029
126
+ DEVICE_QUEUE_PROPERTIES = 0x102A
127
+ DEVICE_NAME = 0x102B
128
+ DEVICE_VENDOR = 0x102C
129
+ DRIVER_VERSION = 0x102D
130
+ DEVICE_PROFILE = 0x102E
131
+ DEVICE_VERSION = 0x102F
132
+ DEVICE_EXTENSIONS = 0x1030
133
+ DEVICE_PLATFORM = 0x1031
134
+ DEVICE_DOUBLE_FP_CONFIG = 0x1032
135
+ DEVICE_PREFERRED_VECTOR_WIDTH_HALF = 0x1034
136
+ DEVICE_HOST_UNIFIED_MEMORY = 0x1035
137
+ DEVICE_NATIVE_VECTOR_WIDTH_CHAR = 0x1036
138
+ DEVICE_NATIVE_VECTOR_WIDTH_SHORT = 0x1037
139
+ DEVICE_NATIVE_VECTOR_WIDTH_INT = 0x1038
140
+ DEVICE_NATIVE_VECTOR_WIDTH_LONG = 0x1039
141
+ DEVICE_NATIVE_VECTOR_WIDTH_FLOAT = 0x103A
142
+ DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE = 0x103B
143
+ DEVICE_NATIVE_VECTOR_WIDTH_HALF = 0x103C
144
+ DEVICE_OPENCL_C_VERSION = 0x103D
145
+ DEVICE_LINKER_AVAILABLE = 0x103E
146
+ DEVICE_BUILT_IN_KERNELS = 0x103F
147
+ DEVICE_IMAGE_MAX_BUFFER_SIZE = 0x1040
148
+ DEVICE_IMAGE_MAX_ARRAY_SIZE = 0x1041
149
+ DEVICE_PARENT_DEVICE = 0x1042
150
+ DEVICE_PARTITION_MAX_SUB_DEVICES = 0x1043
151
+ DEVICE_PARTITION_PROPERTIES = 0x1044
152
+ DEVICE_PARTITION_AFFINITY_DOMAIN = 0x1045
153
+ DEVICE_PARTITION_TYPE = 0x1046
154
+ DEVICE_REFERENCE_COUNT = 0x1047
155
+ DEVICE_PREFERRED_INTEROP_USER_SYNC = 0x1048
156
+ DEVICE_PRINTF_BUFFER_SIZE = 0x1049
157
+ DEVICE_IMAGE_PITCH_ALIGNMENT = 0x104A
158
+ DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT = 0x104B
159
+ FP_DENORM = (1 << 0)
160
+ FP_INF_NAN = (1 << 1)
161
+ FP_ROUND_TO_NEAREST = (1 << 2)
162
+ FP_ROUND_TO_ZERO = (1 << 3)
163
+ FP_ROUND_TO_INF = (1 << 4)
164
+ FP_FMA = (1 << 5)
165
+ FP_SOFT_FLOAT = (1 << 6)
166
+ FP_CORRECTLY_ROUNDED_DIVIDE_SQRT = (1 << 7)
167
+ NONE = 0x0
168
+ READ_ONLY_CACHE = 0x1
169
+ READ_WRITE_CACHE = 0x2
170
+ LOCAL = 0x1
171
+ GLOBAL = 0x2
172
+ EXEC_KERNEL = (1 << 0)
173
+ EXEC_NATIVE_KERNEL = (1 << 1)
174
+ QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE = (1 << 0)
175
+ QUEUE_PROFILING_ENABLE = (1 << 1)
176
+ CONTEXT_REFERENCE_COUNT = 0x1080
177
+ CONTEXT_DEVICES = 0x1081
178
+ CONTEXT_PROPERTIES = 0x1082
179
+ CONTEXT_NUM_DEVICES = 0x1083
180
+ CONTEXT_PLATFORM = 0x1084
181
+ CONTEXT_INTEROP_USER_SYNC = 0x1085
182
+ DEVICE_PARTITION_EQUALLY = 0x1086
183
+ DEVICE_PARTITION_BY_COUNTS = 0x1087
184
+ DEVICE_PARTITION_BY_COUNTS_LIST_END = 0x0
185
+ DEVICE_PARTITION_BY_AFFINITY_DOMAIN = 0x1088
186
+ DEVICE_AFFINITY_DOMAIN_NUMA = (1 << 0)
187
+ DEVICE_AFFINITY_DOMAIN_L4_CACHE = (1 << 1)
188
+ DEVICE_AFFINITY_DOMAIN_L3_CACHE = (1 << 2)
189
+ DEVICE_AFFINITY_DOMAIN_L2_CACHE = (1 << 3)
190
+ DEVICE_AFFINITY_DOMAIN_L1_CACHE = (1 << 4)
191
+ DEVICE_AFFINITY_DOMAIN_NEXT_PARTITIONABLE = (1 << 5)
192
+ QUEUE_CONTEXT = 0x1090
193
+ QUEUE_DEVICE = 0x1091
194
+ QUEUE_REFERENCE_COUNT = 0x1092
195
+ QUEUE_PROPERTIES = 0x1093
196
+ MEM_READ_WRITE = (1 << 0)
197
+ MEM_WRITE_ONLY = (1 << 1)
198
+ MEM_READ_ONLY = (1 << 2)
199
+ MEM_USE_HOST_PTR = (1 << 3)
200
+ MEM_ALLOC_HOST_PTR = (1 << 4)
201
+ MEM_COPY_HOST_PTR = (1 << 5)
202
+ MEM_HOST_WRITE_ONLY = (1 << 7)
203
+ MEM_HOST_READ_ONLY = (1 << 8)
204
+ MEM_HOST_NO_ACCESS = (1 << 9)
205
+ MIGRATE_MEM_OBJECT_HOST = (1 << 0)
206
+ MIGRATE_MEM_OBJECT_CONTENT_UNDEFINED = (1 << 1)
207
+ R = 0x10B0
208
+ A = 0x10B1
209
+ RG = 0x10B2
210
+ RA = 0x10B3
211
+ RGB = 0x10B4
212
+ RGBA = 0x10B5
213
+ BGRA = 0x10B6
214
+ ARGB = 0x10B7
215
+ INTENSITY = 0x10B8
216
+ LUMINANCE = 0x10B9
217
+ Rx = 0x10BA
218
+ RGx = 0x10BB
219
+ RGBx = 0x10BC
220
+ DEPTH = 0x10BD
221
+ DEPTH_STENCIL = 0x10BE
222
+ SNORM_INT8 = 0x10D0
223
+ SNORM_INT16 = 0x10D1
224
+ UNORM_INT8 = 0x10D2
225
+ UNORM_INT16 = 0x10D3
226
+ UNORM_SHORT_565 = 0x10D4
227
+ UNORM_SHORT_555 = 0x10D5
228
+ UNORM_INT_101010 = 0x10D6
229
+ SIGNED_INT8 = 0x10D7
230
+ SIGNED_INT16 = 0x10D8
231
+ SIGNED_INT32 = 0x10D9
232
+ UNSIGNED_INT8 = 0x10DA
233
+ UNSIGNED_INT16 = 0x10DB
234
+ UNSIGNED_INT32 = 0x10DC
235
+ HALF_FLOAT = 0x10DD
236
+ FLOAT = 0x10DE
237
+ UNORM_INT24 = 0x10DF
238
+ MEM_OBJECT_BUFFER = 0x10F0
239
+ MEM_OBJECT_IMAGE2D = 0x10F1
240
+ MEM_OBJECT_IMAGE3D = 0x10F2
241
+ MEM_OBJECT_IMAGE2D_ARRAY = 0x10F3
242
+ MEM_OBJECT_IMAGE1D = 0x10F4
243
+ MEM_OBJECT_IMAGE1D_ARRAY = 0x10F5
244
+ MEM_OBJECT_IMAGE1D_BUFFER = 0x10F6
245
+ MEM_TYPE = 0x1100
246
+ MEM_FLAGS = 0x1101
247
+ MEM_SIZE = 0x1102
248
+ MEM_HOST_PTR = 0x1103
249
+ MEM_MAP_COUNT = 0x1104
250
+ MEM_REFERENCE_COUNT = 0x1105
251
+ MEM_CONTEXT = 0x1106
252
+ MEM_ASSOCIATED_MEMOBJECT = 0x1107
253
+ MEM_OFFSET = 0x1108
254
+ IMAGE_FORMAT = 0x1110
255
+ IMAGE_ELEMENT_SIZE = 0x1111
256
+ IMAGE_ROW_PITCH = 0x1112
257
+ IMAGE_SLICE_PITCH = 0x1113
258
+ IMAGE_WIDTH = 0x1114
259
+ IMAGE_HEIGHT = 0x1115
260
+ IMAGE_DEPTH = 0x1116
261
+ IMAGE_ARRAY_SIZE = 0x1117
262
+ IMAGE_BUFFER = 0x1118
263
+ IMAGE_NUM_MIP_LEVELS = 0x1119
264
+ IMAGE_NUM_SAMPLES = 0x111A
265
+ ADDRESS_NONE = 0x1130
266
+ ADDRESS_CLAMP_TO_EDGE = 0x1131
267
+ ADDRESS_CLAMP = 0x1132
268
+ ADDRESS_REPEAT = 0x1133
269
+ ADDRESS_MIRRORED_REPEAT = 0x1134
270
+ FILTER_NEAREST = 0x1140
271
+ FILTER_LINEAR = 0x1141
272
+ SAMPLER_REFERENCE_COUNT = 0x1150
273
+ SAMPLER_CONTEXT = 0x1151
274
+ SAMPLER_NORMALIZED_COORDS = 0x1152
275
+ SAMPLER_ADDRESSING_MODE = 0x1153
276
+ SAMPLER_FILTER_MODE = 0x1154
277
+ MAP_READ = (1 << 0)
278
+ MAP_WRITE = (1 << 1)
279
+ MAP_WRITE_INVALIDATE_REGION = (1 << 2)
280
+ PROGRAM_REFERENCE_COUNT = 0x1160
281
+ PROGRAM_CONTEXT = 0x1161
282
+ PROGRAM_NUM_DEVICES = 0x1162
283
+ PROGRAM_DEVICES = 0x1163
284
+ PROGRAM_SOURCE = 0x1164
285
+ PROGRAM_BINARY_SIZES = 0x1165
286
+ PROGRAM_BINARIES = 0x1166
287
+ PROGRAM_NUM_KERNELS = 0x1167
288
+ PROGRAM_KERNEL_NAMES = 0x1168
289
+ PROGRAM_BUILD_STATUS = 0x1181
290
+ PROGRAM_BUILD_OPTIONS = 0x1182
291
+ PROGRAM_BUILD_LOG = 0x1183
292
+ PROGRAM_BINARY_TYPE = 0x1184
293
+ PROGRAM_BINARY_TYPE_NONE = 0x0
294
+ PROGRAM_BINARY_TYPE_COMPILED_OBJECT = 0x1
295
+ PROGRAM_BINARY_TYPE_LIBRARY = 0x2
296
+ PROGRAM_BINARY_TYPE_EXECUTABLE = 0x4
297
+ BUILD_SUCCESS = 0
298
+ BUILD_NONE = -1
299
+ BUILD_ERROR = -2
300
+ BUILD_IN_PROGRESS = -3
301
+ KERNEL_FUNCTION_NAME = 0x1190
302
+ KERNEL_NUM_ARGS = 0x1191
303
+ KERNEL_REFERENCE_COUNT = 0x1192
304
+ KERNEL_CONTEXT = 0x1193
305
+ KERNEL_PROGRAM = 0x1194
306
+ KERNEL_ATTRIBUTES = 0x1195
307
+ KERNEL_ARG_ADDRESS_QUALIFIER = 0x1196
308
+ KERNEL_ARG_ACCESS_QUALIFIER = 0x1197
309
+ KERNEL_ARG_TYPE_NAME = 0x1198
310
+ KERNEL_ARG_TYPE_QUALIFIER = 0x1199
311
+ KERNEL_ARG_NAME = 0x119A
312
+ KERNEL_ARG_ADDRESS_GLOBAL = 0x119B
313
+ KERNEL_ARG_ADDRESS_LOCAL = 0x119C
314
+ KERNEL_ARG_ADDRESS_CONSTANT = 0x119D
315
+ KERNEL_ARG_ADDRESS_PRIVATE = 0x119E
316
+ KERNEL_ARG_ACCESS_READ_ONLY = 0x11A0
317
+ KERNEL_ARG_ACCESS_WRITE_ONLY = 0x11A1
318
+ KERNEL_ARG_ACCESS_READ_WRITE = 0x11A2
319
+ KERNEL_ARG_ACCESS_NONE = 0x11A3
320
+ KERNEL_ARG_TYPE_NONE = 0
321
+ KERNEL_ARG_TYPE_CONST = (1 << 0)
322
+ KERNEL_ARG_TYPE_RESTRICT = (1 << 1)
323
+ KERNEL_ARG_TYPE_VOLATILE = (1 << 2)
324
+ KERNEL_WORK_GROUP_SIZE = 0x11B0
325
+ KERNEL_COMPILE_WORK_GROUP_SIZE = 0x11B1
326
+ KERNEL_LOCAL_MEM_SIZE = 0x11B2
327
+ KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE = 0x11B3
328
+ KERNEL_PRIVATE_MEM_SIZE = 0x11B4
329
+ KERNEL_GLOBAL_WORK_SIZE = 0x11B5
330
+ EVENT_COMMAND_QUEUE = 0x11D0
331
+ EVENT_COMMAND_TYPE = 0x11D1
332
+ EVENT_REFERENCE_COUNT = 0x11D2
333
+ EVENT_COMMAND_EXECUTION_STATUS = 0x11D3
334
+ EVENT_CONTEXT = 0x11D4
335
+ COMMAND_NDRANGE_KERNEL = 0x11F0
336
+ COMMAND_TASK = 0x11F1
337
+ COMMAND_NATIVE_KERNEL = 0x11F2
338
+ COMMAND_READ_BUFFER = 0x11F3
339
+ COMMAND_WRITE_BUFFER = 0x11F4
340
+ COMMAND_COPY_BUFFER = 0x11F5
341
+ COMMAND_READ_IMAGE = 0x11F6
342
+ COMMAND_WRITE_IMAGE = 0x11F7
343
+ COMMAND_COPY_IMAGE = 0x11F8
344
+ COMMAND_COPY_IMAGE_TO_BUFFER = 0x11F9
345
+ COMMAND_COPY_BUFFER_TO_IMAGE = 0x11FA
346
+ COMMAND_MAP_BUFFER = 0x11FB
347
+ COMMAND_MAP_IMAGE = 0x11FC
348
+ COMMAND_UNMAP_MEM_OBJECT = 0x11FD
349
+ COMMAND_MARKER = 0x11FE
350
+ COMMAND_ACQUIRE_GL_OBJECTS = 0x11FF
351
+ COMMAND_RELEASE_GL_OBJECTS = 0x1200
352
+ COMMAND_READ_BUFFER_RECT = 0x1201
353
+ COMMAND_WRITE_BUFFER_RECT = 0x1202
354
+ COMMAND_COPY_BUFFER_RECT = 0x1203
355
+ COMMAND_USER = 0x1204
356
+ COMMAND_BARRIER = 0x1205
357
+ COMMAND_MIGRATE_MEM_OBJECTS = 0x1206
358
+ COMMAND_FILL_BUFFER = 0x1207
359
+ COMMAND_FILL_IMAGE = 0x1208
360
+ COMPLETE = 0x0
361
+ RUNNING = 0x1
362
+ SUBMITTED = 0x2
363
+ QUEUED = 0x3
364
+ BUFFER_CREATE_TYPE_REGION = 0x1220
365
+ PROFILING_COMMAND_QUEUED = 0x1280
366
+ PROFILING_COMMAND_SUBMIT = 0x1281
367
+ PROFILING_COMMAND_START = 0x1282
368
+ PROFILING_COMMAND_END = 0x1283
369
+ GL_OBJECT_BUFFER = 0x2000
370
+ GL_OBJECT_TEXTURE2D = 0x2001
371
+ GL_OBJECT_TEXTURE3D = 0x2002
372
+ GL_OBJECT_RENDERBUFFER = 0x2003
373
+ GL_OBJECT_TEXTURE2D_ARRAY = 0x200E
374
+ GL_OBJECT_TEXTURE1D = 0x200F
375
+ GL_OBJECT_TEXTURE1D_ARRAY = 0x2010
376
+ GL_OBJECT_TEXTURE_BUFFER = 0x2011
377
+ GL_TEXTURE_TARGET = 0x2004
378
+ GL_MIPMAP_LEVEL = 0x2005
379
+ GL_NUM_SAMPLES = 0x2012
380
+ cl_khr_gl_sharing = 1
381
+ INVALID_GL_SHAREGROUP_REFERENCE_KHR = -1000
382
+ CURRENT_DEVICE_FOR_GL_CONTEXT_KHR = 0x2006
383
+ DEVICES_FOR_GL_CONTEXT_KHR = 0x2007
384
+ GL_CONTEXT_KHR = 0x2008
385
+ EGL_DISPLAY_KHR = 0x2009
386
+ GLX_DISPLAY_KHR = 0x200A
387
+ WGL_HDC_KHR = 0x200B
388
+ CGL_SHAREGROUP_KHR = 0x200C
389
+ DEVICE_HALF_FP_CONFIG = 0x1033
390
+ cl_APPLE_SetMemObjectDestructor = 1
391
+ cl_APPLE_ContextLoggingFunctions = 1
392
+ cl_khr_icd = 1
393
+ PLATFORM_ICD_SUFFIX_KHR = 0x0920
394
+ PLATFORM_NOT_FOUND_KHR = -1001
395
+ CONTEXT_MEMORY_INITIALIZE_KHR = 0x200E
396
+ DEVICE_TERMINATE_CAPABILITY_KHR = 0x200F
397
+ CONTEXT_TERMINATE_KHR = 0x2010
398
+ cl_khr_terminate_context = 1
399
+ DEVICE_COMPUTE_CAPABILITY_MAJOR_NV = 0x4000
400
+ DEVICE_COMPUTE_CAPABILITY_MINOR_NV = 0x4001
401
+ DEVICE_REGISTERS_PER_BLOCK_NV = 0x4002
402
+ DEVICE_WARP_SIZE_NV = 0x4003
403
+ DEVICE_GPU_OVERLAP_NV = 0x4004
404
+ DEVICE_KERNEL_EXEC_TIMEOUT_NV = 0x4005
405
+ DEVICE_INTEGRATED_MEMORY_NV = 0x4006
406
+ cl_amd_device_memory_flags = 1
407
+ MEM_USE_PERSISTENT_MEM_AMD = (1 << 6)
408
+ DEVICE_MAX_ATOMIC_COUNTERS_EXT = 0x4032
409
+ DEVICE_PROFILING_TIMER_OFFSET_AMD = 0x4036
410
+ DEVICE_TOPOLOGY_AMD = 0x4037
411
+ DEVICE_BOARD_NAME_AMD = 0x4038
412
+ DEVICE_GLOBAL_FREE_MEMORY_AMD = 0x4039
413
+ DEVICE_SIMD_PER_COMPUTE_UNIT_AMD = 0x4040
414
+ DEVICE_SIMD_WIDTH_AMD = 0x4041
415
+ DEVICE_SIMD_INSTRUCTION_WIDTH_AMD = 0x4042
416
+ DEVICE_WAVEFRONT_WIDTH_AMD = 0x4043
417
+ DEVICE_GLOBAL_MEM_CHANNELS_AMD = 0x4044
418
+ DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD = 0x4045
419
+ DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD = 0x4046
420
+ DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD = 0x4047
421
+ DEVICE_LOCAL_MEM_BANKS_AMD = 0x4048
422
+ DEVICE_TOPOLOGY_TYPE_PCIE_AMD = 1
423
+ CONTEXT_OFFLINE_DEVICES_AMD = 0x403F
424
+ MEM_EXT_HOST_PTR_QCOM = (1 << 29)
425
+ DEVICE_EXT_MEM_PADDING_IN_BYTES_QCOM = 0x40A0
426
+ DEVICE_PAGE_SIZE_QCOM = 0x40A1
427
+ IMAGE_ROW_ALIGNMENT_QCOM = 0x40A2
428
+ IMAGE_SLICE_ALIGNMENT_QCOM = 0x40A3
429
+ MEM_HOST_UNCACHED_QCOM = 0x40A4
430
+ MEM_HOST_WRITEBACK_QCOM = 0x40A5
431
+ MEM_HOST_WRITETHROUGH_QCOM = 0x40A6
432
+ MEM_HOST_WRITE_COMBINING_QCOM = 0x40A7
433
+ MEM_ION_HOST_PTR_QCOM = 0x40A8
434
+ #:startdoc:
435
+ # Maps OpenCL logiczal Error Type, and is used to raise Errors
436
+ class Error < StandardError
437
+ @@codes = {}
438
+ @@codes[-1001] = 'PLATFORM_NOT_FOUND_KHR'
439
+ @@codes[-1000] = 'INVALID_GL_SHAREGROUP_REFERENCE_KHR'
440
+ @@codes[-3] = 'COMPILER_NOT_AVAILABLE'
441
+ @@codes[-2] = 'DEVICE_NOT_AVAILABLE'
442
+ @@codes[-1] = 'DEVICE_NOT_FOUND'
443
+ @@codes[-68] = 'INVALID_DEVICE_PARTITION_COUNT'
444
+ @@codes[-67] = 'INVALID_LINKER_OPTIONS'
445
+ @@codes[-66] = 'INVALID_COMPILER_OPTIONS'
446
+ @@codes[-65] = 'INVALID_IMAGE_DESCRIPTOR'
447
+ @@codes[-64] = 'INVALID_PROPERTY'
448
+ @@codes[-63] = 'INVALID_GLOBAL_WORK_SIZE'
449
+ @@codes[-62] = 'INVALID_MIP_LEVEL'
450
+ @@codes[-61] = 'INVALID_BUFFER_SIZE'
451
+ @@codes[-60] = 'INVALID_GL_OBJECT'
452
+ @@codes[-59] = 'INVALID_OPERATION'
453
+ @@codes[-58] = 'INVALID_EVENT'
454
+ @@codes[-57] = 'INVALID_EVENT_WAIT_LIST'
455
+ @@codes[-56] = 'INVALID_GLOBAL_OFFSET'
456
+ @@codes[-55] = 'INVALID_WORK_ITEM_SIZE'
457
+ @@codes[-54] = 'INVALID_WORK_GROUP_SIZE'
458
+ @@codes[-53] = 'INVALID_WORK_DIMENSION'
459
+ @@codes[-52] = 'INVALID_KERNEL_ARGS'
460
+ @@codes[-51] = 'INVALID_ARG_SIZE'
461
+ @@codes[-50] = 'INVALID_ARG_VALUE'
462
+ @@codes[-49] = 'INVALID_ARG_INDEX'
463
+ @@codes[-48] = 'INVALID_KERNEL'
464
+ @@codes[-47] = 'INVALID_KERNEL_DEFINITION'
465
+ @@codes[-46] = 'INVALID_KERNEL_NAME'
466
+ @@codes[-45] = 'INVALID_PROGRAM_EXECUTABLE'
467
+ @@codes[-44] = 'INVALID_PROGRAM'
468
+ @@codes[-43] = 'INVALID_BUILD_OPTIONS'
469
+ @@codes[-42] = 'INVALID_BINARY'
470
+ @@codes[-41] = 'INVALID_SAMPLER'
471
+ @@codes[-40] = 'INVALID_IMAGE_SIZE'
472
+ @@codes[-39] = 'INVALID_IMAGE_FORMAT_DESCRIPTOR'
473
+ @@codes[-38] = 'INVALID_MEM_OBJECT'
474
+ @@codes[-37] = 'INVALID_HOST_PTR'
475
+ @@codes[-36] = 'INVALID_COMMAND_QUEUE'
476
+ @@codes[-35] = 'INVALID_QUEUE_PROPERTIES'
477
+ @@codes[-34] = 'INVALID_CONTEXT'
478
+ @@codes[-33] = 'INVALID_DEVICE'
479
+ @@codes[-32] = 'INVALID_PLATFORM'
480
+ @@codes[-31] = 'INVALID_DEVICE_TYPE'
481
+ @@codes[-30] = 'INVALID_VALUE'
482
+ @@codes[-19] = 'KERNEL_ARG_INFO_NOT_AVAILABLE'
483
+ @@codes[-18] = 'DEVICE_PARTITION_FAILED'
484
+ @@codes[-17] = 'LINK_PROGRAM_FAILURE'
485
+ @@codes[-16] = 'LINKER_NOT_AVAILABLE'
486
+ @@codes[-15] = 'COMPILE_PROGRAM_FAILURE'
487
+ @@codes[-14] = 'EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST'
488
+ @@codes[-13] = 'MISALIGNED_SUB_BUFFER_OFFSET'
489
+ @@codes[-12] = 'MAP_FAILURE'
490
+ @@codes[-11] = 'BUILD_PROGRAM_FAILURE'
491
+ @@codes[-10] = 'IMAGE_FORMAT_NOT_SUPPORTED'
492
+ @@codes[-9] = 'IMAGE_FORMAT_MISMATCH'
493
+ @@codes[-8] = 'MEM_COPY_OVERLAP'
494
+ @@codes[-7] = 'PROFILING_INFO_NOT_AVAILABLE'
495
+ @@codes[-6] = 'OUT_OF_HOST_MEMORY'
496
+ @@codes[-5] = 'OUT_OF_RESOURCES'
497
+ @@codes[-4] = 'MEM_OBJECT_ALLOCATION_FAILURE'
498
+ # Returns a more descriptive String for the provided error code
499
+ def self.get_error_string(errcode)
500
+ return "OpenCL Error: #{@@codes[errcode]} (#{errcode})"
501
+ end
502
+
503
+ # Returns a string representing the name corresponding to the error code given
504
+ def self.get_name(errcode)
505
+ return @@codes[errcode]
506
+ end
507
+ end
508
+ FFI.typedef :int8, :cl_char
509
+ FFI.typedef :uint8, :cl_uchar
510
+ FFI.typedef :int16, :cl_short
511
+ FFI.typedef :uint16, :cl_ushort
512
+ FFI.typedef :int32, :cl_int
513
+ FFI.typedef :uint32, :cl_uint
514
+ FFI.typedef :int64, :cl_long
515
+ FFI.typedef :uint64, :cl_ulong
516
+ FFI.typedef :uint16, :cl_half
517
+ FFI.typedef :float, :cl_float
518
+ FFI.typedef :double, :cl_double
519
+ FFI.typedef :uint32, :cl_GLuint
520
+ FFI.typedef :int32, :cl_GLint
521
+ FFI.typedef :uint32, :cl_GLenum
522
+ FFI.typedef :cl_uint, :cl_bool
523
+ FFI.typedef :cl_ulong, :cl_bitfield
524
+ FFI.typedef :cl_bitfield, :cl_device_type
525
+ FFI.typedef :cl_uint, :cl_platform_info
526
+ FFI.typedef :cl_uint, :cl_device_info
527
+ FFI.typedef :cl_bitfield, :cl_device_fp_config
528
+ FFI.typedef :cl_uint, :cl_device_mem_cache_type
529
+ FFI.typedef :cl_uint, :cl_device_local_mem_type
530
+ FFI.typedef :cl_bitfield, :cl_device_exec_capabilities
531
+ FFI.typedef :cl_bitfield, :cl_command_queue_properties
532
+ FFI.typedef :pointer, :cl_device_partition_property
533
+ FFI.typedef :cl_bitfield, :cl_device_affinity_domain
534
+ FFI.typedef :pointer, :cl_context_properties
535
+ FFI.typedef :cl_uint, :cl_context_info
536
+ FFI.typedef :cl_uint, :cl_command_queue_info
537
+ FFI.typedef :cl_uint, :cl_channel_order
538
+ FFI.typedef :cl_uint, :cl_channel_type
539
+ FFI.typedef :cl_bitfield, :cl_mem_flags
540
+ FFI.typedef :cl_uint, :cl_mem_object_type
541
+ FFI.typedef :cl_uint, :cl_mem_info
542
+ FFI.typedef :cl_bitfield, :cl_mem_migration_flags
543
+ FFI.typedef :cl_uint, :cl_image_info
544
+ FFI.typedef :cl_uint, :cl_buffer_create_type
545
+ FFI.typedef :cl_uint, :cl_addressing_mode
546
+ FFI.typedef :cl_uint, :cl_filter_mode
547
+ FFI.typedef :cl_uint, :cl_sampler_info
548
+ FFI.typedef :cl_bitfield, :cl_map_flags
549
+ FFI.typedef :cl_uint, :cl_program_info
550
+ FFI.typedef :cl_uint, :cl_program_build_info
551
+ FFI.typedef :cl_uint, :cl_program_binary_type
552
+ FFI.typedef :cl_int, :cl_build_status
553
+ FFI.typedef :cl_uint, :cl_kernel_info
554
+ FFI.typedef :cl_uint, :cl_kernel_arg_info
555
+ FFI.typedef :cl_uint, :cl_kernel_arg_address_qualifier
556
+ FFI.typedef :cl_uint, :cl_kernel_arg_access_qualifier
557
+ FFI.typedef :cl_bitfield, :cl_kernel_arg_type_qualifier
558
+ FFI.typedef :cl_uint, :cl_kernel_work_group_info
559
+ FFI.typedef :cl_uint, :cl_event_info
560
+ FFI.typedef :cl_uint, :cl_command_type
561
+ FFI.typedef :cl_uint, :cl_profiling_info
562
+ FFI.typedef :cl_uint, :cl_gl_object_type
563
+ FFI.typedef :cl_uint, :cl_gl_texture_info
564
+ FFI.typedef :cl_uint, :cl_gl_platform_info
565
+ FFI.typedef :cl_uint, :cl_gl_context_info
566
+ # A parent class to represent OpenCL enums that use :cl_uint
567
+ class Enum
568
+ # extend FFI::DataConverter
569
+ # native_type :cl_uint
570
+ @@codes = {}
571
+
572
+ # Initializes an enum with the given val
573
+ def initialize( val )
574
+ OpenCL::check_error( OpenCL::INVALID_VALUE ) if not @@codes[val]
575
+ super()
576
+ @val = val
577
+ end
578
+
579
+ # Sets the internal value of the enum
580
+ def val=(v)
581
+ OpenCL::check_error( OpenCL::INVALID_VALUE ) if not @@codes[val]
582
+ @val = v
583
+ end
584
+
585
+ # Returns true if val corresponds to the enum value
586
+ def is?(val)
587
+ return true if @val == val
588
+ end
589
+
590
+ # Return true if val corresponds to the enum value
591
+ def ==(val)
592
+ return true if @val == val
593
+ end
594
+
595
+ # Returns a String corresponfing to the Enum value
596
+ def to_s
597
+ return "#{self.name}"
598
+ end
599
+
600
+ # Returns the integer representing the Enum value
601
+ def to_i
602
+ return @val
603
+ end
604
+
605
+ # #:stopdoc:
606
+ # def self.to_native(value, context)
607
+ # if value then
608
+ # return value.flags
609
+ # else
610
+ # return 0
611
+ # end
612
+ # end
613
+ #
614
+ # def self.from_native(value, context)
615
+ # new(value)
616
+ # end
617
+ #
618
+ # def self.size
619
+ # FFI::find_type(:cl_uint).size
620
+ # end
621
+ #
622
+ # def self.reference_required?
623
+ # return false
624
+ # end
625
+ # #:startdoc:
626
+
627
+ end
628
+
629
+ # A parent class to represent enums that use cl_int
630
+ class EnumInt < OpenCL::Enum
631
+ # extend FFI::DataConverter
632
+ # native_type :cl_int
633
+ end
634
+
635
+ # A parent class to represent OpenCL bitfields that use :cl_bitfield
636
+ class Bitfield
637
+ # extend FFI::DataConverter
638
+ # native_type :cl_bitfield
639
+
640
+ # Initializes a new Bitfield to val
641
+ def initialize( val = 0 )
642
+ super()
643
+ @val = val
644
+ end
645
+
646
+ # Returns true if flag is bitwise included in the Bitfield
647
+ def include?(flag)
648
+ return true if ( @val & flag ) == flag
649
+ return false
650
+ end
651
+
652
+ # Returns a String corresponfing to the Bitfield value
653
+ def to_s
654
+ return "#{self.names}"
655
+ end
656
+
657
+ # Returns the integer representing the Bitfield value
658
+ def to_i
659
+ return @val
660
+ end
661
+
662
+ # Returns the bitwise & operation between f and the internal Bitfield representation
663
+ def &(f)
664
+ return @val & f
665
+ end
666
+
667
+ # Returns the bitwise ^ operation between f and the internal Bitfield representation
668
+ def ^(f)
669
+ return @val ^ f
670
+ end
671
+
672
+ # Returns the bitwise | operation between f and the internal Bitfield representation
673
+ def |(f)
674
+ return @val | f
675
+ end
676
+
677
+ # Returns the internal representation of the Bitfield
678
+ def flags
679
+ return @val
680
+ end
681
+
682
+ # Setss the internal representation of the Bitfield to val
683
+ def flags=(val)
684
+ @val = val
685
+ end
686
+
687
+ # #:stopdoc:
688
+ # def self.to_native(value, context)
689
+ # if value then
690
+ # return value.flags
691
+ # else
692
+ # return 0
693
+ # end
694
+ # end
695
+ #
696
+ # def self.from_native(value, context)
697
+ # new(value)
698
+ # end
699
+ #
700
+ # def self.size
701
+ # FFI::find_type(:cl_bitfield).size
702
+ # end
703
+ #
704
+ # def self.reference_required?
705
+ # return false
706
+ # end
707
+ # #:startdoc:
708
+
709
+ end
710
+ class Platform < FFI::ManagedStruct
711
+ layout :dummy, :pointer
712
+ #:stopdoc:
713
+ PROFILE = 0x0900
714
+ VERSION = 0x0901
715
+ NAME = 0x0902
716
+ VENDOR = 0x0903
717
+ EXTENSIONS = 0x0904
718
+ ICD_SUFFIX_KHR = 0x0920
719
+ #:startdoc:
720
+
721
+ # Creates a new Platform and retains it if specified and aplicable
722
+ def initialize(ptr, retain = true)
723
+ super(ptr)
724
+ #STDERR.puts "Allocating Platform: #{ptr}"
725
+ end
726
+
727
+ # method called at Platform deletion, releases the object if aplicable
728
+ def self.release(ptr)
729
+ #STDERR.puts "Releasing Platform: #{ptr}"
730
+ end
731
+ end
732
+
733
+ class Device < FFI::ManagedStruct
734
+ layout :dummy, :pointer
735
+ #:stopdoc:
736
+ TYPE_DEFAULT = (1 << 0)
737
+ TYPE_CPU = (1 << 1)
738
+ TYPE_GPU = (1 << 2)
739
+ TYPE_ACCELERATOR = (1 << 3)
740
+ TYPE_CUSTOM = (1 << 4)
741
+ TYPE_ALL = 0xFFFFFFFF
742
+ TYPE = 0x1000
743
+ VENDOR_ID = 0x1001
744
+ MAX_COMPUTE_UNITS = 0x1002
745
+ MAX_WORK_ITEM_DIMENSIONS = 0x1003
746
+ MAX_WORK_GROUP_SIZE = 0x1004
747
+ MAX_WORK_ITEM_SIZES = 0x1005
748
+ PREFERRED_VECTOR_WIDTH_CHAR = 0x1006
749
+ PREFERRED_VECTOR_WIDTH_SHORT = 0x1007
750
+ PREFERRED_VECTOR_WIDTH_INT = 0x1008
751
+ PREFERRED_VECTOR_WIDTH_LONG = 0x1009
752
+ PREFERRED_VECTOR_WIDTH_FLOAT = 0x100A
753
+ PREFERRED_VECTOR_WIDTH_DOUBLE = 0x100B
754
+ MAX_CLOCK_FREQUENCY = 0x100C
755
+ ADDRESS_BITS = 0x100D
756
+ MAX_READ_IMAGE_ARGS = 0x100E
757
+ MAX_WRITE_IMAGE_ARGS = 0x100F
758
+ MAX_MEM_ALLOC_SIZE = 0x1010
759
+ IMAGE2D_MAX_WIDTH = 0x1011
760
+ IMAGE2D_MAX_HEIGHT = 0x1012
761
+ IMAGE3D_MAX_WIDTH = 0x1013
762
+ IMAGE3D_MAX_HEIGHT = 0x1014
763
+ IMAGE3D_MAX_DEPTH = 0x1015
764
+ IMAGE_SUPPORT = 0x1016
765
+ MAX_PARAMETER_SIZE = 0x1017
766
+ MAX_SAMPLERS = 0x1018
767
+ MEM_BASE_ADDR_ALIGN = 0x1019
768
+ MIN_DATA_TYPE_ALIGN_SIZE = 0x101A
769
+ SINGLE_FP_CONFIG = 0x101B
770
+ GLOBAL_MEM_CACHE_TYPE = 0x101C
771
+ GLOBAL_MEM_CACHELINE_SIZE = 0x101D
772
+ GLOBAL_MEM_CACHE_SIZE = 0x101E
773
+ GLOBAL_MEM_SIZE = 0x101F
774
+ MAX_CONSTANT_BUFFER_SIZE = 0x1020
775
+ MAX_CONSTANT_ARGS = 0x1021
776
+ LOCAL_MEM_TYPE = 0x1022
777
+ LOCAL_MEM_SIZE = 0x1023
778
+ ERROR_CORRECTION_SUPPORT = 0x1024
779
+ PROFILING_TIMER_RESOLUTION = 0x1025
780
+ ENDIAN_LITTLE = 0x1026
781
+ AVAILABLE = 0x1027
782
+ COMPILER_AVAILABLE = 0x1028
783
+ EXECUTION_CAPABILITIES = 0x1029
784
+ QUEUE_PROPERTIES = 0x102A
785
+ NAME = 0x102B
786
+ VENDOR = 0x102C
787
+ PROFILE = 0x102E
788
+ VERSION = 0x102F
789
+ EXTENSIONS = 0x1030
790
+ PLATFORM = 0x1031
791
+ DOUBLE_FP_CONFIG = 0x1032
792
+ PREFERRED_VECTOR_WIDTH_HALF = 0x1034
793
+ HOST_UNIFIED_MEMORY = 0x1035
794
+ NATIVE_VECTOR_WIDTH_CHAR = 0x1036
795
+ NATIVE_VECTOR_WIDTH_SHORT = 0x1037
796
+ NATIVE_VECTOR_WIDTH_INT = 0x1038
797
+ NATIVE_VECTOR_WIDTH_LONG = 0x1039
798
+ NATIVE_VECTOR_WIDTH_FLOAT = 0x103A
799
+ NATIVE_VECTOR_WIDTH_DOUBLE = 0x103B
800
+ NATIVE_VECTOR_WIDTH_HALF = 0x103C
801
+ OPENCL_C_VERSION = 0x103D
802
+ LINKER_AVAILABLE = 0x103E
803
+ BUILT_IN_KERNELS = 0x103F
804
+ IMAGE_MAX_BUFFER_SIZE = 0x1040
805
+ IMAGE_MAX_ARRAY_SIZE = 0x1041
806
+ PARENT_DEVICE = 0x1042
807
+ PARTITION_MAX_SUB_DEVICES = 0x1043
808
+ PARTITION_PROPERTIES = 0x1044
809
+ PARTITION_AFFINITY_DOMAIN = 0x1045
810
+ PARTITION_TYPE = 0x1046
811
+ REFERENCE_COUNT = 0x1047
812
+ PREFERRED_INTEROP_USER_SYNC = 0x1048
813
+ PRINTF_BUFFER_SIZE = 0x1049
814
+ IMAGE_PITCH_ALIGNMENT = 0x104A
815
+ IMAGE_BASE_ADDRESS_ALIGNMENT = 0x104B
816
+ PARTITION_EQUALLY = 0x1086
817
+ PARTITION_BY_COUNTS = 0x1087
818
+ PARTITION_BY_COUNTS_LIST_END = 0x0
819
+ PARTITION_BY_AFFINITY_DOMAIN = 0x1088
820
+ AFFINITY_DOMAIN_NUMA = (1 << 0)
821
+ AFFINITY_DOMAIN_L4_CACHE = (1 << 1)
822
+ AFFINITY_DOMAIN_L3_CACHE = (1 << 2)
823
+ AFFINITY_DOMAIN_L2_CACHE = (1 << 3)
824
+ AFFINITY_DOMAIN_L1_CACHE = (1 << 4)
825
+ AFFINITY_DOMAIN_NEXT_PARTITIONABLE = (1 << 5)
826
+ HALF_FP_CONFIG = 0x1033
827
+ TERMINATE_CAPABILITY_KHR = 0x200F
828
+ COMPUTE_CAPABILITY_MAJOR_NV = 0x4000
829
+ COMPUTE_CAPABILITY_MINOR_NV = 0x4001
830
+ REGISTERS_PER_BLOCK_NV = 0x4002
831
+ WARP_SIZE_NV = 0x4003
832
+ GPU_OVERLAP_NV = 0x4004
833
+ KERNEL_EXEC_TIMEOUT_NV = 0x4005
834
+ INTEGRATED_MEMORY_NV = 0x4006
835
+ MAX_ATOMIC_COUNTERS_EXT = 0x4032
836
+ PROFILING_TIMER_OFFSET_AMD = 0x4036
837
+ TOPOLOGY_AMD = 0x4037
838
+ BOARD_NAME_AMD = 0x4038
839
+ GLOBAL_FREE_MEMORY_AMD = 0x4039
840
+ SIMD_PER_COMPUTE_UNIT_AMD = 0x4040
841
+ SIMD_WIDTH_AMD = 0x4041
842
+ SIMD_INSTRUCTION_WIDTH_AMD = 0x4042
843
+ WAVEFRONT_WIDTH_AMD = 0x4043
844
+ GLOBAL_MEM_CHANNELS_AMD = 0x4044
845
+ GLOBAL_MEM_CHANNEL_BANKS_AMD = 0x4045
846
+ GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD = 0x4046
847
+ LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD = 0x4047
848
+ LOCAL_MEM_BANKS_AMD = 0x4048
849
+ TOPOLOGY_TYPE_PCIE_AMD = 1
850
+ EXT_MEM_PADDING_IN_BYTES_QCOM = 0x40A0
851
+ PAGE_SIZE_QCOM = 0x40A1
852
+ #:startdoc:
853
+
854
+ # Creates a new Device and retains it if specified and aplicable
855
+ def initialize(ptr, retain = true)
856
+ super(ptr)
857
+ #STDERR.puts "Allocating Device: #{ptr}"
858
+ end
859
+
860
+ # method called at Device deletion, releases the object if aplicable
861
+ def self.release(ptr)
862
+ #STDERR.puts "Releasing Device: #{ptr}"
863
+ end
864
+ end
865
+
866
+ class Device
867
+ # Bitfield that maps the :cl_device_type type
868
+ class Type < OpenCL::Bitfield
869
+ #:stopdoc:
870
+ DEFAULT = (1 << 0)
871
+ CPU = (1 << 1)
872
+ GPU = (1 << 2)
873
+ ACCELERATOR = (1 << 3)
874
+ CUSTOM = (1 << 4)
875
+ ALL = 0xFFFFFFFF
876
+ #:startdoc:
877
+ # Returns an Array of String representing the different flags set
878
+ def names
879
+ fs = []
880
+ %w( DEFAULT CPU GPU ACCELERATOR CUSTOM ALL ).each { |f|
881
+ fs.push(f) if self.include?( self.class.const_get(f) )
882
+ }
883
+ return fs
884
+ end
885
+ end
886
+
887
+ # Bitfield that maps the :cl_device_fp_config type
888
+ class FPConfig < OpenCL::Bitfield
889
+ #:stopdoc:
890
+ DENORM = (1 << 0)
891
+ INF_NAN = (1 << 1)
892
+ ROUND_TO_NEAREST = (1 << 2)
893
+ ROUND_TO_ZERO = (1 << 3)
894
+ ROUND_TO_INF = (1 << 4)
895
+ FMA = (1 << 5)
896
+ SOFT_FLOAT = (1 << 6)
897
+ CORRECTLY_ROUNDED_DIVIDE_SQRT = (1 << 7)
898
+ #:startdoc:
899
+ # Returns an Array of String representing the different flags set
900
+ def names
901
+ fs = []
902
+ %w( DENORM INF_NAN ROUND_TO_NEAREST ROUND_TO_ZERO ROUND_TO_INF FMA SOFT_FLOAT CORRECTLY_ROUNDED_DIVIDE_SQRT ).each { |f|
903
+ fs.push(f) if self.include?( self.class.const_get(f) )
904
+ }
905
+ return fs
906
+ end
907
+ end
908
+
909
+ # Bitfield that maps the :cl_device_exec_capabilities type
910
+ class ExecCapabilities < OpenCL::Bitfield
911
+ #:stopdoc:
912
+ KERNEL = (1 << 0)
913
+ NATIVE_KERNEL = (1 << 1)
914
+ #:startdoc:
915
+ # Returns an Array of String representing the different flags set
916
+ def names
917
+ fs = []
918
+ %w( KERNEL NATIVE_KERNEL ).each { |f|
919
+ fs.push(f) if self.include?( self.class.const_get(f) )
920
+ }
921
+ return fs
922
+ end
923
+ end
924
+
925
+ # Enum that maps the :cl_device_mem_cache_type type
926
+ class MemCacheType < OpenCL::Enum
927
+ #:stopdoc:
928
+ NONE = 0x0
929
+ READ_ONLY_CACHE = 0x1
930
+ READ_WRITE_CACHE = 0x2
931
+ @@codes[0x0] = 'NONE'
932
+ @@codes[0x1] = 'READ_ONLY_CACHE'
933
+ @@codes[0x2] = 'READ_WRITE_CACHE'
934
+ #:startdoc:
935
+
936
+ # Returns a String representing the Enum value name
937
+ def name
938
+ return @@codes[@val]
939
+ end
940
+ end
941
+
942
+ # Enum that maps the :cl_device_local_mem_type type
943
+ class LocalMemType < OpenCL::Enum
944
+ #:stopdoc:
945
+ LOCAL = 0x1
946
+ GLOBAL = 0x2
947
+ @@codes[0x1] = 'LOCAL'
948
+ @@codes[0x2] = 'GLOBAL'
949
+ #:startdoc:
950
+
951
+ # Returns a String representing the Enum value name
952
+ def name
953
+ return @@codes[@val]
954
+ end
955
+ end
956
+
957
+ # Bitfield that maps the :cl_device_affinity_domain type
958
+ class AffinityDomain < OpenCL::Bitfield
959
+ #:stopdoc:
960
+ NUMA = (1 << 0)
961
+ L4_CACHE = (1 << 1)
962
+ L3_CACHE = (1 << 2)
963
+ L2_CACHE = (1 << 3)
964
+ L1_CACHE = (1 << 4)
965
+ NEXT_PARTITIONABLE = (1 << 5)
966
+ #:startdoc:
967
+ # Returns an Array of String representing the different flags set
968
+ def names
969
+ fs = []
970
+ %w( NUMA L4_CACHE L3_CACHE L2_CACHE L1_CACHE NEXT_PARTITIONABLE ).each { |f|
971
+ fs.push(f) if self.include?( self.class.const_get(f) )
972
+ }
973
+ return fs
974
+ end
975
+ end
976
+
977
+ end
978
+ class Context < FFI::ManagedStruct
979
+ layout :dummy, :pointer
980
+ #:stopdoc:
981
+ REFERENCE_COUNT = 0x1080
982
+ DEVICES = 0x1081
983
+ PROPERTIES = 0x1082
984
+ NUM_DEVICES = 0x1083
985
+ PLATFORM = 0x1084
986
+ INTEROP_USER_SYNC = 0x1085
987
+ MEMORY_INITIALIZE_KHR = 0x200E
988
+ TERMINATE_KHR = 0x2010
989
+ OFFLINE_DEVICES_AMD = 0x403F
990
+ #:startdoc:
991
+
992
+ # Creates a new Context and retains it if specified and aplicable
993
+ def initialize(ptr, retain = true)
994
+ super(ptr)
995
+ OpenCL.clRetainContext(ptr) if retain
996
+ #STDERR.puts "Allocating Context: #{ptr}"
997
+ end
998
+
999
+ # method called at Context deletion, releases the object if aplicable
1000
+ def self.release(ptr)
1001
+ #STDERR.puts "Releasing Context: #{ptr}"
1002
+ error = OpenCL.clReleaseContext(ptr)
1003
+ #STDERR.puts "Object released! #{error}"
1004
+ OpenCL.error_check( error )
1005
+ end
1006
+ end
1007
+
1008
+ class CommandQueue < FFI::ManagedStruct
1009
+ layout :dummy, :pointer
1010
+ #:stopdoc:
1011
+ OUT_OF_ORDER_EXEC_MODE_ENABLE = (1 << 0)
1012
+ PROFILING_ENABLE = (1 << 1)
1013
+ CONTEXT = 0x1090
1014
+ DEVICE = 0x1091
1015
+ REFERENCE_COUNT = 0x1092
1016
+ PROPERTIES = 0x1093
1017
+ #:startdoc:
1018
+
1019
+ # Creates a new CommandQueue and retains it if specified and aplicable
1020
+ def initialize(ptr, retain = true)
1021
+ super(ptr)
1022
+ OpenCL.clRetainCommandQueue(ptr) if retain
1023
+ #STDERR.puts "Allocating CommandQueue: #{ptr}"
1024
+ end
1025
+
1026
+ # method called at CommandQueue deletion, releases the object if aplicable
1027
+ def self.release(ptr)
1028
+ #STDERR.puts "Releasing CommandQueue: #{ptr}"
1029
+ error = OpenCL.clReleaseCommandQueue(ptr)
1030
+ #STDERR.puts "Object released! #{error}"
1031
+ OpenCL.error_check( error )
1032
+ end
1033
+ end
1034
+
1035
+ class CommandQueue
1036
+ class Properties < OpenCL::Bitfield
1037
+ #:stopdoc:
1038
+ OUT_OF_ORDER_EXEC_MODE_ENABLE = (1 << 0)
1039
+ PROFILING_ENABLE = (1 << 1)
1040
+ #:startdoc:
1041
+ # Returns an Array of String representing the different flags set
1042
+ def names
1043
+ fs = []
1044
+ %w( OUT_OF_ORDER_EXEC_MODE_ENABLE PROFILING_ENABLE ).each { |f|
1045
+ fs.push(f) if self.include?( self.class.const_get(f) )
1046
+ }
1047
+ return fs
1048
+ end
1049
+ end
1050
+
1051
+ end
1052
+ class Mem < FFI::ManagedStruct
1053
+ layout :dummy, :pointer
1054
+ #:stopdoc:
1055
+ READ_WRITE = (1 << 0)
1056
+ WRITE_ONLY = (1 << 1)
1057
+ READ_ONLY = (1 << 2)
1058
+ USE_HOST_PTR = (1 << 3)
1059
+ ALLOC_HOST_PTR = (1 << 4)
1060
+ COPY_HOST_PTR = (1 << 5)
1061
+ HOST_WRITE_ONLY = (1 << 7)
1062
+ HOST_READ_ONLY = (1 << 8)
1063
+ HOST_NO_ACCESS = (1 << 9)
1064
+ BUFFER = 0x10F0
1065
+ IMAGE2D = 0x10F1
1066
+ IMAGE3D = 0x10F2
1067
+ IMAGE2D_ARRAY = 0x10F3
1068
+ IMAGE1D = 0x10F4
1069
+ IMAGE1D_ARRAY = 0x10F5
1070
+ IMAGE1D_BUFFER = 0x10F6
1071
+ TYPE = 0x1100
1072
+ FLAGS = 0x1101
1073
+ SIZE = 0x1102
1074
+ HOST_PTR = 0x1103
1075
+ MAP_COUNT = 0x1104
1076
+ REFERENCE_COUNT = 0x1105
1077
+ CONTEXT = 0x1106
1078
+ ASSOCIATED_MEMOBJECT = 0x1107
1079
+ OFFSET = 0x1108
1080
+ USE_PERSISTENT_MEM_AMD = (1 << 6)
1081
+ EXT_HOST_PTR_QCOM = (1 << 29)
1082
+ HOST_UNCACHED_QCOM = 0x40A4
1083
+ HOST_WRITEBACK_QCOM = 0x40A5
1084
+ HOST_WRITETHROUGH_QCOM = 0x40A6
1085
+ HOST_WRITE_COMBINING_QCOM = 0x40A7
1086
+ ION_HOST_PTR_QCOM = 0x40A8
1087
+ #:startdoc:
1088
+
1089
+ # Creates a new Mem and retains it if specified and aplicable
1090
+ def initialize(ptr, retain = true)
1091
+ super(ptr)
1092
+ OpenCL.clRetainMemObject(ptr) if retain
1093
+ #STDERR.puts "Allocating Mem: #{ptr}"
1094
+ end
1095
+
1096
+ # method called at Mem deletion, releases the object if aplicable
1097
+ def self.release(ptr)
1098
+ #STDERR.puts "Releasing Mem: #{ptr}"
1099
+ error = OpenCL.clReleaseMemObject(ptr)
1100
+ #STDERR.puts "Object released! #{error}"
1101
+ OpenCL.error_check( error )
1102
+ end
1103
+ end
1104
+
1105
+ class Mem
1106
+ # Bitfield that maps the :cl_mem_flags type
1107
+ class Flags < OpenCL::Bitfield
1108
+ #:stopdoc:
1109
+ READ_WRITE = (1 << 0)
1110
+ WRITE_ONLY = (1 << 1)
1111
+ READ_ONLY = (1 << 2)
1112
+ USE_HOST_PTR = (1 << 3)
1113
+ ALLOC_HOST_PTR = (1 << 4)
1114
+ COPY_HOST_PTR = (1 << 5)
1115
+ HOST_WRITE_ONLY = (1 << 7)
1116
+ HOST_READ_ONLY = (1 << 8)
1117
+ HOST_NO_ACCESS = (1 << 9)
1118
+ #:startdoc:
1119
+ # Returns an Array of String representing the different flags set
1120
+ def names
1121
+ fs = []
1122
+ %w( READ_WRITE WRITE_ONLY READ_ONLY USE_HOST_PTR ALLOC_HOST_PTR COPY_HOST_PTR HOST_WRITE_ONLY HOST_READ_ONLY HOST_NO_ACCESS ).each { |f|
1123
+ fs.push(f) if self.include?( self.class.const_get(f) )
1124
+ }
1125
+ return fs
1126
+ end
1127
+ end
1128
+
1129
+ # Bitfield that maps the :cl_mem_migration_flags type
1130
+ class MigrationFlags < OpenCL::Bitfield
1131
+ #:stopdoc:
1132
+ HOST = (1 << 0)
1133
+ CONTENT_UNDEFINED = (1 << 1)
1134
+ #:startdoc:
1135
+ # Returns an Array of String representing the different flags set
1136
+ def names
1137
+ fs = []
1138
+ %w( HOST CONTENT_UNDEFINED ).each { |f|
1139
+ fs.push(f) if self.include?( self.class.const_get(f) )
1140
+ }
1141
+ return fs
1142
+ end
1143
+ end
1144
+
1145
+ # Enum that maps the :cl_mem_object_type
1146
+ class Type < OpenCL::Enum
1147
+ #:stopdoc:
1148
+ BUFFER = 0x10F0
1149
+ IMAGE2D = 0x10F1
1150
+ IMAGE3D = 0x10F2
1151
+ IMAGE2D_ARRAY = 0x10F3
1152
+ IMAGE1D = 0x10F4
1153
+ IMAGE1D_ARRAY = 0x10F5
1154
+ IMAGE1D_BUFFER = 0x10F6
1155
+ @@codes[0x10F0] = 'BUFFER'
1156
+ @@codes[0x10F1] = 'IMAGE2D'
1157
+ @@codes[0x10F2] = 'IMAGE3D'
1158
+ @@codes[0x10F3] = 'IMAGE2D_ARRAY'
1159
+ @@codes[0x10F4] = 'IMAGE1D'
1160
+ @@codes[0x10F5] = 'IMAGE1D_ARRAY'
1161
+ @@codes[0x10F6] = 'IMAGE1D_BUFFER'
1162
+ #:startdoc:
1163
+
1164
+ # Returns a String representing the Enum value name
1165
+ def name
1166
+ return @@codes[@val]
1167
+ end
1168
+ end
1169
+
1170
+ end
1171
+ class Program < FFI::ManagedStruct
1172
+ layout :dummy, :pointer
1173
+ #:stopdoc:
1174
+ REFERENCE_COUNT = 0x1160
1175
+ CONTEXT = 0x1161
1176
+ NUM_DEVICES = 0x1162
1177
+ DEVICES = 0x1163
1178
+ SOURCE = 0x1164
1179
+ BINARY_SIZES = 0x1165
1180
+ BINARIES = 0x1166
1181
+ NUM_KERNELS = 0x1167
1182
+ KERNEL_NAMES = 0x1168
1183
+ BUILD_STATUS = 0x1181
1184
+ BUILD_OPTIONS = 0x1182
1185
+ BUILD_LOG = 0x1183
1186
+ BINARY_TYPE = 0x1184
1187
+ BINARY_TYPE_NONE = 0x0
1188
+ BINARY_TYPE_COMPILED_OBJECT = 0x1
1189
+ BINARY_TYPE_LIBRARY = 0x2
1190
+ BINARY_TYPE_EXECUTABLE = 0x4
1191
+ #:startdoc:
1192
+
1193
+ # Creates a new Program and retains it if specified and aplicable
1194
+ def initialize(ptr, retain = true)
1195
+ super(ptr)
1196
+ OpenCL.clRetainProgram(ptr) if retain
1197
+ #STDERR.puts "Allocating Program: #{ptr}"
1198
+ end
1199
+
1200
+ # method called at Program deletion, releases the object if aplicable
1201
+ def self.release(ptr)
1202
+ #STDERR.puts "Releasing Program: #{ptr}"
1203
+ error = OpenCL.clReleaseProgram(ptr)
1204
+ #STDERR.puts "Object released! #{error}"
1205
+ OpenCL.error_check( error )
1206
+ end
1207
+ end
1208
+
1209
+ class Program
1210
+ # Enum that maps the :cl_program_binary_type type
1211
+ class BinaryType < OpenCL::Enum
1212
+ #:stopdoc:
1213
+ NONE = 0x0
1214
+ COMPILED_OBJECT = 0x1
1215
+ LIBRARY = 0x2
1216
+ EXECUTABLE = 0x4
1217
+ @@codes[0x0] = 'NONE'
1218
+ @@codes[0x1] = 'COMPILED_OBJECT'
1219
+ @@codes[0x2] = 'LIBRARY'
1220
+ @@codes[0x4] = 'EXECUTABLE'
1221
+ #:startdoc:
1222
+
1223
+ # Returns a String representing the Enum value name
1224
+ def name
1225
+ return @@codes[@val]
1226
+ end
1227
+ end
1228
+
1229
+ end
1230
+ class Kernel < FFI::ManagedStruct
1231
+ layout :dummy, :pointer
1232
+ #:stopdoc:
1233
+ FUNCTION_NAME = 0x1190
1234
+ NUM_ARGS = 0x1191
1235
+ REFERENCE_COUNT = 0x1192
1236
+ CONTEXT = 0x1193
1237
+ PROGRAM = 0x1194
1238
+ ATTRIBUTES = 0x1195
1239
+ ARG_ADDRESS_QUALIFIER = 0x1196
1240
+ ARG_ACCESS_QUALIFIER = 0x1197
1241
+ ARG_TYPE_NAME = 0x1198
1242
+ ARG_TYPE_QUALIFIER = 0x1199
1243
+ ARG_NAME = 0x119A
1244
+ ARG_ADDRESS_GLOBAL = 0x119B
1245
+ ARG_ADDRESS_LOCAL = 0x119C
1246
+ ARG_ADDRESS_CONSTANT = 0x119D
1247
+ ARG_ADDRESS_PRIVATE = 0x119E
1248
+ ARG_ACCESS_READ_ONLY = 0x11A0
1249
+ ARG_ACCESS_WRITE_ONLY = 0x11A1
1250
+ ARG_ACCESS_READ_WRITE = 0x11A2
1251
+ ARG_ACCESS_NONE = 0x11A3
1252
+ ARG_TYPE_NONE = 0
1253
+ ARG_TYPE_CONST = (1 << 0)
1254
+ ARG_TYPE_RESTRICT = (1 << 1)
1255
+ ARG_TYPE_VOLATILE = (1 << 2)
1256
+ WORK_GROUP_SIZE = 0x11B0
1257
+ COMPILE_WORK_GROUP_SIZE = 0x11B1
1258
+ LOCAL_MEM_SIZE = 0x11B2
1259
+ PREFERRED_WORK_GROUP_SIZE_MULTIPLE = 0x11B3
1260
+ PRIVATE_MEM_SIZE = 0x11B4
1261
+ GLOBAL_WORK_SIZE = 0x11B5
1262
+ #:startdoc:
1263
+
1264
+ # Creates a new Kernel and retains it if specified and aplicable
1265
+ def initialize(ptr, retain = true)
1266
+ super(ptr)
1267
+ OpenCL.clRetainKernel(ptr) if retain
1268
+ #STDERR.puts "Allocating Kernel: #{ptr}"
1269
+ end
1270
+
1271
+ # method called at Kernel deletion, releases the object if aplicable
1272
+ def self.release(ptr)
1273
+ #STDERR.puts "Releasing Kernel: #{ptr}"
1274
+ error = OpenCL.clReleaseKernel(ptr)
1275
+ #STDERR.puts "Object released! #{error}"
1276
+ OpenCL.error_check( error )
1277
+ end
1278
+ end
1279
+
1280
+ class Kernel
1281
+ # Maps the arg logical OpenCL objects
1282
+ class Arg
1283
+ #:stopdoc:
1284
+ ADDRESS_QUALIFIER = 0x1196
1285
+ ACCESS_QUALIFIER = 0x1197
1286
+ TYPE_NAME = 0x1198
1287
+ TYPE_QUALIFIER = 0x1199
1288
+ NAME = 0x119A
1289
+ ADDRESS_GLOBAL = 0x119B
1290
+ ADDRESS_LOCAL = 0x119C
1291
+ ADDRESS_CONSTANT = 0x119D
1292
+ ADDRESS_PRIVATE = 0x119E
1293
+ ACCESS_READ_ONLY = 0x11A0
1294
+ ACCESS_WRITE_ONLY = 0x11A1
1295
+ ACCESS_READ_WRITE = 0x11A2
1296
+ ACCESS_NONE = 0x11A3
1297
+ TYPE_NONE = 0
1298
+ TYPE_CONST = (1 << 0)
1299
+ TYPE_RESTRICT = (1 << 1)
1300
+ TYPE_VOLATILE = (1 << 2)
1301
+ #:startdoc:
1302
+ end
1303
+
1304
+ class Arg
1305
+ # Enum that maps the :cl_kernel_arg_address_qualifier type
1306
+ class AddressQualifier < OpenCL::Enum
1307
+ #:stopdoc:
1308
+ GLOBAL = 0x119B
1309
+ LOCAL = 0x119C
1310
+ CONSTANT = 0x119D
1311
+ PRIVATE = 0x119E
1312
+ @@codes[0x119B] = 'GLOBAL'
1313
+ @@codes[0x119C] = 'LOCAL'
1314
+ @@codes[0x119D] = 'CONSTANT'
1315
+ @@codes[0x119E] = 'PRIVATE'
1316
+ #:startdoc:
1317
+
1318
+ # Returns a String representing the Enum value name
1319
+ def name
1320
+ return @@codes[@val]
1321
+ end
1322
+ end
1323
+
1324
+ # Enum that maps the :cl_kernel_arg_access_qualifier type
1325
+ class AccessQualifier < OpenCL::Enum
1326
+ #:stopdoc:
1327
+ READ_ONLY = 0x11A0
1328
+ WRITE_ONLY = 0x11A1
1329
+ READ_WRITE = 0x11A2
1330
+ NONE = 0x11A3
1331
+ @@codes[0x11A0] = 'READ_ONLY'
1332
+ @@codes[0x11A1] = 'WRITE_ONLY'
1333
+ @@codes[0x11A2] = 'READ_WRITE'
1334
+ @@codes[0x11A3] = 'NONE'
1335
+ #:startdoc:
1336
+
1337
+ # Returns a String representing the Enum value name
1338
+ def name
1339
+ return @@codes[@val]
1340
+ end
1341
+ end
1342
+
1343
+ # Bitfield that maps the :cl_kernel_arg_type_qualifier type
1344
+ class TypeQualifier < OpenCL::Bitfield
1345
+ #:stopdoc:
1346
+ NONE = 0
1347
+ CONST = (1 << 0)
1348
+ RESTRICT = (1 << 1)
1349
+ VOLATILE = (1 << 2)
1350
+ #:startdoc:
1351
+ # Returns an Array of String representing the different flags set
1352
+ def names
1353
+ fs = []
1354
+ %w( NONE CONST RESTRICT VOLATILE ).each { |f|
1355
+ fs.push(f) if self.include?( self.class.const_get(f) )
1356
+ }
1357
+ return fs
1358
+ end
1359
+ end
1360
+
1361
+ end
1362
+ end
1363
+ class Event < FFI::ManagedStruct
1364
+ layout :dummy, :pointer
1365
+ #:stopdoc:
1366
+ COMMAND_QUEUE = 0x11D0
1367
+ COMMAND_TYPE = 0x11D1
1368
+ REFERENCE_COUNT = 0x11D2
1369
+ COMMAND_EXECUTION_STATUS = 0x11D3
1370
+ CONTEXT = 0x11D4
1371
+ #:startdoc:
1372
+
1373
+ # Creates a new Event and retains it if specified and aplicable
1374
+ def initialize(ptr, retain = true)
1375
+ super(ptr)
1376
+ OpenCL.clRetainEvent(ptr) if retain
1377
+ #STDERR.puts "Allocating Event: #{ptr}"
1378
+ end
1379
+
1380
+ # method called at Event deletion, releases the object if aplicable
1381
+ def self.release(ptr)
1382
+ #STDERR.puts "Releasing Event: #{ptr}"
1383
+ error = OpenCL.clReleaseEvent(ptr)
1384
+ #STDERR.puts "Object released! #{error}"
1385
+ OpenCL.error_check( error )
1386
+ end
1387
+ end
1388
+
1389
+ class Sampler < FFI::ManagedStruct
1390
+ layout :dummy, :pointer
1391
+ #:stopdoc:
1392
+ REFERENCE_COUNT = 0x1150
1393
+ CONTEXT = 0x1151
1394
+ NORMALIZED_COORDS = 0x1152
1395
+ ADDRESSING_MODE = 0x1153
1396
+ FILTER_MODE = 0x1154
1397
+ #:startdoc:
1398
+
1399
+ # Creates a new Sampler and retains it if specified and aplicable
1400
+ def initialize(ptr, retain = true)
1401
+ super(ptr)
1402
+ OpenCL.clRetainSampler(ptr) if retain
1403
+ #STDERR.puts "Allocating Sampler: #{ptr}"
1404
+ end
1405
+
1406
+ # method called at Sampler deletion, releases the object if aplicable
1407
+ def self.release(ptr)
1408
+ #STDERR.puts "Releasing Sampler: #{ptr}"
1409
+ error = OpenCL.clReleaseSampler(ptr)
1410
+ #STDERR.puts "Object released! #{error}"
1411
+ OpenCL.error_check( error )
1412
+ end
1413
+ end
1414
+
1415
+ class GLsync < FFI::ManagedStruct
1416
+ layout :dummy, :pointer
1417
+ #:stopdoc:
1418
+
1419
+ #:startdoc:
1420
+
1421
+ # Creates a new GLsync and retains it if specified and aplicable
1422
+ def initialize(ptr, retain = true)
1423
+ super(ptr)
1424
+ #STDERR.puts "Allocating GLsync: #{ptr}"
1425
+ end
1426
+
1427
+ # method called at GLsync deletion, releases the object if aplicable
1428
+ def self.release(ptr)
1429
+ #STDERR.puts "Releasing GLsync: #{ptr}"
1430
+ end
1431
+ end
1432
+
1433
+ # Enum that maps the :cl_channel_order type
1434
+ class ChannelOrder < OpenCL::Enum
1435
+ #:stopdoc:
1436
+ R = 0x10B0
1437
+ A = 0x10B1
1438
+ RG = 0x10B2
1439
+ RA = 0x10B3
1440
+ RGB = 0x10B4
1441
+ RGBA = 0x10B5
1442
+ BGRA = 0x10B6
1443
+ ARGB = 0x10B7
1444
+ INTENSITY = 0x10B8
1445
+ LUMINANCE = 0x10B9
1446
+ Rx = 0x10BA
1447
+ RGx = 0x10BB
1448
+ RGBx = 0x10BC
1449
+ DEPTH = 0x10BD
1450
+ DEPTH_STENCIL = 0x10BE
1451
+ @@codes[0x10B0] = 'R'
1452
+ @@codes[0x10B1] = 'A'
1453
+ @@codes[0x10B2] = 'RG'
1454
+ @@codes[0x10B3] = 'RA'
1455
+ @@codes[0x10B4] = 'RGB'
1456
+ @@codes[0x10B5] = 'RGBA'
1457
+ @@codes[0x10B6] = 'BGRA'
1458
+ @@codes[0x10B7] = 'ARGB'
1459
+ @@codes[0x10B8] = 'INTENSITY'
1460
+ @@codes[0x10B9] = 'LUMINANCE'
1461
+ @@codes[0x10BA] = 'Rx'
1462
+ @@codes[0x10BB] = 'RGx'
1463
+ @@codes[0x10BC] = 'RGBx'
1464
+ @@codes[0x10BD] = 'DEPTH'
1465
+ @@codes[0x10BE] = 'DEPTH_STENCIL'
1466
+ #:startdoc:
1467
+
1468
+ # Returns a String representing the Enum value name
1469
+ def name
1470
+ return @@codes[@val]
1471
+ end
1472
+ end
1473
+
1474
+ # Enum that maps the :cl_channel_type type
1475
+ class ChannelType < OpenCL::Enum
1476
+ #:stopdoc:
1477
+ SNORM_INT8 = 0x10D0
1478
+ SNORM_INT16 = 0x10D1
1479
+ UNORM_INT8 = 0x10D2
1480
+ UNORM_INT16 = 0x10D3
1481
+ UNORM_SHORT_565 = 0x10D4
1482
+ UNORM_SHORT_555 = 0x10D5
1483
+ UNORM_INT_101010 = 0x10D6
1484
+ SIGNED_INT8 = 0x10D7
1485
+ SIGNED_INT16 = 0x10D8
1486
+ SIGNED_INT32 = 0x10D9
1487
+ UNSIGNED_INT8 = 0x10DA
1488
+ UNSIGNED_INT16 = 0x10DB
1489
+ UNSIGNED_INT32 = 0x10DC
1490
+ HALF_FLOAT = 0x10DD
1491
+ FLOAT = 0x10DE
1492
+ UNORM_INT24 = 0x10DF
1493
+ @@codes[0x10D0] = 'SNORM_INT8'
1494
+ @@codes[0x10D1] = 'SNORM_INT16'
1495
+ @@codes[0x10D2] = 'UNORM_INT8'
1496
+ @@codes[0x10D3] = 'UNORM_INT16'
1497
+ @@codes[0x10D4] = 'UNORM_SHORT_565'
1498
+ @@codes[0x10D5] = 'UNORM_SHORT_555'
1499
+ @@codes[0x10D6] = 'UNORM_INT_101010'
1500
+ @@codes[0x10D7] = 'SIGNED_INT8'
1501
+ @@codes[0x10D8] = 'SIGNED_INT16'
1502
+ @@codes[0x10D9] = 'SIGNED_INT32'
1503
+ @@codes[0x10DA] = 'UNSIGNED_INT8'
1504
+ @@codes[0x10DB] = 'UNSIGNED_INT16'
1505
+ @@codes[0x10DC] = 'UNSIGNED_INT32'
1506
+ @@codes[0x10DD] = 'HALF_FLOAT'
1507
+ @@codes[0x10DE] = 'FLOAT'
1508
+ @@codes[0x10DF] = 'UNORM_INT24'
1509
+ #:startdoc:
1510
+
1511
+ # Returns a String representing the Enum value name
1512
+ def name
1513
+ return @@codes[@val]
1514
+ end
1515
+ end
1516
+
1517
+ # Enum that maps the :cl_addressing_mode type
1518
+ class AddressingMode < OpenCL::Enum
1519
+ #:stopdoc:
1520
+ NONE = 0x1130
1521
+ CLAMP_TO_EDGE = 0x1131
1522
+ CLAMP = 0x1132
1523
+ REPEAT = 0x1133
1524
+ MIRRORED_REPEAT = 0x1134
1525
+ @@codes[0x1130] = 'NONE'
1526
+ @@codes[0x1131] = 'CLAMP_TO_EDGE'
1527
+ @@codes[0x1132] = 'CLAMP'
1528
+ @@codes[0x1133] = 'REPEAT'
1529
+ @@codes[0x1134] = 'MIRRORED_REPEAT'
1530
+ #:startdoc:
1531
+
1532
+ # Returns a String representing the Enum value name
1533
+ def name
1534
+ return @@codes[@val]
1535
+ end
1536
+ end
1537
+
1538
+ # Enum that maps the :cl_filter_mode type
1539
+ class FilterMode < OpenCL::Enum
1540
+ #:stopdoc:
1541
+ NEAREST = 0x1140
1542
+ LINEAR = 0x1141
1543
+ @@codes[0x1140] = 'NEAREST'
1544
+ @@codes[0x1141] = 'LINEAR'
1545
+ #:startdoc:
1546
+
1547
+ # Returns a String representing the Enum value name
1548
+ def name
1549
+ return @@codes[@val]
1550
+ end
1551
+ end
1552
+
1553
+ # Bitfield that maps the :cl_map_flags type
1554
+ class MapFlags < OpenCL::Bitfield
1555
+ #:stopdoc:
1556
+ READ = (1 << 0)
1557
+ WRITE = (1 << 1)
1558
+ WRITE_INVALIDATE_REGION = (1 << 2)
1559
+ #:startdoc:
1560
+ # Returns an Array of String representing the different flags set
1561
+ def names
1562
+ fs = []
1563
+ %w( READ WRITE WRITE_INVALIDATE_REGION ).each { |f|
1564
+ fs.push(f) if self.include?( self.class.const_get(f) )
1565
+ }
1566
+ return fs
1567
+ end
1568
+ end
1569
+
1570
+ # Enum that maps the :cl_command_type type
1571
+ class CommandType < OpenCL::Enum
1572
+ #:stopdoc:
1573
+ NDRANGE_KERNEL = 0x11F0
1574
+ TASK = 0x11F1
1575
+ NATIVE_KERNEL = 0x11F2
1576
+ READ_BUFFER = 0x11F3
1577
+ WRITE_BUFFER = 0x11F4
1578
+ COPY_BUFFER = 0x11F5
1579
+ READ_IMAGE = 0x11F6
1580
+ WRITE_IMAGE = 0x11F7
1581
+ COPY_IMAGE = 0x11F8
1582
+ COPY_IMAGE_TO_BUFFER = 0x11F9
1583
+ COPY_BUFFER_TO_IMAGE = 0x11FA
1584
+ MAP_BUFFER = 0x11FB
1585
+ MAP_IMAGE = 0x11FC
1586
+ UNMAP_MEM_OBJECT = 0x11FD
1587
+ MARKER = 0x11FE
1588
+ ACQUIRE_GL_OBJECTS = 0x11FF
1589
+ RELEASE_GL_OBJECTS = 0x1200
1590
+ READ_BUFFER_RECT = 0x1201
1591
+ WRITE_BUFFER_RECT = 0x1202
1592
+ COPY_BUFFER_RECT = 0x1203
1593
+ USER = 0x1204
1594
+ BARRIER = 0x1205
1595
+ MIGRATE_MEM_OBJECTS = 0x1206
1596
+ FILL_BUFFER = 0x1207
1597
+ FILL_IMAGE = 0x1208
1598
+ @@codes[0x11F0] = 'NDRANGE_KERNEL'
1599
+ @@codes[0x11F1] = 'TASK'
1600
+ @@codes[0x11F2] = 'NATIVE_KERNEL'
1601
+ @@codes[0x11F3] = 'READ_BUFFER'
1602
+ @@codes[0x11F4] = 'WRITE_BUFFER'
1603
+ @@codes[0x11F5] = 'COPY_BUFFER'
1604
+ @@codes[0x11F6] = 'READ_IMAGE'
1605
+ @@codes[0x11F7] = 'WRITE_IMAGE'
1606
+ @@codes[0x11F8] = 'COPY_IMAGE'
1607
+ @@codes[0x11F9] = 'COPY_IMAGE_TO_BUFFER'
1608
+ @@codes[0x11FA] = 'COPY_BUFFER_TO_IMAGE'
1609
+ @@codes[0x11FB] = 'MAP_BUFFER'
1610
+ @@codes[0x11FC] = 'MAP_IMAGE'
1611
+ @@codes[0x11FD] = 'UNMAP_MEM_OBJECT'
1612
+ @@codes[0x11FE] = 'MARKER'
1613
+ @@codes[0x11FF] = 'ACQUIRE_GL_OBJECTS'
1614
+ @@codes[0x1200] = 'RELEASE_GL_OBJECTS'
1615
+ @@codes[0x1201] = 'READ_BUFFER_RECT'
1616
+ @@codes[0x1202] = 'WRITE_BUFFER_RECT'
1617
+ @@codes[0x1203] = 'COPY_BUFFER_RECT'
1618
+ @@codes[0x1204] = 'USER'
1619
+ @@codes[0x1205] = 'BARRIER'
1620
+ @@codes[0x1206] = 'MIGRATE_MEM_OBJECTS'
1621
+ @@codes[0x1207] = 'FILL_BUFFER'
1622
+ @@codes[0x1208] = 'FILL_IMAGE'
1623
+ #:startdoc:
1624
+
1625
+ # Returns a String representing the Enum value name
1626
+ def name
1627
+ return @@codes[@val]
1628
+ end
1629
+ end
1630
+
1631
+ # Enum that maps the :cl_gl_object_type type
1632
+ class GLObjectType < OpenCL::Enum
1633
+ #:stopdoc:
1634
+ BUFFER = 0x2000
1635
+ TEXTURE2D = 0x2001
1636
+ TEXTURE3D = 0x2002
1637
+ RENDERBUFFER = 0x2003
1638
+ TEXTURE2D_ARRAY = 0x200E
1639
+ TEXTURE1D = 0x200F
1640
+ TEXTURE1D_ARRAY = 0x2010
1641
+ TEXTURE_BUFFER = 0x2011
1642
+ @@codes[0x2000] = 'BUFFER'
1643
+ @@codes[0x2001] = 'TEXTURE2D'
1644
+ @@codes[0x2002] = 'TEXTURE3D'
1645
+ @@codes[0x2003] = 'RENDERBUFFER'
1646
+ @@codes[0x200E] = 'TEXTURE2D_ARRAY'
1647
+ @@codes[0x200F] = 'TEXTURE1D'
1648
+ @@codes[0x2010] = 'TEXTURE1D_ARRAY'
1649
+ @@codes[0x2011] = 'TEXTURE_BUFFER'
1650
+ #:startdoc:
1651
+
1652
+ # Returns a String representing the Enum value name
1653
+ def name
1654
+ return @@codes[@val]
1655
+ end
1656
+ end
1657
+
1658
+ # Enum that maps the :cl_build_status type
1659
+ class BuildStatus < OpenCL::EnumInt
1660
+ #:stopdoc:
1661
+ SUCCESS = 0
1662
+ NONE = -1
1663
+ ERROR = -2
1664
+ IN_PROGRESS = -3
1665
+ @@codes[0] = 'SUCCESS'
1666
+ @@codes[-1] = 'NONE'
1667
+ @@codes[-2] = 'ERROR'
1668
+ @@codes[-3] = 'IN_PROGRESS'
1669
+ #:startdoc:
1670
+
1671
+ # Returns a String representing the Enum value name
1672
+ def name
1673
+ return @@codes[@val]
1674
+ end
1675
+ end
1676
+
1677
+ # Enum that maps the command execution status logical type
1678
+ class CommandExecutionStatus < OpenCL::EnumInt
1679
+ #:stopdoc:
1680
+ COMPLETE = 0x0
1681
+ RUNNING = 0x1
1682
+ SUBMITTED = 0x2
1683
+ QUEUED = 0x3
1684
+ @@codes[0x0] = 'COMPLETE'
1685
+ @@codes[0x1] = 'RUNNING'
1686
+ @@codes[0x2] = 'SUBMITTED'
1687
+ @@codes[0x3] = 'QUEUED'
1688
+ #:startdoc:
1689
+
1690
+ # Returns a String representing the Enum value name
1691
+ def name
1692
+ return @@codes[@val]
1693
+ end
1694
+ end
1695
+
1696
+ class Image < Mem
1697
+ layout :dummy, :pointer
1698
+ #:stopdoc:
1699
+ FORMAT_MISMATCH = -9
1700
+ FORMAT_NOT_SUPPORTED = -10
1701
+ FORMAT = 0x1110
1702
+ ELEMENT_SIZE = 0x1111
1703
+ ROW_PITCH = 0x1112
1704
+ SLICE_PITCH = 0x1113
1705
+ WIDTH = 0x1114
1706
+ HEIGHT = 0x1115
1707
+ DEPTH = 0x1116
1708
+ ARRAY_SIZE = 0x1117
1709
+ BUFFER = 0x1118
1710
+ NUM_MIP_LEVELS = 0x1119
1711
+ NUM_SAMPLES = 0x111A
1712
+ ROW_ALIGNMENT_QCOM = 0x40A2
1713
+ SLICE_ALIGNMENT_QCOM = 0x40A3
1714
+ #:startdoc:
1715
+ end
1716
+ attach_function :clGetPlatformIDs, [:cl_uint,:pointer,:pointer], :cl_int
1717
+ attach_function :clGetPlatformInfo, [Platform,:cl_platform_info,:size_t,:pointer,:pointer], :cl_int
1718
+ attach_function :clGetDeviceIDs, [Platform,:cl_device_type,:cl_uint,:pointer,:pointer], :cl_int
1719
+ attach_function :clGetDeviceInfo, [Device,:cl_device_info,:size_t,:pointer,:pointer], :cl_int
1720
+ attach_function :clCreateSubDevices, [Device,:pointer,:cl_uint,:pointer,:pointer], :cl_int
1721
+ attach_function :clRetainDevice, [Device], :cl_int
1722
+ attach_function :clReleaseDevice, [Device], :cl_int
1723
+ callback :clCreateContext_notify, [:pointer,:pointer,:size_t,:pointer], :void
1724
+ attach_function :clCreateContext, [:pointer,:cl_uint,:pointer,:clCreateContext_notify,:pointer,:pointer], Context
1725
+ callback :clCreateContextFromType_notify, [:pointer,:pointer,:size_t,:pointer], :void
1726
+ attach_function :clCreateContextFromType, [:pointer,:cl_device_type,:clCreateContextFromType_notify,:pointer,:pointer], Context
1727
+ attach_function :clRetainContext, [Context], :cl_int
1728
+ attach_function :clReleaseContext, [Context], :cl_int
1729
+ attach_function :clGetContextInfo, [Context,:cl_context_info,:size_t,:pointer,:pointer], :cl_int
1730
+ attach_function :clCreateCommandQueue, [Context,Device,:cl_command_queue_properties,:pointer], CommandQueue
1731
+ attach_function :clRetainCommandQueue, [CommandQueue], :cl_int
1732
+ attach_function :clReleaseCommandQueue, [CommandQueue], :cl_int
1733
+ attach_function :clGetCommandQueueInfo, [CommandQueue,:cl_command_queue_info,:size_t,:pointer,:pointer], :cl_int
1734
+ attach_function :clCreateBuffer, [Context,:cl_mem_flags,:size_t,:pointer,:pointer], Mem
1735
+ attach_function :clCreateSubBuffer, [Mem,:cl_mem_flags,:cl_buffer_create_type,:pointer,:pointer], Mem
1736
+ attach_function :clCreateImage, [Context,:cl_mem_flags,:pointer,:pointer,:pointer,:pointer], Mem
1737
+ attach_function :clRetainMemObject, [Mem], :cl_int
1738
+ attach_function :clReleaseMemObject, [Mem], :cl_int
1739
+ attach_function :clGetSupportedImageFormats, [Context,:cl_mem_flags,:cl_mem_object_type,:cl_uint,:pointer,:pointer], :cl_int
1740
+ attach_function :clGetMemObjectInfo, [Mem,:cl_mem_info,:size_t,:pointer,:pointer], :cl_int
1741
+ attach_function :clGetImageInfo, [Mem,:cl_image_info,:size_t,:pointer,:pointer], :cl_int
1742
+ callback :clSetMemObjectDestructorCallback_notify, [Mem.by_ref,:pointer], :void
1743
+ attach_function :clSetMemObjectDestructorCallback, [Mem,:clSetMemObjectDestructorCallback_notify,:pointer], :cl_int
1744
+ attach_function :clCreateSampler, [Context,:cl_bool,:cl_addressing_mode,:cl_filter_mode,:pointer], Sampler
1745
+ attach_function :clRetainSampler, [Sampler], :cl_int
1746
+ attach_function :clReleaseSampler, [Sampler], :cl_int
1747
+ attach_function :clGetSamplerInfo, [Sampler,:cl_sampler_info,:size_t,:pointer,:pointer], :cl_int
1748
+ attach_function :clCreateProgramWithSource, [Context,:cl_uint,:pointer,:pointer,:pointer], Program
1749
+ attach_function :clCreateProgramWithBinary, [Context,:cl_uint,:pointer,:pointer,:pointer,:pointer,:pointer], Program
1750
+ attach_function :clCreateProgramWithBuiltInKernels, [Context,:cl_uint,:pointer,:pointer,:pointer], Program
1751
+ attach_function :clRetainProgram, [Program], :cl_int
1752
+ attach_function :clReleaseProgram, [Program], :cl_int
1753
+ callback :clBuildProgram_notify, [Program.by_ref,:pointer], :void
1754
+ attach_function :clBuildProgram, [Program,:cl_uint,:pointer,:pointer,:clBuildProgram_notify,:pointer], :cl_int
1755
+ callback :clCompileProgram_notify, [Program.by_ref,:pointer], :void
1756
+ attach_function :clCompileProgram, [Program,:cl_uint,:pointer,:pointer,:cl_uint,:pointer,:pointer,:clCompileProgram_notify,:pointer], :cl_int
1757
+ callback :clLinkProgram_notify, [Program.by_ref,:pointer], :void
1758
+ attach_function :clLinkProgram, [Context,:cl_uint,:pointer,:pointer,:cl_uint,:pointer,:clLinkProgram_notify,:pointer,:pointer], Program
1759
+ attach_function :clUnloadPlatformCompiler, [Platform], :cl_int
1760
+ attach_function :clGetProgramInfo, [Program,:cl_program_info,:size_t,:pointer,:pointer], :cl_int
1761
+ attach_function :clGetProgramBuildInfo, [Program,Device,:cl_program_build_info,:size_t,:pointer,:pointer], :cl_int
1762
+ attach_function :clCreateKernel, [Program,:pointer,:pointer], Kernel
1763
+ attach_function :clCreateKernelsInProgram, [Program,:cl_uint,:pointer,:pointer], :cl_int
1764
+ attach_function :clRetainKernel, [Kernel], :cl_int
1765
+ attach_function :clReleaseKernel, [Kernel], :cl_int
1766
+ attach_function :clSetKernelArg, [Kernel,:cl_uint,:size_t,:pointer], :cl_int
1767
+ attach_function :clGetKernelInfo, [Kernel,:cl_kernel_info,:size_t,:pointer,:pointer], :cl_int
1768
+ attach_function :clGetKernelArgInfo, [Kernel,:cl_uint,:cl_kernel_arg_info,:size_t,:pointer,:pointer], :cl_int
1769
+ attach_function :clGetKernelWorkGroupInfo, [Kernel,Device,:cl_kernel_work_group_info,:size_t,:pointer,:pointer], :cl_int
1770
+ attach_function :clWaitForEvents, [:cl_uint,:pointer], :cl_int
1771
+ attach_function :clGetEventInfo, [Event,:cl_event_info,:size_t,:pointer,:pointer], :cl_int
1772
+ attach_function :clCreateUserEvent, [Context,:pointer], Event
1773
+ attach_function :clRetainEvent, [Event], :cl_int
1774
+ attach_function :clReleaseEvent, [Event], :cl_int
1775
+ attach_function :clSetUserEventStatus, [Event,:cl_int], :cl_int
1776
+ callback :clSetEventCallback_notify, [Event.by_ref,:cl_int,:pointer], :void
1777
+ attach_function :clSetEventCallback, [Event,:cl_int,:clSetEventCallback_notify,:pointer], :cl_int
1778
+ attach_function :clGetEventProfilingInfo, [Event,:cl_profiling_info,:size_t,:pointer,:pointer], :cl_int
1779
+ attach_function :clFlush, [CommandQueue], :cl_int
1780
+ attach_function :clFinish, [CommandQueue], :cl_int
1781
+ attach_function :clEnqueueReadBuffer, [CommandQueue,Mem,:cl_bool,:size_t,:size_t,:pointer,:cl_uint,:pointer,:pointer], :cl_int
1782
+ attach_function :clEnqueueReadBufferRect, [CommandQueue,Mem,:cl_bool,:pointer,:pointer,:pointer,:size_t,:size_t,:size_t,:size_t,:pointer,:cl_uint,:pointer,:pointer], :cl_int
1783
+ attach_function :clEnqueueWriteBuffer, [CommandQueue,Mem,:cl_bool,:size_t,:size_t,:pointer,:cl_uint,:pointer,:pointer], :cl_int
1784
+ attach_function :clEnqueueWriteBufferRect, [CommandQueue,Mem,:cl_bool,:pointer,:pointer,:pointer,:size_t,:size_t,:size_t,:size_t,:pointer,:cl_uint,:pointer,:pointer], :cl_int
1785
+ attach_function :clEnqueueFillBuffer, [CommandQueue,Mem,:pointer,:size_t,:size_t,:size_t,:cl_uint,:pointer,:pointer], :cl_int
1786
+ attach_function :clEnqueueCopyBuffer, [CommandQueue,Mem,Mem,:size_t,:size_t,:size_t,:cl_uint,:pointer,:pointer], :cl_int
1787
+ attach_function :clEnqueueCopyBufferRect, [CommandQueue,Mem,Mem,:pointer,:pointer,:pointer,:size_t,:size_t,:size_t,:size_t,:cl_uint,:pointer,:pointer], :cl_int
1788
+ attach_function :clEnqueueReadImage, [CommandQueue,Mem,:cl_bool,:pointer,:pointer,:size_t,:size_t,:pointer,:cl_uint,:pointer,:pointer], :cl_int
1789
+ attach_function :clEnqueueWriteImage, [CommandQueue,Mem,:cl_bool,:pointer,:pointer,:size_t,:size_t,:pointer,:cl_uint,:pointer,:pointer], :cl_int
1790
+ attach_function :clEnqueueFillImage, [CommandQueue,Mem,:pointer,:pointer,:pointer,:cl_uint,:pointer,:pointer], :cl_int
1791
+ attach_function :clEnqueueCopyImage, [CommandQueue,Mem,Mem,:pointer,:pointer,:pointer,:cl_uint,:pointer,:pointer], :cl_int
1792
+ attach_function :clEnqueueCopyImageToBuffer, [CommandQueue,Mem,Mem,:pointer,:pointer,:size_t,:cl_uint,:pointer,:pointer], :cl_int
1793
+ attach_function :clEnqueueCopyBufferToImage, [CommandQueue,Mem,Mem,:size_t,:pointer,:pointer,:cl_uint,:pointer,:pointer], :cl_int
1794
+ attach_function :clEnqueueMapBuffer, [CommandQueue,Mem,:cl_bool,:cl_map_flags,:size_t,:size_t,:cl_uint,:pointer,:pointer,:pointer], :pointer
1795
+ attach_function :clEnqueueMapImage, [CommandQueue,Mem,:cl_bool,:cl_map_flags,:pointer,:pointer,:pointer,:pointer,:cl_uint,:pointer,:pointer,:pointer], :pointer
1796
+ attach_function :clEnqueueUnmapMemObject, [CommandQueue,Mem,:pointer,:cl_uint,:pointer,:pointer], :cl_int
1797
+ attach_function :clEnqueueMigrateMemObjects, [CommandQueue,:cl_uint,:pointer,:cl_mem_migration_flags,:cl_uint,:pointer,:pointer], :cl_int
1798
+ attach_function :clEnqueueNDRangeKernel, [CommandQueue,Kernel,:cl_uint,:pointer,:pointer,:pointer,:cl_uint,:pointer,:pointer], :cl_int
1799
+ attach_function :clEnqueueTask, [CommandQueue,Kernel,:cl_uint,:pointer,:pointer], :cl_int
1800
+ callback :clEnqueueNativeKernel_notify, [:pointer], :void
1801
+ attach_function :clEnqueueNativeKernel, [CommandQueue,:clEnqueueNativeKernel_notify,:pointer,:size_t,:cl_uint,:pointer,:pointer,:cl_uint,:pointer,:pointer], :cl_int
1802
+ attach_function :clEnqueueMarkerWithWaitList, [CommandQueue,:cl_uint,:pointer,:pointer], :cl_int
1803
+ attach_function :clEnqueueBarrierWithWaitList, [CommandQueue,:cl_uint,:pointer,:pointer], :cl_int
1804
+ attach_function :clGetExtensionFunctionAddressForPlatform, [Platform,:pointer], :pointer
1805
+ attach_function :clCreateImage2D, [Context,:cl_mem_flags,:pointer,:size_t,:size_t,:size_t,:pointer,:pointer], Mem
1806
+ attach_function :clCreateImage3D, [Context,:cl_mem_flags,:pointer,:size_t,:size_t,:size_t,:size_t,:size_t,:pointer,:pointer], Mem
1807
+ attach_function :clEnqueueMarker, [CommandQueue,:pointer], :cl_int
1808
+ attach_function :clEnqueueWaitForEvents, [CommandQueue,:cl_uint,:pointer], :cl_int
1809
+ attach_function :clEnqueueBarrier, [CommandQueue], :cl_int
1810
+ attach_function :clUnloadCompiler, [:void], :cl_int
1811
+ attach_function :clGetExtensionFunctionAddress, [:pointer], :pointer
1812
+ attach_function :clCreateFromGLBuffer, [Context,:cl_mem_flags,:cl_GLuint,:pointer], Mem
1813
+ attach_function :clCreateFromGLTexture, [Context,:cl_mem_flags,:cl_GLenum,:cl_GLint,:cl_GLuint,:pointer], Mem
1814
+ attach_function :clCreateFromGLRenderbuffer, [Context,:cl_mem_flags,:cl_GLuint,:pointer], Mem
1815
+ attach_function :clGetGLObjectInfo, [Mem,:pointer,:pointer], :cl_int
1816
+ attach_function :clGetGLTextureInfo, [Mem,:cl_gl_texture_info,:size_t,:pointer,:pointer], :cl_int
1817
+ attach_function :clEnqueueAcquireGLObjects, [CommandQueue,:cl_uint,:pointer,:cl_uint,:pointer,:pointer], :cl_int
1818
+ attach_function :clEnqueueReleaseGLObjects, [CommandQueue,:cl_uint,:pointer,:cl_uint,:pointer,:pointer], :cl_int
1819
+ attach_function :clCreateFromGLTexture2D, [Context,:cl_mem_flags,:cl_GLenum,:cl_GLint,:cl_GLuint,:pointer], Mem
1820
+ attach_function :clCreateFromGLTexture3D, [Context,:cl_mem_flags,:cl_GLenum,:cl_GLint,:cl_GLuint,:pointer], Mem
1821
+ attach_function :clGetGLContextInfoKHR, [:pointer,:cl_gl_context_info,:size_t,:pointer,:pointer], :cl_int
1822
+ attach_function :clReleaseDeviceEXT, [Device], :cl_int
1823
+ attach_function :clRetainDeviceEXT, [Device], :cl_int
1824
+ attach_function :clCreateSubDevicesEXT, [Device,:pointer,:cl_uint,:pointer,:pointer], :cl_int
1825
+ attach_function :clCreateEventFromGLsyncKHR, [Context,GLsync,:pointer], Event
1826
+ end