Class: OpenCL::Device

Inherits:
FFI::ManagedStruct
  • Object
show all
Defined in:
lib/opencl_ruby_ffi/Device.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_device_id object of OpenCL

Defined Under Namespace

Classes: AffinityDomain, ExecCapabilities, FPConfig, LocalMemType, MemCacheType, SVMCapabilities, Type

Constant Summary collapse

DRIVER_VERSION =

:stopdoc:

0x102D
TYPE_DEFAULT =

:stopdoc:

(1 << 0)
TYPE_CPU =
(1 << 1)
TYPE_GPU =
(1 << 2)
TYPE_ACCELERATOR =
(1 << 3)
TYPE_CUSTOM =
(1 << 4)
TYPE_ALL =
0xFFFFFFFF
TYPE =
0x1000
VENDOR_ID =
0x1001
MAX_COMPUTE_UNITS =
0x1002
MAX_WORK_ITEM_DIMENSIONS =
0x1003
MAX_WORK_GROUP_SIZE =
0x1004
MAX_WORK_ITEM_SIZES =
0x1005
PREFERRED_VECTOR_WIDTH_CHAR =
0x1006
PREFERRED_VECTOR_WIDTH_SHORT =
0x1007
PREFERRED_VECTOR_WIDTH_INT =
0x1008
PREFERRED_VECTOR_WIDTH_LONG =
0x1009
PREFERRED_VECTOR_WIDTH_FLOAT =
0x100A
PREFERRED_VECTOR_WIDTH_DOUBLE =
0x100B
MAX_CLOCK_FREQUENCY =
0x100C
ADDRESS_BITS =
0x100D
MAX_READ_IMAGE_ARGS =
0x100E
MAX_WRITE_IMAGE_ARGS =
0x100F
MAX_MEM_ALLOC_SIZE =
0x1010
IMAGE2D_MAX_WIDTH =
0x1011
IMAGE2D_MAX_HEIGHT =
0x1012
IMAGE3D_MAX_WIDTH =
0x1013
IMAGE3D_MAX_HEIGHT =
0x1014
IMAGE3D_MAX_DEPTH =
0x1015
IMAGE_SUPPORT =
0x1016
MAX_PARAMETER_SIZE =
0x1017
MAX_SAMPLERS =
0x1018
MEM_BASE_ADDR_ALIGN =
0x1019
MIN_DATA_TYPE_ALIGN_SIZE =
0x101A
SINGLE_FP_CONFIG =
0x101B
GLOBAL_MEM_CACHE_TYPE =
0x101C
GLOBAL_MEM_CACHELINE_SIZE =
0x101D
GLOBAL_MEM_CACHE_SIZE =
0x101E
GLOBAL_MEM_SIZE =
0x101F
MAX_CONSTANT_BUFFER_SIZE =
0x1020
MAX_CONSTANT_ARGS =
0x1021
LOCAL_MEM_TYPE =
0x1022
LOCAL_MEM_SIZE =
0x1023
ERROR_CORRECTION_SUPPORT =
0x1024
PROFILING_TIMER_RESOLUTION =
0x1025
ENDIAN_LITTLE =
0x1026
AVAILABLE =
0x1027
COMPILER_AVAILABLE =
0x1028
EXECUTION_CAPABILITIES =
0x1029
QUEUE_PROPERTIES =
0x102A
QUEUE_ON_HOST_PROPERTIES =
0x102A
NAME =
0x102B
VENDOR =
0x102C
PROFILE =
0x102E
VERSION =
0x102F
EXTENSIONS =
0x1030
PLATFORM =
0x1031
DOUBLE_FP_CONFIG =
0x1032
PREFERRED_VECTOR_WIDTH_HALF =
0x1034
HOST_UNIFIED_MEMORY =
0x1035
NATIVE_VECTOR_WIDTH_CHAR =
0x1036
NATIVE_VECTOR_WIDTH_SHORT =
0x1037
NATIVE_VECTOR_WIDTH_INT =
0x1038
NATIVE_VECTOR_WIDTH_LONG =
0x1039
NATIVE_VECTOR_WIDTH_FLOAT =
0x103A
NATIVE_VECTOR_WIDTH_DOUBLE =
0x103B
NATIVE_VECTOR_WIDTH_HALF =
0x103C
OPENCL_C_VERSION =
0x103D
LINKER_AVAILABLE =
0x103E
BUILT_IN_KERNELS =
0x103F
IMAGE_MAX_BUFFER_SIZE =
0x1040
IMAGE_MAX_ARRAY_SIZE =
0x1041
PARENT_DEVICE =
0x1042
PARTITION_MAX_SUB_DEVICES =
0x1043
PARTITION_PROPERTIES =
0x1044
PARTITION_AFFINITY_DOMAIN =
0x1045
PARTITION_TYPE =
0x1046
REFERENCE_COUNT =
0x1047
PREFERRED_INTEROP_USER_SYNC =
0x1048
PRINTF_BUFFER_SIZE =
0x1049
IMAGE_PITCH_ALIGNMENT =
0x104A
IMAGE_BASE_ADDRESS_ALIGNMENT =
0x104B
MAX_READ_WRITE_IMAGE_ARGS =
0x104C
MAX_GLOBAL_VARIABLE_SIZE =
0x104D
QUEUE_ON_DEVICE_PROPERTIES =
0x104E
QUEUE_ON_DEVICE_PREFERRED_SIZE =
0x104F
QUEUE_ON_DEVICE_MAX_SIZE =
0x1050
MAX_ON_DEVICE_QUEUES =
0x1051
MAX_ON_DEVICE_EVENTS =
0x1052
SVM_CAPABILITIES =
0x1053
GLOBAL_VARIABLE_PREFERRED_TOTAL_SIZE =
0x1054
MAX_PIPE_ARGS =
0x1055
PIPE_MAX_ACTIVE_RESERVATIONS =
0x1056
PIPE_MAX_PACKET_SIZE =
0x1057
PREFERRED_PLATFORM_ATOMIC_ALIGNMENT =
0x1058
PREFERRED_GLOBAL_ATOMIC_ALIGNMENT =
0x1059
PREFERRED_LOCAL_ATOMIC_ALIGNMENT =
0x105A
PARTITION_EQUALLY =
0x1086
PARTITION_BY_COUNTS =
0x1087
PARTITION_BY_COUNTS_LIST_END =
0x0
PARTITION_BY_AFFINITY_DOMAIN =
0x1088
AFFINITY_DOMAIN_NUMA =
(1 << 0)
AFFINITY_DOMAIN_L4_CACHE =
(1 << 1)
AFFINITY_DOMAIN_L3_CACHE =
(1 << 2)
AFFINITY_DOMAIN_L2_CACHE =
(1 << 3)
AFFINITY_DOMAIN_L1_CACHE =
(1 << 4)
AFFINITY_DOMAIN_NEXT_PARTITIONABLE =
(1 << 5)
SVM_COARSE_GRAIN_BUFFER =
(1 << 0)
SVM_FINE_GRAIN_BUFFER =
(1 << 1)
SVM_FINE_GRAIN_SYSTEM =
(1 << 2)
SVM_ATOMICS =
(1 << 3)
HALF_FP_CONFIG =
0x1033
TERMINATE_CAPABILITY_KHR =
0x200F
SPIR_VERSIONS =
0x40E0
COMPUTE_CAPABILITY_MAJOR_NV =
0x4000
COMPUTE_CAPABILITY_MINOR_NV =
0x4001
REGISTERS_PER_BLOCK_NV =
0x4002
WARP_SIZE_NV =
0x4003
GPU_OVERLAP_NV =
0x4004
KERNEL_EXEC_TIMEOUT_NV =
0x4005
INTEGRATED_MEMORY_NV =
0x4006
PROFILING_TIMER_OFFSET_AMD =
0x4036
PAGE_SIZE_QCOM =
0x40A1

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr, retain = true) ⇒ Device

Creates a new Device and retains it if specified and aplicable



926
927
928
929
930
931
932
933
934
935
936
# File 'lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb', line 926

def initialize(ptr, retain = true)
  super(ptr)
  platform = FFI::MemoryPointer::new( Platform )
  OpenCL.clGetDeviceInfo( ptr, OpenCL::Device::PLATFORM, platform.size, platform, nil)
  p = OpenCL::Platform::new(platform.read_pointer)
  if p.version_number >= 1.2 and retain then
    error = OpenCL.clRetainDevice(ptr)
    OpenCL.error_check( error )
  end
  #STDERR.puts "Allocating Device: #{ptr}"
end

Class Method Details

.release(ptr) ⇒ Object

method called at Device deletion, releases the object if aplicable



947
948
949
950
951
952
953
954
955
# File 'lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb', line 947

def self.release(ptr)
  platform = FFI::MemoryPointer::new( Platform )
  OpenCL.clGetDeviceInfo( ptr, OpenCL::Device::PLATFORM, platform.size, platform, nil)
  p = OpenCL::Platform::new(platform.read_pointer)
  if p.version_number >= 1.2 then
    error = OpenCL.clReleaseDevice(ptr)
    OpenCL.error_check( error )
  end
end

Instance Method Details

#built_in_kernelsObject

Returns an Array of String corresponding to the Device built in kernel names



52
53
54
55
56
57
58
59
60
61
# File 'lib/opencl_ruby_ffi/Device.rb', line 52

def built_in_kernels
  built_in_kernels_size = FFI::MemoryPointer::new( :size_t )
  error = OpenCL.clGetDeviceInfo( self, OpenCL::Device::BUILT_IN_KERNELS, 0, nil, built_in_kernels_size)
  OpenCL.error_check(error)
  ker = FFI::MemoryPointer::new( built_in_kernels_size.read_size_t )
  error = OpenCL.clGetDeviceInfo( self, OpenCL::Device::BUILT_IN_KERNELS, built_in_kernels_size.read_size_t, ker, nil)
  OpenCL.error_check(error)
  ker_string = ext.read_string
  return ker_string.split(";")
end

#create_sub_devices(properties) ⇒ Object

Partitions the Device in serveral sub-devices

Attributes

  • properties - an Array of :cl_device_partition_property

Returns

an Array of Device



182
183
184
# File 'lib/opencl_ruby_ffi/Device.rb', line 182

def create_sub_devices( properties )
  return OpenCL.create_sub_devices( self, properties )
end

#extensionsObject

Returns an Array of String corresponding to the Device extensions



40
41
42
43
44
45
46
47
48
49
# File 'lib/opencl_ruby_ffi/Device.rb', line 40

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

#get_infoObject

:method: partition_affinity_domain() Returns an AffinityDomain representing the list of supported affinity domains for partitioning the Device using OpenCL::Device::PARTITION_BY_AFFINITY_DOMAIN



90
# File 'lib/opencl_ruby_ffi/Device.rb', line 90

eval OpenCL.get_info("Device", :cl_device_exec_capabilities, "EXECUTION_CAPABILITIES")

#get_info_arrayObject

:method: partition_type() Returns a list of :cl_device_partition_property used to create the Device



130
# File 'lib/opencl_ruby_ffi/Device.rb', line 130

eval OpenCL.get_info_array("Device", :size_t, "MAX_WORK_ITEM_SIZES")

#parent_deviceObject

Returns the parent Device if it exists



165
166
167
168
169
170
171
# File 'lib/opencl_ruby_ffi/Device.rb', line 165

def parent_device
  ptr = FFI::MemoryPointer::new( OpenCL::Device )
  error = OpenCL.clGetDeviceInfo(self, OpenCL::Device::PARENT_DEVICE, OpenCL::Device.size, ptr, nil)
  OpenCL.error_check(error)
  return nil if ptr.null?
  return OpenCL::Device::new(ptr.read_pointer)
end

#partition_by_affinity_domain(affinity_domain = OpenCL::Device::AFFINITY_DOMAIN_NEXT_PARTITIONABLE) ⇒ Object

Partitions the Device in serveral sub-devices by affinity domain

Attributes

  • affinity_domain - the :cl_device_partition_property specifying the target affinity domain

Returns

an Array of Device



195
196
197
# File 'lib/opencl_ruby_ffi/Device.rb', line 195

def partition_by_affinity_domain( affinity_domain = OpenCL::Device::AFFINITY_DOMAIN_NEXT_PARTITIONABLE )
  return OpenCL.create_sub_devices( self,  [ OpenCL::Device::PARTITION_BY_AFFINITY_DOMAIN, affinity_domain ] )
end

#partition_by_count(compute_unit_number_list = [1]) ⇒ Object

Partitions the Device in serveral sub-devices each containing a specific number of compute units

Attributes

  • compute_unit_number_list - an Array of compute unit number

Returns

an Array of Device



221
222
223
# File 'lib/opencl_ruby_ffi/Device.rb', line 221

def partition_by_count( compute_unit_number_list = [1] )
  return OpenCL.create_sub_devices( self,  [ OpenCL::Device::PARTITION_BY_COUNTS] + compute_unit_number_list + [ OpenCL::Device::PARTITION_BY_COUNTS_LIST_END ] )
end

#partition_equally(compute_unit_number = 1) ⇒ Object

Partitions the Device in serveral sub-devices containing compute_unit_number compute units

Attributes

  • compute_unit_number - the number of compute units in each sub-device

Returns

an Array of Device



208
209
210
# File 'lib/opencl_ruby_ffi/Device.rb', line 208

def partition_equally( compute_unit_number = 1 )
  return OpenCL.create_sub_devices( self,  [ OpenCL::Device::PARTITION_EQUALLY, compute_unit_number ] )
end

#partition_properties_namesObject

Return an Array of partition properties names representing the partition type supported by the device



143
144
145
146
147
148
149
# File 'lib/opencl_ruby_ffi/Device.rb', line 143

def partition_properties_names
  prop_names = []
  props = self.partition_properties
  %w( PARTITION_EQUALLY PARTITION_BY_COUNTS PARTITION_BY_AFFINITY_DOMAIN ).each { |prop|
    prop_names.push(prop) if props.include?(OpenCL::Device.const_get(prop))
  }
end

#platformObject

Returns the platform the Device belongs to



157
158
159
160
161
162
# File 'lib/opencl_ruby_ffi/Device.rb', line 157

def platform
  ptr = FFI::MemoryPointer::new( OpenCL::Platform )
  error = OpenCL.clGetDeviceInfo(self, OpenCL::Device::PLATFORM, OpenCL::Platform.size, ptr, nil)
  OpenCL.error_check(error)
  return OpenCL::Platform::new(ptr.read_pointer)
end

#to_sObject



938
939
940
941
942
943
944
# File 'lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb', line 938

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