Class: OpenCL::Platform

Inherits:
ExtendedStruct show all
Includes:
KHRICD, OpenCL12, OpenCL21, OpenCL30
Defined in:
lib/opencl_ruby_ffi/Platform.rb,
lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb,
lib/opencl_ruby_ffi/khr/icd.rb

Overview

Maps the cl_platform_id object of OpenCL

Defined Under Namespace

Modules: KHRICD, OpenCL12, OpenCL21, OpenCL30

Constant Summary collapse

PROFILE =
0x0900
VERSION =
0x0901
NAME =
0x0902
VENDOR =
0x0903
EXTENSIONS =
0x0904
HOST_TIMER_RESOLUTION =
0x0905
NUMERIC_VERSION =
0x0906
EXTENSIONS_WITH_VERSION =
0x0907
ICD_SUFFIX_KHR =
0x0920

Instance Method Summary collapse

Methods included from OpenCL30

#extensions_with_version, #numeric_version

Methods included from OpenCL21

#host_timer_resolution

Methods included from OpenCL12

#get_extension_function, #unload_compiler

Methods included from KHRICD

#icd_suffix_khr

Methods inherited from ExtendedStruct

register_extension

Constructor Details

#initialize(ptr, retain = true) ⇒ Platform

Creates a new Platform and retains it if specified and aplicable



818
819
820
821
# File 'lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb', line 818

def initialize(ptr, retain = true)
  super(ptr)
  #STDERR.puts "Allocating Platform: #{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 { |Pointer to null terminated c string, Pointer to binary data, :size_t number of bytes of binary data, Pointer to user_data| … }

Options

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

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



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

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 = MemoryPointer::new(:cl_uint , 1)
  error = OpenCL.clGetDeviceIDs(self, type, 0, nil, ptr1)
  error_check(error)
  ptr2 = 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 = MemoryPointer::new( :size_t )
  error = OpenCL.clGetPlatformInfo( self, EXTENSIONS, 0, nil, extensions_size)
  error_check(error)
  ext = 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

#inspectObject



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

def inspect
  return "#<#{self.class.name}: #{self.name}>"
end

#nameObject Also known as: to_s

Returns the OpenCL::Platform::name info

Returns:

  • string



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

get_info("Platform", :string, "name", true)

#profileObject

Returns the OpenCL::Platform::profile info

Returns:

  • string



93
# File 'lib/opencl_ruby_ffi/Platform.rb', line 93

get_info("Platform", :string, "profile", true)

#vendorObject

Returns the OpenCL::Platform::vendor info

Returns:

  • string



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

get_info("Platform", :string, "vendor", true)

#versionObject

Returns the OpenCL::Platform::version info

Returns:

  • string



94
# File 'lib/opencl_ruby_ffi/Platform.rb', line 94

get_info("Platform", :string, "version", true)

#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