Documentation
¶
Overview ¶
Package driver provides Pure-Go bindings to NVIDIA's CUDA Driver API (libcuda.so.1 / nvcuda.dll) loaded dynamically via internal/dynlib.
Index ¶
- Constants
- Variables
- type API
- func (a *API) CtxGetCurrent() (Context, error)
- func (a *API) CtxSetCurrent(ctx Context) error
- func (a *API) CtxSynchronize() error
- func (a *API) DeviceAttribute(dev Device, attr DeviceAttribute) (int, error)
- func (a *API) DeviceCount() (int, error)
- func (a *API) DeviceGet(ordinal int) (Device, error)
- func (a *API) DeviceGetDefaultMemPool(dev Device) (MemPool, error)
- func (a *API) DriverVersion() int
- func (a *API) DriverVersionString() string
- func (a *API) EventCreate(flags EventFlags) (Event, error)
- func (a *API) EventDestroy(e Event) error
- func (a *API) EventElapsedTime(start, end Event) (float32, error)
- func (a *API) EventRecord(e Event, s Stream) error
- func (a *API) EventSynchronize(e Event) error
- func (a *API) GraphDestroy(graph Graph) error
- func (a *API) GraphExecDestroy(graphExec GraphExec) error
- func (a *API) GraphExecUpdate(graphExec GraphExec, graph Graph) (bool, error)
- func (a *API) GraphInstantiate(graph Graph, flags uint64) (GraphExec, error)
- func (a *API) GraphLaunch(graphExec GraphExec, stream Stream) error
- func (a *API) HasGraphAPI() bool
- func (a *API) HasGraphExecUpdate() bool
- func (a *API) HasStreamOrderedAlloc() bool
- func (a *API) LaunchKernel(fn Function, gridX, gridY, gridZ uint32, blockX, blockY, blockZ uint32, ...) error
- func (a *API) LibraryPath() string
- func (a *API) MemAlloc(byteSize uintptr) (DevicePtr, error)
- func (a *API) MemAllocAsync(byteSize uintptr, s Stream) (DevicePtr, error)
- func (a *API) MemFree(ptr DevicePtr) error
- func (a *API) MemFreeAsync(ptr DevicePtr, s Stream) error
- func (a *API) MemFreeHost(ptr unsafe.Pointer) error
- func (a *API) MemGetInfo() (freeBytes, totalBytes uint64, err error)
- func (a *API) MemHostAlloc(byteSize uintptr, flags uint32) (unsafe.Pointer, error)
- func (a *API) MemPoolSetReleaseThreshold(pool MemPool, thresholdBytes uint64) error
- func (a *API) MemPoolTrimTo(pool MemPool, minBytesToKeep uintptr) error
- func (a *API) MemcpyDtoD(dst, src DevicePtr, byteSize uintptr) error
- func (a *API) MemcpyDtoDAsync(dst, src DevicePtr, byteSize uintptr, s Stream) error
- func (a *API) MemcpyDtoH(dst unsafe.Pointer, src DevicePtr, byteSize uintptr) error
- func (a *API) MemcpyDtoHAsync(dst unsafe.Pointer, src DevicePtr, byteSize uintptr, s Stream) error
- func (a *API) MemcpyHtoD(dst DevicePtr, src unsafe.Pointer, byteSize uintptr) error
- func (a *API) MemcpyHtoDAsync(dst DevicePtr, src unsafe.Pointer, byteSize uintptr, s Stream) error
- func (a *API) MemsetD8Async(dst DevicePtr, value byte, count uintptr, s Stream) error
- func (a *API) ModuleGetFunction(mod Module, name string) (Function, error)
- func (a *API) ModuleLoadData(image []byte) (Module, error)
- func (a *API) ModuleUnload(mod Module) error
- func (a *API) PrimaryCtxRelease(dev Device) error
- func (a *API) PrimaryCtxRetain(dev Device) (Context, error)
- func (a *API) QueryDeviceInfo(ordinal int) (DeviceInfo, error)
- func (a *API) StreamBeginCapture(stream Stream, mode StreamCaptureMode) error
- func (a *API) StreamCreate(flags StreamFlags) (Stream, error)
- func (a *API) StreamDestroy(s Stream) error
- func (a *API) StreamEndCapture(stream Stream) (Graph, error)
- func (a *API) StreamIsCapturing(stream Stream) (StreamCaptureStatus, error)
- func (a *API) StreamSynchronize(s Stream) error
- func (a *API) StreamWaitEvent(s Stream, e Event) error
- type CUDAError
- type Context
- type Device
- type DeviceAttribute
- type DeviceContext
- func (dc *DeviceContext) API() *API
- func (dc *DeviceContext) ComputeStream() Stream
- func (dc *DeviceContext) Context() Context
- func (dc *DeviceContext) CopyStream() Stream
- func (dc *DeviceContext) Info() DeviceInfo
- func (dc *DeviceContext) Release() error
- func (dc *DeviceContext) WithContext(fn func() error) error
- type DeviceInfo
- type DevicePtr
- type Event
- type EventFlags
- type Function
- type Graph
- type GraphExec
- type GraphExecUpdateResult
- type GraphExecUpdateResultInfo
- type MemPool
- type MemPoolAttr
- type Module
- type Result
- type Stream
- type StreamCaptureMode
- type StreamCaptureStatus
- type StreamFlags
Constants ¶
const ( MemHostAllocPortable uint32 = 0x01 MemHostAllocDeviceMap uint32 = 0x02 MemHostAllocWriteCombined uint32 = 0x04 )
MemHostAllocFlags corresponds to CU_MEMHOSTALLOC_* flags.
Variables ¶
ErrDriverUnavailable indicates that no usable CUDA driver library or CUDA-capable GPU is present.
Functions ¶
This section is empty.
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
API holds dynamically bound CUDA Driver API function pointers.
func Load ¶
Load lazily opens the CUDA Driver library, binds core Driver API symbols, and calls cuInit(0). Subsequent calls return the cached *API instance.
func (*API) CtxGetCurrent ¶
CtxGetCurrent returns the CUDA context currently bound to the calling OS thread.
func (*API) CtxSetCurrent ¶
CtxSetCurrent binds ctx to the calling OS thread.
func (*API) CtxSynchronize ¶
CtxSynchronize blocks until all work on the current context completes.
func (*API) DeviceAttribute ¶
func (a *API) DeviceAttribute(dev Device, attr DeviceAttribute) (int, error)
DeviceAttribute queries a single CUdevice_attribute integer value.
func (*API) DeviceCount ¶
DeviceCount returns the number of CUDA-capable devices.
func (*API) DeviceGetDefaultMemPool ¶
DeviceGetDefaultMemPool returns the default CUDA memory pool for dev.
func (*API) DriverVersion ¶
DriverVersion returns the raw CUDA driver version integer (e.g., 13030 for CUDA 13.3).
func (*API) DriverVersionString ¶
DriverVersionString returns the formatted CUDA driver version (e.g., "13.3").
func (*API) EventCreate ¶
func (a *API) EventCreate(flags EventFlags) (Event, error)
EventCreate creates a CUDA event in the current context.
func (*API) EventDestroy ¶
EventDestroy destroys a CUDA event.
func (*API) EventElapsedTime ¶
EventElapsedTime returns the elapsed time in milliseconds between start and end events.
func (*API) EventRecord ¶
EventRecord records event in stream.
func (*API) EventSynchronize ¶
EventSynchronize blocks until event completes.
func (*API) GraphDestroy ¶ added in v0.1.1
GraphDestroy releases a captured Graph template (independent of any instantiated GraphExec).
func (*API) GraphExecDestroy ¶ added in v0.1.1
GraphExecDestroy releases an instantiated GraphExec.
func (*API) GraphExecUpdate ¶ added in v0.1.1
GraphExecUpdate attempts to update an instantiated GraphExec in-place from a topologically identical Graph. Returns updated=true on success; updated=false (with nil error) when cuGraphExecUpdate_v2 is unavailable or reports a non-updatable change so the caller can fall back to destroying and re-instantiating the GraphExec.
func (*API) GraphInstantiate ¶ added in v0.1.1
GraphInstantiate instantiates a captured Graph into a launchable GraphExec.
func (*API) GraphLaunch ¶ added in v0.1.1
GraphLaunch submits an instantiated GraphExec onto stream.
func (*API) HasGraphAPI ¶ added in v0.1.1
HasGraphAPI reports whether CUDA Graph stream capture and replay symbols are available.
func (*API) HasGraphExecUpdate ¶ added in v0.1.1
HasGraphExecUpdate reports whether cuGraphExecUpdate_v2 is available.
func (*API) HasStreamOrderedAlloc ¶
HasStreamOrderedAlloc reports whether cuMemAllocAsync / cuMemFreeAsync symbols were bound.
func (*API) LaunchKernel ¶
func (a *API) LaunchKernel( fn Function, gridX, gridY, gridZ uint32, blockX, blockY, blockZ uint32, sharedMemBytes uint32, stream Stream, kernelParams unsafe.Pointer, ) error
LaunchKernel launches a CUDA kernel function on stream with the given grid/block dimensions and kernelParams (void** pointer array, e.g., from arena.KernelArgs.ParamsPtr()).
func (*API) LibraryPath ¶
LibraryPath returns the dynamic library name/path that was opened (e.g., "libcuda.so.1").
func (*API) MemAlloc ¶
MemAlloc allocates byteSize bytes of linear device memory in the current context.
func (*API) MemAllocAsync ¶
MemAllocAsync allocates byteSize bytes of stream-ordered VRAM on stream s.
func (*API) MemFreeAsync ¶
MemFreeAsync asynchronously frees stream-ordered VRAM ptr on stream s.
func (*API) MemFreeHost ¶
MemFreeHost frees page-locked host memory allocated by MemHostAlloc.
func (*API) MemGetInfo ¶
MemGetInfo returns free and total VRAM in bytes for the current context.
func (*API) MemHostAlloc ¶
MemHostAlloc allocates page-locked (pinned) host memory.
func (*API) MemPoolSetReleaseThreshold ¶
MemPoolSetReleaseThreshold configures CU_MEMPOOL_ATTR_RELEASE_THRESHOLD on pool.
func (*API) MemPoolTrimTo ¶
MemPoolTrimTo releases unused memory from pool back to the OS down to minBytesToKeep.
func (*API) MemcpyDtoD ¶
MemcpyDtoD synchronously copies byteSize bytes between device allocations.
func (*API) MemcpyDtoDAsync ¶
MemcpyDtoDAsync asynchronously copies byteSize bytes from device src to device dst on stream s.
func (*API) MemcpyDtoH ¶
MemcpyDtoH synchronously copies byteSize bytes from device src to host dst.
func (*API) MemcpyDtoHAsync ¶
MemcpyDtoHAsync asynchronously copies byteSize bytes from device src to host dst on stream s.
func (*API) MemcpyHtoD ¶
MemcpyHtoD synchronously copies byteSize bytes from host src to device dst.
func (*API) MemcpyHtoDAsync ¶
MemcpyHtoDAsync asynchronously copies byteSize bytes from host src to device dst on stream s.
func (*API) MemsetD8Async ¶
MemsetD8Async asynchronously fills count bytes at device dst with value on stream s.
func (*API) ModuleGetFunction ¶
ModuleGetFunction retrieves a kernel function handle by symbol name from mod.
func (*API) ModuleLoadData ¶
ModuleLoadData loads a PTX string or cubin/fatbin binary into the current CUDA context. If loading fails, it retries with cuModuleLoadDataEx to capture detailed NVIDIA JIT error logs.
func (*API) ModuleUnload ¶
ModuleUnload unloads a previously loaded CUDA module.
func (*API) PrimaryCtxRelease ¶
PrimaryCtxRelease releases the primary context on dev.
func (*API) PrimaryCtxRetain ¶
PrimaryCtxRetain retains the primary context on dev.
func (*API) QueryDeviceInfo ¶
func (a *API) QueryDeviceInfo(ordinal int) (DeviceInfo, error)
QueryDeviceInfo returns hardware properties for the specified device ordinal.
func (*API) StreamBeginCapture ¶ added in v0.1.1
func (a *API) StreamBeginCapture(stream Stream, mode StreamCaptureMode) error
StreamBeginCapture begins capturing asynchronous GPU work submitted to stream into a CUDA Graph.
func (*API) StreamCreate ¶
func (a *API) StreamCreate(flags StreamFlags) (Stream, error)
StreamCreate creates a CUDA stream in the current context.
func (*API) StreamDestroy ¶
StreamDestroy destroys a CUDA stream.
func (*API) StreamEndCapture ¶ added in v0.1.1
StreamEndCapture terminates stream capture and returns the captured Graph.
func (*API) StreamIsCapturing ¶ added in v0.1.1
func (a *API) StreamIsCapturing(stream Stream) (StreamCaptureStatus, error)
StreamIsCapturing queries whether stream is currently capturing into a graph.
func (*API) StreamSynchronize ¶
StreamSynchronize waits until all queued operations in stream have completed.
type DeviceAttribute ¶
type DeviceAttribute int32
DeviceAttribute corresponds to CUdevice_attribute.
const ( AttrMaxThreadsPerBlock DeviceAttribute = 1 AttrWarpSize DeviceAttribute = 10 AttrMultiprocessorCount DeviceAttribute = 16 AttrUnifiedAddressing DeviceAttribute = 41 AttrComputeCapabilityMajor DeviceAttribute = 75 AttrComputeCapabilityMinor DeviceAttribute = 76 AttrMemoryPoolsSupported DeviceAttribute = 115 )
type DeviceContext ¶
type DeviceContext struct {
// contains filtered or unexported fields
}
DeviceContext owns a retained CUDA primary context and its default compute/copy streams for a single GPU ordinal.
Because CUDA Driver API contexts are OS-thread-local while Go goroutines migrate freely across OS threads, all context-bound driver operations must execute inside WithContext.
func RetainDeviceContext ¶
func RetainDeviceContext(api *API, ordinal int) (*DeviceContext, error)
RetainDeviceContext retains the primary CUDA context for ordinal and creates non-blocking compute and copy streams on it.
func (*DeviceContext) API ¶
func (dc *DeviceContext) API() *API
API returns the underlying CUDA Driver API bindings.
func (*DeviceContext) ComputeStream ¶
func (dc *DeviceContext) ComputeStream() Stream
ComputeStream returns the default non-blocking compute stream for this device.
func (*DeviceContext) Context ¶
func (dc *DeviceContext) Context() Context
Context returns the retained primary CUcontext handle.
func (*DeviceContext) CopyStream ¶
func (dc *DeviceContext) CopyStream() Stream
CopyStream returns the default non-blocking async copy stream for this device.
func (*DeviceContext) Info ¶
func (dc *DeviceContext) Info() DeviceInfo
Info returns the queried hardware properties of this device.
func (*DeviceContext) Release ¶
func (dc *DeviceContext) Release() error
Release destroys the device's streams and releases its retained primary context. Release is goroutine-safe and idempotent. Callers must ensure all in-flight work using this DeviceContext has finished before calling Release.
func (*DeviceContext) WithContext ¶
func (dc *DeviceContext) WithContext(fn func() error) error
WithContext locks the calling goroutine to its OS thread, binds the primary CUDA context as current on that thread, invokes fn, and unlocks the OS thread on return.
Callers should group a sequence of driver calls (such as a full graph execution) inside a single WithContext call to amortize the OS-thread lock and cuCtxSetCurrent cost.
type DeviceInfo ¶
type DeviceInfo struct {
Ordinal int
Handle Device
Name string
TotalMemBytes uint64
ComputeMajor int
ComputeMinor int
MultiprocessorCount int
MaxThreadsPerBlock int
WarpSize int
UnifiedAddressing bool
MemoryPoolsSupported bool
}
DeviceInfo holds queried hardware properties of a CUDA GPU.
func (DeviceInfo) ComputeCapability ¶
func (d DeviceInfo) ComputeCapability() int
ComputeCapability returns the combined SM capability integer (e.g., 75 for sm_75, 120 for sm_120).
func (DeviceInfo) String ¶
func (d DeviceInfo) String() string
String returns a concise human-readable description of the device.
func (DeviceInfo) SupportsDP4A ¶
func (d DeviceInfo) SupportsDP4A() bool
SupportsDP4A reports whether the GPU supports native Int8 DP4A dot-product instructions (Pascal sm_61+).
func (DeviceInfo) SupportsNativeBF16 ¶
func (d DeviceInfo) SupportsNativeBF16() bool
SupportsNativeBF16 reports whether the GPU has native BFloat16 hardware instructions (Ampere sm_80+).
func (DeviceInfo) SupportsNativeFP16 ¶
func (d DeviceInfo) SupportsNativeFP16() bool
SupportsNativeFP16 reports whether the GPU has native Float16 compute units (Volta sm_70+ / Turing sm_75+).
type EventFlags ¶
type EventFlags uint32
EventFlags corresponds to CUevent_flags.
const ( EventDefault EventFlags = 0x0 EventBlockingSync EventFlags = 0x1 EventDisableTiming EventFlags = 0x2 )
type GraphExec ¶ added in v0.1.1
type GraphExec uintptr
GraphExec corresponds to CUgraphExec (opaque pointer).
type GraphExecUpdateResult ¶ added in v0.1.1
type GraphExecUpdateResult uint32
GraphExecUpdateResult corresponds to CUgraphExecUpdateResult.
const (
GraphExecUpdateSuccess GraphExecUpdateResult = 0
)
type GraphExecUpdateResultInfo ¶ added in v0.1.1
type GraphExecUpdateResultInfo struct {
Result GraphExecUpdateResult
ErrorNode uintptr
ErrorFromNode uintptr
// contains filtered or unexported fields
}
GraphExecUpdateResultInfo matches CUDA's CUgraphExecUpdateResultInfo (24 bytes on 64-bit).
type MemPoolAttr ¶
type MemPoolAttr uint32
MemPoolAttr corresponds to CUmemPool_attribute.
const ( // MemPoolAttrReleaseThreshold (CU_MEMPOOL_ATTR_RELEASE_THRESHOLD) controls the amount of // reserved memory in bytes that a pool holds onto before trying to release memory back to the OS. MemPoolAttrReleaseThreshold MemPoolAttr = 4 )
type Result ¶
type Result int32
Result corresponds to CUDA's CUresult status code.
const ( Success Result = 0 ErrorInvalidValue Result = 1 ErrorOutOfMemory Result = 2 ErrorNotInitialized Result = 3 ErrorDeinitialized Result = 4 ErrorNoDevice Result = 100 ErrorInvalidDevice Result = 101 ErrorInvalidImage Result = 200 ErrorInvalidContext Result = 201 ErrorInvalidPTX Result = 218 ErrorUnsupportedPTX Result = 222 ErrorNotFound Result = 500 ErrorNotReady Result = 600 ErrorIllegalAddress Result = 700 ErrorLaunchFailed Result = 719 ErrorInsufficientDriver Result = 35 )
type StreamCaptureMode ¶ added in v0.1.1
type StreamCaptureMode uint32
StreamCaptureMode corresponds to CUstreamCaptureMode.
const ( StreamCaptureModeGlobal StreamCaptureMode = 0 StreamCaptureModeThreadLocal StreamCaptureMode = 1 StreamCaptureModeRelaxed StreamCaptureMode = 2 )
type StreamCaptureStatus ¶ added in v0.1.1
type StreamCaptureStatus uint32
StreamCaptureStatus corresponds to CUstreamCaptureStatus.
const ( StreamCaptureStatusNone StreamCaptureStatus = 0 StreamCaptureStatusActive StreamCaptureStatus = 1 StreamCaptureStatusInvalidated StreamCaptureStatus = 2 )
type StreamFlags ¶
type StreamFlags uint32
StreamFlags corresponds to CUstream_flags.
const ( StreamDefault StreamFlags = 0x0 StreamNonBlocking StreamFlags = 0x1 )