Class: OpenCL::Platform

Inherits:
FFI::ManagedStruct
  • Object
show all
Defined in:
lib/opencl_ruby_ffi/Platform.rb,
lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb

Overview

Maps the cl_platform_id object of OpenCL

Constant Summary collapse

PROFILE =

:stopdoc:

0x0900
VERSION =
0x0901
NAME =
0x0902
VENDOR =
0x0903
EXTENSIONS =
0x0904
ICD_SUFFIX_KHR =
0x0920

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr, retain = true) ⇒ Platform

Creates a new Platform and retains it if specified and aplicable



780
781
782
783
# File 'lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb', line 780

def initialize(ptr, retain = true)
  super(ptr)
  #STDERR.puts "Allocating Platform: #{ptr}"
end

Class Method Details

.release(ptr) ⇒ Object

method called at Platform deletion, releases the object if aplicable



794
795
# File 'lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb', line 794

def self.release(ptr)
end

Instance Method Details

#create_context_from_type(type, options = {}, &block) ⇒ Object

Creates a Context gathering devices of a certain type and belonging to this Platform

Attributes

  • type - type of device to be used

  • options - if given, a hash of named options

  • block - if provided, a callback invoked when error arise in the context. Signature of the callback is { |FFI::Pointer to null terminated c string, FFI::Pointer to binary data, :size_t number of bytes of binary data, FFI::Pointer to user_data| … }

Options

  • :properties - a list of :cl_context_properties, the Platform will be prepended

  • :user_data - an FFI::Pointer or an object that can be converted into one using to_ptr. The pointer is passed to the callback.



160
161
162
163
164
165
166
167
168
169
170
# File 'lib/opencl_ruby_ffi/Platform.rb', line 160

def create_context_from_type(type, options = {}, &block)
  props = [ OpenCL::Context::PLATFORM, self ]
  if options[:properties] then
    props = props +  options[:properties]
  else
    props.push( 0 )
  end
  opts = options.clone
  opts[:properties] = props
  OpenCL.create_context_from_type(type, opts, &block)
end

#devices(type = OpenCL::Device::Type::ALL) ⇒ Object

Returns an Array of Device corresponding to the available devices on the Platform The type of the desired devices can be specified



108
109
110
111
112
113
114
115
116
117
118
# File 'lib/opencl_ruby_ffi/Platform.rb', line 108

def devices(type = OpenCL::Device::Type::ALL)
  ptr1 = FFI::MemoryPointer::new(:cl_uint , 1)
  error = OpenCL::clGetDeviceIDs(self, type, 0, nil, ptr1)
  OpenCL.error_check(error)
  ptr2 = FFI::MemoryPointer::new(:pointer, ptr1.read_uint)
  error = OpenCL::clGetDeviceIDs(self, type, ptr1.read_uint(), ptr2, nil)
  OpenCL.error_check(error)
  return ptr2.get_array_of_pointer(0, ptr1.read_uint()).collect { |device_ptr|
    OpenCL::Device::new(device_ptr, false)
  }
end

#extensionsObject

Returns an Array of string corresponding to the Platform extensions



95
96
97
98
99
100
101
102
103
104
# File 'lib/opencl_ruby_ffi/Platform.rb', line 95

def extensions
  extensions_size = FFI::MemoryPointer::new( :size_t )
  error = OpenCL.clGetPlatformInfo( self, OpenCL::Platform::EXTENSIONS, 0, nil, extensions_size)
  OpenCL.error_check(error)
  ext = FFI::MemoryPointer::new( extensions_size.read_size_t )
  error = OpenCL.clGetPlatformInfo( self, OpenCL::Platform::EXTENSIONS, extensions_size.read_size_t, ext, nil)
  OpenCL.error_check(error)
  ext_string = ext.read_string
  return ext_string.split(" ")
end

#get_extension_function(name, return_type, param_types, options = {}) ⇒ Object

Returns an FFI::Function corresponding to an extension function for a Platform

Attributes

  • name - a String representing the name of the function

  • return_type - the type of data returned by the function

  • param_types - an Array of types, corresponding to the parameters type

  • options - if given, a hash of named options that will be given to FFI::Function::new. See FFI doc for details.



140
141
142
143
144
145
146
# File 'lib/opencl_ruby_ffi/Platform.rb', line 140

def get_extension_function( name, return_type, param_types, options = {} )
  OpenCL.error_check(OpenCL::INVALID_OPERATION) if self.version_number < 1.2
  name_p = FFI::MemoryPointer.from_string(name)
  ptr = OpenCL.clGetExtensionFunctionAddressForPlatform( self, name_p )
  return nil if ptr.null?
  return FFI::Function::new(return_type, param_types, ptr, options)
end

#propObject

:mathod: vendor() Returns a String identifying the Platform vendor



90
91
92
# File 'lib/opencl_ruby_ffi/Platform.rb', line 90

%w(PROFILE VERSION NAME VENDOR).each { |prop|
  eval OpenCL.get_info("Platform", :string, prop)
}

#to_sObject



785
786
787
788
789
790
791
# File 'lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb', line 785

def to_s
  if self.respond_to?(:name) then
    return self.name
  else
    return super
  end
end

#unload_compilerObject

Unloads the Platform compiler



128
129
130
# File 'lib/opencl_ruby_ffi/Platform.rb', line 128

def unload_compiler
  return OpenCL.unload_platform_compiler(self)
end

#version_numberObject

returs a floating point number corresponding to the OpenCL version of the Platform



121
122
123
124
125
# File 'lib/opencl_ruby_ffi/Platform.rb', line 121

def version_number
  ver = self.version
  n = ver.scan(/OpenCL (\d+\.\d+)/)
  return n.first.first.to_f
end