opencl_ruby_ffi 0.994 → 0.995

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,13 +20,18 @@ module OpenCL
20
20
 
21
21
  # Maps the cl_mem object of OpenCL
22
22
  class Mem
23
+ include InnerInterface
24
+
25
+ class << self
26
+ include InnerGenerator
27
+ end
23
28
 
24
29
  # Returns the Context associated to the Mem
25
30
  def context
26
31
  ptr = FFI::MemoryPointer::new( Context )
27
32
  error = OpenCL.clGetMemObjectInfo(self, CONTEXT, Context.size, ptr, nil)
28
- OpenCL.error_check(error)
29
- return OpenCL::Context::new( ptr.read_pointer )
33
+ error_check(error)
34
+ return Context::new( ptr.read_pointer )
30
35
  end
31
36
 
32
37
  # Returns the Platform associated to the Mem
@@ -38,7 +43,7 @@ module OpenCL
38
43
  def associated_memobject
39
44
  ptr = FFI::MemoryPointer::new( Mem )
40
45
  error = OpenCL.clGetMemObjectInfo(self, ASSOCIATED_MEMOBJECT, Mem.size, ptr, nil)
41
- OpenCL.error_check(error)
46
+ error_check(error)
42
47
  return nil if ptr.read_pointer.null?
43
48
  return Mem::new( ptr.read_pointer )
44
49
  end
@@ -51,7 +56,7 @@ module OpenCL
51
56
  # :method: size()
52
57
  # Returns the size of the Buffer
53
58
  %w( OFFSET SIZE ).each { |prop|
54
- eval OpenCL.get_info("Mem", :size_t, prop)
59
+ eval get_info("Mem", :size_t, prop)
55
60
  }
56
61
 
57
62
  ##
@@ -62,28 +67,28 @@ module OpenCL
62
67
  # :method: reference_count()
63
68
  # Returns the Mem reference counter
64
69
  %w( MAP_COUNT REFERENCE_COUNT ).each { |prop|
65
- eval OpenCL.get_info("Mem", :cl_uint, prop)
70
+ eval get_info("Mem", :cl_uint, prop)
66
71
  }
67
72
 
68
73
  ##
69
74
  # :method: uses_svn_pointer()
70
75
  # Returns true if Mem uses an SVM pointer
71
- eval OpenCL.get_info("Mem", :cl_bool, "USES_SVM_POINTER")
76
+ eval get_info("Mem", :cl_bool, "USES_SVM_POINTER")
72
77
 
73
78
  ##
74
79
  # :method: type()
75
- # Returns an OpenCL::Mem::Type corresponding to the Mem
76
- eval OpenCL.get_info("Mem", :cl_mem_object_type, "TYPE")
80
+ # Returns a Mem::Type corresponding to the Mem
81
+ eval get_info("Mem", :cl_mem_object_type, "TYPE")
77
82
 
78
83
  ##
79
84
  # :method: flags()
80
- # Returns an OpenCL::Mem::Flags corresponding to the flags used at Mem creation
81
- eval OpenCL.get_info("Mem", :cl_mem_flags, "FLAGS")
85
+ # Returns a Mem::Flags corresponding to the flags used at Mem creation
86
+ eval get_info("Mem", :cl_mem_flags, "FLAGS")
82
87
 
83
88
  ##
84
89
  # :method: host_ptr()
85
90
  # Returns the host Pointer specified at Mem creation or the pointer + the ofsset if it is a sub-buffer. A null Pointer is returned otherwise.
86
- eval OpenCL.get_info("Mem", :pointer, "HOST_PTR")
91
+ eval get_info("Mem", :pointer, "HOST_PTR")
87
92
 
88
93
  # Attaches a callback to memobj that will be called on the memobj destruction
89
94
  #
@@ -102,33 +107,33 @@ module OpenCL
102
107
 
103
108
  # Returns the texture_target argument specified in create_from_GL_texture for Mem
104
109
  def GL_texture_target
105
- param_value = MemoryPointer::new( :cl_GLenum )
106
- error = OpenCL.clGetGLTextureInfo( self, OpenCL::GL_TEXTURE_TARGET, param_value.size, param_value, nil )
107
- OpenCL.error_check(error)
110
+ param_value = FFI::MemoryPointer::new( :cl_GLenum )
111
+ error = OpenCL.clGetGLTextureInfo( self, GL_TEXTURE_TARGET, param_value.size, param_value, nil )
112
+ error_check(error)
108
113
  return param_value.read_cl_GLenum
109
114
  end
110
115
 
111
116
  # Returns the miplevel argument specified in create_from_GL_texture for Mem
112
117
  def GL_mimap_level
113
- param_value = MemoryPointer::new( :cl_GLint )
114
- error = OpenCL.clGetGLTextureInfo( self, OpenCL::GL_MIPMAP_LEVEL, param_value.size, param_value, nil )
115
- OpenCL.error_check(error)
118
+ param_value = FFI::MemoryPointer::new( :cl_GLint )
119
+ error = OpenCL.clGetGLTextureInfo( self, GL_MIPMAP_LEVEL, param_value.size, param_value, nil )
120
+ error_check(error)
116
121
  return param_value.read_cl_GLint
117
122
  end
118
123
 
119
124
  # Returns the type of the GL object associated with Mem
120
125
  def GL_object_type
121
- param_value = MemoryPointer::new( :cl_gl_object_type )
126
+ param_value = FFI::MemoryPointer::new( :cl_gl_object_type )
122
127
  error = OpenCL.clGetGLObjectInfo( self, param_value, nil )
123
- OpenCL.error_check(error)
124
- return OpenCL::GLObjectType::new(param_value.read_cl_gl_object_type)
128
+ error_check(error)
129
+ return GLObjectType::new(param_value.read_cl_gl_object_type)
125
130
  end
126
131
 
127
132
  # Returns the name of the GL object associated with Mem
128
133
  def GL_object_name
129
- param_value = MemoryPointer::new( :cl_GLuint )
134
+ param_value = FFI::MemoryPointer::new( :cl_GLuint )
130
135
  error = OpenCL.clGetGLObjectInfo( self, nil, param_value )
131
- OpenCL.error_check(error)
136
+ error_check(error)
132
137
  return param_value.read_cl_GLuint
133
138
  end
134
139
 
@@ -22,6 +22,11 @@ module OpenCL
22
22
 
23
23
  # Maps the cl_mem OpenCL objects of type CL_MEM_OBJECT_PIPE
24
24
  class Pipe
25
+ include InnerInterface
26
+
27
+ class << self
28
+ include InnerGenerator
29
+ end
25
30
 
26
31
  ##
27
32
  # :method: packet_size
@@ -31,7 +36,7 @@ module OpenCL
31
36
  # :method: max_packets
32
37
  # Returns the max_packets of the Pipe
33
38
  %w( PACKET_SIZE MAX_PACKETS ).each { |prop|
34
- eval OpenCL.get_info("Pipe", :cl_uint, prop)
39
+ eval get_info("Pipe", :cl_uint, prop)
35
40
  }
36
41
 
37
42
  end
@@ -71,6 +71,11 @@ module OpenCL
71
71
 
72
72
  # Maps the cl_platform_id object of OpenCL
73
73
  class Platform
74
+ include InnerInterface
75
+
76
+ class << self
77
+ include InnerGenerator
78
+ end
74
79
 
75
80
  ##
76
81
  # :method: profile()
@@ -88,32 +93,32 @@ module OpenCL
88
93
  # :mathod: vendor()
89
94
  # Returns a String identifying the Platform vendor
90
95
  %w(PROFILE VERSION NAME VENDOR).each { |prop|
91
- eval OpenCL.get_info("Platform", :string, prop)
96
+ eval get_info("Platform", :string, prop)
92
97
  }
93
98
 
94
99
  # Returns an Array of string corresponding to the Platform extensions
95
100
  def extensions
96
101
  extensions_size = FFI::MemoryPointer::new( :size_t )
97
102
  error = OpenCL.clGetPlatformInfo( self, EXTENSIONS, 0, nil, extensions_size)
98
- OpenCL.error_check(error)
103
+ error_check(error)
99
104
  ext = FFI::MemoryPointer::new( extensions_size.read_size_t )
100
105
  error = OpenCL.clGetPlatformInfo( self, EXTENSIONS, extensions_size.read_size_t, ext, nil)
101
- OpenCL.error_check(error)
106
+ error_check(error)
102
107
  ext_string = ext.read_string
103
108
  return ext_string.split(" ")
104
109
  end
105
110
 
106
111
  # Returns an Array of Device corresponding to the available devices on the Platform
107
112
  # The type of the desired devices can be specified
108
- def devices(type = OpenCL::Device::Type::ALL)
113
+ def devices(type = Device::Type::ALL)
109
114
  ptr1 = FFI::MemoryPointer::new(:cl_uint , 1)
110
115
  error = OpenCL.clGetDeviceIDs(self, type, 0, nil, ptr1)
111
- OpenCL.error_check(error)
116
+ error_check(error)
112
117
  ptr2 = FFI::MemoryPointer::new(:pointer, ptr1.read_uint)
113
118
  error = OpenCL.clGetDeviceIDs(self, type, ptr1.read_uint(), ptr2, nil)
114
- OpenCL.error_check(error)
119
+ error_check(error)
115
120
  return ptr2.get_array_of_pointer(0, ptr1.read_uint()).collect { |device_ptr|
116
- OpenCL::Device::new(device_ptr, false)
121
+ Device::new(device_ptr, false)
117
122
  }
118
123
  end
119
124
 
@@ -138,7 +143,7 @@ module OpenCL
138
143
  # * +param_types+ - an Array of types, corresponding to the parameters type
139
144
  # * +options+ - if given, a hash of named options that will be given to FFI::Function::new. See FFI doc for details.
140
145
  def get_extension_function( name, return_type, param_types, options = {} )
141
- OpenCL.error_check(OpenCL::INVALID_OPERATION) if self.version_number < 1.2
146
+ error_check(INVALID_OPERATION) if self.version_number < 1.2
142
147
  name_p = FFI::MemoryPointer.from_string(name)
143
148
  ptr = OpenCL.clGetExtensionFunctionAddressForPlatform( self, name_p )
144
149
  return nil if ptr.null?
@@ -158,7 +163,7 @@ module OpenCL
158
163
  # * +:properties+ - a list of :cl_context_properties, the Platform will be prepended
159
164
  # * +:user_data+ - an FFI::Pointer or an object that can be converted into one using to_ptr. The pointer is passed to the callback.
160
165
  def create_context_from_type(type, options = {}, &block)
161
- props = [ OpenCL::Context::PLATFORM, self ]
166
+ props = [ Context::PLATFORM, self ]
162
167
  if options[:properties] then
163
168
  props = props + options[:properties]
164
169
  else
@@ -15,17 +15,7 @@ module OpenCL
15
15
  # * +:user_data+ - a Pointer (or convertible to Pointer using to_ptr) to the memory area to pass to the callback
16
16
  def self.build_program(program, options = {}, &block)
17
17
  @@callbacks.push( block ) if block
18
- devices = options[:device_list]
19
- devices = [devices].flatten if devices
20
- devices_p = nil
21
- num_devices = 0
22
- if devices and devices.size > 0 then
23
- num_devices = devices.size
24
- devices_p = FFI::MemoryPointer::new( Device, num_devices)
25
- num_devices.times { |indx|
26
- devices_p[indx].write_pointer(devices[indx])
27
- }
28
- end
18
+ num_devices, devices_p = get_device_list( options )
29
19
  opt = ""
30
20
  opt = options[:options] if options[:options]
31
21
  options_p = FFI::MemoryPointer.from_string(opt)
@@ -50,26 +40,14 @@ module OpenCL
50
40
  # * +:user_data+ - a Pointer (or convertible to Pointer using to_ptr) to the memory area to pass to the callback
51
41
  def self.link_program(context, input_programs, options = {}, &block)
52
42
  @@callbacks.push( block ) if block
53
- devices = options[:device_list]
54
- devices = [devices].flatten if devices
55
- devices_p = nil
56
- num_devices = 0
57
- if devices and devices.size > 0 then
58
- num_devices = devices.size
59
- devices_p = FFI::MemoryPointer::new( Device, num_devices)
60
- num_devices.times { |indx|
61
- devices_p[indx].write_pointer(devices[indx])
62
- }
63
- end
43
+ num_devices, devices_p = get_device_list( options )
64
44
  opt = ""
65
45
  opt = options[:options] if options[:options]
66
46
  options_p = FFI::MemoryPointer.from_string(opt)
67
47
  programs = [input_programs].flatten
68
48
  num_programs = programs.length
69
49
  programs_p = FFI::MemoryPointer::new( Program, num_programs )
70
- programs.each_with_index { |e, i|
71
- programs_p[i].write_pointer(e)
72
- }
50
+ programs_p.write_array_of_pointer(programs)
73
51
  error = FFI::MemoryPointer::new( :cl_int )
74
52
  prog = clLinkProgram( context, num_devices, devices_p, options_p, num_programs, programs_p, block, options[:user_data], error)
75
53
  error_check(error.read_cl_int)
@@ -91,18 +69,8 @@ module OpenCL
91
69
  # * +:options+ - a String containing the options to use for the compilation
92
70
  # * +:input_headers+ - a Hash containing pairs of : String: header_include_name => Program: header
93
71
  def self.compile_program(program, options = {}, &block)
94
- @@callback.push( block ) if block
95
- devices = options[:device_list]
96
- devices = [devices].flatten if devices
97
- devices_p = nil
98
- num_devices = 0
99
- if devices and devices.size > 0 then
100
- num_devices = devices.size
101
- devices_p = FFI::MemoryPointer::new( Device, num_devices)
102
- num_devices.times { |indx|
103
- devices_p[indx].write_pointer(devices[indx])
104
- }
105
- end
72
+ @@callbacks.push( block ) if block
73
+ num_devices, devices_p = get_device_list( options )
106
74
  opt = ""
107
75
  opt = options[:options] if options[:options]
108
76
  options_p = FFI::MemoryPointer.from_string(opt)
@@ -220,6 +188,11 @@ module OpenCL
220
188
 
221
189
  # Maps the cl_program object of OpenCL
222
190
  class Program
191
+ include InnerInterface
192
+
193
+ class << self
194
+ include InnerGenerator
195
+ end
223
196
  alias_method :orig_method_missing, :method_missing
224
197
 
225
198
  # Intercepts a call to a missing method and tries to see if it is defined as a Kernel inside
@@ -229,7 +202,7 @@ module OpenCL
229
202
  k = nil
230
203
  begin
231
204
  k = self.create_kernel(m_string)
232
- rescue OpenCL::Error
205
+ rescue Error
233
206
  k = nil
234
207
  end
235
208
  if k then
@@ -240,25 +213,25 @@ module OpenCL
240
213
  end
241
214
 
242
215
  # Returns an Array containing the sizes of the binary inside the Program for each device
243
- eval OpenCL.get_info_array("Program", :size_t, "BINARY_SIZES")
216
+ eval get_info_array("Program", :size_t, "BINARY_SIZES")
244
217
 
245
218
  # Returns the number of Kernels defined in the Program
246
- eval OpenCL.get_info("Program", :size_t, "NUM_KERNELS")
219
+ eval get_info("Program", :size_t, "NUM_KERNELS")
247
220
 
248
221
  # Returns an Array of String representing the Kernel names inside the Program
249
222
  def kernel_names
250
223
  kernel_names_size = FFI::MemoryPointer::new( :size_t )
251
224
  error = OpenCL.clGetProgramInfo( self, KERNEL_NAMES, 0, nil, kernel_names_size)
252
- OpenCL.error_check(error)
225
+ error_check(error)
253
226
  k_names = FFI::MemoryPointer::new( kernel_names_size.read_size_t )
254
227
  error = OpenCL.clGetProgramInfo( self, KERNEL_NAMES, kernel_names_size.read_size_t, k_names, nil)
255
- OpenCL.error_check(error)
228
+ error_check(error)
256
229
  k_names_string = k_names.read_string
257
230
  returns k_names_string.split(";")
258
231
  end
259
232
 
260
233
  # Returns the concatenated Program sources
261
- eval OpenCL.get_info("Program", :string, "SOURCE")
234
+ eval get_info("Program", :string, "SOURCE")
262
235
 
263
236
  # Returns the total amount in byte used by the Program variables in the global address space for the Device(s) specified. Returns an Array of tuple [ Device, size ] (2.0 only)
264
237
  def build_global_variable_total_size(devs = nil)
@@ -267,7 +240,7 @@ module OpenCL
267
240
  ptr = FFI::MemoryPointer::new( :size_t )
268
241
  return devs.collect { |dev|
269
242
  error = OpenCL.clGetProgramBuildInfo(self, dev, BUILD_GLOBAL_VARIABLE_TOTAL_SIZE, ptr.size, ptr, nil)
270
- OpenCL.error_check(error)
243
+ error_check(error)
271
244
  [dev, ptr.read_size_t]
272
245
  }
273
246
  end
@@ -279,8 +252,8 @@ module OpenCL
279
252
  ptr = FFI::MemoryPointer::new( :cl_build_status )
280
253
  return devs.collect { |dev|
281
254
  error = OpenCL.clGetProgramBuildInfo(self, dev, BUILD_STATUS, ptr.size, ptr, nil)
282
- OpenCL.error_check(error)
283
- [dev, OpenCL::BuildStatus::new(ptr.read_cl_build_status)]
255
+ error_check(error)
256
+ [dev, BuildStatus::new(ptr.read_cl_build_status)]
284
257
  }
285
258
  end
286
259
 
@@ -291,8 +264,8 @@ module OpenCL
291
264
  ptr = FFI::MemoryPointer::new( :cl_program_binary_type )
292
265
  return devs.collect { |dev|
293
266
  error = OpenCL.clGetProgramBuildInfo(self, dev, BINARY_TYPE, ptr.size, ptr, nil)
294
- OpenCL.error_check(error)
295
- [dev, OpenCL::Program::BinaryType::new(ptr.read_cl_program_binary_type)]
267
+ error_check(error)
268
+ [dev, BinaryType::new(ptr.read_cl_program_binary_type)]
296
269
  }
297
270
  end
298
271
 
@@ -303,10 +276,10 @@ module OpenCL
303
276
  return devs.collect { |dev|
304
277
  ptr1 = FFI::MemoryPointer::new( :size_t, 1)
305
278
  error = OpenCL.clGetProgramBuildInfo(self, dev, BUILD_OPTIONS, 0, nil, ptr1)
306
- OpenCL.error_check(error)
279
+ error_check(error)
307
280
  ptr2 = FFI::MemoryPointer::new( ptr1.read_size_t )
308
281
  error = OpenCL.clGetProgramBuildInfo(self, dev, BUILD_OPTIONS, ptr1.read_size_t, ptr2, nil)
309
- OpenCL.error_check(error)
282
+ error_check(error)
310
283
  [dev, ptr2.read_string]
311
284
  }
312
285
  end
@@ -318,10 +291,10 @@ module OpenCL
318
291
  return devs.collect { |dev|
319
292
  ptr1 = FFI::MemoryPointer::new( :size_t, 1)
320
293
  error = OpenCL.clGetProgramBuildInfo(self, dev, BUILD_LOG, 0, nil, ptr1)
321
- OpenCL.error_check(error)
294
+ error_check(error)
322
295
  ptr2 = FFI::MemoryPointer::new( ptr1.read_size_t )
323
296
  error = OpenCL.clGetProgramBuildInfo(self, dev, BUILD_LOG, ptr1.read_size_t, ptr2, nil)
324
- OpenCL.error_check(error)
297
+ error_check(error)
325
298
  [dev, ptr2.read_string]
326
299
  }
327
300
  end
@@ -337,7 +310,7 @@ module OpenCL
337
310
  bin_array[i].write_pointer(FFI::MemoryPointer::new(s))
338
311
  }
339
312
  error = OpenCL.clGetProgramInfo(self, BINARIES, total_size, bin_array, nil)
340
- OpenCL.error_check(error)
313
+ error_check(error)
341
314
  bins = []
342
315
  devs = self.devices
343
316
  sizes.each_with_index { |s, i|
@@ -382,8 +355,8 @@ module OpenCL
382
355
  def context
383
356
  ptr = FFI::MemoryPointer::new( Context )
384
357
  error = OpenCL.clGetProgramInfo(self, CONTEXT, Context.size, ptr, nil)
385
- OpenCL.error_check(error)
386
- return OpenCL::Context::new( ptr.read_pointer )
358
+ error_check(error)
359
+ return Context::new( ptr.read_pointer )
387
360
  end
388
361
 
389
362
  ##
@@ -394,7 +367,7 @@ module OpenCL
394
367
  # :method: reference_count()
395
368
  # Returns the reference counter for this Program
396
369
  %w( NUM_DEVICES REFERENCE_COUNT ).each { |prop|
397
- eval OpenCL.get_info("Program", :cl_uint, prop)
370
+ eval get_info("Program", :cl_uint, prop)
398
371
  }
399
372
 
400
373
  # Returns the Array of Device the Program is associated with
@@ -402,9 +375,9 @@ module OpenCL
402
375
  n = self.num_devices
403
376
  ptr2 = FFI::MemoryPointer::new( Device, n )
404
377
  error = OpenCL.clGetProgramInfo(self, DEVICES, Device.size*n, ptr2, nil)
405
- OpenCL.error_check(error)
378
+ error_check(error)
406
379
  return ptr2.get_array_of_pointer(0, n).collect { |device_ptr|
407
- OpenCL::Device::new(device_ptr)
380
+ Device::new(device_ptr)
408
381
  }
409
382
  end
410
383
 
@@ -61,34 +61,39 @@ module OpenCL
61
61
 
62
62
  # Maps the cl_smapler object of OpenCL
63
63
  class Sampler
64
+ include InnerInterface
65
+
66
+ class << self
67
+ include InnerGenerator
68
+ end
64
69
 
65
70
  # Returns the context associated with the Sampler
66
71
  def context
67
72
  ptr = FFI::MemoryPointer::new( Context )
68
73
  error = OpenCL.clGetSamplerInfo(self, CONTEXT, Context.size, ptr, nil)
69
- OpenCL.error_check(error)
70
- return OpenCL::Context::new( ptr.read_pointer )
74
+ error_check(error)
75
+ return Context::new( ptr.read_pointer )
71
76
  end
72
77
 
73
78
  ##
74
79
  # :method: reference_count()
75
80
  # returns the reference counter of the Sampler
76
- eval OpenCL.get_info("Sampler", :cl_uint, "REFERENCE_COUNT")
81
+ eval get_info("Sampler", :cl_uint, "REFERENCE_COUNT")
77
82
 
78
83
  ##
79
84
  # :method: normalized_coords()
80
85
  # returns if the Sampler uses normalized coords
81
- eval OpenCL.get_info("Sampler", :cl_bool, "NORMALIZED_COORDS")
86
+ eval get_info("Sampler", :cl_bool, "NORMALIZED_COORDS")
82
87
 
83
88
  ##
84
89
  # :method: addressing_mode()
85
90
  # returns an AddressingMode representing the addressing mode used by the Sampler
86
- eval OpenCL.get_info("Sampler", :cl_addressing_mode, "ADDRESSING_MODE")
91
+ eval get_info("Sampler", :cl_addressing_mode, "ADDRESSING_MODE")
87
92
 
88
93
  ##
89
94
  # :method: filter_mode()
90
95
  # returns a FilterMode representing the filtering mode used by the Sampler
91
- eval OpenCL.get_info("Sampler", :cl_filter_mode, "FILTER_MODE")
96
+ eval get_info("Sampler", :cl_filter_mode, "FILTER_MODE")
92
97
 
93
98
  end
94
99