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 CudaRuntimeInheritance
Inherited Members
Fields
EventDisableTiming
cudaEventDisableTiming flag value.
public const uint EventDisableTiming = 2Field Value
StreamNonBlocking
cudaStreamNonBlocking flag value.
public const uint StreamNonBlocking = 1Field Value
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
DeviceCanAccessPeer(int, int)
Returns whether device can access memory on peerDevice.
public static bool DeviceCanAccessPeer(int device, int peerDevice)Parameters
Returns
DeviceDisablePeerAccess(int)
Disables previously enabled peer access to peerDevice.
public static void DeviceDisablePeerAccess(int peerDevice)Parameters
peerDeviceint
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
peerDeviceint
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
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
flagsuint
Returns
EventDestroy(nint)
Destroys a CUDA event.
public static void EventDestroy(nint @event)Parameters
eventnint
EventElapsedTime(nint, nint)
Returns elapsed time in milliseconds between two recorded events.
public static float EventElapsedTime(nint start, nint end)Parameters
Returns
EventRecord(nint, nint)
Records event in stream.
public static void EventRecord(nint @event, nint stream)Parameters
EventSynchronize(nint)
Blocks the calling thread until event has been recorded.
public static void EventSynchronize(nint @event)Parameters
eventnint
Free(void*)
Frees device memory synchronously.
public static void Free(void* devPtr)Parameters
devPtrvoid*
FreeAsync(void*, nint)
Frees device memory asynchronously on stream.
public static void FreeAsync(void* devPtr, nint stream)Parameters
FreeHost(void*)
Frees page-locked host memory allocated with NVMathNet.Interop.CudaRuntime.MallocHost(System.UIntPtr).
public static void FreeHost(void* ptr)Parameters
ptrvoid*
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
tType
Returns
Exceptions
GetDevice()
Returns the index of the device currently selected for the calling thread.
public static int GetDevice()Returns
GetDeviceCount()
Returns the number of CUDA-capable devices visible to the runtime.
public static int GetDeviceCount()Returns
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
deviceint
Returns
GetDriverVersion()
Returns the CUDA driver version (e.g. 12000 = v12.0).
public static int GetDriverVersion()Returns
GetErrorString(CudaError)
Returns the human-readable description for a CUDA error code.
public static string GetErrorString(CudaError error)Parameters
errorCudaError
Returns
GetLastError()
Returns and clears the last CUDA error set on the calling host thread.
public static CudaError GetLastError()Returns
GetRuntimeVersion()
Returns the CUDA runtime version (e.g. 12000 = v12.0).
public static int GetRuntimeVersion()Returns
Malloc(nuint)
Allocates size bytes of device memory synchronously.
public static void* Malloc(nuint size)Parameters
sizenuint
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
Returns
- void*
-
Raw device pointer.
MallocHost(nuint)
Allocates size bytes of page-locked (pinned) host memory.
public static void* MallocHost(nuint size)Parameters
sizenuint
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
dstvoid*srcvoid*countnuintkindCudaMemcpyKind
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
dstvoid*srcvoid*countnuintkindCudaMemcpyKindstreamnint
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
Memset(void*, int, nuint)
Fills count bytes of device memory with value synchronously.
public static void Memset(void* devPtr, int value, nuint count)Parameters
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
SetDevice(int)
Sets the active CUDA device for the calling host thread.
public static void SetDevice(int device)Parameters
deviceint
StreamCreate()
Creates a CUDA stream with default flags. Caller must call NVMathNet.Interop.CudaRuntime.StreamDestroy(System.IntPtr) when done.
public static nint StreamCreate()Returns
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
flagsuint
Returns
StreamDestroy(nint)
Destroys a CUDA stream.
public static void StreamDestroy(nint stream)Parameters
streamnint
StreamSynchronize(nint)
Blocks the calling thread until all operations in stream complete.
public static void StreamSynchronize(nint stream)Parameters
streamnint
StreamWaitEvent(nint, nint, uint)
Makes stream wait until event has been recorded.
public static void StreamWaitEvent(nint stream, nint @event, uint flags = 0)