opencl_ruby_ffi 1.3.6 → 1.3.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,95 @@
1
+ if RUBY_VERSION.scan(/\d+/).collect(&:to_i).first >= 2
2
+ using OpenCLRefinements
3
+ end
4
+
5
+ module OpenCL
6
+
7
+ # Unofficial kernel profiling extension
8
+ CONTEXT_KERNEL_PROFILING_MODES_COUNT_INTEL = 0x407A
9
+ CONTEXT_KERNEL_PROFILING_MODE_INFO_INTEL = 0x407B
10
+ KERNEL_IL_SYMBOLS_INTEL = 0x407C
11
+ KERNEL_BINARY_PROGRAM_INTEL = 0x407D
12
+ # Unofficial VTune Debug Info extension
13
+ PROGRAM_DEBUG_INFO_INTEL = 0x4100
14
+ PROGRAM_DEBUG_INFO_SIZES_INTEL = 0x4101
15
+ KERNEL_BINARIES_INTEL = 0x4102
16
+ KERNEL_BINARY_SIZES_INTEL = 0x4103
17
+
18
+ class Kernel
19
+ IL_SYMBOLS_INTEL = 0x407C
20
+ BINARY_PROGRAM_INTEL = 0x407D
21
+ BINARIES_INTEL = 0x4102
22
+ BINARY_SIZES_INTEL = 0x4103
23
+
24
+ def binary_program_intel(device = program.devices.first)
25
+ sz = MemoryPointer::new( :size_t )
26
+ begin
27
+ error = OpenCL.clGetKernelWorkGroupInfo(self, device, BINARY_PROGRAM_INTEL, 0, nil, sz)
28
+ error_check(error)
29
+ sz = sz.read_size_t
30
+ bin = MemoryPointer::new(sz)
31
+ error = OpenCL.clGetKernelWorkGroupInfo(self, device, BINARY_PROGRAM_INTEL, sz, bin, nil)
32
+ error_check(error)
33
+ return bin.read_bytes(sz)
34
+ rescue
35
+ error = OpenCL.clGetKernelInfo(self, BINARY_PROGRAM_INTEL, 0, nil, sz)
36
+ error_check(error)
37
+ sz = sz.read_size_t
38
+ bin = MemoryPointer::new(sz)
39
+ error = OpenCL.clGetKernelInfo(self, BINARY_PROGRAM_INTEL, sz, bin, nil)
40
+ error_check(error)
41
+ return bin.read_bytes(sz)
42
+ end
43
+ end
44
+
45
+ get_info_array("Kernel", :size_t, "binary_sizes_intel")
46
+
47
+ def binaries_intel
48
+ sizes = self.binary_sizes_intel
49
+ bin_array = MemoryPointer::new( :pointer, sizes.length )
50
+ total_size = 0
51
+ pointers = []
52
+ sizes.each_with_index { |s, i|
53
+ total_size += s
54
+ pointers[i] = MemoryPointer::new(s)
55
+ bin_array[i].write_pointer(pointers[i])
56
+ }
57
+ error = OpenCL.clGetKernelInfo(self, BINARIES_INTEL, total_size, bin_array, nil)
58
+ error_check(error)
59
+ bins = []
60
+ devs = self.program.devices
61
+ sizes.each_with_index { |s, i|
62
+ bins.push [devs[i], pointers[i].read_bytes(s)]
63
+ }
64
+ return bins
65
+ end
66
+
67
+ end
68
+
69
+ class Program
70
+ DEBUG_INFO_INTEL = 0x4100
71
+ DEBUG_INFO_SIZES_INTEL = 0x4101
72
+
73
+ get_info_array("Program", :size_t, "debug_info_sizes_intel")
74
+
75
+ def debug_info_intel
76
+ sizes = self.debug_info_sizes_intel
77
+ bin_array = MemoryPointer::new( :pointer, sizes.length )
78
+ total_size = 0
79
+ sizes.each_with_index { |s, i|
80
+ total_size += s
81
+ pointers[i] = MemoryPointer::new(s)
82
+ bin_array[i].write_pointer(pointers[i])
83
+ }
84
+ error = OpenCL.clGetProgramInfo(self, DEBUG_INFO_INTEL, total_size, bin_array, nil)
85
+ error_check(error)
86
+ bins = []
87
+ devs = self.devices
88
+ sizes.each_with_index { |s, i|
89
+ bins.push [devs[i], pointers[i].read_bytes(s)]
90
+ }
91
+ return bins
92
+ end
93
+ end
94
+
95
+ end
@@ -35,7 +35,7 @@ module OpenCL
35
35
  class Union < FFI::Union
36
36
  end
37
37
 
38
- @@callbacks = []
38
+ @@callbacks = {}
39
39
 
40
40
  # Maps the :cl_image_fomat type of OpenCL
41
41
  class ImageFormat < Struct
@@ -287,7 +287,7 @@ module OpenCL
287
287
  module ExtensionInnerGenerator
288
288
 
289
289
  private
290
- # Generates a new method for klass that use the given clGetKlassInfo on the object platform, to read an info of the given type. The info queried is specified by name.
290
+ # Generates a new method for klass that use the given clGetKlassInfo extension of the object's platform, to read an info of the given type. The info queried is specified by name.
291
291
  # @param [String] klass the property is to be found
292
292
  # @param [Symbol] type of the property
293
293
  # @param [String] name of the property
@@ -295,18 +295,38 @@ module OpenCL
295
295
  # @!method $3
296
296
  # Returns the OpenCL::$1::$3 info
297
297
  # @return $2
298
- def get_info_ext(klass, type, name, function)
299
- klass_name = klass
300
- klass_name = "MemObject" if klass == "Mem"
298
+ def get_info_ext(klass, type, name, function, memoizable = false)
299
+ if memoizable
300
+ s = <<EOF
301
+ def #{name.downcase}
302
+ return @_#{name.downcase} if @_#{name.downcase}
303
+ f = platform.get_extension_function("#{function}", :cl_int, [#{klass}, :cl_uint, :size_t, :pointer, :pointer])
304
+ error_check(OpenCL::INVALID_OPERATION) unless f
305
+
306
+ ptr1 = MemoryPointer::new(:size_t, 1)
307
+ error = f.call(self, #{klass}::#{name.upcase}, 0, nil, ptr1)
308
+ error_check(error)
309
+ ptr2 = MemoryPointer::new(ptr1.read_size_t)
310
+ error = f.call(self, #{klass}::#{name.upcase}, ptr1.read_size_t, ptr2, nil)
311
+ error_check(error)
312
+ if(convert_type(:#{type})) then
313
+ @_#{name.downcase} = convert_type(:#{type})::new(ptr2.read_#{type})
314
+ else
315
+ @_#{name.downcase} = ptr2.read_#{type}
316
+ end
317
+ return @_#{name.downcase}
318
+ end
319
+ EOF
320
+ else
301
321
  s = <<EOF
302
322
  def #{name.downcase}
303
- f = platform.get_extension_function("#{function}", :cl_int, [#{klass_name}, :cl_uint, :size_t, :pointer, :pointer])
323
+ f = platform.get_extension_function("#{function}", :cl_int, [#{klass}, :cl_uint, :size_t, :pointer, :pointer])
304
324
  error_check(OpenCL::INVALID_OPERATION) unless f
305
325
 
306
- ptr1 = MemoryPointer::new( :size_t, 1)
326
+ ptr1 = MemoryPointer::new(:size_t, 1)
307
327
  error = f.call(self, #{klass}::#{name.upcase}, 0, nil, ptr1)
308
328
  error_check(error)
309
- ptr2 = MemoryPointer::new( ptr1.read_size_t )
329
+ ptr2 = MemoryPointer::new(ptr1.read_size_t)
310
330
  error = f.call(self, #{klass}::#{name.upcase}, ptr1.read_size_t, ptr2, nil)
311
331
  error_check(error)
312
332
  if(convert_type(:#{type})) then
@@ -316,6 +336,7 @@ module OpenCL
316
336
  end
317
337
  end
318
338
  EOF
339
+ end
319
340
  if type == :cl_bool then
320
341
  s += <<EOF
321
342
  def #{name.downcase}?
@@ -326,7 +347,7 @@ EOF
326
347
  module_eval s
327
348
  end
328
349
 
329
- # 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.
350
+ # Generates a new method for klass that use the given clGetKlassInfo extension of the object's platform, to read an Array of element of the given type. The info queried is specified by name.
330
351
  # @param [String] klass the property is to be found
331
352
  # @param [Symbol] type of the property
332
353
  # @param [String] name of the property
@@ -334,21 +355,42 @@ EOF
334
355
  # @!method $3
335
356
  # Returns the OpenCL::$1::$3 info
336
357
  # @return an Array of $2
337
- def get_info_array_ext(klass, type, name, function)
338
- klass_name = klass
339
- klass_name = "MemObject" if klass == "Mem"
358
+ def get_info_array_ext(klass, type, name, function, memoizable = false)
359
+ if memoizable
340
360
  s = <<EOF
341
361
  def #{name.downcase}
342
- f = platform.get_extension_function("#{function}", :cl_int, [:cl_uint, :size_t, :pointer, :pointer])
362
+ return @_#{name.downcase} if @_#{name.downcase}
363
+ f = platform.get_extension_function("#{function}", :cl_int, [#{klass}, :cl_uint, :size_t, :pointer, :pointer])
343
364
  error_check(OpenCL::INVALID_OPERATION) unless f
344
365
 
345
- ptr1 = MemoryPointer::new( :size_t, 1)
366
+ ptr1 = MemoryPointer::new(:size_t, 1)
346
367
  error = f.call(self, #{klass}::#{name.upcase}, 0, nil, ptr1)
347
368
  error_check(error)
348
- ptr2 = MemoryPointer::new( ptr1.read_size_t )
369
+ ptr2 = MemoryPointer::new(ptr1.read_size_t)
349
370
  error = f.call(self, #{klass}::#{name.upcase}, ptr1.read_size_t, ptr2, nil)
350
371
  error_check(error)
351
- arr = ptr2.get_array_of_#{type}(0, ptr1.read_size_t/ OpenCL.find_type(:#{type}).size)
372
+ arr = ptr2.get_array_of_#{type}(0, ptr1.read_size_t / OpenCL.find_type(:#{type}).size)
373
+ if(convert_type(:#{type})) then
374
+ @_#{name.downcase} = arr.collect { |e| convert_type(:#{type})::new(e) }
375
+ else
376
+ @_#{name.downcase} = arr
377
+ end
378
+ return @_#{name.downcase}
379
+ end
380
+ EOF
381
+ else
382
+ s = <<EOF
383
+ def #{name.downcase}
384
+ f = platform.get_extension_function("#{function}", :cl_int, [#{klass}, :cl_uint, :size_t, :pointer, :pointer])
385
+ error_check(OpenCL::INVALID_OPERATION) unless f
386
+
387
+ ptr1 = MemoryPointer::new(:size_t, 1)
388
+ error = f.call(self, #{klass}::#{name.upcase}, 0, nil, ptr1)
389
+ error_check(error)
390
+ ptr2 = MemoryPointer::new(ptr1.read_size_t)
391
+ error = f.call(self, #{klass}::#{name.upcase}, ptr1.read_size_t, ptr2, nil)
392
+ error_check(error)
393
+ arr = ptr2.get_array_of_#{type}(0, ptr1.read_size_t / OpenCL.find_type(:#{type}).size)
352
394
  if(convert_type(:#{type})) then
353
395
  return arr.collect { |e| convert_type(:#{type})::new(e) }
354
396
  else
@@ -356,6 +398,7 @@ EOF
356
398
  end
357
399
  end
358
400
  EOF
401
+ end
359
402
  module_eval s
360
403
  end
361
404
 
@@ -374,15 +417,34 @@ EOF
374
417
  # @!method $3
375
418
  # Returns the OpenCL::$1::$3 info
376
419
  # @return $2
377
- def get_info(klass, type, name)
420
+ def get_info(klass, type, name, memoizable = false)
378
421
  klass_name = klass
379
422
  klass_name = "MemObject" if klass == "Mem"
423
+ if memoizable
424
+ s = <<EOF
425
+ def #{name.downcase}
426
+ return @_#{name.downcase} if @_#{name.downcase}
427
+ ptr1 = MemoryPointer::new(:size_t, 1)
428
+ error = OpenCL.clGet#{klass_name}Info(self, #{klass}::#{name.upcase}, 0, nil, ptr1)
429
+ error_check(error)
430
+ ptr2 = MemoryPointer::new(ptr1.read_size_t)
431
+ error = OpenCL.clGet#{klass_name}Info(self, #{klass}::#{name.upcase}, ptr1.read_size_t, ptr2, nil)
432
+ error_check(error)
433
+ if(convert_type(:#{type})) then
434
+ @_#{name.downcase} = convert_type(:#{type})::new(ptr2.read_#{type})
435
+ else
436
+ @_#{name.downcase} = ptr2.read_#{type}
437
+ end
438
+ return @_#{name.downcase}
439
+ end
440
+ EOF
441
+ else
380
442
  s = <<EOF
381
443
  def #{name.downcase}
382
- ptr1 = MemoryPointer::new( :size_t, 1)
444
+ ptr1 = MemoryPointer::new(:size_t, 1)
383
445
  error = OpenCL.clGet#{klass_name}Info(self, #{klass}::#{name.upcase}, 0, nil, ptr1)
384
446
  error_check(error)
385
- ptr2 = MemoryPointer::new( ptr1.read_size_t )
447
+ ptr2 = MemoryPointer::new(ptr1.read_size_t)
386
448
  error = OpenCL.clGet#{klass_name}Info(self, #{klass}::#{name.upcase}, ptr1.read_size_t, ptr2, nil)
387
449
  error_check(error)
388
450
  if(convert_type(:#{type})) then
@@ -392,6 +454,7 @@ EOF
392
454
  end
393
455
  end
394
456
  EOF
457
+ end
395
458
  if type == :cl_bool then
396
459
  s += <<EOF
397
460
  def #{name.downcase}?
@@ -406,22 +469,43 @@ EOF
406
469
  # @param [String] klass the property is to be found
407
470
  # @param [Symbol] type of the property
408
471
  # @param [String] name of the property
472
+ # @param [Bool]
409
473
  # @!macro [attach] get_info_array
410
474
  # @!method $3
411
475
  # Returns the OpenCL::$1::$3 info
412
476
  # @return an Array of $2
413
- def get_info_array(klass, type, name)
477
+ def get_info_array(klass, type, name, memoizable = false)
414
478
  klass_name = klass
415
479
  klass_name = "MemObject" if klass == "Mem"
416
- s = <<EOF
480
+ if memoizable
481
+ s = <<EOF
417
482
  def #{name.downcase}
418
- ptr1 = MemoryPointer::new( :size_t, 1)
483
+ return @_#{name.downcase} if @_#{name.downcase}
484
+ ptr1 = MemoryPointer::new(:size_t, 1)
419
485
  error = OpenCL.clGet#{klass_name}Info(self, #{klass}::#{name.upcase}, 0, nil, ptr1)
420
486
  error_check(error)
421
- ptr2 = MemoryPointer::new( ptr1.read_size_t )
487
+ ptr2 = MemoryPointer::new(ptr1.read_size_t)
422
488
  error = OpenCL.clGet#{klass_name}Info(self, #{klass}::#{name.upcase}, ptr1.read_size_t, ptr2, nil)
423
489
  error_check(error)
424
- arr = ptr2.get_array_of_#{type}(0, ptr1.read_size_t/ OpenCL.find_type(:#{type}).size)
490
+ arr = ptr2.get_array_of_#{type}(0, ptr1.read_size_t / OpenCL.find_type(:#{type}).size)
491
+ if(convert_type(:#{type})) then
492
+ @_#{name.downcase} = arr.collect { |e| convert_type(:#{type})::new(e) }
493
+ else
494
+ @_#{name.downcase} = arr
495
+ end
496
+ return @_#{name.downcase}
497
+ end
498
+ EOF
499
+ else
500
+ s = <<EOF
501
+ def #{name.downcase}
502
+ ptr1 = MemoryPointer::new(:size_t, 1)
503
+ error = OpenCL.clGet#{klass_name}Info(self, #{klass}::#{name.upcase}, 0, nil, ptr1)
504
+ error_check(error)
505
+ ptr2 = MemoryPointer::new(ptr1.read_size_t)
506
+ error = OpenCL.clGet#{klass_name}Info(self, #{klass}::#{name.upcase}, ptr1.read_size_t, ptr2, nil)
507
+ error_check(error)
508
+ arr = ptr2.get_array_of_#{type}(0, ptr1.read_size_t / OpenCL.find_type(:#{type}).size)
425
509
  if(convert_type(:#{type})) then
426
510
  return arr.collect { |e| convert_type(:#{type})::new(e) }
427
511
  else
@@ -429,6 +513,7 @@ EOF
429
513
  end
430
514
  end
431
515
  EOF
516
+ end
432
517
  module_eval s
433
518
  end
434
519
 
@@ -1,13 +1,12 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'opencl_ruby_ffi'
3
- s.version = "1.3.6"
3
+ s.version = "1.3.7"
4
4
  s.author = "Brice Videau"
5
5
  s.email = "bvideau@anl.gov"
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.2 ready"
9
9
  s.files = Dir[ 'opencl_ruby_ffi.gemspec', 'LICENSE', 'lib/**/**/*.rb', '.yardopts', 'templates_custom/default/module/setup.rb' ]
10
- s.has_rdoc = false
11
10
  s.license = 'BSD-2-Clause'
12
11
  s.required_ruby_version = '>= 1.8.7'
13
12
  s.add_dependency 'narray', '~> 0.6', '>=0.6.0.8'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opencl_ruby_ffi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.6
4
+ version: 1.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brice Videau
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-18 00:00:00.000000000 Z
11
+ date: 2020-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: narray
@@ -100,7 +100,10 @@ files:
100
100
  - lib/opencl_ruby_ffi/intel/accelerator.rb
101
101
  - lib/opencl_ruby_ffi/intel/advanced_motion_estimation.rb
102
102
  - lib/opencl_ruby_ffi/intel/driver_diagnostics.rb
103
+ - lib/opencl_ruby_ffi/intel/kernel_profiling.rb
103
104
  - lib/opencl_ruby_ffi/intel/motion_estimation.rb
105
+ - lib/opencl_ruby_ffi/intel/unified_shared_memory_preview.rb
106
+ - lib/opencl_ruby_ffi/intel/unofficial.rb
104
107
  - lib/opencl_ruby_ffi/khr/d3d10_sharing.rb
105
108
  - lib/opencl_ruby_ffi/khr/d3d11_sharing.rb
106
109
  - lib/opencl_ruby_ffi/khr/dx9_media_sharing.rb
@@ -143,8 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
146
  - !ruby/object:Gem::Version
144
147
  version: '0'
145
148
  requirements: []
146
- rubyforge_project:
147
- rubygems_version: 2.7.6.2
149
+ rubygems_version: 3.1.2
148
150
  signing_key:
149
151
  specification_version: 4
150
152
  summary: Ruby OpenCL FFI bindings