opencl_ruby_ffi 0.993 → 0.994
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/opencl_ruby_ffi/Buffer.rb +13 -13
- data/lib/opencl_ruby_ffi/CommandQueue.rb +177 -177
- data/lib/opencl_ruby_ffi/Context.rb +11 -13
- data/lib/opencl_ruby_ffi/Device.rb +20 -20
- data/lib/opencl_ruby_ffi/Event.rb +22 -20
- data/lib/opencl_ruby_ffi/Image.rb +42 -42
- data/lib/opencl_ruby_ffi/Kernel.rb +28 -28
- data/lib/opencl_ruby_ffi/Mem.rb +9 -8
- data/lib/opencl_ruby_ffi/Pipe.rb +5 -5
- data/lib/opencl_ruby_ffi/Platform.rb +17 -17
- data/lib/opencl_ruby_ffi/Program.rb +32 -32
- data/lib/opencl_ruby_ffi/SVM.rb +42 -42
- data/lib/opencl_ruby_ffi/Sampler.rb +14 -14
- data/lib/opencl_ruby_ffi/opencl_ruby_ffi_base.rb +29 -29
- data/lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb +1 -55
- data/opencl_ruby_ffi.gemspec +2 -2
- metadata +3 -3
@@ -16,22 +16,20 @@ module OpenCL
|
|
16
16
|
@@callbacks.push( block ) if block
|
17
17
|
devs = [devices].flatten
|
18
18
|
pointer = FFI::MemoryPointer::new( Device, devs.size)
|
19
|
-
devs
|
20
|
-
|
21
|
-
}
|
22
|
-
properties = OpenCL.get_context_properties( options )
|
19
|
+
pointer.write_array_of_pointer(devs)
|
20
|
+
properties = get_context_properties( options )
|
23
21
|
user_data = options[:user_data]
|
24
22
|
error = FFI::MemoryPointer::new( :cl_int )
|
25
|
-
ptr =
|
26
|
-
|
27
|
-
return
|
23
|
+
ptr = clCreateContext(properties, devs.size, pointer, block, user_data, error)
|
24
|
+
error_check(error.read_cl_int)
|
25
|
+
return Context::new(ptr, false)
|
28
26
|
end
|
29
27
|
|
30
28
|
# Creates an Context using devices of the selected type
|
31
29
|
#
|
32
30
|
# ==== Attributes
|
33
31
|
#
|
34
|
-
# * +type+ -
|
32
|
+
# * +type+ - a Device::Type
|
35
33
|
# * +options+ - a hash containing named options
|
36
34
|
# * +block+ - if provided, a callback invoked when error arise in the context. Signature of the callback is { |FFI::Pointer to null terminated c string, FFI::Pointer to binary data, :size_t number of bytes of binary data, FFI::Pointer to user_data| ... }
|
37
35
|
#
|
@@ -41,12 +39,12 @@ module OpenCL
|
|
41
39
|
# * +:user_data+ - an FFI::Pointer or an object that can be converted into one using to_ptr. The pointer is passed to the callback.
|
42
40
|
def self.create_context_from_type(type, options = {}, &block)
|
43
41
|
@@callbacks.push( block ) if block
|
44
|
-
properties =
|
42
|
+
properties = get_context_properties( options )
|
45
43
|
user_data = options[:user_data]
|
46
44
|
error = FFI::MemoryPointer::new( :cl_int )
|
47
|
-
ptr =
|
48
|
-
|
49
|
-
return
|
45
|
+
ptr = clCreateContextFromType(properties, type, block, user_data, error)
|
46
|
+
error_check(error.read_cl_int)
|
47
|
+
return Context::new(ptr, false)
|
50
48
|
end
|
51
49
|
|
52
50
|
#Maps the cl_context object of OpenCL
|
@@ -206,7 +204,7 @@ module OpenCL
|
|
206
204
|
# * +:miplevel+ - a :GLint specifying the mipmap level to be used (default 0)
|
207
205
|
# * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Image
|
208
206
|
def create_from_GL_texture_2D( texture_target, texture, options = {} )
|
209
|
-
return OpenCL.create_from_GL_texture_2D( self, texture_target, texture, options
|
207
|
+
return OpenCL.create_from_GL_texture_2D( self, texture_target, texture, options )
|
210
208
|
end
|
211
209
|
|
212
210
|
# Creates an Image in the Context from an OpenGL 3D texture
|
@@ -11,21 +11,21 @@ module OpenCL
|
|
11
11
|
#
|
12
12
|
# an Array of Device
|
13
13
|
def self.create_sub_devices( in_device, properties )
|
14
|
-
|
14
|
+
error_check(INVALID_OPERATION) if in_device.platform.version_number < 1.2
|
15
15
|
props = FFI::MemoryPointer::new( :cl_device_partition_property, properties.length + 1 )
|
16
16
|
properties.each_with_index { |e,i|
|
17
17
|
props[i].write_cl_device_partition_property(e)
|
18
18
|
}
|
19
19
|
props[properties.length].write_cl_device_partition_property(0)
|
20
20
|
device_number_ptr = FFI::MemoryPointer::new( :cl_uint )
|
21
|
-
error =
|
22
|
-
|
21
|
+
error = clCreateSubDevice( in_device, props, 0, nil, device_number_ptr )
|
22
|
+
error_check(error)
|
23
23
|
device_number = device_number_ptr.read_cl_uint
|
24
|
-
devices_ptr = FFI::MemoryPointer::new(
|
25
|
-
error =
|
26
|
-
|
24
|
+
devices_ptr = FFI::MemoryPointer::new( Device, device_number )
|
25
|
+
error = clCreateSubDevice( in_device, props, device_number, devices_ptr, nil )
|
26
|
+
error_check(error)
|
27
27
|
devices_ptr.get_array_of_pointer(0, device_number).collect { |device_ptr|
|
28
|
-
|
28
|
+
Device::new(device_ptr, false)
|
29
29
|
}
|
30
30
|
end
|
31
31
|
|
@@ -39,10 +39,10 @@ module OpenCL
|
|
39
39
|
# Returns an Array of String corresponding to the Device extensions
|
40
40
|
def extensions
|
41
41
|
extensions_size = FFI::MemoryPointer::new( :size_t )
|
42
|
-
error = OpenCL.clGetDeviceInfo( self,
|
42
|
+
error = OpenCL.clGetDeviceInfo( self, EXTENSIONS, 0, nil, extensions_size)
|
43
43
|
OpenCL.error_check(error)
|
44
44
|
ext = FFI::MemoryPointer::new( extensions_size.read_size_t )
|
45
|
-
error = OpenCL.clGetDeviceInfo( self,
|
45
|
+
error = OpenCL.clGetDeviceInfo( self, EXTENSIONS, extensions_size.read_size_t, ext, nil)
|
46
46
|
OpenCL.error_check(error)
|
47
47
|
ext_string = ext.read_string
|
48
48
|
return ext_string.split(" ")
|
@@ -51,10 +51,10 @@ module OpenCL
|
|
51
51
|
# Returns an Array of String corresponding to the Device built in kernel names
|
52
52
|
def built_in_kernels
|
53
53
|
built_in_kernels_size = FFI::MemoryPointer::new( :size_t )
|
54
|
-
error = OpenCL.clGetDeviceInfo( self,
|
54
|
+
error = OpenCL.clGetDeviceInfo( self, BUILT_IN_KERNELS, 0, nil, built_in_kernels_size)
|
55
55
|
OpenCL.error_check(error)
|
56
56
|
ker = FFI::MemoryPointer::new( built_in_kernels_size.read_size_t )
|
57
|
-
error = OpenCL.clGetDeviceInfo( self,
|
57
|
+
error = OpenCL.clGetDeviceInfo( self, BUILT_IN_KERNELS, built_in_kernels_size.read_size_t, ker, nil)
|
58
58
|
OpenCL.error_check(error)
|
59
59
|
ker_string = ext.read_string
|
60
60
|
return ker_string.split(";")
|
@@ -144,7 +144,7 @@ module OpenCL
|
|
144
144
|
prop_names = []
|
145
145
|
props = self.partition_properties
|
146
146
|
%w( PARTITION_EQUALLY PARTITION_BY_COUNTS PARTITION_BY_AFFINITY_DOMAIN ).each { |prop|
|
147
|
-
prop_names.push(prop) if props.include?(
|
147
|
+
prop_names.push(prop) if props.include?(Device.const_get(prop))
|
148
148
|
}
|
149
149
|
end
|
150
150
|
|
@@ -156,18 +156,18 @@ module OpenCL
|
|
156
156
|
# Returns the platform the Device belongs to
|
157
157
|
def platform
|
158
158
|
ptr = FFI::MemoryPointer::new( OpenCL::Platform )
|
159
|
-
error = OpenCL.clGetDeviceInfo(self,
|
159
|
+
error = OpenCL.clGetDeviceInfo(self, PLATFORM, OpenCL::Platform.size, ptr, nil)
|
160
160
|
OpenCL.error_check(error)
|
161
161
|
return OpenCL::Platform::new(ptr.read_pointer)
|
162
162
|
end
|
163
163
|
|
164
164
|
# Returns the parent Device if it exists
|
165
165
|
def parent_device
|
166
|
-
ptr = FFI::MemoryPointer::new(
|
167
|
-
error = OpenCL.clGetDeviceInfo(self,
|
166
|
+
ptr = FFI::MemoryPointer::new( Device )
|
167
|
+
error = OpenCL.clGetDeviceInfo(self, PARENT_DEVICE, Device.size, ptr, nil)
|
168
168
|
OpenCL.error_check(error)
|
169
169
|
return nil if ptr.null?
|
170
|
-
return
|
170
|
+
return Device::new(ptr.read_pointer)
|
171
171
|
end
|
172
172
|
|
173
173
|
# Partitions the Device in serveral sub-devices
|
@@ -192,8 +192,8 @@ module OpenCL
|
|
192
192
|
# ==== Returns
|
193
193
|
#
|
194
194
|
# an Array of Device
|
195
|
-
def partition_by_affinity_domain( affinity_domain =
|
196
|
-
return OpenCL.create_sub_devices( self, [
|
195
|
+
def partition_by_affinity_domain( affinity_domain = AFFINITY_DOMAIN_NEXT_PARTITIONABLE )
|
196
|
+
return OpenCL.create_sub_devices( self, [ PARTITION_BY_AFFINITY_DOMAIN, affinity_domain ] )
|
197
197
|
end
|
198
198
|
|
199
199
|
# Partitions the Device in serveral sub-devices containing compute_unit_number compute units
|
@@ -206,7 +206,7 @@ module OpenCL
|
|
206
206
|
#
|
207
207
|
# an Array of Device
|
208
208
|
def partition_equally( compute_unit_number = 1 )
|
209
|
-
return OpenCL.create_sub_devices( self, [
|
209
|
+
return OpenCL.create_sub_devices( self, [ PARTITION_EQUALLY, compute_unit_number ] )
|
210
210
|
end
|
211
211
|
|
212
212
|
# Partitions the Device in serveral sub-devices each containing a specific number of compute units
|
@@ -219,7 +219,7 @@ module OpenCL
|
|
219
219
|
#
|
220
220
|
# an Array of Device
|
221
221
|
def partition_by_count( compute_unit_number_list = [1] )
|
222
|
-
return OpenCL.create_sub_devices( self, [
|
222
|
+
return OpenCL.create_sub_devices( self, [ PARTITION_BY_COUNTS] + compute_unit_number_list + [ PARTITION_BY_COUNTS_LIST_END ] )
|
223
223
|
end
|
224
224
|
|
225
225
|
end
|
@@ -6,9 +6,9 @@ module OpenCL
|
|
6
6
|
#
|
7
7
|
# * +event_list+ - a single or an Array of Event to wait upon before returning
|
8
8
|
def self.wait_for_events(event_list)
|
9
|
-
num_events, events =
|
10
|
-
error =
|
11
|
-
|
9
|
+
num_events, events = get_event_wait_list( {:event_wait_list => event_list } )
|
10
|
+
error = clWaitForEvents(num_events, events)
|
11
|
+
error_check(error)
|
12
12
|
return nil
|
13
13
|
end
|
14
14
|
|
@@ -17,6 +17,7 @@ module OpenCL
|
|
17
17
|
# ==== Attributes
|
18
18
|
#
|
19
19
|
# * +event+ - the Event to attach the callback to
|
20
|
+
# * +command_exec_callback_type+ - a CommandExecutionStatus
|
20
21
|
# * +options+ - a hash containing named options
|
21
22
|
# * +block+ - a callback invoked when the given event occurs. Signature of the callback is { |Event, :cl_int event_command_exec_status, FFI::Pointer to user_data| ... }
|
22
23
|
#
|
@@ -24,9 +25,9 @@ module OpenCL
|
|
24
25
|
#
|
25
26
|
# * +:user_data+ - a Pointer (or convertible to Pointer using to_ptr) to the memory area to pass to the callback
|
26
27
|
def self.set_event_callback( event, command_exec_callback_type, options = {}, &proc )
|
27
|
-
|
28
|
-
error =
|
29
|
-
|
28
|
+
error_check(INVALID_OPERATION) if event.context.platform.version_number < 1.1
|
29
|
+
error = clSetEventCallback( event, command_exec_callback_type, proc, options[:user_data] )
|
30
|
+
error_check(error)
|
30
31
|
return self
|
31
32
|
end
|
32
33
|
|
@@ -36,18 +37,18 @@ module OpenCL
|
|
36
37
|
#
|
37
38
|
# * +context+ - Context the created Event will be associated to
|
38
39
|
def self.create_user_event(context)
|
39
|
-
|
40
|
+
error_check(INVALID_OPERATION) if context.platform.version_number < 1.1
|
40
41
|
error = FFI::MemoryPointer::new(:cl_int)
|
41
|
-
event =
|
42
|
-
|
43
|
-
return
|
42
|
+
event = clCreateUserEvent(context, error)
|
43
|
+
error_check(error.read_cl_int)
|
44
|
+
return Event::new(event, false)
|
44
45
|
end
|
45
46
|
|
46
47
|
# Sets the satus of user Event to the given execution status
|
47
48
|
def self.set_user_event_status( event, execution_status )
|
48
|
-
|
49
|
-
error =
|
50
|
-
|
49
|
+
error_check(INVALID_OPERATION) if event.context.platform.version_number < 1.1
|
50
|
+
error = clSetUserEventStatus( event, execution_status )
|
51
|
+
error_check(error)
|
51
52
|
return self
|
52
53
|
end
|
53
54
|
|
@@ -59,9 +60,9 @@ module OpenCL
|
|
59
60
|
# # * +sync+ - a :GLsync representing the name of the sync object
|
60
61
|
# def self.create_event_from_GL_sync_KHR( context, sync )
|
61
62
|
# error = FFI::MemoryPointer::new(:cl_int)
|
62
|
-
# event =
|
63
|
-
#
|
64
|
-
# return
|
63
|
+
# event = clCreateEventFromGLsyncKHR(context, sync, error)
|
64
|
+
# error_check(error.read_cl_int)
|
65
|
+
# return Event::new(event, false)
|
65
66
|
# end
|
66
67
|
|
67
68
|
# Maps the cl_event object
|
@@ -70,7 +71,7 @@ module OpenCL
|
|
70
71
|
# Returns the CommandQueue associated with the Event, if it exists
|
71
72
|
def command_queue
|
72
73
|
ptr = FFI::MemoryPointer::new( OpenCL::CommandQueue )
|
73
|
-
error = OpenCL.clGetEventInfo(self,
|
74
|
+
error = OpenCL.clGetEventInfo(self, COMMAND_QUEUE, OpenCL::CommandQueue.size, ptr, nil)
|
74
75
|
OpenCL.error_check(error)
|
75
76
|
pt = ptr.read_pointer
|
76
77
|
if pt.null? then
|
@@ -83,7 +84,7 @@ module OpenCL
|
|
83
84
|
# Returns the Context associated with the Event
|
84
85
|
def context
|
85
86
|
ptr = FFI::MemoryPointer::new( OpenCL::Context )
|
86
|
-
error = OpenCL.clGetEventInfo(self,
|
87
|
+
error = OpenCL.clGetEventInfo(self, CONTEXT, OpenCL::Context.size, ptr, nil)
|
87
88
|
OpenCL.error_check(error)
|
88
89
|
return OpenCL::Context::new( ptr.read_pointer )
|
89
90
|
end
|
@@ -94,7 +95,7 @@ module OpenCL
|
|
94
95
|
# Returns a CommandExecutionStatus corresponding to the status of the command associtated with the Event
|
95
96
|
def command_execution_status
|
96
97
|
ptr = FFI::MemoryPointer::new( :cl_int )
|
97
|
-
error = OpenCL.clGetEventInfo(self,
|
98
|
+
error = OpenCL.clGetEventInfo(self, COMMAND_EXECUTION_STATUS, ptr.size, ptr, nil )
|
98
99
|
OpenCL.error_check(error)
|
99
100
|
return OpenCL::CommandExecutionStatus::new( ptr.read_cl_int )
|
100
101
|
end
|
@@ -147,6 +148,7 @@ module OpenCL
|
|
147
148
|
#
|
148
149
|
# ==== Attributes
|
149
150
|
#
|
151
|
+
# * +command_exec_callback_type+ - a CommandExecutionStatus
|
150
152
|
# * +options+ - a hash containing named options
|
151
153
|
# * +block+ - a callback invoked when the given Event occurs. Signature of the callback is { |Event, :cl_int event_command_exec_status, FFI::Pointer to user_data| ... }
|
152
154
|
#
|
@@ -154,7 +156,7 @@ module OpenCL
|
|
154
156
|
#
|
155
157
|
# * +:user_data+ - a Pointer (or convertible to Pointer using to_ptr) to the memory area to pass to the callback
|
156
158
|
def set_event_callback( command_exec_callback_type, options={}, &proc )
|
157
|
-
return OpenCL.set_event_callback( self, command_exec_callback_type, options
|
159
|
+
return OpenCL.set_event_callback( self, command_exec_callback_type, options, &proc )
|
158
160
|
end
|
159
161
|
|
160
162
|
alias :set_callback :set_event_callback
|
@@ -13,12 +13,12 @@ module OpenCL
|
|
13
13
|
# * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Image
|
14
14
|
# * +:host_ptr+ - if provided, the Pointer (or convertible to Pointer using to_ptr) to the memory area to use
|
15
15
|
def self.create_image( context, format, desc, options = {} )
|
16
|
-
flags =
|
16
|
+
flags = get_flags( options )
|
17
17
|
host_ptr = options[:host_ptr]
|
18
18
|
error = FFI::MemoryPointer::new( :cl_int )
|
19
|
-
img_ptr =
|
20
|
-
|
21
|
-
return
|
19
|
+
img_ptr = clCreateImage( context, flags, format, desc, host_ptr, error )
|
20
|
+
error_check(error.read_cl_int)
|
21
|
+
return Image::new(img_ptr, false)
|
22
22
|
end
|
23
23
|
|
24
24
|
# Creates a 1D Image
|
@@ -35,10 +35,10 @@ module OpenCL
|
|
35
35
|
# * +:host_ptr+ - if provided, the Pointer (or convertible to Pointer using to_ptr) to the memory area to use
|
36
36
|
def self.create_image_1D( context, format, width, options = {} )
|
37
37
|
if context.platform.version_number > 1.1 then
|
38
|
-
desc =
|
39
|
-
return
|
38
|
+
desc = ImageDesc::new(Mem::IMAGE1D, width, 0, 0, 0, 0, 0, 0, 0, nil)
|
39
|
+
return create_image( context, format, desc, options )
|
40
40
|
else
|
41
|
-
|
41
|
+
error_check(INVALID_OPERATION)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -59,15 +59,15 @@ module OpenCL
|
|
59
59
|
row_pitch = 0
|
60
60
|
row_pitch = options[:row_pitch] if options[:row_pitch]
|
61
61
|
if context.platform.version_number > 1.1 then
|
62
|
-
desc =
|
63
|
-
return
|
62
|
+
desc = ImageDesc::new(Mem::IMAGE2D, width, height, 0, 0, row_pitch, 0, 0, 0, nil)
|
63
|
+
return create_image( context, format, desc, options )
|
64
64
|
end
|
65
|
-
flags =
|
65
|
+
flags = get_flags( options )
|
66
66
|
host_ptr = options[:host_ptr]
|
67
67
|
error = FFI::MemoryPointer::new( :cl_int )
|
68
|
-
img_ptr =
|
69
|
-
|
70
|
-
return
|
68
|
+
img_ptr = clCreateImage2D( context, flags, format, width, height, row_pitch, host_ptr, error )
|
69
|
+
error_check(error.read_cl_int)
|
70
|
+
return Image::new(img_ptr, false)
|
71
71
|
end
|
72
72
|
|
73
73
|
# Creates a 3D Image
|
@@ -90,15 +90,15 @@ module OpenCL
|
|
90
90
|
slice_pitch = 0
|
91
91
|
slice_pitch = options[:slice_pitch] if options[:slice_pitch]
|
92
92
|
if context.platform.version_number > 1.1 then
|
93
|
-
desc =
|
94
|
-
return
|
93
|
+
desc = ImageDesc::new(Mem::IMAGE3D, width, height, depth, 0, row_pitch, slice_pitch, 0, 0, nil)
|
94
|
+
return create_image( context, format, desc, flags, data )
|
95
95
|
end
|
96
|
-
flags =
|
96
|
+
flags = get_flags( options )
|
97
97
|
host_ptr = options[:host_ptr]
|
98
98
|
error = FFI::MemoryPointer::new( :cl_int )
|
99
|
-
img_ptr =
|
100
|
-
|
101
|
-
return
|
99
|
+
img_ptr = clCreateImage3D( context, fs, format, width, height, depth, row_pitch, slice_pitch, d, error )
|
100
|
+
error_check(error.read_cl_int)
|
101
|
+
return Image::new(img_ptr, false)
|
102
102
|
end
|
103
103
|
|
104
104
|
# Creates an Image from an OpenGL render buffer
|
@@ -111,13 +111,13 @@ module OpenCL
|
|
111
111
|
#
|
112
112
|
# ==== Options
|
113
113
|
#
|
114
|
-
# * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Image (default
|
114
|
+
# * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Image (default Mem::READ_WRITE)
|
115
115
|
def self.create_from_GL_render_buffer( context, renderbuffer, options = {} )
|
116
|
-
flags =
|
116
|
+
flags = get_flags( options )
|
117
117
|
error = FFI::MemoryPointer::new( :cl_int )
|
118
|
-
img =
|
119
|
-
|
120
|
-
return
|
118
|
+
img = clCreateFromGLRenderBuffer( context, flags, renderbuffer, error )
|
119
|
+
error_check(error.read_cl_int)
|
120
|
+
return Image::new( img, false )
|
121
121
|
end
|
122
122
|
|
123
123
|
# Creates an Image from an OpenGL texture
|
@@ -132,18 +132,18 @@ module OpenCL
|
|
132
132
|
# ==== Options
|
133
133
|
#
|
134
134
|
# * +:miplevel+ - a :GLint specifying the mipmap level to be used (default 0)
|
135
|
-
# * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Image (default
|
135
|
+
# * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Image (default Mem::READ_WRITE)
|
136
136
|
def self.create_from_GL_texture( context, texture_target, texture, options = {} )
|
137
137
|
if context.platform.version_number < 1.2 then
|
138
|
-
|
138
|
+
error_check(INVALID_OPERATION)
|
139
139
|
end
|
140
|
-
flags =
|
140
|
+
flags = get_flags( options )
|
141
141
|
miplevel = 0
|
142
142
|
miplevel = options[:miplevel] if options[:miplevel]
|
143
143
|
error = FFI::MemoryPointer::new( :cl_int )
|
144
|
-
img =
|
145
|
-
|
146
|
-
return
|
144
|
+
img = clCreateFromGLTexture( context, flags, texture_target, miplevel, texture, error )
|
145
|
+
error_check(error.read_cl_int)
|
146
|
+
return Image::new( img, false )
|
147
147
|
end
|
148
148
|
|
149
149
|
# Creates an Image from an OpenGL 2D texture
|
@@ -160,15 +160,15 @@ module OpenCL
|
|
160
160
|
# * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Image
|
161
161
|
def self.create_from_GL_texture_2D( context, texture_target, texture, options = {} )
|
162
162
|
if context.platform.version_number > 1.1 then
|
163
|
-
return
|
163
|
+
return create_from_GL_texture( context, texture_target, texture, options )
|
164
164
|
end
|
165
|
-
flags =
|
165
|
+
flags = get_flags( options )
|
166
166
|
miplevel = 0
|
167
167
|
miplevel = options[:miplevel] if options[:miplevel]
|
168
168
|
error = FFI::MemoryPointer::new( :cl_int )
|
169
|
-
img =
|
170
|
-
|
171
|
-
return
|
169
|
+
img = clCreateFromGLTexture2D( context, flags, texture_target, miplevel, texture, error )
|
170
|
+
error_check(error.read_cl_int)
|
171
|
+
return Image::new( img, false )
|
172
172
|
end
|
173
173
|
|
174
174
|
# Creates an Image from an OpenGL 3D texture
|
@@ -185,15 +185,15 @@ module OpenCL
|
|
185
185
|
# * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Image
|
186
186
|
def self.create_from_GL_texture_3D( context, texture_target, texture, options = {} )
|
187
187
|
if context.platform.version_number > 1.1 then
|
188
|
-
return
|
188
|
+
return create_from_GL_texture( context, texture_target, texture, options )
|
189
189
|
end
|
190
|
-
flags =
|
190
|
+
flags = get_flags( options )
|
191
191
|
miplevel = 0
|
192
192
|
miplevel = options[:miplevel] if options[:miplevel]
|
193
193
|
error = FFI::MemoryPointer::new( :cl_int )
|
194
|
-
img =
|
195
|
-
|
196
|
-
return
|
194
|
+
img = clCreateFromGLTexture3D( context, flags, texture_target, miplevel, texture, error )
|
195
|
+
error_check(error.read_cl_int)
|
196
|
+
return Image::new( img, false )
|
197
197
|
end
|
198
198
|
|
199
199
|
# Maps the cl_mem OpenCL objects of type CL_MEM_OBJECT_IMAGE*
|
@@ -250,7 +250,7 @@ module OpenCL
|
|
250
250
|
# Returns the ImageFormat corresponding to the image
|
251
251
|
def format
|
252
252
|
image_format = FFI::MemoryPointer::new( OpenCL::ImageFormat )
|
253
|
-
error = OpenCL.clGetImageInfo( self,
|
253
|
+
error = OpenCL.clGetImageInfo( self, FORMAT, image_format.size, image_format, nil)
|
254
254
|
OpenCL.error_check(error)
|
255
255
|
return OpenCL::ImageFormat::from_pointer( image_format )
|
256
256
|
end
|
@@ -258,7 +258,7 @@ module OpenCL
|
|
258
258
|
# Returns the associated Buffer if any, nil otherwise
|
259
259
|
def buffer
|
260
260
|
ptr = FFI::MemoryPointer::new( OpenCL::Buffer )
|
261
|
-
error = OpenCL.clGetImageInfo(self,
|
261
|
+
error = OpenCL.clGetImageInfo(self, BUFFER, OpenCL::Buffer.size, ptr, nil)
|
262
262
|
OpenCL.error_check(error)
|
263
263
|
return nil if ptr.null?
|
264
264
|
return OpenCL::Buffer::new(ptr.read_pointer)
|
@@ -3,23 +3,23 @@ module OpenCL
|
|
3
3
|
# Creates an Array of Kernel corresponding to the kernels defined inside the Program
|
4
4
|
def self.create_kernels_in_program( program )
|
5
5
|
num_ptr = FFI::MemoryPointer::new( :cl_uint )
|
6
|
-
error =
|
7
|
-
|
6
|
+
error = clCreateKernelsInProgram( program, 0, nil, num_ptr )
|
7
|
+
error_check(error)
|
8
8
|
num_kernels = num_ptr.read_cl_uint
|
9
|
-
kernels_ptr = FFI::MemoryPointer::new(
|
10
|
-
error =
|
11
|
-
|
9
|
+
kernels_ptr = FFI::MemoryPointer::new( Kernel, num_kernels )
|
10
|
+
error = clCreateKernelsInProgram( program, num_kernels, kernels_ptr, 0 )
|
11
|
+
error_check(error)
|
12
12
|
return kernels_ptr.get_array_of_pointer(0, num_kernels).collect { |kernel_ptr|
|
13
|
-
|
13
|
+
Kernel::new(kernel_ptr, false)
|
14
14
|
}
|
15
15
|
end
|
16
16
|
|
17
17
|
# Returns the Kernel corresponding the the specified name in the given Program
|
18
18
|
def self.create_kernel(program, name)
|
19
19
|
error = FFI::MemoryPointer::new( :cl_int )
|
20
|
-
kernel_ptr =
|
21
|
-
|
22
|
-
return
|
20
|
+
kernel_ptr = clCreateKernel(program, name, error)
|
21
|
+
error_check(error.read_cl_int)
|
22
|
+
return Kernel::new( kernel_ptr, false )
|
23
23
|
end
|
24
24
|
|
25
25
|
# Set the index th argument of Kernel to value. size of value can be specified
|
@@ -27,12 +27,12 @@ module OpenCL
|
|
27
27
|
sz = size
|
28
28
|
sz = value.class.size if sz == nil
|
29
29
|
val = value
|
30
|
-
if value.kind_of?(
|
31
|
-
val = FFI::MemoryPointer::new(
|
30
|
+
if value.kind_of?(Mem) then
|
31
|
+
val = FFI::MemoryPointer::new( Mem )
|
32
32
|
val.write_pointer(value.to_ptr)
|
33
33
|
end
|
34
|
-
error =
|
35
|
-
|
34
|
+
error = clSetKernelArg( kernel, index, sz, val )
|
35
|
+
error_check(error)
|
36
36
|
end
|
37
37
|
|
38
38
|
# Maps the cl_kernel object
|
@@ -55,37 +55,37 @@ module OpenCL
|
|
55
55
|
def address_qualifier
|
56
56
|
OpenCL.error_check(OpenCL::INVALID_OPERATION) if @kernel.context.platform.version_number < 1.2
|
57
57
|
ptr = FFI::MemoryPointer::new( :cl_kernel_arg_address_qualifier )
|
58
|
-
error = OpenCL.clGetKernelArgInfo(@kernel, @index,
|
58
|
+
error = OpenCL.clGetKernelArgInfo(@kernel, @index, ADDRESS_QUALIFIER, ptr.size, ptr, nil)
|
59
59
|
OpenCL.error_check(error)
|
60
|
-
return
|
60
|
+
return AddressQualifier::new( ptr.read_cl_kernel_arg_address_qualifier )
|
61
61
|
end
|
62
62
|
|
63
63
|
# Returns an AccessQualifier corresponding to the Arg
|
64
64
|
def access_qualifier
|
65
65
|
OpenCL.error_check(OpenCL::INVALID_OPERATION) if @kernel.context.platform.version_number < 1.2
|
66
66
|
ptr = FFI::MemoryPointer::new( :cl_kernel_arg_access_qualifier )
|
67
|
-
error = OpenCL.clGetKernelArgInfo(@kernel, @index,
|
67
|
+
error = OpenCL.clGetKernelArgInfo(@kernel, @index, ACCESS_QUALIFIER, ptr.size, ptr, nil)
|
68
68
|
OpenCL.error_check(error)
|
69
|
-
return
|
69
|
+
return AccessQualifier::new( ptr.read_cl_kernel_arg_access_qualifier )
|
70
70
|
end
|
71
71
|
|
72
72
|
# Returns a TypeQualifier corresponding to the Arg
|
73
73
|
def type_qualifier
|
74
74
|
OpenCL.error_check(OpenCL::INVALID_OPERATION) if @kernel.context.platform.version_number < 1.2
|
75
75
|
ptr = FFI::MemoryPointer::new( :cl_kernel_arg_type_qualifier )
|
76
|
-
error = OpenCL.clGetKernelArgInfo(@kernel, @index,
|
76
|
+
error = OpenCL.clGetKernelArgInfo(@kernel, @index, TYPE_QUALIFIER, ptr.size, ptr, nil)
|
77
77
|
OpenCL.error_check(error)
|
78
|
-
return
|
78
|
+
return TypeQualifier::new( ptr.read_cl_kernel_arg_type_qualifier )
|
79
79
|
end
|
80
80
|
|
81
81
|
# Returns a String corresponding to the Arg type name
|
82
82
|
def type_name
|
83
83
|
OpenCL.error_check(OpenCL::INVALID_OPERATION) if @kernel.context.platform.version_number < 1.2
|
84
84
|
ptr1 = FFI::MemoryPointer::new( :size_t, 1)
|
85
|
-
error = OpenCL.clGetKernelArgInfo(@kernel, @index,
|
85
|
+
error = OpenCL.clGetKernelArgInfo(@kernel, @index, TYPE_NAME, 0, nil, ptr1)
|
86
86
|
OpenCL.error_check(error)
|
87
87
|
ptr2 = FFI::MemoryPointer::new( ptr1.read_size_t )
|
88
|
-
error = OpenCL.clGetKernelArgInfo(@kernel, @index,
|
88
|
+
error = OpenCL.clGetKernelArgInfo(@kernel, @index, TYPE_NAME, ptr1.read_size_t, ptr2, nil)
|
89
89
|
OpenCL.error_check(error)
|
90
90
|
return ptr2.read_string
|
91
91
|
end
|
@@ -94,10 +94,10 @@ module OpenCL
|
|
94
94
|
def name
|
95
95
|
OpenCL.error_check(OpenCL::INVALID_OPERATION) if @kernel.context.platform.version_number < 1.2
|
96
96
|
ptr1 = FFI::MemoryPointer::new( :size_t, 1)
|
97
|
-
error = OpenCL.clGetKernelArgInfo(@kernel, @index,
|
97
|
+
error = OpenCL.clGetKernelArgInfo(@kernel, @index, NAME, 0, nil, ptr1)
|
98
98
|
OpenCL.error_check(error)
|
99
99
|
ptr2 = FFI::MemoryPointer::new( ptr1.read_size_t )
|
100
|
-
error = OpenCL.clGetKernelArgInfo(@kernel, @index,
|
100
|
+
error = OpenCL.clGetKernelArgInfo(@kernel, @index, NAME, ptr1.read_size_t, ptr2, nil)
|
101
101
|
OpenCL.error_check(error)
|
102
102
|
return ptr2.read_string
|
103
103
|
end
|
@@ -118,7 +118,7 @@ module OpenCL
|
|
118
118
|
n = self.num_args
|
119
119
|
a = []
|
120
120
|
n.times { |i|
|
121
|
-
a.push
|
121
|
+
a.push Arg::new(self, i)
|
122
122
|
}
|
123
123
|
return a
|
124
124
|
end
|
@@ -131,7 +131,7 @@ module OpenCL
|
|
131
131
|
pointers.each_with_index { |p, i|
|
132
132
|
pt[i].write_pointer(p)
|
133
133
|
}
|
134
|
-
error = OpenCL.clSetKernelExecInfo( self,
|
134
|
+
error = OpenCL.clSetKernelExecInfo( self, EXEC_INFO_SVM_PTRS, pt.size, pt)
|
135
135
|
OpenCL.error_check(error)
|
136
136
|
return self
|
137
137
|
end
|
@@ -141,7 +141,7 @@ module OpenCL
|
|
141
141
|
OpenCL.error_check(OpenCL::INVALID_OPERATION) if self.context.platform.version_number < 2.0
|
142
142
|
pt = FFI::MemoryPointer::new( :cl_bool )
|
143
143
|
pt.write_cl_bool( flag )
|
144
|
-
error = OpenCL.clSetKernelExecInfo( self,
|
144
|
+
error = OpenCL.clSetKernelExecInfo( self, EXEC_INFO_SVM_FINE_GRAIN_SYSTEL, pt.size, pt)
|
145
145
|
OpenCL.error_check(error)
|
146
146
|
return self
|
147
147
|
end
|
@@ -173,7 +173,7 @@ module OpenCL
|
|
173
173
|
# Returns the Context the Kernel is associated with
|
174
174
|
def context
|
175
175
|
ptr = FFI::MemoryPointer::new( Context )
|
176
|
-
error = OpenCL.clGetKernelInfo(self,
|
176
|
+
error = OpenCL.clGetKernelInfo(self, CONTEXT, Context.size, ptr, nil)
|
177
177
|
OpenCL.error_check(error)
|
178
178
|
return OpenCL::Context::new( ptr.read_pointer )
|
179
179
|
end
|
@@ -181,7 +181,7 @@ module OpenCL
|
|
181
181
|
# Returns the Program the Kernel was created from
|
182
182
|
def program
|
183
183
|
ptr = FFI::MemoryPointer::new( Program )
|
184
|
-
error = OpenCL.clGetKernelInfo(self,
|
184
|
+
error = OpenCL.clGetKernelInfo(self, PROGRAM, Program.size, ptr, nil)
|
185
185
|
OpenCL.error_check(error)
|
186
186
|
return OpenCL::Program::new(ptr.read_pointer)
|
187
187
|
end
|
data/lib/opencl_ruby_ffi/Mem.rb
CHANGED
@@ -6,15 +6,15 @@ module OpenCL
|
|
6
6
|
#
|
7
7
|
# * +memobj+ - the Mem to attach the callback to
|
8
8
|
# * +options+ - a hash containing named options
|
9
|
-
# * +block+ - if provided, a callback invoked when memobj is released. Signature of the callback is { |Mem, FFI::Pointer to user_data| ... }
|
9
|
+
# * +block+ - if provided, a callback invoked when memobj is released. Signature of the callback is { |FFI::Poniter to the deleted Mem, FFI::Pointer to user_data| ... }
|
10
10
|
#
|
11
11
|
# ==== Options
|
12
12
|
#
|
13
13
|
# * +:user_data+ - a Pointer (or convertible to Pointer using to_ptr) to the memory area to pass to the callback
|
14
|
-
def self.set_mem_object_destructor_callback( memobj, options = {}, &
|
14
|
+
def self.set_mem_object_destructor_callback( memobj, options = {}, &block )
|
15
15
|
@@callbacks.push( block ) if block
|
16
|
-
error =
|
17
|
-
|
16
|
+
error = clSetMemObjectDestructorCallback( memobj, block, options[:user_data] )
|
17
|
+
error_check(error)
|
18
18
|
return self
|
19
19
|
end
|
20
20
|
|
@@ -24,7 +24,7 @@ module OpenCL
|
|
24
24
|
# Returns the Context associated to the Mem
|
25
25
|
def context
|
26
26
|
ptr = FFI::MemoryPointer::new( Context )
|
27
|
-
error = OpenCL.clGetMemObjectInfo(self,
|
27
|
+
error = OpenCL.clGetMemObjectInfo(self, CONTEXT, Context.size, ptr, nil)
|
28
28
|
OpenCL.error_check(error)
|
29
29
|
return OpenCL::Context::new( ptr.read_pointer )
|
30
30
|
end
|
@@ -37,10 +37,10 @@ module OpenCL
|
|
37
37
|
# Returns the Buffer this Buffer was created from using create_sub_buffer
|
38
38
|
def associated_memobject
|
39
39
|
ptr = FFI::MemoryPointer::new( Mem )
|
40
|
-
error = OpenCL.clGetMemObjectInfo(self,
|
40
|
+
error = OpenCL.clGetMemObjectInfo(self, ASSOCIATED_MEMOBJECT, Mem.size, ptr, nil)
|
41
41
|
OpenCL.error_check(error)
|
42
42
|
return nil if ptr.read_pointer.null?
|
43
|
-
return
|
43
|
+
return Mem::new( ptr.read_pointer )
|
44
44
|
end
|
45
45
|
|
46
46
|
##
|
@@ -96,7 +96,8 @@ module OpenCL
|
|
96
96
|
#
|
97
97
|
# * +:user_data+ - a Pointer (or convertible to Pointer using to_ptr) to the memory area to pass to the callback
|
98
98
|
def set_destructor_callback( options = {}, &proc )
|
99
|
-
|
99
|
+
OpenCL.set_mem_object_destructor_callback( self, options, &proc )
|
100
|
+
return self
|
100
101
|
end
|
101
102
|
|
102
103
|
# Returns the texture_target argument specified in create_from_GL_texture for Mem
|