VTK  9.7.20261110
vtkDeviceMemory Class Reference

#include <vtkDeviceMemory.h>

Detailed Description

reads GPU memory through the vendor's runtime, loaded when first needed

vtkDeviceDataArray holds memory another library allocated on a GPU. To read it on the host it needs a copy, and the copy needs the vendor's runtime. VTK does not link against one: this class loads it the first time it is asked, so a VTK built without any GPU toolkit can still hold and read GPU memory on a machine that has the driver.

CUDA through the driver API (libcuda.so.1, nvcuda.dll), which every NVIDIA driver installs. HIP through ROCm's runtime (libamdhip64.so.7, amdhip64_7.dll, or version 6), which every HIP program runs on: the one the process has loaded already, if any, since two copies of it share nothing. ROCm 5's runtime is refused: it numbers memory types differently. Level Zero through its loader (libze_loader.so.1, ze_loader.dll), which Intel's GPU driver installs.

A Level Zero pointer means something only in the context that allocated it, so VTK keeps one Level Zero context for the process: one a producer gave it (SetLevelZeroContext), or else one it makes on the first GPU the loader reports, the first time it needs one. Pointers are checked and copied in it.

Nothing here allocates or frees: the memory belongs to whoever made it.

Definition at line 39 of file vtkDeviceMemory.h.

Static Public Member Functions

static bool SpaceFromName (const char *name, vtkDataArray::MemorySpace &space)
 The memory space a vtkMemoryDescriptor names ("cuda", "hip", "level_zero").
static const char * NameOf (vtkDataArray::MemorySpace space)
 The name of a device memory space, as vtkMemoryDescriptor spells it.
static bool IsAvailable (vtkDataArray::MemorySpace space, std::string *why=nullptr)
 Whether the runtime for space could be loaded.
static bool IsDevicePointer (vtkDataArray::MemorySpace space, const void *pointer, std::string *why=nullptr)
 Whether pointer is memory of space that the runtime knows: device or managed memory, not ordinary host memory.
static bool CopyToHost (vtkDataArray::MemorySpace space, void *destination, const void *source, std::size_t bytes, std::string *why=nullptr)
 Copy bytes from device memory at source to host memory at destination.
static int DeviceOrdinal (vtkDataArray::MemorySpace space, const void *pointer, std::string *why=nullptr)
 The number of the device pointer is on, as the vendor's runtime counts devices (and DLPack's device_id does): CUDA's and HIP's device ordinal, or the device's index among its Level Zero driver's devices.
static void SetLevelZeroContext (void *driver, void *device, void *context)
 VTK's Level Zero context and the driver and device it is on (the ze_*_handle_ts).
static bool HasLevelZeroContext ()
 VTK's Level Zero context and the driver and device it is on (the ze_*_handle_ts).
static bool GetLevelZeroContext (void *&driver, void *&device, void *&context, std::string *why=nullptr)
 VTK's Level Zero context and the driver and device it is on (the ze_*_handle_ts).

Member Function Documentation

◆ SpaceFromName()

bool vtkDeviceMemory::SpaceFromName ( const char * name,
vtkDataArray::MemorySpace & space )
static

The memory space a vtkMemoryDescriptor names ("cuda", "hip", "level_zero").

Returns false for "host" and for names it does not know.

◆ NameOf()

const char * vtkDeviceMemory::NameOf ( vtkDataArray::MemorySpace space)
static

The name of a device memory space, as vtkMemoryDescriptor spells it.

◆ IsAvailable()

bool vtkDeviceMemory::IsAvailable ( vtkDataArray::MemorySpace space,
std::string * why = nullptr )
static

Whether the runtime for space could be loaded.

When it could not, why (if given) says why.

◆ IsDevicePointer()

bool vtkDeviceMemory::IsDevicePointer ( vtkDataArray::MemorySpace space,
const void * pointer,
std::string * why = nullptr )
static

Whether pointer is memory of space that the runtime knows: device or managed memory, not ordinary host memory.

◆ CopyToHost()

bool vtkDeviceMemory::CopyToHost ( vtkDataArray::MemorySpace space,
void * destination,
const void * source,
std::size_t bytes,
std::string * why = nullptr )
static

Copy bytes from device memory at source to host memory at destination.

Returns false, with the reason in why, if it could not.

For CUDA and HIP, work already queued on the memory's device is finished first, so the copy sees it. Level Zero has no device-wide synchronize: the copy runs on VTK's own command list and does not wait for work a producer queued elsewhere (a SYCL queue, say), so the producer must finish writing before VTK reads.

◆ DeviceOrdinal()

int vtkDeviceMemory::DeviceOrdinal ( vtkDataArray::MemorySpace space,
const void * pointer,
std::string * why = nullptr )
static

The number of the device pointer is on, as the vendor's runtime counts devices (and DLPack's device_id does): CUDA's and HIP's device ordinal, or the device's index among its Level Zero driver's devices.

-1, with the reason in why, if it cannot be told.

◆ SetLevelZeroContext()

void vtkDeviceMemory::SetLevelZeroContext ( void * driver,
void * device,
void * context )
static

VTK's Level Zero context and the driver and device it is on (the ze_*_handle_ts).

SetLevelZeroContext makes VTK use another library's; set it before any Level Zero array is made, since arrays copy in whichever context is current. A null context forgets it (a context VTK made is kept alive, not destroyed). HasLevelZeroContext says whether there is one without making one; GetLevelZeroContext makes one if there is none, and returns false, with the reason in why, if it cannot.

◆ HasLevelZeroContext()

bool vtkDeviceMemory::HasLevelZeroContext ( )
static

VTK's Level Zero context and the driver and device it is on (the ze_*_handle_ts).

SetLevelZeroContext makes VTK use another library's; set it before any Level Zero array is made, since arrays copy in whichever context is current. A null context forgets it (a context VTK made is kept alive, not destroyed). HasLevelZeroContext says whether there is one without making one; GetLevelZeroContext makes one if there is none, and returns false, with the reason in why, if it cannot.

◆ GetLevelZeroContext()

bool vtkDeviceMemory::GetLevelZeroContext ( void *& driver,
void *& device,
void *& context,
std::string * why = nullptr )
static

VTK's Level Zero context and the driver and device it is on (the ze_*_handle_ts).

SetLevelZeroContext makes VTK use another library's; set it before any Level Zero array is made, since arrays copy in whichever context is current. A null context forgets it (a context VTK made is kept alive, not destroyed). HasLevelZeroContext says whether there is one without making one; GetLevelZeroContext makes one if there is none, and returns false, with the reason in why, if it cannot.


The documentation for this class was generated from the following file: