Class: Ignis::Memory::DeviceMemoryResource Abstract
- Inherits:
-
Object
- Object
- Ignis::Memory::DeviceMemoryResource
- Defined in:
- lib/nvruby/memory/device_memory_resource.rb
Overview
Abstract base class for device memory resources
Modeled after RMM’s device_memory_resource interface
Direct Known Subclasses
CudaAsyncMemoryResource, CudaMemoryResource, PoolMemoryResource
Constant Summary collapse
- ALIGNMENT =
Minimum alignment for all allocations (256 bytes per RMM standard)
256
Instance Attribute Summary collapse
-
#device_index ⇒ Integer
readonly
Device index this resource manages.
Instance Method Summary collapse
-
#allocate(bytes, stream: nil) ⇒ FFI::Pointer
Allocate device memory with optional stream ordering.
-
#deallocate(ptr, bytes, stream: nil) ⇒ void
Deallocate device memory with optional stream ordering.
- #initialize(device_index: nil) ⇒ void constructor
- #inspect ⇒ String
-
#is_equal?(other) ⇒ Boolean
Check if memory from this resource can be deallocated by another.
-
#supports_streams? ⇒ Boolean
Check if this resource supports stream-ordered allocation.
- #to_s ⇒ String
Constructor Details
#initialize(device_index: nil) ⇒ void
16 17 18 19 |
# File 'lib/nvruby/memory/device_memory_resource.rb', line 16 def initialize(device_index: nil) @device_index = device_index || Ignis.configuration.default_device @mutex = Mutex.new end |
Instance Attribute Details
#device_index ⇒ Integer (readonly)
Returns Device index this resource manages.
12 13 14 |
# File 'lib/nvruby/memory/device_memory_resource.rb', line 12 def device_index @device_index end |
Instance Method Details
#allocate(bytes, stream: nil) ⇒ FFI::Pointer
Allocate device memory with optional stream ordering
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/nvruby/memory/device_memory_resource.rb', line 26 def allocate(bytes, stream: nil) raise ArgumentError, "bytes must be positive, got #{bytes}" if bytes <= 0 aligned_bytes = align_up(bytes) @mutex.synchronize do ptr = do_allocate(aligned_bytes, stream) Stats.record_allocation(aligned_bytes) ptr end end |
#deallocate(ptr, bytes, stream: nil) ⇒ void
This method returns an undefined value.
Deallocate device memory with optional stream ordering
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/nvruby/memory/device_memory_resource.rb', line 43 def deallocate(ptr, bytes, stream: nil) return if ptr.null? aligned_bytes = align_up(bytes) @mutex.synchronize do do_deallocate(ptr, aligned_bytes, stream) Stats.record_deallocation(aligned_bytes) end end |
#inspect ⇒ String
73 74 75 |
# File 'lib/nvruby/memory/device_memory_resource.rb', line 73 def inspect "#<#{self.class.name}:0x#{object_id.to_s(16)} device=#{@device_index}>" end |
#is_equal?(other) ⇒ Boolean
Check if memory from this resource can be deallocated by another
63 64 65 |
# File 'lib/nvruby/memory/device_memory_resource.rb', line 63 def is_equal?(other) self.class == other.class && @device_index == other.device_index end |
#supports_streams? ⇒ Boolean
Check if this resource supports stream-ordered allocation
56 57 58 |
# File 'lib/nvruby/memory/device_memory_resource.rb', line 56 def supports_streams? false end |
#to_s ⇒ String
68 69 70 |
# File 'lib/nvruby/memory/device_memory_resource.rb', line 68 def to_s "#{self.class.name}[device=#{@device_index}]" end |