opencl_ruby_ffi 1.3.7 → 1.3.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/opencl_ruby_ffi.rb +1 -0
- data/lib/opencl_ruby_ffi/Buffer.rb +7 -1
- data/lib/opencl_ruby_ffi/CommandQueue.rb +10 -4
- data/lib/opencl_ruby_ffi/Context.rb +82 -20
- data/lib/opencl_ruby_ffi/Device.rb +90 -11
- data/lib/opencl_ruby_ffi/Event.rb +17 -17
- data/lib/opencl_ruby_ffi/Image.rb +7 -1
- data/lib/opencl_ruby_ffi/Kernel.rb +68 -58
- data/lib/opencl_ruby_ffi/Mem.rb +13 -7
- data/lib/opencl_ruby_ffi/Pipe.rb +8 -0
- data/lib/opencl_ruby_ffi/Platform.rb +36 -11
- data/lib/opencl_ruby_ffi/Program.rb +21 -17
- data/lib/opencl_ruby_ffi/SVM.rb +1 -1
- data/lib/opencl_ruby_ffi/Sampler.rb +7 -6
- data/lib/opencl_ruby_ffi/ext.rb +1 -0
- data/lib/opencl_ruby_ffi/intel/unified_shared_memory_preview.rb +67 -40
- data/lib/opencl_ruby_ffi/khr/device_uuid.rb +119 -0
- data/lib/opencl_ruby_ffi/opencl_ruby_ffi_base.rb +292 -98
- data/lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb +83 -173
- data/lib/opencl_ruby_ffi/opencl_ruby_ffi_library.rb +181 -0
- data/lib/opencl_ruby_ffi/opencl_types.rb +4 -0
- data/opencl_ruby_ffi.gemspec +2 -2
- metadata +6 -4
@@ -47,13 +47,13 @@ module OpenCL
|
|
47
47
|
end
|
48
48
|
|
49
49
|
# Creates a new ImageFormat from an image channel order and data type
|
50
|
-
def initialize( image_channel_order, image_channel_data_type = nil )
|
51
|
-
if image_channel_order.is_a?(FFI::Pointer)
|
50
|
+
def initialize( image_channel_order = nil, image_channel_data_type = nil )
|
51
|
+
if image_channel_order.is_a?(FFI::Pointer) then
|
52
52
|
super(image_channel_order)
|
53
53
|
else
|
54
54
|
super()
|
55
|
-
self[:image_channel_order] = image_channel_order
|
56
|
-
self[:image_channel_data_type] = image_channel_data_type
|
55
|
+
self[:image_channel_order] = image_channel_order if image_channel_order
|
56
|
+
self[:image_channel_data_type] = image_channel_data_type if image_channel_data_type
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
@@ -79,7 +79,7 @@ module OpenCL
|
|
79
79
|
|
80
80
|
# Returns a String containing a user friendly representation of the ImageFormat
|
81
81
|
def to_s
|
82
|
-
return "{ #{self.channel_order}, #{self.channel_data_type} }"
|
82
|
+
return "{ channel_order: #{self.channel_order}, channel_data_type: #{self.channel_data_type} }"
|
83
83
|
end
|
84
84
|
|
85
85
|
end
|
@@ -95,21 +95,119 @@ module OpenCL
|
|
95
95
|
:image_slice_pitch, :size_t,
|
96
96
|
:num_mip_levels, :cl_uint,
|
97
97
|
:num_samples, :cl_uint,
|
98
|
-
:buffer,
|
98
|
+
:buffer, :pointer
|
99
99
|
|
100
100
|
# Creates anew ImageDesc using the values provided by the user
|
101
|
-
def initialize( image_type, image_width, image_height, image_depth, image_array_size, image_row_pitch, image_slice_pitch, num_mip_levels, num_samples, buffer )
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
101
|
+
def initialize( image_type = nil, image_width = nil, image_height = nil, image_depth = nil, image_array_size = nil, image_row_pitch = nil, image_slice_pitch = nil, num_mip_levels = nil, num_samples = nil, buffer = nil )
|
102
|
+
if (image_type.is_a?(FFI::Pointer))
|
103
|
+
super(image_type)
|
104
|
+
else
|
105
|
+
super()
|
106
|
+
self[:image_type] = image_type if image_type
|
107
|
+
self[:image_width] = image_width if image_width
|
108
|
+
self[:image_height] = image_height if image_height
|
109
|
+
self[:image_depth] = image_depth if image_depth
|
110
|
+
self[:image_array_size] = image_array_size if image_array_size
|
111
|
+
self[:image_row_pitch] = image_row_pitch if image_row_pitch
|
112
|
+
self[:image_slice_pitch] = image_slice_pitch if image_slice_pitch
|
113
|
+
self[:num_mip_levels] = num_mip_levels if num_mip_levels
|
114
|
+
self[:num_samples] = num_samples if num_samples
|
115
|
+
self[:buffer] = buffer if buffer
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def image_type
|
120
|
+
return Mem::Type.new(self[:image_type])
|
121
|
+
end
|
122
|
+
|
123
|
+
def image_type=(type)
|
124
|
+
return self[:image_type] = type
|
125
|
+
end
|
126
|
+
|
127
|
+
def image_width
|
128
|
+
return self[:image_width]
|
129
|
+
end
|
130
|
+
|
131
|
+
def image_width=(width)
|
132
|
+
return self[:image_width] = width
|
133
|
+
end
|
134
|
+
|
135
|
+
def image_height
|
136
|
+
return self[:image_height]
|
137
|
+
end
|
138
|
+
|
139
|
+
def image_height=(height)
|
140
|
+
return self[:image_height] = height
|
141
|
+
end
|
142
|
+
|
143
|
+
def image_depth
|
144
|
+
return self[:image_depth]
|
145
|
+
end
|
146
|
+
|
147
|
+
def image_depth=(depth)
|
148
|
+
return self[:image_depth] = depth
|
149
|
+
end
|
150
|
+
|
151
|
+
def image_array_size
|
152
|
+
return self[:image_array_size]
|
153
|
+
end
|
154
|
+
|
155
|
+
def image_array_size=(array_size)
|
156
|
+
return self[:image_array_size] = array_size
|
157
|
+
end
|
158
|
+
|
159
|
+
def image_row_pitch
|
160
|
+
return self[:image_row_pitch]
|
161
|
+
end
|
162
|
+
|
163
|
+
def image_row_pitch=(row_pitch)
|
164
|
+
return self[:image_row_pitch] = row_pitch
|
165
|
+
end
|
166
|
+
|
167
|
+
def image_slice_pitch
|
168
|
+
return self[:image_slice_pitch]
|
169
|
+
end
|
170
|
+
|
171
|
+
def image_slice_pitch=(slice_pitch)
|
172
|
+
return self[:image_slice_pitch] = slice_pitch
|
173
|
+
end
|
174
|
+
|
175
|
+
def num_mip_levels
|
176
|
+
return self[:num_mip_levels]
|
177
|
+
end
|
178
|
+
|
179
|
+
def num_mip_levels=(num_mip_levels)
|
180
|
+
return self[:num_mip_levels] = num_mip_levels
|
181
|
+
end
|
182
|
+
|
183
|
+
def num_samples
|
184
|
+
return self[:num_samples]
|
185
|
+
end
|
186
|
+
|
187
|
+
def num_samples=(num_samples)
|
188
|
+
return self[:num_samples] = num_samples
|
189
|
+
end
|
190
|
+
|
191
|
+
def buffer
|
192
|
+
return self[:buffer]
|
193
|
+
end
|
194
|
+
|
195
|
+
def buffer=(buffer)
|
196
|
+
return self[:buffer] = buffer
|
197
|
+
end
|
198
|
+
|
199
|
+
# Returns a String containing a user friendly representation of the ImageDesc
|
200
|
+
def to_s
|
201
|
+
return "{ image_type: #{image_type},"\
|
202
|
+
" image_width: #{self[:image_width]},"\
|
203
|
+
" image_height: #{self[:image_height]},"\
|
204
|
+
" image_depth: #{self[:image_depth]},"\
|
205
|
+
" image_array_size: #{self[:image_array_size]},"\
|
206
|
+
" image_row_pitch: #{self[:image_row_pitch]},"\
|
207
|
+
" image_slice_pitch: #{self[:image_slice_pitch]},"\
|
208
|
+
" num_mip_levels: #{self[:num_mip_levels]},"\
|
209
|
+
" num_samples: #{self[:num_samples]},"\
|
210
|
+
" buffer: #{self[:buffer].to_i.to_s(16)} }"
|
113
211
|
end
|
114
212
|
end
|
115
213
|
|
@@ -119,10 +217,108 @@ module OpenCL
|
|
119
217
|
:size, :size_t
|
120
218
|
|
121
219
|
# Creates a new BufferRegion using the value provided by the user
|
122
|
-
def initialize( origin, sz )
|
123
|
-
|
124
|
-
|
125
|
-
|
220
|
+
def initialize( origin = nil, sz = nil )
|
221
|
+
if (origin.is_a?(FFI::Pointer))
|
222
|
+
super(origin)
|
223
|
+
else
|
224
|
+
super()
|
225
|
+
self[:origin] = origin if origin
|
226
|
+
self[:size] = sz if sz
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
def origin
|
231
|
+
return self[:origin]
|
232
|
+
end
|
233
|
+
|
234
|
+
def origin=(origin)
|
235
|
+
return self[:origin] = origin
|
236
|
+
end
|
237
|
+
|
238
|
+
def sz
|
239
|
+
return self[:size]
|
240
|
+
end
|
241
|
+
|
242
|
+
def sz=(sz)
|
243
|
+
return self[:size] = sz
|
244
|
+
end
|
245
|
+
|
246
|
+
def to_s
|
247
|
+
return "{ origin: #{self[:origin]}, size: #{self[:size]} }"
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
class Version
|
252
|
+
include Comparable
|
253
|
+
MAJOR_BITS = 10
|
254
|
+
MINOR_BITS = 10
|
255
|
+
PATCH_BITS = 12
|
256
|
+
MAJOR_MASK = (1 << MAJOR_BITS) - 1
|
257
|
+
MINOR_MASK = (1 << MINOR_BITS) - 1
|
258
|
+
PATCH_MASK = (1 << PATCH_BITS) - 1
|
259
|
+
|
260
|
+
attr_reader :major, :minor, :patch
|
261
|
+
def initialize(major, minor = 0, patch = 0)
|
262
|
+
@major = major
|
263
|
+
@minor = minor
|
264
|
+
@patch = patch
|
265
|
+
end
|
266
|
+
|
267
|
+
def to_int
|
268
|
+
Version.make(@major, @minor, @patch)
|
269
|
+
end
|
270
|
+
alias to_i to_int
|
271
|
+
|
272
|
+
def <=>(other)
|
273
|
+
res = (@major <=> other.major)
|
274
|
+
res = (@minor <=> other.minor) if res == 0
|
275
|
+
res = (@patch <=> other.patch) if res == 0
|
276
|
+
res
|
277
|
+
end
|
278
|
+
|
279
|
+
def to_s
|
280
|
+
"#{@major}.#{@minor}.#{@patch}"
|
281
|
+
end
|
282
|
+
|
283
|
+
def self.major(v)
|
284
|
+
v >> (MINOR_BITS + PATCH_BITS)
|
285
|
+
end
|
286
|
+
|
287
|
+
def self.minor(v)
|
288
|
+
(v >> (PATCH_BITS)) & MINOR_MASK
|
289
|
+
end
|
290
|
+
|
291
|
+
def self.patch(v)
|
292
|
+
v & PATCH_MASK
|
293
|
+
end
|
294
|
+
|
295
|
+
def self.make(major, minor = 0, patch = 0)
|
296
|
+
((major & MAJOR_MASK) << (MINOR_BITS + PATCH_BITS)) +
|
297
|
+
((minor & MINOR_MASK) << PATCH_BITS) +
|
298
|
+
(patch & PATCH_MASK)
|
299
|
+
end
|
300
|
+
|
301
|
+
def self.from_int(v)
|
302
|
+
self.new(major(v), minor(v), patch(v))
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
# Maps the :cl_name_version type of OpenCL
|
307
|
+
class NameVersion < Struct
|
308
|
+
MAX_NAME_SIZE = 64
|
309
|
+
layout :version, :cl_version,
|
310
|
+
:name, [:char, MAX_NAME_SIZE]
|
311
|
+
|
312
|
+
def version
|
313
|
+
Version.from_int(self[:version])
|
314
|
+
end
|
315
|
+
|
316
|
+
def name
|
317
|
+
self[:name].to_s
|
318
|
+
end
|
319
|
+
|
320
|
+
def to_s
|
321
|
+
"{ name: #{name}, version: #{version} }"
|
126
322
|
end
|
127
323
|
end
|
128
324
|
|
@@ -169,7 +365,7 @@ module OpenCL
|
|
169
365
|
end
|
170
366
|
return properties
|
171
367
|
end
|
172
|
-
|
368
|
+
|
173
369
|
# 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
|
174
370
|
def get_origin_region( image, options, origin_symbol, region_symbol )
|
175
371
|
origin = MemoryPointer::new( :size_t, 3 )
|
@@ -214,6 +410,19 @@ module OpenCL
|
|
214
410
|
return properties
|
215
411
|
end
|
216
412
|
|
413
|
+
# EXtracts the :properties named option (for a Mem) from the hash given and returns the properties values
|
414
|
+
def get_mem_properties( options )
|
415
|
+
properties = nil
|
416
|
+
if options[:properties] then
|
417
|
+
properties = MemoryPointer::new( :cl_mem_properties, options[:properties].length + 1 )
|
418
|
+
options[:properties].each_with_index { |e,i|
|
419
|
+
properties[i].write_cl_mem_properties(e.respond_to?(:to_ptr) ? e : e.to_i)
|
420
|
+
}
|
421
|
+
properties[options[:properties].length].write_cl_mem_properties(0)
|
422
|
+
end
|
423
|
+
return properties
|
424
|
+
end
|
425
|
+
|
217
426
|
# Extracts the :device_list named option from the hash given and returns [ number of devices, an Pointer to the list of Device or nil ]
|
218
427
|
def get_device_list( options )
|
219
428
|
devices = options[:device_list]
|
@@ -248,6 +457,7 @@ module OpenCL
|
|
248
457
|
:cl_command_queue_properties => CommandQueue::Properties,
|
249
458
|
:cl_device_affinity_domain => Device::AffinityDomain,
|
250
459
|
:cl_device_svm_capabilities => Device::SVMCapabilities,
|
460
|
+
:cl_device_atomic_capabilities => Device::AtomicCapabilities,
|
251
461
|
:cl_channel_order => ChannelOrder,
|
252
462
|
:cl_channel_type => ChannelType,
|
253
463
|
:cl_mem_flags => Mem::Flags,
|
@@ -287,11 +497,8 @@ module OpenCL
|
|
287
497
|
module ExtensionInnerGenerator
|
288
498
|
|
289
499
|
private
|
290
|
-
|
291
|
-
#
|
292
|
-
# @param [Symbol] type of the property
|
293
|
-
# @param [String] name of the property
|
294
|
-
# @!macro [attach] get_info
|
500
|
+
|
501
|
+
# @!macro [attach] get_info_ext
|
295
502
|
# @!method $3
|
296
503
|
# Returns the OpenCL::$1::$3 info
|
297
504
|
# @return $2
|
@@ -299,22 +506,22 @@ module OpenCL
|
|
299
506
|
if memoizable
|
300
507
|
s = <<EOF
|
301
508
|
def #{name.downcase}
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
509
|
+
@_#{name.downcase} ||= begin
|
510
|
+
f = platform.get_extension_function("#{function}", :cl_int, [#{klass}, :cl_uint, :size_t, :pointer, :pointer])
|
511
|
+
error_check(OpenCL::INVALID_OPERATION) unless f
|
512
|
+
|
513
|
+
ptr1 = MemoryPointer::new(:size_t, 1)
|
514
|
+
error = f.call(self, #{klass}::#{name.upcase}, 0, nil, ptr1)
|
515
|
+
error_check(error)
|
516
|
+
ptr2 = MemoryPointer::new(ptr1.read_size_t)
|
517
|
+
error = f.call(self, #{klass}::#{name.upcase}, ptr1.read_size_t, ptr2, nil)
|
518
|
+
error_check(error)
|
519
|
+
if(convert_type(:#{type})) then
|
520
|
+
convert_type(:#{type})::new(ptr2.read_#{type})
|
521
|
+
else
|
522
|
+
ptr2.read_#{type}
|
523
|
+
end
|
316
524
|
end
|
317
|
-
return @_#{name.downcase}
|
318
525
|
end
|
319
526
|
EOF
|
320
527
|
else
|
@@ -347,11 +554,7 @@ EOF
|
|
347
554
|
module_eval s
|
348
555
|
end
|
349
556
|
|
350
|
-
#
|
351
|
-
# @param [String] klass the property is to be found
|
352
|
-
# @param [Symbol] type of the property
|
353
|
-
# @param [String] name of the property
|
354
|
-
# @!macro [attach] get_info_array
|
557
|
+
# @!macro [attach] get_info_array_ext
|
355
558
|
# @!method $3
|
356
559
|
# Returns the OpenCL::$1::$3 info
|
357
560
|
# @return an Array of $2
|
@@ -359,23 +562,23 @@ EOF
|
|
359
562
|
if memoizable
|
360
563
|
s = <<EOF
|
361
564
|
def #{name.downcase}
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
565
|
+
@_#{name.downcase} ||= begin
|
566
|
+
f = platform.get_extension_function("#{function}", :cl_int, [#{klass}, :cl_uint, :size_t, :pointer, :pointer])
|
567
|
+
error_check(OpenCL::INVALID_OPERATION) unless f
|
568
|
+
|
569
|
+
ptr1 = MemoryPointer::new(:size_t, 1)
|
570
|
+
error = f.call(self, #{klass}::#{name.upcase}, 0, nil, ptr1)
|
571
|
+
error_check(error)
|
572
|
+
ptr2 = MemoryPointer::new(ptr1.read_size_t)
|
573
|
+
error = f.call(self, #{klass}::#{name.upcase}, ptr1.read_size_t, ptr2, nil)
|
574
|
+
error_check(error)
|
575
|
+
arr = ptr2.get_array_of_#{type}(0, ptr1.read_size_t / OpenCL.find_type(:#{type}).size)
|
576
|
+
if(convert_type(:#{type})) then
|
577
|
+
arr.collect { |e| convert_type(:#{type})::new(e) }
|
578
|
+
else
|
579
|
+
arr
|
580
|
+
end
|
377
581
|
end
|
378
|
-
return @_#{name.downcase}
|
379
582
|
end
|
380
583
|
EOF
|
381
584
|
else
|
@@ -409,10 +612,6 @@ EOF
|
|
409
612
|
|
410
613
|
private
|
411
614
|
|
412
|
-
# 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.
|
413
|
-
# @param [String] klass the property is to be found
|
414
|
-
# @param [Symbol] type of the property
|
415
|
-
# @param [String] name of the property
|
416
615
|
# @!macro [attach] get_info
|
417
616
|
# @!method $3
|
418
617
|
# Returns the OpenCL::$1::$3 info
|
@@ -423,19 +622,19 @@ EOF
|
|
423
622
|
if memoizable
|
424
623
|
s = <<EOF
|
425
624
|
def #{name.downcase}
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
625
|
+
@_#{name.downcase} ||= begin
|
626
|
+
ptr1 = MemoryPointer::new(:size_t, 1)
|
627
|
+
error = OpenCL.clGet#{klass_name}Info(self, #{klass}::#{name.upcase}, 0, nil, ptr1)
|
628
|
+
error_check(error)
|
629
|
+
ptr2 = MemoryPointer::new(ptr1.read_size_t)
|
630
|
+
error = OpenCL.clGet#{klass_name}Info(self, #{klass}::#{name.upcase}, ptr1.read_size_t, ptr2, nil)
|
631
|
+
error_check(error)
|
632
|
+
if(convert_type(:#{type})) then
|
633
|
+
convert_type(:#{type})::new(ptr2.read_#{type})
|
634
|
+
else
|
635
|
+
ptr2.read_#{type}
|
636
|
+
end
|
437
637
|
end
|
438
|
-
return @_#{name.downcase}
|
439
638
|
end
|
440
639
|
EOF
|
441
640
|
else
|
@@ -465,11 +664,6 @@ EOF
|
|
465
664
|
module_eval s
|
466
665
|
end
|
467
666
|
|
468
|
-
# 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.
|
469
|
-
# @param [String] klass the property is to be found
|
470
|
-
# @param [Symbol] type of the property
|
471
|
-
# @param [String] name of the property
|
472
|
-
# @param [Bool]
|
473
667
|
# @!macro [attach] get_info_array
|
474
668
|
# @!method $3
|
475
669
|
# Returns the OpenCL::$1::$3 info
|
@@ -480,20 +674,20 @@ EOF
|
|
480
674
|
if memoizable
|
481
675
|
s = <<EOF
|
482
676
|
def #{name.downcase}
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
677
|
+
@_#{name.downcase} ||= begin
|
678
|
+
ptr1 = MemoryPointer::new(:size_t, 1)
|
679
|
+
error = OpenCL.clGet#{klass_name}Info(self, #{klass}::#{name.upcase}, 0, nil, ptr1)
|
680
|
+
error_check(error)
|
681
|
+
ptr2 = MemoryPointer::new(ptr1.read_size_t)
|
682
|
+
error = OpenCL.clGet#{klass_name}Info(self, #{klass}::#{name.upcase}, ptr1.read_size_t, ptr2, nil)
|
683
|
+
error_check(error)
|
684
|
+
arr = ptr2.get_array_of_#{type}(0, ptr1.read_size_t / OpenCL.find_type(:#{type}).size)
|
685
|
+
if(convert_type(:#{type})) then
|
686
|
+
arr.collect { |e| convert_type(:#{type})::new(e) }
|
687
|
+
else
|
688
|
+
arr
|
689
|
+
end
|
495
690
|
end
|
496
|
-
return @_#{name.downcase}
|
497
691
|
end
|
498
692
|
EOF
|
499
693
|
else
|