opencl_ruby_ffi 1.1.0 → 1.2.0
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/Buffer.rb +4 -3
- data/lib/opencl_ruby_ffi/CommandQueue.rb +57 -56
- data/lib/opencl_ruby_ffi/Context.rb +18 -17
- data/lib/opencl_ruby_ffi/Device.rb +22 -21
- data/lib/opencl_ruby_ffi/Event.rb +12 -11
- data/lib/opencl_ruby_ffi/GLExt.rb +9 -8
- data/lib/opencl_ruby_ffi/Image.rb +11 -10
- data/lib/opencl_ruby_ffi/Kernel.rb +32 -31
- data/lib/opencl_ruby_ffi/Mem.rb +9 -8
- data/lib/opencl_ruby_ffi/Pipe.rb +2 -1
- data/lib/opencl_ruby_ffi/Platform.rb +20 -19
- data/lib/opencl_ruby_ffi/Program.rb +46 -45
- data/lib/opencl_ruby_ffi/SVM.rb +12 -11
- data/lib/opencl_ruby_ffi/Sampler.rb +4 -3
- data/lib/opencl_ruby_ffi/Stream.rb +127 -0
- data/lib/opencl_ruby_ffi/{Arithmetic_gen.rb → opencl_arithmetic_gen.rb} +737 -836
- data/lib/opencl_ruby_ffi/opencl_ruby_ffi_base.rb +49 -69
- data/lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb +30 -99
- data/lib/opencl_ruby_ffi/opencl_types.rb +114 -0
- data/lib/opencl_ruby_ffi.rb +2 -1
- data/opencl_ruby_ffi.gemspec +2 -2
- metadata +5 -3
@@ -1,3 +1,4 @@
|
|
1
|
+
using OpenCLRefinements if RUBY_VERSION.scan(/\d+/).collect(&:to_i).first >= 2
|
1
2
|
module OpenCL
|
2
3
|
|
3
4
|
# Splits a Device in serveral sub-devices
|
@@ -12,16 +13,16 @@ module OpenCL
|
|
12
13
|
# an Array of Device
|
13
14
|
def self.create_sub_devices( in_device, properties )
|
14
15
|
error_check(INVALID_OPERATION) if in_device.platform.version_number < 1.2
|
15
|
-
props =
|
16
|
+
props = MemoryPointer::new( :cl_device_partition_property, properties.length + 1 )
|
16
17
|
properties.each_with_index { |e,i|
|
17
18
|
props[i].write_cl_device_partition_property(e)
|
18
19
|
}
|
19
20
|
props[properties.length].write_cl_device_partition_property(0)
|
20
|
-
device_number_ptr =
|
21
|
+
device_number_ptr = MemoryPointer::new( :cl_uint )
|
21
22
|
error = clCreateSubDevices( in_device, props, 0, nil, device_number_ptr )
|
22
23
|
error_check(error)
|
23
24
|
device_number = device_number_ptr.read_cl_uint
|
24
|
-
devices_ptr =
|
25
|
+
devices_ptr = MemoryPointer::new( Device, device_number )
|
25
26
|
error = clCreateSubDevices( in_device, props, device_number, devices_ptr, nil )
|
26
27
|
error_check(error)
|
27
28
|
devices_ptr.get_array_of_pointer(0, device_number).collect { |device_ptr|
|
@@ -31,8 +32,8 @@ module OpenCL
|
|
31
32
|
|
32
33
|
def self.get_device_and_host_timer( device )
|
33
34
|
error_check(INVALID_OPERATION) if device.platform.version_number < 2.1
|
34
|
-
device_timestamp_p =
|
35
|
-
host_timestamp_p =
|
35
|
+
device_timestamp_p = MemoryPointer::new( :cl_ulong )
|
36
|
+
host_timestamp_p = MemoryPointer::new( :cl_ulong )
|
36
37
|
error = clGetDeviceAndHostTimer( device, device_timestamp_p, host_timestamp_p)
|
37
38
|
error_check(error)
|
38
39
|
return [ device_timestamp_p.read_cl_ulong, host_timestamp_p.read_cl_ulong ]
|
@@ -40,7 +41,7 @@ module OpenCL
|
|
40
41
|
|
41
42
|
def self.get_device_and_host_timer( device )
|
42
43
|
error_check(INVALID_OPERATION) if device.platform.version_number < 2.1
|
43
|
-
host_timestamp_p =
|
44
|
+
host_timestamp_p = MemoryPointer::new( :cl_ulong )
|
44
45
|
error = clGetHostTimer( device, host_timestamp_p)
|
45
46
|
error_check(error)
|
46
47
|
return host_timestamp_p.read_cl_ulong
|
@@ -64,10 +65,10 @@ module OpenCL
|
|
64
65
|
|
65
66
|
# Returns an Array of String corresponding to the Device extensions
|
66
67
|
def extensions
|
67
|
-
extensions_size =
|
68
|
+
extensions_size = MemoryPointer::new( :size_t )
|
68
69
|
error = OpenCL.clGetDeviceInfo( self, EXTENSIONS, 0, nil, extensions_size)
|
69
70
|
error_check(error)
|
70
|
-
ext =
|
71
|
+
ext = MemoryPointer::new( extensions_size.read_size_t )
|
71
72
|
error = OpenCL.clGetDeviceInfo( self, EXTENSIONS, extensions_size.read_size_t, ext, nil)
|
72
73
|
error_check(error)
|
73
74
|
ext_string = ext.read_string
|
@@ -76,10 +77,10 @@ module OpenCL
|
|
76
77
|
|
77
78
|
# Returns an Array of String corresponding to the Device built in kernel names
|
78
79
|
def built_in_kernels
|
79
|
-
built_in_kernels_size =
|
80
|
+
built_in_kernels_size = MemoryPointer::new( :size_t )
|
80
81
|
error = OpenCL.clGetDeviceInfo( self, BUILT_IN_KERNELS, 0, nil, built_in_kernels_size)
|
81
82
|
error_check(error)
|
82
|
-
ker =
|
83
|
+
ker = MemoryPointer::new( built_in_kernels_size.read_size_t )
|
83
84
|
error = OpenCL.clGetDeviceInfo( self, BUILT_IN_KERNELS, built_in_kernels_size.read_size_t, ker, nil)
|
84
85
|
error_check(error)
|
85
86
|
ker_string = ker.read_string
|
@@ -88,10 +89,10 @@ module OpenCL
|
|
88
89
|
|
89
90
|
# Return an Array of String corresponding to the SPIR versions supported by the device
|
90
91
|
def spir_versions
|
91
|
-
spir_versions_size =
|
92
|
+
spir_versions_size = MemoryPointer::new( :size_t )
|
92
93
|
error = OpenCL.clGetDeviceInfo( self, SPIR_VERSIONS, 0, nil, spir_versions_size)
|
93
94
|
error_check(error)
|
94
|
-
vers =
|
95
|
+
vers = MemoryPointer::new( spir_versions_size.read_size_t )
|
95
96
|
error = OpenCL.clGetDeviceInfo( self, SPIR_VERSIONS, spir_versions_size.read_size_t, vers, nil)
|
96
97
|
error_check(error)
|
97
98
|
vers_string = vers.read_string
|
@@ -194,13 +195,13 @@ module OpenCL
|
|
194
195
|
# :method: partition_properties()
|
195
196
|
# Returns the list of partition types supported by the Device
|
196
197
|
def partition_properties
|
197
|
-
ptr1 =
|
198
|
+
ptr1 = MemoryPointer::new( :size_t, 1)
|
198
199
|
error = OpenCL.clGetDeviceInfo(self, PARTITION_PROPERTIES, 0, nil, ptr1)
|
199
200
|
error_check(error)
|
200
|
-
ptr2 =
|
201
|
+
ptr2 = MemoryPointer::new( ptr1.read_size_t )
|
201
202
|
error = OpenCL.clGetDeviceInfo(self, PARTITION_PROPERTIES, ptr1.read_size_t, ptr2, nil)
|
202
203
|
error_check(error)
|
203
|
-
arr = ptr2.get_array_of_cl_device_partition_property(0, ptr1.read_size_t/
|
204
|
+
arr = ptr2.get_array_of_cl_device_partition_property(0, ptr1.read_size_t/ OpenCL.find_type(:cl_device_partition_property).size)
|
204
205
|
arr.reject! { |e| e.null? }
|
205
206
|
return arr.collect { |e| Partition::new(e.to_i) }
|
206
207
|
end
|
@@ -219,19 +220,19 @@ module OpenCL
|
|
219
220
|
# :method: partition_type()
|
220
221
|
# Returns a list of :cl_device_partition_property used to create the Device
|
221
222
|
def partition_type
|
222
|
-
ptr1 =
|
223
|
+
ptr1 = MemoryPointer::new( :size_t, 1)
|
223
224
|
error = OpenCL.clGetDeviceInfo(self, PARTITION_TYPE, 0, nil, ptr1)
|
224
225
|
error_check(error)
|
225
|
-
ptr2 =
|
226
|
+
ptr2 = MemoryPointer::new( ptr1.read_size_t )
|
226
227
|
error = OpenCL.clGetDeviceInfo(self, PARTITION_TYPE, ptr1.read_size_t, ptr2, nil)
|
227
228
|
error_check(error)
|
228
|
-
arr = ptr2.get_array_of_cl_device_partition_property(0, ptr1.read_size_t/
|
229
|
+
arr = ptr2.get_array_of_cl_device_partition_property(0, ptr1.read_size_t/ OpenCL.find_type(:cl_device_partition_property).size)
|
229
230
|
if arr.first.to_i == Partition::BY_NAMES_EXT then
|
230
231
|
arr_2 = []
|
231
232
|
arr_2.push(Partition::new(arr.first.to_i))
|
232
233
|
i = 1
|
233
234
|
return arr_2 if arr.length <= i
|
234
|
-
while arr[i].to_i - (0x1 <<
|
235
|
+
while arr[i].to_i - (0x1 << Pointer.size * 8) != Partition::BY_NAMES_LIST_END_EXT do
|
235
236
|
arr_2[i] = arr[i].to_i
|
236
237
|
i += 1
|
237
238
|
return arr_2 if arr.length <= i
|
@@ -247,7 +248,7 @@ module OpenCL
|
|
247
248
|
|
248
249
|
# Returns the Platform the Device belongs to
|
249
250
|
def platform
|
250
|
-
ptr =
|
251
|
+
ptr = MemoryPointer::new( OpenCL::Platform )
|
251
252
|
error = OpenCL.clGetDeviceInfo(self, PLATFORM, OpenCL::Platform.size, ptr, nil)
|
252
253
|
error_check(error)
|
253
254
|
return OpenCL::Platform::new(ptr.read_pointer)
|
@@ -255,7 +256,7 @@ module OpenCL
|
|
255
256
|
|
256
257
|
# Returns the parent Device if it exists
|
257
258
|
def parent_device
|
258
|
-
ptr =
|
259
|
+
ptr = MemoryPointer::new( Device )
|
259
260
|
error = OpenCL.clGetDeviceInfo(self, PARENT_DEVICE, Device.size, ptr, nil)
|
260
261
|
error_check(error)
|
261
262
|
return nil if ptr.null?
|
@@ -1,3 +1,4 @@
|
|
1
|
+
using OpenCLRefinements if RUBY_VERSION.scan(/\d+/).collect(&:to_i).first >= 2
|
1
2
|
module OpenCL
|
2
3
|
|
3
4
|
# Waits for the command identified by Event objects to complete
|
@@ -19,7 +20,7 @@ module OpenCL
|
|
19
20
|
# * +event+ - the Event to attach the callback to
|
20
21
|
# * +command_exec_callback_type+ - a CommandExecutionStatus
|
21
22
|
# * +options+ - a hash containing named options
|
22
|
-
# * +block+ - a callback invoked when the given event occurs. Signature of the callback is { |Event, :cl_int event_command_exec_status,
|
23
|
+
# * +block+ - a callback invoked when the given event occurs. Signature of the callback is { |Event, :cl_int event_command_exec_status, Pointer to user_data| ... }
|
23
24
|
#
|
24
25
|
# ==== Options
|
25
26
|
#
|
@@ -38,7 +39,7 @@ module OpenCL
|
|
38
39
|
# * +context+ - Context the created Event will be associated to
|
39
40
|
def self.create_user_event(context)
|
40
41
|
error_check(INVALID_OPERATION) if context.platform.version_number < 1.1
|
41
|
-
error =
|
42
|
+
error = MemoryPointer::new(:cl_int)
|
42
43
|
event = clCreateUserEvent(context, error)
|
43
44
|
error_check(error.read_cl_int)
|
44
45
|
return Event::new(event, false)
|
@@ -59,7 +60,7 @@ module OpenCL
|
|
59
60
|
# # * +context+ - Context the created Event will be associated to
|
60
61
|
# # * +sync+ - a :GLsync representing the name of the sync object
|
61
62
|
# def self.create_event_from_gl_sync_khr( context, sync )
|
62
|
-
# error =
|
63
|
+
# error = MemoryPointer::new(:cl_int)
|
63
64
|
# event = clCreateEventFromGLsyncKHR(context, sync, error)
|
64
65
|
# error_check(error.read_cl_int)
|
65
66
|
# return Event::new(event, false)
|
@@ -79,7 +80,7 @@ module OpenCL
|
|
79
80
|
|
80
81
|
# Returns the CommandQueue associated with the Event, if it exists
|
81
82
|
def command_queue
|
82
|
-
ptr =
|
83
|
+
ptr = MemoryPointer::new( CommandQueue )
|
83
84
|
error = OpenCL.clGetEventInfo(self, COMMAND_QUEUE, CommandQueue.size, ptr, nil)
|
84
85
|
error_check(error)
|
85
86
|
pt = ptr.read_pointer
|
@@ -92,7 +93,7 @@ module OpenCL
|
|
92
93
|
|
93
94
|
# Returns the Context associated with the Event
|
94
95
|
def context
|
95
|
-
ptr =
|
96
|
+
ptr = MemoryPointer::new( Context )
|
96
97
|
error = OpenCL.clGetEventInfo(self, CONTEXT, Context.size, ptr, nil)
|
97
98
|
error_check(error)
|
98
99
|
return Context::new( ptr.read_pointer )
|
@@ -103,7 +104,7 @@ module OpenCL
|
|
103
104
|
|
104
105
|
# Returns a CommandExecutionStatus corresponding to the status of the command associtated with the Event
|
105
106
|
def command_execution_status
|
106
|
-
ptr =
|
107
|
+
ptr = MemoryPointer::new( :cl_int )
|
107
108
|
error = OpenCL.clGetEventInfo(self, COMMAND_EXECUTION_STATUS, ptr.size, ptr, nil )
|
108
109
|
error_check(error)
|
109
110
|
return CommandExecutionStatus::new( ptr.read_cl_int )
|
@@ -116,7 +117,7 @@ module OpenCL
|
|
116
117
|
|
117
118
|
# Returns the date the command corresponding to Event was queued
|
118
119
|
def profiling_command_queued
|
119
|
-
ptr =
|
120
|
+
ptr = MemoryPointer::new( :cl_ulong )
|
120
121
|
error = OpenCL.clGetEventProfilingInfo(self, PROFILING_COMMAND_QUEUED, ptr.size, ptr, nil )
|
121
122
|
error_check(error)
|
122
123
|
return ptr.read_cl_ulong
|
@@ -124,7 +125,7 @@ module OpenCL
|
|
124
125
|
|
125
126
|
# Returns the date the command corresponding to Event was submited
|
126
127
|
def profiling_command_submit
|
127
|
-
ptr =
|
128
|
+
ptr = MemoryPointer::new( :cl_ulong )
|
128
129
|
error = OpenCL.clGetEventProfilingInfo(self, PROFILING_COMMAND_SUBMIT, ptr.size, ptr, nil )
|
129
130
|
error_check(error)
|
130
131
|
return ptr.read_cl_ulong
|
@@ -132,7 +133,7 @@ module OpenCL
|
|
132
133
|
|
133
134
|
# Returns the date the command corresponding to Event started
|
134
135
|
def profiling_command_start
|
135
|
-
ptr =
|
136
|
+
ptr = MemoryPointer::new( :cl_ulong )
|
136
137
|
error = OpenCL.clGetEventProfilingInfo(self, PROFILING_COMMAND_START, ptr.size, ptr, nil )
|
137
138
|
error_check(error)
|
138
139
|
return ptr.read_cl_ulong
|
@@ -140,7 +141,7 @@ module OpenCL
|
|
140
141
|
|
141
142
|
# Returns the date the command corresponding to Event ended
|
142
143
|
def profiling_command_end
|
143
|
-
ptr =
|
144
|
+
ptr = MemoryPointer::new( :cl_ulong )
|
144
145
|
error = OpenCL.clGetEventProfilingInfo(self, PROFILING_COMMAND_END, ptr.size, ptr, nil )
|
145
146
|
error_check(error)
|
146
147
|
return ptr.read_cl_ulong
|
@@ -159,7 +160,7 @@ module OpenCL
|
|
159
160
|
#
|
160
161
|
# * +command_exec_callback_type+ - a CommandExecutionStatus
|
161
162
|
# * +options+ - a hash containing named options
|
162
|
-
# * +block+ - a callback invoked when the given Event occurs. Signature of the callback is { |Event, :cl_int event_command_exec_status,
|
163
|
+
# * +block+ - a callback invoked when the given Event occurs. Signature of the callback is { |Event, :cl_int event_command_exec_status, Pointer to user_data| ... }
|
163
164
|
#
|
164
165
|
# ==== Options
|
165
166
|
#
|
@@ -1,25 +1,26 @@
|
|
1
1
|
require 'opencl_ruby_ffi'
|
2
|
+
using OpenCLRefinements if RUBY_VERSION.scan(/\d+/).collect(&:to_i).first >= 2
|
2
3
|
|
3
4
|
module OpenCL
|
4
5
|
|
5
|
-
name_p =
|
6
|
+
name_p = MemoryPointer.from_string("clGetGLContextInfoKHR")
|
6
7
|
p = clGetExtensionFunctionAddress(name_p)
|
7
8
|
if p then
|
8
|
-
func =
|
9
|
+
func = Function::new( :cl_int, [:pointer, :cl_gl_context_info, :size_t, :pointer, :pointer], p)
|
9
10
|
func.attach(OpenCL, "clGetGLContextInfoKHR")
|
10
11
|
|
11
12
|
def self.get_gl_context_info_khr( properties, param_name )
|
12
|
-
props =
|
13
|
+
props = MemoryPointer::new( :cl_context_properties, properties.length + 1 )
|
13
14
|
properties.each_with_index { |e,i|
|
14
15
|
props[i].write_cl_context_properties(e)
|
15
16
|
}
|
16
17
|
props[properties.length].write_cl_context_properties(0)
|
17
|
-
size_p =
|
18
|
+
size_p = MemoryPointer::new( :size_t )
|
18
19
|
error = clGetGLContextInfoKHR( props, param_name, 0, nil, size_p )
|
19
20
|
error_check(error)
|
20
21
|
size = size_p.read_size_t
|
21
22
|
nb_devices = size/Device.size
|
22
|
-
values =
|
23
|
+
values = MemoryPointer::new( Device, nb_devices )
|
23
24
|
error = clGetGLContextInfoKHR( props, param_name, size, values, nil )
|
24
25
|
error_check(error)
|
25
26
|
return values.get_array_of_pointer(0, nb_devices).collect { |device_ptr|
|
@@ -28,15 +29,15 @@ module OpenCL
|
|
28
29
|
end
|
29
30
|
end
|
30
31
|
|
31
|
-
name_p =
|
32
|
+
name_p = MemoryPointer.from_string("clCreateEventFromGLsyncKHR")
|
32
33
|
p = clGetExtensionFunctionAddress(name_p)
|
33
34
|
if p then
|
34
|
-
func =
|
35
|
+
func = Function::new( Event, [Context, :pointer, :pointer], p)
|
35
36
|
func.attach(OpenCL, "clCreateEventFromGLsyncKHR")
|
36
37
|
|
37
38
|
def self.create_event_from_glsync_khr( context, sync)
|
38
39
|
error_check(INVALID_OPERATION) if context.platform.version_number < 1.1
|
39
|
-
error_p =
|
40
|
+
error_p = MemoryPointer::new( :cl_int )
|
40
41
|
event = clCreateEventFromGLsyncKHR( context, sync, error_p )
|
41
42
|
error_check(error_p.read_cl_int)
|
42
43
|
return Event::new( event, false )
|
@@ -1,3 +1,4 @@
|
|
1
|
+
using OpenCLRefinements if RUBY_VERSION.scan(/\d+/).collect(&:to_i).first >= 2
|
1
2
|
module OpenCL
|
2
3
|
|
3
4
|
# Creates an Image
|
@@ -15,7 +16,7 @@ module OpenCL
|
|
15
16
|
def self.create_image( context, format, desc, options = {} )
|
16
17
|
flags = get_flags( options )
|
17
18
|
host_ptr = options[:host_ptr]
|
18
|
-
error =
|
19
|
+
error = MemoryPointer::new( :cl_int )
|
19
20
|
img_ptr = clCreateImage( context, flags, format, desc, host_ptr, error )
|
20
21
|
error_check(error.read_cl_int)
|
21
22
|
return Image::new(img_ptr, false)
|
@@ -67,7 +68,7 @@ module OpenCL
|
|
67
68
|
end
|
68
69
|
flags = get_flags( options )
|
69
70
|
host_ptr = options[:host_ptr]
|
70
|
-
error =
|
71
|
+
error = MemoryPointer::new( :cl_int )
|
71
72
|
img_ptr = clCreateImage2D( context, flags, format, width, height, row_pitch, host_ptr, error )
|
72
73
|
error_check(error.read_cl_int)
|
73
74
|
return Image::new(img_ptr, false)
|
@@ -101,7 +102,7 @@ module OpenCL
|
|
101
102
|
end
|
102
103
|
flags = get_flags( options )
|
103
104
|
host_ptr = options[:host_ptr]
|
104
|
-
error =
|
105
|
+
error = MemoryPointer::new( :cl_int )
|
105
106
|
img_ptr = clCreateImage3D( context, fs, format, width, height, depth, row_pitch, slice_pitch, d, error )
|
106
107
|
error_check(error.read_cl_int)
|
107
108
|
return Image::new(img_ptr, false)
|
@@ -123,7 +124,7 @@ module OpenCL
|
|
123
124
|
# * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Image
|
124
125
|
def self.create_from_gl_render_buffer( context, renderbuffer, options = {} )
|
125
126
|
flags = get_flags( options )
|
126
|
-
error =
|
127
|
+
error = MemoryPointer::new( :cl_int )
|
127
128
|
img = clCreateFromGLRenderBuffer( context, flags, renderbuffer, error )
|
128
129
|
error_check(error.read_cl_int)
|
129
130
|
return Image::new( img, false )
|
@@ -152,7 +153,7 @@ module OpenCL
|
|
152
153
|
flags = get_flags( options )
|
153
154
|
miplevel = 0
|
154
155
|
miplevel = options[:miplevel] if options[:miplevel]
|
155
|
-
error =
|
156
|
+
error = MemoryPointer::new( :cl_int )
|
156
157
|
img = clCreateFromGLTexture( context, flags, texture_target, miplevel, texture, error )
|
157
158
|
error_check(error.read_cl_int)
|
158
159
|
return Image::new( img, false )
|
@@ -180,7 +181,7 @@ module OpenCL
|
|
180
181
|
flags = get_flags( options )
|
181
182
|
miplevel = 0
|
182
183
|
miplevel = options[:miplevel] if options[:miplevel]
|
183
|
-
error =
|
184
|
+
error = MemoryPointer::new( :cl_int )
|
184
185
|
img = clCreateFromGLTexture2D( context, flags, texture_target, miplevel, texture, error )
|
185
186
|
error_check(error.read_cl_int)
|
186
187
|
return Image::new( img, false )
|
@@ -208,7 +209,7 @@ module OpenCL
|
|
208
209
|
flags = get_flags( options )
|
209
210
|
miplevel = 0
|
210
211
|
miplevel = options[:miplevel] if options[:miplevel]
|
211
|
-
error =
|
212
|
+
error = MemoryPointer::new( :cl_int )
|
212
213
|
img = clCreateFromGLTexture3D( context, flags, texture_target, miplevel, texture, error )
|
213
214
|
error_check(error.read_cl_int)
|
214
215
|
return Image::new( img, false )
|
@@ -276,15 +277,15 @@ module OpenCL
|
|
276
277
|
|
277
278
|
# Returns the ImageFormat corresponding to the image
|
278
279
|
def format
|
279
|
-
image_format =
|
280
|
+
image_format = MemoryPointer::new( ImageFormat )
|
280
281
|
error = OpenCL.clGetImageInfo( self, FORMAT, image_format.size, image_format, nil)
|
281
282
|
error_check(error)
|
282
|
-
return ImageFormat::
|
283
|
+
return ImageFormat::new( image_format )
|
283
284
|
end
|
284
285
|
|
285
286
|
# Returns the associated Buffer if any, nil otherwise
|
286
287
|
def buffer
|
287
|
-
ptr =
|
288
|
+
ptr = MemoryPointer::new( Buffer )
|
288
289
|
error = OpenCL.clGetImageInfo(self, BUFFER, Buffer.size, ptr, nil)
|
289
290
|
error_check(error)
|
290
291
|
return nil if ptr.null?
|
@@ -1,12 +1,13 @@
|
|
1
|
+
using OpenCLRefinements if RUBY_VERSION.scan(/\d+/).collect(&:to_i).first >= 2
|
1
2
|
module OpenCL
|
2
3
|
|
3
4
|
# Creates an Array of Kernel corresponding to the kernels defined inside the Program
|
4
5
|
def self.create_kernels_in_program( program )
|
5
|
-
num_ptr =
|
6
|
+
num_ptr = MemoryPointer::new( :cl_uint )
|
6
7
|
error = clCreateKernelsInProgram( program, 0, nil, num_ptr )
|
7
8
|
error_check(error)
|
8
9
|
num_kernels = num_ptr.read_cl_uint
|
9
|
-
kernels_ptr =
|
10
|
+
kernels_ptr = MemoryPointer::new( Kernel, num_kernels )
|
10
11
|
error = clCreateKernelsInProgram( program, num_kernels, kernels_ptr, nil )
|
11
12
|
error_check(error)
|
12
13
|
return kernels_ptr.get_array_of_pointer(0, num_kernels).collect { |kernel_ptr|
|
@@ -16,7 +17,7 @@ module OpenCL
|
|
16
17
|
|
17
18
|
# Returns the Kernel corresponding the the specified name in the given Program
|
18
19
|
def self.create_kernel(program, name)
|
19
|
-
error =
|
20
|
+
error = MemoryPointer::new( :cl_int )
|
20
21
|
kernel_ptr = clCreateKernel(program, name, error)
|
21
22
|
error_check(error.read_cl_int)
|
22
23
|
return Kernel::new( kernel_ptr, false )
|
@@ -28,7 +29,7 @@ module OpenCL
|
|
28
29
|
sz = value.class.size if sz == nil
|
29
30
|
val = value
|
30
31
|
if value.kind_of?(Mem) then
|
31
|
-
val =
|
32
|
+
val = MemoryPointer::new( Mem )
|
32
33
|
val.write_pointer(value.to_ptr)
|
33
34
|
end
|
34
35
|
error = clSetKernelArg( kernel, index, sz, val )
|
@@ -37,7 +38,7 @@ module OpenCL
|
|
37
38
|
|
38
39
|
def self.clone_kernel( kernel )
|
39
40
|
error_check(INVALID_OPERATION) if kernel.context.platform.version_number < 2.1
|
40
|
-
error =
|
41
|
+
error = MemoryPointer::new( :cl_int )
|
41
42
|
kernel_ptr = clCloneKernel( kernel, error )
|
42
43
|
error_check(error.read_cl_int)
|
43
44
|
return Kernel::new( kernel_ptr, false )
|
@@ -76,7 +77,7 @@ module OpenCL
|
|
76
77
|
# Returns an AddressQualifier corresponding to the Arg
|
77
78
|
def address_qualifier
|
78
79
|
error_check(INVALID_OPERATION) if @kernel.context.platform.version_number < 1.2
|
79
|
-
ptr =
|
80
|
+
ptr = MemoryPointer::new( :cl_kernel_arg_address_qualifier )
|
80
81
|
error = OpenCL.clGetKernelArgInfo(@kernel, @index, ADDRESS_QUALIFIER, ptr.size, ptr, nil)
|
81
82
|
error_check(error)
|
82
83
|
return AddressQualifier::new( ptr.read_cl_kernel_arg_address_qualifier )
|
@@ -85,7 +86,7 @@ module OpenCL
|
|
85
86
|
# Returns an AccessQualifier corresponding to the Arg
|
86
87
|
def access_qualifier
|
87
88
|
error_check(INVALID_OPERATION) if @kernel.context.platform.version_number < 1.2
|
88
|
-
ptr =
|
89
|
+
ptr = MemoryPointer::new( :cl_kernel_arg_access_qualifier )
|
89
90
|
error = OpenCL.clGetKernelArgInfo(@kernel, @index, ACCESS_QUALIFIER, ptr.size, ptr, nil)
|
90
91
|
error_check(error)
|
91
92
|
return AccessQualifier::new( ptr.read_cl_kernel_arg_access_qualifier )
|
@@ -94,7 +95,7 @@ module OpenCL
|
|
94
95
|
# Returns a TypeQualifier corresponding to the Arg
|
95
96
|
def type_qualifier
|
96
97
|
error_check(INVALID_OPERATION) if @kernel.context.platform.version_number < 1.2
|
97
|
-
ptr =
|
98
|
+
ptr = MemoryPointer::new( :cl_kernel_arg_type_qualifier )
|
98
99
|
error = OpenCL.clGetKernelArgInfo(@kernel, @index, TYPE_QUALIFIER, ptr.size, ptr, nil)
|
99
100
|
error_check(error)
|
100
101
|
return TypeQualifier::new( ptr.read_cl_kernel_arg_type_qualifier )
|
@@ -103,10 +104,10 @@ module OpenCL
|
|
103
104
|
# Returns a String corresponding to the Arg type name
|
104
105
|
def type_name
|
105
106
|
error_check(INVALID_OPERATION) if @kernel.context.platform.version_number < 1.2
|
106
|
-
ptr1 =
|
107
|
+
ptr1 = MemoryPointer::new( :size_t, 1)
|
107
108
|
error = OpenCL.clGetKernelArgInfo(@kernel, @index, TYPE_NAME, 0, nil, ptr1)
|
108
109
|
error_check(error)
|
109
|
-
ptr2 =
|
110
|
+
ptr2 = MemoryPointer::new( ptr1.read_size_t )
|
110
111
|
error = OpenCL.clGetKernelArgInfo(@kernel, @index, TYPE_NAME, ptr1.read_size_t, ptr2, nil)
|
111
112
|
error_check(error)
|
112
113
|
return ptr2.read_string
|
@@ -115,10 +116,10 @@ module OpenCL
|
|
115
116
|
# Returns a String corresponding to the Arg name
|
116
117
|
def name
|
117
118
|
error_check(INVALID_OPERATION) if @kernel.context.platform.version_number < 1.2
|
118
|
-
ptr1 =
|
119
|
+
ptr1 = MemoryPointer::new( :size_t, 1)
|
119
120
|
error = OpenCL.clGetKernelArgInfo(@kernel, @index, NAME, 0, nil, ptr1)
|
120
121
|
error_check(error)
|
121
|
-
ptr2 =
|
122
|
+
ptr2 = MemoryPointer::new( ptr1.read_size_t )
|
122
123
|
error = OpenCL.clGetKernelArgInfo(@kernel, @index, NAME, ptr1.read_size_t, ptr2, nil)
|
123
124
|
error_check(error)
|
124
125
|
return ptr2.read_string
|
@@ -149,7 +150,7 @@ module OpenCL
|
|
149
150
|
def set_svm_ptrs( ptrs )
|
150
151
|
error_check(INVALID_OPERATION) if self.context.platform.version_number < 2.0
|
151
152
|
pointers = [ptrs].flatten
|
152
|
-
pt =
|
153
|
+
pt = MemoryPointer::new( :pointer, pointers.length )
|
153
154
|
pointers.each_with_index { |p, i|
|
154
155
|
pt[i].write_pointer(p)
|
155
156
|
}
|
@@ -161,7 +162,7 @@ module OpenCL
|
|
161
162
|
# Specifies the granularity of the SVM system.
|
162
163
|
def set_svm_fine_grain_system( flag )
|
163
164
|
error_check(INVALID_OPERATION) if self.context.platform.version_number < 2.0
|
164
|
-
pt =
|
165
|
+
pt = MemoryPointer::new( :cl_bool )
|
165
166
|
pt.write_cl_bool( flag )
|
166
167
|
error = OpenCL.clSetKernelExecInfo( self, EXEC_INFO_SVM_FINE_GRAIN_SYSTEM, pt.size, pt)
|
167
168
|
error_check(error)
|
@@ -194,7 +195,7 @@ module OpenCL
|
|
194
195
|
|
195
196
|
# Returns the Context the Kernel is associated with
|
196
197
|
def context
|
197
|
-
ptr =
|
198
|
+
ptr = MemoryPointer::new( Context )
|
198
199
|
error = OpenCL.clGetKernelInfo(self, CONTEXT, Context.size, ptr, nil)
|
199
200
|
error_check(error)
|
200
201
|
return Context::new( ptr.read_pointer )
|
@@ -202,49 +203,49 @@ module OpenCL
|
|
202
203
|
|
203
204
|
# Returns the Program the Kernel was created from
|
204
205
|
def program
|
205
|
-
ptr =
|
206
|
+
ptr = MemoryPointer::new( Program )
|
206
207
|
error = OpenCL.clGetKernelInfo(self, PROGRAM, Program.size, ptr, nil)
|
207
208
|
error_check(error)
|
208
209
|
return Program::new(ptr.read_pointer)
|
209
210
|
end
|
210
211
|
|
211
212
|
def work_group_size(device = program.devices.first)
|
212
|
-
ptr =
|
213
|
+
ptr = MemoryPointer::new( :size_t )
|
213
214
|
error = OpenCL.clGetKernelWorkGroupInfo(self, device, WORK_GROUP_SIZE, ptr.size, ptr, nil)
|
214
215
|
error_check(error)
|
215
216
|
return ptr.read_size_t
|
216
217
|
end
|
217
218
|
|
218
219
|
def compile_work_group_size(device = program.devices.first)
|
219
|
-
ptr =
|
220
|
+
ptr = MemoryPointer::new( :size_t, 3 )
|
220
221
|
error = OpenCL.clGetKernelWorkGroupInfo(self, device, COMPILE_WORK_GROUP_SIZE, ptr.size, ptr, nil)
|
221
222
|
error_check(error)
|
222
223
|
return ptr.get_array_of_size_t(0,3)
|
223
224
|
end
|
224
225
|
|
225
226
|
def local_mem_size(device = program.devices.first)
|
226
|
-
ptr =
|
227
|
+
ptr = MemoryPointer::new( :cl_ulong )
|
227
228
|
error = OpenCL.clGetKernelWorkGroupInfo(self, device, LOCAL_MEM_SIZE, ptr.size, ptr, nil)
|
228
229
|
error_check(error)
|
229
230
|
return ptr.read_cl_ulong
|
230
231
|
end
|
231
232
|
|
232
233
|
def preferred_work_group_size_multiple(device = program.devices.first)
|
233
|
-
ptr =
|
234
|
+
ptr = MemoryPointer::new( :size_t )
|
234
235
|
error = OpenCL.clGetKernelWorkGroupInfo(self, device, PREFERRED_WORK_GROUP_SIZE_MULTIPLE, ptr.size, ptr, nil)
|
235
236
|
error_check(error)
|
236
237
|
return ptr.read_size_t
|
237
238
|
end
|
238
239
|
|
239
240
|
def private_mem_size(device = program.devices.first)
|
240
|
-
ptr =
|
241
|
+
ptr = MemoryPointer::new( :cl_ulong )
|
241
242
|
error = OpenCL.clGetKernelWorkGroupInfo(self, device, PRIVATE_MEM_SIZE, ptr.size, ptr, nil)
|
242
243
|
error_check(error)
|
243
244
|
return ptr.read_cl_ulong
|
244
245
|
end
|
245
246
|
|
246
247
|
def global_work_size(device = program.devices.first)
|
247
|
-
ptr =
|
248
|
+
ptr = MemoryPointer::new( :size_t, 3 )
|
248
249
|
error = OpenCL.clGetKernelWorkGroupInfo(self, device, GLOBAL_WORK_SIZE, ptr.size, ptr, nil)
|
249
250
|
error_check(error)
|
250
251
|
return ptr.get_array_of_size_t(0,3)
|
@@ -252,7 +253,7 @@ module OpenCL
|
|
252
253
|
|
253
254
|
def max_num_sub_groups(device = program.devices.first)
|
254
255
|
error_check(INVALID_OPERATION) if self.context.platform.version_number < 2.1
|
255
|
-
ptr =
|
256
|
+
ptr = MemoryPointer::new( :size_t )
|
256
257
|
error = OpenCL.clGetKernelSubGroupInfo(self, device, MAX_NUM_SUB_GROUPS, 0, nil, ptr.size, ptr, nil)
|
257
258
|
error_check(error)
|
258
259
|
return ptr.read_size_t
|
@@ -260,7 +261,7 @@ module OpenCL
|
|
260
261
|
|
261
262
|
def compile_num_sub_groups(device = program.devices.first)
|
262
263
|
error_check(INVALID_OPERATION) if self.context.platform.version_number < 2.1
|
263
|
-
ptr =
|
264
|
+
ptr = MemoryPointer::new( :size_t )
|
264
265
|
error = OpenCL.clGetKernelSubGroupInfo(self, device, COMPILE_NUM_SUB_GROUPS, 0, nil, ptr.size, ptr, nil)
|
265
266
|
error_check(error)
|
266
267
|
return ptr.read_size_t
|
@@ -269,11 +270,11 @@ module OpenCL
|
|
269
270
|
def max_sub_group_size_for_ndrange(local_work_size, device = program.devices.first)
|
270
271
|
error_check(INVALID_OPERATION) if self.context.platform.version_number < 2.1
|
271
272
|
local_work_size = [local_work_size].flatten
|
272
|
-
lws_p =
|
273
|
+
lws_p = MemoryPointer::new( :size_t, local_work_size.length )
|
273
274
|
local_work_size.each_with_index { |e,i|
|
274
275
|
lws_p[i].write_size_t( e )
|
275
276
|
}
|
276
|
-
ptr =
|
277
|
+
ptr = MemoryPointer::new( :size_t )
|
277
278
|
error = OpenCL.clGetKernelSubGroupInfo(self, device, MAX_SUB_GROUP_SIZE_FOR_NDRANGE, lws_p.size, lws_p, ptr.size, ptr, nil)
|
278
279
|
error_check(error)
|
279
280
|
return ptr.read_size_t
|
@@ -282,11 +283,11 @@ module OpenCL
|
|
282
283
|
def sub_groups_count_for_ndrange(local_work_size, device = program.devices.first)
|
283
284
|
error_check(INVALID_OPERATION) if self.context.platform.version_number < 2.1
|
284
285
|
local_work_size = [local_work_size].flatten
|
285
|
-
lws_p =
|
286
|
+
lws_p = MemoryPointer::new( :size_t, local_work_size.length )
|
286
287
|
local_work_size.each_with_index { |e,i|
|
287
288
|
lws_p[i].write_size_t( e )
|
288
289
|
}
|
289
|
-
ptr =
|
290
|
+
ptr = MemoryPointer::new( :size_t )
|
290
291
|
error = OpenCL.clGetKernelSubGroupInfo(self, device, SUB_GROUP_COUNT_FOR_NDRANGE, lws_p.size, lws_p, ptr.size, ptr, nil)
|
291
292
|
error_check(error)
|
292
293
|
return ptr.read_size_t
|
@@ -294,12 +295,12 @@ module OpenCL
|
|
294
295
|
|
295
296
|
def local_size_for_sub_group_count(sub_group_number, device = program.devices.first)
|
296
297
|
error_check(INVALID_OPERATION) if self.context.platform.version_number < 2.1
|
297
|
-
sgp_p =
|
298
|
+
sgp_p = MemoryPointer::new( :size_t )
|
298
299
|
sgp_p.write_size_t(sub_group_number)
|
299
|
-
size_ptr =
|
300
|
+
size_ptr = MemoryPointer::new( :size_t )
|
300
301
|
error = OpenCL.clGetKernelSubGroupInfo(self, device, LOCAL_SIZE_FOR_SUB_GROUP_COUNT, sgp_p.size, sgp_p, 0, nil, size_ptr)
|
301
302
|
error_check(error)
|
302
|
-
lws_p =
|
303
|
+
lws_p = MemoryPointer::new( size_ptr.read_size_t )
|
303
304
|
error = OpenCL.clGetKernelSubGroupInfo(self, device, LOCAL_SIZE_FOR_SUB_GROUP_COUNT, sgp_p.size, sgp_p, lws_p.size, lws_p, nil)
|
304
305
|
error_check(error)
|
305
306
|
return lws_p.get_array_of_size_t(0, lws_p.size/size_ptr.size)
|