opencl_ruby_ffi 1.2.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -0
  3. data/lib/opencl_ruby_ffi.rb +2 -0
  4. data/lib/opencl_ruby_ffi/Buffer.rb +18 -13
  5. data/lib/opencl_ruby_ffi/CommandQueue.rb +301 -302
  6. data/lib/opencl_ruby_ffi/Context.rb +158 -158
  7. data/lib/opencl_ruby_ffi/Device.rb +270 -224
  8. data/lib/opencl_ruby_ffi/Event.rb +40 -36
  9. data/lib/opencl_ruby_ffi/Image.rb +34 -57
  10. data/lib/opencl_ruby_ffi/Kernel.rb +251 -191
  11. data/lib/opencl_ruby_ffi/Mem.rb +49 -70
  12. data/lib/opencl_ruby_ffi/Pipe.rb +3 -14
  13. data/lib/opencl_ruby_ffi/Platform.rb +46 -48
  14. data/lib/opencl_ruby_ffi/Program.rb +131 -124
  15. data/lib/opencl_ruby_ffi/Sampler.rb +6 -24
  16. data/lib/opencl_ruby_ffi/amd/device_attribute_query.rb +100 -0
  17. data/lib/opencl_ruby_ffi/egl.rb +2 -0
  18. data/lib/opencl_ruby_ffi/ext.rb +11 -0
  19. data/lib/opencl_ruby_ffi/ext/device_fission.rb +264 -0
  20. data/lib/opencl_ruby_ffi/gl_ext.rb +2 -0
  21. data/lib/opencl_ruby_ffi/khr/d3d10_sharing.rb +120 -0
  22. data/lib/opencl_ruby_ffi/khr/d3d11_sharing.rb +120 -0
  23. data/lib/opencl_ruby_ffi/khr/dx9_media_sharing.rb +113 -0
  24. data/lib/opencl_ruby_ffi/khr/egl_event.rb +15 -0
  25. data/lib/opencl_ruby_ffi/khr/egl_image.rb +58 -0
  26. data/lib/opencl_ruby_ffi/khr/fp16.rb +23 -0
  27. data/lib/opencl_ruby_ffi/khr/fp64.rb +23 -0
  28. data/lib/opencl_ruby_ffi/khr/gl_event.rb +38 -0
  29. data/lib/opencl_ruby_ffi/khr/gl_sharing.rb +79 -0
  30. data/lib/opencl_ruby_ffi/khr/icd.rb +30 -0
  31. data/lib/opencl_ruby_ffi/khr/initalize_memory.rb +19 -0
  32. data/lib/opencl_ruby_ffi/khr/priority_hints.rb +48 -0
  33. data/lib/opencl_ruby_ffi/khr/spir.rb +45 -0
  34. data/lib/opencl_ruby_ffi/khr/sub_groups.rb +49 -0
  35. data/lib/opencl_ruby_ffi/khr/terminate_context.rb +46 -0
  36. data/lib/opencl_ruby_ffi/khr/throttle_hints.rb +47 -0
  37. data/lib/opencl_ruby_ffi/nv/device_attribute_query.rb +50 -0
  38. data/lib/opencl_ruby_ffi/opencl_ruby_ffi_base.rb +40 -13
  39. data/lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb +214 -2114
  40. data/lib/opencl_ruby_ffi/opencl_types.rb +15 -3
  41. data/opencl_ruby_ffi.gemspec +4 -4
  42. data/templates_custom/default/module/setup.rb +9 -0
  43. metadata +29 -6
  44. data/lib/opencl_ruby_ffi/GLExt.rb +0 -58
  45. data/lib/opencl_ruby_ffi/Stream.rb +0 -127
@@ -69,10 +69,7 @@ module OpenCL
69
69
  # Maps the cl_event object
70
70
  class Event
71
71
  include InnerInterface
72
-
73
- class << self
74
- include InnerGenerator
75
- end
72
+ extend InnerGenerator
76
73
 
77
74
  def inspect
78
75
  return "#<#{self.class.name}: #{command_type}>"
@@ -91,17 +88,12 @@ module OpenCL
91
88
  end
92
89
  end
93
90
 
94
- # Returns the Context associated with the Event
91
+ get_info("Event", :cl_command_type, "command_type")
92
+
95
93
  def context
96
- ptr = MemoryPointer::new( Context )
97
- error = OpenCL.clGetEventInfo(self, CONTEXT, Context.size, ptr, nil)
98
- error_check(error)
99
- return Context::new( ptr.read_pointer )
94
+ return command_queue.context
100
95
  end
101
96
 
102
- # Returns a CommandType corresponding to the type of the command associated with the Event
103
- eval get_info("Event", :cl_command_type, "COMMAND_TYPE")
104
-
105
97
  # Returns a CommandExecutionStatus corresponding to the status of the command associtated with the Event
106
98
  def command_execution_status
107
99
  ptr = MemoryPointer::new( :cl_int )
@@ -110,10 +102,7 @@ module OpenCL
110
102
  return CommandExecutionStatus::new( ptr.read_cl_int )
111
103
  end
112
104
 
113
- ##
114
- # :method: reference_count()
115
- # Returns the reference counter of th Event
116
- eval get_info("Event", :cl_uint, "REFERENCE_COUNT")
105
+ get_info("Event", :cl_uint, "reference_count")
117
106
 
118
107
  # Returns the date the command corresponding to Event was queued
119
108
  def profiling_command_queued
@@ -147,29 +136,44 @@ module OpenCL
147
136
  return ptr.read_cl_ulong
148
137
  end
149
138
 
150
- # Sets the satus of Event (a user event) to the given execution status
151
- def set_user_event_status( execution_status )
152
- return OpenCL.set_user_event_status( self, execution_status )
153
- end
139
+ module OpenCL11
140
+
141
+ # Returns the Context associated with the Event
142
+ def context
143
+ ptr = MemoryPointer::new( Context )
144
+ error = OpenCL.clGetEventInfo(self, CONTEXT, Context.size, ptr, nil)
145
+ error_check(error)
146
+ return Context::new( ptr.read_pointer )
147
+ end
148
+
149
+ # Sets the satus of Event (a user event) to the given execution status
150
+ def set_user_event_status( execution_status )
151
+ return OpenCL.set_user_event_status( self, execution_status )
152
+ end
153
+
154
+ alias :set_status :set_user_event_status
155
+
156
+ # Attaches a callback to the Event that will be called on the given transition
157
+ #
158
+ # ==== Attributes
159
+ #
160
+ # * +command_exec_callback_type+ - a CommandExecutionStatus
161
+ # * +options+ - a hash containing named options
162
+ # * +block+ - a callback invoked when the given Event occurs. Signature of the callback is { |Event, :cl_int event_command_exec_status, Pointer to user_data| ... }
163
+ #
164
+ # ==== Options
165
+ #
166
+ # * +:user_data+ - a Pointer (or convertible to Pointer using to_ptr) to the memory area to pass to the callback
167
+ def set_event_callback( command_exec_callback_type, options={}, &proc )
168
+ return OpenCL.set_event_callback( self, command_exec_callback_type, options, &proc )
169
+ end
170
+
171
+ alias :set_callback :set_event_callback
154
172
 
155
- alias :set_status :set_user_event_status
156
-
157
- # Attaches a callback to the Event that will be called on the given transition
158
- #
159
- # ==== Attributes
160
- #
161
- # * +command_exec_callback_type+ - a CommandExecutionStatus
162
- # * +options+ - a hash containing named options
163
- # * +block+ - a callback invoked when the given Event occurs. Signature of the callback is { |Event, :cl_int event_command_exec_status, Pointer to user_data| ... }
164
- #
165
- # ==== Options
166
- #
167
- # * +:user_data+ - a Pointer (or convertible to Pointer using to_ptr) to the memory area to pass to the callback
168
- def set_event_callback( command_exec_callback_type, options={}, &proc )
169
- return OpenCL.set_event_callback( self, command_exec_callback_type, options, &proc )
170
173
  end
171
174
 
172
- alias :set_callback :set_event_callback
175
+ register_extension( :v11, OpenCL11, "cond = false; if command_queue then cond = (command_queue.device.platform.version_number >= 1.1) else ptr = MemoryPointer::new( Context ); error = OpenCL.clGetEventInfo(self, CONTEXT, Context.size, ptr, nil); error_check(error); cond = (Context::new( ptr.read_pointer ).platform.version_number >= 1.1) end; cond" )
173
176
 
174
177
  end
178
+
175
179
  end
@@ -122,15 +122,15 @@ module OpenCL
122
122
  # ==== Options
123
123
  #
124
124
  # * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Image
125
- def self.create_from_gl_render_buffer( context, renderbuffer, options = {} )
125
+ def self.create_from_gl_renderbuffer( context, renderbuffer, options = {} )
126
126
  flags = get_flags( options )
127
127
  error = MemoryPointer::new( :cl_int )
128
- img = clCreateFromGLRenderBuffer( context, flags, renderbuffer, error )
128
+ img = clCreateFromGLRenderbuffer( context, flags, renderbuffer, error )
129
129
  error_check(error.read_cl_int)
130
130
  return Image::new( img, false )
131
131
  end
132
132
  class << self
133
- alias :create_from_GL_render_buffer :create_from_gl_render_buffer
133
+ alias :create_from_GL_renderbuffer :create_from_gl_renderbuffer
134
134
  end
135
135
 
136
136
  # Creates an Image from an OpenGL texture
@@ -228,53 +228,6 @@ module OpenCL
228
228
  return "#<#{self.class.name}: #{format.channel_order}, #{format.channel_data_type}, #{width}#{h != 0 ? "x#{h}" : ""}#{d != 0 ? "x#{d}" : ""} (#{size})#{f.to_i != 0 ? " (#{f})" : "" }>"
229
229
  end
230
230
 
231
- ##
232
- # :method: element_size
233
- # Returns the element_size of the Image
234
-
235
- ##
236
- # :method: row_pitch
237
- # Returns the row_pitch of the Image
238
-
239
- ##
240
- # :method: slice_pitch
241
- # Returns the slice_pitch of the Image
242
-
243
- ##
244
- # :method: width
245
- # Returns the width of the Image
246
-
247
- ##
248
- # :method: height
249
- # Returns the height of the Image
250
-
251
- ##
252
- # :method: depth
253
- # Returns the depth of the Image
254
-
255
- ##
256
- # :method: array_size
257
- # Returns the array_size of the Image
258
- %w( ELEMENT_SIZE ROW_PITCH SLICE_PITCH WIDTH HEIGHT DEPTH ARRAY_SIZE ).each { |prop|
259
- eval get_info("Image", :size_t, prop)
260
- }
261
-
262
- ##
263
- # :method: num_mip_levels
264
- # Returns the num_mip_levels of the Image
265
-
266
- ##
267
- # :method: num_samples
268
- # Returns the num_samples of the Image
269
- %w( NUM_MIP_LEVELS NUM_SAMPLES ).each { |prop|
270
- eval get_info("Image", :cl_uint, prop)
271
- }
272
-
273
- # Returns the ImageDesc corresponding to the Image
274
- def desc
275
- return ImageDesc::new( self.type, self.width, self.height, self.depth, self.array_size, self.row_pitch, self.slice_pitch, self.num_mip_levels, self.num_samples, self.buffer )
276
- end
277
-
278
231
  # Returns the ImageFormat corresponding to the image
279
232
  def format
280
233
  image_format = MemoryPointer::new( ImageFormat )
@@ -283,15 +236,39 @@ module OpenCL
283
236
  return ImageFormat::new( image_format )
284
237
  end
285
238
 
286
- # Returns the associated Buffer if any, nil otherwise
287
- def buffer
288
- ptr = MemoryPointer::new( Buffer )
289
- error = OpenCL.clGetImageInfo(self, BUFFER, Buffer.size, ptr, nil)
290
- error_check(error)
291
- return nil if ptr.null?
292
- return Buffer::new(ptr.read_pointer)
239
+ get_info("Image", :size_t, "element_size")
240
+ get_info("Image", :size_t, "row_pitch")
241
+ get_info("Image", :size_t, "slice_pitch")
242
+ get_info("Image", :size_t, "width")
243
+ get_info("Image", :size_t, "height")
244
+ get_info("Image", :size_t, "depth")
245
+
246
+ module OpenCL12
247
+ extend InnerGenerator
248
+
249
+ get_info("Image", :size_t, "array_size")
250
+
251
+ # Returns the associated Buffer if any, nil otherwise
252
+ def buffer
253
+ ptr = MemoryPointer::new( Buffer )
254
+ error = OpenCL.clGetImageInfo(self, BUFFER, Buffer.size, ptr, nil)
255
+ error_check(error)
256
+ return nil if ptr.null?
257
+ return Buffer::new(ptr.read_pointer)
258
+ end
259
+
260
+ get_info("Image", :cl_uint, "num_mip_levels")
261
+ get_info("Image", :cl_uint, "num_samples")
262
+
263
+ # Returns the ImageDesc corresponding to the Image
264
+ def desc
265
+ return ImageDesc::new( self.type, self.width, self.height, self.depth, self.array_size, self.row_pitch, self.slice_pitch, self.num_mip_levels, self.num_samples, self.buffer )
266
+ end
267
+
293
268
  end
294
269
 
270
+ register_extension( :v12, OpenCL12, "platform.version_number >= 1.2" )
271
+
295
272
  end
296
273
 
297
274
  end
@@ -47,10 +47,7 @@ module OpenCL
47
47
  # Maps the cl_kernel object
48
48
  class Kernel
49
49
  include InnerInterface
50
-
51
- class << self
52
- include InnerGenerator
53
- end
50
+ extend InnerGenerator
54
51
 
55
52
  def inspect
56
53
  return "#<#{self.class.name}: #{name}>"
@@ -59,72 +56,43 @@ module OpenCL
59
56
  # Maps the logical cl arg object
60
57
  class Arg
61
58
  include InnerInterface
62
-
63
- class << self
64
- include InnerGenerator
65
- end
59
+ extend InnerGenerator
60
+
66
61
  # Returns the index of the Arg in the list
67
62
  attr_reader :index
68
63
  # Returns the Kernel this Arg belongs to
69
64
  attr_reader :kernel
70
65
 
71
- # Creates a new arg for a Kernel at index
72
- def initialize( kernel, index )
73
- @index = index
74
- @kernel = kernel
75
- end
66
+ if ExtendedStruct::const_get(:FORCE_EXTENSIONS_LOADING) then
76
67
 
77
- # Returns an AddressQualifier corresponding to the Arg
78
- def address_qualifier
79
- error_check(INVALID_OPERATION) if @kernel.context.platform.version_number < 1.2
80
- ptr = MemoryPointer::new( :cl_kernel_arg_address_qualifier )
81
- error = OpenCL.clGetKernelArgInfo(@kernel, @index, ADDRESS_QUALIFIER, ptr.size, ptr, nil)
82
- error_check(error)
83
- return AddressQualifier::new( ptr.read_cl_kernel_arg_address_qualifier )
84
- end
68
+ def self.register_extension(name, mod, cond)
69
+ include mod
70
+ end
85
71
 
86
- # Returns an AccessQualifier corresponding to the Arg
87
- def access_qualifier
88
- error_check(INVALID_OPERATION) if @kernel.context.platform.version_number < 1.2
89
- ptr = MemoryPointer::new( :cl_kernel_arg_access_qualifier )
90
- error = OpenCL.clGetKernelArgInfo(@kernel, @index, ACCESS_QUALIFIER, ptr.size, ptr, nil)
91
- error_check(error)
92
- return AccessQualifier::new( ptr.read_cl_kernel_arg_access_qualifier )
93
- end
72
+ # Creates a new arg for a Kernel at index
73
+ def initialize( kernel, index )
74
+ @index = index
75
+ @kernel = kernel
76
+ end
94
77
 
95
- # Returns a TypeQualifier corresponding to the Arg
96
- def type_qualifier
97
- error_check(INVALID_OPERATION) if @kernel.context.platform.version_number < 1.2
98
- ptr = MemoryPointer::new( :cl_kernel_arg_type_qualifier )
99
- error = OpenCL.clGetKernelArgInfo(@kernel, @index, TYPE_QUALIFIER, ptr.size, ptr, nil)
100
- error_check(error)
101
- return TypeQualifier::new( ptr.read_cl_kernel_arg_type_qualifier )
102
- end
78
+ else
103
79
 
104
- # Returns a String corresponding to the Arg type name
105
- def type_name
106
- error_check(INVALID_OPERATION) if @kernel.context.platform.version_number < 1.2
107
- ptr1 = MemoryPointer::new( :size_t, 1)
108
- error = OpenCL.clGetKernelArgInfo(@kernel, @index, TYPE_NAME, 0, nil, ptr1)
109
- error_check(error)
110
- ptr2 = MemoryPointer::new( ptr1.read_size_t )
111
- error = OpenCL.clGetKernelArgInfo(@kernel, @index, TYPE_NAME, ptr1.read_size_t, ptr2, nil)
112
- error_check(error)
113
- return ptr2.read_string
114
- end
80
+ Extensions = {}
115
81
 
116
- # Returns a String corresponding to the Arg name
117
- def name
118
- error_check(INVALID_OPERATION) if @kernel.context.platform.version_number < 1.2
119
- ptr1 = MemoryPointer::new( :size_t, 1)
120
- error = OpenCL.clGetKernelArgInfo(@kernel, @index, NAME, 0, nil, ptr1)
121
- error_check(error)
122
- ptr2 = MemoryPointer::new( ptr1.read_size_t )
123
- error = OpenCL.clGetKernelArgInfo(@kernel, @index, NAME, ptr1.read_size_t, ptr2, nil)
124
- error_check(error)
125
- return ptr2.read_string
126
- end
82
+ def self.register_extension(name, mod, cond)
83
+ Extensions[name] = [mod, cond]
84
+ end
127
85
 
86
+ # Creates a new arg for a Kernel at index
87
+ def initialize( kernel, index )
88
+ @index = index
89
+ @kernel = kernel
90
+ Extensions.each { |name, ext|
91
+ extend ext[0] if eval(ext[1])
92
+ }
93
+ end
94
+
95
+ end
128
96
  # Sets this Arg to value. The size of value can be specified.
129
97
  def set(value, size = nil)
130
98
  if value.class == SVMPointer and @kernel.context.platform.version_number >= 2.0 then
@@ -134,6 +102,65 @@ module OpenCL
134
102
  end
135
103
  end
136
104
 
105
+ module OpenCL12
106
+
107
+ # Returns an AddressQualifier corresponding to the Arg
108
+ def address_qualifier
109
+ error_check(INVALID_OPERATION) if @kernel.context.platform.version_number < 1.2
110
+ ptr = MemoryPointer::new( :cl_kernel_arg_address_qualifier )
111
+ error = OpenCL.clGetKernelArgInfo(@kernel, @index, ADDRESS_QUALIFIER, ptr.size, ptr, nil)
112
+ error_check(error)
113
+ return AddressQualifier::new( ptr.read_cl_kernel_arg_address_qualifier )
114
+ end
115
+
116
+ # Returns an AccessQualifier corresponding to the Arg
117
+ def access_qualifier
118
+ error_check(INVALID_OPERATION) if @kernel.context.platform.version_number < 1.2
119
+ ptr = MemoryPointer::new( :cl_kernel_arg_access_qualifier )
120
+ error = OpenCL.clGetKernelArgInfo(@kernel, @index, ACCESS_QUALIFIER, ptr.size, ptr, nil)
121
+ error_check(error)
122
+ return AccessQualifier::new( ptr.read_cl_kernel_arg_access_qualifier )
123
+ end
124
+
125
+ # Returns a String corresponding to the Arg type name
126
+ def type_name
127
+ error_check(INVALID_OPERATION) if @kernel.context.platform.version_number < 1.2
128
+ ptr1 = MemoryPointer::new( :size_t, 1)
129
+ error = OpenCL.clGetKernelArgInfo(@kernel, @index, TYPE_NAME, 0, nil, ptr1)
130
+ error_check(error)
131
+ ptr2 = MemoryPointer::new( ptr1.read_size_t )
132
+ error = OpenCL.clGetKernelArgInfo(@kernel, @index, TYPE_NAME, ptr1.read_size_t, ptr2, nil)
133
+ error_check(error)
134
+ return ptr2.read_string
135
+ end
136
+
137
+ # Returns a TypeQualifier corresponding to the Arg
138
+ def type_qualifier
139
+ error_check(INVALID_OPERATION) if @kernel.context.platform.version_number < 1.2
140
+ ptr = MemoryPointer::new( :cl_kernel_arg_type_qualifier )
141
+ error = OpenCL.clGetKernelArgInfo(@kernel, @index, TYPE_QUALIFIER, ptr.size, ptr, nil)
142
+ error_check(error)
143
+ return TypeQualifier::new( ptr.read_cl_kernel_arg_type_qualifier )
144
+ end
145
+
146
+ # Returns a String corresponding to the Arg name
147
+ def name
148
+ error_check(INVALID_OPERATION) if @kernel.context.platform.version_number < 1.2
149
+ ptr1 = MemoryPointer::new( :size_t, 1)
150
+ error = OpenCL.clGetKernelArgInfo(@kernel, @index, NAME, 0, nil, ptr1)
151
+ error_check(error)
152
+ ptr2 = MemoryPointer::new( ptr1.read_size_t )
153
+ error = OpenCL.clGetKernelArgInfo(@kernel, @index, NAME, ptr1.read_size_t, ptr2, nil)
154
+ error_check(error)
155
+ return ptr2.read_string
156
+ end
157
+
158
+ alias to_s name
159
+
160
+ end
161
+
162
+ register_extension( :v12, OpenCL12, "kernel.context.platform.version_number >= 1.2" )
163
+
137
164
  end
138
165
 
139
166
  # Returns an Array of Arg corresponding to the arguments of the Kernel
@@ -146,52 +173,12 @@ module OpenCL
146
173
  return a
147
174
  end
148
175
 
149
- # Specifies the list of SVM pointers the kernel will be using
150
- def set_svm_ptrs( ptrs )
151
- error_check(INVALID_OPERATION) if self.context.platform.version_number < 2.0
152
- pointers = [ptrs].flatten
153
- pt = MemoryPointer::new( :pointer, pointers.length )
154
- pointers.each_with_index { |p, i|
155
- pt[i].write_pointer(p)
156
- }
157
- error = OpenCL.clSetKernelExecInfo( self, EXEC_INFO_SVM_PTRS, pt.size, pt)
158
- error_check(error)
159
- return self
160
- end
161
-
162
- # Specifies the granularity of the SVM system.
163
- def set_svm_fine_grain_system( flag )
164
- error_check(INVALID_OPERATION) if self.context.platform.version_number < 2.0
165
- pt = MemoryPointer::new( :cl_bool )
166
- pt.write_cl_bool( flag )
167
- error = OpenCL.clSetKernelExecInfo( self, EXEC_INFO_SVM_FINE_GRAIN_SYSTEM, pt.size, pt)
168
- error_check(error)
169
- return self
170
- end
171
-
172
- ##
173
- # :method: function_name()
174
- # returns a String correspondig to the Kernel function name
175
-
176
- ##
177
- # :method: attributes()
178
- # returns a String containing the attributes qualifier used at kernel definition
179
- %w( FUNCTION_NAME ATTRIBUTES ).each { |prop|
180
- eval get_info("Kernel", :string, prop)
181
- }
182
-
176
+ get_info("Kernel", :string, "function_name")
183
177
  alias name function_name
178
+ alias to_s name
184
179
 
185
- ##
186
- # :method: num_args()
187
- # Returns the number of arguments for the Kernel
188
-
189
- ##
190
- # :method: reference_count
191
- # Returns the reference counter for the Kernel
192
- %w( NUM_ARGS REFERENCE_COUNT ).each { |prop|
193
- eval get_info("Kernel", :cl_uint, prop)
194
- }
180
+ get_info("Kernel", :cl_uint, "num_args")
181
+ get_info("Kernel", :cl_uint, "reference_count")
195
182
 
196
183
  # Returns the Context the Kernel is associated with
197
184
  def context
@@ -230,92 +217,11 @@ module OpenCL
230
217
  return ptr.read_cl_ulong
231
218
  end
232
219
 
233
- def preferred_work_group_size_multiple(device = program.devices.first)
234
- ptr = MemoryPointer::new( :size_t )
235
- error = OpenCL.clGetKernelWorkGroupInfo(self, device, PREFERRED_WORK_GROUP_SIZE_MULTIPLE, ptr.size, ptr, nil)
236
- error_check(error)
237
- return ptr.read_size_t
238
- end
239
-
240
- def private_mem_size(device = program.devices.first)
241
- ptr = MemoryPointer::new( :cl_ulong )
242
- error = OpenCL.clGetKernelWorkGroupInfo(self, device, PRIVATE_MEM_SIZE, ptr.size, ptr, nil)
243
- error_check(error)
244
- return ptr.read_cl_ulong
245
- end
246
-
247
- def global_work_size(device = program.devices.first)
248
- ptr = MemoryPointer::new( :size_t, 3 )
249
- error = OpenCL.clGetKernelWorkGroupInfo(self, device, GLOBAL_WORK_SIZE, ptr.size, ptr, nil)
250
- error_check(error)
251
- return ptr.get_array_of_size_t(0,3)
252
- end
253
-
254
- def max_num_sub_groups(device = program.devices.first)
255
- error_check(INVALID_OPERATION) if self.context.platform.version_number < 2.1
256
- ptr = MemoryPointer::new( :size_t )
257
- error = OpenCL.clGetKernelSubGroupInfo(self, device, MAX_NUM_SUB_GROUPS, 0, nil, ptr.size, ptr, nil)
258
- error_check(error)
259
- return ptr.read_size_t
260
- end
261
-
262
- def compile_num_sub_groups(device = program.devices.first)
263
- error_check(INVALID_OPERATION) if self.context.platform.version_number < 2.1
264
- ptr = MemoryPointer::new( :size_t )
265
- error = OpenCL.clGetKernelSubGroupInfo(self, device, COMPILE_NUM_SUB_GROUPS, 0, nil, ptr.size, ptr, nil)
266
- error_check(error)
267
- return ptr.read_size_t
268
- end
269
-
270
- def max_sub_group_size_for_ndrange(local_work_size, device = program.devices.first)
271
- error_check(INVALID_OPERATION) if self.context.platform.version_number < 2.1
272
- local_work_size = [local_work_size].flatten
273
- lws_p = MemoryPointer::new( :size_t, local_work_size.length )
274
- local_work_size.each_with_index { |e,i|
275
- lws_p[i].write_size_t( e )
276
- }
277
- ptr = MemoryPointer::new( :size_t )
278
- error = OpenCL.clGetKernelSubGroupInfo(self, device, MAX_SUB_GROUP_SIZE_FOR_NDRANGE, lws_p.size, lws_p, ptr.size, ptr, nil)
279
- error_check(error)
280
- return ptr.read_size_t
281
- end
282
-
283
- def sub_groups_count_for_ndrange(local_work_size, device = program.devices.first)
284
- error_check(INVALID_OPERATION) if self.context.platform.version_number < 2.1
285
- local_work_size = [local_work_size].flatten
286
- lws_p = MemoryPointer::new( :size_t, local_work_size.length )
287
- local_work_size.each_with_index { |e,i|
288
- lws_p[i].write_size_t( e )
289
- }
290
- ptr = MemoryPointer::new( :size_t )
291
- error = OpenCL.clGetKernelSubGroupInfo(self, device, SUB_GROUP_COUNT_FOR_NDRANGE, lws_p.size, lws_p, ptr.size, ptr, nil)
292
- error_check(error)
293
- return ptr.read_size_t
294
- end
295
-
296
- def local_size_for_sub_group_count(sub_group_number, device = program.devices.first)
297
- error_check(INVALID_OPERATION) if self.context.platform.version_number < 2.1
298
- sgp_p = MemoryPointer::new( :size_t )
299
- sgp_p.write_size_t(sub_group_number)
300
- size_ptr = MemoryPointer::new( :size_t )
301
- error = OpenCL.clGetKernelSubGroupInfo(self, device, LOCAL_SIZE_FOR_SUB_GROUP_COUNT, sgp_p.size, sgp_p, 0, nil, size_ptr)
302
- error_check(error)
303
- lws_p = MemoryPointer::new( size_ptr.read_size_t )
304
- error = OpenCL.clGetKernelSubGroupInfo(self, device, LOCAL_SIZE_FOR_SUB_GROUP_COUNT, sgp_p.size, sgp_p, lws_p.size, lws_p, nil)
305
- error_check(error)
306
- return lws_p.get_array_of_size_t(0, lws_p.size/size_ptr.size)
307
- end
308
-
309
220
  # Set the index th argument of the Kernel to value. The size of value can be specified.
310
221
  def set_arg(index, value, size = nil)
311
222
  OpenCL.set_kernel_arg(self, index, value, size)
312
223
  end
313
224
 
314
- # Set the index th argument of the Kernel to an svm pointer value.
315
- def set_arg_svm_pointer(index, svm_pointer)
316
- OpenCL.set_kernel_arg_svm_pointer(self, index, svm_pointer)
317
- end
318
-
319
225
  # Enqueues the Kernel in the given queue, specifying the global_work_size. Arguments for the kernel are specified afterwards. Last, a hash containing options for enqueu_ndrange kernel can be specified
320
226
  def enqueue_with_args(command_queue, global_work_size, *args)
321
227
  n = self.num_args
@@ -327,19 +233,173 @@ module OpenCL
327
233
  options = {}
328
234
  end
329
235
  n.times { |i|
330
- if args[i].class == SVMPointer and self.context.platform.version_number >= 2.0 then
331
- self.set_arg_svm_pointer(i, args[i])
332
- else
333
- self.set_arg(i, args[i])
334
- end
236
+ self.set_arg(i, args[i])
335
237
  }
336
238
  command_queue.enqueue_ndrange_kernel(self, global_work_size, options)
337
239
  end
338
240
 
339
- def clone
340
- return OpenCL.clone_kernel( self )
241
+ module OpenCL11
242
+
243
+ def preferred_work_group_size_multiple(device = program.devices.first)
244
+ ptr = MemoryPointer::new( :size_t )
245
+ error = OpenCL.clGetKernelWorkGroupInfo(self, device, PREFERRED_WORK_GROUP_SIZE_MULTIPLE, ptr.size, ptr, nil)
246
+ error_check(error)
247
+ return ptr.read_size_t
248
+ end
249
+
250
+ def private_mem_size(device = program.devices.first)
251
+ ptr = MemoryPointer::new( :cl_ulong )
252
+ error = OpenCL.clGetKernelWorkGroupInfo(self, device, PRIVATE_MEM_SIZE, ptr.size, ptr, nil)
253
+ error_check(error)
254
+ return ptr.read_cl_ulong
255
+ end
256
+
257
+ end
258
+
259
+ module OpenCL12
260
+
261
+ ##
262
+ # returns a String containing the attributes qualifier used at kernel definition
263
+ def attributes
264
+ attributes_size = MemoryPointer::new( :size_t )
265
+ error = OpenCL.clGetKernelInfo( self, ATTRIBUTES, 0, nil, attributes_size)
266
+ error_check(error)
267
+ attr = MemoryPointer::new( attributes_size.read_size_t )
268
+ error = OpenCL.clGetKernelInfo( self, ATTRIBUTES, attributes_size.read_size_t, attr, nil)
269
+ error_check(error)
270
+ attr_string = attr.read_string
271
+ return attr_string.split(" ")
272
+ end
273
+
274
+ def global_work_size(device = program.devices.first)
275
+ ptr = MemoryPointer::new( :size_t, 3 )
276
+ error = OpenCL.clGetKernelWorkGroupInfo(self, device, GLOBAL_WORK_SIZE, ptr.size, ptr, nil)
277
+ error_check(error)
278
+ return ptr.get_array_of_size_t(0,3)
279
+ end
280
+
281
+ end
282
+
283
+ module OpenCL20
284
+
285
+ # Specifies the list of SVM pointers the kernel will be using
286
+ def set_svm_ptrs( ptrs )
287
+ error_check(INVALID_OPERATION) if self.context.platform.version_number < 2.0
288
+ pointers = [ptrs].flatten
289
+ pt = MemoryPointer::new( :pointer, pointers.length )
290
+ pointers.each_with_index { |p, i|
291
+ pt[i].write_pointer(p)
292
+ }
293
+ error = OpenCL.clSetKernelExecInfo( self, EXEC_INFO_SVM_PTRS, pt.size, pt)
294
+ error_check(error)
295
+ return self
296
+ end
297
+
298
+ # Specifies the granularity of the SVM system.
299
+ def set_svm_fine_grain_system( flag )
300
+ error_check(INVALID_OPERATION) if self.context.platform.version_number < 2.0
301
+ pt = MemoryPointer::new( :cl_bool )
302
+ pt.write_cl_bool( flag )
303
+ error = OpenCL.clSetKernelExecInfo( self, EXEC_INFO_SVM_FINE_GRAIN_SYSTEM, pt.size, pt)
304
+ error_check(error)
305
+ return self
306
+ end
307
+
308
+ # Set the index th argument of the Kernel to an svm pointer value.
309
+ def set_arg_svm_pointer(index, svm_pointer)
310
+ OpenCL.set_kernel_arg_svm_pointer(self, index, svm_pointer)
311
+ end
312
+
313
+ # Enqueues the Kernel in the given queue, specifying the global_work_size. Arguments for the kernel are specified afterwards. Last, a hash containing options for enqueu_ndrange kernel can be specified
314
+ def enqueue_with_args(command_queue, global_work_size, *args)
315
+ n = self.num_args
316
+ error_check(INVALID_KERNEL_ARGS) if args.length < n
317
+ error_check(INVALID_KERNEL_ARGS) if args.length > n + 1
318
+ if args.length == n + 1
319
+ options = args.last
320
+ else
321
+ options = {}
322
+ end
323
+ n.times { |i|
324
+ if args[i].class == SVMPointer and self.context.platform.version_number >= 2.0 then
325
+ self.set_arg_svm_pointer(i, args[i])
326
+ else
327
+ self.set_arg(i, args[i])
328
+ end
329
+ }
330
+ command_queue.enqueue_ndrange_kernel(self, global_work_size, options)
331
+ end
332
+
341
333
  end
342
334
 
335
+ module OpenCL21
336
+
337
+ def max_num_sub_groups(device = program.devices.first)
338
+ error_check(INVALID_OPERATION) if self.context.platform.version_number < 2.1
339
+ ptr = MemoryPointer::new( :size_t )
340
+ error = OpenCL.clGetKernelSubGroupInfo(self, device, MAX_NUM_SUB_GROUPS, 0, nil, ptr.size, ptr, nil)
341
+ error_check(error)
342
+ return ptr.read_size_t
343
+ end
344
+
345
+ def compile_num_sub_groups(device = program.devices.first)
346
+ error_check(INVALID_OPERATION) if self.context.platform.version_number < 2.1
347
+ ptr = MemoryPointer::new( :size_t )
348
+ error = OpenCL.clGetKernelSubGroupInfo(self, device, COMPILE_NUM_SUB_GROUPS, 0, nil, ptr.size, ptr, nil)
349
+ error_check(error)
350
+ return ptr.read_size_t
351
+ end
352
+
353
+ def max_sub_group_size_for_ndrange(local_work_size, device = program.devices.first)
354
+ error_check(INVALID_OPERATION) if self.context.platform.version_number < 2.1
355
+ local_work_size = [local_work_size].flatten
356
+ lws_p = MemoryPointer::new( :size_t, local_work_size.length )
357
+ local_work_size.each_with_index { |e,i|
358
+ lws_p[i].write_size_t( e )
359
+ }
360
+ ptr = MemoryPointer::new( :size_t )
361
+ error = OpenCL.clGetKernelSubGroupInfo(self, device, MAX_SUB_GROUP_SIZE_FOR_NDRANGE, lws_p.size, lws_p, ptr.size, ptr, nil)
362
+ error_check(error)
363
+ return ptr.read_size_t
364
+ end
365
+
366
+ def sub_groups_count_for_ndrange(local_work_size, device = program.devices.first)
367
+ error_check(INVALID_OPERATION) if self.context.platform.version_number < 2.1
368
+ local_work_size = [local_work_size].flatten
369
+ lws_p = MemoryPointer::new( :size_t, local_work_size.length )
370
+ local_work_size.each_with_index { |e,i|
371
+ lws_p[i].write_size_t( e )
372
+ }
373
+ ptr = MemoryPointer::new( :size_t )
374
+ error = OpenCL.clGetKernelSubGroupInfo(self, device, SUB_GROUP_COUNT_FOR_NDRANGE, lws_p.size, lws_p, ptr.size, ptr, nil)
375
+ error_check(error)
376
+ return ptr.read_size_t
377
+ end
378
+
379
+ def local_size_for_sub_group_count(sub_group_number, device = program.devices.first)
380
+ error_check(INVALID_OPERATION) if self.context.platform.version_number < 2.1
381
+ sgp_p = MemoryPointer::new( :size_t )
382
+ sgp_p.write_size_t(sub_group_number)
383
+ size_ptr = MemoryPointer::new( :size_t )
384
+ error = OpenCL.clGetKernelSubGroupInfo(self, device, LOCAL_SIZE_FOR_SUB_GROUP_COUNT, sgp_p.size, sgp_p, 0, nil, size_ptr)
385
+ error_check(error)
386
+ lws_p = MemoryPointer::new( size_ptr.read_size_t )
387
+ error = OpenCL.clGetKernelSubGroupInfo(self, device, LOCAL_SIZE_FOR_SUB_GROUP_COUNT, sgp_p.size, sgp_p, lws_p.size, lws_p, nil)
388
+ error_check(error)
389
+ return lws_p.get_array_of_size_t(0, lws_p.size/size_ptr.size)
390
+ end
391
+
392
+ def clone
393
+ return OpenCL.clone_kernel( self )
394
+ end
395
+
396
+ end
397
+
398
+ register_extension( :v11, OpenCL11, "context.platform.version_number >= 1.1" )
399
+ register_extension( :v12, OpenCL12, "context.platform.version_number >= 1.2" )
400
+ register_extension( :v20, OpenCL20, "context.platform.version_number >= 2.0" )
401
+ register_extension( :v21, OpenCL21, "context.platform.version_number >= 2.1" )
402
+
343
403
  end
344
404
 
345
405
  end