Class: OpenCL::Mem
- Inherits:
-
FFI::ManagedStruct
- Object
- FFI::ManagedStruct
- OpenCL::Mem
- Defined in:
- lib/opencl_ruby_ffi/Mem.rb,
lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb,
lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb
Overview
Maps the cl_mem object of OpenCL
Defined Under Namespace
Classes: Flags, MigrationFlags, SVMFlags, Type
Constant Summary collapse
- READ_WRITE =
:stopdoc:
(1 << 0)
- WRITE_ONLY =
(1 << 1)
- READ_ONLY =
(1 << 2)
- USE_HOST_PTR =
(1 << 3)
- ALLOC_HOST_PTR =
(1 << 4)
- COPY_HOST_PTR =
(1 << 5)
- HOST_WRITE_ONLY =
(1 << 7)
- HOST_READ_ONLY =
(1 << 8)
- HOST_NO_ACCESS =
(1 << 9)
- SVM_FINE_GRAIN_BUFFER =
(1 << 10)
- SVM_ATOMICS =
(1 << 11)
- BUFFER =
0x10F0- IMAGE2D =
0x10F1- IMAGE3D =
0x10F2- IMAGE2D_ARRAY =
0x10F3- IMAGE1D =
0x10F4- IMAGE1D_ARRAY =
0x10F5- IMAGE1D_BUFFER =
0x10F6- PIPE =
0x10F7- TYPE =
0x1100- FLAGS =
0x1101- SIZE =
0x1102- HOST_PTR =
0x1103- MAP_COUNT =
0x1104- REFERENCE_COUNT =
0x1105- CONTEXT =
0x1106- ASSOCIATED_MEMOBJECT =
0x1107- OFFSET =
0x1108- USES_SVM_POINTER =
0x1109- HOST_UNCACHED_QCOM =
0x40A4- HOST_WRITEBACK_QCOM =
0x40A5- HOST_WRITETHROUGH_QCOM =
0x40A6- HOST_WRITE_COMBINING_QCOM =
0x40A7- ION_HOST_PTR_QCOM =
0x40A8
Class Method Summary collapse
-
.release(ptr) ⇒ Object
method called at Mem deletion, releases the object if aplicable.
Instance Method Summary collapse
-
#associated_memobject ⇒ Object
Returns the Buffer this Buffer was created from using create_sub_buffer.
-
#context ⇒ Object
Returns the Context associated to the Mem.
-
#get_info ⇒ Object
:method: host_ptr() Returns the host Pointer specified at Mem creation or the pointer + the ofsset if it is a sub-buffer.
-
#GL_mimap_level ⇒ Object
Returns the miplevel argument specified in create_from_GL_texture for Mem.
-
#GL_object_name ⇒ Object
Returns the name of the GL object associated with Mem.
-
#GL_object_type ⇒ Object
Returns the type of the GL object associated with Mem.
-
#GL_texture_target ⇒ Object
Returns the texture_target argument specified in create_from_GL_texture for Mem.
-
#initialize(ptr, retain = true) ⇒ Mem
constructor
Creates a new Mem and retains it if specified and aplicable.
-
#platform ⇒ Object
Returns the Platform associated to the Mem.
-
#prop ⇒ Object
:method: reference_count() Returns the Mem reference counter.
-
#set_destructor_callback(options = {}, &proc) ⇒ Object
Attaches a callback to memobj that will be called on the memobj destruction.
- #to_s ⇒ Object
Constructor Details
#initialize(ptr, retain = true) ⇒ Mem
Creates a new Mem and retains it if specified and aplicable
1226 1227 1228 1229 1230 |
# File 'lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb', line 1226 def initialize(ptr, retain = true) super(ptr) OpenCL.clRetainMemObject(ptr) if retain #STDERR.puts "Allocating Mem: #{ptr}" end |
Class Method Details
.release(ptr) ⇒ Object
method called at Mem deletion, releases the object if aplicable
1241 1242 1243 1244 1245 1246 1247 1248 1249 |
# File 'lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb', line 1241 def self.release(ptr) #STDERR.puts "Releasing Mem: #{ptr}" #ref_count = FFI::MemoryPointer::new( :cl_uint ) #OpenCL.clGetMemObjectInfo(ptr, OpenCL::Mem::REFERENCE_COUNT, ref_count.size, ref_count, nil) #STDERR.puts "reference counter: #{ref_count.read_cl_uint}" error = OpenCL.clReleaseMemObject(ptr) #STDERR.puts "Object released! #{error}" OpenCL.error_check( error ) end |
Instance Method Details
#associated_memobject ⇒ Object
Returns the Buffer this Buffer was created from using create_sub_buffer
38 39 40 41 42 43 44 |
# File 'lib/opencl_ruby_ffi/Mem.rb', line 38 def associated_memobject ptr = FFI::MemoryPointer::new( Mem ) error = OpenCL.clGetMemObjectInfo(self, OpenCL::Mem::ASSOCIATED_MEMOBJECT, Mem.size, ptr, nil) OpenCL.error_check(error) return nil if ptr.read_pointer.null? return OpenCL::Mem::new( ptr.read_pointer ) end |
#context ⇒ Object
Returns the Context associated to the Mem
25 26 27 28 29 30 |
# File 'lib/opencl_ruby_ffi/Mem.rb', line 25 def context ptr = FFI::MemoryPointer::new( Context ) error = OpenCL.clGetMemObjectInfo(self, OpenCL::Mem::CONTEXT, Context.size, ptr, nil) OpenCL.error_check(error) return OpenCL::Context::new( ptr.read_pointer ) end |
#get_info ⇒ Object
:method: host_ptr() Returns the host Pointer specified at Mem creation or the pointer + the ofsset if it is a sub-buffer. A null Pointer is returned otherwise.
71 |
# File 'lib/opencl_ruby_ffi/Mem.rb', line 71 eval OpenCL.get_info("Mem", :cl_bool, "USES_SVM_POINTER") |
#GL_mimap_level ⇒ Object
Returns the miplevel argument specified in create_from_GL_texture for Mem
111 112 113 114 115 116 |
# File 'lib/opencl_ruby_ffi/Mem.rb', line 111 def GL_mimap_level param_value = MemoryPointer::new( :cl_GLint ) error = OpenCL.clGetGLTextureInfo( self, OpenCL::GL_MIPMAP_LEVEL, param_value.size, param_value, nil ) OpenCL.error_check(error) return param_value.read_cl_GLint end |
#GL_object_name ⇒ Object
Returns the name of the GL object associated with Mem
127 128 129 130 131 132 |
# File 'lib/opencl_ruby_ffi/Mem.rb', line 127 def GL_object_name param_value = MemoryPointer::new( :cl_GLuint ) error = OpenCL.clGetGLObjectInfo( self, nil, param_value ) OpenCL.error_check(error) return param_value.read_cl_GLuint end |
#GL_object_type ⇒ Object
Returns the type of the GL object associated with Mem
119 120 121 122 123 124 |
# File 'lib/opencl_ruby_ffi/Mem.rb', line 119 def GL_object_type param_value = MemoryPointer::new( :cl_gl_object_type ) error = OpenCL.clGetGLObjectInfo( self, param_value, nil ) OpenCL.error_check(error) return OpenCL::GLObjectType::new(param_value.read_cl_gl_object_type) end |
#GL_texture_target ⇒ Object
Returns the texture_target argument specified in create_from_GL_texture for Mem
103 104 105 106 107 108 |
# File 'lib/opencl_ruby_ffi/Mem.rb', line 103 def GL_texture_target param_value = MemoryPointer::new( :cl_GLenum ) error = OpenCL.clGetGLTextureInfo( self, OpenCL::GL_TEXTURE_TARGET, param_value.size, param_value, nil ) OpenCL.error_check(error) return param_value.read_cl_GLenum end |
#platform ⇒ Object
Returns the Platform associated to the Mem
33 34 35 |
# File 'lib/opencl_ruby_ffi/Mem.rb', line 33 def platform return self.context.platform end |
#prop ⇒ Object
:method: reference_count() Returns the Mem reference counter
53 54 55 |
# File 'lib/opencl_ruby_ffi/Mem.rb', line 53 %w( OFFSET SIZE ).each { |prop| eval OpenCL.get_info("Mem", :size_t, prop) } |
#set_destructor_callback(options = {}, &proc) ⇒ Object
Attaches a callback to memobj that will be called on the memobj destruction
Attributes
-
options- a hash containing named options -
block- if provided, a callback invoked when memobj is released. Signature of the callback is { |Mem, FFI::Pointer to user_data| … }
Options
-
:user_data- a Pointer (or convertible to Pointer using to_ptr) to the memory area to pass to the callback
98 99 100 |
# File 'lib/opencl_ruby_ffi/Mem.rb', line 98 def set_destructor_callback( = {}, &proc ) return OpenCL.set_mem_object_destructor_callback( self, , &proc ) end |
#to_s ⇒ Object
1232 1233 1234 1235 1236 1237 1238 |
# File 'lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb', line 1232 def to_s if self.respond_to?(:name) then return self.name else return super end end |