Class: SGC::Cuda::CudaDevice
- Inherits:
-
Object
- Object
- SGC::Cuda::CudaDevice
- Defined in:
- lib/cuda/runtime/device.rb
Class Method Summary collapse
-
.cache_config ⇒ CudaFunctionCache
The cache config of the current CUDA device.
-
.cache_config=(conf) ⇒ Object
Set the cache config of the current CUDA device to conf.
-
.can_access_peer?(devid = self.get, peer_devid) ⇒ Boolean
True if device devid is capable of directly accessing memory from device peer_devid.
-
.choose(prop) ⇒ Integer
The index of the CUDA device best matches the criteria.
-
.count ⇒ Integer
The number of CUDA devices.
-
.disable_peer_access(peer_devid) ⇒ Class
Disable the current device from accessing the memory of the peer device.
-
.enable_peer_access(peer_devid, flags = 0) ⇒ Class
Enable the current device to access the memory of the peer device.
-
.flags=(flags) ⇒ Object
Set the flags to be used for device execution.
-
.get ⇒ Integer
(also: current)
The index of the current CUDA device in use.
-
.limit(lim) ⇒ CudaLimit
The limit lim of the current CUDA device.
-
.limit=(*lim_val_pair) ⇒ Object
Set the limit lim of the current CUDA device.
-
.properties(devid = self.get) ⇒ CudaDeviceProp
The properties of the device devid.
-
.reset ⇒ Class
Destroy all allocations and reset all state on the current CUDA device.
-
.set(devid) ⇒ Class
(also: current=)
Set devid as the current CUDA device.
-
.synchronize ⇒ Class
Block until all the tasks of the current CUDA device complete.
-
.valid_devices=(devs) ⇒ Object
Set the list of CUDA devices that can be used.
Class Method Details
.cache_config ⇒ CudaFunctionCache
Returns The cache config of the current CUDA device.
108 109 110 111 112 113 |
# File 'lib/cuda/runtime/device.rb', line 108 def self.cache_config p = FFI::MemoryPointer.new(:enum) status = API::cudaDeviceGetCacheConfig(p) Pvt::handle_error(status, "Failed to get the current CUDA device cache config.") CudaFunctionCache[API::read_enum(p)] end |
.cache_config=(conf) ⇒ Object
Set the cache config of the current CUDA device to conf.
120 121 122 123 |
# File 'lib/cuda/runtime/device.rb', line 120 def self.cache_config=(conf) status = API::cudaDeviceSetCacheConfig(conf) Pvt::handle_error(status, "Failed to set the current CUDA device cache config.") end |
.can_access_peer?(devid = self.get, peer_devid) ⇒ Boolean
Returns True if device devid is capable of directly accessing memory from device peer_devid.
178 179 180 181 182 183 |
# File 'lib/cuda/runtime/device.rb', line 178 def self.can_access_peer?(devid = self.get, peer_devid) b = FFI::MemoryPointer.new(:int) status = API::cudaDeviceCanAccessPeer(b, devid, peer_devid) Pvt::handle_error(status, "Failed to query can access peer: devid = #{devid}, peer_devid = #{peer_devid}.") b.read_int == 1 ? true : false end |
.choose(prop) ⇒ Integer
Returns The index of the CUDA device best matches the criteria.
66 67 68 69 70 71 |
# File 'lib/cuda/runtime/device.rb', line 66 def self.choose(prop) pdev = FFI::MemoryPointer.new(:int) status = API::cudaChooseDevice(pdev, prop.to_ptr) Pvt::handle_error(status, "Failed to choose a device with criteria.") pdev.read_int end |
.count ⇒ Integer
Returns The number of CUDA devices.
35 36 37 38 39 40 |
# File 'lib/cuda/runtime/device.rb', line 35 def self.count p = FFI::MemoryPointer.new(:int) status = API::cudaGetDeviceCount(p) Pvt::handle_error(status, "Failed to get device count.") p.read_int end |
.disable_peer_access(peer_devid) ⇒ Class
Disable the current device from accessing the memory of the peer device.
204 205 206 207 208 |
# File 'lib/cuda/runtime/device.rb', line 204 def self.disable_peer_access(peer_devid) status = API::cudaDeviceDisablePeerAccess(peer_devid) Pvt::handle_error(status, "Failed to disable peer access: peer_devid = #{peer_devid}.") self end |
.enable_peer_access(peer_devid, flags = 0) ⇒ Class
Enable the current device to access the memory of the peer device.
192 193 194 195 196 |
# File 'lib/cuda/runtime/device.rb', line 192 def self.enable_peer_access(peer_devid, flags = 0) status = API::cudaDeviceEnablePeerAccess(peer_devid, flags) Pvt::handle_error(status, "Failed to enable peer access: peer_devid = #{peer_devid}, flags = #{flags}.") self end |
.flags=(flags) ⇒ Object
Set the flags to be used for device execution.
86 87 88 89 90 |
# File 'lib/cuda/runtime/device.rb', line 86 def self.flags=(flags) f = CudaDeviceFlags.value(flags) status = API::cudaSetDeviceFlags(f) Pvt::handle_error(status, "Failed to set device flags: flags = #{flags}.") end |
.get ⇒ Integer Also known as: current
Returns The index of the current CUDA device in use.
44 45 46 47 48 49 |
# File 'lib/cuda/runtime/device.rb', line 44 def self.get p = FFI::MemoryPointer.new(:int) status = API::cudaGetDevice(p) Pvt::handle_error(status, "Failed to get current device.") p.read_int end |
.limit(lim) ⇒ CudaLimit
Returns The limit lim of the current CUDA device.
130 131 132 133 134 135 |
# File 'lib/cuda/runtime/device.rb', line 130 def self.limit(lim) p = FFI::MemoryPointer.new(:size_t) status = API::cudaDeviceGetLimit(p, lim) Pvt::handle_error(status, "Failed to get the current CUDA device limit: limit = #{lim}.") API::read_size_t(p) end |
.limit=(*lim_val_pair) ⇒ Object
Set the limit lim of the current CUDA device.
143 144 145 146 147 148 |
# File 'lib/cuda/runtime/device.rb', line 143 def self.limit=(*lim_val_pair) lim, val = lim_val_pair.flatten lim != nil && val != nil or raise ArgumentError, "Invalid limit and value pair given: limit = #{lim}, value = #{val}." status = API::cudaDeviceSetLimit(lim, val) Pvt::handle_error(status, "Failed to set the current CUDA device limit: limit = #{lim}, value = #{val}") end |
.properties(devid = self.get) ⇒ CudaDeviceProp
Returns The properties of the device devid.
76 77 78 79 80 81 |
# File 'lib/cuda/runtime/device.rb', line 76 def self.properties(devid = self.get) prop = CudaDeviceProp.new status = API::cudaGetDeviceProperties(prop.to_ptr, devid) Pvt::handle_error(status, "Failed to get device properties: devid = #{devid}.") prop end |
.reset ⇒ Class
Destroy all allocations and reset all state on the current CUDA device.
155 156 157 158 159 |
# File 'lib/cuda/runtime/device.rb', line 155 def self.reset status = API::cudaDeviceReset() Pvt::handle_error(status, "Failed to reset the current CUDA device.") self end |
.set(devid) ⇒ Class Also known as: current=
Set devid as the current CUDA device.
56 57 58 59 60 |
# File 'lib/cuda/runtime/device.rb', line 56 def self.set(devid) status = API::cudaSetDevice(devid) Pvt::handle_error(status, "Failed to set current device: devid = #{devid}.") self end |
.synchronize ⇒ Class
Block until all the tasks of the current CUDA device complete.
166 167 168 169 170 |
# File 'lib/cuda/runtime/device.rb', line 166 def self.synchronize status = API::cudaDeviceSynchronize() Pvt::handle_error(status, "Failed to synchronize the current CUDA device.") self end |
.valid_devices=(devs) ⇒ Object
Set the list of CUDA devices that can be used.
95 96 97 98 99 100 101 102 |
# File 'lib/cuda/runtime/device.rb', line 95 def self.valid_devices=(devs) p = FFI::MemoryPointer.new(:int, devs.count) devs.each_with_index do |devid, i| p[i].write_int(devid) end status = API::cudaSetValidDevices(p, devs.count) Pvt::handle_error(status, "Failed to set valid devices: devs = #{devs}.") end |