C API reference

Enums

enum vkgdr_open_flags

Valid flags to pass to vkgdr_open.

Values:

enumerator VKGDR_OPEN_CURRENT_CONTEXT_BIT

Ignore the given device and use the current CUDA context instead.

enumerator VKGDR_OPEN_FORCE_NON_COHERENT_BIT

Treat the memory as non-coherent even if it is coherent (for debugging only)

enumerator VKGDR_OPEN_REQUIRE_COHERENT_BIT

Fail unless memory is guaranteed to be coherent.

Functions

char *vkgdr_last_error(void)

Get the error (if any) from the previous call to vkgdr_open or vkgdr_memory_alloc in the current thread. If the last call was successful, returns NULL. The caller is responsible for freeing the return value.

vkgdr_t vkgdr_open(CUdevice device, uint32_t flags)

Obtain a handle to the library.

Parameters
  • device – CUDA device from which to allocate the memory (ignored if flags contains VKGDR_OPEN_CURRENT_CONTEXT_BIT)

  • flags – A bitwise combination of zero or more flags from vkgdr_open_flags.

Returns

a handle, or NULL on error

void vkgdr_close(vkgdr_t g)

Close a handle obtained from vkgdr_open.

This must only be called after all memory allocations have been freed.

vkgdr_memory_t vkgdr_memory_alloc(vkgdr_t g, size_t size, uint32_t flags)

Allocate memory. The current CUDA context must be one associated with the device passed to vkgdr_open.

Parameters
  • g – A handle obtained from vkgdr_open

  • size – Number of bytes to allocate

  • flags – Flags for future expansion; must be 0

Returns

A handle to the memory allocation, or NULL on failure.

void vkgdr_memory_free(vkgdr_memory_t mem)

Free memory allocated with vkgdr_memory_alloc. This must be called with the same CUDA context current as when vkgdr_memory_alloc was called.

void *vkgdr_memory_get_host_ptr(vkgdr_memory_t mem)

Retrieve the host pointer for a memory allocation.

CUdeviceptr vkgdr_memory_get_device_ptr(vkgdr_memory_t mem)

Retrieve the CUDA device pointer for a memory allocation.

size_t vkgdr_memory_get_size(vkgdr_memory_t mem)

Retrieve the size of a memory allocation.

bool vkgdr_memory_is_coherent(vkgdr_memory_t mem)

Determine whether a memory allocation is coherent from the host’s point of view.

size_t vkgdr_memory_non_coherent_atom_size(vkgdr_memory_t mem)

Get the alignment requirement for flush and invalidate operations. If the memory is coherent, returns 1.

void vkgdr_memory_flush(vkgdr_memory_t mem, size_t offset, size_t size)

Flush host writes so that they are visible to the device.

Warning

offset and size must be multiples of the value returned by vkgdr_memory_non_coherent_atom_size (except where offset + size corresponds to the end of the memory allocation). Failing to observer this has undefined behaviour.

Parameters
  • mem – Memory handle returned by vkgdr_memory_alloc

  • offset – Offset in bytes to the first byte to flush.

  • size – Size in bytes of the region to flush.

void vkgdr_memory_invalidate(vkgdr_memory_t mem, size_t offset, size_t size)

Invalidate host view of device memory so that previous device writes are visible to the host.

Warning

offset and size must be multiples of the value returned by vkgdr_memory_non_coherent_atom_size (except where offset + size corresponds to the end of the memory allocation). Failing to observe this has undefined behaviour.

Parameters
  • mem – Memory handle returned by vkgdr_memory_alloc

  • offset – Offset in bytes to the first byte to invalidate.

  • size – Size in bytes of the region to invalidate.