opencl_ruby_ffi 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +22 -0
- data/lib/opencl_ruby_ffi.rb +18 -0
- data/lib/opencl_ruby_ffi/Arithmetic_gen.rb +3566 -0
- data/lib/opencl_ruby_ffi/Buffer.rb +84 -0
- data/lib/opencl_ruby_ffi/CommandQueue.rb +1544 -0
- data/lib/opencl_ruby_ffi/Context.rb +326 -0
- data/lib/opencl_ruby_ffi/Device.rb +188 -0
- data/lib/opencl_ruby_ffi/Event.rb +152 -0
- data/lib/opencl_ruby_ffi/Image.rb +270 -0
- data/lib/opencl_ruby_ffi/Kernel.rb +183 -0
- data/lib/opencl_ruby_ffi/Mem.rb +131 -0
- data/lib/opencl_ruby_ffi/Platform.rb +119 -0
- data/lib/opencl_ruby_ffi/Program.rb +245 -0
- data/lib/opencl_ruby_ffi/Sampler.rb +51 -0
- data/lib/opencl_ruby_ffi/opencl_ruby_ffi_base.rb +320 -0
- data/lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb +1826 -0
- data/opencl_ruby_ffi.gemspec +16 -0
- metadata +110 -0
@@ -0,0 +1,84 @@
|
|
1
|
+
module OpenCL
|
2
|
+
|
3
|
+
# Creates a Buffer
|
4
|
+
#
|
5
|
+
# ==== Attributes
|
6
|
+
#
|
7
|
+
# * +context+ - Context the created Buffer will be associated to
|
8
|
+
# * +size+ - size of the Buffer to be created
|
9
|
+
# * +options+ - a hash containing named options
|
10
|
+
#
|
11
|
+
# ==== Options
|
12
|
+
#
|
13
|
+
# * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Buffer
|
14
|
+
# * +:host_ptr+ - if provided, the Pointer (or convertible to Pointer using to_ptr) to the memory area to use
|
15
|
+
def self.create_buffer( context, size, options = {} )
|
16
|
+
flags = OpenCL.get_flags( options )
|
17
|
+
host_ptr = options[:host_ptr]
|
18
|
+
error = FFI::MemoryPointer.new( :cl_int )
|
19
|
+
buff = OpenCL.clCreateBuffer(context, flags, size, host_ptr, error)
|
20
|
+
OpenCL.error_check(error.read_cl_int)
|
21
|
+
return Buffer::new( buff, false )
|
22
|
+
end
|
23
|
+
|
24
|
+
# Creates a Buffer from a sub part of an existing Buffer
|
25
|
+
#
|
26
|
+
# ==== Attributes
|
27
|
+
#
|
28
|
+
# * +buffer+ - source Buffer
|
29
|
+
# * +type+ - type of sub-buffer to create. Only OpenCL::BUFFER_CREATE_TYPE_REGION is supported for now
|
30
|
+
# * +info+ - inf reguarding the type of sub-buffer created. if type == OpenCL::BUFFER_CREATE_TYPE_REGION, info is a BufferRegion
|
31
|
+
# * +options+ - a hash containing named options
|
32
|
+
#
|
33
|
+
# ==== Options
|
34
|
+
#
|
35
|
+
# * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Buffer
|
36
|
+
def self.create_sub_buffer( buffer, type, info, options = {} )
|
37
|
+
OpenCL.error_check(OpenCL::INVALID_OPERATION) if buffer.platform.version_number < 1.1
|
38
|
+
flags = OpenCL.get_flags( options )
|
39
|
+
error = FFI::MemoryPointer.new( :cl_int )
|
40
|
+
buff = OpenCL.clCreateSubBuffer( buffer, flags, type, info, error)
|
41
|
+
OpenCL.error_check(error.read_cl_int)
|
42
|
+
return Buffer::new( buff, false )
|
43
|
+
end
|
44
|
+
|
45
|
+
# Creates Buffer from an opengl buffer
|
46
|
+
#
|
47
|
+
# ==== Attributes
|
48
|
+
#
|
49
|
+
# * +context+ - Context the created Buffer will be associated to
|
50
|
+
# * +bufobj+ - opengl buffer object
|
51
|
+
# * +options+ - a hash containing named options
|
52
|
+
#
|
53
|
+
# ==== Options
|
54
|
+
#
|
55
|
+
# * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Image
|
56
|
+
def self.create_from_GL_buffer( context, bufobj, options = {} )
|
57
|
+
flags = OpenCL.get_flags( options )
|
58
|
+
error = FFI::MemoryPointer.new( :cl_int )
|
59
|
+
buff = OpenCL.clCreateFromGLBuffer( context, flags, bufobj, error )
|
60
|
+
OpenCL.error_check(error.read_cl_int)
|
61
|
+
return Buffer::new( buff, false )
|
62
|
+
end
|
63
|
+
|
64
|
+
# Maps the cl_mem OpenCL object of type CL_MEM_OBJECT_BUFFER
|
65
|
+
class Buffer < OpenCL::Mem
|
66
|
+
layout :dummy, :pointer
|
67
|
+
|
68
|
+
# Creates a Buffer from a sub part of the Buffer
|
69
|
+
#
|
70
|
+
# ==== Attributes
|
71
|
+
#
|
72
|
+
# * +info+ - inf reguarding the type of sub-buffer created. if type == OpenCL::BUFFER_CREATE_TYPE_REGION, info is a BufferRegion
|
73
|
+
# * +tyep+ - type of sub-buffer to create. Only OpenCL::BUFFER_CREATE_TYPE_REGION is supported for now
|
74
|
+
# * +options+ - a hash containing named options
|
75
|
+
#
|
76
|
+
# ==== Options
|
77
|
+
#
|
78
|
+
# * :flags - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Buffer
|
79
|
+
def create_sub_buffer( type, region, options = {} )
|
80
|
+
OpenCL.create_sub_buffer( self, type, region, options )
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
@@ -0,0 +1,1544 @@
|
|
1
|
+
module OpenCL
|
2
|
+
|
3
|
+
# Blocks until all the commands in the queue have completed
|
4
|
+
#
|
5
|
+
# ==== Attributes
|
6
|
+
#
|
7
|
+
# * +command_queue+ - the CommandQueue to finish
|
8
|
+
def self.finish( command_queue )
|
9
|
+
error = OpenCL.clFinish( command_queue )
|
10
|
+
OpenCL.error_check( error )
|
11
|
+
return command_queue
|
12
|
+
end
|
13
|
+
|
14
|
+
# Creates a CommandQueue targeting the specified Device
|
15
|
+
#
|
16
|
+
# ==== Attributes
|
17
|
+
#
|
18
|
+
# * +context+ - the Context the CommandQueue will be associated with
|
19
|
+
# * +device+ - the Device targetted by the CommandQueue being created
|
20
|
+
# * +options+ - a hash containing named options
|
21
|
+
#
|
22
|
+
# ==== Options
|
23
|
+
#
|
24
|
+
# * +:properties+ - a single or an Array of :cl_command_queue_properties
|
25
|
+
def self.create_command_queue( context, device, options = {} )
|
26
|
+
properties = OpenCL.get_command_queue_properties( options )
|
27
|
+
error = FFI::MemoryPointer.new( :cl_int )
|
28
|
+
cmd = OpenCL.clCreateCommandQueue( context, device, properties, error )
|
29
|
+
OpenCL.error_check(error.read_cl_int)
|
30
|
+
return CommandQueue::new(cmd, false)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Enqueues a command to indicate which device a set of memory objects should be migrated to
|
34
|
+
#
|
35
|
+
# ==== Attributes
|
36
|
+
#
|
37
|
+
# * +command_queue+ - objects will be migrated to the device associated with this CommandQueue
|
38
|
+
# * +mem_objects+ - the Mem objects to migrate
|
39
|
+
# * +options+ - a hash containing named options
|
40
|
+
#
|
41
|
+
# ==== Options
|
42
|
+
#
|
43
|
+
# * +:flags+ - a single or an Array of :cl_mem_migration flags
|
44
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
45
|
+
#
|
46
|
+
# ==== Returns
|
47
|
+
#
|
48
|
+
# the Event associated with the command
|
49
|
+
def self.enqueue_migrate_mem_objects( command_queue, mem_objects, options = {} )
|
50
|
+
OpenCL.error_check(OpenCL::INVALID_OPERATION) if command_queue.context.platform.version_number < 1.2
|
51
|
+
num_mem_objects = [mem_objects].flatten.length
|
52
|
+
mem_list = nil
|
53
|
+
if num_mem_objects > 0 then
|
54
|
+
mem_list = FFI::MemoryPointer.new( OpenCL::Mem, num_mem_objects )
|
55
|
+
[mem_objects].flatten.each_with_index { |e, i|
|
56
|
+
mem_list[i].write_pointer(e)
|
57
|
+
}
|
58
|
+
end
|
59
|
+
flags = OpenCL.get_flags( options )
|
60
|
+
num_events, events = OpenCL.get_event_wait_list( options )
|
61
|
+
event = FFI::MemoryPointer.new( Event )
|
62
|
+
error = OpenCL.clEnqueueMigrateMemObjects( command_queue, num_mem_objects, mem_list, flags, num_events, events, event )
|
63
|
+
OpenCL.error_check( error )
|
64
|
+
return OpenCL::Event::new( event.read_ptr )
|
65
|
+
end
|
66
|
+
|
67
|
+
# Enqueues a command to map an Image into host memory
|
68
|
+
#
|
69
|
+
# ==== Attributes
|
70
|
+
#
|
71
|
+
# * +command_queue+ - CommandQueue used to execute the map command
|
72
|
+
# * +image+ - the Image object to map
|
73
|
+
# * +map_flags+ - a single or an Array of :cl_map_flags flags
|
74
|
+
# * +options+ - a hash containing named options
|
75
|
+
#
|
76
|
+
# ==== Options
|
77
|
+
#
|
78
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
79
|
+
# * +:blocking_map+ - if provided indicates if the command blocks until the region is mapped
|
80
|
+
# * +:blocking+ - if provided indicates if the command blocks until the region is mapped
|
81
|
+
# * +:origin+ - if provided the origin in the Image of the region to map, else [0, 0, 0]
|
82
|
+
# * +:region+ - if provided the region in the image to map, else the largest possible area is used
|
83
|
+
#
|
84
|
+
# ==== Returns
|
85
|
+
#
|
86
|
+
# an Array composed of [event, pointer, image_row_pitch, image_slice_pitch] where:
|
87
|
+
# * +event+ - the Event associated with the command
|
88
|
+
# * +pointer+ - a Pointer to the mapped memory region
|
89
|
+
# * +image_row_pitch+ - the row pitch of the mapped region
|
90
|
+
# * +image_slice_pitch+ - the slice pitch of the mapped region
|
91
|
+
def self.enqueue_map_image( command_queue, image, map_flags, options = {} )
|
92
|
+
blocking = OpenCL::FALSE
|
93
|
+
blocking = OpenCL::TRUE if options[:blocking] or options[:blocking_map]
|
94
|
+
|
95
|
+
origin, region = OpenCL.get_origin_region( image, options, :origin, :region )
|
96
|
+
|
97
|
+
num_events, events = OpenCL.get_event_wait_list( options )
|
98
|
+
image_row_pitch = FFI::MemoryPointer.new( :size_t )
|
99
|
+
image_slice_pitch = FFI::MemoryPointer.new( :size_t )
|
100
|
+
event = FFI::MemoryPointer.new( Event )
|
101
|
+
error = FFI::MemoryPointer.new( :cl_int )
|
102
|
+
OpenCL.clEnqueueMapImage( command_queue, image, blocking, map_flags, origin, region, image_row_pitch, image_slice_pitch, num_events, events, event, error )
|
103
|
+
OpenCL.error_check( error.read_cl_int )
|
104
|
+
ev = OpenCL::Event::new( event.read_ptr )
|
105
|
+
return [ev, ptr, image_row_pitch.read_size_t, image_slice_pitch.read_size_t]
|
106
|
+
end
|
107
|
+
|
108
|
+
# Enqueues a command to map an Image into host memory
|
109
|
+
#
|
110
|
+
# ==== Attributes
|
111
|
+
#
|
112
|
+
# * +command_queue+ - CommandQueue used to execute the map command
|
113
|
+
# * +buffer+ - the Buffer object to map
|
114
|
+
# * +map_flags+ - a single or an Array of :cl_map_flags flags
|
115
|
+
# * +options+ - a hash containing named options
|
116
|
+
#
|
117
|
+
# ==== Options
|
118
|
+
#
|
119
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
120
|
+
# * +:blocking_map+ - if provided indicates if the command blocks until the region is mapped
|
121
|
+
# * +:blocking+ - if provided indicates if the command blocks until the region is mapped
|
122
|
+
# * +:offset+ - if provided the offset inside the Buffer region to map, else 0
|
123
|
+
# * +:size+ - if provided the size of the region in the Buffer to map, else the largest possible size is used
|
124
|
+
#
|
125
|
+
# ==== Returns
|
126
|
+
#
|
127
|
+
# an Array composed of [event, pointer] where:
|
128
|
+
# * +event+ - the Event associated with the command
|
129
|
+
# * +pointer+ - a Pointer to the mapped memory region
|
130
|
+
def self.enqueue_map_buffer( command_queue, buffer, map_flags, options = {} )
|
131
|
+
blocking = OpenCL::FALSE
|
132
|
+
blocking = OpenCL::TRUE if options[:blocking] or options[:blocking_map]
|
133
|
+
offset = 0
|
134
|
+
offset = options[:offset] if options[:offset]
|
135
|
+
size = buffer.size - offset
|
136
|
+
size = options[:size] - offset if options[:size]
|
137
|
+
num_events, events = OpenCL.get_event_wait_list( options )
|
138
|
+
event = FFI::MemoryPointer.new( Event )
|
139
|
+
error = FFI::MemoryPointer.new( :cl_int )
|
140
|
+
ptr = OpenCL.clEnqueueMapBuffer( command_queue, buffer, blocking, map_flags, offset, size, num_events, events, error )
|
141
|
+
OpenCL.error_check( error.read_cl_int )
|
142
|
+
ev = OpenCL::Event::new( event.read_ptr )
|
143
|
+
return [ev, ptr]
|
144
|
+
end
|
145
|
+
|
146
|
+
# Enqueues a command to unmap a previously mapped region of a memory object
|
147
|
+
#
|
148
|
+
# ==== Attributes
|
149
|
+
#
|
150
|
+
# * +command_queue+ - CommandQueue used to execute the unmap command
|
151
|
+
# * +mem_obj+ - the Mem object that was previously mapped
|
152
|
+
# * +mapped_ptr+ - the Pointer previously returned by a map command
|
153
|
+
# * +options+ - a hash containing named options
|
154
|
+
#
|
155
|
+
# ==== Options
|
156
|
+
#
|
157
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
158
|
+
#
|
159
|
+
# ==== Returns
|
160
|
+
#
|
161
|
+
# the Event associated with the command
|
162
|
+
def self.enqueue_unmap_mem_object( command_queue, mem_obj, mapped_ptr, options = {} )
|
163
|
+
num_events, events = OpenCL.get_event_wait_list( options )
|
164
|
+
event = FFI::MemoryPointer.new( Event )
|
165
|
+
error = OpenCL.clEnqueueUnmapMemObject( command_queue, mem_obj, mapped_ptr, num_events, events, event )
|
166
|
+
OpenCL.error_check( error )
|
167
|
+
return OpenCL::Event::new( event.read_ptr )
|
168
|
+
end
|
169
|
+
|
170
|
+
# Enqueues a command to read from a rectangular region from a Buffer object to host memory
|
171
|
+
#
|
172
|
+
# ==== Attributes
|
173
|
+
#
|
174
|
+
# * +command_queue+ - CommandQueue used to execute the read command
|
175
|
+
# * +buffer+ - the Buffer to be read from
|
176
|
+
# * +ptr+ - the Pointer (or convertible to Pointer using to_ptr) to the memory area to use
|
177
|
+
# * +region+ - the region in the Buffer to copy
|
178
|
+
# * +options+ - a hash containing named options
|
179
|
+
#
|
180
|
+
# ==== Options
|
181
|
+
#
|
182
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
183
|
+
# * +:blocking_read+ - if provided indicates if the command blocks until the region is read
|
184
|
+
# * +:blocking+ - if provided indicates if the command blocks until the region is read
|
185
|
+
# * +:buffer_origin+ - if provided indicates the origin inside the buffer of the area to copy, else [0, 0, 0]
|
186
|
+
# * +:host_origin+ - if provided indicates the origin inside the target host area, else [0, 0, 0]
|
187
|
+
# * +:buffer_row_pitch+ - if provided indicates the row pitch inside the buffer, else 0
|
188
|
+
# * +:buffer_slice_pitch+ - if provided indicates the slice pitch inside the buffer, else 0
|
189
|
+
# * +:host_row_pitch+ - if provided indicates the row pitch inside the host area, else 0
|
190
|
+
# * +:host_slice_pitch+ - if provided indicates the slice pitch inside the host area, else 0
|
191
|
+
#
|
192
|
+
# ==== Returns
|
193
|
+
#
|
194
|
+
# the Event associated with the command
|
195
|
+
def self.enqueue_read_buffer_rect( command_queue, buffer, ptr, region, options = {} )
|
196
|
+
OpenCL.error_check(OpenCL::INVALID_OPERATION) if command_queue.context.platform.version_number < 1.1
|
197
|
+
blocking = OpenCL::FALSE
|
198
|
+
blocking = OpenCL::TRUE if options[:blocking] or options[:blocking_read]
|
199
|
+
|
200
|
+
buffer_origin = FFI::MemoryPointer.new( :size_t, 3 )
|
201
|
+
(0..2).each { |i| buffer_origin[i].write_size_t(0) }
|
202
|
+
bo = options[:src_origin] ? options[:src_origin] : options[:buffer_origin]
|
203
|
+
if bo then
|
204
|
+
bo.each_with_index { |e, i|
|
205
|
+
buffer_origin[i].write_size_t(e)
|
206
|
+
}
|
207
|
+
end
|
208
|
+
|
209
|
+
host_origin = FFI::MemoryPointer.new( :size_t, 3 )
|
210
|
+
(0..2).each { |i| host_origin[i].write_size_t(0) }
|
211
|
+
ho = options[:dst_origin] ? options[:dst_origin] : options[:host_origin]
|
212
|
+
if ho then
|
213
|
+
ho.each_with_index { |e, i|
|
214
|
+
host_origin[i].write_size_t(e)
|
215
|
+
}
|
216
|
+
end
|
217
|
+
|
218
|
+
r = FFI::MemoryPointer.new( :size_t, 3 )
|
219
|
+
(0..2).each { |i| r[i].write_size_t(0) }
|
220
|
+
region[0..3].each_with_index { |e, i|
|
221
|
+
r[i].write_size_t(e)
|
222
|
+
}
|
223
|
+
|
224
|
+
buffer_row_pitch = options[:src_row_pitch] ? options[:src_row_pitch] : options[:buffer_row_pitch]
|
225
|
+
if not buffer_row_pitch then
|
226
|
+
buffer_row_pitch = 0
|
227
|
+
end
|
228
|
+
buffer_slice_pitch = options[:src_slice_pitch] ? options[:src_slice_pitch] : options[:buffer_slice_pitch]
|
229
|
+
if not buffer_slice_pitch then
|
230
|
+
buffer_slice_pitch = 0
|
231
|
+
end
|
232
|
+
host_row_pitch = options[:dst_row_pitch] ? options[:dst_row_pitch] : options[:host_row_pitch]
|
233
|
+
if not host_row_pitch then
|
234
|
+
host_row_pitch = 0
|
235
|
+
end
|
236
|
+
host_slice_pitch = options[:dst_slice_pitch] ? options[:dst_slice_pitch] : options[:host_slice_pitch]
|
237
|
+
if not host_slice_pitch then
|
238
|
+
host_slice_pitch = 0
|
239
|
+
end
|
240
|
+
num_events, events = OpenCL.get_event_wait_list( options )
|
241
|
+
event = FFI::MemoryPointer.new( Event )
|
242
|
+
error = OpenCL.clEnqueueReadBufferRect(command_queue, buffer, blocking, buffer_origin, host_origin, r, buffer_row_pitch, buffer_slice_pitch, host_row_pitch, host_slice_pitch, ptr, num_events, events, event)
|
243
|
+
OpenCL.error_check(error)
|
244
|
+
return OpenCL::Event::new(event.read_pointer)
|
245
|
+
end
|
246
|
+
|
247
|
+
# Enqueues a command to write to a rectangular region in a Buffer object from host memory
|
248
|
+
#
|
249
|
+
# ==== Attributes
|
250
|
+
#
|
251
|
+
# * +command_queue+ - CommandQueue used to execute the write command
|
252
|
+
# * +buffer+ - the Buffer to be written to
|
253
|
+
# * +ptr+ - the Pointer (or convertible to Pointer using to_ptr) to the memory area to use
|
254
|
+
# * +region+ - the region to write in the Buffer
|
255
|
+
# * +options+ - a hash containing named options
|
256
|
+
#
|
257
|
+
# ==== Options
|
258
|
+
#
|
259
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
260
|
+
# * +:blocking_write+ - if provided indicates if the command blocks until the region is written
|
261
|
+
# * +:blocking+ - if provided indicates if the command blocks until the region is written
|
262
|
+
# * +:buffer_origin+ - if provided indicates the origin inside the buffer of the area to copy, else [0, 0, 0]
|
263
|
+
# * +:host_origin+ - if provided indicates the origin inside the target host area, else [0, 0, 0]
|
264
|
+
# * +:buffer_row_pitch+ - if provided indicates the row pitch inside the buffer, else 0
|
265
|
+
# * +:buffer_slice_pitch+ - if provided indicates the slice pitch inside the buffer, else 0
|
266
|
+
# * +:host_row_pitch+ - if provided indicates the row pitch inside the host area, else 0
|
267
|
+
# * +:host_slice_pitch+ - if provided indicates the slice pitch inside the host area, else 0
|
268
|
+
#
|
269
|
+
# ==== Returns
|
270
|
+
#
|
271
|
+
# the Event associated with the command
|
272
|
+
def self.enqueue_write_buffer_rect(command_queue, buffer, ptr, region, options = {})
|
273
|
+
OpenCL.error_check(OpenCL::INVALID_OPERATION) if command_queue.context.platform.version_number < 1.1
|
274
|
+
blocking = OpenCL::FALSE
|
275
|
+
blocking = OpenCL::TRUE if options[:blocking] or options[:blocking_write]
|
276
|
+
|
277
|
+
buffer_origin = FFI::MemoryPointer.new( :size_t, 3 )
|
278
|
+
(0..2).each { |i| buffer_origin[i].write_size_t(0) }
|
279
|
+
bo = options[:dst_origin] ? options[:dst_origin] : options[:buffer_origin]
|
280
|
+
if bo then
|
281
|
+
bo.each_with_index { |e, i|
|
282
|
+
buffer_origin[i].write_size_t(e)
|
283
|
+
}
|
284
|
+
end
|
285
|
+
|
286
|
+
host_origin = FFI::MemoryPointer.new( :size_t, 3 )
|
287
|
+
(0..2).each { |i| host_origin[i].write_size_t(0) }
|
288
|
+
ho = options[:src_origin] ? options[:src_origin] : options[:host_origin]
|
289
|
+
if ho then
|
290
|
+
ho.each_with_index { |e, i|
|
291
|
+
host_origin[i].write_size_t(e)
|
292
|
+
}
|
293
|
+
end
|
294
|
+
|
295
|
+
r = FFI::MemoryPointer.new( :size_t, 3 )
|
296
|
+
(0..2).each { |i| r[i].write_size_t(0) }
|
297
|
+
region[0..3].each_with_index { |e, i|
|
298
|
+
r[i].write_size_t(e)
|
299
|
+
}
|
300
|
+
|
301
|
+
buffer_row_pitch = options[:dst_row_pitch] ? options[:dst_row_pitch] : options[:buffer_row_pitch]
|
302
|
+
if not buffer_row_pitch then
|
303
|
+
buffer_row_pitch = 0
|
304
|
+
end
|
305
|
+
buffer_slice_pitch = options[:dst_slice_pitch] ? options[:dst_slice_pitch] : options[:buffer_slice_pitch]
|
306
|
+
if not buffer_slice_pitch then
|
307
|
+
buffer_slice_pitch = 0
|
308
|
+
end
|
309
|
+
host_row_pitch = options[:src_row_pitch] ? options[:src_row_pitch] : options[:host_row_pitch]
|
310
|
+
if not host_row_pitch then
|
311
|
+
host_row_pitch = 0
|
312
|
+
end
|
313
|
+
host_slice_pitch = options[:src_slice_pitch] ? options[:src_slice_pitch] : options[:host_slice_pitch]
|
314
|
+
if not host_slice_pitch then
|
315
|
+
host_slice_pitch = 0
|
316
|
+
end
|
317
|
+
num_events, events = OpenCL.get_event_wait_list( options )
|
318
|
+
event = FFI::MemoryPointer.new( Event )
|
319
|
+
error = OpenCL.clEnqueueWriteBufferRect(command_queue, buffer, blocking, buffer_origin, host_origin, r, buffer_row_pitch, buffer_slice_pitch, host_row_pitch, host_slice_pitch, ptr, num_events, events, event)
|
320
|
+
OpenCL.error_check(error)
|
321
|
+
return OpenCL::Event::new(event.read_pointer)
|
322
|
+
end
|
323
|
+
|
324
|
+
# Enqueues a command to copy a rectangular region into a Buffer object from another Buffer object
|
325
|
+
#
|
326
|
+
# ==== Attributes
|
327
|
+
#
|
328
|
+
# * +command_queue+ - CommandQueue used to execute the write command
|
329
|
+
# * +src_buffer+ - the Buffer to be read from
|
330
|
+
# * +dst_buffer+ - the Buffer to be written to
|
331
|
+
# * +region+ - the region to write in the Buffer
|
332
|
+
# * +options+ - a hash containing named options
|
333
|
+
#
|
334
|
+
# ==== Options
|
335
|
+
#
|
336
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
337
|
+
# * +:src_origin+ - if provided indicates the origin inside the src Buffer of the area to copy, else [0, 0, 0]
|
338
|
+
# * +:dst_origin+ - if provided indicates the origin inside the dst Buffer of the area to write to, else [0, 0, 0]
|
339
|
+
# * +:src_row_pitch+ - if provided indicates the row pitch inside the src Buffer, else 0
|
340
|
+
# * +:src_slice_pitch+ - if provided indicates the slice pitch inside the src Buffer, else 0
|
341
|
+
# * +:dst_row_pitch+ - if provided indicates the row pitch inside the dst Buffer, else 0
|
342
|
+
# * +:dst_slice_pitch+ - if provided indicates the slice pitch inside the dst Buffer area, else 0
|
343
|
+
#
|
344
|
+
# ==== Returns
|
345
|
+
#
|
346
|
+
# the Event associated with the command
|
347
|
+
def self.enqueue_copy_buffer_rect(command_queue, src_buffer, dst_buffer, region, options = {})
|
348
|
+
OpenCL.error_check(OpenCL::INVALID_OPERATION) if command_queue.context.platform.version_number < 1.1
|
349
|
+
|
350
|
+
src_origin = FFI::MemoryPointer.new( :size_t, 3 )
|
351
|
+
(0..2).each { |i| src_origin[i].write_size_t(0) }
|
352
|
+
if options[:src_origin] then
|
353
|
+
options[:src_origin].each_with_index { |e, i|
|
354
|
+
src_origin[i].write_size_t(e)
|
355
|
+
}
|
356
|
+
end
|
357
|
+
|
358
|
+
dst_origin = FFI::MemoryPointer.new( :size_t, 3 )
|
359
|
+
(0..2).each { |i| dst_origin[i].write_size_t(0) }
|
360
|
+
if options[:dst_origin] then
|
361
|
+
options[:dst_origin].each_with_index { |e, i|
|
362
|
+
dst_origin[i].write_size_t(e)
|
363
|
+
}
|
364
|
+
end
|
365
|
+
|
366
|
+
r = FFI::MemoryPointer.new( :size_t, 3 )
|
367
|
+
(0..2).each { |i| r[i].write_size_t(0) }
|
368
|
+
region[0..3].each_with_index { |e, i|
|
369
|
+
r[i].write_size_t(e)
|
370
|
+
}
|
371
|
+
|
372
|
+
src_row_pitch = options[:src_row_pitch]
|
373
|
+
if not src_row_pitch then
|
374
|
+
src_row_pitch = 0
|
375
|
+
end
|
376
|
+
src_slice_pitch = options[:src_slice_pitch]
|
377
|
+
if not src_slice_pitch then
|
378
|
+
src_slice_pitch = 0
|
379
|
+
end
|
380
|
+
dst_row_pitch = options[:dst_row_pitch]
|
381
|
+
if not dst_row_pitch then
|
382
|
+
dst_row_pitch = 0
|
383
|
+
end
|
384
|
+
dst_slice_pitch = options[:dst_slice_pitch]
|
385
|
+
if not dst_slice_pitch then
|
386
|
+
dst_slice_pitch = 0
|
387
|
+
end
|
388
|
+
num_events, events = OpenCL.get_event_wait_list( options )
|
389
|
+
event = FFI::MemoryPointer.new( Event )
|
390
|
+
error = OpenCL.clEnqueueCopyBufferRect(command_queue, src_buffer, dst_buffer, src_origin, dst_origin, r, src_row_pitch, src_slice_pitch, dst_row_pitch, dst_slice_pitch, num_events, events, event)
|
391
|
+
OpenCL.error_check(error)
|
392
|
+
return OpenCL::Event::new(event.read_pointer)
|
393
|
+
end
|
394
|
+
|
395
|
+
# Enqueues a command to copy data from a Buffer object into another Buffer object
|
396
|
+
#
|
397
|
+
# ==== Attributes
|
398
|
+
#
|
399
|
+
# * +command_queue+ - CommandQueue used to execute the write command
|
400
|
+
# * +src_buffer+ - the Buffer to be read from
|
401
|
+
# * +dst_buffer+ - the Buffer to be written to
|
402
|
+
# * +options+ - a hash containing named options
|
403
|
+
#
|
404
|
+
# ==== Options
|
405
|
+
#
|
406
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
407
|
+
# * +:src_offset+ - if provided indicates the offset inside the src Buffer of the area to copy, else 0
|
408
|
+
# * +:dst_offset+ - if provided indicates the offset inside the dst Buffer of the area to write to, else 0
|
409
|
+
# * +:size+ - if provided indicates the size of data to copy, else the maximum possible is copied
|
410
|
+
#
|
411
|
+
# ==== Returns
|
412
|
+
#
|
413
|
+
# the Event associated with the command
|
414
|
+
def self.enqueue_copy_buffer(command_queue, src_buffer, dst_buffer, options = {})
|
415
|
+
src_offset = 0
|
416
|
+
src_offset = options[:src_offset] if options[:src_offset]
|
417
|
+
dst_offset = 0
|
418
|
+
dst_offset = options[:dst_offset] if options[:dst_offset]
|
419
|
+
size = [ src_buffer.size - src_offset, dst_buffer.size - dst_offset ].min
|
420
|
+
size = options[:size] if options[:size]
|
421
|
+
num_events, events = OpenCL.get_event_wait_list( options )
|
422
|
+
event = FFI::MemoryPointer.new( Event )
|
423
|
+
error = OpenCL.clEnqueueCopyBuffer(command_queue, src_buffer, dst_buffer, src_offset, dst_offset, size, num_events, events, event)
|
424
|
+
OpenCL.error_check(error)
|
425
|
+
return OpenCL::Event::new(event.read_pointer)
|
426
|
+
end
|
427
|
+
|
428
|
+
|
429
|
+
# Enqueues a command to write to a Buffer object from host memory
|
430
|
+
#
|
431
|
+
# ==== Attributes
|
432
|
+
#
|
433
|
+
# * +command_queue+ - CommandQueue used to execute the write command
|
434
|
+
# * +buffer+ - the Buffer to be written to
|
435
|
+
# * +ptr+ - the Pointer (or convertible to Pointer using to_ptr) to the memory area to use
|
436
|
+
# * +options+ - a hash containing named options
|
437
|
+
#
|
438
|
+
# ==== Options
|
439
|
+
#
|
440
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
441
|
+
# * +:blocking_write+ - if provided indicates if the command blocks until the region is written.
|
442
|
+
# * +:blocking+ - if provided indicates if the command blocks until the region is written
|
443
|
+
# * +:offset+ - if provided indicates the offset inside the Buffer of the area to read from, else 0
|
444
|
+
# * +:size+ - if provided indicates the size of data to copy, else the maximum data is copied
|
445
|
+
#
|
446
|
+
# ==== Returns
|
447
|
+
#
|
448
|
+
# the Event associated with the command
|
449
|
+
def self.enqueue_write_buffer( command_queue, buffer, ptr, options = {} )
|
450
|
+
blocking = OpenCL::FALSE
|
451
|
+
blocking = OpenCL::TRUE if options[:blocking] or options[:blocking_write]
|
452
|
+
offset = 0
|
453
|
+
offset = options[:offset] if options[:offset]
|
454
|
+
size = buffer.size - offset
|
455
|
+
size = options[:size] if options[:size]
|
456
|
+
num_events, events = OpenCL.get_event_wait_list( options )
|
457
|
+
event = FFI::MemoryPointer.new( Event )
|
458
|
+
error = OpenCL.clEnqueueWriteBuffer(command_queue, buffer, blocking, offset, size, ptr, num_events, events, event)
|
459
|
+
OpenCL.error_check(error)
|
460
|
+
return OpenCL::Event::new(event.read_pointer)
|
461
|
+
end
|
462
|
+
|
463
|
+
# Enqueues a command to read from a Buffer object to host memory
|
464
|
+
#
|
465
|
+
# ==== Attributes
|
466
|
+
#
|
467
|
+
# * +command_queue+ - CommandQueue used to execute the read command
|
468
|
+
# * +buffer+ - the Buffer to be read from
|
469
|
+
# * +ptr+ - the Pointer (or convertible to Pointer using to_ptr) to the memory area to use
|
470
|
+
# * +options+ - a hash containing named options
|
471
|
+
#
|
472
|
+
# ==== Options
|
473
|
+
#
|
474
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
475
|
+
# * +:blocking_read+ - if provided indicates if the command blocks until the region is read
|
476
|
+
# * +:blocking+ - if provided indicates if the command blocks until the region is read
|
477
|
+
# * +:offset+ - if provided indicates the offset inside the Buffer of the area to read from, else 0
|
478
|
+
# * +:size+ - if provided indicates the size of data to copy, else the maximum data is copied
|
479
|
+
#
|
480
|
+
# ==== Returns
|
481
|
+
#
|
482
|
+
# the Event associated with the command
|
483
|
+
def self.enqueue_read_buffer( command_queue, buffer, ptr, options = {} )
|
484
|
+
blocking = OpenCL::FALSE
|
485
|
+
blocking = OpenCL::TRUE if options[:blocking] or options[:blocking_read]
|
486
|
+
offset = 0
|
487
|
+
offset = options[:offset] if options[:offset]
|
488
|
+
size = buffer.size - offset
|
489
|
+
size = options[:size] if options[:size]
|
490
|
+
num_events, events = OpenCL.get_event_wait_list( options )
|
491
|
+
event = FFI::MemoryPointer.new( Event )
|
492
|
+
error = OpenCL.clEnqueueReadBuffer(command_queue, buffer, blocking, offset, size, ptr, num_events, events, event)
|
493
|
+
OpenCL.error_check(error)
|
494
|
+
return OpenCL::Event::new(event.read_pointer)
|
495
|
+
end
|
496
|
+
|
497
|
+
# Acquire OpenCL Mem objects that have been created from OpenGL objects
|
498
|
+
#
|
499
|
+
# ==== Attributes
|
500
|
+
#
|
501
|
+
# * +command_queue+ - CommandQueue used to execute the acquire command
|
502
|
+
# * +mem_objects+ - a single or an Array of Mem objects
|
503
|
+
# * +options+ - a hash containing named options
|
504
|
+
#
|
505
|
+
# ==== Options
|
506
|
+
#
|
507
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
508
|
+
#
|
509
|
+
# ==== Returns
|
510
|
+
#
|
511
|
+
# the Event associated with the command
|
512
|
+
def self.enqueue_acquire_GL_object( command_queue, mem_objects, options = {} )
|
513
|
+
num_objs = [mem_objects].flatten.length
|
514
|
+
objs = nil
|
515
|
+
if num_objs > 0 then
|
516
|
+
objs = FFI::MemoryPointer.new( Mem, num_objs )
|
517
|
+
[mem_objects].flatten.each_with_index { |o, i|
|
518
|
+
objs[i].write_pointer(e)
|
519
|
+
}
|
520
|
+
end
|
521
|
+
num_events, events = OpenCL.get_event_wait_list( options )
|
522
|
+
event = FFI::MemoryPointer.new( Event )
|
523
|
+
error = OpenCL.clEnqueueAcquireGLObject( command_queue, num_objs, objs, num_events, events, event )
|
524
|
+
OpenCL.error_check(error)
|
525
|
+
return OpenCL::Event::new(event.read_pointer)
|
526
|
+
end
|
527
|
+
|
528
|
+
# Release OpenCL Mem objects that have been created from OpenGL objects and previously acquired
|
529
|
+
#
|
530
|
+
# ==== Attributes
|
531
|
+
#
|
532
|
+
# * +command_queue+ - CommandQueue used to execute the release command
|
533
|
+
# * +mem_objects+ - a single or an Array of Mem objects
|
534
|
+
# * +options+ - a hash containing named options
|
535
|
+
#
|
536
|
+
# ==== Options
|
537
|
+
#
|
538
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
539
|
+
#
|
540
|
+
# ==== Returns
|
541
|
+
#
|
542
|
+
# the Event associated with the command
|
543
|
+
def self.enqueue_release_GL_object( command_queue, mem_objects, options = {} )
|
544
|
+
num_objs = [mem_objects].flatten.length
|
545
|
+
objs = nil
|
546
|
+
if num_objs > 0 then
|
547
|
+
objs = FFI::MemoryPointer.new( Mem, num_objs )
|
548
|
+
[mem_objects].flatten.each_with_index { |o, i|
|
549
|
+
objs[i].write_pointer(e)
|
550
|
+
}
|
551
|
+
end
|
552
|
+
num_events, events = OpenCL.get_event_wait_list( options )
|
553
|
+
event = FFI::MemoryPointer.new( Event )
|
554
|
+
error = OpenCL.clEnqueueReleaseGLObject( command_queue, num_objs, objs, num_events, events, event )
|
555
|
+
OpenCL.error_check(error)
|
556
|
+
return OpenCL::Event::new(event.read_pointer)
|
557
|
+
end
|
558
|
+
|
559
|
+
# Enqueues a command to fill a Buffer with the given pattern
|
560
|
+
#
|
561
|
+
# ==== Attributes
|
562
|
+
#
|
563
|
+
# * +command_queue+ - CommandQueue used to execute the fill command
|
564
|
+
# * +buffer+ - a Buffer object to be filled
|
565
|
+
# * +pattern+ - the Pointer (or convertible to Pointer using to_ptr) to the memory area where the pattern is stored
|
566
|
+
# * +options+ - a hash containing named options
|
567
|
+
#
|
568
|
+
# ==== Options
|
569
|
+
#
|
570
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
571
|
+
# * +:offset+ - if provided indicates the offset inside the Buffer of the area to be filled, else 0
|
572
|
+
# * +:size+ - if provided indicates the size of data to fill, else the maximum size is filled
|
573
|
+
# * +:pattern_size+ - if provided indicates the size of the pattern, else the maximum pattern data is used
|
574
|
+
#
|
575
|
+
# ==== Returns
|
576
|
+
#
|
577
|
+
# the Event associated with the command
|
578
|
+
def self.enqueue_fill_buffer( command_queue, buffer, pattern, options = {} )
|
579
|
+
OpenCL.error_check(OpenCL::INVALID_OPERATION) if command_queue.context.platform.version_number < 1.1
|
580
|
+
offset = 0
|
581
|
+
offset = options[:offset] if options[:offset]
|
582
|
+
pattern_size = pattern.size
|
583
|
+
pattern_size = options[:pattern_size] if options[:pattern_size]
|
584
|
+
size = (buffer.size - offset) % pattern_size
|
585
|
+
size = options[:size] if options[:size]
|
586
|
+
num_events, events = OpenCL.get_event_wait_list( options )
|
587
|
+
event = FFI::MemoryPointer.new( Event )
|
588
|
+
error = OpenCL.clEnqueueFillBuffer( command_queue, buffer, pattern, pattern_size, offset, size, num_events, events, event )
|
589
|
+
OpenCL.error_check(error)
|
590
|
+
return OpenCL::Event::new(event.read_pointer)
|
591
|
+
end
|
592
|
+
|
593
|
+
# Enqueues a command to fill an Image with the given color
|
594
|
+
#
|
595
|
+
# ==== Attributes
|
596
|
+
#
|
597
|
+
# * +command_queue+ - CommandQueue used to execute the fill command
|
598
|
+
# * +image+ - an Image object to be filled
|
599
|
+
# * +fill_color+ - the Pointer (or convertible to Pointer using to_ptr) to the memory area where the color is stored
|
600
|
+
# * +options+ - a hash containing named options
|
601
|
+
#
|
602
|
+
# ==== Options
|
603
|
+
#
|
604
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
605
|
+
# * +:origin+ - if provided indicates the origin of the region to fill inside the Image, else [0, 0, 0]
|
606
|
+
# * +:region+ - if provided indicates the dimension of the region to fill, else the maximum region is filled
|
607
|
+
#
|
608
|
+
# ==== Returns
|
609
|
+
#
|
610
|
+
# the Event associated with the command
|
611
|
+
def self.enqueue_fill_image( command_queue, image, fill_color, options = {} )
|
612
|
+
OpenCL.error_check(OpenCL::INVALID_OPERATION) if command_queue.context.platform.version_number < 1.1
|
613
|
+
origin, region = OpenCL.get_origin_region( image, options, :origin, :region )
|
614
|
+
num_events, events = OpenCL.get_event_wait_list( options )
|
615
|
+
event = FFI::MemoryPointer.new( Event )
|
616
|
+
error = OpenCL.clEnqueueFillImage( command_queue, image, fill_color, origin, region, num_events, events, event )
|
617
|
+
OpenCL.error_check(error)
|
618
|
+
return OpenCL::Event::new(event.read_pointer)
|
619
|
+
end
|
620
|
+
|
621
|
+
# Enqueues a command to copy an Image into a Buffer
|
622
|
+
#
|
623
|
+
# ==== Attributes
|
624
|
+
#
|
625
|
+
# * +command_queue+ - CommandQueue used to execute the copy command
|
626
|
+
# * +src_image+ - the Image to be read from
|
627
|
+
# * +dst_buffer+ - the Buffer to be written to
|
628
|
+
# * +options+ - a hash containing named options
|
629
|
+
#
|
630
|
+
# ==== Options
|
631
|
+
#
|
632
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
633
|
+
# * +:src_origin+ - if provided indicates the origin of the region to copy from the Image, else [0, 0, 0]
|
634
|
+
# * +:region+ - if provided indicates the dimension of the region to copy, else the maximum region is copied
|
635
|
+
# * +:dst_offset+ - if provided indicates the offset inside the Buffer, else 0
|
636
|
+
#
|
637
|
+
# ==== Returns
|
638
|
+
#
|
639
|
+
# the Event associated with the command
|
640
|
+
def self.enqueue_copy_image_to_buffer( command_queue, src_image, dst_buffer, options = {} )
|
641
|
+
src_origin, region = OpenCL.get_origin_region( src_image, options, :src_origin, :region )
|
642
|
+
dst_offset = 0
|
643
|
+
dst_offset = options[:dst_offset] if options[:dst_offset]
|
644
|
+
num_events, events = OpenCL.get_event_wait_list( options )
|
645
|
+
event = FFI::MemoryPointer.new( Event )
|
646
|
+
error = OpenCL.clEnqueueCopyImageToBuffer( command_queue, src_image, dst_buffer, src_origin, region, dst_offset, num_events, events, event )
|
647
|
+
OpenCL.error_check(error)
|
648
|
+
return OpenCL::Event::new(event.read_pointer)
|
649
|
+
end
|
650
|
+
|
651
|
+
# Enqueues a command to copy a Buffer into an Image
|
652
|
+
#
|
653
|
+
# ==== Attributes
|
654
|
+
#
|
655
|
+
# * +command_queue+ - CommandQueue used to execute the copy command
|
656
|
+
# * +src_buffer+ - the Buffer to be read from
|
657
|
+
# * +dst_image+ - the Image to be written to
|
658
|
+
# * +options+ - a hash containing named options
|
659
|
+
#
|
660
|
+
# ==== Options
|
661
|
+
#
|
662
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
663
|
+
# * +:dst_origin+ - if provided indicates the origin of the region to write into the Image, else [0, 0, 0]
|
664
|
+
# * +:region+ - if provided indicates the dimension of the region to copy, else the maximum region is copied
|
665
|
+
# * +:src_offset+ - if provided indicates the offset inside the Buffer, else 0
|
666
|
+
#
|
667
|
+
# ==== Returns
|
668
|
+
#
|
669
|
+
# the Event associated with the command
|
670
|
+
def self.enqueue_copy_buffer_to_image(command_queue, src_buffer, dst_image, options = {})
|
671
|
+
dst_origin, region = OpenCL.get_origin_region( dst_image, options, :dst_origin, :region )
|
672
|
+
src_offset = 0
|
673
|
+
src_offset = options[:src_offset] if options[:src_offset]
|
674
|
+
num_events, events = OpenCL.get_event_wait_list( options )
|
675
|
+
event = FFI::MemoryPointer.new( Event )
|
676
|
+
error = OpenCL.clEnqueueCopyBufferToImage( command_queue, src_buffer, dst_image, src_offset, dst_origin, region, num_events, events, event )
|
677
|
+
OpenCL.error_check(error)
|
678
|
+
return OpenCL::Event::new(event.read_pointer)
|
679
|
+
end
|
680
|
+
|
681
|
+
# Enqueues a command to copy from host memory into an Image
|
682
|
+
#
|
683
|
+
# ==== Attributes
|
684
|
+
#
|
685
|
+
# * +command_queue+ - CommandQueue used to execute the write command
|
686
|
+
# * +image+ - the Image to be written to
|
687
|
+
# * +ptr+ - the Pointer (or convertible to Pointer using to_ptr) to the memory area to use
|
688
|
+
# * +options+ - a hash containing named options
|
689
|
+
#
|
690
|
+
# ==== Options
|
691
|
+
#
|
692
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
693
|
+
# * +:blocking_write+ - if provided indicates if the command blocks until the region is written.
|
694
|
+
# * +:blocking+ - if provided indicates if the command blocks until the region is written
|
695
|
+
# * +:origin+ - if provided indicates the origin of the region to write into the Image, else [0, 0, 0]
|
696
|
+
# * +:region+ - if provided indicates the dimension of the region to copy, else the maximum region is copied
|
697
|
+
# * +:input_row_pitch+ - if provided indicates the row pitch inside the host area, else 0
|
698
|
+
# * +:input_slice_pitch+ - if provided indicates the slice pitch inside the host area, else 0
|
699
|
+
#
|
700
|
+
# ==== Returns
|
701
|
+
#
|
702
|
+
# the Event associated with the command
|
703
|
+
def self.enqueue_write_image(command_queue, image, ptr, options = {})
|
704
|
+
blocking = OpenCL::FALSE
|
705
|
+
blocking = OpenCL::TRUE if options[:blocking] or options[:blocking_write]
|
706
|
+
|
707
|
+
origin, region = OpenCL.get_origin_region( image, options, :origin, :region )
|
708
|
+
|
709
|
+
input_row_pitch = 0
|
710
|
+
input_row_pitch = options[:input_row_pitch] if options[:input_row_pitch]
|
711
|
+
input_slice_pitch = 0
|
712
|
+
input_slice_pitch = options[:input_slice_pitch] if options[:input_slice_pitch]
|
713
|
+
num_events, events = OpenCL.get_event_wait_list( options )
|
714
|
+
event = FFI::MemoryPointer.new( Event )
|
715
|
+
error = OpenCL.clEnqueueWriteImage( command_queue, image, blocking, origin, region, input_row_pitch, input_slice_pitch, ptr, num_events, events, event )
|
716
|
+
OpenCL.error_check(error)
|
717
|
+
return OpenCL::Event::new(event.read_pointer)
|
718
|
+
end
|
719
|
+
|
720
|
+
# Enqueues a command to copy from an Image into an Image
|
721
|
+
#
|
722
|
+
# ==== Attributes
|
723
|
+
#
|
724
|
+
# * +command_queue+ - CommandQueue used to execute the copy command
|
725
|
+
# * +src_image+ - the Image to be written to
|
726
|
+
# * +dst_image+ - the Image to be written to
|
727
|
+
# * +options+ - a hash containing named options
|
728
|
+
#
|
729
|
+
# ==== Options
|
730
|
+
#
|
731
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
732
|
+
# * +:src_origin+ - if provided indicates the origin of the region to read into the src Image, else [0, 0, 0]
|
733
|
+
# * +:dst_origin+ - if provided indicates the origin of the region to write into the dst Image, else [0, 0, 0]
|
734
|
+
# * +:region+ - if provided indicates the dimension of the region to copy, else the maximum region is copied
|
735
|
+
#
|
736
|
+
# ==== Returns
|
737
|
+
#
|
738
|
+
# the Event associated with the command
|
739
|
+
def self.enqueue_copy_image( command_queue, src_image, dst_image, options = {} )
|
740
|
+
src_origin, src_region = OpenCL.get_origin_region( src_image, options, :src_origin, :region )
|
741
|
+
dst_origin, dst_region = OpenCL.get_origin_region( dst_image, options, :dst_origin, :region )
|
742
|
+
region = FFI::MemoryPointer.new( :size_t, 3 )
|
743
|
+
(0..2).each { |i|
|
744
|
+
region[i].write_size_t( [src_region[i].read_size_t, dst_region[i].read_size_t].min )
|
745
|
+
}
|
746
|
+
num_events, events = OpenCL.get_event_wait_list( options )
|
747
|
+
event = FFI::MemoryPointer.new( Event )
|
748
|
+
error = OpenCL.clEnqueueCopyImage( command_queue, src_image, dst_image, src_origin, dst_origin, region, num_events, events, event )
|
749
|
+
OpenCL.error_check(error)
|
750
|
+
return OpenCL::Event::new(event.read_pointer)
|
751
|
+
end
|
752
|
+
|
753
|
+
# Enqueues a command to copy from an Image into host memory
|
754
|
+
#
|
755
|
+
# ==== Attributes
|
756
|
+
#
|
757
|
+
# * +command_queue+ - CommandQueue used to execute the read command
|
758
|
+
# * +image+ - the Image to be written to
|
759
|
+
# * +ptr+ - the Pointer (or convertible to Pointer using to_ptr) to the memory area to use
|
760
|
+
# * +options+ - a hash containing named options
|
761
|
+
#
|
762
|
+
# ==== Options
|
763
|
+
#
|
764
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
765
|
+
# * +:blocking_read+ - if provided indicates if the command blocks until the region is read.
|
766
|
+
# * +:blocking+ - if provided indicates if the command blocks until the region is read
|
767
|
+
# * +:origin+ - if provided indicates the origin of the region to read from the Image, else [0, 0, 0]
|
768
|
+
# * +:region+ - if provided indicates the dimension of the region to copy, else the maximum region is copied
|
769
|
+
# * +:row_pitch+ - if provided indicates the row pitch inside the host area, else 0
|
770
|
+
# * +:slice_pitch+ - if provided indicates the slice pitch inside the host area, else 0
|
771
|
+
#
|
772
|
+
# ==== Returns
|
773
|
+
#
|
774
|
+
# the Event associated with the command
|
775
|
+
def self.enqueue_read_image( command_queue, image, ptr, options = {} )
|
776
|
+
blocking = OpenCL::FALSE
|
777
|
+
blocking = OpenCL::TRUE if options[:blocking] or options[:blocking_read]
|
778
|
+
|
779
|
+
origin, region = OpenCL.get_origin_region( image, options, :origin, :region )
|
780
|
+
row_pitch = 0
|
781
|
+
row_pitch = options[:row_pitch] if options[:row_pitch]
|
782
|
+
slice_pitch = 0
|
783
|
+
slice_pitch = options[:slice_pitch] if options[:slice_pitch]
|
784
|
+
num_events, events = OpenCL.get_event_wait_list( options )
|
785
|
+
event = FFI::MemoryPointer.new( Event )
|
786
|
+
error = OpenCL.clEnqueueReadImage( command_queue, image, blocking, origin, region, row_pitch, slice_pitch, ptr, num_events, events, event )
|
787
|
+
OpenCL.error_check(error)
|
788
|
+
return OpenCL::Event::new(event.read_pointer)
|
789
|
+
end
|
790
|
+
|
791
|
+
# Enqueues a native kernel
|
792
|
+
# not yet fully implemented
|
793
|
+
#
|
794
|
+
# ==== Attributes
|
795
|
+
#
|
796
|
+
# * +command_queue+ - CommandQueue used to execute the command
|
797
|
+
# * +options+ - a hash containing named options
|
798
|
+
# * +func+ - a Proc object to execute
|
799
|
+
#
|
800
|
+
# ==== Options
|
801
|
+
#
|
802
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
803
|
+
#
|
804
|
+
# ==== Returns
|
805
|
+
#
|
806
|
+
# the Event associated with the command
|
807
|
+
def self.enqueue_native_kernel( command_queue, options = {}, &func )
|
808
|
+
# num_mem_objects = 0
|
809
|
+
# mem_list = nil
|
810
|
+
# if options[:mem_list] then
|
811
|
+
# num_mem_objects = options[:mem_list].length
|
812
|
+
# if num_mem_objects > 0 then
|
813
|
+
# mem_list = FFI::MemoryPointer.new( OpenCL::Mem, num_mem_objects )
|
814
|
+
# options[:mem_list].each_with_index { |e, i|
|
815
|
+
# mem_list[i].write_pointer(e)
|
816
|
+
# }
|
817
|
+
# end
|
818
|
+
# end
|
819
|
+
num_events, events = OpenCL.get_event_wait_list( options )
|
820
|
+
event = FFI::MemoryPointer.new( Event )
|
821
|
+
error = OpenCL.clEnqueueNativeKernel( command_queue, func, nil, 0, 0, nil, nil, num_events, events, event )
|
822
|
+
OpenCL.error_check(error)
|
823
|
+
return OpenCL::Event::new(event.read_pointer)
|
824
|
+
end
|
825
|
+
|
826
|
+
# Enqueues a kernel as a task
|
827
|
+
#
|
828
|
+
# ==== Attributes
|
829
|
+
#
|
830
|
+
# * +command_queue+ - CommandQueue used to execute the command
|
831
|
+
# * +kernel+ - a Kernel object to execute
|
832
|
+
# * +options+ - a hash containing named options
|
833
|
+
#
|
834
|
+
# ==== Options
|
835
|
+
#
|
836
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
837
|
+
#
|
838
|
+
# ==== Returns
|
839
|
+
#
|
840
|
+
# the Event associated with the command
|
841
|
+
def self.enqueue_task( command_queue, kernel, options = {} )
|
842
|
+
num_events, events = OpenCL.get_event_wait_list( options )
|
843
|
+
event = FFI::MemoryPointer.new( Event )
|
844
|
+
error = OpenCL.clEnqueueTask( command_queue, kernel, num_events, events, event )
|
845
|
+
OpenCL.error_check(error)
|
846
|
+
return OpenCL::Event::new(event.read_pointer)
|
847
|
+
end
|
848
|
+
|
849
|
+
# Enqueues a kernel as a NDrange
|
850
|
+
#
|
851
|
+
# ==== Attributes
|
852
|
+
#
|
853
|
+
# * +command_queue+ - CommandQueue used to execute the command
|
854
|
+
# * +kernel+ - a Kernel object to execute
|
855
|
+
# * +global_work_size+ - dimensions of the work
|
856
|
+
# * +options+ - a hash containing named options
|
857
|
+
#
|
858
|
+
# ==== Options
|
859
|
+
#
|
860
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
861
|
+
# * +:local_work_size+ - if provided, dimensions of the local work group size
|
862
|
+
# * +:global_work_offset+ - if provided, offset inside the global work size
|
863
|
+
#
|
864
|
+
# ==== Returns
|
865
|
+
#
|
866
|
+
# the Event associated with the command
|
867
|
+
def self.enqueue_NDrange_kernel( command_queue, kernel, global_work_size, options={} )
|
868
|
+
gws = FFI::MemoryPointer.new( :size_t, global_work_size.length )
|
869
|
+
global_work_size.each_with_index { |g, i|
|
870
|
+
gws[i].write_size_t(g)
|
871
|
+
}
|
872
|
+
lws = nil
|
873
|
+
if options[:local_work_size] then
|
874
|
+
lws = FFI::MemoryPointer.new( :size_t, global_work_size.length )
|
875
|
+
global_work_size.each_index { |i|
|
876
|
+
lws[i].write_size_t(options[:local_work_size][i])
|
877
|
+
}
|
878
|
+
end
|
879
|
+
gwo = nil
|
880
|
+
if options[:global_work_offset] then
|
881
|
+
gwo = FFI::MemoryPointer.new( :size_t, global_work_size.length )
|
882
|
+
global_work_size.each_index { |i|
|
883
|
+
gwo[i].write_size_t(options[:global_work_offset][i])
|
884
|
+
}
|
885
|
+
end
|
886
|
+
num_events, events = OpenCL.get_event_wait_list( options )
|
887
|
+
event = FFI::MemoryPointer.new( Event )
|
888
|
+
error = OpenCL.clEnqueueNDRangeKernel(command_queue, kernel, global_work_size.length, gwo, gws, lws, num_events, events, event)
|
889
|
+
OpenCL.error_check(error)
|
890
|
+
return OpenCL::Event::new(event.read_pointer)
|
891
|
+
end
|
892
|
+
|
893
|
+
# Enqueues a barrier on a list of envents
|
894
|
+
#
|
895
|
+
# ==== Attributes
|
896
|
+
#
|
897
|
+
# * +command_queue+ - CommandQueue used to execute the command
|
898
|
+
# * +events+ - a single or an Array of Event to wait upon before the barrier is considered finished
|
899
|
+
#
|
900
|
+
# ==== Returns
|
901
|
+
#
|
902
|
+
# an Event if implementation version is >= 1.2, nil otherwise
|
903
|
+
def self.enqueue_wait_for_events( command_queue, events )
|
904
|
+
return OpenCL.enqueue_barrier( command_queue, events )
|
905
|
+
end
|
906
|
+
|
907
|
+
# Enqueues a barrier that prevents subsequent execution to take place in the command queue, until the barrier is considered finished
|
908
|
+
#
|
909
|
+
# ==== Attributes
|
910
|
+
#
|
911
|
+
# * +command_queue+ - CommandQueue used to execute the command
|
912
|
+
# * +events+ - an optional single or Array of Event to wait upon before the barrier is considered finished
|
913
|
+
#
|
914
|
+
# ==== Returns
|
915
|
+
#
|
916
|
+
# an Event if implementation version is >= 1.2, nil otherwise
|
917
|
+
def self.enqueue_barrier( command_queue, events = [] )
|
918
|
+
if command_queue.context.platform.version_number < 1.2 then
|
919
|
+
num_events = [events].flatten.length
|
920
|
+
if num_events > 0 then
|
921
|
+
evts = FFI::MemoryPointer.new( Event, num_events )
|
922
|
+
[events].flatten.each_with_index { |e, i|
|
923
|
+
evts[i].write_pointer(e)
|
924
|
+
}
|
925
|
+
error = OpenCL.clnqueueWaitForEvents( command_queue, num_events, evts )
|
926
|
+
else
|
927
|
+
error = OpenCL.clEnqueueBarrier( command_queue )
|
928
|
+
end
|
929
|
+
OpenCL.error_check(error)
|
930
|
+
return nil
|
931
|
+
else
|
932
|
+
num_events = [events].flatten.length
|
933
|
+
evts = nil
|
934
|
+
if num_events > 0 then
|
935
|
+
evts = FFI::MemoryPointer.new( Event, num_events )
|
936
|
+
[events].flatten.each_with_index { |e, i|
|
937
|
+
evts[i].write_pointer(e)
|
938
|
+
}
|
939
|
+
end
|
940
|
+
event = FFI::MemoryPointer.new( Event )
|
941
|
+
error = OpenCL.clEnqueueBarrierWithWaitList( command_queue, num_events, evts, event )
|
942
|
+
OpenCL.error_check(error)
|
943
|
+
return OpenCL::Event::new(event.read_pointer)
|
944
|
+
end
|
945
|
+
end
|
946
|
+
|
947
|
+
# Enqueues a marker
|
948
|
+
#
|
949
|
+
# ==== Attributes
|
950
|
+
#
|
951
|
+
# * +command_queue+ - CommandQueue used to execute the command
|
952
|
+
# * +events+ - an optional single or Array of Event to wait upon before the marker is considered finished, if not provided all previous command are waited for before the marker is considered finished (unavailable if implementation version < 1.2 )
|
953
|
+
#
|
954
|
+
# ==== Returns
|
955
|
+
#
|
956
|
+
# an Event
|
957
|
+
def self.enqueue_marker( command_queue, events = [] )
|
958
|
+
event = FFI::MemoryPointer.new( Event )
|
959
|
+
if command_queue.context.platform.version_number < 1.2 then
|
960
|
+
error = OpenCL.clEnqueueMarker( command_queue, event )
|
961
|
+
else
|
962
|
+
num_events = [events].flatten.length
|
963
|
+
evts = nil
|
964
|
+
if num_events > 0 then
|
965
|
+
evts = FFI::MemoryPointer.new( Event, num_events )
|
966
|
+
[events].flatten.each_with_index { |e, i|
|
967
|
+
evts[i].write_pointer(e)
|
968
|
+
}
|
969
|
+
end
|
970
|
+
error = OpenCL.clEnqueueMarkerWithWaitList( command_queue, num_events, evts, event )
|
971
|
+
end
|
972
|
+
OpenCL.error_check(error)
|
973
|
+
return OpenCL::Event::new(event.read_pointer)
|
974
|
+
end
|
975
|
+
|
976
|
+
# Maps the cl_command_queue object of OpenCL
|
977
|
+
class CommandQueue
|
978
|
+
|
979
|
+
# Returns the Context associated to the CommandQueue
|
980
|
+
def context
|
981
|
+
ptr = FFI::MemoryPointer.new( Context )
|
982
|
+
error = OpenCL.clGetCommandQueueInfo(self, CommandQueue::CONTEXT, Context.size, ptr, nil)
|
983
|
+
OpenCL.error_check(error)
|
984
|
+
return OpenCL::Context::new( ptr.read_pointer )
|
985
|
+
end
|
986
|
+
|
987
|
+
# Returns the Device associated to the CommandQueue
|
988
|
+
def device
|
989
|
+
ptr = FFI::MemoryPointer.new( Device )
|
990
|
+
error = OpenCL.clGetCommandQueueInfo(self, CommandQueue::DEVICE, Device.size, ptr, nil)
|
991
|
+
OpenCL.error_check(error)
|
992
|
+
return OpenCL::Device::new( ptr.read_pointer )
|
993
|
+
end
|
994
|
+
|
995
|
+
##
|
996
|
+
# :method: reference_count
|
997
|
+
# Returns the reference count of the CommandQueue
|
998
|
+
eval OpenCL.get_info("CommandQueue", :cl_uint, "REFERENCE_COUNT")
|
999
|
+
|
1000
|
+
##
|
1001
|
+
# :method: properties
|
1002
|
+
# Returns the :cl_command_queue_properties used to create the CommandQueue
|
1003
|
+
eval OpenCL.get_info("CommandQueue", :cl_command_queue_properties, "PROPERTIES")
|
1004
|
+
|
1005
|
+
# Enqueues a native kernel using the CommandQueue
|
1006
|
+
# not yet fully implemented
|
1007
|
+
#
|
1008
|
+
# ==== Attributes
|
1009
|
+
#
|
1010
|
+
# * +options+ - a hash containing named options
|
1011
|
+
# * +func+ - a Proc object to execute
|
1012
|
+
#
|
1013
|
+
# ==== Options
|
1014
|
+
#
|
1015
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
1016
|
+
#
|
1017
|
+
# ==== Returns
|
1018
|
+
#
|
1019
|
+
# the Event associated with the command
|
1020
|
+
def enqueue_native_kernel( options = {}, &func )
|
1021
|
+
return OpenCL.enqueue_native_kernel( self, options, &func )
|
1022
|
+
end
|
1023
|
+
|
1024
|
+
# Enqueues a kernel as a task using the CommandQueue
|
1025
|
+
#
|
1026
|
+
# ==== Attributes
|
1027
|
+
#
|
1028
|
+
# * +kernel+ - a Kernel object to execute
|
1029
|
+
# * +options+ - a hash containing named options
|
1030
|
+
#
|
1031
|
+
# ==== Options
|
1032
|
+
#
|
1033
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
1034
|
+
#
|
1035
|
+
# ==== Returns
|
1036
|
+
#
|
1037
|
+
# the Event associated with the command
|
1038
|
+
def enqueue_task( kernel, options = {} )
|
1039
|
+
return OpenCL.enqueue_task( self, kernel, options )
|
1040
|
+
end
|
1041
|
+
|
1042
|
+
# Enqueues a kernel as a NDrange using the CommandQueue
|
1043
|
+
#
|
1044
|
+
# ==== Attributes
|
1045
|
+
#
|
1046
|
+
# * +kernel+ - a Kernel object to execute
|
1047
|
+
# * +global_work_size+ - dimensions of the work
|
1048
|
+
# * +options+ - a hash containing named options
|
1049
|
+
#
|
1050
|
+
# ==== Options
|
1051
|
+
#
|
1052
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
1053
|
+
# * +:local_work_size+ - if provided, dimensions of the local work group size
|
1054
|
+
# * +:global_work_offset+ - if provided, offset inside the global work size
|
1055
|
+
#
|
1056
|
+
# ==== Returns
|
1057
|
+
#
|
1058
|
+
# the Event associated with the command
|
1059
|
+
def enqueue_NDrange_kernel( kernel, global_work_size, options = {} )
|
1060
|
+
return OpenCL.enqueue_NDrange_kernel( self, kernel, global_work_size, options )
|
1061
|
+
end
|
1062
|
+
|
1063
|
+
# Enqueues a command to write to a Buffer object from host memory using the CommandQueue
|
1064
|
+
#
|
1065
|
+
# ==== Attributes
|
1066
|
+
#
|
1067
|
+
# * +buffer+ - the Buffer to be written to
|
1068
|
+
# * +ptr+ - the Pointer (or convertible to Pointer using to_ptr) to the memory area to use
|
1069
|
+
# * +options+ - a hash containing named options
|
1070
|
+
#
|
1071
|
+
# ==== Options
|
1072
|
+
#
|
1073
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
1074
|
+
# * +:blocking_write+ - if provided indicates if the command blocks until the region is written.
|
1075
|
+
# * +:blocking+ - if provided indicates if the command blocks until the region is written
|
1076
|
+
# * +:offset+ - if provided indicates the offset inside the Buffer of the area to read from, else 0
|
1077
|
+
# * +:size+ - if provided indicates the size of data to copy, else the maximum data is copied
|
1078
|
+
#
|
1079
|
+
# ==== Returns
|
1080
|
+
#
|
1081
|
+
# the Event associated with the command
|
1082
|
+
def enqueue_write_buffer( buffer, ptr, options = {} )
|
1083
|
+
return OpenCL.enqueue_write_buffer( self, buffer, ptr, options )
|
1084
|
+
end
|
1085
|
+
|
1086
|
+
# Enqueues a command to write to a rectangular region in a Buffer object from host memory using the CommandQueue
|
1087
|
+
#
|
1088
|
+
# ==== Attributes
|
1089
|
+
#
|
1090
|
+
# * +buffer+ - the Buffer to be written to
|
1091
|
+
# * +ptr+ - the Pointer (or convertible to Pointer using to_ptr) to the memory area to use
|
1092
|
+
# * +region+ - the region to write in the Buffer
|
1093
|
+
# * +options+ - a hash containing named options
|
1094
|
+
#
|
1095
|
+
# ==== Options
|
1096
|
+
#
|
1097
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
1098
|
+
# * +:blocking_write+ - if provided indicates if the command blocks until the region is written
|
1099
|
+
# * +:blocking+ - if provided indicates if the command blocks until the region is written
|
1100
|
+
# * +:buffer_origin+ - if provided indicates the origin inside the buffer of the area to copy, else [0, 0, 0]
|
1101
|
+
# * +:host_origin+ - if provided indicates the origin inside the target host area, else [0, 0, 0]
|
1102
|
+
# * +:buffer_row_pitch+ - if provided indicates the row pitch inside the buffer, else 0
|
1103
|
+
# * +:buffer_slice_pitch+ - if provided indicates the slice pitch inside the buffer, else 0
|
1104
|
+
# * +:host_row_pitch+ - if provided indicates the row pitch inside the host area, else 0
|
1105
|
+
# * +:host_slice_pitch+ - if provided indicates the slice pitch inside the host area, else 0
|
1106
|
+
#
|
1107
|
+
# ==== Returns
|
1108
|
+
#
|
1109
|
+
# the Event associated with the command
|
1110
|
+
def enqueue_write_buffer_rect( buffer, ptr, region, options = {} )
|
1111
|
+
return OpenCL.enqueue_write_buffer_rect( self, buffer, ptr, region, options )
|
1112
|
+
end
|
1113
|
+
|
1114
|
+
# Enqueues a command to read from a Buffer object to host memory using the CommandQueue
|
1115
|
+
#
|
1116
|
+
# ==== Attributes
|
1117
|
+
#
|
1118
|
+
# * +buffer+ - the Buffer to be read from
|
1119
|
+
# * +ptr+ - the Pointer (or convertible to Pointer using to_ptr) to the memory area to use
|
1120
|
+
# * +options+ - a hash containing named options
|
1121
|
+
#
|
1122
|
+
# ==== Options
|
1123
|
+
#
|
1124
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
1125
|
+
# * +:blocking_read+ - if provided indicates if the command blocks until the region is read
|
1126
|
+
# * +:blocking+ - if provided indicates if the command blocks until the region is read
|
1127
|
+
# * +:offset+ - if provided indicates the offset inside the Buffer of the area to read from, else 0
|
1128
|
+
# * +:size+ - if provided indicates the size of data to copy, else the maximum data is copied
|
1129
|
+
#
|
1130
|
+
# ==== Returns
|
1131
|
+
#
|
1132
|
+
# the Event associated with the command
|
1133
|
+
def enqueue_read_buffer( buffer, ptr, options = {} )
|
1134
|
+
return OpenCL.enqueue_read_buffer( self, buffer, ptr, options)
|
1135
|
+
end
|
1136
|
+
|
1137
|
+
# Enqueues a command to read from a rectangular region from a Buffer object to host memory using the CommandQueue
|
1138
|
+
#
|
1139
|
+
# ==== Attributes
|
1140
|
+
#
|
1141
|
+
# * +buffer+ - the Buffer to be read from
|
1142
|
+
# * +ptr+ - the Pointer (or convertible to Pointer using to_ptr) to the memory area to use
|
1143
|
+
# * +region+ - the region in the Buffer to copy
|
1144
|
+
# * +options+ - a hash containing named options
|
1145
|
+
#
|
1146
|
+
# ==== Options
|
1147
|
+
#
|
1148
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
1149
|
+
# * +:blocking_read+ - if provided indicates if the command blocks until the region is read
|
1150
|
+
# * +:blocking+ - if provided indicates if the command blocks until the region is read
|
1151
|
+
# * +:buffer_origin+ - if provided indicates the origin inside the buffer of the area to copy, else [0, 0, 0]
|
1152
|
+
# * +:host_origin+ - if provided indicates the origin inside the target host area, else [0, 0, 0]
|
1153
|
+
# * +:buffer_row_pitch+ - if provided indicates the row pitch inside the buffer, else 0
|
1154
|
+
# * +:buffer_slice_pitch+ - if provided indicates the slice pitch inside the buffer, else 0
|
1155
|
+
# * +:host_row_pitch+ - if provided indicates the row pitch inside the host area, else 0
|
1156
|
+
# * +:host_slice_pitch+ - if provided indicates the slice pitch inside the host area, else 0
|
1157
|
+
#
|
1158
|
+
# ==== Returns
|
1159
|
+
#
|
1160
|
+
# the Event associated with the command
|
1161
|
+
def enqueue_read_buffer_rect( buffer, ptr, region, options = {} )
|
1162
|
+
return OpenCL.enqueue_read_buffer_rect( self, buffer, ptr, region, options )
|
1163
|
+
end
|
1164
|
+
|
1165
|
+
# Enqueues a command to copy data from a Buffer object into another Buffer object using the CommandQueue
|
1166
|
+
#
|
1167
|
+
# ==== Attributes
|
1168
|
+
#
|
1169
|
+
# * +src_buffer+ - the Buffer to be read from
|
1170
|
+
# * +dst_buffer+ - the Buffer to be written to
|
1171
|
+
# * +options+ - a hash containing named options
|
1172
|
+
#
|
1173
|
+
# ==== Options
|
1174
|
+
#
|
1175
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
1176
|
+
# * +:src_offset+ - if provided indicates the offset inside the src Buffer of the area to copy, else 0
|
1177
|
+
# * +:dst_offset+ - if provided indicates the offset inside the dst Buffer of the area to write to, else 0
|
1178
|
+
# * +:size+ - if provided indicates the size of data to copy, else the maximum possible is copied
|
1179
|
+
#
|
1180
|
+
# ==== Returns
|
1181
|
+
#
|
1182
|
+
# the Event associated with the command
|
1183
|
+
def enqueue_copy_buffer( src_buffer, dst_buffer, options = {} )
|
1184
|
+
return OpenCL.enqueue_copy_buffer( self, src_buffer, dst_buffer, options )
|
1185
|
+
end
|
1186
|
+
|
1187
|
+
# Enqueues a command to copy a rectangular region into a Buffer object from another Buffer object using the CommandQueue
|
1188
|
+
#
|
1189
|
+
# ==== Attributes
|
1190
|
+
#
|
1191
|
+
# * +src_buffer+ - the Buffer to be read from
|
1192
|
+
# * +dst_buffer+ - the Buffer to be written to
|
1193
|
+
# * +region+ - the region to write in the Buffer
|
1194
|
+
# * +options+ - a hash containing named options
|
1195
|
+
#
|
1196
|
+
# ==== Options
|
1197
|
+
#
|
1198
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
1199
|
+
# * +:src_origin+ - if provided indicates the origin inside the src Buffer of the area to copy, else [0, 0, 0]
|
1200
|
+
# * +:dst_origin+ - if provided indicates the origin inside the dst Buffer of the area to write to, else [0, 0, 0]
|
1201
|
+
# * +:src_row_pitch+ - if provided indicates the row pitch inside the src Buffer, else 0
|
1202
|
+
# * +:src_slice_pitch+ - if provided indicates the slice pitch inside the src Buffer, else 0
|
1203
|
+
# * +:dst_row_pitch+ - if provided indicates the row pitch inside the dst Buffer, else 0
|
1204
|
+
# * +:dst_slice_pitch+ - if provided indicates the slice pitch inside the dst Buffer area, else 0
|
1205
|
+
#
|
1206
|
+
# ==== Returns
|
1207
|
+
#
|
1208
|
+
# the Event associated with the command
|
1209
|
+
def enqueue_copy_buffer_rect( src_buffer, dst_buffer, region, options = {} )
|
1210
|
+
return OpenCL.enqueue_copy_buffer_rect( self, src_buffer, dst_buffer, region, options )
|
1211
|
+
end
|
1212
|
+
|
1213
|
+
# Enqueues a barrier on a list of envents using the CommandQueue
|
1214
|
+
#
|
1215
|
+
# ==== Attributes
|
1216
|
+
#
|
1217
|
+
# * +events+ - a single or an Array of Event to wait upon before the barrier is considered finished
|
1218
|
+
#
|
1219
|
+
# ==== Returns
|
1220
|
+
#
|
1221
|
+
# an Event if implementation version is >= 1.2, nil otherwise
|
1222
|
+
def enqueue_barrier( events )
|
1223
|
+
return OpenCL.enqueue_barrier( self, events )
|
1224
|
+
end
|
1225
|
+
|
1226
|
+
# Enqueues a marker using the CommandQueue
|
1227
|
+
#
|
1228
|
+
# ==== Attributes
|
1229
|
+
#
|
1230
|
+
# * +events+ - an optional single or Array of Event to wait upon before the marker is considered finished, if not provided all previous command are waited for before the marker is considered finished (unavailable if implementation version < 1.2 )
|
1231
|
+
#
|
1232
|
+
# ==== Returns
|
1233
|
+
#
|
1234
|
+
# an Event
|
1235
|
+
def enqueue_marker( events = [] )
|
1236
|
+
return OpenCL.enqueue_marker( self, events )
|
1237
|
+
end
|
1238
|
+
|
1239
|
+
# Enqueues a barrier on a list of envents using the CommandQueue
|
1240
|
+
#
|
1241
|
+
# ==== Attributes
|
1242
|
+
#
|
1243
|
+
# * +events+ - a single or an Array of Event to wait upon before the barrier is considered finished
|
1244
|
+
#
|
1245
|
+
# ==== Returns
|
1246
|
+
#
|
1247
|
+
# an Event if implementation version is >= 1.2, nil otherwise
|
1248
|
+
def enqueue_wait_for_events( events = [] )
|
1249
|
+
return OpenCL.enqueue_wait_for_events( self, events )
|
1250
|
+
end
|
1251
|
+
|
1252
|
+
# Enqueues a command to copy from host memory into an Image using the CommandQueue
|
1253
|
+
#
|
1254
|
+
# ==== Attributes
|
1255
|
+
#
|
1256
|
+
# * +image+ - the Image to be written to
|
1257
|
+
# * +ptr+ - the Pointer (or convertible to Pointer using to_ptr) to the memory area to use
|
1258
|
+
# * +options+ - a hash containing named options
|
1259
|
+
#
|
1260
|
+
# ==== Options
|
1261
|
+
#
|
1262
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
1263
|
+
# * +:blocking_write+ - if provided indicates if the command blocks until the region is written.
|
1264
|
+
# * +:blocking+ - if provided indicates if the command blocks until the region is written
|
1265
|
+
# * +:origin+ - if provided indicates the origin of the region to write into the Image, else [0, 0, 0]
|
1266
|
+
# * +:region+ - if provided indicates the dimension of the region to copy, else the maximum region is copied
|
1267
|
+
# * +:input_row_pitch+ - if provided indicates the row pitch inside the host area, else 0
|
1268
|
+
# * +:input_slice_pitch+ - if provided indicates the slice pitch inside the host area, else 0
|
1269
|
+
#
|
1270
|
+
# ==== Returns
|
1271
|
+
#
|
1272
|
+
# the Event associated with the command
|
1273
|
+
def enqueue_write_image( image, ptr, options = {} )
|
1274
|
+
return OpenCL.enqueue_write_image( self, image, ptr, options )
|
1275
|
+
end
|
1276
|
+
|
1277
|
+
# Enqueues a command to copy from an Image into host memory using the CommandQueue
|
1278
|
+
#
|
1279
|
+
# ==== Attributes
|
1280
|
+
#
|
1281
|
+
# * +image+ - the Image to be written to
|
1282
|
+
# * +ptr+ - the Pointer (or convertible to Pointer using to_ptr) to the memory area to use
|
1283
|
+
# * +options+ - a hash containing named options
|
1284
|
+
#
|
1285
|
+
# ==== Options
|
1286
|
+
#
|
1287
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
1288
|
+
# * +:blocking_read+ - if provided indicates if the command blocks until the region is read.
|
1289
|
+
# * +:blocking+ - if provided indicates if the command blocks until the region is read
|
1290
|
+
# * +:origin+ - if provided indicates the origin of the region to read from the Image, else [0, 0, 0]
|
1291
|
+
# * +:region+ - if provided indicates the dimension of the region to copy, else the maximum region is copied
|
1292
|
+
# * +:row_pitch+ - if provided indicates the row pitch inside the host area, else 0
|
1293
|
+
# * +:slice_pitch+ - if provided indicates the slice pitch inside the host area, else 0
|
1294
|
+
#
|
1295
|
+
# ==== Returns
|
1296
|
+
#
|
1297
|
+
# the Event associated with the command
|
1298
|
+
def enqueue_read_image( image, ptr, options = {} )
|
1299
|
+
return OpenCL.enqueue_read_image( self, image, ptr, options )
|
1300
|
+
end
|
1301
|
+
|
1302
|
+
# Enqueues a command to copy from an Image into an Image using the CommandQueue
|
1303
|
+
#
|
1304
|
+
# ==== Attributes
|
1305
|
+
#
|
1306
|
+
# * +src_image+ - the Image to be written to
|
1307
|
+
# * +dst_image+ - the Image to be written to
|
1308
|
+
# * +options+ - a hash containing named options
|
1309
|
+
#
|
1310
|
+
# ==== Options
|
1311
|
+
#
|
1312
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
1313
|
+
# * +:src_origin+ - if provided indicates the origin of the region to read into the src Image, else [0, 0, 0]
|
1314
|
+
# * +:dst_origin+ - if provided indicates the origin of the region to write into the dst Image, else [0, 0, 0]
|
1315
|
+
# * +:region+ - if provided indicates the dimension of the region to copy, else the maximum region is copied
|
1316
|
+
#
|
1317
|
+
# ==== Returns
|
1318
|
+
#
|
1319
|
+
# the Event associated with the command
|
1320
|
+
def enqueue_copy_image( src_image, dst_image, options = {} )
|
1321
|
+
return OpenCL.enqueue_copy_image( self, src_image, dst_image, options )
|
1322
|
+
end
|
1323
|
+
|
1324
|
+
# Enqueues a command to copy a Buffer into an Image using the CommandQueue
|
1325
|
+
#
|
1326
|
+
# ==== Attributes
|
1327
|
+
#
|
1328
|
+
# * +src_buffer+ - the Buffer to be read from
|
1329
|
+
# * +dst_image+ - the Image to be written to
|
1330
|
+
# * +options+ - a hash containing named options
|
1331
|
+
#
|
1332
|
+
# ==== Options
|
1333
|
+
#
|
1334
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
1335
|
+
# * +:dst_origin+ - if provided indicates the origin of the region to write into the Image, else [0, 0, 0]
|
1336
|
+
# * +:region+ - if provided indicates the dimension of the region to copy, else the maximum region is copied
|
1337
|
+
# * +:src_offset+ - if provided indicates the offset inside the Buffer, else 0
|
1338
|
+
#
|
1339
|
+
# ==== Returns
|
1340
|
+
#
|
1341
|
+
# the Event associated with the command
|
1342
|
+
def enqueue_copy_buffer_to_image( src_buffer, dst_image, options = {} )
|
1343
|
+
return OpenCL.enqueue_copy_buffer_to_image( self, src_buffer, dst_image, options )
|
1344
|
+
end
|
1345
|
+
|
1346
|
+
# Enqueues a command to copy an Image into a Buffer using the CommandQueue
|
1347
|
+
#
|
1348
|
+
# ==== Attributes
|
1349
|
+
#
|
1350
|
+
# * +src_image+ - the Image to be read from
|
1351
|
+
# * +dst_buffer+ - the Buffer to be written to
|
1352
|
+
# * +options+ - a hash containing named options
|
1353
|
+
#
|
1354
|
+
# ==== Options
|
1355
|
+
#
|
1356
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
1357
|
+
# * +:src_origin+ - if provided indicates the origin of the region to copy from the Image, else [0, 0, 0]
|
1358
|
+
# * +:region+ - if provided indicates the dimension of the region to copy, else the maximum region is copied
|
1359
|
+
# * +:dst_offset+ - if provided indicates the offset inside the Buffer, else 0
|
1360
|
+
#
|
1361
|
+
# ==== Returns
|
1362
|
+
#
|
1363
|
+
# the Event associated with the command
|
1364
|
+
def enqueue_copy_image_to_buffer( src_image, dst_buffer, options = {} )
|
1365
|
+
return OpenCL.enqueue_copy_image_to_buffer( self, src_image, dst_buffer, options )
|
1366
|
+
end
|
1367
|
+
|
1368
|
+
# Enqueues a command to fill an Image with the given color using the CommandQueue
|
1369
|
+
#
|
1370
|
+
# ==== Attributes
|
1371
|
+
#
|
1372
|
+
# * +image+ - an Image object to be filled
|
1373
|
+
# * +fill_color+ - the Pointer (or convertible to Pointer using to_ptr) to the memory area where the color is stored
|
1374
|
+
# * +options+ - a hash containing named options
|
1375
|
+
#
|
1376
|
+
# ==== Options
|
1377
|
+
#
|
1378
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
1379
|
+
# * +:origin+ - if provided indicates the origin of the region to fill inside the Image, else [0, 0, 0]
|
1380
|
+
# * +:region+ - if provided indicates the dimension of the region to fill, else the maximum region is filled
|
1381
|
+
#
|
1382
|
+
# ==== Returns
|
1383
|
+
#
|
1384
|
+
# the Event associated with the command
|
1385
|
+
def enqueue_fill_image( image, fill_color, options = {} )
|
1386
|
+
return OpenCL.enqueue_fill_image( self, image, fill_color, options )
|
1387
|
+
end
|
1388
|
+
|
1389
|
+
# Enqueues a command to fill a Buffer with the given pattern using the CommandQueue
|
1390
|
+
#
|
1391
|
+
# ==== Attributes
|
1392
|
+
#
|
1393
|
+
# * +buffer+ - a Buffer object to be filled
|
1394
|
+
# * +pattern+ - the Pointer (or convertible to Pointer using to_ptr) to the memory area where the pattern is stored
|
1395
|
+
# * +options+ - a hash containing named options
|
1396
|
+
#
|
1397
|
+
# ==== Options
|
1398
|
+
#
|
1399
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
1400
|
+
# * +:offset+ - if provided indicates the offset inside the Buffer of the area to be filled, else 0
|
1401
|
+
# * +:size+ - if provided indicates the size of data to fill, else the maximum size is filled
|
1402
|
+
# * +:pattern_size+ - if provided indicates the size of the pattern, else the maximum pattern data is used
|
1403
|
+
#
|
1404
|
+
# ==== Returns
|
1405
|
+
#
|
1406
|
+
# the Event associated with the command
|
1407
|
+
def enqueue_fill_buffer( buffer, pattern, options = {} )
|
1408
|
+
return OpenCL.enqueue_fill_buffer( self, buffer, pattern, options )
|
1409
|
+
end
|
1410
|
+
|
1411
|
+
# Acquire OpenCL Mem objects that have been created from OpenGL objects using the CommandQueue
|
1412
|
+
#
|
1413
|
+
# ==== Attributes
|
1414
|
+
#
|
1415
|
+
# * +mem_objects+ - a single or an Array of Mem objects
|
1416
|
+
# * +options+ - a hash containing named options
|
1417
|
+
#
|
1418
|
+
# ==== Options
|
1419
|
+
#
|
1420
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
1421
|
+
#
|
1422
|
+
# ==== Returns
|
1423
|
+
#
|
1424
|
+
# the Event associated with the command
|
1425
|
+
def enqueue_acquire_GL_object( mem_objects, options = {} )
|
1426
|
+
return OpenCL.enqueue_acquire_GL_object( self, mem_objects, options )
|
1427
|
+
end
|
1428
|
+
|
1429
|
+
# Release OpenCL Mem objects that have been created from OpenGL objects and previously acquired using the CommandQueue
|
1430
|
+
#
|
1431
|
+
# ==== Attributes
|
1432
|
+
#
|
1433
|
+
# * +mem_objects+ - a single or an Array of Mem objects
|
1434
|
+
# * +options+ - a hash containing named options
|
1435
|
+
#
|
1436
|
+
# ==== Options
|
1437
|
+
#
|
1438
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
1439
|
+
#
|
1440
|
+
# ==== Returns
|
1441
|
+
#
|
1442
|
+
# the Event associated with the command
|
1443
|
+
def enqueue_release_GL_object( mem_objects, options = {} )
|
1444
|
+
return OpenCL.enqueue_release_GL_object( self, mem_objects, options )
|
1445
|
+
end
|
1446
|
+
|
1447
|
+
# Enqueues a command to map an Image into host memory using the CommandQueue
|
1448
|
+
#
|
1449
|
+
# ==== Attributes
|
1450
|
+
#
|
1451
|
+
# * +buffer+ - the Buffer object to map
|
1452
|
+
# * +map_flags+ - a single or an Array of :cl_map_flags flags
|
1453
|
+
# * +options+ - a hash containing named options
|
1454
|
+
#
|
1455
|
+
# ==== Options
|
1456
|
+
#
|
1457
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
1458
|
+
# * +:blocking_map+ - if provided indicates if the command blocks until the region is mapped
|
1459
|
+
# * +:blocking+ - if provided indicates if the command blocks until the region is mapped
|
1460
|
+
# * +:offset+ - if provided the offset inside the Buffer region to map, else 0
|
1461
|
+
# * +:size+ - if provided the size of the region in the Buffer to map, else the largest possible size is used
|
1462
|
+
#
|
1463
|
+
# ==== Returns
|
1464
|
+
#
|
1465
|
+
# an Array composed of [event, pointer] where:
|
1466
|
+
# * +event+ - the Event associated with the command
|
1467
|
+
# * +pointer+ - a Pointer to the mapped memory region
|
1468
|
+
def enqueue_map_buffer( buffer, map_flags, options = {} )
|
1469
|
+
return OpenCL.enqueue_map_buffer( self, buffer, map_flags, options )
|
1470
|
+
end
|
1471
|
+
|
1472
|
+
# Enqueues a command to map an Image into host memory using the CommandQueue
|
1473
|
+
#
|
1474
|
+
# ==== Attributes
|
1475
|
+
#
|
1476
|
+
# * +image+ - the Image object to map
|
1477
|
+
# * +map_flags+ - a single or an Array of :cl_map_flags flags
|
1478
|
+
# * +options+ - a hash containing named options
|
1479
|
+
#
|
1480
|
+
# ==== Options
|
1481
|
+
#
|
1482
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
1483
|
+
# * +:blocking_map+ - if provided indicates if the command blocks until the region is mapped
|
1484
|
+
# * +:blocking+ - if provided indicates if the command blocks until the region is mapped
|
1485
|
+
# * +:origin+ - if provided the origin in the Image of the region to map, else [0, 0, 0]
|
1486
|
+
# * +:region+ - if provided the region in the image to map, else the largest possible area is used
|
1487
|
+
#
|
1488
|
+
# ==== Returns
|
1489
|
+
#
|
1490
|
+
# an Array composed of [event, pointer, image_row_pitch, image_slice_pitch] where:
|
1491
|
+
# * +event+ - the Event associated with the command
|
1492
|
+
# * +pointer+ - a Pointer to the mapped memory region
|
1493
|
+
# * +image_row_pitch+ - the row pitch of the mapped region
|
1494
|
+
# * +image_slice_pitch+ - the slice pitch of the mapped region
|
1495
|
+
def enqueue_map_image( image, map_flags, options = {} )
|
1496
|
+
return OpenCL.enqueue_map_image( self, image, map_flags, options )
|
1497
|
+
end
|
1498
|
+
|
1499
|
+
# Enqueues a command to unmap a previously mapped region of a memory object using the CommandQueue
|
1500
|
+
#
|
1501
|
+
# ==== Attributes
|
1502
|
+
#
|
1503
|
+
# * +mem_obj+ - the Mem object that was previously mapped
|
1504
|
+
# * +mapped_ptr+ - the Pointer previously returned by a map command
|
1505
|
+
# * +options+ - a hash containing named options
|
1506
|
+
#
|
1507
|
+
# ==== Options
|
1508
|
+
#
|
1509
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
1510
|
+
#
|
1511
|
+
# ==== Returns
|
1512
|
+
#
|
1513
|
+
# the Event associated with the command
|
1514
|
+
def enqueue_unmap_mem_object( command_queue, mem_obj, mapped_ptr, options = {} )
|
1515
|
+
return OpenCL.enqueue_unmap_mem_object( self, mem_obj, mapped_ptr, options )
|
1516
|
+
end
|
1517
|
+
|
1518
|
+
# Enqueues a command to indicate which device a set of memory objects should be migrated to using the CommandQueue
|
1519
|
+
#
|
1520
|
+
# ==== Attributes
|
1521
|
+
#
|
1522
|
+
# * +mem_objects+ - the Mem objects to migrate
|
1523
|
+
# * +options+ - a hash containing named options
|
1524
|
+
#
|
1525
|
+
# ==== Options
|
1526
|
+
#
|
1527
|
+
# * +:flags+ - a single or an Array of :cl_mem_migration flags
|
1528
|
+
# * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
|
1529
|
+
#
|
1530
|
+
# ==== Returns
|
1531
|
+
#
|
1532
|
+
# the Event associated with the command
|
1533
|
+
def enqueue_migrate_mem_objects( mem_objects, options = {} )
|
1534
|
+
return OpenCL.enqueue_migrate_mem_objects( self, mem_objects, options )
|
1535
|
+
end
|
1536
|
+
|
1537
|
+
# Blocks until all the commands in the CommandQueue have completed
|
1538
|
+
def finish
|
1539
|
+
return OpenCL.finish(self)
|
1540
|
+
end
|
1541
|
+
|
1542
|
+
end
|
1543
|
+
|
1544
|
+
end
|