Class: Ignis::Memory::CudaAsyncMemoryResource

Inherits:
DeviceMemoryResource show all
Defined in:
lib/nvruby/memory/cuda_async_memory_resource.rb

Overview

Stream-ordered memory resource using cudaMallocAsync/cudaFreeAsync Uses CUDA’s built-in stream-ordered allocator (CUDA 11.2+) Optimal for workloads with many allocations on the same stream

Constant Summary collapse

MEMPOOL_ATTR_REUSE_FOLLOW_EVENT_DEPENDENCIES =

cudaMemPoolAttr enum values

0x1
MEMPOOL_ATTR_REUSE_ALLOW_OPPORTUNISTIC =
0x2
MEMPOOL_ATTR_REUSE_ALLOW_INTERNAL_DEPENDENCIES =
0x3
MEMPOOL_ATTR_RELEASE_THRESHOLD =
0x4

Constants inherited from DeviceMemoryResource

DeviceMemoryResource::ALIGNMENT

Instance Attribute Summary

Attributes inherited from DeviceMemoryResource

#device_index

Instance Method Summary collapse

Methods inherited from DeviceMemoryResource

#allocate, #deallocate, #inspect, #is_equal?, #to_s

Constructor Details

#initialize(device_index: nil, initial_pool_size: 0, release_threshold: 0) ⇒ CudaAsyncMemoryResource

Returns a new instance of CudaAsyncMemoryResource.

Parameters:

  • device_index (Integer) (defaults to: nil)

    GPU device index

  • initial_pool_size (Integer) (defaults to: 0)

    Initial pool size in bytes (default: 0 = driver managed)

  • release_threshold (Integer) (defaults to: 0)

    Release threshold in bytes (default: 0 = driver managed)



20
21
22
23
24
25
26
27
# File 'lib/nvruby/memory/cuda_async_memory_resource.rb', line 20

def initialize(device_index: nil, initial_pool_size: 0, release_threshold: 0)
  super(device_index: device_index)
  @initial_pool_size = initial_pool_size
  @release_threshold = release_threshold
  @pool_handle = nil

  setup_pool!
end

Instance Method Details

#destroy!void

This method returns an undefined value.

Release the memory pool



36
37
38
39
40
41
42
43
44
45
# File 'lib/nvruby/memory/cuda_async_memory_resource.rb', line 36

def destroy!
  return unless @pool_handle

  @mutex.synchronize do
    if @pool_handle && !@pool_handle.null?
      CUDA::RuntimeAPI.cudaMemPoolDestroy(@pool_handle)
      @pool_handle = nil
    end
  end
end

#supports_streams?Boolean

Returns true - supports stream-ordered allocation.

Returns:

  • (Boolean)

    true - supports stream-ordered allocation



30
31
32
# File 'lib/nvruby/memory/cuda_async_memory_resource.rb', line 30

def supports_streams?
  true
end