Class: Ignis::Memory::HostMemoryResource Abstract
- Inherits:
-
Object
- Object
- Ignis::Memory::HostMemoryResource
- Defined in:
- lib/nvruby/memory/pinned_host_memory_resource.rb
Overview
This class is abstract.
Abstract base class for host memory resources
Direct Known Subclasses
Constant Summary collapse
- ALIGNMENT =
Minimum alignment for all allocations
64
Instance Method Summary collapse
-
#allocate(bytes) ⇒ FFI::Pointer
Allocate host memory.
-
#deallocate(ptr, bytes) ⇒ void
Deallocate host memory.
- #initialize ⇒ void constructor
Constructor Details
#initialize ⇒ void
11 12 13 |
# File 'lib/nvruby/memory/pinned_host_memory_resource.rb', line 11 def initialize @mutex = Mutex.new end |
Instance Method Details
#allocate(bytes) ⇒ FFI::Pointer
Allocate host memory
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/nvruby/memory/pinned_host_memory_resource.rb', line 19 def allocate(bytes) raise ArgumentError, "bytes must be positive, got #{bytes}" if bytes <= 0 aligned_bytes = align_up(bytes) @mutex.synchronize do ptr = do_allocate(aligned_bytes) Stats.record_allocation(aligned_bytes) ptr end end |
#deallocate(ptr, bytes) ⇒ void
This method returns an undefined value.
Deallocate host memory
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/nvruby/memory/pinned_host_memory_resource.rb', line 35 def deallocate(ptr, bytes) return if ptr.null? aligned_bytes = align_up(bytes) @mutex.synchronize do do_deallocate(ptr, aligned_bytes) Stats.record_deallocation(aligned_bytes) end end |