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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fdde36869013e898818c10e84618fc8af7efbfb37f65f0dc420a5cbcfe98e724
|
4
|
+
data.tar.gz: a1934b0c7beb47644793083adaa04765dcc8eb7cddf54fc51ee1f203ebf545c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0c9376a0dc33def8c99a553526f77755223ca2592b845713fad3567bd30b8e3c4af8a1630db4f30739ada00119f53b75ab16a5a13c323205c87410565e6d568
|
7
|
+
data.tar.gz: ade66f8ccb6bdfbfdd8a3e0a88878e129507317fd710bf52ec0425c96441d5982765e7e222c6c6c154a68ee7812e6cb144fa72aefcc35ada654899c69e2c40ef
|
data/lib/opencl_ruby_ffi.rb
CHANGED
@@ -2,6 +2,7 @@ require "opencl_ruby_ffi/opencl_types.rb"
|
|
2
2
|
require "opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb"
|
3
3
|
require "opencl_ruby_ffi/opencl_arithmetic_gen.rb"
|
4
4
|
require "opencl_ruby_ffi/opencl_ruby_ffi_base.rb"
|
5
|
+
require "opencl_ruby_ffi/opencl_ruby_ffi_library.rb"
|
5
6
|
require "opencl_ruby_ffi/Context.rb"
|
6
7
|
require "opencl_ruby_ffi/Platform.rb"
|
7
8
|
require "opencl_ruby_ffi/Device.rb"
|
@@ -13,11 +13,17 @@ module OpenCL
|
|
13
13
|
#
|
14
14
|
# * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Buffer
|
15
15
|
# * +:host_ptr+ - if provided, the Pointer (or convertible to Pointer using to_ptr) to the memory area to use
|
16
|
+
# * +:properties+ - if provided, an array of :cl_mem_properties (OpenCL 3.0)
|
16
17
|
def self.create_buffer( context, size, options = {} )
|
17
18
|
flags = get_flags( options )
|
18
19
|
host_ptr = options[:host_ptr]
|
19
20
|
error = MemoryPointer::new( :cl_int )
|
20
|
-
|
21
|
+
if context.platform.version_number < 3.0 then
|
22
|
+
buff = clCreateBuffer(context, flags, size, host_ptr, error)
|
23
|
+
else
|
24
|
+
properties = get_mem_properties( options )
|
25
|
+
buff = clCreateBufferWithProperties(context, properties, flags, size, host_ptr, error)
|
26
|
+
end
|
21
27
|
error_check(error.read_cl_int)
|
22
28
|
return Buffer::new( buff, false )
|
23
29
|
end
|
@@ -566,7 +566,7 @@ module OpenCL
|
|
566
566
|
objs = nil
|
567
567
|
if num_objs > 0 then
|
568
568
|
objs = MemoryPointer::new( Mem, num_objs )
|
569
|
-
[mem_objects].flatten.each_with_index { |
|
569
|
+
[mem_objects].flatten.each_with_index { |e, i|
|
570
570
|
objs[i].write_pointer(e)
|
571
571
|
}
|
572
572
|
end
|
@@ -600,7 +600,7 @@ module OpenCL
|
|
600
600
|
objs = nil
|
601
601
|
if num_objs > 0 then
|
602
602
|
objs = MemoryPointer::new( Mem, num_objs )
|
603
|
-
[mem_objects].flatten.each_with_index { |
|
603
|
+
[mem_objects].flatten.each_with_index { |e, i|
|
604
604
|
objs[i].write_pointer(e)
|
605
605
|
}
|
606
606
|
end
|
@@ -1072,8 +1072,7 @@ module OpenCL
|
|
1072
1072
|
|
1073
1073
|
# Returns the Platform associated with the CommandQueue
|
1074
1074
|
def platform
|
1075
|
-
|
1076
|
-
@_platform = self.context.platform
|
1075
|
+
@_platform ||= self.context.platform
|
1077
1076
|
end
|
1078
1077
|
|
1079
1078
|
# Returns the Context associated to the CommandQueue
|
@@ -1790,10 +1789,17 @@ module OpenCL
|
|
1790
1789
|
|
1791
1790
|
end
|
1792
1791
|
|
1792
|
+
module OpenCL30
|
1793
|
+
extend InnerGenerator
|
1794
|
+
|
1795
|
+
get_info_array("CommandQueue", :cl_queue_properties, "properties_array")
|
1796
|
+
end
|
1797
|
+
|
1793
1798
|
register_extension( :v11, OpenCL11, "device.platform.version_number >= 1.1" )
|
1794
1799
|
register_extension( :v12, OpenCL12, "device.platform.version_number >= 1.2" )
|
1795
1800
|
register_extension( :v20, OpenCL20, "device.platform.version_number >= 2.0" )
|
1796
1801
|
register_extension( :v21, OpenCL21, "device.platform.version_number >= 2.1" )
|
1802
|
+
register_extension( :v30, OpenCL30, "device.platform.version_number >= 3.0" )
|
1797
1803
|
|
1798
1804
|
end
|
1799
1805
|
|
@@ -25,7 +25,16 @@ module OpenCL
|
|
25
25
|
error = MemoryPointer::new( :cl_int )
|
26
26
|
ptr = clCreateContext(properties, devs.size, pointer, block, user_data, error)
|
27
27
|
error_check(error.read_cl_int)
|
28
|
-
|
28
|
+
context = Context::new(ptr, false)
|
29
|
+
if block && context.platform.version_number >= 3.0
|
30
|
+
callback_destructor_callback = lambda { |c, u|
|
31
|
+
@@callbacks.delete(block)
|
32
|
+
@@callbacks.delete(callback_destructor_callback)
|
33
|
+
}
|
34
|
+
@@callbacks[callback_destructor_callback] = nil
|
35
|
+
context.set_destructor_callback(&callback_destructor_callback)
|
36
|
+
end
|
37
|
+
return context
|
29
38
|
end
|
30
39
|
|
31
40
|
# Creates an Context using devices of the selected type
|
@@ -49,7 +58,16 @@ module OpenCL
|
|
49
58
|
error = MemoryPointer::new( :cl_int )
|
50
59
|
ptr = clCreateContextFromType(properties, type, block, user_data, error)
|
51
60
|
error_check(error.read_cl_int)
|
52
|
-
|
61
|
+
context = Context::new(ptr, false)
|
62
|
+
if block && context.platform.version_number >= 3.0
|
63
|
+
callback_destructor_callback = lambda { |c, u|
|
64
|
+
@@callbacks.delete(block)
|
65
|
+
@@callbacks.delete(callback_destructor_callback)
|
66
|
+
}
|
67
|
+
@@callbacks[callback_destructor_callback] = nil
|
68
|
+
context.set_destructor_callback(&callback_destructor_callback)
|
69
|
+
end
|
70
|
+
return context
|
53
71
|
end
|
54
72
|
|
55
73
|
def self.set_default_device_command_queue( context, device, command_queue )
|
@@ -59,6 +77,32 @@ module OpenCL
|
|
59
77
|
return context
|
60
78
|
end
|
61
79
|
|
80
|
+
# Attaches a callback to context that will be called on context destruction
|
81
|
+
#
|
82
|
+
# ==== Attributes
|
83
|
+
#
|
84
|
+
# * +context+ - the Program to attach the callback to
|
85
|
+
# * +options+ - a hash containing named options
|
86
|
+
# * +block+ - if provided, a callback invoked when program is released. Signature of the callback is { |Pointer to the context, Pointer to user_data| ... }
|
87
|
+
#
|
88
|
+
# ==== Options
|
89
|
+
#
|
90
|
+
# * +:user_data+ - a Pointer (or convertible to Pointer using to_ptr) to the memory area to pass to the callback
|
91
|
+
def self.set_context_destructor_callback( context, options = {}, &block )
|
92
|
+
if block
|
93
|
+
wrapper_block = lambda { |p, u|
|
94
|
+
block.call(p, u)
|
95
|
+
@@callbacks.delete(wrapper_block)
|
96
|
+
}
|
97
|
+
@@callbacks[wrapper_block] = options[:user_data]
|
98
|
+
else
|
99
|
+
wrapper_block = nil
|
100
|
+
end
|
101
|
+
error = clSetContextDestructorCallback( context, wrapper_block, options[:user_data] )
|
102
|
+
error_check(error)
|
103
|
+
return context
|
104
|
+
end
|
105
|
+
|
62
106
|
#Maps the cl_context object of OpenCL
|
63
107
|
class Context
|
64
108
|
include InnerInterface
|
@@ -72,26 +116,25 @@ module OpenCL
|
|
72
116
|
|
73
117
|
# Returns the number of devices associated to the Context
|
74
118
|
def num_devices
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
@_num_devices = d_n
|
119
|
+
@_num_devices ||= begin
|
120
|
+
ptr = MemoryPointer::new( :size_t )
|
121
|
+
error = OpenCL.clGetContextInfo(self, DEVICES, 0, nil, ptr)
|
122
|
+
error_check(error)
|
123
|
+
ptr.read_size_t / Platform.size
|
124
|
+
end
|
82
125
|
end
|
83
126
|
|
84
127
|
# Returns an Array of Device associated to the Context
|
85
128
|
def devices
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
129
|
+
@_devices ||= begin
|
130
|
+
n = self.num_devices
|
131
|
+
ptr2 = MemoryPointer::new( Device, n )
|
132
|
+
error = OpenCL.clGetContextInfo(self, DEVICES, Device.size*n, ptr2, nil)
|
133
|
+
error_check(error)
|
134
|
+
ptr2.get_array_of_pointer(0, n).collect { |device_ptr|
|
135
|
+
Device::new(device_ptr)
|
136
|
+
}
|
137
|
+
end
|
95
138
|
end
|
96
139
|
|
97
140
|
##
|
@@ -125,8 +168,7 @@ module OpenCL
|
|
125
168
|
|
126
169
|
# Returns the platform associated to the Context
|
127
170
|
def platform
|
128
|
-
|
129
|
-
@_platform = self.devices.first.platform
|
171
|
+
@_platform ||= self.devices.first.platform
|
130
172
|
end
|
131
173
|
|
132
174
|
# Returns an Array of ImageFormat that are supported for a given image type in the Context
|
@@ -459,16 +501,36 @@ module OpenCL
|
|
459
501
|
return OpenCL.create_program_with_il(self, il)
|
460
502
|
end
|
461
503
|
|
504
|
+
#
|
462
505
|
def set_default_device_command_queue( device, command_queue )
|
463
506
|
return OpenCL.set_default_device_command_queue( self, device, command_queue )
|
464
507
|
end
|
465
508
|
|
466
509
|
end
|
467
510
|
|
511
|
+
module OpenCL30
|
512
|
+
|
513
|
+
# Attaches a callback to context that will be called on context destruction
|
514
|
+
#
|
515
|
+
# ==== Attributes
|
516
|
+
#
|
517
|
+
# * +options+ - a hash containing named options
|
518
|
+
# * +block+ - if provided, a callback invoked when program is released. Signature of the callback is { |Pointer to the context, Pointer to user_data| ... }
|
519
|
+
#
|
520
|
+
# ==== Options
|
521
|
+
#
|
522
|
+
# * +:user_data+ - a Pointer (or convertible to Pointer using to_ptr) to the memory area to pass to the callback
|
523
|
+
def set_destructor_callback( options = {}, &block )
|
524
|
+
OpenCL.set_context_destructor_callback( self, option, &block )
|
525
|
+
return self
|
526
|
+
end
|
527
|
+
end
|
528
|
+
|
468
529
|
register_extension( :v11, OpenCL11, "platform.version_number >= 1.1" )
|
469
530
|
register_extension( :v12, OpenCL12, "platform.version_number >= 1.2" )
|
470
531
|
register_extension( :v20, OpenCL20, "platform.version_number >= 2.0" )
|
471
532
|
register_extension( :v21, OpenCL21, "platform.version_number >= 2.1" )
|
533
|
+
register_extension( :v30, OpenCL30, "platform.version_number >= 3.0" )
|
472
534
|
|
473
535
|
end
|
474
536
|
|
@@ -107,11 +107,12 @@ module OpenCL
|
|
107
107
|
|
108
108
|
# Returns the Platform the Device belongs to
|
109
109
|
def platform
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
110
|
+
@_platform ||= begin
|
111
|
+
ptr = MemoryPointer::new( OpenCL::Platform )
|
112
|
+
error = OpenCL.clGetDeviceInfo(self, PLATFORM, OpenCL::Platform.size, ptr, nil)
|
113
|
+
error_check(error)
|
114
|
+
OpenCL::Platform::new(ptr.read_pointer)
|
115
|
+
end
|
115
116
|
end
|
116
117
|
|
117
118
|
get_info("Device", :cl_uint, "preferred_vector_width_char")
|
@@ -158,8 +159,6 @@ module OpenCL
|
|
158
159
|
n = ver.scan(/OpenCL C (\d+\.\d+)/)
|
159
160
|
return n.first.first.to_f
|
160
161
|
end
|
161
|
-
|
162
|
-
get_info("Device", :cl_uint, "preferred_vector_width_half")
|
163
162
|
|
164
163
|
end
|
165
164
|
|
@@ -366,10 +365,90 @@ module OpenCL
|
|
366
365
|
|
367
366
|
end
|
368
367
|
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
368
|
+
module OpenCL30
|
369
|
+
extend InnerGenerator
|
370
|
+
get_info("Device", :cl_device_atomic_capabilities, "atomic_memory_capabilities")
|
371
|
+
get_info("Device", :cl_device_atomic_capabilities, "atomic_fence_capabilities")
|
372
|
+
get_info("Device", :cl_bool, "non_uniform_work_group_support")
|
373
|
+
get_info("Device", :size_t, "preferred_work_group_size_multiple")
|
374
|
+
get_info("Device", :cl_bool, "work_group_collective_functions_support")
|
375
|
+
get_info("Device", :cl_bool, "generic_address_space_support")
|
376
|
+
get_info("Device", :cl_bool, "device_enqueue_support")
|
377
|
+
get_info("Device", :cl_bool, "pipe_support")
|
378
|
+
|
379
|
+
def numeric_version
|
380
|
+
ptr = MemoryPointer::new( :cl_version )
|
381
|
+
error = OpenCL.clGetDeviceInfo( self, NUMERIC_VERSION, 4, ptr, nil)
|
382
|
+
error_check(error)
|
383
|
+
return Version::from_int(ptr.read_cl_version)
|
384
|
+
end
|
385
|
+
|
386
|
+
def extensions_with_version
|
387
|
+
sz = MemoryPointer::new( :size_t )
|
388
|
+
error = OpenCL.clGetDeviceInfo( self, EXTENSIONS_WITH_VERSION, 0, nil, sz)
|
389
|
+
error_check(error)
|
390
|
+
sz = sz.read_size_t
|
391
|
+
ptr = MemoryPointer::new( sz )
|
392
|
+
error = OpenCL.clGetDeviceInfo( self, EXTENSIONS_WITH_VERSION, sz, ptr, nil)
|
393
|
+
error_check(error)
|
394
|
+
nvsz = NameVersion.size
|
395
|
+
return (sz/nvsz).times.collect { |i| NameVersion::new(ptr + i*nvsz) }
|
396
|
+
end
|
397
|
+
|
398
|
+
def ils_with_version
|
399
|
+
sz = MemoryPointer::new( :size_t )
|
400
|
+
error = OpenCL.clGetDeviceInfo( self, ILS_WITH_VERSION, 0, nil, sz)
|
401
|
+
error_check(error)
|
402
|
+
sz = sz.read_size_t
|
403
|
+
ptr = MemoryPointer::new( sz )
|
404
|
+
error = OpenCL.clGetDeviceInfo( self, ILS_WITH_VERSION, sz, ptr, nil)
|
405
|
+
error_check(error)
|
406
|
+
nvsz = NameVersion.size
|
407
|
+
return (sz/nvsz).times.collect { |i| NameVersion::new(ptr + i*nvsz) }
|
408
|
+
end
|
409
|
+
|
410
|
+
def built_in_kernels_with_version
|
411
|
+
sz = MemoryPointer::new( :size_t )
|
412
|
+
error = OpenCL.clGetDeviceInfo( self, BUILT_IN_KERNELS_WITH_VERSION, 0, nil, sz)
|
413
|
+
error_check(error)
|
414
|
+
sz = sz.read_size_t
|
415
|
+
ptr = MemoryPointer::new( sz )
|
416
|
+
error = OpenCL.clGetDeviceInfo( self, BUILT_IN_KERNELS_WITH_VERSION, sz, ptr, nil)
|
417
|
+
error_check(error)
|
418
|
+
nvsz = NameVersion.size
|
419
|
+
return (sz/nvsz).times.collect { |i| NameVersion::new(ptr + i*nvsz) }
|
420
|
+
end
|
421
|
+
|
422
|
+
def opencl_c_all_versions
|
423
|
+
sz = MemoryPointer::new( :size_t )
|
424
|
+
error = OpenCL.clGetDeviceInfo( self, OPENCL_C_ALL_VERSIONS, 0, nil, sz)
|
425
|
+
error_check(error)
|
426
|
+
sz = sz.read_size_t
|
427
|
+
ptr = MemoryPointer::new( sz )
|
428
|
+
error = OpenCL.clGetDeviceInfo( self, OPENCL_C_ALL_VERSIONS, sz, ptr, nil)
|
429
|
+
error_check(error)
|
430
|
+
nvsz = NameVersion.size
|
431
|
+
return (sz/nvsz).times.collect { |i| NameVersion::new(ptr + i*nvsz) }
|
432
|
+
end
|
433
|
+
|
434
|
+
def opencl_c_features
|
435
|
+
sz = MemoryPointer::new( :size_t )
|
436
|
+
error = OpenCL.clGetDeviceInfo( self, OPENCL_C_FEATURES, 0, nil, sz)
|
437
|
+
error_check(error)
|
438
|
+
sz = sz.read_size_t
|
439
|
+
ptr = MemoryPointer::new( sz )
|
440
|
+
error = OpenCL.clGetDeviceInfo( self, OPENCL_C_FEATURES, sz, ptr, nil)
|
441
|
+
error_check(error)
|
442
|
+
nvsz = NameVersion.size
|
443
|
+
return (sz/nvsz).times.collect { |i| NameVersion::new(ptr + i*nvsz) }
|
444
|
+
end
|
445
|
+
end
|
446
|
+
|
447
|
+
register_extension( :v11, OpenCL11, "platform.version_number >= 1.1" )
|
448
|
+
register_extension( :v12, OpenCL12, "platform.version_number >= 1.2" )
|
449
|
+
register_extension( :v20, OpenCL20, "platform.version_number >= 2.0" )
|
450
|
+
register_extension( :v21, OpenCL21, "platform.version_number >= 2.1" )
|
451
|
+
register_extension( :v30, OpenCL30, "platform.version_number >= 3.0" )
|
373
452
|
|
374
453
|
end
|
375
454
|
|
@@ -77,17 +77,17 @@ module OpenCL
|
|
77
77
|
|
78
78
|
# Returns the CommandQueue associated with the Event, if it exists
|
79
79
|
def command_queue
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
80
|
+
@_command_queue ||= begin
|
81
|
+
ptr = MemoryPointer::new( CommandQueue )
|
82
|
+
error = OpenCL.clGetEventInfo(self, COMMAND_QUEUE, CommandQueue.size, ptr, nil)
|
83
|
+
error_check(error)
|
84
|
+
pt = ptr.read_pointer
|
85
|
+
if pt.null? then
|
86
|
+
nil
|
87
|
+
else
|
88
|
+
CommandQueue::new( pt )
|
89
|
+
end
|
89
90
|
end
|
90
|
-
@_command_queue
|
91
91
|
end
|
92
92
|
|
93
93
|
get_info("Event", :cl_command_type, "command_type", true)
|
@@ -98,8 +98,7 @@ module OpenCL
|
|
98
98
|
|
99
99
|
# Returns the Platform associated with the Event
|
100
100
|
def platform
|
101
|
-
|
102
|
-
@_platform = self.context.platform
|
101
|
+
@_platform ||= self.context.platform
|
103
102
|
end
|
104
103
|
|
105
104
|
# Returns a CommandExecutionStatus corresponding to the status of the command associtated with the Event
|
@@ -148,11 +147,12 @@ module OpenCL
|
|
148
147
|
|
149
148
|
# Returns the Context associated with the Event
|
150
149
|
def context
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
150
|
+
@_context ||= begin
|
151
|
+
ptr = MemoryPointer::new( Context )
|
152
|
+
error = OpenCL.clGetEventInfo(self, CONTEXT, Context.size, ptr, nil)
|
153
|
+
error_check(error)
|
154
|
+
Context::new( ptr.read_pointer )
|
155
|
+
end
|
156
156
|
end
|
157
157
|
|
158
158
|
# Sets the satus of Event (a user event) to the given execution status
|
@@ -13,11 +13,17 @@ module OpenCL
|
|
13
13
|
#
|
14
14
|
# * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Image
|
15
15
|
# * +:host_ptr+ - if provided, the Pointer (or convertible to Pointer using to_ptr) to the memory area to use
|
16
|
+
# * +:properties+ - if provided, an array of :cl_mem_properties (OpenCL 3.0)
|
16
17
|
def self.create_image( context, format, desc, options = {} )
|
17
18
|
flags = get_flags( options )
|
18
19
|
host_ptr = options[:host_ptr]
|
19
20
|
error = MemoryPointer::new( :cl_int )
|
20
|
-
|
21
|
+
if context.platform.version_number < 3.0 then
|
22
|
+
img_ptr = clCreateImage( context, flags, format, desc, host_ptr, error )
|
23
|
+
else
|
24
|
+
properties = get_mem_properties( options )
|
25
|
+
img_ptr = clCreateImageWithProperties( context, properties, flags, format, desc, host_ptr, error )
|
26
|
+
end
|
21
27
|
error_check(error.read_cl_int)
|
22
28
|
return Image::new(img_ptr, false)
|
23
29
|
end
|
@@ -29,9 +29,12 @@ module OpenCL
|
|
29
29
|
sz = size
|
30
30
|
sz = value.class.size if sz == nil
|
31
31
|
val = value
|
32
|
-
if value.kind_of?(Mem)
|
32
|
+
if value.kind_of?(Mem)
|
33
33
|
val = MemoryPointer::new( Mem )
|
34
34
|
val.write_pointer(value.to_ptr)
|
35
|
+
elsif value.kind_of?(Sampler)
|
36
|
+
val = MemoryPointer::new( Sampler )
|
37
|
+
val.write_pointer(value.to_ptr)
|
35
38
|
end
|
36
39
|
error = clSetKernelArg( kernel, index, sz, val )
|
37
40
|
error_check(error)
|
@@ -113,58 +116,63 @@ module OpenCL
|
|
113
116
|
|
114
117
|
# Returns an AddressQualifier corresponding to the Arg
|
115
118
|
def address_qualifier
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
119
|
+
@_address_qualifier ||= begin
|
120
|
+
error_check(INVALID_OPERATION) if @kernel.context.platform.version_number < 1.2
|
121
|
+
ptr = MemoryPointer::new( :cl_kernel_arg_address_qualifier )
|
122
|
+
error = OpenCL.clGetKernelArgInfo(@kernel, @index, ADDRESS_QUALIFIER, ptr.size, ptr, nil)
|
123
|
+
error_check(error)
|
124
|
+
AddressQualifier::new( ptr.read_cl_kernel_arg_address_qualifier )
|
125
|
+
end
|
122
126
|
end
|
123
127
|
|
124
128
|
# Returns an AccessQualifier corresponding to the Arg
|
125
129
|
def access_qualifier
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
130
|
+
@_access_qualifier ||= begin
|
131
|
+
error_check(INVALID_OPERATION) if @kernel.context.platform.version_number < 1.2
|
132
|
+
ptr = MemoryPointer::new( :cl_kernel_arg_access_qualifier )
|
133
|
+
error = OpenCL.clGetKernelArgInfo(@kernel, @index, ACCESS_QUALIFIER, ptr.size, ptr, nil)
|
134
|
+
error_check(error)
|
135
|
+
AccessQualifier::new( ptr.read_cl_kernel_arg_access_qualifier )
|
136
|
+
end
|
132
137
|
end
|
133
138
|
|
134
139
|
# Returns a String corresponding to the Arg type name
|
135
140
|
def type_name
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
141
|
+
@_type_name ||= begin
|
142
|
+
error_check(INVALID_OPERATION) if @kernel.context.platform.version_number < 1.2
|
143
|
+
ptr1 = MemoryPointer::new( :size_t, 1)
|
144
|
+
error = OpenCL.clGetKernelArgInfo(@kernel, @index, TYPE_NAME, 0, nil, ptr1)
|
145
|
+
error_check(error)
|
146
|
+
ptr2 = MemoryPointer::new( ptr1.read_size_t )
|
147
|
+
error = OpenCL.clGetKernelArgInfo(@kernel, @index, TYPE_NAME, ptr1.read_size_t, ptr2, nil)
|
148
|
+
error_check(error)
|
149
|
+
ptr2.read_string
|
150
|
+
end
|
145
151
|
end
|
146
152
|
|
147
153
|
# Returns a TypeQualifier corresponding to the Arg
|
148
154
|
def type_qualifier
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
+
@_type_qualifier ||= begin
|
156
|
+
error_check(INVALID_OPERATION) if @kernel.context.platform.version_number < 1.2
|
157
|
+
ptr = MemoryPointer::new( :cl_kernel_arg_type_qualifier )
|
158
|
+
error = OpenCL.clGetKernelArgInfo(@kernel, @index, TYPE_QUALIFIER, ptr.size, ptr, nil)
|
159
|
+
error_check(error)
|
160
|
+
TypeQualifier::new( ptr.read_cl_kernel_arg_type_qualifier )
|
161
|
+
end
|
155
162
|
end
|
156
163
|
|
157
164
|
# Returns a String corresponding to the Arg name
|
158
165
|
def name
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
166
|
+
@_name ||= begin
|
167
|
+
error_check(INVALID_OPERATION) if @kernel.context.platform.version_number < 1.2
|
168
|
+
ptr1 = MemoryPointer::new( :size_t, 1)
|
169
|
+
error = OpenCL.clGetKernelArgInfo(@kernel, @index, NAME, 0, nil, ptr1)
|
170
|
+
error_check(error)
|
171
|
+
ptr2 = MemoryPointer::new( ptr1.read_size_t )
|
172
|
+
error = OpenCL.clGetKernelArgInfo(@kernel, @index, NAME, ptr1.read_size_t, ptr2, nil)
|
173
|
+
error_check(error)
|
174
|
+
ptr2.read_string
|
175
|
+
end
|
168
176
|
end
|
169
177
|
|
170
178
|
alias to_s name
|
@@ -194,26 +202,27 @@ module OpenCL
|
|
194
202
|
|
195
203
|
# Returns the Platform associated with the Kernel
|
196
204
|
def platform
|
197
|
-
|
198
|
-
@_platform = self.context.platform
|
205
|
+
@_platform ||= self.context.platform
|
199
206
|
end
|
200
207
|
|
201
208
|
# Returns the Context the Kernel is associated with
|
202
209
|
def context
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
210
|
+
@_context ||= begin
|
211
|
+
ptr = MemoryPointer::new( Context )
|
212
|
+
error = OpenCL.clGetKernelInfo(self, CONTEXT, Context.size, ptr, nil)
|
213
|
+
error_check(error)
|
214
|
+
Context::new( ptr.read_pointer )
|
215
|
+
end
|
208
216
|
end
|
209
217
|
|
210
218
|
# Returns the Program the Kernel was created from
|
211
219
|
def program
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
220
|
+
@_program ||= begin
|
221
|
+
ptr = MemoryPointer::new( Program )
|
222
|
+
error = OpenCL.clGetKernelInfo(self, PROGRAM, Program.size, ptr, nil)
|
223
|
+
error_check(error)
|
224
|
+
Program::new(ptr.read_pointer)
|
225
|
+
end
|
217
226
|
end
|
218
227
|
|
219
228
|
def work_group_size(device = program.devices.first)
|
@@ -286,15 +295,16 @@ module OpenCL
|
|
286
295
|
##
|
287
296
|
# returns a String containing the attributes qualifier used at kernel definition
|
288
297
|
def attributes
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
+
@_attributes ||= begin
|
299
|
+
attributes_size = MemoryPointer::new( :size_t )
|
300
|
+
error = OpenCL.clGetKernelInfo( self, ATTRIBUTES, 0, nil, attributes_size)
|
301
|
+
error_check(error)
|
302
|
+
attr = MemoryPointer::new( attributes_size.read_size_t )
|
303
|
+
error = OpenCL.clGetKernelInfo( self, ATTRIBUTES, attributes_size.read_size_t, attr, nil)
|
304
|
+
error_check(error)
|
305
|
+
attr_string = attr.read_string
|
306
|
+
attr_string.split(" ")
|
307
|
+
end
|
298
308
|
end
|
299
309
|
|
300
310
|
def global_work_size(device = program.devices.first)
|