Table of Contents

Class CudaRuntime

Namespace
NVMathNet.Interop
Assembly
NVMath.Net.dll

Raw P/Invoke bindings for the CUDA Runtime API (cudart). All methods are loaded lazily via NVMathNet.Interop.NativeLibraryLoader.

public static class CudaRuntime

Inheritance

Inherited Members

Fields

EventDisableTiming

cudaEventDisableTiming flag value.

public const uint EventDisableTiming = 2

Field Value

uint

StreamNonBlocking

cudaStreamNonBlocking flag value.

public const uint StreamNonBlocking = 1

Field Value

uint

Methods

CheckError(CudaError, string?)

Throws NVMathNet.Interop.CudaException if error is not NVMathNet.Interop.CudaError.Success. Optionally prefixes the message with context.

public static void CheckError(CudaError error, string? context = null)

Parameters

error CudaError
context string?

DeviceCanAccessPeer(int, int)

Returns whether device can access memory on peerDevice.

public static bool DeviceCanAccessPeer(int device, int peerDevice)

Parameters

device int
peerDevice int

Returns

bool

DeviceDisablePeerAccess(int)

Disables previously enabled peer access to peerDevice.

public static void DeviceDisablePeerAccess(int peerDevice)

Parameters

peerDevice int

DeviceEnablePeerAccess(int)

Enables peer access from the current device to peerDevice. Must be called after NVMathNet.Interop.CudaRuntime.SetDevice(System.Int32) to set the current device.

public static void DeviceEnablePeerAccess(int peerDevice)

Parameters

peerDevice int

DeviceSynchronize()

Blocks until all preceding CUDA work on all streams of the active device completes.

public static void DeviceSynchronize()

EventCreate()

Creates a CUDA event with default flags. Caller must call NVMathNet.Interop.CudaRuntime.EventDestroy(System.IntPtr) when done.

public static nint EventCreate()

Returns

nint

EventCreateWithFlags(uint)

Creates a CUDA event with the given flags. Use NVMathNet.Interop.CudaRuntime.EventDisableTiming to skip timing and reduce overhead.

public static nint EventCreateWithFlags(uint flags)

Parameters

flags uint

Returns

nint

EventDestroy(nint)

Destroys a CUDA event.

public static void EventDestroy(nint @event)

Parameters

event nint

EventElapsedTime(nint, nint)

Returns elapsed time in milliseconds between two recorded events.

public static float EventElapsedTime(nint start, nint end)

Parameters

start nint
end nint

Returns

float

EventRecord(nint, nint)

Records event in stream.

public static void EventRecord(nint @event, nint stream)

Parameters

event nint
stream nint

EventSynchronize(nint)

Blocks the calling thread until event has been recorded.

public static void EventSynchronize(nint @event)

Parameters

event nint

Free(void*)

Frees device memory synchronously.

public static void Free(void* devPtr)

Parameters

devPtr void*

FreeAsync(void*, nint)

Frees device memory asynchronously on stream.

public static void FreeAsync(void* devPtr, nint stream)

Parameters

devPtr void*
stream nint

FreeHost(void*)

Frees page-locked host memory allocated with NVMathNet.Interop.CudaRuntime.MallocHost(System.UIntPtr).

public static void FreeHost(void* ptr)

Parameters

ptr void*

GetCudaDataType<T>()

Gets the CUDA data type corresponding to the specified type parameter.

public static CudaDataType GetCudaDataType<T>() where T : unmanaged, INumberBase<T>

Returns

CudaDataType

The CUDA data type corresponding to the specified type.

Type Parameters

T

The type to get the CUDA data type for.

GetCudaDataType(Type)

Gets the CUDA data type corresponding to the specified System.Type.

public static CudaDataType GetCudaDataType(Type t)

Parameters

t Type

Returns

CudaDataType

Exceptions

NotSupportedException

GetDevice()

Returns the index of the device currently selected for the calling thread.

public static int GetDevice()

Returns

int

GetDeviceCount()

Returns the number of CUDA-capable devices visible to the runtime.

public static int GetDeviceCount()

Returns

int

GetDeviceName(int)

Returns the device name for the given device ordinal. Reads the first 256 bytes of the cudaDeviceProp structure (name field).

public static string GetDeviceName(int device)

Parameters

device int

Returns

string

GetDriverVersion()

Returns the CUDA driver version (e.g. 12000 = v12.0).

public static int GetDriverVersion()

Returns

int

GetErrorString(CudaError)

Returns the human-readable description for a CUDA error code.

public static string GetErrorString(CudaError error)

Parameters

error CudaError

Returns

string

GetLastError()

Returns and clears the last CUDA error set on the calling host thread.

public static CudaError GetLastError()

Returns

CudaError

GetRuntimeVersion()

Returns the CUDA runtime version (e.g. 12000 = v12.0).

public static int GetRuntimeVersion()

Returns

int

Malloc(nuint)

Allocates size bytes of device memory synchronously.

public static void* Malloc(nuint size)

Parameters

size nuint

Returns

void*

Raw device pointer.

MallocAsync(nuint, nint)

Allocates size bytes of device memory asynchronously on stream.

public static void* MallocAsync(nuint size, nint stream)

Parameters

size nuint
stream nint

Returns

void*

Raw device pointer.

MallocHost(nuint)

Allocates size bytes of page-locked (pinned) host memory.

public static void* MallocHost(nuint size)

Parameters

size nuint

Returns

void*

Raw host pointer.

Memcpy(void*, void*, nuint, CudaMemcpyKind)

Copies count bytes synchronously.

public static void Memcpy(void* dst, void* src, nuint count, CudaMemcpyKind kind)

Parameters

dst void*
src void*
count nuint
kind CudaMemcpyKind

MemcpyAsync(void*, void*, nuint, CudaMemcpyKind, nint)

Copies count bytes asynchronously on stream.

public static void MemcpyAsync(void* dst, void* src, nuint count, CudaMemcpyKind kind, nint stream)

Parameters

dst void*
src void*
count nuint
kind CudaMemcpyKind
stream nint

MemcpyPeerAsync(void*, int, void*, int, nuint, nint)

Copies count bytes from srcDevice to dstDevice asynchronously on stream.

public static void MemcpyPeerAsync(void* dst, int dstDevice, void* src, int srcDevice, nuint count, nint stream)

Parameters

dst void*
dstDevice int
src void*
srcDevice int
count nuint
stream nint

Memset(void*, int, nuint)

Fills count bytes of device memory with value synchronously.

public static void Memset(void* devPtr, int value, nuint count)

Parameters

devPtr void*
value int
count nuint

MemsetAsync(void*, int, nuint, nint)

Fills count bytes of device memory with value asynchronously.

public static void MemsetAsync(void* devPtr, int value, nuint count, nint stream)

Parameters

devPtr void*
value int
count nuint
stream nint

SetDevice(int)

Sets the active CUDA device for the calling host thread.

public static void SetDevice(int device)

Parameters

device int

StreamCreate()

Creates a CUDA stream with default flags. Caller must call NVMathNet.Interop.CudaRuntime.StreamDestroy(System.IntPtr) when done.

public static nint StreamCreate()

Returns

nint

StreamCreateWithFlags(uint)

Creates a CUDA stream with the given flags. Use NVMathNet.Interop.CudaRuntime.StreamNonBlocking to create a non-blocking stream.

public static nint StreamCreateWithFlags(uint flags)

Parameters

flags uint

Returns

nint

StreamDestroy(nint)

Destroys a CUDA stream.

public static void StreamDestroy(nint stream)

Parameters

stream nint

StreamSynchronize(nint)

Blocks the calling thread until all operations in stream complete.

public static void StreamSynchronize(nint stream)

Parameters

stream nint

StreamWaitEvent(nint, nint, uint)

Makes stream wait until event has been recorded.

public static void StreamWaitEvent(nint stream, nint @event, uint flags = 0)

Parameters

stream nint
event nint
flags uint