Class: OpenCL::Program
- Inherits:
-
ExtendedStruct
- Object
- ManagedStruct
- ExtendedStruct
- OpenCL::Program
- Defined in:
- lib/opencl_ruby_ffi/Program.rb,
lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb,
lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb,
lib/opencl_ruby_ffi/khr/spir.rb
Overview
Maps the cl_program object of OpenCL
Defined Under Namespace
Modules: OpenCL12, OpenCL20, OpenCL21 Classes: BinaryType
Constant Summary collapse
- REFERENCE_COUNT =
0x1160
- CONTEXT =
0x1161
- NUM_DEVICES =
0x1162
- DEVICES =
0x1163
- SOURCE =
0x1164
- BINARY_SIZES =
0x1165
- BINARIES =
0x1166
- NUM_KERNELS =
0x1167
- KERNEL_NAMES =
0x1168
- IL =
0x1169
- BUILD_STATUS =
0x1181
- BUILD_OPTIONS =
0x1182
- BUILD_LOG =
0x1183
- BINARY_TYPE =
0x1184
- BUILD_GLOBAL_VARIABLE_TOTAL_SIZE =
0x1185
- BINARY_TYPE_NONE =
0x0
- BINARY_TYPE_COMPILED_OBJECT =
0x1
- BINARY_TYPE_LIBRARY =
0x2
- BINARY_TYPE_EXECUTABLE =
0x4
- BINARY_TYPE_INTERMEDIATE =
0x40E1
Instance Method Summary collapse
-
#binaries ⇒ Object
Returns the binaries associated to the Program for each Device.
-
#binary_sizes ⇒ Object
Returns the OpenCL::Program::binary_sizes info.
-
#build(options = { }, &block) ⇒ Object
Builds (compile and link) the Program created from sources or binary.
-
#build_log(devs = nil) ⇒ Object
Returns the build log for each Device associated to the Program or the Device(s) specified.
-
#build_options(devs = nil) ⇒ Object
Returns the build options for each Device associated to the Program or the Device(s) specified.
-
#build_status(devs = nil) ⇒ Object
Returns the BuildStatus of the Program for each device associated to the Program or the Device(s) specified.
-
#context ⇒ Object
Returns the Context the Program is associated to.
-
#create_kernel(name) ⇒ Object
Returns the Kernel corresponding the the specified name in the Program.
-
#devices ⇒ Object
Returns the Array of Device the Program is associated with.
-
#initialize(ptr, retain = true) ⇒ Program
constructor
Creates a new Program and retains it if specified and aplicable.
- #inspect ⇒ Object
- #kernel_names ⇒ Object
-
#kernels ⇒ Object
Returns an Array of Kernel corresponding to the kernels defined inside the Program.
-
#method_missing(m, *a, &b) ⇒ Object
Intercepts a call to a missing method and tries to see if it is defined as a Kernel inside the Program.
-
#num_devices ⇒ Object
Returns the OpenCL::Program::num_devices info.
- #orig_method_missing ⇒ Object
-
#reference_count ⇒ Object
Returns the OpenCL::Program::reference_count info.
-
#source ⇒ Object
Returns the OpenCL::Program::source info.
Methods included from OpenCL21
Methods included from OpenCL20
#build_global_variable_total_size
Methods included from OpenCL12
#binary_type, #compile, #num_kernels
Methods inherited from ExtendedStruct
Constructor Details
#initialize(ptr, retain = true) ⇒ Program
Creates a new Program and retains it if specified and aplicable
1322 1323 1324 1325 1326 |
# File 'lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb', line 1322 def initialize(ptr, retain = true) super(ptr) OpenCL.clRetainProgram(ptr) if retain #STDERR.puts "Allocating Program: #{ptr}" end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *a, &b) ⇒ Object
Intercepts a call to a missing method and tries to see if it is defined as a Kernel inside the Program. It then calls the Kernel enqueue_with_args method. Thanks pyopencl (Andreas Klöeckner) for the idea
223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/opencl_ruby_ffi/Program.rb', line 223 def method_missing(m, *a, &b) m_string = m.to_s k = nil begin k = self.create_kernel(m_string) rescue Error k = nil end if k then k.enqueue_with_args(*a, &b) else orig_method_missing(m, *a, &b) end end |
Instance Method Details
#binaries ⇒ Object
Returns the binaries associated to the Program for each Device. Returns an Array of tuple [ Device, String ]
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/opencl_ruby_ffi/Program.rb', line 264 def binaries sizes = self.binary_sizes bin_array = MemoryPointer::new( :pointer, sizes.length ) total_size = 0 pointers = [] sizes.each_with_index { |s, i| total_size += s pointers[i] = MemoryPointer::new(s) bin_array[i].write_pointer(pointers[i]) } error = OpenCL.clGetProgramInfo(self, BINARIES, total_size, bin_array, nil) error_check(error) bins = [] devs = self.devices sizes.each_with_index { |s, i| bins.push [devs[i], pointers[i].read_bytes(s)] } return bins end |
#binary_sizes ⇒ Object
Returns the OpenCL::Program::binary_sizes info
261 |
# File 'lib/opencl_ruby_ffi/Program.rb', line 261 get_info_array("Program", :size_t, "binary_sizes") |
#build(options = { }, &block) ⇒ Object
Builds (compile and link) the Program created from sources or binary
Attributes
-
options
- a hash containing named options -
block
- if provided, a callback invoked when the Program is built. Signature of the callback is { |Program, Pointer to user_data| … }
Options
-
:device_list
- an Array of Device to build the program for -
:user_data
- a Pointer (or convertible to Pointer using to_ptr) to the memory area to pass to the callback -
:options
- a String containing the options to use for the build
337 338 339 |
# File 'lib/opencl_ruby_ffi/Program.rb', line 337 def build( = { }, &block) OpenCL.build_program(self, , &block) end |
#build_log(devs = nil) ⇒ Object
Returns the build log for each Device associated to the Program or the Device(s) specified. Returns an Array of tuple [ Device, String ]
312 313 314 315 316 317 318 319 320 321 322 323 324 |
# File 'lib/opencl_ruby_ffi/Program.rb', line 312 def build_log(devs = nil) devs = self.devices if not devs devs = [devs].flatten return devs.collect { |dev| ptr1 = MemoryPointer::new( :size_t, 1) error = OpenCL.clGetProgramBuildInfo(self, dev, BUILD_LOG, 0, nil, ptr1) error_check(error) ptr2 = MemoryPointer::new( ptr1.read_size_t ) error = OpenCL.clGetProgramBuildInfo(self, dev, BUILD_LOG, ptr1.read_size_t, ptr2, nil) error_check(error) [dev, ptr2.read_string] } end |
#build_options(devs = nil) ⇒ Object
Returns the build options for each Device associated to the Program or the Device(s) specified. Returns an Array of tuple [ Device, String ]
297 298 299 300 301 302 303 304 305 306 307 308 309 |
# File 'lib/opencl_ruby_ffi/Program.rb', line 297 def (devs = nil) devs = self.devices if not devs devs = [devs].flatten return devs.collect { |dev| ptr1 = MemoryPointer::new( :size_t, 1) error = OpenCL.clGetProgramBuildInfo(self, dev, BUILD_OPTIONS, 0, nil, ptr1) error_check(error) ptr2 = MemoryPointer::new( ptr1.read_size_t ) error = OpenCL.clGetProgramBuildInfo(self, dev, BUILD_OPTIONS, ptr1.read_size_t, ptr2, nil) error_check(error) [dev, ptr2.read_string] } end |
#build_status(devs = nil) ⇒ Object
Returns the BuildStatus of the Program for each device associated to the Program or the Device(s) specified. Returns an Array of tuple [ Device, BuildStatus ]
285 286 287 288 289 290 291 292 293 294 |
# File 'lib/opencl_ruby_ffi/Program.rb', line 285 def build_status(devs = nil) devs = self.devices if not devs devs = [devs].flatten ptr = MemoryPointer::new( :cl_build_status ) return devs.collect { |dev| error = OpenCL.clGetProgramBuildInfo(self, dev, BUILD_STATUS, ptr.size, ptr, nil) error_check(error) [dev, BuildStatus::new(ptr.read_cl_build_status)] } end |
#context ⇒ Object
Returns the Context the Program is associated to
239 240 241 242 243 244 |
# File 'lib/opencl_ruby_ffi/Program.rb', line 239 def context ptr = MemoryPointer::new( Context ) error = OpenCL.clGetProgramInfo(self, CONTEXT, Context.size, ptr, nil) error_check(error) return Context::new( ptr.read_pointer ) end |
#create_kernel(name) ⇒ Object
Returns the Kernel corresponding the the specified name in the Program
342 343 344 |
# File 'lib/opencl_ruby_ffi/Program.rb', line 342 def create_kernel( name ) return OpenCL.create_kernel( self, name ) end |
#devices ⇒ Object
Returns the Array of Device the Program is associated with
250 251 252 253 254 255 256 257 258 |
# File 'lib/opencl_ruby_ffi/Program.rb', line 250 def devices n = self.num_devices ptr2 = MemoryPointer::new( Device, n ) error = OpenCL.clGetProgramInfo(self, DEVICES, Device.size*n, ptr2, nil) error_check(error) return ptr2.get_array_of_pointer(0, n).collect { |device_ptr| Device::new(device_ptr) } end |
#inspect ⇒ Object
211 212 213 214 215 216 217 |
# File 'lib/opencl_ruby_ffi/Program.rb', line 211 def inspect success = false build_status.each { |d,s| success |= true if s.to_i == BuildStatus::SUCCESS } return "#<#{self.class.name}: #{success ? kernel_names : ""}>" end |
#kernel_names ⇒ Object
351 352 353 |
# File 'lib/opencl_ruby_ffi/Program.rb', line 351 def kernel_names return kernels.collect(&:name) end |
#kernels ⇒ Object
Returns an Array of Kernel corresponding to the kernels defined inside the Program
347 348 349 |
# File 'lib/opencl_ruby_ffi/Program.rb', line 347 def kernels return OpenCL.create_kernels_in_program( self ) end |
#num_devices ⇒ Object
Returns the OpenCL::Program::num_devices info
246 |
# File 'lib/opencl_ruby_ffi/Program.rb', line 246 get_info("Program", :cl_uint, "num_devices") |
#orig_method_missing ⇒ Object
219 |
# File 'lib/opencl_ruby_ffi/Program.rb', line 219 alias_method :orig_method_missing, :method_missing |
#reference_count ⇒ Object
Returns the OpenCL::Program::reference_count info
247 |
# File 'lib/opencl_ruby_ffi/Program.rb', line 247 get_info("Program", :cl_uint, "reference_count") |
#source ⇒ Object
Returns the OpenCL::Program::source info
260 |
# File 'lib/opencl_ruby_ffi/Program.rb', line 260 get_info("Program", :string, "source") |