Module: Ignis::Collective::Transport::VmmIpcStructs

Extended by:
FFI::Library
Defined in:
lib/nvruby/collective/transport/vmm_ipc_structs.rb

Overview

FFI struct definitions for CUDA VMM (Virtual Memory Management) IPC.

Defined Under Namespace

Classes: CUipcEventHandle, CUipcMemHandle, CUmemAccessDesc, CUmemAllocationProp, CUmemLocation

Constant Summary collapse

CUDA_DRIVER_LIB =

Resolve CUDA driver library per platform.

if defined?(Ignis::Platform)
  Ignis::Platform.find_cuda_lib(:cuda_driver) || (Ignis::Platform.windows? ? 'nvcuda.dll' : 'libcuda.so.1')
elsif RUBY_PLATFORM.match?(/mswin|mingw|cygwin/i)
  cuda_bin = File.join('C:', 'Program Files', 'NVIDIA GPU Computing Toolkit', 'CUDA', 'v13.0', 'bin')
  File.join(cuda_bin, 'nvcuda.dll')
else
  'libcuda.so.1'
end
CU_MEM_LOCATION_TYPE_INVALID =

CUmemLocationType — specifies where memory is located

0
CU_MEM_LOCATION_TYPE_DEVICE =
1
CU_MEM_LOCATION_TYPE_HOST =
2
CU_MEM_ALLOCATION_TYPE_INVALID =

CUmemAllocationType

0
CU_MEM_ALLOCATION_TYPE_PINNED =
1
CU_MEM_ACCESS_FLAGS_PROT_NONE =

CUmemAccess_flags

0
CU_MEM_ACCESS_FLAGS_PROT_READ =
1
CU_MEM_ACCESS_FLAGS_PROT_READWRITE =
3
CU_MEM_HANDLE_TYPE_NONE =

CUmemAllocationHandleType

0
CU_MEM_HANDLE_TYPE_POSIX_FILE_DESC =
1
CU_MEM_HANDLE_TYPE_WIN32 =
2
CU_MEM_HANDLE_TYPE_WIN32_KMT =
4
CU_MEM_HANDLE_TYPE_FABRIC =
8

Class Method Summary collapse

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


183
184
185
# File 'lib/nvruby/collective/transport/vmm_ipc_structs.rb', line 183

def self.available?
  defined?(VMM_AVAILABLE) && VMM_AVAILABLE
end

.device_location(device_id) ⇒ CUmemLocation

Helper: Create a CUmemLocation for a given GPU device.

Parameters:

  • device_id (Integer)

Returns:



99
100
101
102
103
104
# File 'lib/nvruby/collective/transport/vmm_ipc_structs.rb', line 99

def self.device_location(device_id)
  loc = CUmemLocation.new
  loc[:type] = CU_MEM_LOCATION_TYPE_DEVICE
  loc[:id] = device_id
  loc
end

.device_rw_access(device_id) ⇒ CUmemAccessDesc

Helper: Create a CUmemAccessDesc for read-write access to a device.

Parameters:

  • device_id (Integer)

Returns:



109
110
111
112
113
114
115
# File 'lib/nvruby/collective/transport/vmm_ipc_structs.rb', line 109

def self.device_rw_access(device_id)
  desc = CUmemAccessDesc.new
  desc[:location][:type] = CU_MEM_LOCATION_TYPE_DEVICE
  desc[:location][:id] = device_id
  desc[:flags] = CU_MEM_ACCESS_FLAGS_PROT_READWRITE
  desc
end

.pinned_device_prop(device_id, rdma_capable: false) ⇒ CUmemAllocationProp

Helper: Create CUmemAllocationProp for device-pinned memory with Windows handle support (Win32).

Parameters:

  • device_id (Integer)
  • rdma_capable (Boolean) (defaults to: false)

    whether to request GPU Direct RDMA

Returns:



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/nvruby/collective/transport/vmm_ipc_structs.rb', line 123

def self.pinned_device_prop(device_id, rdma_capable: false)
  prop = CUmemAllocationProp.new
  prop[:type] = CU_MEM_ALLOCATION_TYPE_PINNED
  prop[:requestedHandleTypes] = if RUBY_PLATFORM.match?(/mswin|mingw|cygwin/i)
                                   CU_MEM_HANDLE_TYPE_WIN32
                                 else
                                   CU_MEM_HANDLE_TYPE_POSIX_FILE_DESC
                                 end
  prop[:location][:type] = CU_MEM_LOCATION_TYPE_DEVICE
  prop[:location][:id] = device_id
  prop[:win32HandleMetaData] = FFI::Pointer::NULL
  prop[:allocFlags_compressionType] = 0
  prop[:allocFlags_gpuDirectRDMACapable] = rdma_capable ? 1 : 0
  prop[:allocFlags_usage] = 0
  prop
end