opencl_ruby_ffi 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,53 +1,38 @@
1
- module FFI
2
-
3
- class Pointer
4
- alias_method :orig_method_missing, :method_missing
5
- # 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
6
- def method_missing(m, *a, &b)
7
- if m.to_s.match("read_")
8
- type = m.to_s.sub("read_","")
9
- type = FFI.find_type(type.to_sym)
10
- type, _ = FFI::TypeDefs.find do |(name, t)|
11
- Pointer.method_defined?("read_#{name}") if t == type
12
- end
13
- eval "alias :#{m} :read_#{type}" if type
14
- return eval "read_#{type}( *a, &b)" if type
15
- elsif m.to_s.match ("write_")
16
- type = m.to_s.sub("write_","")
17
- type = FFI.find_type(type.to_sym)
18
- type, _ = FFI::TypeDefs.find do |(name, t)|
19
- Pointer.method_defined?("write_#{name}") if t == type
20
- end
21
- eval "alias :#{m} :write_#{type}" if type
22
- return eval "write_#{type}( *a, &b)" if type
23
- elsif m.to_s.match ("get_array_of_")
24
- type = m.to_s.sub("get_array_of_","")
25
- type = FFI.find_type(type.to_sym)
26
- type, _ = FFI::TypeDefs.find do |(name, t)|
27
- Pointer.method_defined?("get_array_of_#{name}") if t == type
28
- end
29
- eval "alias :#{m} :get_array_of_#{type}" if type
30
- return eval "get_array_of_#{type}( *a, &b)" if type
31
- end
32
- orig_method_missing m, *a, &b
1
+ using OpenCLRefinements if RUBY_VERSION.scan(/\d+/).collect(&:to_i).first >= 2
33
2
 
34
- end
35
- end
3
+ module OpenCL
36
4
 
37
- class Struct
5
+ class Pointer < FFI::Pointer
6
+ def initialize(*args)
7
+ if args.length == 2 then
8
+ super(OpenCL::find_type(args[0]), args[1])
9
+ else
10
+ super(*args)
11
+ end
12
+ end
13
+ end
38
14
 
39
- # alias initialize in order to call it from another function from a child class
40
- alias_method :parent_initialize, :initialize
15
+ class Function < FFI::Function
16
+ def initialize(ret, args, *opts, &block)
17
+ super(OpenCL::find_type(ret), args.collect { |a| OpenCL::find_type(a) }, *opts, &block)
18
+ end
41
19
  end
42
20
 
43
- end
21
+ class MemoryPointer < FFI::MemoryPointer
44
22
 
45
- module OpenCL
23
+ def initialize(size, count = 1, clear = true)
24
+ if size.is_a?(Symbol)
25
+ size = OpenCL::find_type(size)
26
+ end
27
+ super(size, count, clear)
28
+ end
29
+
30
+ end
46
31
 
47
32
  @@callbacks = []
48
33
 
49
34
  # Maps the :cl_image_fomat type of OpenCL
50
- class ImageFormat < FFI::Struct
35
+ class ImageFormat < Struct
51
36
  layout :image_channel_order, :cl_channel_order,
52
37
  :image_channel_data_type, :cl_channel_type
53
38
 
@@ -56,10 +41,14 @@ module OpenCL
56
41
  end
57
42
 
58
43
  # Creates a new ImageFormat from an image channel order and data type
59
- def initialize( image_channel_order, image_channel_data_type )
60
- super()
61
- self[:image_channel_order] = image_channel_order
62
- self[:image_channel_data_type] = image_channel_data_type
44
+ def initialize( image_channel_order, image_channel_data_type = nil )
45
+ if image_channel_order.is_a?(FFI::Pointer) and image_channel_data_type.nil? then
46
+ super(image_channel_order)
47
+ else
48
+ super()
49
+ self[:image_channel_order] = image_channel_order
50
+ self[:image_channel_data_type] = image_channel_data_type
51
+ end
63
52
  end
64
53
 
65
54
  # Returns a new ChannelOrder corresponding to the ImageFormat internal value
@@ -87,21 +76,10 @@ module OpenCL
87
76
  return "{ #{self.channel_order}, #{self.channel_data_type} }"
88
77
  end
89
78
 
90
- # A workaroud to call the parent initialize from another function (from_pointer)
91
- def parent_initialize(ptr)
92
- super(ptr)
93
- end
94
-
95
- # Creates a new ImageFormat using an FFI::Pointer, fonctionality was lost when initialize was defined
96
- def self.from_pointer( ptr )
97
- object = allocate
98
- object.parent_initialize( ptr )
99
- object
100
- end
101
79
  end
102
80
 
103
81
  # Map the :cl_image_desc type of OpenCL
104
- class ImageDesc < FFI::Struct
82
+ class ImageDesc < Struct
105
83
  layout :image_type, :cl_mem_object_type,
106
84
  :image_width, :size_t,
107
85
  :image_height, :size_t,
@@ -130,7 +108,7 @@ module OpenCL
130
108
  end
131
109
 
132
110
  # Maps the :cl_buffer_region type of OpenCL
133
- class BufferRegion < FFI::Struct
111
+ class BufferRegion < Struct
134
112
  layout :origin, :size_t,
135
113
  :size, :size_t
136
114
 
@@ -168,7 +146,7 @@ module OpenCL
168
146
  num_events = 0
169
147
  if events and events.size > 0 then
170
148
  num_events = events.size
171
- events_p = FFI::MemoryPointer::new( Event, num_events )
149
+ events_p = MemoryPointer::new( Event, num_events )
172
150
  events_p.write_array_of_pointer(events)
173
151
  end
174
152
  return [num_events, events_p]
@@ -189,14 +167,14 @@ module OpenCL
189
167
 
190
168
  # 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
191
169
  def get_origin_region( image, options, origin_symbol, region_symbol )
192
- origin = FFI::MemoryPointer::new( :size_t, 3 )
170
+ origin = MemoryPointer::new( :size_t, 3 )
193
171
  (0..2).each { |i| origin[i].write_size_t(0) }
194
172
  if options[origin_symbol] then
195
173
  options[origin_symbol].each_with_index { |e, i|
196
174
  origin[i].write_size_t(e)
197
175
  }
198
176
  end
199
- region = FFI::MemoryPointer::new( :size_t, 3 )
177
+ region = MemoryPointer::new( :size_t, 3 )
200
178
  (0..2).each { |i| region[i].write_size_t(1) }
201
179
  if options[region_symbol] then
202
180
  options[region_symbol].each_with_index { |e, i|
@@ -218,11 +196,11 @@ module OpenCL
218
196
  return [origin, region]
219
197
  end
220
198
 
221
- # Extracts the :properties named option (for a Context) from the hash given and returns an FFI:Pointer to a 0 terminated list of properties
199
+ # Extracts the :properties named option (for a Context) from the hash given and returns an Pointer to a 0 terminated list of properties
222
200
  def get_context_properties( options )
223
201
  properties = nil
224
202
  if options[:properties] then
225
- properties = FFI::MemoryPointer::new( :cl_context_properties, options[:properties].length + 1 )
203
+ properties = MemoryPointer::new( :cl_context_properties, options[:properties].length + 1 )
226
204
  options[:properties].each_with_index { |e,i|
227
205
  properties[i].write_cl_context_properties(e.respond_to?(:to_ptr) ? e : e.to_i)
228
206
  }
@@ -231,7 +209,7 @@ module OpenCL
231
209
  return properties
232
210
  end
233
211
 
234
- # Extracts the :device_list named option from the hash given and returns [ number of devices, an FFI:Pointer to the list of Device or nil ]
212
+ # Extracts the :device_list named option from the hash given and returns [ number of devices, an Pointer to the list of Device or nil ]
235
213
  def get_device_list( options )
236
214
  devices = options[:device_list]
237
215
  devices = [devices].flatten if devices
@@ -239,7 +217,7 @@ module OpenCL
239
217
  num_devices = 0
240
218
  if devices and devices.size > 0 then
241
219
  num_devices = devices.size
242
- devices_p = FFI::MemoryPointer::new( Device, num_devices)
220
+ devices_p = MemoryPointer::new( Device, num_devices)
243
221
  devices_p.write_array_of_pointer(devices)
244
222
  end
245
223
  return [num_devices, devices_p]
@@ -313,10 +291,10 @@ module OpenCL
313
291
  klass_name = "MemObject" if klass == "Mem"
314
292
  s = <<EOF
315
293
  def #{name.downcase}
316
- ptr1 = FFI::MemoryPointer::new( :size_t, 1)
294
+ ptr1 = MemoryPointer::new( :size_t, 1)
317
295
  error = OpenCL.clGet#{klass_name}Info(self, #{klass}::#{name}, 0, nil, ptr1)
318
296
  error_check(error)
319
- ptr2 = FFI::MemoryPointer::new( ptr1.read_size_t )
297
+ ptr2 = MemoryPointer::new( ptr1.read_size_t )
320
298
  error = OpenCL.clGet#{klass_name}Info(self, #{klass}::#{name}, ptr1.read_size_t, ptr2, nil)
321
299
  error_check(error)
322
300
  if(convert_type(:#{type})) then
@@ -335,13 +313,13 @@ EOF
335
313
  klass_name = "MemObject" if klass == "Mem"
336
314
  s = <<EOF
337
315
  def #{name.downcase}
338
- ptr1 = FFI::MemoryPointer::new( :size_t, 1)
316
+ ptr1 = MemoryPointer::new( :size_t, 1)
339
317
  error = OpenCL.clGet#{klass_name}Info(self, #{klass}::#{name}, 0, nil, ptr1)
340
318
  error_check(error)
341
- ptr2 = FFI::MemoryPointer::new( ptr1.read_size_t )
319
+ ptr2 = MemoryPointer::new( ptr1.read_size_t )
342
320
  error = OpenCL.clGet#{klass_name}Info(self, #{klass}::#{name}, ptr1.read_size_t, ptr2, nil)
343
321
  error_check(error)
344
- arr = ptr2.get_array_of_#{type}(0, ptr1.read_size_t/ FFI.find_type(:#{type}).size)
322
+ arr = ptr2.get_array_of_#{type}(0, ptr1.read_size_t/ OpenCL.find_type(:#{type}).size)
345
323
  return arr
346
324
  end
347
325
  EOF
@@ -353,3 +331,5 @@ EOF
353
331
  #:startdoc:
354
332
 
355
333
  end
334
+
335
+ CL = OpenCL
@@ -1,8 +1,6 @@
1
- require 'ffi'
2
-
1
+ using OpenCLRefinements if RUBY_VERSION.scan(/\d+/).collect(&:to_i).first >= 2
3
2
  # Maps the OpenCL API using FFI
4
3
  module OpenCL
5
- extend FFI::Library
6
4
  begin
7
5
  ffi_lib ENV["LIBOPENCL_SO"]
8
6
  rescue LoadError => e
@@ -2317,77 +2315,10 @@ module OpenCL
2317
2315
  CLASSES[-4] = MEM_OBJECT_ALLOCATION_FAILURE
2318
2316
  MemObjectAllocationFailure = MEM_OBJECT_ALLOCATION_FAILURE
2319
2317
  end
2320
- FFI.typedef :int8, :cl_char
2321
- FFI.typedef :uint8, :cl_uchar
2322
- FFI.typedef :int16, :cl_short
2323
- FFI.typedef :uint16, :cl_ushort
2324
- FFI.typedef :int32, :cl_int
2325
- FFI.typedef :uint32, :cl_uint
2326
- FFI.typedef :int64, :cl_long
2327
- FFI.typedef :uint64, :cl_ulong
2328
- FFI.typedef :uint16, :cl_half
2329
- FFI.typedef :float, :cl_float
2330
- FFI.typedef :double, :cl_double
2331
- FFI.typedef :uint32, :cl_GLuint
2332
- FFI.typedef :int32, :cl_GLint
2333
- FFI.typedef :uint32, :cl_GLenum
2334
- FFI.typedef :cl_uint, :cl_bool
2335
- FFI.typedef :cl_ulong, :cl_bitfield
2336
- FFI.typedef :cl_bitfield, :cl_device_type
2337
- FFI.typedef :cl_uint, :cl_platform_info
2338
- FFI.typedef :cl_uint, :cl_device_info
2339
- FFI.typedef :cl_bitfield, :cl_device_fp_config
2340
- FFI.typedef :cl_uint, :cl_device_mem_cache_type
2341
- FFI.typedef :cl_uint, :cl_device_local_mem_type
2342
- FFI.typedef :cl_bitfield, :cl_device_exec_capabilities
2343
- FFI.typedef :cl_bitfield, :cl_device_svm_capabilities
2344
- FFI.typedef :cl_bitfield, :cl_command_queue_properties
2345
- FFI.typedef :pointer, :cl_device_partition_property
2346
- FFI.typedef :cl_bitfield, :cl_device_affinity_domain
2347
- FFI.typedef :pointer, :cl_context_properties
2348
- FFI.typedef :cl_uint, :cl_context_info
2349
- FFI.typedef :cl_bitfield, :cl_queue_properties
2350
- FFI.typedef :cl_uint, :cl_command_queue_info
2351
- FFI.typedef :cl_uint, :cl_channel_order
2352
- FFI.typedef :cl_uint, :cl_channel_type
2353
- FFI.typedef :cl_bitfield, :cl_mem_flags
2354
- FFI.typedef :cl_bitfield, :cl_svm_mem_flags
2355
- FFI.typedef :cl_uint, :cl_mem_object_type
2356
- FFI.typedef :cl_uint, :cl_mem_info
2357
- FFI.typedef :cl_bitfield, :cl_mem_migration_flags
2358
- FFI.typedef :cl_uint, :cl_image_info
2359
- FFI.typedef :cl_uint, :cl_buffer_create_type
2360
- FFI.typedef :cl_uint, :cl_addressing_mode
2361
- FFI.typedef :cl_uint, :cl_filter_mode
2362
- FFI.typedef :cl_uint, :cl_sampler_info
2363
- FFI.typedef :cl_bitfield, :cl_map_flags
2364
- FFI.typedef :pointer, :cl_pipe_properties
2365
- FFI.typedef :cl_uint, :cl_pipe_info
2366
- FFI.typedef :cl_uint, :cl_program_info
2367
- FFI.typedef :cl_uint, :cl_program_build_info
2368
- FFI.typedef :cl_uint, :cl_program_binary_type
2369
- FFI.typedef :cl_int, :cl_build_status
2370
- FFI.typedef :cl_uint, :cl_kernel_info
2371
- FFI.typedef :cl_uint, :cl_kernel_arg_info
2372
- FFI.typedef :cl_uint, :cl_kernel_arg_address_qualifier
2373
- FFI.typedef :cl_uint, :cl_kernel_arg_access_qualifier
2374
- FFI.typedef :cl_bitfield, :cl_kernel_arg_type_qualifier
2375
- FFI.typedef :cl_uint, :cl_kernel_work_group_info
2376
- FFI.typedef :cl_uint, :cl_kernel_sub_group_info
2377
- FFI.typedef :cl_uint, :cl_event_info
2378
- FFI.typedef :cl_uint, :cl_command_type
2379
- FFI.typedef :cl_uint, :cl_profiling_info
2380
- FFI.typedef :cl_bitfield, :cl_sampler_properties
2381
- FFI.typedef :cl_uint, :cl_kernel_exec_info
2382
- FFI.typedef :cl_uint, :cl_gl_object_type
2383
- FFI.typedef :cl_uint, :cl_gl_texture_info
2384
- FFI.typedef :cl_uint, :cl_gl_platform_info
2385
- FFI.typedef :cl_uint, :cl_gl_context_info
2386
- FFI.typedef :cl_uint, :cl_queue_priority_khr
2387
- FFI.typedef :cl_uint, :cl_queue_throttle_khr
2318
+
2388
2319
  # A parent class to represent OpenCL enums that use :cl_uint
2389
2320
  class Enum
2390
- # extend FFI::DataConverter
2321
+ # extend DataConverter
2391
2322
  # native_type :cl_uint
2392
2323
  class << self
2393
2324
  attr_reader :codes
@@ -2434,7 +2365,7 @@ module OpenCL
2434
2365
 
2435
2366
  # Enum should be considered an integer
2436
2367
  def coerce(other)
2437
- return [other, FFI::Pointer::new(self.to_i)] if other.is_a?(FFI::Pointer)
2368
+ return [other, Pointer::new(self.to_i)] if other.is_a?(Pointer)
2438
2369
  return [other, self.to_i]
2439
2370
  end
2440
2371
 
@@ -2462,7 +2393,7 @@ module OpenCL
2462
2393
  # end
2463
2394
  #
2464
2395
  # def self.size
2465
- # FFI::find_type(:cl_uint).size
2396
+ # find_type(:cl_uint).size
2466
2397
  # end
2467
2398
  #
2468
2399
  # def self.reference_required?
@@ -2474,13 +2405,13 @@ module OpenCL
2474
2405
 
2475
2406
  # A parent class to represent enums that use cl_int
2476
2407
  class EnumInt < Enum
2477
- # extend FFI::DataConverter
2408
+ # extend DataConverter
2478
2409
  # native_type :cl_int
2479
2410
  end
2480
2411
 
2481
2412
  # A parent class to represent OpenCL bitfields that use :cl_bitfield
2482
2413
  class Bitfield
2483
- # extend FFI::DataConverter
2414
+ # extend DataConverter
2484
2415
  # native_type :cl_bitfield
2485
2416
 
2486
2417
  # Initializes a new Bitfield to val
@@ -2559,7 +2490,7 @@ module OpenCL
2559
2490
  # end
2560
2491
  #
2561
2492
  # def self.size
2562
- # FFI::find_type(:cl_bitfield).size
2493
+ # find_type(:cl_bitfield).size
2563
2494
  # end
2564
2495
  #
2565
2496
  # def self.reference_required?
@@ -2568,7 +2499,7 @@ module OpenCL
2568
2499
  # #:startdoc:
2569
2500
 
2570
2501
  end
2571
- class Platform < FFI::ManagedStruct
2502
+ class Platform < ManagedStruct
2572
2503
  layout :dummy, :pointer
2573
2504
  #:stopdoc:
2574
2505
  PROFILE = 0x0900
@@ -2600,7 +2531,7 @@ module OpenCL
2600
2531
 
2601
2532
  end
2602
2533
 
2603
- class Device < FFI::ManagedStruct
2534
+ class Device < ManagedStruct
2604
2535
  layout :dummy, :pointer
2605
2536
  #:stopdoc:
2606
2537
  TYPE_DEFAULT = (1 << 0)
@@ -2732,7 +2663,7 @@ module OpenCL
2732
2663
  # Creates a new Device and retains it if specified and aplicable
2733
2664
  def initialize(ptr, retain = true)
2734
2665
  super(ptr)
2735
- platform = FFI::MemoryPointer::new( Platform )
2666
+ platform = MemoryPointer::new( Platform )
2736
2667
  OpenCL.clGetDeviceInfo( ptr, OpenCL::Device::PLATFORM, platform.size, platform, nil)
2737
2668
  p = OpenCL::Platform::new(platform.read_pointer)
2738
2669
  if p.version_number >= 1.2 and retain then
@@ -2744,7 +2675,7 @@ module OpenCL
2744
2675
 
2745
2676
  # method called at Device deletion, releases the object if aplicable
2746
2677
  def self.release(ptr)
2747
- platform = FFI::MemoryPointer::new( Platform )
2678
+ platform = MemoryPointer::new( Platform )
2748
2679
  OpenCL.clGetDeviceInfo( ptr, OpenCL::Device::PLATFORM, platform.size, platform, nil)
2749
2680
  p = OpenCL::Platform::new(platform.read_pointer)
2750
2681
  if p.version_number >= 1.2 then
@@ -2889,7 +2820,7 @@ module OpenCL
2889
2820
  end
2890
2821
 
2891
2822
  end
2892
- class Context < FFI::ManagedStruct
2823
+ class Context < ManagedStruct
2893
2824
  layout :dummy, :pointer
2894
2825
  #:stopdoc:
2895
2826
  REFERENCE_COUNT = 0x1080
@@ -2911,7 +2842,7 @@ module OpenCL
2911
2842
  # method called at Context deletion, releases the object if aplicable
2912
2843
  def self.release(ptr)
2913
2844
  #STDERR.puts "Releasing Context: #{ptr}"
2914
- #ref_count = FFI::MemoryPointer::new( :cl_uint )
2845
+ #ref_count = MemoryPointer::new( :cl_uint )
2915
2846
  #OpenCL.clGetContextInfo(ptr, OpenCL::Context::REFERENCE_COUNT, ref_count.size, ref_count, nil)
2916
2847
  #STDERR.puts "reference counter: #{ref_count.read_cl_uint}"
2917
2848
  error = OpenCL.clReleaseContext(ptr)
@@ -2964,7 +2895,7 @@ module OpenCL
2964
2895
  end
2965
2896
  end
2966
2897
 
2967
- class CommandQueue < FFI::ManagedStruct
2898
+ class CommandQueue < ManagedStruct
2968
2899
  layout :dummy, :pointer
2969
2900
  #:stopdoc:
2970
2901
  OUT_OF_ORDER_EXEC_MODE_ENABLE = (1 << 0)
@@ -2995,7 +2926,7 @@ module OpenCL
2995
2926
  # method called at CommandQueue deletion, releases the object if aplicable
2996
2927
  def self.release(ptr)
2997
2928
  #STDERR.puts "Releasing CommandQueue: #{ptr}"
2998
- #ref_count = FFI::MemoryPointer::new( :cl_uint )
2929
+ #ref_count = MemoryPointer::new( :cl_uint )
2999
2930
  #OpenCL.clGetCommandQueueInfo(ptr, OpenCL::CommandQueue::REFERENCE_COUNT, ref_count.size, ref_count, nil)
3000
2931
  #STDERR.puts "reference counter: #{ref_count.read_cl_uint}"
3001
2932
  error = OpenCL.clReleaseCommandQueue(ptr)
@@ -3050,7 +2981,7 @@ module OpenCL
3050
2981
  @codes[(1 << 2)] = 'THROTTLE_LOW_KHR'
3051
2982
  end
3052
2983
  end
3053
- class Mem < FFI::ManagedStruct
2984
+ class Mem < ManagedStruct
3054
2985
  layout :dummy, :pointer
3055
2986
  #:stopdoc:
3056
2987
  READ_WRITE = (1 << 0)
@@ -3099,7 +3030,7 @@ module OpenCL
3099
3030
  # method called at Mem deletion, releases the object if aplicable
3100
3031
  def self.release(ptr)
3101
3032
  #STDERR.puts "Releasing Mem: #{ptr}"
3102
- #ref_count = FFI::MemoryPointer::new( :cl_uint )
3033
+ #ref_count = MemoryPointer::new( :cl_uint )
3103
3034
  #OpenCL.clGetMemObjectInfo(ptr, OpenCL::Mem::REFERENCE_COUNT, ref_count.size, ref_count, nil)
3104
3035
  #STDERR.puts "reference counter: #{ref_count.read_cl_uint}"
3105
3036
  error = OpenCL.clReleaseMemObject(ptr)
@@ -3196,7 +3127,7 @@ module OpenCL
3196
3127
  end
3197
3128
 
3198
3129
  end
3199
- class Program < FFI::ManagedStruct
3130
+ class Program < ManagedStruct
3200
3131
  layout :dummy, :pointer
3201
3132
  #:stopdoc:
3202
3133
  REFERENCE_COUNT = 0x1160
@@ -3230,7 +3161,7 @@ module OpenCL
3230
3161
  # method called at Program deletion, releases the object if aplicable
3231
3162
  def self.release(ptr)
3232
3163
  #STDERR.puts "Releasing Program: #{ptr}"
3233
- #ref_count = FFI::MemoryPointer::new( :cl_uint )
3164
+ #ref_count = MemoryPointer::new( :cl_uint )
3234
3165
  #OpenCL.clGetProgramInfo(ptr, OpenCL::Program::REFERENCE_COUNT, ref_count.size, ref_count, nil)
3235
3166
  #STDERR.puts "reference counter: #{ref_count.read_cl_uint}"
3236
3167
  error = OpenCL.clReleaseProgram(ptr)
@@ -3266,7 +3197,7 @@ module OpenCL
3266
3197
  end
3267
3198
 
3268
3199
  end
3269
- class Kernel < FFI::ManagedStruct
3200
+ class Kernel < ManagedStruct
3270
3201
  layout :dummy, :pointer
3271
3202
  #:stopdoc:
3272
3203
  FUNCTION_NAME = 0x1190
@@ -3317,7 +3248,7 @@ module OpenCL
3317
3248
  # method called at Kernel deletion, releases the object if aplicable
3318
3249
  def self.release(ptr)
3319
3250
  #STDERR.puts "Releasing Kernel: #{ptr}"
3320
- #ref_count = FFI::MemoryPointer::new( :cl_uint )
3251
+ #ref_count = MemoryPointer::new( :cl_uint )
3321
3252
  #OpenCL.clGetKernelInfo(ptr, OpenCL::Kernel::REFERENCE_COUNT, ref_count.size, ref_count, nil)
3322
3253
  #STDERR.puts "reference counter: #{ref_count.read_cl_uint}"
3323
3254
  error = OpenCL.clReleaseKernel(ptr)
@@ -3405,7 +3336,7 @@ module OpenCL
3405
3336
 
3406
3337
  end
3407
3338
  end
3408
- class Event < FFI::ManagedStruct
3339
+ class Event < ManagedStruct
3409
3340
  layout :dummy, :pointer
3410
3341
  #:stopdoc:
3411
3342
  COMMAND_QUEUE = 0x11D0
@@ -3424,7 +3355,7 @@ module OpenCL
3424
3355
  # method called at Event deletion, releases the object if aplicable
3425
3356
  def self.release(ptr)
3426
3357
  #STDERR.puts "Releasing Event: #{ptr}"
3427
- #ref_count = FFI::MemoryPointer::new( :cl_uint )
3358
+ #ref_count = MemoryPointer::new( :cl_uint )
3428
3359
  #OpenCL.clGetEventInfo(ptr, OpenCL::Event::REFERENCE_COUNT, ref_count.size, ref_count, nil)
3429
3360
  #STDERR.puts "reference counter: #{ref_count.read_cl_uint}"
3430
3361
  error = OpenCL.clReleaseEvent(ptr)
@@ -3443,7 +3374,7 @@ module OpenCL
3443
3374
 
3444
3375
  end
3445
3376
 
3446
- class Sampler < FFI::ManagedStruct
3377
+ class Sampler < ManagedStruct
3447
3378
  layout :dummy, :pointer
3448
3379
  #:stopdoc:
3449
3380
  REFERENCE_COUNT = 0x1150
@@ -3465,7 +3396,7 @@ module OpenCL
3465
3396
  # method called at Sampler deletion, releases the object if aplicable
3466
3397
  def self.release(ptr)
3467
3398
  #STDERR.puts "Releasing Sampler: #{ptr}"
3468
- #ref_count = FFI::MemoryPointer::new( :cl_uint )
3399
+ #ref_count = MemoryPointer::new( :cl_uint )
3469
3400
  #OpenCL.clGetSamplerInfo(ptr, OpenCL::Sampler::REFERENCE_COUNT, ref_count.size, ref_count, nil)
3470
3401
  #STDERR.puts "reference counter: #{ref_count.read_cl_uint}"
3471
3402
  error = OpenCL.clReleaseSampler(ptr)
@@ -3483,7 +3414,7 @@ module OpenCL
3483
3414
  end
3484
3415
 
3485
3416
  end
3486
- class GLsync < FFI::ManagedStruct
3417
+ class GLsync < ManagedStruct
3487
3418
  layout :dummy, :pointer
3488
3419
  #:stopdoc:
3489
3420
 
@@ -3928,13 +3859,13 @@ module OpenCL
3928
3859
  attach_function :clCloneKernel, [Kernel,:pointer], Kernel
3929
3860
  attach_function :clGetKernelSubGroupInfo, [Kernel,Device,:cl_kernel_sub_group_info,:size_t,:pointer,:size_t,:pointer,:pointer], :cl_int
3930
3861
  attach_function :clEnqueueSVMMigrateMem, [CommandQueue,:cl_uint,:pointer,:pointer,:cl_mem_migration_flags,:cl_uint,:pointer,:pointer], :cl_int
3931
- rescue FFI::NotFoundError => e
3862
+ rescue NotFoundError => e
3932
3863
  warn "Warning OpenCL 2.0 loader detected!"
3933
3864
  end
3934
- rescue FFI::NotFoundError => e
3865
+ rescue NotFoundError => e
3935
3866
  warn "Warning OpenCL 1.2 loader detected!"
3936
3867
  end
3937
- rescue FFI::NotFoundError => e
3868
+ rescue NotFoundError => e
3938
3869
  warn "Warning OpenCL 1.1 loader detected!"
3939
3870
  end
3940
3871
  end
@@ -0,0 +1,114 @@
1
+ require 'ffi'
2
+
3
+ module OpenCL
4
+ include FFI
5
+ extend Library
6
+
7
+ TYPES = [
8
+ [ :int8, :cl_char ],
9
+ [ :uint8, :cl_uchar ],
10
+ [ :int16, :cl_short ],
11
+ [ :uint16, :cl_ushort ],
12
+ [ :int32, :cl_int ],
13
+ [ :uint32, :cl_uint ],
14
+ [ :int64, :cl_long ],
15
+ [ :uint64, :cl_ulong ],
16
+ [ :uint16, :cl_half ],
17
+ [ :float, :cl_float ],
18
+ [ :double, :cl_double ],
19
+ [ :uint32, :cl_GLuint ],
20
+ [ :int32, :cl_GLint ],
21
+ [ :uint32, :cl_GLenum ],
22
+ [ :cl_uint, :cl_bool ],
23
+ [ :cl_ulong, :cl_bitfield ],
24
+ [ :cl_bitfield, :cl_device_type ],
25
+ [ :cl_uint, :cl_platform_info ],
26
+ [ :cl_uint, :cl_device_info ],
27
+ [ :cl_bitfield, :cl_device_fp_config ],
28
+ [ :cl_uint, :cl_device_mem_cache_type ],
29
+ [ :cl_uint, :cl_device_local_mem_type ],
30
+ [ :cl_bitfield, :cl_device_exec_capabilities ],
31
+ [ :cl_bitfield, :cl_device_svm_capabilities ],
32
+ [ :cl_bitfield, :cl_command_queue_properties ],
33
+ [ :pointer, :cl_device_partition_property ],
34
+ [ :cl_bitfield, :cl_device_affinity_domain ],
35
+ [ :pointer, :cl_context_properties ],
36
+ [ :cl_uint, :cl_context_info ],
37
+ [ :cl_bitfield, :cl_queue_properties ],
38
+ [ :cl_uint, :cl_command_queue_info ],
39
+ [ :cl_uint, :cl_channel_order ],
40
+ [ :cl_uint, :cl_channel_type ],
41
+ [ :cl_bitfield, :cl_mem_flags ],
42
+ [ :cl_bitfield, :cl_svm_mem_flags ],
43
+ [ :cl_uint, :cl_mem_object_type ],
44
+ [ :cl_uint, :cl_mem_info ],
45
+ [ :cl_bitfield, :cl_mem_migration_flags ],
46
+ [ :cl_uint, :cl_image_info ],
47
+ [ :cl_uint, :cl_buffer_create_type ],
48
+ [ :cl_uint, :cl_addressing_mode ],
49
+ [ :cl_uint, :cl_filter_mode ],
50
+ [ :cl_uint, :cl_sampler_info ],
51
+ [ :cl_bitfield, :cl_map_flags ],
52
+ [ :pointer, :cl_pipe_properties ],
53
+ [ :cl_uint, :cl_pipe_info ],
54
+ [ :cl_uint, :cl_program_info ],
55
+ [ :cl_uint, :cl_program_build_info ],
56
+ [ :cl_uint, :cl_program_binary_type ],
57
+ [ :cl_int, :cl_build_status ],
58
+ [ :cl_uint, :cl_kernel_info ],
59
+ [ :cl_uint, :cl_kernel_arg_info ],
60
+ [ :cl_uint, :cl_kernel_arg_address_qualifier ],
61
+ [ :cl_uint, :cl_kernel_arg_access_qualifier ],
62
+ [ :cl_bitfield, :cl_kernel_arg_type_qualifier ],
63
+ [ :cl_uint, :cl_kernel_work_group_info ],
64
+ [ :cl_uint, :cl_kernel_sub_group_info ],
65
+ [ :cl_uint, :cl_event_info ],
66
+ [ :cl_uint, :cl_command_type ],
67
+ [ :cl_uint, :cl_profiling_info ],
68
+ [ :cl_bitfield, :cl_sampler_properties ],
69
+ [ :cl_uint, :cl_kernel_exec_info ],
70
+ [ :cl_uint, :cl_gl_object_type ],
71
+ [ :cl_uint, :cl_gl_texture_info ],
72
+ [ :cl_uint, :cl_gl_platform_info ],
73
+ [ :cl_uint, :cl_gl_context_info ],
74
+ [ :cl_uint, :cl_queue_priority_khr ],
75
+ [ :cl_uint, :cl_queue_throttle_khr ]
76
+ ]
77
+
78
+ TYPES.each { |orig, add|
79
+ typedef orig, add
80
+ }
81
+ TYPES.push [ FFI::TypeDefs.find { |name,t| t == FFI.find_type(:size_t) }.first, :size_t]
82
+ end
83
+
84
+ if RUBY_VERSION.scan(/\d+/).collect(&:to_i).first >= 2
85
+
86
+ module OpenCLRefinements
87
+
88
+ refine FFI::Pointer do
89
+ methods_prefix = [:put, :get, :write, :read, :put_array_of, :get_array_of]
90
+ OpenCL::TYPES.each { |orig, add|
91
+ methods_prefix.each { |meth|
92
+ alias_method "#{meth}_#{add}".to_sym, "#{meth}_#{orig}".to_sym
93
+ }
94
+ }
95
+ end
96
+
97
+ end
98
+ using OpenCLRefinements
99
+ else
100
+
101
+ class FFI::Pointer
102
+ methods_prefix = [:put, :get, :write, :read, :put_array_of, :get_array_of]
103
+ OpenCL::TYPES.each { |orig, add|
104
+ methods_prefix.each { |meth|
105
+ alias_method "#{meth}_#{add}".to_sym, "#{meth}_#{orig}".to_sym
106
+ }
107
+ }
108
+ end
109
+
110
+ end
111
+
112
+ module OpenCL
113
+ remove_const(:TYPES)
114
+ end
@@ -1,6 +1,7 @@
1
+ require "opencl_ruby_ffi/opencl_types.rb"
1
2
  require "opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb"
3
+ require "opencl_ruby_ffi/opencl_arithmetic_gen.rb"
2
4
  require "opencl_ruby_ffi/opencl_ruby_ffi_base.rb"
3
- require "opencl_ruby_ffi/Arithmetic_gen.rb"
4
5
  require "opencl_ruby_ffi/Context.rb"
5
6
  require "opencl_ruby_ffi/Platform.rb"
6
7
  require "opencl_ruby_ffi/Device.rb"
@@ -1,12 +1,12 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'opencl_ruby_ffi'
3
- s.version = "1.1.0"
3
+ s.version = "1.2.0"
4
4
  s.author = "Brice Videau"
5
5
  s.email = "brice.videau@imag.fr"
6
6
  s.homepage = "https://github.com/Nanosim-LIG/opencl-ruby"
7
7
  s.summary = "Ruby OpenCL FFI bindings"
8
8
  s.description = "Ruby OpenCL FFI bindings. OpenCL 2.1 ready"
9
- s.files = %w( opencl_ruby_ffi.gemspec LICENSE lib/opencl_ruby_ffi.rb lib/opencl_ruby_ffi/ lib/opencl_ruby_ffi/Arithmetic_gen.rb lib/opencl_ruby_ffi/Buffer.rb lib/opencl_ruby_ffi/CommandQueue.rb lib/opencl_ruby_ffi/Context.rb lib/opencl_ruby_ffi/Device.rb lib/opencl_ruby_ffi/Event.rb lib/opencl_ruby_ffi/Image.rb lib/opencl_ruby_ffi/Kernel.rb lib/opencl_ruby_ffi/Mem.rb lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb lib/opencl_ruby_ffi/opencl_ruby_ffi_base.rb lib/opencl_ruby_ffi/Platform.rb lib/opencl_ruby_ffi/Program.rb lib/opencl_ruby_ffi/Sampler.rb lib/opencl_ruby_ffi/Pipe.rb lib/opencl_ruby_ffi/SVM.rb lib/opencl_ruby_ffi/GLExt.rb )
9
+ s.files = Dir[ 'opencl_ruby_ffi.gemspec', 'LICENSE', 'lib/**/*']
10
10
  s.has_rdoc = true
11
11
  s.license = 'BSD'
12
12
  s.required_ruby_version = '>= 1.8.7'