Class: OpenCL::Context
- Inherits:
-
ExtendedStruct
- Object
- ManagedStruct
- ExtendedStruct
- OpenCL::Context
- Includes:
- AcceleratorINTEL, KHRGLEvent, KHRGLSharing, KHRTerminateContext, OpenCL11, OpenCL12, OpenCL20, OpenCL21, OpenCL30, UnifiedSharedMemoryPreviewINTEL
- Defined in:
- lib/opencl_ruby_ffi/Context.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/gl_event.rb,
lib/opencl_ruby_ffi/khr/gl_sharing.rb,
lib/opencl_ruby_ffi/khr/d3d10_sharing.rb,
lib/opencl_ruby_ffi/khr/d3d11_sharing.rb,
lib/opencl_ruby_ffi/khr/initalize_memory.rb,
lib/opencl_ruby_ffi/khr/dx9_media_sharing.rb,
lib/opencl_ruby_ffi/khr/terminate_context.rb,
lib/opencl_ruby_ffi/intel/driver_diagnostics.rb,
lib/opencl_ruby_ffi/intel/unified_shared_memory_preview.rb,
lib/opencl_ruby_ffi/intel/accelerator.rb
Overview
Maps the cl_context object of OpenCL
Defined Under Namespace
Modules: AcceleratorINTEL, KHRGLEvent, KHRGLSharing, KHRTerminateContext, OpenCL11, OpenCL12, OpenCL20, OpenCL21, OpenCL30, UnifiedSharedMemoryPreviewINTEL Classes: Properties
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
(also: #create_from_GL_buffer)
Creates a Buffer in the Context from an opengl buffer.
-
#create_from_gl_renderbuffer(renderbuffer, options = {}) ⇒ Object
(also: #create_from_GL_renderbuffer)
Creates an Image in the Context from an OpenGL render buffer.
-
#create_from_gl_texture_2d(texture_target, texture, options = {}) ⇒ Object
(also: #create_from_GL_texture_2D)
Creates an Image in the Context from an OpenGL 2D texture.
-
#create_from_gl_texture_3d(texture_target, texture, options = {}) ⇒ Object
(also: #create_from_GL_texture_3D)
Creates an Image in the Context from an OpenGL 3D texture.
-
#create_image_1d(format, width, options = {}) ⇒ Object
(also: #create_image_1D)
Creates a 1D Image in the Context.
-
#create_image_2d(format, width, height, options = {}) ⇒ Object
(also: #create_image_2D)
Creates a 2D Image in the Context.
-
#create_image_3d(format, width, height, depth, options = {}) ⇒ Object
(also: #create_image_3D)
Creates a 3D Image in the Context.
-
#create_program_with_binary(device_list, binaries) ⇒ Object
Creates a Program from binary.
-
#create_program_with_source(strings) ⇒ Object
Creates a Program from sources in the Context.
-
#create_sampler(options = {}) ⇒ Object
Creates a Sampler in the Context.
-
#devices ⇒ Object
Returns an Array of Device associated to the Context.
-
#initialize(ptr, retain = true) ⇒ Context
constructor
Creates a new Context and retains it if specified and aplicable.
- #inspect ⇒ Object
-
#num_devices ⇒ Object
Returns the number of devices associated to the Context.
-
#platform ⇒ Object
Returns the platform associated to the Context.
-
#properties ⇒ Object
the Array of :cl_context_properties used to create the Context.
-
#reference_count ⇒ Object
Returns the OpenCL::Context::reference_count info.
-
#supported_image_formats(image_type, options = {}) ⇒ Object
Returns an Array of ImageFormat that are supported for a given image type in the Context.
Methods included from AcceleratorINTEL
#__release_accelerator_intel, #__retain_accelerator_intel, #create_accelerator_intel
Methods included from UnifiedSharedMemoryPreviewINTEL
#clDeviceMemAllocINTEL, #clGetMemAllocInfoINTEL, #clHostMemAllocINTEL, #clMemFreeINTEL, #clSharedMemAllocINTEL, #device_mem_alloc_intel, #host_mem_alloc_intel, #mem_alloc_base_ptr_intel, #mem_alloc_device_intel, #mem_alloc_flags_intel, #mem_alloc_size_intel, #mem_alloc_type_intel, #mem_free_intel, #shared_mem_alloc_intel
Methods included from KHRTerminateContext
Methods included from KHRGLSharing
Methods included from KHRGLEvent
Methods included from OpenCL30
Methods included from OpenCL21
#create_program_with_il, #set_default_device_command_queue
Methods included from OpenCL20
#create_pipe, #svm_alloc, #svm_free
Methods included from OpenCL12
#create_from_gl_texture, #create_image, #create_program_with_built_in_kernels, #link_program
Methods included from OpenCL11
Methods inherited from ExtendedStruct
Constructor Details
#initialize(ptr, retain = true) ⇒ Context
Creates a new Context and retains it if specified and aplicable
1147 1148 1149 1150 1151 |
# File 'lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb', line 1147 def initialize(ptr, retain = true) super(ptr) OpenCL.clRetainContext(ptr) if retain #STDERR.puts "Allocating Context: #{ptr}" 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
224 225 226 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 224 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
209 210 211 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 209 def create_command_queue( device, = {} ) return OpenCL.create_command_queue( self, device, ) end |
#create_from_gl_buffer(bufobj, options = {}) ⇒ Object Also known as: create_from_GL_buffer
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
238 239 240 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 238 def create_from_gl_buffer( bufobj, = {} ) return OpenCL.create_from_gl_buffer( self, bufobj, ) end |
#create_from_gl_renderbuffer(renderbuffer, options = {}) ⇒ Object Also known as: create_from_GL_renderbuffer
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
253 254 255 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 253 def create_from_gl_renderbuffer( renderbuffer, = {} ) return OpenCL.create_from_gl_renderbuffer( self, renderbuffer, ) end |
#create_from_gl_texture_2d(texture_target, texture, options = {}) ⇒ Object Also known as: create_from_GL_texture_2D
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
270 271 272 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 270 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 Also known as: create_from_GL_texture_3D
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
287 288 289 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 287 def create_from_gl_texture_3d( texture_target, texture, = {} ) return OpenCL.create_from_gl_texture_3d( self, texture_target, texture, ) end |
#create_image_1d(format, width, options = {}) ⇒ Object Also known as: create_image_1D
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
303 304 305 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 303 def create_image_1d( format, width, = {} ) return OpenCL.create_image_1d( self, format, width, ) end |
#create_image_2d(format, width, height, options = {}) ⇒ Object Also known as: create_image_2D
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
320 321 322 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 320 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 Also known as: create_image_3D
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
338 339 340 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 338 def create_image_3d( format, width, height, depth, = {} ) return OpenCL.create_image_3d( self, format, width, height, depth, ) 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
349 350 351 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 349 def create_program_with_binary( device_list, binaries) return OpenCL.create_program_with_binary(self, device_list, binaries) 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
358 359 360 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 358 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)
372 373 374 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 372 def create_sampler( = {} ) return OpenCL.create_sampler( self, ) end |
#devices ⇒ Object
Returns an Array of Device associated to the Context
128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 128 def devices @_devices ||= begin n = self.num_devices ptr2 = MemoryPointer::new( Device, n ) error = OpenCL.clGetContextInfo(self, DEVICES, Device.size*n, ptr2, nil) error_check(error) ptr2.get_array_of_pointer(0, n).collect { |device_ptr| Device::new(device_ptr) } end end |
#inspect ⇒ Object
111 112 113 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 111 def inspect return "#<#{self.class.name}: #{self.devices}>" end |
#num_devices ⇒ Object
Returns the number of devices associated to the Context
118 119 120 121 122 123 124 125 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 118 def num_devices @_num_devices ||= begin ptr = MemoryPointer::new( :size_t ) error = OpenCL.clGetContextInfo(self, DEVICES, 0, nil, ptr) error_check(error) ptr.read_size_t / Platform.size end end |
#platform ⇒ Object
Returns the platform associated to the Context
170 171 172 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 170 def platform @_platform ||= self.devices.first.platform end |
#properties ⇒ Object
the Array of :cl_context_properties used to create the Context
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 143 def properties ptr1 = MemoryPointer::new( :size_t, 1) error = OpenCL.clGetContextInfo(self, PROPERTIES, 0, nil, ptr1) error_check(error) return [] if ptr1.read_size_t == 0 ptr2 = MemoryPointer::new( ptr1.read_size_t ) error = OpenCL.clGetContextInfo(self, PROPERTIES, ptr1.read_size_t, ptr2, nil) error_check(error) arr = ptr2.get_array_of_cl_context_properties(0, ptr1.read_size_t/ OpenCL.find_type(:cl_context_properties).size) return arr if arr.length == 1 and arr[0].to_i == 0 arr_2 = [] while arr.length > 2 do prop = arr.shift.to_i arr_2.push Properties::new(prop) return arr_2 if arr.length <= 0 if prop == Properties::PLATFORM then arr_2.push Platform::new(arr.shift) else arr_2.push arr.shift.to_i end return arr_2 if arr.length <= 0 end arr_2.push arr.shift.to_i if arr.length > 0 return arr_2 end |
#reference_count ⇒ Object
Returns the OpenCL::Context::reference_count info
115 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 115 get_info("Context", :cl_uint, "reference_count") |
#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
183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/opencl_ruby_ffi/Context.rb', line 183 def supported_image_formats( image_type, = {} ) flags = get_flags( ) flags = Mem::Flags::READ_WRITE if flags.to_i == 0 #ensure default READ_WRITE, Intel bug. num_image_formats = 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 = 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::new( image_formats + i * ImageFormat.size ) } end |
Constant Summary collapse
- REFERENCE_COUNT =
0x1080
- DEVICES =
0x1081
- PROPERTIES =
0x1082
- NUM_DEVICES =
0x1083
- PLATFORM =
0x1084
- INTEROP_USER_SYNC =
0x1085
- D3D10_DEVICE_KHR =
0x4014
- D3D10_PREFER_SHARED_RESOURCES_KHR =
0x402C
- D3D11_DEVICE_KHR =
0x401D
- D3D11_PREFER_SHARED_RESOURCES_KHR =
0x402D
- MEMORY_INITIALIZE_KHR =
0x200E
- ADAPTER_D3D9_KHR =
0x2025
- ADAPTER_D3D9EX_KHR =
0x2026
- ADAPTER_DXVA_KHR =
0x2027
- TERMINATE_KHR =
0x2032
- DRIVER_DIAGNOSTICS_INTEL =
0x4106
- SHOW_DIAGNOSTICS_INTEL =
0x4106
- DIAGNOSTICS_LEVEL_GOOD_INTEL =
0x1
- DIAGNOSTICS_LEVEL_BAD_INTEL =
0x2
- DIAGNOSTICS_LEVEL_NEUTRAL_INTEL =
0x4