opencl_ruby_ffi 1.2.2 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +1 -0
- data/lib/opencl_ruby_ffi.rb +2 -0
- data/lib/opencl_ruby_ffi/Buffer.rb +18 -13
- data/lib/opencl_ruby_ffi/CommandQueue.rb +301 -302
- data/lib/opencl_ruby_ffi/Context.rb +158 -158
- data/lib/opencl_ruby_ffi/Device.rb +270 -224
- data/lib/opencl_ruby_ffi/Event.rb +40 -36
- data/lib/opencl_ruby_ffi/Image.rb +34 -57
- data/lib/opencl_ruby_ffi/Kernel.rb +251 -191
- data/lib/opencl_ruby_ffi/Mem.rb +49 -70
- data/lib/opencl_ruby_ffi/Pipe.rb +3 -14
- data/lib/opencl_ruby_ffi/Platform.rb +46 -48
- data/lib/opencl_ruby_ffi/Program.rb +131 -124
- data/lib/opencl_ruby_ffi/Sampler.rb +6 -24
- data/lib/opencl_ruby_ffi/amd/device_attribute_query.rb +100 -0
- data/lib/opencl_ruby_ffi/egl.rb +2 -0
- data/lib/opencl_ruby_ffi/ext.rb +11 -0
- data/lib/opencl_ruby_ffi/ext/device_fission.rb +264 -0
- data/lib/opencl_ruby_ffi/gl_ext.rb +2 -0
- data/lib/opencl_ruby_ffi/khr/d3d10_sharing.rb +120 -0
- data/lib/opencl_ruby_ffi/khr/d3d11_sharing.rb +120 -0
- data/lib/opencl_ruby_ffi/khr/dx9_media_sharing.rb +113 -0
- data/lib/opencl_ruby_ffi/khr/egl_event.rb +15 -0
- data/lib/opencl_ruby_ffi/khr/egl_image.rb +58 -0
- data/lib/opencl_ruby_ffi/khr/fp16.rb +23 -0
- data/lib/opencl_ruby_ffi/khr/fp64.rb +23 -0
- data/lib/opencl_ruby_ffi/khr/gl_event.rb +38 -0
- data/lib/opencl_ruby_ffi/khr/gl_sharing.rb +79 -0
- data/lib/opencl_ruby_ffi/khr/icd.rb +30 -0
- data/lib/opencl_ruby_ffi/khr/initalize_memory.rb +19 -0
- data/lib/opencl_ruby_ffi/khr/priority_hints.rb +48 -0
- data/lib/opencl_ruby_ffi/khr/spir.rb +45 -0
- data/lib/opencl_ruby_ffi/khr/sub_groups.rb +49 -0
- data/lib/opencl_ruby_ffi/khr/terminate_context.rb +46 -0
- data/lib/opencl_ruby_ffi/khr/throttle_hints.rb +47 -0
- data/lib/opencl_ruby_ffi/nv/device_attribute_query.rb +50 -0
- data/lib/opencl_ruby_ffi/opencl_ruby_ffi_base.rb +40 -13
- data/lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb +214 -2114
- data/lib/opencl_ruby_ffi/opencl_types.rb +15 -3
- data/opencl_ruby_ffi.gemspec +4 -4
- data/templates_custom/default/module/setup.rb +9 -0
- metadata +29 -6
- data/lib/opencl_ruby_ffi/GLExt.rb +0 -58
- data/lib/opencl_ruby_ffi/Stream.rb +0 -127
data/lib/opencl_ruby_ffi/Mem.rb
CHANGED
@@ -22,16 +22,20 @@ module OpenCL
|
|
22
22
|
# Maps the cl_mem object of OpenCL
|
23
23
|
class Mem
|
24
24
|
include InnerInterface
|
25
|
-
|
26
|
-
class << self
|
27
|
-
include InnerGenerator
|
28
|
-
end
|
25
|
+
extend InnerGenerator
|
29
26
|
|
30
27
|
def inspect
|
31
28
|
f = flags
|
32
29
|
return "#<#{self.class.name}: #{size}#{ 0 != f.to_i ? " (#{f})" : ""}>"
|
33
30
|
end
|
34
31
|
|
32
|
+
get_info("Mem", :cl_mem_object_type, "type")
|
33
|
+
get_info("Mem", :cl_mem_flags, "flags")
|
34
|
+
get_info("Mem", :size_t, "size")
|
35
|
+
get_info("Mem", :pointer, "host_ptr")
|
36
|
+
get_info("Mem", :cl_uint, "map_count")
|
37
|
+
get_info("Mem", :cl_uint, "reference_count")
|
38
|
+
|
35
39
|
# Returns the Context associated to the Mem
|
36
40
|
def context
|
37
41
|
ptr = MemoryPointer::new( Context )
|
@@ -45,72 +49,6 @@ module OpenCL
|
|
45
49
|
return self.context.platform
|
46
50
|
end
|
47
51
|
|
48
|
-
# Returns the Buffer this Buffer was created from using create_sub_buffer
|
49
|
-
def associated_memobject
|
50
|
-
ptr = MemoryPointer::new( Mem )
|
51
|
-
error = OpenCL.clGetMemObjectInfo(self, ASSOCIATED_MEMOBJECT, Mem.size, ptr, nil)
|
52
|
-
error_check(error)
|
53
|
-
return nil if ptr.read_pointer.null?
|
54
|
-
return Mem::new( ptr.read_pointer )
|
55
|
-
end
|
56
|
-
|
57
|
-
##
|
58
|
-
# :method: offset()
|
59
|
-
# Returns the offset used to create this Buffer using create_sub_buffer
|
60
|
-
|
61
|
-
##
|
62
|
-
# :method: size()
|
63
|
-
# Returns the size of the Buffer
|
64
|
-
%w( OFFSET SIZE ).each { |prop|
|
65
|
-
eval get_info("Mem", :size_t, prop)
|
66
|
-
}
|
67
|
-
|
68
|
-
##
|
69
|
-
# :method: map_count()
|
70
|
-
# Returns the number of times this Mem is mapped
|
71
|
-
|
72
|
-
##
|
73
|
-
# :method: reference_count()
|
74
|
-
# Returns the Mem reference counter
|
75
|
-
%w( MAP_COUNT REFERENCE_COUNT ).each { |prop|
|
76
|
-
eval get_info("Mem", :cl_uint, prop)
|
77
|
-
}
|
78
|
-
|
79
|
-
##
|
80
|
-
# :method: uses_svn_pointer()
|
81
|
-
# Returns true if Mem uses an SVM pointer
|
82
|
-
eval get_info("Mem", :cl_bool, "USES_SVM_POINTER")
|
83
|
-
|
84
|
-
##
|
85
|
-
# :method: type()
|
86
|
-
# Returns a Mem::Type corresponding to the Mem
|
87
|
-
eval get_info("Mem", :cl_mem_object_type, "TYPE")
|
88
|
-
|
89
|
-
##
|
90
|
-
# :method: flags()
|
91
|
-
# Returns a Mem::Flags corresponding to the flags used at Mem creation
|
92
|
-
eval get_info("Mem", :cl_mem_flags, "FLAGS")
|
93
|
-
|
94
|
-
##
|
95
|
-
# :method: host_ptr()
|
96
|
-
# Returns the host Pointer specified at Mem creation or the pointer + the ofsset if it is a sub-buffer. A null Pointer is returned otherwise.
|
97
|
-
eval get_info("Mem", :pointer, "HOST_PTR")
|
98
|
-
|
99
|
-
# Attaches a callback to memobj that will be called on the memobj destruction
|
100
|
-
#
|
101
|
-
# ==== Attributes
|
102
|
-
#
|
103
|
-
# * +options+ - a hash containing named options
|
104
|
-
# * +block+ - if provided, a callback invoked when memobj is released. Signature of the callback is { |Mem, Pointer to user_data| ... }
|
105
|
-
#
|
106
|
-
# ==== Options
|
107
|
-
#
|
108
|
-
# * +:user_data+ - a Pointer (or convertible to Pointer using to_ptr) to the memory area to pass to the callback
|
109
|
-
def set_destructor_callback( options = {}, &proc )
|
110
|
-
OpenCL.set_mem_object_destructor_callback( self, options, &proc )
|
111
|
-
return self
|
112
|
-
end
|
113
|
-
|
114
52
|
# Returns the texture_target argument specified in create_from_GL_texture for Mem
|
115
53
|
def gl_texture_target
|
116
54
|
param_value = MemoryPointer::new( :cl_GLenum )
|
@@ -147,6 +85,47 @@ module OpenCL
|
|
147
85
|
end
|
148
86
|
alias :GL_object_name :gl_object_name
|
149
87
|
|
88
|
+
module OpenCL11
|
89
|
+
extend InnerGenerator
|
90
|
+
|
91
|
+
get_info("Mem", :size_t, "offset")
|
92
|
+
|
93
|
+
# Returns the Buffer this Buffer was created from using create_sub_buffer
|
94
|
+
def associated_memobject
|
95
|
+
ptr = MemoryPointer::new( Mem )
|
96
|
+
error = OpenCL.clGetMemObjectInfo(self, ASSOCIATED_MEMOBJECT, Mem.size, ptr, nil)
|
97
|
+
error_check(error)
|
98
|
+
return nil if ptr.read_pointer.null?
|
99
|
+
return Mem::new( ptr.read_pointer )
|
100
|
+
end
|
101
|
+
|
102
|
+
# Attaches a callback to memobj that will be called on the memobj destruction
|
103
|
+
#
|
104
|
+
# ==== Attributes
|
105
|
+
#
|
106
|
+
# * +options+ - a hash containing named options
|
107
|
+
# * +block+ - if provided, a callback invoked when memobj is released. Signature of the callback is { |Mem, Pointer to user_data| ... }
|
108
|
+
#
|
109
|
+
# ==== Options
|
110
|
+
#
|
111
|
+
# * +:user_data+ - a Pointer (or convertible to Pointer using to_ptr) to the memory area to pass to the callback
|
112
|
+
def set_destructor_callback( options = {}, &proc )
|
113
|
+
OpenCL.set_mem_object_destructor_callback( self, options, &proc )
|
114
|
+
return self
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
module OpenCL20
|
120
|
+
extend InnerGenerator
|
121
|
+
|
122
|
+
get_info("Mem", :cl_bool, "uses_svm_pointer")
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
register_extension( :v11, OpenCL11, "platform.version_number >= 1.1" )
|
127
|
+
register_extension( :v20, OpenCL20, "platform.version_number >= 2.0" )
|
128
|
+
|
150
129
|
end
|
151
130
|
|
152
131
|
end
|
data/lib/opencl_ruby_ffi/Pipe.rb
CHANGED
@@ -24,26 +24,15 @@ module OpenCL
|
|
24
24
|
# Maps the cl_mem OpenCL objects of type CL_MEM_OBJECT_PIPE
|
25
25
|
class Pipe #< Mem
|
26
26
|
include InnerInterface
|
27
|
-
|
28
|
-
class << self
|
29
|
-
include InnerGenerator
|
30
|
-
end
|
27
|
+
extend InnerGenerator
|
31
28
|
|
32
29
|
def inspect
|
33
30
|
f = flags
|
34
31
|
return "#<#{self.class.inspect}: #{packet_size}x#{max_packets}#{ 0 != f.to_i ? " (#{f})" : ""}>"
|
35
32
|
end
|
36
33
|
|
37
|
-
|
38
|
-
|
39
|
-
# Returns the packet_size of the Pipe
|
40
|
-
|
41
|
-
##
|
42
|
-
# :method: max_packets
|
43
|
-
# Returns the max_packets of the Pipe
|
44
|
-
%w( PACKET_SIZE MAX_PACKETS ).each { |prop|
|
45
|
-
eval get_info("Pipe", :cl_uint, prop)
|
46
|
-
}
|
34
|
+
get_info("Pipe", :cl_uint, "packet_size")
|
35
|
+
get_info("Pipe", :cl_uint, "max_packets")
|
47
36
|
|
48
37
|
end
|
49
38
|
|
@@ -35,6 +35,15 @@ module OpenCL
|
|
35
35
|
return Function::new(return_type, param_types, ptr, options)
|
36
36
|
end
|
37
37
|
|
38
|
+
def self.attach_extension_function( name, return_type, param_types, options = {} )
|
39
|
+
f = get_extension_function( name, return_type, param_types, options )
|
40
|
+
if not f then
|
41
|
+
warn "Warning: could not find extension function #{name}!"
|
42
|
+
return nil
|
43
|
+
end
|
44
|
+
f.attach(OpenCL, name)
|
45
|
+
end
|
46
|
+
|
38
47
|
# Returns a Function corresponding to an extension function for the Platform
|
39
48
|
#
|
40
49
|
# ==== Attributes
|
@@ -73,42 +82,17 @@ module OpenCL
|
|
73
82
|
# Maps the cl_platform_id object of OpenCL
|
74
83
|
class Platform
|
75
84
|
include InnerInterface
|
76
|
-
|
77
|
-
class << self
|
78
|
-
include InnerGenerator
|
79
|
-
end
|
85
|
+
extend InnerGenerator
|
80
86
|
|
81
87
|
def inspect
|
82
88
|
return "#<#{self.class.name}: #{self.name}>"
|
83
89
|
end
|
84
90
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
# :method: profile()
|
91
|
-
# Returns a String containing the profile name supported by the Platform
|
92
|
-
|
93
|
-
##
|
94
|
-
# :method: version()
|
95
|
-
# Returns a String containing the version number
|
96
|
-
|
97
|
-
##
|
98
|
-
# :method: name()
|
99
|
-
# Returns a String containing the Platform name
|
100
|
-
|
101
|
-
##
|
102
|
-
# :method: vendor()
|
103
|
-
# Returns a String identifying the Platform vendor
|
104
|
-
%w(PROFILE VERSION NAME VENDOR ICD_SUFFIX_KHR).each { |prop|
|
105
|
-
eval get_info("Platform", :string, prop)
|
106
|
-
}
|
107
|
-
|
108
|
-
##
|
109
|
-
# :method: host_timer_resolution()
|
110
|
-
# returns the host timer resulution in nanoseconds
|
111
|
-
eval get_info("Platform", :cl_ulong, "HOST_TIMER_RESOLUTION")
|
91
|
+
get_info("Platform", :string, "profile")
|
92
|
+
get_info("Platform", :string, "version")
|
93
|
+
get_info("Platform", :string, "name")
|
94
|
+
alias to_s name
|
95
|
+
get_info("Platform", :string, "vendor")
|
112
96
|
|
113
97
|
# Returns an Array of string corresponding to the Platform extensions
|
114
98
|
def extensions
|
@@ -143,23 +127,6 @@ module OpenCL
|
|
143
127
|
return n.first.first.to_f
|
144
128
|
end
|
145
129
|
|
146
|
-
# Unloads the Platform compiler
|
147
|
-
def unload_compiler
|
148
|
-
return OpenCL.unload_platform_compiler(self)
|
149
|
-
end
|
150
|
-
|
151
|
-
# Returns a Function corresponding to an extension function for a Platform
|
152
|
-
#
|
153
|
-
# ==== Attributes
|
154
|
-
#
|
155
|
-
# * +name+ - a String representing the name of the function
|
156
|
-
# * +return_type+ - the type of data returned by the function
|
157
|
-
# * +param_types+ - an Array of types, corresponding to the parameters type
|
158
|
-
# * +options+ - if given, a hash of named options that will be given to Function::new. See FFI doc for details.
|
159
|
-
def get_extension_function( name, return_type, param_types, options = {} )
|
160
|
-
return OpenCL.get_extension_function_for_platform( self, name, return_type, param_types, options )
|
161
|
-
end
|
162
|
-
|
163
130
|
# Creates a Context gathering devices of a certain type and belonging to this Platform
|
164
131
|
#
|
165
132
|
# ==== Attributes
|
@@ -184,6 +151,37 @@ module OpenCL
|
|
184
151
|
OpenCL.create_context_from_type(type, opts, &block)
|
185
152
|
end
|
186
153
|
|
154
|
+
module OpenCL12
|
155
|
+
|
156
|
+
# Returns a Function corresponding to an extension function for a Platform
|
157
|
+
#
|
158
|
+
# ==== Attributes
|
159
|
+
#
|
160
|
+
# * +name+ - a String representing the name of the function
|
161
|
+
# * +return_type+ - the type of data returned by the function
|
162
|
+
# * +param_types+ - an Array of types, corresponding to the parameters type
|
163
|
+
# * +options+ - if given, a hash of named options that will be given to Function::new. See FFI doc for details.
|
164
|
+
def get_extension_function( name, return_type, param_types, options = {} )
|
165
|
+
return OpenCL.get_extension_function_for_platform( self, name, return_type, param_types, options )
|
166
|
+
end
|
167
|
+
|
168
|
+
# Unloads the Platform compiler
|
169
|
+
def unload_compiler
|
170
|
+
return OpenCL.unload_platform_compiler(self)
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
module OpenCL21
|
176
|
+
extend InnerGenerator
|
177
|
+
|
178
|
+
get_info("Platform", :cl_ulong, "host_timer_resolution")
|
179
|
+
|
180
|
+
end
|
181
|
+
|
182
|
+
register_extension( :v12, OpenCL12, "version_number >= 1.2" )
|
183
|
+
register_extension( :v21, OpenCL21, "version_number >= 2.1" )
|
184
|
+
|
187
185
|
end
|
188
186
|
|
189
187
|
end
|
@@ -179,7 +179,7 @@ module OpenCL
|
|
179
179
|
c_strs_length = MemoryPointer::new( :size_t, c_strs_p.size )
|
180
180
|
c_strs_p.each_with_index { |p, i|
|
181
181
|
c_strs[i].write_pointer(p)
|
182
|
-
c_strs_length[i].write_size_t(p.size)
|
182
|
+
c_strs_length[i].write_size_t(p.size == 0 ? 0 : p.size - 1) # minus the null character
|
183
183
|
}
|
184
184
|
error = MemoryPointer::new( :cl_int )
|
185
185
|
program_ptr = clCreateProgramWithSource(context, c_strs_p.size, c_strs, c_strs_length, error)
|
@@ -207,10 +207,7 @@ module OpenCL
|
|
207
207
|
# Maps the cl_program object of OpenCL
|
208
208
|
class Program
|
209
209
|
include InnerInterface
|
210
|
-
|
211
|
-
class << self
|
212
|
-
include InnerGenerator
|
213
|
-
end
|
210
|
+
extend InnerGenerator
|
214
211
|
|
215
212
|
def inspect
|
216
213
|
success = false
|
@@ -239,41 +236,50 @@ module OpenCL
|
|
239
236
|
end
|
240
237
|
end
|
241
238
|
|
242
|
-
# Returns
|
243
|
-
|
239
|
+
# Returns the Context the Program is associated to
|
240
|
+
def context
|
241
|
+
ptr = MemoryPointer::new( Context )
|
242
|
+
error = OpenCL.clGetProgramInfo(self, CONTEXT, Context.size, ptr, nil)
|
243
|
+
error_check(error)
|
244
|
+
return Context::new( ptr.read_pointer )
|
245
|
+
end
|
244
246
|
|
245
|
-
|
246
|
-
|
247
|
+
get_info("Program", :cl_uint, "num_devices")
|
248
|
+
get_info("Program", :cl_uint, "reference_count")
|
247
249
|
|
248
|
-
# Returns
|
249
|
-
def
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
error = OpenCL.clGetProgramInfo( self, KERNEL_NAMES, kernel_names_size.read_size_t, k_names, nil)
|
258
|
-
error_check(error)
|
259
|
-
k_names_string = k_names.read_string
|
260
|
-
return k_names_string.split(";")
|
261
|
-
end
|
250
|
+
# Returns the Array of Device the Program is associated with
|
251
|
+
def devices
|
252
|
+
n = self.num_devices
|
253
|
+
ptr2 = MemoryPointer::new( Device, n )
|
254
|
+
error = OpenCL.clGetProgramInfo(self, DEVICES, Device.size*n, ptr2, nil)
|
255
|
+
error_check(error)
|
256
|
+
return ptr2.get_array_of_pointer(0, n).collect { |device_ptr|
|
257
|
+
Device::new(device_ptr)
|
258
|
+
}
|
262
259
|
end
|
263
260
|
|
264
|
-
|
265
|
-
|
261
|
+
get_info("Program", :string, "source")
|
262
|
+
get_info_array("Program", :size_t, "binary_sizes")
|
266
263
|
|
267
|
-
# Returns the
|
268
|
-
def
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
[
|
264
|
+
# Returns the binaries associated to the Program for each Device. Returns an Array of tuple [ Device, String ]
|
265
|
+
def binaries
|
266
|
+
sizes = self.binary_sizes
|
267
|
+
bin_array = MemoryPointer::new( :pointer, sizes.length )
|
268
|
+
total_size = 0
|
269
|
+
pointers = []
|
270
|
+
sizes.each_with_index { |s, i|
|
271
|
+
total_size += s
|
272
|
+
pointers[i] = MemoryPointer::new(s)
|
273
|
+
bin_array[i].write_pointer(pointers[i])
|
276
274
|
}
|
275
|
+
error = OpenCL.clGetProgramInfo(self, BINARIES, total_size, bin_array, nil)
|
276
|
+
error_check(error)
|
277
|
+
bins = []
|
278
|
+
devs = self.devices
|
279
|
+
sizes.each_with_index { |s, i|
|
280
|
+
bins.push [devs[i], pointers[i].read_bytes(s)]
|
281
|
+
}
|
282
|
+
return bins
|
277
283
|
end
|
278
284
|
|
279
285
|
# Returns the BuildStatus of the Program for each device associated to the Program or the Device(s) specified. Returns an Array of tuple [ Device, BuildStatus ]
|
@@ -288,18 +294,6 @@ module OpenCL
|
|
288
294
|
}
|
289
295
|
end
|
290
296
|
|
291
|
-
# Returns the BinaryType for each Device associated to the Program or the Device(s) specified. Returns an Array of tuple [ Device, BinaryType ]
|
292
|
-
def binary_type(devs = nil)
|
293
|
-
devs = self.devices if not devs
|
294
|
-
devs = [devs].flatten
|
295
|
-
ptr = MemoryPointer::new( :cl_program_binary_type )
|
296
|
-
return devs.collect { |dev|
|
297
|
-
error = OpenCL.clGetProgramBuildInfo(self, dev, BINARY_TYPE, ptr.size, ptr, nil)
|
298
|
-
error_check(error)
|
299
|
-
[dev, BinaryType::new(ptr.read_cl_program_binary_type)]
|
300
|
-
}
|
301
|
-
end
|
302
|
-
|
303
297
|
# Returns the build options for each Device associated to the Program or the Device(s) specified. Returns an Array of tuple [ Device, String ]
|
304
298
|
def build_options(devs = nil)
|
305
299
|
devs = self.devices if not devs
|
@@ -330,39 +324,6 @@ module OpenCL
|
|
330
324
|
}
|
331
325
|
end
|
332
326
|
|
333
|
-
# Returns the binaries associated to the Program for each Device. Returns an Array of tuple [ Device, String ]
|
334
|
-
def binaries
|
335
|
-
sizes = self.binary_sizes
|
336
|
-
bin_array = MemoryPointer::new( :pointer, sizes.length )
|
337
|
-
sizes.length
|
338
|
-
total_size = 0
|
339
|
-
sizes.each_with_index { |s, i|
|
340
|
-
total_size += s
|
341
|
-
bin_array[i].write_pointer(MemoryPointer::new(s))
|
342
|
-
}
|
343
|
-
error = OpenCL.clGetProgramInfo(self, BINARIES, total_size, bin_array, nil)
|
344
|
-
error_check(error)
|
345
|
-
bins = []
|
346
|
-
devs = self.devices
|
347
|
-
sizes.each_with_index { |s, i|
|
348
|
-
bins.push [devs, bin_array[i].read_pointer.read_bytes(s)]
|
349
|
-
}
|
350
|
-
return bins
|
351
|
-
end
|
352
|
-
|
353
|
-
# Return the intermediate level representation of the program if any, nil otherwise
|
354
|
-
def il
|
355
|
-
il_size = MemoryPointer::new( :size_t )
|
356
|
-
error = OpenCL.clGetProgramInfo(self, IL, 0, nil, il_size)
|
357
|
-
error_check(error)
|
358
|
-
return nil if il_size == 0
|
359
|
-
length = il_size.read_size_t
|
360
|
-
il_p = MemoryPointer::new( length )
|
361
|
-
error = OpenCL.clGetProgramInfo(self, IL, length, il_p, nil)
|
362
|
-
error_check(error)
|
363
|
-
return il_p.read_bytes(length)
|
364
|
-
end
|
365
|
-
|
366
327
|
# Builds (compile and link) the Program created from sources or binary
|
367
328
|
#
|
368
329
|
# ==== Attributes
|
@@ -378,63 +339,109 @@ module OpenCL
|
|
378
339
|
OpenCL.build_program(self, options, &block)
|
379
340
|
end
|
380
341
|
|
381
|
-
#
|
382
|
-
|
383
|
-
|
384
|
-
#
|
385
|
-
# * +options+ - a Hash containing named options
|
386
|
-
# * +block+ - if provided, a callback invoked when the Program is compiled. Signature of the callback is { |Program, Pointer to user_data| ... }
|
387
|
-
#
|
388
|
-
# ==== Options
|
389
|
-
#
|
390
|
-
# * +:device_list+ - an Array of Device to build the program for
|
391
|
-
# * +:user_data+ - a Pointer (or convertible to Pointer using to_ptr) to the memory area to pass to the callback
|
392
|
-
# * +:options+ - a String containing the options to use for the compilation
|
393
|
-
# * +:input_headers+ - a Hash containing pairs of : String: header_include_name => Program: header
|
394
|
-
def compile(options = {}, &block)
|
395
|
-
return OpenCL.compile_program(self, options, &block)
|
342
|
+
# Returns the Kernel corresponding the the specified name in the Program
|
343
|
+
def create_kernel( name )
|
344
|
+
return OpenCL.create_kernel( self, name )
|
396
345
|
end
|
397
346
|
|
398
|
-
# Returns
|
399
|
-
def
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
347
|
+
# Returns an Array of Kernel corresponding to the kernels defined inside the Program
|
348
|
+
def kernels
|
349
|
+
return OpenCL.create_kernels_in_program( self )
|
350
|
+
end
|
351
|
+
|
352
|
+
def kernel_names
|
353
|
+
return kernels.collect(&:name)
|
404
354
|
end
|
405
355
|
|
406
|
-
|
407
|
-
|
408
|
-
|
356
|
+
module OpenCL12
|
357
|
+
extend InnerGenerator
|
358
|
+
|
359
|
+
get_info("Program", :size_t, "num_kernels")
|
360
|
+
|
361
|
+
# Returns an Array of String representing the Kernel names inside the Program
|
362
|
+
def kernel_names
|
363
|
+
if context.platform.version_number < 1.2 then
|
364
|
+
return kernels.collect(&:name)
|
365
|
+
else
|
366
|
+
kernel_names_size = MemoryPointer::new( :size_t )
|
367
|
+
error = OpenCL.clGetProgramInfo( self, KERNEL_NAMES, 0, nil, kernel_names_size)
|
368
|
+
error_check(error)
|
369
|
+
k_names = MemoryPointer::new( kernel_names_size.read_size_t )
|
370
|
+
error = OpenCL.clGetProgramInfo( self, KERNEL_NAMES, kernel_names_size.read_size_t, k_names, nil)
|
371
|
+
error_check(error)
|
372
|
+
k_names_string = k_names.read_string
|
373
|
+
return k_names_string.split(";")
|
374
|
+
end
|
375
|
+
end
|
409
376
|
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
377
|
+
# Returns the BinaryType for each Device associated to the Program or the Device(s) specified. Returns an Array of tuple [ Device, BinaryType ]
|
378
|
+
def binary_type(devs = nil)
|
379
|
+
devs = self.devices if not devs
|
380
|
+
devs = [devs].flatten
|
381
|
+
ptr = MemoryPointer::new( :cl_program_binary_type )
|
382
|
+
return devs.collect { |dev|
|
383
|
+
error = OpenCL.clGetProgramBuildInfo(self, dev, BINARY_TYPE, ptr.size, ptr, nil)
|
384
|
+
error_check(error)
|
385
|
+
[dev, BinaryType::new(ptr.read_cl_program_binary_type)]
|
386
|
+
}
|
387
|
+
end
|
388
|
+
|
389
|
+
# Compiles the Program' sources
|
390
|
+
#
|
391
|
+
# ==== Attributes
|
392
|
+
#
|
393
|
+
# * +options+ - a Hash containing named options
|
394
|
+
# * +block+ - if provided, a callback invoked when the Program is compiled. Signature of the callback is { |Program, Pointer to user_data| ... }
|
395
|
+
#
|
396
|
+
# ==== Options
|
397
|
+
#
|
398
|
+
# * +:device_list+ - an Array of Device to build the program for
|
399
|
+
# * +:user_data+ - a Pointer (or convertible to Pointer using to_ptr) to the memory area to pass to the callback
|
400
|
+
# * +:options+ - a String containing the options to use for the compilation
|
401
|
+
# * +:input_headers+ - a Hash containing pairs of : String: header_include_name => Program: header
|
402
|
+
def compile(options = {}, &block)
|
403
|
+
return OpenCL.compile_program(self, options, &block)
|
404
|
+
end
|
416
405
|
|
417
|
-
# Returns the Array of Device the Program is associated with
|
418
|
-
def devices
|
419
|
-
n = self.num_devices
|
420
|
-
ptr2 = MemoryPointer::new( Device, n )
|
421
|
-
error = OpenCL.clGetProgramInfo(self, DEVICES, Device.size*n, ptr2, nil)
|
422
|
-
error_check(error)
|
423
|
-
return ptr2.get_array_of_pointer(0, n).collect { |device_ptr|
|
424
|
-
Device::new(device_ptr)
|
425
|
-
}
|
426
406
|
end
|
427
407
|
|
428
|
-
|
429
|
-
|
430
|
-
|
408
|
+
module OpenCL20
|
409
|
+
|
410
|
+
# Returns the total amount in byte used by the Program variables in the global address space for the Device(s) specified. Returns an Array of tuple [ Device, size ] (2.0 only)
|
411
|
+
def build_global_variable_total_size(devs = nil)
|
412
|
+
devs = self.devices if not devs
|
413
|
+
devs = [devs].flatten
|
414
|
+
ptr = MemoryPointer::new( :size_t )
|
415
|
+
return devs.collect { |dev|
|
416
|
+
error = OpenCL.clGetProgramBuildInfo(self, dev, BUILD_GLOBAL_VARIABLE_TOTAL_SIZE, ptr.size, ptr, nil)
|
417
|
+
error_check(error)
|
418
|
+
[dev, ptr.read_size_t]
|
419
|
+
}
|
420
|
+
end
|
421
|
+
|
431
422
|
end
|
432
423
|
|
433
|
-
|
434
|
-
|
435
|
-
|
424
|
+
module OpenCL21
|
425
|
+
|
426
|
+
# Return the intermediate level representation of the program if any, nil otherwise
|
427
|
+
def il
|
428
|
+
il_size = MemoryPointer::new( :size_t )
|
429
|
+
error = OpenCL.clGetProgramInfo(self, IL, 0, nil, il_size)
|
430
|
+
error_check(error)
|
431
|
+
return nil if il_size == 0
|
432
|
+
length = il_size.read_size_t
|
433
|
+
il_p = MemoryPointer::new( length )
|
434
|
+
error = OpenCL.clGetProgramInfo(self, IL, length, il_p, nil)
|
435
|
+
error_check(error)
|
436
|
+
return il_p.read_bytes(length)
|
437
|
+
end
|
438
|
+
|
436
439
|
end
|
437
440
|
|
441
|
+
register_extension( :v12, OpenCL12, "context.platform.version_number >= 1.2" )
|
442
|
+
register_extension( :v20, OpenCL20, "context.platform.version_number >= 2.0" )
|
443
|
+
register_extension( :v21, OpenCL21, "context.platform.version_number >= 2.1" )
|
444
|
+
|
438
445
|
end
|
439
446
|
|
440
447
|
end
|