Class: SGC::CU::CUDevice
- Inherits:
-
Object
- Object
- SGC::CU::CUDevice
- Defined in:
- lib/cuda/driver/device.rb
Class Method Summary collapse
-
.can_access_peer?(dev, peer_dev = nil) ⇒ Boolean
True if device dev may directly access the memory of device peer_dev.
-
.count ⇒ Integer
The number of CUDA devices.
-
.get(index) ⇒ CUDevice
The device corresponding to CUDA device index.
-
.malloc(nbytes) ⇒ CUDevicePtr
Allocate nbytes of device memory from the current device.
Instance Method Summary collapse
-
#attribute(attrib) ⇒ Integer
The attribute attrib of this device.
-
#compute_capability ⇒ Hash{ :major, :minor }
The compute capability of this device.
-
#name ⇒ String
The name of this device with a maximum of 255 characters.
-
#properties ⇒ Hash
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.
-
#total_mem ⇒ Integer
The total amount of device memory in bytes.
Class Method Details
.can_access_peer?(dev, peer_dev = nil) ⇒ Boolean
Returns 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 |
.count ⇒ Integer
Returns 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 |
.get(index) ⇒ CUDevice
Returns 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 |
.malloc(nbytes) ⇒ CUDevicePtr
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
#attribute(attrib) ⇒ Integer
Returns 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 |
#compute_capability ⇒ Hash{ :major, :minor }
Returns 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 |
#name ⇒ String
Returns 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 |
#properties ⇒ Hash
Returns 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 |
#total_mem ⇒ Integer
Returns 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 |