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



2470
2471
2472
2473
# File 'lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb', line 2470

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



2476
2477
# File 'lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb', line 2476

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.



165
166
167
168
169
170
171
172
173
174
175
# File 'lib/opencl_ruby_ffi/Platform.rb', line 165

def create_context_from_type(type, options = {}, &block)
  props = [ 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 = 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



113
114
115
116
117
118
119
120
121
122
123
# File 'lib/opencl_ruby_ffi/Platform.rb', line 113

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

#extensionsObject

Returns an Array of string corresponding to the Platform extensions



100
101
102
103
104
105
106
107
108
109
# File 'lib/opencl_ruby_ffi/Platform.rb', line 100

def extensions
  extensions_size = FFI::MemoryPointer::new( :size_t )
  error = OpenCL.clGetPlatformInfo( self, EXTENSIONS, 0, nil, extensions_size)
  error_check(error)
  ext = FFI::MemoryPointer::new( extensions_size.read_size_t )
  error = OpenCL.clGetPlatformInfo( self, EXTENSIONS, extensions_size.read_size_t, ext, nil)
  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.



145
146
147
148
149
150
151
# File 'lib/opencl_ruby_ffi/Platform.rb', line 145

def get_extension_function( name, return_type, param_types, options = {} )
  error_check(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



95
96
97
# File 'lib/opencl_ruby_ffi/Platform.rb', line 95

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

#to_sObject

:startdoc:



2480
2481
2482
2483
2484
2485
2486
# File 'lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb', line 2480

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

#unload_compilerObject

Unloads the Platform compiler



133
134
135
# File 'lib/opencl_ruby_ffi/Platform.rb', line 133

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



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

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