Class: Ignis::CUDA::Device
- Inherits:
-
Object
- Object
- Ignis::CUDA::Device
- Defined in:
- lib/nvruby/cuda/device.rb
Overview
Represents a CUDA GPU device.
Uses RuntimeAPI (Fiddle-based) for hot-path attribute queries and DeviceProperties (FFI::Struct) for full device property reads.
Instance Attribute Summary collapse
-
#index ⇒ Integer
readonly
Device index.
Class Method Summary collapse
-
.available? ⇒ Boolean
Check if any CUDA device is available.
-
.count ⇒ Integer
Get the number of CUDA devices.
-
.current ⇒ Device
Get the current device.
-
.default ⇒ Device
Get the default device from configuration.
-
.list ⇒ Array<Device>
List all available devices.
Instance Method Summary collapse
-
#clock_rate ⇒ Integer
Clock rate in kHz.
-
#compute_capability ⇒ String
Compute capability as “major.minor”.
-
#compute_capability_major ⇒ Integer
Major compute capability.
-
#compute_capability_minor ⇒ Integer
Minor compute capability.
-
#concurrent_kernels? ⇒ Boolean
Whether concurrent kernels are supported.
-
#cooperative_launch? ⇒ Boolean
Whether cooperative launch is supported.
-
#ecc_enabled? ⇒ Boolean
Whether ECC memory is enabled.
-
#free_memory ⇒ Integer
Free memory in bytes.
-
#initialize(index) ⇒ Device
constructor
A new instance of Device.
-
#inspect ⇒ String
Detailed inspection.
-
#l2_cache_size ⇒ Integer
L2 cache size in bytes.
-
#managed_memory? ⇒ Boolean
Whether managed memory is supported.
-
#max_grid_size ⇒ Array<Integer>
Max grid size [x, y, z].
-
#max_threads_dim ⇒ Array<Integer>
Max threads per dimension [x, y, z].
-
#max_threads_per_block ⇒ Integer
Max threads per block.
-
#memory_bus_width ⇒ Integer
Memory bus width in bits.
-
#memory_clock_rate ⇒ Integer
Memory clock rate in kHz.
-
#memory_info ⇒ Hash
Get available and total memory via RuntimeAPI (Fiddle hot path).
-
#multiprocessor_count ⇒ Integer
Number of streaming multiprocessors.
-
#name ⇒ String
Device name.
-
#properties ⇒ Hash
Get full device properties via DeviceProperties (FFI::Struct).
-
#reset! ⇒ void
Reset this device.
-
#set_current! ⇒ void
Set this device as the current device.
-
#shared_memory_per_block ⇒ Integer
Shared memory per block in bytes.
-
#synchronize ⇒ void
Synchronize this device.
-
#to_s ⇒ String
Human-readable device description.
-
#total_memory ⇒ Integer
Total global memory in bytes.
-
#unified_addressing? ⇒ Boolean
Whether unified addressing is supported.
-
#warp_size ⇒ Integer
Warp size (typically 32).
Constructor Details
#initialize(index) ⇒ Device
Returns a new instance of Device.
52 53 54 55 56 57 58 |
# File 'lib/nvruby/cuda/device.rb', line 52 def initialize(index) @index = index @attribute_cache = {} @name = nil @total_memory = nil @props_cache = nil end |
Instance Attribute Details
#index ⇒ Integer (readonly)
Returns Device index.
49 50 51 |
# File 'lib/nvruby/cuda/device.rb', line 49 def index @index end |
Class Method Details
.available? ⇒ Boolean
Check if any CUDA device is available.
254 255 256 257 258 |
# File 'lib/nvruby/cuda/device.rb', line 254 def available? count.positive? rescue CudaRuntimeError false end |
.count ⇒ Integer
Get the number of CUDA devices.
228 229 230 231 |
# File 'lib/nvruby/cuda/device.rb', line 228 def count RuntimeAPI.ensure_loaded! RuntimeAPI.get_device_count end |
.current ⇒ Device
Get the current device.
241 242 243 244 |
# File 'lib/nvruby/cuda/device.rb', line 241 def current RuntimeAPI.ensure_loaded! new(RuntimeAPI.get_device) end |
.default ⇒ Device
Get the default device from configuration.
248 249 250 |
# File 'lib/nvruby/cuda/device.rb', line 248 def default new(Ignis.configuration.default_device) end |
.list ⇒ Array<Device>
List all available devices.
235 236 237 |
# File 'lib/nvruby/cuda/device.rb', line 235 def list count.times.map { |i| new(i) } end |
Instance Method Details
#clock_rate ⇒ Integer
Returns Clock rate in kHz.
128 129 130 |
# File 'lib/nvruby/cuda/device.rb', line 128 def clock_rate get_attribute(DeviceAttribute::CLOCK_RATE) end |
#compute_capability ⇒ String
Returns Compute capability as “major.minor”.
90 91 92 |
# File 'lib/nvruby/cuda/device.rb', line 90 def compute_capability "#{compute_capability_major}.#{compute_capability_minor}" end |
#compute_capability_major ⇒ Integer
Returns Major compute capability.
95 96 97 |
# File 'lib/nvruby/cuda/device.rb', line 95 def compute_capability_major get_attribute(DeviceAttribute::COMPUTE_CAPABILITY_MAJOR) end |
#compute_capability_minor ⇒ Integer
Returns Minor compute capability.
100 101 102 |
# File 'lib/nvruby/cuda/device.rb', line 100 def compute_capability_minor get_attribute(DeviceAttribute::COMPUTE_CAPABILITY_MINOR) end |
#concurrent_kernels? ⇒ Boolean
Returns Whether concurrent kernels are supported.
153 154 155 |
# File 'lib/nvruby/cuda/device.rb', line 153 def concurrent_kernels? get_attribute(DeviceAttribute::CONCURRENT_KERNELS) != 0 end |
#cooperative_launch? ⇒ Boolean
Returns Whether cooperative launch is supported.
168 169 170 |
# File 'lib/nvruby/cuda/device.rb', line 168 def cooperative_launch? get_attribute(DeviceAttribute::COOPERATIVE_LAUNCH) != 0 end |
#ecc_enabled? ⇒ Boolean
Returns Whether ECC memory is enabled.
148 149 150 |
# File 'lib/nvruby/cuda/device.rb', line 148 def ecc_enabled? get_attribute(DeviceAttribute::ECC_ENABLED) != 0 end |
#free_memory ⇒ Integer
Returns Free memory in bytes.
181 182 183 |
# File 'lib/nvruby/cuda/device.rb', line 181 def free_memory memory_info[:free_bytes] end |
#inspect ⇒ String
Returns Detailed inspection.
220 221 222 223 |
# File 'lib/nvruby/cuda/device.rb', line 220 def inspect "#<Ignis::CUDA::Device:#{object_id} index=#{@index} name=#{name.inspect} " \ "compute=#{compute_capability} memory=#{total_memory}>" end |
#l2_cache_size ⇒ Integer
Returns L2 cache size in bytes.
143 144 145 |
# File 'lib/nvruby/cuda/device.rb', line 143 def l2_cache_size get_attribute(DeviceAttribute::L2_CACHE_SIZE) end |
#managed_memory? ⇒ Boolean
Returns Whether managed memory is supported.
163 164 165 |
# File 'lib/nvruby/cuda/device.rb', line 163 def managed_memory? get_attribute(DeviceAttribute::MANAGED_MEMORY) != 0 end |
#max_grid_size ⇒ Array<Integer>
Returns Max grid size [x, y, z].
119 120 121 122 123 124 125 |
# File 'lib/nvruby/cuda/device.rb', line 119 def max_grid_size [ get_attribute(DeviceAttribute::MAX_GRID_DIM_X), get_attribute(DeviceAttribute::MAX_GRID_DIM_Y), get_attribute(DeviceAttribute::MAX_GRID_DIM_Z) ] end |
#max_threads_dim ⇒ Array<Integer>
Returns Max threads per dimension [x, y, z].
110 111 112 113 114 115 116 |
# File 'lib/nvruby/cuda/device.rb', line 110 def max_threads_dim [ get_attribute(DeviceAttribute::MAX_BLOCK_DIM_X), get_attribute(DeviceAttribute::MAX_BLOCK_DIM_Y), get_attribute(DeviceAttribute::MAX_BLOCK_DIM_Z) ] end |
#max_threads_per_block ⇒ Integer
Returns Max threads per block.
105 106 107 |
# File 'lib/nvruby/cuda/device.rb', line 105 def max_threads_per_block get_attribute(DeviceAttribute::MAX_THREADS_PER_BLOCK) end |
#memory_bus_width ⇒ Integer
Returns Memory bus width in bits.
138 139 140 |
# File 'lib/nvruby/cuda/device.rb', line 138 def memory_bus_width get_attribute(DeviceAttribute::GLOBAL_MEMORY_BUS_WIDTH) end |
#memory_clock_rate ⇒ Integer
Returns Memory clock rate in kHz.
133 134 135 |
# File 'lib/nvruby/cuda/device.rb', line 133 def memory_clock_rate get_attribute(DeviceAttribute::MEMORY_CLOCK_RATE) end |
#memory_info ⇒ Hash
Get available and total memory via RuntimeAPI (Fiddle hot path).
174 175 176 177 178 |
# File 'lib/nvruby/cuda/device.rb', line 174 def memory_info RuntimeAPI.ensure_loaded! RuntimeAPI.set_device(@index) RuntimeAPI.mem_get_info end |
#multiprocessor_count ⇒ Integer
Returns Number of streaming multiprocessors.
80 81 82 |
# File 'lib/nvruby/cuda/device.rb', line 80 def multiprocessor_count get_attribute(DeviceAttribute::MULTIPROCESSOR_COUNT) end |
#name ⇒ String
Returns Device name.
61 62 63 64 65 |
# File 'lib/nvruby/cuda/device.rb', line 61 def name return @name if @name @name = properties[:name] end |
#properties ⇒ Hash
Get full device properties via DeviceProperties (FFI::Struct). Cached after first call.
188 189 190 |
# File 'lib/nvruby/cuda/device.rb', line 188 def properties @props_cache ||= DeviceProperties.summary(@index) end |
#reset! ⇒ void
This method returns an undefined value.
Reset this device.
208 209 210 211 |
# File 'lib/nvruby/cuda/device.rb', line 208 def reset! set_current! RuntimeAPI.device_reset end |
#set_current! ⇒ void
This method returns an undefined value.
Set this device as the current device.
194 195 196 197 |
# File 'lib/nvruby/cuda/device.rb', line 194 def set_current! RuntimeAPI.ensure_loaded! RuntimeAPI.set_device(@index) end |
#shared_memory_per_block ⇒ Integer
Returns Shared memory per block in bytes.
75 76 77 |
# File 'lib/nvruby/cuda/device.rb', line 75 def shared_memory_per_block get_attribute(DeviceAttribute::MAX_SHARED_MEMORY_PER_BLOCK) end |
#synchronize ⇒ void
This method returns an undefined value.
Synchronize this device.
201 202 203 204 |
# File 'lib/nvruby/cuda/device.rb', line 201 def synchronize set_current! RuntimeAPI.device_synchronize end |
#to_s ⇒ String
Returns Human-readable device description.
214 215 216 217 |
# File 'lib/nvruby/cuda/device.rb', line 214 def to_s mem_mb = total_memory / (1024 * 1024) "Device[#{@index}]: #{name} (CC #{compute_capability}, #{mem_mb} MB)" end |
#total_memory ⇒ Integer
Returns Total global memory in bytes.
68 69 70 71 72 |
# File 'lib/nvruby/cuda/device.rb', line 68 def total_memory return @total_memory if @total_memory @total_memory = memory_info[:total_bytes] end |
#unified_addressing? ⇒ Boolean
Returns Whether unified addressing is supported.
158 159 160 |
# File 'lib/nvruby/cuda/device.rb', line 158 def unified_addressing? get_attribute(DeviceAttribute::UNIFIED_ADDRESSING) != 0 end |
#warp_size ⇒ Integer
Returns Warp size (typically 32).
85 86 87 |
# File 'lib/nvruby/cuda/device.rb', line 85 def warp_size get_attribute(DeviceAttribute::WARP_SIZE) end |