opencl_ruby_ffi 1.2.2 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -0
  3. data/lib/opencl_ruby_ffi.rb +2 -0
  4. data/lib/opencl_ruby_ffi/Buffer.rb +18 -13
  5. data/lib/opencl_ruby_ffi/CommandQueue.rb +301 -302
  6. data/lib/opencl_ruby_ffi/Context.rb +158 -158
  7. data/lib/opencl_ruby_ffi/Device.rb +270 -224
  8. data/lib/opencl_ruby_ffi/Event.rb +40 -36
  9. data/lib/opencl_ruby_ffi/Image.rb +34 -57
  10. data/lib/opencl_ruby_ffi/Kernel.rb +251 -191
  11. data/lib/opencl_ruby_ffi/Mem.rb +49 -70
  12. data/lib/opencl_ruby_ffi/Pipe.rb +3 -14
  13. data/lib/opencl_ruby_ffi/Platform.rb +46 -48
  14. data/lib/opencl_ruby_ffi/Program.rb +131 -124
  15. data/lib/opencl_ruby_ffi/Sampler.rb +6 -24
  16. data/lib/opencl_ruby_ffi/amd/device_attribute_query.rb +100 -0
  17. data/lib/opencl_ruby_ffi/egl.rb +2 -0
  18. data/lib/opencl_ruby_ffi/ext.rb +11 -0
  19. data/lib/opencl_ruby_ffi/ext/device_fission.rb +264 -0
  20. data/lib/opencl_ruby_ffi/gl_ext.rb +2 -0
  21. data/lib/opencl_ruby_ffi/khr/d3d10_sharing.rb +120 -0
  22. data/lib/opencl_ruby_ffi/khr/d3d11_sharing.rb +120 -0
  23. data/lib/opencl_ruby_ffi/khr/dx9_media_sharing.rb +113 -0
  24. data/lib/opencl_ruby_ffi/khr/egl_event.rb +15 -0
  25. data/lib/opencl_ruby_ffi/khr/egl_image.rb +58 -0
  26. data/lib/opencl_ruby_ffi/khr/fp16.rb +23 -0
  27. data/lib/opencl_ruby_ffi/khr/fp64.rb +23 -0
  28. data/lib/opencl_ruby_ffi/khr/gl_event.rb +38 -0
  29. data/lib/opencl_ruby_ffi/khr/gl_sharing.rb +79 -0
  30. data/lib/opencl_ruby_ffi/khr/icd.rb +30 -0
  31. data/lib/opencl_ruby_ffi/khr/initalize_memory.rb +19 -0
  32. data/lib/opencl_ruby_ffi/khr/priority_hints.rb +48 -0
  33. data/lib/opencl_ruby_ffi/khr/spir.rb +45 -0
  34. data/lib/opencl_ruby_ffi/khr/sub_groups.rb +49 -0
  35. data/lib/opencl_ruby_ffi/khr/terminate_context.rb +46 -0
  36. data/lib/opencl_ruby_ffi/khr/throttle_hints.rb +47 -0
  37. data/lib/opencl_ruby_ffi/nv/device_attribute_query.rb +50 -0
  38. data/lib/opencl_ruby_ffi/opencl_ruby_ffi_base.rb +40 -13
  39. data/lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb +214 -2114
  40. data/lib/opencl_ruby_ffi/opencl_types.rb +15 -3
  41. data/opencl_ruby_ffi.gemspec +4 -4
  42. data/templates_custom/default/module/setup.rb +9 -0
  43. metadata +29 -6
  44. data/lib/opencl_ruby_ffi/GLExt.rb +0 -58
  45. data/lib/opencl_ruby_ffi/Stream.rb +0 -127
@@ -0,0 +1,30 @@
1
+ require 'opencl_ruby_ffi'
2
+ using OpenCLRefinements if RUBY_VERSION.scan(/\d+/).collect(&:to_i).first >= 2
3
+
4
+ module OpenCL
5
+
6
+ PLATFORM_NOT_FOUND_KHR = -1001
7
+
8
+ PLATFORM_ICD_SUFFIX_KHR = 0x0920
9
+
10
+ class Error
11
+
12
+ eval error_class_constructor( :PLATFORM_NOT_FOUND_KHR, :PlatformNotFoundKHR )
13
+
14
+ end
15
+
16
+ class Platform
17
+ ICD_SUFFIX_KHR = 0x0920
18
+
19
+ module KHRICD
20
+ extend InnerGenerator
21
+
22
+ get_info("Platform", :string, "icd_suffix_khr")
23
+
24
+ end
25
+
26
+ register_extension( :cl_khr_icd, KHRICD, "extensions.include?(\"cl_khr_icd\")" )
27
+
28
+ end
29
+
30
+ end
@@ -0,0 +1,19 @@
1
+ require 'opencl_ruby_ffi'
2
+ using OpenCLRefinements if RUBY_VERSION.scan(/\d+/).collect(&:to_i).first >= 2
3
+
4
+ module OpenCL
5
+
6
+ CONTEXT_MEMORY_INITIALIZE_KHR = 0x200E
7
+
8
+ class Context
9
+
10
+ MEMORY_INITIALIZE_KHR = 0x200E
11
+
12
+ class Properties
13
+ MEMORY_INITIALIZE_KHR = 0x2030
14
+ @codes[0x2030] = 'MEMORY_INITIALIZE_KHR'
15
+ end
16
+
17
+ end
18
+
19
+ end
@@ -0,0 +1,48 @@
1
+ require 'opencl_ruby_ffi'
2
+ using OpenCLRefinements if RUBY_VERSION.scan(/\d+/).collect(&:to_i).first >= 2
3
+
4
+ module OpenCL
5
+
6
+ QUEUE_PRIORITY_KHR = 0x1096
7
+ QUEUE_PRIORITY_HIGH_KHR = (1<<0)
8
+ QUEUE_PRIORITY_MED_KHR = (1<<1)
9
+ QUEUE_PRIORITY_LOW_KHR = (1<<2)
10
+
11
+ class CommandQueue
12
+
13
+ PRIORITY_KHR = 0x1096
14
+ PRIORITY_HIGH_KHR = (1 << 0)
15
+ PRIORITY_MED_KHR = (1 << 1)
16
+ PRIORITY_LOW_KHR = (1 << 2)
17
+
18
+ class PriorityKHR < Enum
19
+ HIGH_KHR = (1 << 0)
20
+ MED_KHR = (1 << 1)
21
+ LOW_KHR = (1 << 2)
22
+ @codes = {}
23
+ @codes[(1 << 0)] = 'HIGH_KHR'
24
+ @codes[(1 << 1)] = 'MED_KHR'
25
+ @codes[(1 << 2)] = 'LOW_KHR'
26
+ end
27
+
28
+ end
29
+
30
+ module InnerInterface
31
+ TYPE_CONVERTER[:cl_queue_priority_khr] = CommandQueue::PriorityKHR
32
+ end
33
+
34
+ class CommandQueue
35
+
36
+ module KHRPriorityHints
37
+
38
+ extend InnerGenerator
39
+
40
+ get_info("CommandQueue", :cl_queue_priority_khr, "priority_khr")
41
+
42
+ end
43
+
44
+ register_extension( :cl_khr_priority_hints, KHRPriorityHints, "device.platform.extensions.include?(\"cl_khr_priority_hints\")" )
45
+
46
+ end
47
+
48
+ end
@@ -0,0 +1,45 @@
1
+ require 'opencl_ruby_ffi'
2
+ using OpenCLRefinements if RUBY_VERSION.scan(/\d+/).collect(&:to_i).first >= 2
3
+
4
+ module OpenCL
5
+
6
+ DEVICE_SPIR_VERSIONS = 0x40E0
7
+ PROGRAM_BINARY_TYPE_INTERMEDIATE = 0x40E1
8
+
9
+ class Device
10
+ SPIR_VERSIONS = 0x40E0
11
+
12
+ module KHRSPIR
13
+
14
+ # Return an Array of String corresponding to the SPIR versions supported by the device
15
+ def spir_versions
16
+ spir_versions_size = MemoryPointer::new( :size_t )
17
+ error = OpenCL.clGetDeviceInfo( self, SPIR_VERSIONS, 0, nil, spir_versions_size)
18
+ error_check(error)
19
+ vers = MemoryPointer::new( spir_versions_size.read_size_t )
20
+ error = OpenCL.clGetDeviceInfo( self, SPIR_VERSIONS, spir_versions_size.read_size_t, vers, nil)
21
+ error_check(error)
22
+ vers_string = vers.read_string
23
+ return vers_string.split(" ")
24
+ end
25
+
26
+ def spir_versions_number
27
+ vers_strings = spir_versions
28
+ return vers_strings.collect { |s| s.scan(/(\d+\.\d+)/).first.first.to_f }
29
+ end
30
+
31
+ end
32
+
33
+ register_extension( :cl_khr_spir, KHRSPIR, "platform.extensions.include?(\"cl_khr_spir\") or extensions.include?(\"cl_khr_spir\")" )
34
+
35
+ end
36
+
37
+ class Program
38
+ BINARY_TYPE_INTERMEDIATE = 0x40E1
39
+ class BinaryType
40
+ INTERMEDIATE = 0x40E1
41
+ @codes[0x40E1] = 'INTERMEDIATE'
42
+ end
43
+ end
44
+
45
+ end
@@ -0,0 +1,49 @@
1
+ require 'opencl_ruby_ffi'
2
+ using OpenCLRefinements if RUBY_VERSION.scan(/\d+/).collect(&:to_i).first >= 2
3
+
4
+ module OpenCL
5
+
6
+ KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR = 0x2033
7
+ KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE_KHR = 0x2034
8
+
9
+ attach_extension_function( "clGetKernelSubGroupInfoKHR", :cl_int, [Kernel, Device, :size_t, :pointer, :size_t, :pointer, :pointer] )
10
+
11
+ class Kernel
12
+ MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR = 0x2033
13
+ SUB_GROUP_COUNT_FOR_NDRANGE_KHR = 0x2034
14
+
15
+ module KHRSubGroups
16
+
17
+ def max_sub_group_size_for_ndrange_khr(local_work_size, device = program.devices.first)
18
+ error_check(INVALID_OPERATION) unless device.extensions.include?( "cl_khr_sub_groups" )
19
+ local_work_size = [local_work_size].flatten
20
+ lws_p = MemoryPointer::new( :size_t, local_work_size.length )
21
+ local_work_size.each_with_index { |e,i|
22
+ lws_p[i].write_size_t( e )
23
+ }
24
+ ptr = MemoryPointer::new( :size_t )
25
+ error = OpenCL.clGetKernelSubGroupInfoKHR(self, device, MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR, lws_p.size, lws_p, ptr.size, ptr, nil)
26
+ error_check(error)
27
+ return ptr.read_size_t
28
+ end
29
+
30
+ def sub_groups_count_for_ndrange_khr(local_work_size, device = program.devices.first)
31
+ error_check(INVALID_OPERATION) unless device.extensions.include?( "cl_khr_sub_groups" )
32
+ local_work_size = [local_work_size].flatten
33
+ lws_p = MemoryPointer::new( :size_t, local_work_size.length )
34
+ local_work_size.each_with_index { |e,i|
35
+ lws_p[i].write_size_t( e )
36
+ }
37
+ ptr = MemoryPointer::new( :size_t )
38
+ error = OpenCL.clGetKernelSubGroupInfoKHR(self, device, SUB_GROUP_COUNT_FOR_NDRANGE_KHR, lws_p.size, lws_p, ptr.size, ptr, nil)
39
+ error_check(error)
40
+ return ptr.read_size_t
41
+ end
42
+
43
+ end
44
+
45
+ register_extension( :cl_khr_sub_groups, KHRSubGroups, "program.devices.collect(&:extensions).flatten.include?(\"cl_khr_sub_groups\")" )
46
+
47
+ end
48
+
49
+ end
@@ -0,0 +1,46 @@
1
+ require 'opencl_ruby_ffi'
2
+ using OpenCLRefinements if RUBY_VERSION.scan(/\d+/).collect(&:to_i).first >= 2
3
+
4
+ module OpenCL
5
+
6
+ DEVICE_TERMINATE_CAPABILITY_KHR = 0x2031
7
+ CONTEXT_TERMINATE_KHR = 0x2032
8
+
9
+ attach_extension_function("clTerminateContextKHR", :cl_int, [Context])
10
+
11
+ def self.terminate_context_khr( context )
12
+ error_check(INVALID_OPERATION) unless context.platform.extensions.include? "cl_khr_terminate_context"
13
+ error = clTerminateContextKHR( context )
14
+ error_check(error)
15
+ end
16
+
17
+ class Device
18
+
19
+ TERMINATE_CAPABILITY_KHR = 0x2031
20
+
21
+ get_info("Device", :cl_bitfield, "terminate_capability_khr")
22
+
23
+ end
24
+
25
+ class Context
26
+
27
+ TERMINATE_KHR = 0x2032
28
+
29
+ class Properties
30
+ TERMINATE_KHR = 0x2032
31
+ @codes[0x2032] = 'TERMINATE_KHR'
32
+ end
33
+
34
+ module KHRTerminateContext
35
+
36
+ def terminate_context_khr
37
+ return OpenCL.terminate_context_khr(self)
38
+ end
39
+
40
+ end
41
+
42
+ register_extension( :cl_khr_terminate_context, KHRTerminateContext, "platform.extensions.include?(\"cl_khr_terminate_context\")" )
43
+
44
+ end
45
+
46
+ end
@@ -0,0 +1,47 @@
1
+ require 'opencl_ruby_ffi'
2
+ using OpenCLRefinements if RUBY_VERSION.scan(/\d+/).collect(&:to_i).first >= 2
3
+
4
+ module OpenCL
5
+
6
+ QUEUE_THROTTLE_KHR = 0x1097
7
+ QUEUE_THROTTLE_HIGH_KHR = (1<<0)
8
+ QUEUE_THROTTLE_MED_KHR = (1<<1)
9
+ QUEUE_THROTTLE_LOW_KHR = (1<<2)
10
+
11
+ class CommandQueue
12
+
13
+ THROTTLE_KHR = 0x1097
14
+ THROTTLE_HIGH_KHR = (1 << 0)
15
+ THROTTLE_MED_KHR = (1 << 1)
16
+ THROTTLE_LOW_KHR = (1 << 2)
17
+
18
+ class ThrottleKHR < Enum
19
+ HIGH_KHR = (1 << 0)
20
+ MED_KHR = (1 << 1)
21
+ LOW_KHR = (1 << 2)
22
+ @codes = {}
23
+ @codes[(1 << 0)] = 'HIGH_KHR'
24
+ @codes[(1 << 1)] = 'MED_KHR'
25
+ @codes[(1 << 2)] = 'LOW_KHR'
26
+ end
27
+
28
+ end
29
+
30
+ module InnerInterface
31
+ TYPE_CONVERTER[:cl_queue_throttle_khr] = CommandQueue::ThrottleKHR
32
+ end
33
+
34
+ class CommandQueue
35
+
36
+ module KHRThrottleHints
37
+ extend InnerGenerator
38
+
39
+ get_info("CommandQueue", :cl_queue_throttle_khr, "throttle_khr")
40
+
41
+ end
42
+
43
+ register_extension( :cl_khr_throttle_hints, KHRThrottleHints, "device.platform.extensions.include?(\"cl_khr_throttle_hints\")" )
44
+
45
+ end
46
+
47
+ end
@@ -0,0 +1,50 @@
1
+ require 'opencl_ruby_ffi'
2
+ using OpenCLRefinements if RUBY_VERSION.scan(/\d+/).collect(&:to_i).first >= 2
3
+
4
+ module OpenCL
5
+
6
+ DEVICE_COMPUTE_CAPABILITY_MAJOR_NV = 0x4000
7
+ DEVICE_COMPUTE_CAPABILITY_MINOR_NV = 0x4001
8
+ DEVICE_REGISTERS_PER_BLOCK_NV = 0x4002
9
+ DEVICE_WARP_SIZE_NV = 0x4003
10
+ DEVICE_GPU_OVERLAP_NV = 0x4004
11
+ DEVICE_KERNEL_EXEC_TIMEOUT_NV = 0x4005
12
+ DEVICE_INTEGRATED_MEMORY_NV = 0x4006
13
+ DEVICE_ATTRIBUTE_ASYNC_ENGINE_COUNT_NV = 0x4007
14
+ DEVICE_PCI_BUS_ID_NV = 0x4008
15
+ DEVICE_PCI_SLOT_ID_NV = 0x4009
16
+
17
+ class Device
18
+
19
+ COMPUTE_CAPABILITY_MAJOR_NV = 0x4000
20
+ COMPUTE_CAPABILITY_MINOR_NV = 0x4001
21
+ REGISTERS_PER_BLOCK_NV = 0x4002
22
+ WARP_SIZE_NV = 0x4003
23
+ GPU_OVERLAP_NV = 0x4004
24
+ KERNEL_EXEC_TIMEOUT_NV = 0x4005
25
+ INTEGRATED_MEMORY_NV = 0x4006
26
+ ATTRIBUTE_ASYNC_ENGINE_COUNT_NV = 0x4007
27
+ PCI_BUS_ID_NV = 0x4008
28
+ PCI_SLOT_ID_NV = 0x4009
29
+
30
+ module NVDeviceAttributeQuery
31
+ extend InnerGenerator
32
+
33
+ get_info("Device", :cl_uint, "compute_capability_major_nv")
34
+ get_info("Device", :cl_uint, "compute_capability_minor_nv")
35
+ get_info("Device", :cl_uint, "registers_per_block_nv")
36
+ get_info("Device", :cl_uint, "warp_size_nv")
37
+ get_info("Device", :cl_uint, "attribute_async_engine_count_nv")
38
+ get_info("Device", :cl_uint, "pci_bus_id_nv")
39
+ get_info("Device", :cl_uint, "pci_slot_id_nv")
40
+ get_info("Device", :cl_bool, "gpu_overlap_nv")
41
+ get_info("Device", :cl_bool, "kernel_exec_timeout_nv")
42
+ get_info("Device", :cl_bool, "integrated_memory_nv")
43
+
44
+ end
45
+
46
+ register_extension( :cl_nv_device_attribute_query, NVDeviceAttributeQuery, "extensions.include?(\"cl_nv_device_attribute_query\")" )
47
+
48
+ end
49
+
50
+ end
@@ -29,6 +29,12 @@ module OpenCL
29
29
 
30
30
  end
31
31
 
32
+ class Struct < FFI::Struct
33
+ end
34
+
35
+ class Union < FFI::Union
36
+ end
37
+
32
38
  @@callbacks = []
33
39
 
34
40
  # Maps the :cl_image_fomat type of OpenCL
@@ -120,7 +126,6 @@ module OpenCL
120
126
  end
121
127
  end
122
128
 
123
- #:stopdoc:
124
129
  module InnerInterface
125
130
 
126
131
  private
@@ -241,8 +246,6 @@ module OpenCL
241
246
  :cl_device_local_mem_type => Device::LocalMemType,
242
247
  :cl_device_exec_capabilities => Device::ExecCapabilities,
243
248
  :cl_command_queue_properties => CommandQueue::Properties,
244
- :cl_queue_priority_khr => CommandQueue::PriorityKHR,
245
- :cl_queue_throttle_khr => CommandQueue::ThrottleKHR,
246
249
  :cl_device_affinity_domain => Device::AffinityDomain,
247
250
  :cl_device_svm_capabilities => Device::SVMCapabilities,
248
251
  :cl_channel_order => ChannelOrder,
@@ -285,17 +288,24 @@ module OpenCL
285
288
 
286
289
  private
287
290
 
288
- # 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.
291
+ # Generates a new method for klass that use the apropriate clGetKlassInfo, to read an info of the given type. The info queried is specified by name.
292
+ # @param [String] klass the property is to be found
293
+ # @param [Symbol] type of the property
294
+ # @param [String] name of the property
295
+ # @!macro [attach] get_info
296
+ # @!method $3
297
+ # Returns the OpenCL::$1::$3 info
298
+ # @return $2
289
299
  def get_info(klass, type, name)
290
300
  klass_name = klass
291
301
  klass_name = "MemObject" if klass == "Mem"
292
302
  s = <<EOF
293
303
  def #{name.downcase}
294
304
  ptr1 = MemoryPointer::new( :size_t, 1)
295
- error = OpenCL.clGet#{klass_name}Info(self, #{klass}::#{name}, 0, nil, ptr1)
305
+ error = OpenCL.clGet#{klass_name}Info(self, #{klass}::#{name.upcase}, 0, nil, ptr1)
296
306
  error_check(error)
297
307
  ptr2 = MemoryPointer::new( ptr1.read_size_t )
298
- error = OpenCL.clGet#{klass_name}Info(self, #{klass}::#{name}, ptr1.read_size_t, ptr2, nil)
308
+ error = OpenCL.clGet#{klass_name}Info(self, #{klass}::#{name.upcase}, ptr1.read_size_t, ptr2, nil)
299
309
  error_check(error)
300
310
  if(convert_type(:#{type})) then
301
311
  return convert_type(:#{type})::new(ptr2.read_#{type})
@@ -304,30 +314,47 @@ module OpenCL
304
314
  end
305
315
  end
306
316
  EOF
307
- return s
317
+ if type == :cl_bool then
318
+ s += <<EOF
319
+ def #{name.downcase}?
320
+ #{name.downcase} == 0 ? false : true
321
+ end
322
+ EOF
323
+ end
324
+ module_eval s
308
325
  end
309
326
 
310
- # 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.
327
+ # 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.
328
+ # @param [String] klass the property is to be found
329
+ # @param [Symbol] type of the property
330
+ # @param [String] name of the property
331
+ # @!macro [attach] get_info_array
332
+ # @!method $3
333
+ # Returns the OpenCL::$1::$3 info
334
+ # @return an Array of $2
311
335
  def get_info_array(klass, type, name)
312
336
  klass_name = klass
313
337
  klass_name = "MemObject" if klass == "Mem"
314
338
  s = <<EOF
315
339
  def #{name.downcase}
316
340
  ptr1 = MemoryPointer::new( :size_t, 1)
317
- error = OpenCL.clGet#{klass_name}Info(self, #{klass}::#{name}, 0, nil, ptr1)
341
+ error = OpenCL.clGet#{klass_name}Info(self, #{klass}::#{name.upcase}, 0, nil, ptr1)
318
342
  error_check(error)
319
343
  ptr2 = MemoryPointer::new( ptr1.read_size_t )
320
- error = OpenCL.clGet#{klass_name}Info(self, #{klass}::#{name}, ptr1.read_size_t, ptr2, nil)
344
+ error = OpenCL.clGet#{klass_name}Info(self, #{klass}::#{name.upcase}, ptr1.read_size_t, ptr2, nil)
321
345
  error_check(error)
322
346
  arr = ptr2.get_array_of_#{type}(0, ptr1.read_size_t/ OpenCL.find_type(:#{type}).size)
323
- return arr
347
+ if(convert_type(:#{type})) then
348
+ return arr.collect { |e| convert_type(:#{type})::new(e) }
349
+ else
350
+ return arr
351
+ end
324
352
  end
325
353
  EOF
326
- return s
354
+ module_eval s
327
355
  end
328
356
 
329
357
  end
330
358
  private_constant :InnerGenerator
331
- #:startdoc:
332
359
 
333
360
  end