Class: OpenCL::Platform

Inherits:
ExtendedStruct show all
Includes:
KHRICD, OpenCL12, OpenCL21
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

Constant Summary collapse

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

Instance Method Summary collapse

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



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

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.



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

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



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

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



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

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



87
88
89
# File 'lib/opencl_ruby_ffi/Platform.rb', line 87

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

#nameObject Also known as: to_s

Returns the OpenCL::Platform::name info

Returns:

  • string



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

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

#profileObject

Returns the OpenCL::Platform::profile info

Returns:

  • string



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

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

#vendorObject

Returns the OpenCL::Platform::vendor info

Returns:

  • string



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

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

#versionObject

Returns the OpenCL::Platform::version info

Returns:

  • string



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

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

#version_numberObject

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



124
125
126
127
128
# File 'lib/opencl_ruby_ffi/Platform.rb', line 124

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