Class: OpenCL::Context
- Inherits:
-
FFI::ManagedStruct
- Object
- FFI::ManagedStruct
- OpenCL::Context
- Defined in:
- lib/opencl_ruby_ffi/Context.rb,
lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb
Overview
Maps the cl_context object of OpenCL
Constant Summary collapse
- REFERENCE_COUNT =
:stopdoc:
0x1080- DEVICES =
0x1081- PROPERTIES =
0x1082- NUM_DEVICES =
0x1083- PLATFORM =
0x1084- INTEROP_USER_SYNC =
0x1085- MEMORY_INITIALIZE_KHR =
0x200E- TERMINATE_KHR =
0x2010
Class Method Summary collapse
-
.release(ptr) ⇒ Object
method called at Context deletion, releases the object if aplicable.
Instance Method Summary collapse
-
#create_buffer(size, options = {}) ⇒ Object
Creates a Buffer in the Context.
-
#create_command_queue(device, options = {}) ⇒ Object
Creates a CommandQueue in Context targeting the specified Device.
-
#create_from_GL_buffer(bufobj, options = {}) ⇒ Object
Creates a Buffer in the Context from an opengl buffer.
-
#create_from_GL_render_buffer(renderbuffer, options = {}) ⇒ Object
Creates an Image in the Context from an OpenGL render buffer.
-
#create_from_GL_texture(texture_target, texture, options = {}) ⇒ Object
Creates an Image in the Context from an OpenGL texture.
-
#create_from_GL_texture_2D(texture_target, texture, options = {}) ⇒ Object
Creates an Image in the Context from an OpenGL 2D texture.
-
#create_from_GL_texture_3D(texture_target, texture, options = {}) ⇒ Object
Creates an Image in the Context from an OpenGL 3D texture.
-
#create_image(format, desc, options = {}) ⇒ Object
Creates an Image in the Context.
-
#create_image_1D(format, width, options = {}) ⇒ Object
Creates a 1D Image in the Context.
-
#create_image_2D(format, width, height, options = {}) ⇒ Object
Creates a 2D Image in the Context.
-
#create_image_3D(format, width, height, depth, options = {}) ⇒ Object
Creates a 3D Image in the Context.
-
#create_pipe(pipe_packet_size, pipe_max_packets, opts = {}) ⇒ Object
Creates a Pipe in the Context.
-
#create_program_with_binary(device_list, binaries) ⇒ Object
Creates a Program from binary.
-
#create_program_with_built_in_kernels(device_list, kernel_names) ⇒ Object
Creates a Program from a list of built in kernel names.
-
#create_program_with_source(strings) ⇒ Object
Creates a Program from sources in the Context.
-
#create_sampler(options = {}) ⇒ Object
Creates a Sampler in the Context.
-
#create_user_event ⇒ Object
Creates a user Event in the Context.
-
#devices ⇒ Object
Returns an Array of Device associated to the Context.
-
#get_info_array ⇒ Object
:method: properties the Array of :cl_context_properties used to create the Context.
-
#initialize(ptr, retain = true) ⇒ Context
constructor
Creates a new Context and retains it if specified and aplicable.
-
#link_program(input_programs, options = {}, &block) ⇒ Object
Links a set of compiled programs for all device in the Context, or a subset of devices.
-
#num_devices ⇒ Object
Returns the number of devices associated to the Context.
-
#platform ⇒ Object
Returns the platform associated to the Context.
-
#prop ⇒ Object
:method: reference_count Returns the reference count of the Context.
-
#supported_image_formats(image_type, options = {}) ⇒ Object
Returns an Array of ImageFormat that are supported for a given image type in the Context.
-
#svm_alloc(size, options = {}) ⇒ Object
Creates an SVMPointer pointing to an SVM area of memory in the Context.
-
#svm_free(svm_pointer) ⇒ Object
Frees an SVMPointer.
-
#to_s ⇒ Object
:startdoc:.
Constructor Details
#initialize(ptr, retain = true) ⇒ Context
Creates a new Context and retains it if specified and aplicable
2778 2779 2780 2781 2782 |
# File 'lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb', line 2778 def initialize(ptr, retain = true) super(ptr) OpenCL.clRetainContext(ptr) if retain #STDERR.puts "Allocating Context: #{ptr}" end |
Class Method Details
.release(ptr) ⇒ Object
method called at Context deletion, releases the object if aplicable
2785 2786 2787 2788 2789 2790 2791 2792 2793 |
# File 'lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb', line 2785 def self.release(ptr) #STDERR.puts "Releasing Context: #{ptr}" #ref_count = FFI::MemoryPointer::new( :cl_uint ) #OpenCL.clGetContextInfo(ptr, OpenCL::Context::REFERENCE_COUNT, ref_count.size, ref_count, nil) #STDERR.puts "reference counter: #{ref_count.read_cl_uint}" error = OpenCL.clReleaseContext(ptr) #STDERR.puts "Object released! #{error}" error_check( error ) end |
Instance Method Details
#create_buffer(size, options = {}) ⇒ Object
Creates a Buffer in the Context
Attributes
-
size- size of the Buffer to be created -
options- a hash containing named options
Options
-
:flags- a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Buffer -
:host_ptr- if provided, the Pointer (or convertible to Pointer using to_ptr) to the memory area to use
151 152 153 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 151 def create_buffer( size, = {} ) return OpenCL.create_buffer( self, size, ) end |
#create_command_queue(device, options = {}) ⇒ Object
Creates a CommandQueue in Context targeting the specified Device
Attributes
-
device- the Device targetted by the CommandQueue being created -
options- a hash containing named options
Options
-
:properties- a single or an Array of :cl_command_queue_properties -
:size- the size of the command queue ( if ON_DEVICE is specified in the properties ) 2.0+ only
136 137 138 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 136 def create_command_queue( device, = {} ) return OpenCL.create_command_queue( self, device, ) end |
#create_from_GL_buffer(bufobj, options = {}) ⇒ Object
Creates a Buffer in the Context from an opengl buffer
Attributes
-
bufobj- opengl buffer object -
options- a hash containing named options
Options
-
:flags- a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Image
165 166 167 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 165 def create_from_GL_buffer( bufobj, = {} ) return OpenCL.create_from_GL_buffer( self, bufobj, ) end |
#create_from_GL_render_buffer(renderbuffer, options = {}) ⇒ Object
Creates an Image in the Context from an OpenGL render buffer
Attributes
-
renderbuf- opengl render buffer -
options- a hash containing named options
Options
-
:flags- a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Image
179 180 181 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 179 def create_from_GL_render_buffer( renderbuffer, = {} ) return OpenCL.create_from_GL_render_buffer( self, renderbuffer, ) end |
#create_from_GL_texture(texture_target, texture, options = {}) ⇒ Object
Creates an Image in the Context from an OpenGL texture
Attributes
-
texture_target- a :GLenum defining the image type of texture -
texture- a :GLuint specifying the name of the texture -
options- a hash containing named options
Options
-
:miplevel- a :GLint specifying the mipmap level to be used (default 0) -
:flags- a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Image
195 196 197 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 195 def create_from_GL_texture( texture_target, texture, = {} ) return OpenCL.create_from_GL_texture( self, texture_target, texture, ) end |
#create_from_GL_texture_2D(texture_target, texture, options = {}) ⇒ Object
Creates an Image in the Context from an OpenGL 2D texture
Attributes
-
texture_target- a :GLenum defining the image type of texture -
texture- a :GLuint specifying the name of the texture -
options- a hash containing named options
Options
-
:miplevel- a :GLint specifying the mipmap level to be used (default 0) -
:flags- a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Image
211 212 213 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 211 def create_from_GL_texture_2D( texture_target, texture, = {} ) return OpenCL.create_from_GL_texture_2D( self, texture_target, texture, ) end |
#create_from_GL_texture_3D(texture_target, texture, options = {}) ⇒ Object
Creates an Image in the Context from an OpenGL 3D texture
Attributes
-
texture_target- a :GLenum defining the image type of texture -
texture- a :GLuint specifying the name of the texture -
options- a hash containing named options
Options
-
:miplevel- a :GLint specifying the mipmap level to be used (default 0) -
:flags- a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Image
227 228 229 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 227 def create_from_GL_texture_3D( texture_target, texture, = {} ) return OpenCL.create_from_GL_texture_3D( self, texture_target, texture, ) end |
#create_image(format, desc, options = {}) ⇒ Object
Creates an Image in the Context
Attributes
-
format- an ImageFormat -
options- an ImageDesc
Options
-
:flags- a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Buffer -
:host_ptr- if provided, the Pointer (or convertible to Pointer using to_ptr) to the memory area to use
242 243 244 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 242 def create_image( format, desc, = {} ) return OpenCL.create_image( self, format, desc, ) end |
#create_image_1D(format, width, options = {}) ⇒ Object
Creates a 1D Image in the Context
Attributes
-
format- an ImageFormat -
width- width of the image
Options
-
:flags- a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Buffer -
:host_ptr- if provided, the Pointer (or convertible to Pointer using to_ptr) to the memory area to use
257 258 259 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 257 def create_image_1D( format, width, = {} ) return OpenCL.create_image_1D( self, format, width, ) end |
#create_image_2D(format, width, height, options = {}) ⇒ Object
Creates a 2D Image in the Context
Attributes
-
format- an ImageFormat -
width- width of the image
Options
-
:flags- a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Buffer -
:host_ptr- if provided, the Pointer (or convertible to Pointer using to_ptr) to the memory area to use -
:row_pitch- if provided the row_pitch of data in host_ptr
273 274 275 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 273 def create_image_2D( format, width, height, = {} ) return OpenCL.create_image_2D( self, format, width, height, ) end |
#create_image_3D(format, width, height, depth, options = {}) ⇒ Object
Creates a 3D Image in the Context
Attributes
-
format- an ImageFormat -
width- width of the image
Options
-
:flags- a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Buffer -
:host_ptr- if provided, the Pointer (or convertible to Pointer using to_ptr) to the memory area to use -
:row_pitch- if provided the row_pitch of data in host_ptr -
:slice_pitch- if provided the slice_pitch of data in host_ptr
290 291 292 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 290 def create_image_3D( format, width, height, depth, = {} ) return OpenCL.create_image_3D( self, format, width, height, depth, ) end |
#create_pipe(pipe_packet_size, pipe_max_packets, opts = {}) ⇒ Object
Creates a Pipe in the Context
Attributes
-
pipe_packet_size- size of a packet in the Pipe -
pipe_max_packets- size of the Pipe in packet
Options
-
:flags- a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Buffer
379 380 381 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 379 def create_pipe( pipe_packet_size, pipe_max_packets, opts = {} ) return OpenCL.create_pipe( self, pipe_packet_size, pipe_max_packets, opts ) end |
#create_program_with_binary(device_list, binaries) ⇒ Object
Creates a Program from binary
Attributes
-
device_list- an Array of Device to create the program for. Can throw an OpenCL::Invalid value if the number of supplied devices is different from the number of supplied binaries. -
binaries- Array of binaries
332 333 334 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 332 def create_program_with_binary( device_list, binaries) return OpenCL.create_program_with_binary(self, device_list, binaries) end |
#create_program_with_built_in_kernels(device_list, kernel_names) ⇒ Object
Creates a Program from a list of built in kernel names
Attributes
-
device_list- an Array of Device to create the program for -
kernel_names- a single or an Array of String representing the kernel names
342 343 344 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 342 def create_program_with_built_in_kernels( device_list, kernel_names ) return OpenCL.create_program_with_built_in_kernels(self, device_list, kernel_names ) end |
#create_program_with_source(strings) ⇒ Object
Creates a Program from sources in the Context
Attributes
-
strings- a single or an Array of String repesenting the program source code
351 352 353 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 351 def create_program_with_source( strings ) return OpenCL.create_program_with_source(self, strings) end |
#create_sampler(options = {}) ⇒ Object
Creates a Sampler in the Context
Options
-
:normalized_coords- a :cl_bool specifying if the image coordinates are normalized -
:addressing_mode- a :cl_addressing_mode specifying how out-of-range image coordinates are handled when reading from an image -
:filter_mode- a :cl_filter_mode specifying the type of filter that must be applied when reading an image -
:mip_filter_mode- the filtering mode to use if using mimaps (default CL_FILTER_NONE, requires cl_khr_mipmap_image) -
:lod_min- floating point value representing the minimal LOD (default 0.0f, requires cl_khr_mipmap_image) -
:lod_max- floating point value representing the maximal LOD (default MAXFLOAT, requires cl_khr_mipmap_image)
365 366 367 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 365 def create_sampler( = {} ) return OpenCL.create_sampler( self, ) end |
#create_user_event ⇒ Object
Creates a user Event in the Context
305 306 307 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 305 def create_user_event return OpenCL.create_user_event(self) end |
#devices ⇒ Object
Returns an Array of Device associated to the Context
92 93 94 95 96 97 98 99 100 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 92 def devices n = self.num_devices ptr2 = FFI::MemoryPointer::new( Device, n ) error = OpenCL.clGetContextInfo(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 |
#get_info_array ⇒ Object
:method: properties the Array of :cl_context_properties used to create the Context
68 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 68 eval get_info_array("Context", :cl_context_properties, "PROPERTIES") |
#link_program(input_programs, options = {}, &block) ⇒ Object
Links a set of compiled programs for all device in the Context, or a subset of devices
Attributes
-
input_programs- a single or an Array of Program -
options- a Hash containing named options -
block- if provided, a callback invoked when the Program is built. Signature of the callback is { |Program, FFI::Pointer to user_data| … }
Options
-
:device_list- an Array of Device to build the program for -
:options- a String containing the options to use for the build -
:user_data- a Pointer (or convertible to Pointer using to_ptr) to the memory area to pass to the callback
322 323 324 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 322 def link_program( input_programs, = {}, &block) return OpenCL.link_program(self, input_programs, , &block) end |
#num_devices ⇒ Object
Returns the number of devices associated to the Context
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 76 def num_devices d_n = 0 ptr = FFI::MemoryPointer::new( :size_t ) error = OpenCL.clGetContextInfo(self, DEVICES, 0, nil, ptr) error_check(error) d_n = ptr.read_size_t / Platform.size # else # ptr = FFI::MemoryPointer::new( :cl_uint ) # error = OpenCL.clGetContextInfo(self, OpenCL::Context::NUM_DEVICES, ptr.size, ptr, nil) # OpenCL.error_check(error) # d_n = ptr.read_cl_uint # end return d_n end |
#platform ⇒ Object
Returns the platform associated to the Context
71 72 73 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 71 def platform self.devices.first.platform end |
#prop ⇒ Object
:method: reference_count Returns the reference count of the Context
61 62 63 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 61 %w( REFERENCE_COUNT ).each { |prop| eval get_info("Context", :cl_uint, prop) } |
#supported_image_formats(image_type, options = {}) ⇒ Object
Returns an Array of ImageFormat that are supported for a given image type in the Context
Attributes
-
image_type- a :cl_mem_object_type specifying the type of Image being queried -
options- a hash containing named options
Options
-
:flags- a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Buffer
111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 111 def supported_image_formats( image_type, = {} ) flags = get_flags( ) num_image_formats = FFI::MemoryPointer::new( :cl_uint ) error = OpenCL.clGetSupportedImageFormats( self, flags, image_type, 0, nil, num_image_formats ) error_check(error) num_entries = num_image_formats.read_cl_uint image_formats = FFI::MemoryPointer::new( ImageFormat, num_entries ) error = OpenCL.clGetSupportedImageFormats( self, flags, image_type, num_entries, image_formats, nil ) error_check(error) return num_entries.times.collect { |i| ImageFormat::from_pointer( image_formats + i * ImageFormat.size ) } end |
#svm_alloc(size, options = {}) ⇒ Object
Creates an SVMPointer pointing to an SVM area of memory in the Context
Attributes
-
size- the size of the mmemory area to allocate -
options- a hash containing named options
Options
-
:alignment- imposes the minimum alignment in byte
393 394 395 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 393 def svm_alloc(size, = {}) return OpenCL.svm_alloc( self, size, ) end |
#svm_free(svm_pointer) ⇒ Object
Frees an SVMPointer
Attributes
-
svm_pointer- the SVMPointer to deallocate
402 403 404 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 402 def svm_free(svm_pointer) return OpenCL.svm_free(self, svm_pointer) end |
#to_s ⇒ Object
:startdoc:
2796 2797 2798 2799 2800 2801 2802 |
# File 'lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb', line 2796 def to_s if self.respond_to?(:name) then return self.name else return super end end |