Class: SGC::CU::CUDevice
- Inherits:
-
Object
- Object
- SGC::CU::CUDevice
- Defined in:
- lib/cuda/driver/device.rb
Class Method Summary (collapse)
-
+ (Boolean) can_access_peer?(dev, peer_dev = nil)
True if device dev may directly access the memory of device peer_dev.
-
+ (Integer) count
The number of CUDA devices.
-
+ (CUDevice) get(index)
The device corresponding to CUDA device index.
-
+ (CUDevicePtr) malloc(nbytes)
Allocate nbytes of device memory from the current device.
Instance Method Summary (collapse)
-
- (Integer) attribute(attrib)
The attribute attrib of this device.
-
- (Hash{ :major, :minor }) compute_capability
The compute capability of this device.
-
- (String) name
The name of this device with a maximum of 255 characters.
-
- (Hash) properties
The properties of this device in a hash with the following keys:
-
:clock_rate
-
:max_grid_size
-
:max_threads_dim
-
:max_threads_per_block
-
:mem_pitch
-
:regs_per_block
-
:shared_mem_per_block
-
:simd_width
-
:texture_align
-
:total_constant_memory.
-
-
- (Integer) total_mem
The total amount of device memory in bytes.
Class Method Details
+ (Boolean) can_access_peer?(dev, peer_dev = nil)
True if device dev may directly access the memory of device peer_dev.
146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/cuda/driver/device.rb', line 146 def self.can_access_peer?(dev, peer_dev = nil) # TODO: Remove the following workaround for JRuby when the default argument bug is fixed. if peer_dev.nil? peer_dev = dev dev = CUContext.device end b = FFI::MemoryPointer.new(:int) status = API::cuDeviceCanAccessPeer(b, dev.to_api, peer_dev.to_api) Pvt::handle_error(status, "Failed to query can access peer.") b.read_int == 1 ? true : false end |
+ (Integer) count
The number of CUDA devices.
37 38 39 40 41 42 |
# File 'lib/cuda/driver/device.rb', line 37 def self.count p = FFI::MemoryPointer.new(:int) status = API::cuDeviceGetCount(p) Pvt::handle_error(status, "Failed to get device count.") p.read_int end |
+ (CUDevice) get(index)
The device corresponding to CUDA device index.
47 48 49 50 51 52 |
# File 'lib/cuda/driver/device.rb', line 47 def self.get(index) p = FFI::MemoryPointer.new(:CUDevice) status = API::cuDeviceGet(p, index) Pvt::handle_error(status, "Failed to get device #{index}.") new(p) end |
+ (CUDevicePtr) malloc(nbytes)
Allocate nbytes of device memory from the current device.
133 134 135 136 137 138 |
# File 'lib/cuda/driver/device.rb', line 133 def self.malloc(nbytes) p = FFI::MemoryPointer.new(:CUDevicePtr) status = API::cuMemAlloc(p, nbytes) Pvt::handle_error(status, "Failed to allocate device memory: size = #{nbytes}.") CUDevicePtr.send(:new, p) end |
Instance Method Details
- (Integer) attribute(attrib)
The attribute attrib of this device.
83 84 85 86 87 88 |
# File 'lib/cuda/driver/device.rb', line 83 def attribute(attrib) p = FFI::MemoryPointer.new(:int) status = API::cuDeviceGetAttribute(p, attrib, self.to_api) Pvt::handle_error(status, "Failed to query device attribute #{attrib}.") p.read_int end |
- (Hash{ :major, :minor }) compute_capability
The compute capability of this device.
68 69 70 71 72 73 |
# File 'lib/cuda/driver/device.rb', line 68 def compute_capability cap = FFI::MemoryPointer.new(:int, 2) status = API::cuDeviceComputeCapability(cap[0], cap[1], self.to_api) Pvt::handle_error(status, "Failed to query device compute capability.") { major: cap[0].read_int, minor: cap[1].read_int } end |
- (String) name
The name of this device with a maximum of 255 characters.
56 57 58 59 60 61 |
# File 'lib/cuda/driver/device.rb', line 56 def name s = FFI::MemoryPointer.new(:char, 256) status = API::cuDeviceGetName(s, 256, self.to_api) Pvt::handle_error(status, "Failed to get device name.") s.read_string end |
- (Hash) properties
The properties of this device in a hash with the following keys:
-
:clock_rate
-
:max_grid_size
-
:max_threads_dim
-
:max_threads_per_block
-
:mem_pitch
-
:regs_per_block
-
:shared_mem_per_block
-
:simd_width
-
:texture_align
-
:total_constant_memory
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/cuda/driver/device.rb', line 102 def properties prop = API::CUDevProp.new status = API::cuDeviceGetProperties(prop.to_ptr, self.to_api) Pvt::handle_error(status, "Failed to get device properties.") h = {} h[:clock_rate] = prop[:clockRate] h[:max_grid_size] = prop[:maxGridSize] h[:max_threads_dim] = prop[:maxThreadsDim] h[:max_threads_per_block] = prop[:maxThreadsPerBlock] h[:mem_pitch] = prop[:memPitch] h[:regs_per_block] = prop[:regsPerBlock] h[:shared_mem_per_block] = prop[:sharedMemPerBlock] h[:simd_width] = prop[:SIMDWidth] h[:texture_align] = prop[:textureAlign] h[:total_constant_memory] = prop[:totalConstantMemory] h end |
- (Integer) total_mem
The total amount of device memory in bytes.
122 123 124 125 126 127 |
# File 'lib/cuda/driver/device.rb', line 122 def total_mem p = FFI::MemoryPointer.new(:size_t) status = API::cuDeviceTotalMem(p, self.to_api) Pvt::handle_error(status, "Failed to get device total amount of memory available.") API::read_size_t(p) end |