opencl_ruby_ffi 0.3 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,29 +11,176 @@ module OpenCL
11
11
  # ==== Options
12
12
  #
13
13
  # * +:device_list+ - an Array of Device to build the program for
14
- # * +:user_data+ - a Pointer (or convertible to Pointer using to_ptr) to the memory area to pass to the callback
15
14
  # * +:options+ - a String containing the options to use for the build
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
29
+ opt = ""
30
+ opt = options[:options] if options[:options]
31
+ options_p = FFI::MemoryPointer.from_string(opt)
32
+ error = OpenCL.clBuildProgram(program, num_devices, devices_p, options_p, block, options[:user_data] )
33
+ OpenCL.error_check(error)
34
+ return program
35
+ end
36
+
37
+ # Links a set of compiled programs for all device in a Context, or a subset of devices
38
+ #
39
+ # ==== Attributes
40
+ #
41
+ # * +context+ - Context the created Program will be associated with
42
+ # * +input_programs+ - a single or an Array of Program
43
+ # * +options+ - a Hash containing named options
44
+ # * +block+ - if provided, a callback invoked when the Program is built. Signature of the callback is { |Program, FFI::Pointer to user_data| ... }
45
+ #
46
+ # ==== Options
47
+ #
48
+ # * +:device_list+ - an Array of Device to build the program for
49
+ # * +:options+ - a String containing the options to use for the build
50
+ # * +:user_data+ - a Pointer (or convertible to Pointer using to_ptr) to the memory area to pass to the callback
51
+ def self.link_program(context, input_programs, options = {}, &block)
52
+ @@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
18
64
  opt = ""
19
65
  opt = options[:options] if options[:options]
20
66
  options_p = FFI::MemoryPointer.from_string(opt)
67
+ programs = [input_programs].flatten
68
+ num_programs = programs.length
69
+ programs_p = FFI::MemoryPointer::new( Program, num_programs )
70
+ programs.each_with_index { |e, i|
71
+ programs_p[i].write_pointer(e)
72
+ }
73
+ error = FFI::MemoryPointer::new( :cl_int )
74
+ prog = OpenCL.clLinkProgram( context, num_devices, devices_p, options_p, num_programs, programs_p, block, options[:user_data], error)
75
+ OpenCL.error_check(error.read_cl_int)
76
+ return OpenCL::Program::new( prog, false )
77
+ end
78
+
79
+ # Compiles a Program created from sources
80
+ #
81
+ # ==== Attributes
82
+ #
83
+ # * +program+ - the program to build
84
+ # * +options+ - a Hash containing named options
85
+ # * +block+ - if provided, a callback invoked when the Program is compiled. Signature of the callback is { |Program, FFI::Pointer to user_data| ... }
86
+ #
87
+ # ==== Options
88
+ #
89
+ # * +:device_list+ - an Array of Device to build the program for
90
+ # * +:user_data+ - a Pointer (or convertible to Pointer using to_ptr) to the memory area to pass to the callback
91
+ # * +:options+ - a String containing the options to use for the compilation
92
+ # * +:input_headers+ - a Hash containing pairs of : String: header_include_name => Program: header
93
+ def self.compile_program(program, options = {}, &block)
94
+ @@callback.push( block ) if block
21
95
  devices = options[:device_list]
22
96
  devices = [devices].flatten if devices
23
97
  devices_p = nil
24
98
  num_devices = 0
25
99
  if devices and devices.size > 0 then
26
100
  num_devices = devices.size
27
- devices_p = FFI::MemoryPointer.new( Device, num_devices)
101
+ devices_p = FFI::MemoryPointer::new( Device, num_devices)
28
102
  num_devices.times { |indx|
29
- devices_p.put_pointer(indx, devices[indx])
103
+ devices_p[indx].write_pointer(devices[indx])
104
+ }
105
+ end
106
+ opt = ""
107
+ opt = options[:options] if options[:options]
108
+ options_p = FFI::MemoryPointer.from_string(opt)
109
+ headers = options[:input_headers]
110
+ headers_p = nil
111
+ header_include_names = nil
112
+ num_headers = 0
113
+ num_headers = headers.length if headers
114
+ if num_headers then
115
+ headers_p = FFI::MemoryPointer::new( Program, num_headers )
116
+ header_include_names = FFI::MemoryPointer::new( :pointer, num_headers )
117
+ indx = 0
118
+ headers.each { |key, value|
119
+ headers_p[indx].write_pointer(value)
120
+ header_include_names[indx] = FFI::MemoryPointer.from_string(key)
121
+ indx = indx + 1
30
122
  }
31
123
  end
32
- err = OpenCL.clBuildProgram(program, num_devices, devices_p, options_p, block, options[:user_data] )
33
- OpenCL.error_check(err)
124
+ error = OpenCL.clCompileProgram(program, num_devices, devices_p, options_p, num_headers, headers_p, header_include_names, block, options[:user_data] )
125
+ OpenCL.error_check(error)
34
126
  return program
35
127
  end
36
128
 
129
+ # Creates a Program from a list of built in kernel names
130
+ #
131
+ # ==== Attributes
132
+ #
133
+ # * +context+ - Context the created Program will be associated to
134
+ # * +device_list+ - an Array of Device to create the program for
135
+ # * +kernel_names+ - a single or an Array of String representing the kernel names
136
+ def self.create_program_with_built_in_kernels(context, device_list, kernel_names)
137
+ devices = [device_list].flatten
138
+ num_devices = devices.length
139
+ devices_p = FFI::MemoryPointer::new( Device, num_devices )
140
+ num_devices.times { |indx|
141
+ devices_p[indx].write_pointer(devices[indx])
142
+ }
143
+ names = [kernel_names].flatten.join(",")
144
+ names_p = FFI::MemoryPointer.from_string(names)
145
+ error = FFI::MemoryPointer::new( :cl_int )
146
+ prog = OpenCL.clCreateProgramWithBuiltInKernels( context, num_devices, devices_p, names_p, error )
147
+ OpenCL.error_check(error.read_cl_int)
148
+ return OpenCL::Program::new(prog, false)
149
+ end
150
+
151
+ # Creates a Program from binary
152
+ #
153
+ # ==== Attributes
154
+ #
155
+ # * +context+ - Context the created Program will be associated to
156
+ # * +device_list+ - an Array of Device to create the program for. Can throw an OpenCL::Invalid value if the number of supplied devices is different from the number of supplied binaries.
157
+ # * +binaries+ - Array of binaries
158
+ def self.create_program_with_binary(context, device_list, binaries)
159
+ bins = [binaries].flatten
160
+ num_devices = bins.length
161
+ devices = [device_list].flatten
162
+ OpenCL.error_check(OpenCL::INVALID_VALUE) if devices.length != bins.length
163
+ devices_p = FFI::MemoryPointer::new( Device, num_devices )
164
+ lengths = FFI::MemoryPointer::new( :size_t, num_devices )
165
+ binaries_p = FFI::MemoryPointer::new( :pointer, num_devices )
166
+ num_devices.times { |indx|
167
+ devices_p[indx].write_pointer(devices[indx])
168
+ lengths[indx].write_size_t(binaries[indx].size)
169
+ p = FFI::MemoryPointer::new(binaries[indx].size)
170
+ p.write_bytes(binaries[indx])
171
+ binaries_p[indx].write_pointer(p)
172
+ }
173
+ binary_status = FFI::MemoryPointer::new( :cl_int, num_devices )
174
+ error = FFI::MemoryPointer::new( :cl_int )
175
+ prog = OpenCL.clCreateProgramWithBinary(context, num_devices, devices_p, lengths, binaries_p, binary_status, error)
176
+ OpenCL.error_check(error.read_cl_int)
177
+ d_s = []
178
+ num_devices.times { |indx|
179
+ d_s.push [ devices[indx], binary_status[indx].read_cl_int ]
180
+ }
181
+ return [ OpenCL::Program::new(prog, false), d_s ]
182
+ end
183
+
37
184
  # Creates a Program from sources
38
185
  #
39
186
  # ==== Attributes
@@ -48,8 +195,8 @@ module OpenCL
48
195
  strs = [strings].flatten
49
196
  end
50
197
  n_strs = strs.size
51
- strs_lengths = FFI::MemoryPointer.new( :size_t, n_strs )
52
- c_strs = FFI::MemoryPointer.new( :pointer, n_strs )
198
+ strs_lengths = FFI::MemoryPointer::new( :size_t, n_strs )
199
+ c_strs = FFI::MemoryPointer::new( :pointer, n_strs )
53
200
 
54
201
  c_strs_p = []
55
202
  strs.each { |str|
@@ -59,13 +206,13 @@ module OpenCL
59
206
  }
60
207
  raise OpenCL::Error::new(OpenCL::Error.getErrorString(OpenCL::Error::INVALID_VALUE)) if c_strs_p.size == 0
61
208
 
62
- c_strs = FFI::MemoryPointer.new( :pointer, c_strs_p.size )
63
- c_strs_length = FFI::MemoryPointer.new( :size_t, c_strs_p.size )
209
+ c_strs = FFI::MemoryPointer::new( :pointer, c_strs_p.size )
210
+ c_strs_length = FFI::MemoryPointer::new( :size_t, c_strs_p.size )
64
211
  c_strs_p.each_with_index { |p, i|
65
212
  c_strs[i].write_pointer(p)
66
213
  c_strs_length[i].write_size_t(p.size)
67
214
  }
68
- pointer_err = FFI::MemoryPointer.new( :cl_int )
215
+ pointer_err = FFI::MemoryPointer::new( :cl_int )
69
216
  program_ptr = OpenCL.clCreateProgramWithSource(context, c_strs_p.size, c_strs, c_strs_length, pointer_err)
70
217
  OpenCL.error_check(pointer_err.read_cl_int)
71
218
  return OpenCL::Program::new( program_ptr, false )
@@ -88,9 +235,10 @@ module OpenCL
88
235
  if k then
89
236
  k.enqueue_with_args(*a, &b)
90
237
  else
91
- orig_method_missing(m, *args, &b)
238
+ orig_method_missing(m, *a, &b)
92
239
  end
93
240
  end
241
+
94
242
  # Returns an Array containing the sizes of the binary inside the Program for each device
95
243
  eval OpenCL.get_info_array("Program", :size_t, "BINARY_SIZES")
96
244
 
@@ -99,10 +247,10 @@ module OpenCL
99
247
 
100
248
  # Returns an Array of String representing the Kernel names inside the Program
101
249
  def kernel_names
102
- kernel_names_size = FFI::MemoryPointer.new( :size_t )
250
+ kernel_names_size = FFI::MemoryPointer::new( :size_t )
103
251
  error = OpenCL.clGetProgramInfo( self, OpenCL::Program::KERNEL_NAMES, 0, nil, kernel_names_size)
104
252
  OpenCL.error_check(error)
105
- k_names = FFI::MemoryPointer.new( kernel_names_size.read_size_t )
253
+ k_names = FFI::MemoryPointer::new( kernel_names_size.read_size_t )
106
254
  error = OpenCL.clGetProgramInfo( self, OpenCL::Program::KERNEL_NAMES, kernel_names_size.read_size_t, k_names, nil)
107
255
  OpenCL.error_check(error)
108
256
  k_names_string = k_names.read_string
@@ -112,11 +260,11 @@ module OpenCL
112
260
  # Returns the concatenated Program sources
113
261
  eval OpenCL.get_info("Program", :string, "SOURCE")
114
262
 
115
- # Returns the BuildStatus of the Program
263
+ # Returns the BuildStatus of the Program for each device associated to the Program or the Device(s) specified. Returns an Array of tuple [ Device, BuildStatus ]
116
264
  def build_status(devs = nil)
117
265
  devs = self.devices if not devs
118
266
  devs = [devs].flatten
119
- ptr = FFI::MemoryPointer.new( :cl_build_status )
267
+ ptr = FFI::MemoryPointer::new( :cl_build_status )
120
268
  return devs.collect { |dev|
121
269
  error = OpenCL.clGetProgramBuildInfo(self, dev, OpenCL::Program::BUILD_STATUS, ptr.size, ptr, nil)
122
270
  OpenCL.error_check(error)
@@ -124,11 +272,11 @@ module OpenCL
124
272
  }
125
273
  end
126
274
 
127
- # Returns the BinaryType for each Device associated to the Program or the Device specified
275
+ # Returns the BinaryType for each Device associated to the Program or the Device(s) specified. Returns an Array of tuple [ Device, BinaryType ]
128
276
  def binary_type(devs = nil)
129
277
  devs = self.devices if not devs
130
278
  devs = [devs].flatten
131
- ptr = FFI::MemoryPointer.new( :cl_program_binary_type )
279
+ ptr = FFI::MemoryPointer::new( :cl_program_binary_type )
132
280
  return devs.collect { |dev|
133
281
  error = OpenCL.clGetProgramBuildInfo(self, dev, OpenCL::Program::BINARY_TYPE, ptr.size, ptr, nil)
134
282
  OpenCL.error_check(error)
@@ -136,45 +284,45 @@ module OpenCL
136
284
  }
137
285
  end
138
286
 
139
- # Returns the build options for each Device associated to the Program or the Device specified
287
+ # Returns the build options for each Device associated to the Program or the Device(s) specified. Returns an Array of tuple [ Device, String ]
140
288
  def build_options(devs = nil)
141
289
  devs = self.devices if not devs
142
290
  devs = [devs].flatten
143
291
  return devs.collect { |dev|
144
- ptr1 = FFI::MemoryPointer.new( :size_t, 1)
292
+ ptr1 = FFI::MemoryPointer::new( :size_t, 1)
145
293
  error = OpenCL.clGetProgramBuildInfo(self, dev, OpenCL::Program::BUILD_OPTIONS, 0, nil, ptr1)
146
294
  OpenCL.error_check(error)
147
- ptr2 = FFI::MemoryPointer.new( ptr1.read_size_t )
295
+ ptr2 = FFI::MemoryPointer::new( ptr1.read_size_t )
148
296
  error = OpenCL.clGetProgramBuildInfo(self, dev, OpenCL::Program::BUILD_OPTIONS, ptr1.read_size_t, ptr2, nil)
149
297
  OpenCL.error_check(error)
150
298
  [dev, ptr2.read_string]
151
299
  }
152
300
  end
153
301
 
154
- # Returns the build log for each Device associated to the Program or the Device specified
302
+ # Returns the build log for each Device associated to the Program or the Device(s) specified. Returns an Array of tuple [ Device, String ]
155
303
  def build_log(devs = nil)
156
304
  devs = self.devices if not devs
157
305
  devs = [devs].flatten
158
306
  return devs.collect { |dev|
159
- ptr1 = FFI::MemoryPointer.new( :size_t, 1)
307
+ ptr1 = FFI::MemoryPointer::new( :size_t, 1)
160
308
  error = OpenCL.clGetProgramBuildInfo(self, dev, OpenCL::Program::BUILD_LOG, 0, nil, ptr1)
161
309
  OpenCL.error_check(error)
162
- ptr2 = FFI::MemoryPointer.new( ptr1.read_size_t )
310
+ ptr2 = FFI::MemoryPointer::new( ptr1.read_size_t )
163
311
  error = OpenCL.clGetProgramBuildInfo(self, dev, OpenCL::Program::BUILD_LOG, ptr1.read_size_t, ptr2, nil)
164
312
  OpenCL.error_check(error)
165
313
  [dev, ptr2.read_string]
166
314
  }
167
315
  end
168
316
 
169
- # Returns the binaries associated to the Program for each Device
317
+ # Returns the binaries associated to the Program for each Device. Returns an Array of tuple [ Device, String ]
170
318
  def binaries
171
319
  sizes = self.binary_sizes
172
- bin_array = FFI::MemoryPointer.new( :pointer, sizes.length )
320
+ bin_array = FFI::MemoryPointer::new( :pointer, sizes.length )
173
321
  sizes.length
174
322
  total_size = 0
175
323
  sizes.each_with_index { |s, i|
176
324
  total_size += s
177
- bin_array[i].write_pointer(FFI::MemoryPointer.new(s))
325
+ bin_array[i].write_pointer(FFI::MemoryPointer::new(s))
178
326
  }
179
327
  error = OpenCL.clGetProgramInfo(self, Program::BINARIES, total_size, bin_array, nil)
180
328
  OpenCL.error_check(error)
@@ -191,7 +339,7 @@ module OpenCL
191
339
  # ==== Attributes
192
340
  #
193
341
  # * +options+ - a hash containing named options
194
- # * +block+ - if provided, a callback invoked when error arise in the context. Signature of the callback is { |Program, FFI::Pointer to user_data| ... }
342
+ # * +block+ - if provided, a callback invoked when the Program is built. Signature of the callback is { |Program, FFI::Pointer to user_data| ... }
195
343
  #
196
344
  # ==== Options
197
345
  # * +:device_list+ - an Array of Device to build the program for
@@ -201,9 +349,26 @@ module OpenCL
201
349
  OpenCL.build_program(self, options, &block)
202
350
  end
203
351
 
352
+ # Compiles the Program' sources
353
+ #
354
+ # ==== Attributes
355
+ #
356
+ # * +options+ - a Hash containing named options
357
+ # * +block+ - if provided, a callback invoked when the Program is compiled. Signature of the callback is { |Program, FFI::Pointer to user_data| ... }
358
+ #
359
+ # ==== Options
360
+ #
361
+ # * +:device_list+ - an Array of Device to build the program for
362
+ # * +:user_data+ - a Pointer (or convertible to Pointer using to_ptr) to the memory area to pass to the callback
363
+ # * +:options+ - a String containing the options to use for the compilation
364
+ # * +:input_headers+ - a Hash containing pairs of : String: header_include_name => Program: header
365
+ def compile(options = {}, &block)
366
+ return OpenCL.compile_program(self, options, &block)
367
+ end
368
+
204
369
  # Returns the Context the Program is associated to
205
370
  def context
206
- ptr = FFI::MemoryPointer.new( Context )
371
+ ptr = FFI::MemoryPointer::new( Context )
207
372
  error = OpenCL.clGetProgramInfo(self, Program::CONTEXT, Context.size, ptr, nil)
208
373
  OpenCL.error_check(error)
209
374
  return OpenCL::Context::new( ptr.read_pointer )
@@ -223,11 +388,11 @@ module OpenCL
223
388
  # Returns the Array of Device the Program is associated with
224
389
  def devices
225
390
  n = self.num_devices
226
- ptr2 = FFI::MemoryPointer.new( Device, n )
391
+ ptr2 = FFI::MemoryPointer::new( Device, n )
227
392
  error = OpenCL.clGetProgramInfo(self, Program::DEVICES, Device.size*n, ptr2, nil)
228
393
  OpenCL.error_check(error)
229
394
  return ptr2.get_array_of_pointer(0, n).collect { |device_ptr|
230
- OpenCL::Device.new(device_ptr)
395
+ OpenCL::Device::new(device_ptr)
231
396
  }
232
397
  end
233
398
 
@@ -20,7 +20,7 @@ module OpenCL
20
20
 
21
21
  # Returns the context associated with the Sampler
22
22
  def context
23
- ptr = FFI::MemoryPointer.new( Context )
23
+ ptr = FFI::MemoryPointer::new( Context )
24
24
  error = OpenCL.clGetSamplerInfo(self, Sampler::CONTEXT, Context.size, ptr, nil)
25
25
  OpenCL.error_check(error)
26
26
  return OpenCL::Context::new( ptr.read_pointer )
@@ -184,7 +184,7 @@ module OpenCL
184
184
  if options[:event_wait_list] then
185
185
  num_events = options[:event_wait_list].length
186
186
  if num_events > 0 then
187
- events = FFI::MemoryPointer.new( Event, num_events )
187
+ events = FFI::MemoryPointer::new( Event, num_events )
188
188
  options[:event_wait_list].each_with_index { |e, i|
189
189
  events[i].write_pointer(e)
190
190
  }
@@ -208,14 +208,14 @@ module OpenCL
208
208
 
209
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
210
  def self.get_origin_region( image, options, origin_symbol, region_symbol )
211
- origin = FFI::MemoryPointer.new( :size_t, 3 )
211
+ origin = FFI::MemoryPointer::new( :size_t, 3 )
212
212
  (0..2).each { |i| origin[i].write_size_t(0) }
213
213
  if options[origin_symbol] then
214
214
  options[origin_symbol].each_with_index { |e, i|
215
215
  origin[i].write_size_t(e)
216
216
  }
217
217
  end
218
- region = FFI::MemoryPointer.new( :size_t, 3 )
218
+ region = FFI::MemoryPointer::new( :size_t, 3 )
219
219
  (0..2).each { |i| region[i].write_size_t(1) }
220
220
  if options[region_symbol] then
221
221
  options[region_symbol].each_with_index { |e, i|
@@ -241,7 +241,7 @@ module OpenCL
241
241
  def self.get_context_properties( options )
242
242
  properties = nil
243
243
  if options[:properties] then
244
- properties = FFI::MemoryPointer.new( :cl_context_properties, options[:properties].length + 1 )
244
+ properties = FFI::MemoryPointer::new( :cl_context_properties, options[:properties].length + 1 )
245
245
  options[:properties].each_with_index { |e,i|
246
246
  properties[i].write_cl_context_properties(e)
247
247
  }
@@ -261,7 +261,7 @@ module OpenCL
261
261
  klass_name = "MemObject" if klass == "Mem"
262
262
  s = <<EOF
263
263
  def #{name.downcase}
264
- ptr1 = FFI::MemoryPointer.new( :size_t, 1)
264
+ ptr1 = FFI::MemoryPointer::new( :size_t, 1)
265
265
  error = OpenCL.clGet#{klass_name}Info(self, #{klass}::#{name}, 0, nil, ptr1)
266
266
  OpenCL.error_check(error)
267
267
  EOF
@@ -271,7 +271,7 @@ EOF
271
271
  EOF
272
272
  end
273
273
  s += <<EOF
274
- ptr2 = FFI::MemoryPointer.new( ptr1.read_size_t )
274
+ ptr2 = FFI::MemoryPointer::new( ptr1.read_size_t )
275
275
  error = OpenCL.clGet#{klass_name}Info(self, #{klass}::#{name}, ptr1.read_size_t, ptr2, nil)
276
276
  OpenCL.error_check(error)
277
277
  arr = ptr2.get_array_of_#{type}(0, ptr1.read_size_t/ FFI.find_type(:#{type}).size)
@@ -296,10 +296,10 @@ EOF
296
296
  klass_name = "MemObject" if klass == "Mem"
297
297
  s = <<EOF
298
298
  def #{name.downcase}
299
- ptr1 = FFI::MemoryPointer.new( :size_t, 1)
299
+ ptr1 = FFI::MemoryPointer::new( :size_t, 1)
300
300
  error = OpenCL.clGet#{klass_name}Info(self, #{klass}::#{name}, 0, nil, ptr1)
301
301
  OpenCL.error_check(error)
302
- ptr2 = FFI::MemoryPointer.new( ptr1.read_size_t )
302
+ ptr2 = FFI::MemoryPointer::new( ptr1.read_size_t )
303
303
  error = OpenCL.clGet#{klass_name}Info(self, #{klass}::#{name}, ptr1.read_size_t, ptr2, nil)
304
304
  OpenCL.error_check(error)
305
305
  EOF
@@ -724,6 +724,14 @@ module OpenCL
724
724
  #STDERR.puts "Allocating Platform: #{ptr}"
725
725
  end
726
726
 
727
+ def to_s
728
+ if self.respond_to?(:name) then
729
+ return self.name
730
+ else
731
+ return super
732
+ end
733
+ end
734
+
727
735
  # method called at Platform deletion, releases the object if aplicable
728
736
  def self.release(ptr)
729
737
  end
@@ -853,11 +861,33 @@ module OpenCL
853
861
  # Creates a new Device and retains it if specified and aplicable
854
862
  def initialize(ptr, retain = true)
855
863
  super(ptr)
864
+ platform = FFI::MemoryPointer::new( Platform )
865
+ OpenCL.clGetDeviceInfo( ptr, OpenCL::Device::PLATFORM, platform.size, platform, nil)
866
+ p = OpenCL::Platform::new(platform.read_pointer)
867
+ if p.version_number >= 1.2 and retain then
868
+ error = OpenCL.clRetainDevice(ptr)
869
+ OpenCL.error_check( error )
870
+ end
856
871
  #STDERR.puts "Allocating Device: #{ptr}"
857
872
  end
858
873
 
874
+ def to_s
875
+ if self.respond_to?(:name) then
876
+ return self.name
877
+ else
878
+ return super
879
+ end
880
+ end
881
+
859
882
  # method called at Device deletion, releases the object if aplicable
860
883
  def self.release(ptr)
884
+ platform = FFI::MemoryPointer::new( Platform )
885
+ OpenCL.clGetDeviceInfo( ptr, OpenCL::Device::PLATFORM, platform.size, platform, nil)
886
+ p = OpenCL::Platform::new(platform.read_pointer)
887
+ if p.version_number >= 1.2 then
888
+ error = OpenCL.clReleaseDevice(ptr)
889
+ OpenCL.error_check( error )
890
+ end
861
891
  end
862
892
  end
863
893
 
@@ -994,10 +1024,18 @@ module OpenCL
994
1024
  #STDERR.puts "Allocating Context: #{ptr}"
995
1025
  end
996
1026
 
1027
+ def to_s
1028
+ if self.respond_to?(:name) then
1029
+ return self.name
1030
+ else
1031
+ return super
1032
+ end
1033
+ end
1034
+
997
1035
  # method called at Context deletion, releases the object if aplicable
998
1036
  def self.release(ptr)
999
1037
  #STDERR.puts "Releasing Context: #{ptr}"
1000
- #ref_count = FFI::MemoryPointer.new( :cl_uint )
1038
+ #ref_count = FFI::MemoryPointer::new( :cl_uint )
1001
1039
  #OpenCL.clGetContextInfo(ptr, OpenCL::Context::REFERENCE_COUNT, ref_count.size, ref_count, nil)
1002
1040
  #STDERR.puts "reference counter: #{ref_count.read_cl_uint}"
1003
1041
  error = OpenCL.clReleaseContext(ptr)
@@ -1024,10 +1062,18 @@ module OpenCL
1024
1062
  #STDERR.puts "Allocating CommandQueue: #{ptr}"
1025
1063
  end
1026
1064
 
1065
+ def to_s
1066
+ if self.respond_to?(:name) then
1067
+ return self.name
1068
+ else
1069
+ return super
1070
+ end
1071
+ end
1072
+
1027
1073
  # method called at CommandQueue deletion, releases the object if aplicable
1028
1074
  def self.release(ptr)
1029
1075
  #STDERR.puts "Releasing CommandQueue: #{ptr}"
1030
- #ref_count = FFI::MemoryPointer.new( :cl_uint )
1076
+ #ref_count = FFI::MemoryPointer::new( :cl_uint )
1031
1077
  #OpenCL.clGetCommandQueueInfo(ptr, OpenCL::CommandQueue::REFERENCE_COUNT, ref_count.size, ref_count, nil)
1032
1078
  #STDERR.puts "reference counter: #{ref_count.read_cl_uint}"
1033
1079
  error = OpenCL.clReleaseCommandQueue(ptr)
@@ -1097,10 +1143,18 @@ module OpenCL
1097
1143
  #STDERR.puts "Allocating Mem: #{ptr}"
1098
1144
  end
1099
1145
 
1146
+ def to_s
1147
+ if self.respond_to?(:name) then
1148
+ return self.name
1149
+ else
1150
+ return super
1151
+ end
1152
+ end
1153
+
1100
1154
  # method called at Mem deletion, releases the object if aplicable
1101
1155
  def self.release(ptr)
1102
1156
  #STDERR.puts "Releasing Mem: #{ptr}"
1103
- #ref_count = FFI::MemoryPointer.new( :cl_uint )
1157
+ #ref_count = FFI::MemoryPointer::new( :cl_uint )
1104
1158
  #OpenCL.clGetMemObjectInfo(ptr, OpenCL::Mem::REFERENCE_COUNT, ref_count.size, ref_count, nil)
1105
1159
  #STDERR.puts "reference counter: #{ref_count.read_cl_uint}"
1106
1160
  error = OpenCL.clReleaseMemObject(ptr)
@@ -1204,10 +1258,18 @@ module OpenCL
1204
1258
  #STDERR.puts "Allocating Program: #{ptr}"
1205
1259
  end
1206
1260
 
1261
+ def to_s
1262
+ if self.respond_to?(:name) then
1263
+ return self.name
1264
+ else
1265
+ return super
1266
+ end
1267
+ end
1268
+
1207
1269
  # method called at Program deletion, releases the object if aplicable
1208
1270
  def self.release(ptr)
1209
1271
  #STDERR.puts "Releasing Program: #{ptr}"
1210
- #ref_count = FFI::MemoryPointer.new( :cl_uint )
1272
+ #ref_count = FFI::MemoryPointer::new( :cl_uint )
1211
1273
  #OpenCL.clGetProgramInfo(ptr, OpenCL::Program::REFERENCE_COUNT, ref_count.size, ref_count, nil)
1212
1274
  #STDERR.puts "reference counter: #{ref_count.read_cl_uint}"
1213
1275
  error = OpenCL.clReleaseProgram(ptr)
@@ -1278,10 +1340,18 @@ module OpenCL
1278
1340
  #STDERR.puts "Allocating Kernel: #{ptr}"
1279
1341
  end
1280
1342
 
1343
+ def to_s
1344
+ if self.respond_to?(:name) then
1345
+ return self.name
1346
+ else
1347
+ return super
1348
+ end
1349
+ end
1350
+
1281
1351
  # method called at Kernel deletion, releases the object if aplicable
1282
1352
  def self.release(ptr)
1283
1353
  #STDERR.puts "Releasing Kernel: #{ptr}"
1284
- #ref_count = FFI::MemoryPointer.new( :cl_uint )
1354
+ #ref_count = FFI::MemoryPointer::new( :cl_uint )
1285
1355
  #OpenCL.clGetKernelInfo(ptr, OpenCL::Kernel::REFERENCE_COUNT, ref_count.size, ref_count, nil)
1286
1356
  #STDERR.puts "reference counter: #{ref_count.read_cl_uint}"
1287
1357
  error = OpenCL.clReleaseKernel(ptr)
@@ -1390,10 +1460,18 @@ module OpenCL
1390
1460
  #STDERR.puts "Allocating Event: #{ptr}"
1391
1461
  end
1392
1462
 
1463
+ def to_s
1464
+ if self.respond_to?(:name) then
1465
+ return self.name
1466
+ else
1467
+ return super
1468
+ end
1469
+ end
1470
+
1393
1471
  # method called at Event deletion, releases the object if aplicable
1394
1472
  def self.release(ptr)
1395
1473
  #STDERR.puts "Releasing Event: #{ptr}"
1396
- #ref_count = FFI::MemoryPointer.new( :cl_uint )
1474
+ #ref_count = FFI::MemoryPointer::new( :cl_uint )
1397
1475
  #OpenCL.clGetEventInfo(ptr, OpenCL::Event::REFERENCE_COUNT, ref_count.size, ref_count, nil)
1398
1476
  #STDERR.puts "reference counter: #{ref_count.read_cl_uint}"
1399
1477
  error = OpenCL.clReleaseEvent(ptr)
@@ -1419,10 +1497,18 @@ module OpenCL
1419
1497
  #STDERR.puts "Allocating Sampler: #{ptr}"
1420
1498
  end
1421
1499
 
1500
+ def to_s
1501
+ if self.respond_to?(:name) then
1502
+ return self.name
1503
+ else
1504
+ return super
1505
+ end
1506
+ end
1507
+
1422
1508
  # method called at Sampler deletion, releases the object if aplicable
1423
1509
  def self.release(ptr)
1424
1510
  #STDERR.puts "Releasing Sampler: #{ptr}"
1425
- #ref_count = FFI::MemoryPointer.new( :cl_uint )
1511
+ #ref_count = FFI::MemoryPointer::new( :cl_uint )
1426
1512
  #OpenCL.clGetSamplerInfo(ptr, OpenCL::Sampler::REFERENCE_COUNT, ref_count.size, ref_count, nil)
1427
1513
  #STDERR.puts "reference counter: #{ref_count.read_cl_uint}"
1428
1514
  error = OpenCL.clReleaseSampler(ptr)
@@ -1443,6 +1529,14 @@ module OpenCL
1443
1529
  #STDERR.puts "Allocating GLsync: #{ptr}"
1444
1530
  end
1445
1531
 
1532
+ def to_s
1533
+ if self.respond_to?(:name) then
1534
+ return self.name
1535
+ else
1536
+ return super
1537
+ end
1538
+ end
1539
+
1446
1540
  # method called at GLsync deletion, releases the object if aplicable
1447
1541
  def self.release(ptr)
1448
1542
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'opencl_ruby_ffi'
3
- s.version = "0.3"
3
+ s.version = "0.4"
4
4
  s.author = "Brice Videau"
5
5
  s.email = "brice.videau@imag.fr"
6
6
  s.homepage = "https://forge.imag.fr/projects/opencl-ruby/"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opencl_ruby_ffi
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
4
+ version: '0.4'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-23 00:00:00.000000000 Z
12
+ date: 2014-03-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: narray