cublas

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cublas provides Pure-Go (CGO_ENABLED=0) dynamic bindings to NVIDIA's cuBLAS library (libcublas.so.13 / libcublas.so.12 / libcublas.so) built on top of internal/dynlib.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnavailable = errors.New("cuBLAS library unavailable")

ErrUnavailable is returned when libcublas cannot be loaded on the current host.

Functions

This section is empty.

Types

type API

type API struct {
	// contains filtered or unexported fields
}

API holds dynamically bound cuBLAS library function pointers.

func Load

func Load() (*API, error)

Load lazily opens libcublas and binds required cuBLAS symbols.

func (*API) Create

func (a *API) Create() (Handle, error)

Create creates a new cuBLAS handle bound to the current CUDA context.

func (*API) Destroy

func (a *API) Destroy(h Handle) error

Destroy destroys a cuBLAS handle.

func (*API) GemmEx

func (a *API) GemmEx(
	h Handle,
	transa, transb Operation,
	m, n, k int32,
	alpha unsafe.Pointer,
	A driver.DevicePtr, Atype DataType, lda int32,
	B driver.DevicePtr, Btype DataType, ldb int32,
	beta unsafe.Pointer,
	C driver.DevicePtr, Ctype DataType, ldc int32,
	computeType ComputeType,
	algo GemmAlgo,
) error

GemmEx executes C = alpha * op(A) * op(B) + beta * C in column-major layout.

func (*API) GemmStridedBatchedEx

func (a *API) GemmStridedBatchedEx(
	h Handle,
	transa, transb Operation,
	m, n, k int32,
	alpha unsafe.Pointer,
	A driver.DevicePtr, Atype DataType, lda int32, strideA int64,
	B driver.DevicePtr, Btype DataType, ldb int32, strideB int64,
	beta unsafe.Pointer,
	C driver.DevicePtr, Ctype DataType, ldc int32, strideC int64,
	batchCount int32,
	computeType ComputeType,
	algo GemmAlgo,
) error

GemmStridedBatchedEx executes a strided batch of GEMMs in column-major layout.

func (*API) HasSetWorkspace added in v0.1.1

func (a *API) HasSetWorkspace() bool

HasSetWorkspace reports whether cublasSetWorkspace_v2 is available in the loaded cuBLAS library.

func (*API) LibraryPath

func (a *API) LibraryPath() string

LibraryPath returns the dynamic library path that was loaded.

func (*API) SetMathMode

func (a *API) SetMathMode(h Handle, mode MathMode) error

SetMathMode sets the cuBLAS math mode on the handle.

func (*API) SetStream

func (a *API) SetStream(h Handle, s driver.Stream) error

SetStream binds the cuBLAS handle to the given CUDA stream.

func (*API) SetWorkspace added in v0.1.1

func (a *API) SetWorkspace(h Handle, workspace driver.DevicePtr, sizeBytes uintptr) error

SetWorkspace attaches a user-managed device workspace buffer to the cuBLAS handle (NVIDIA recommends 32 MiB on Hopper/Blackwell for optimal Tensor Core / split-K heuristics). No-op if cublasSetWorkspace_v2 is not present in the loaded library.

func (*API) Version

func (a *API) Version(h Handle) (int, error)

Version returns the cuBLAS version integer (e.g., 130600 for 13.6.0).

type ComputeType

type ComputeType int32

ComputeType represents cublasComputeType_t (from cublas_api.h).

const (
	Compute16F         ComputeType = 64
	Compute16FPedantic ComputeType = 65
	Compute32F         ComputeType = 68
	Compute32FPedantic ComputeType = 69
	Compute64F         ComputeType = 70
	Compute64FPedantic ComputeType = 71
	Compute32I         ComputeType = 72
	Compute32FFast16F  ComputeType = 74
	Compute32FFast16BF ComputeType = 75
	Compute32FFastTF32 ComputeType = 77
)

type DataType

type DataType int32

DataType represents cudaDataType_t (from library_types.h).

const (
	DataR32F  DataType = 0
	DataR64F  DataType = 1
	DataR16F  DataType = 2
	DataR8I   DataType = 3
	DataC32F  DataType = 4
	DataC64F  DataType = 5
	DataR8U   DataType = 8
	DataR32I  DataType = 10
	DataR16BF DataType = 14
)

type Error

type Error struct {
	Op     string
	Status Status
	Name   string
	Desc   string
}

Error represents a non-zero cublasStatus_t returned by a cuBLAS call.

func (*Error) Error

func (e *Error) Error() string

type GemmAlgo

type GemmAlgo int32

GemmAlgo represents cublasGemmAlgo_t.

const (
	GemmDefault         GemmAlgo = -1
	GemmDefaultTensorOp GemmAlgo = 99
)

type Handle

type Handle uintptr

Handle represents an opaque cublasHandle_t.

type LtAPI added in v0.1.1

type LtAPI struct {
	// contains filtered or unexported fields
}

LtAPI holds dynamically bound libcublasLt symbols.

func LoadLt added in v0.1.1

func LoadLt() (*LtAPI, error)

LoadLt lazily opens libcublasLt and binds required cuBLASLt symbols.

func (*LtAPI) Create added in v0.1.1

func (a *LtAPI) Create() (LtHandle, error)

func (*LtAPI) CreatePlan added in v0.1.1

func (a *LtAPI) CreatePlan(h LtHandle, key LtPlanKey, maxWorkspaceBytes uintptr) (*LtPlan, error)

CreatePlan builds descriptors and queries cuBLASLt's heuristic for key within maxWorkspaceBytes. Returns (nil, nil) if cuBLASLt reports no supported algorithm for this configuration.

func (*LtAPI) Destroy added in v0.1.1

func (a *LtAPI) Destroy(h LtHandle) error

func (*LtAPI) DestroyPlan added in v0.1.1

func (a *LtAPI) DestroyPlan(p *LtPlan)

DestroyPlan releases cuBLASLt descriptors held by plan.

func (*LtAPI) ExecutePlan added in v0.1.1

func (a *LtAPI) ExecutePlan(
	h LtHandle,
	p *LtPlan,
	alpha, beta unsafe.Pointer,
	A, B, D, bias driver.DevicePtr,
	workspace driver.DevicePtr,
	workspaceBytes uintptr,
	stream driver.Stream,
) error

ExecutePlan runs D = epilogue(alpha * op(A) * op(B) + bias) using a cached LtPlan.

type LtEpilogue added in v0.1.1

type LtEpilogue uint32

LtEpilogue matches cublasLtEpilogue_t.

const (
	LtEpilogueDefault  LtEpilogue = 1
	LtEpilogueRelu     LtEpilogue = 2
	LtEpilogueBias     LtEpilogue = 4
	LtEpilogueReluBias LtEpilogue = LtEpilogueRelu | LtEpilogueBias
	LtEpilogueGelu     LtEpilogue = 32
	LtEpilogueGeluBias LtEpilogue = LtEpilogueGelu | LtEpilogueBias
)

type LtHandle added in v0.1.1

type LtHandle uintptr

LtHandle is an opaque cublasLtHandle_t.

type LtMatmulAlgo added in v0.1.1

type LtMatmulAlgo struct {
	Data [8]uint64
}

LtMatmulAlgo matches cublasLtMatmulAlgo_t (64 bytes, 8-byte aligned).

type LtMatmulDesc added in v0.1.1

type LtMatmulDesc uintptr

LtMatmulDesc is an opaque cublasLtMatmulDesc_t.

type LtMatmulDescAttr added in v0.1.1

type LtMatmulDescAttr int32

LtMatmulDescAttr matches cublasLtMatmulDescAttributes_t.

type LtMatmulHeuristicResult added in v0.1.1

type LtMatmulHeuristicResult struct {
	Algo          LtMatmulAlgo
	WorkspaceSize uintptr
	State         Status
	WavesCount    float32
	Reserved      [4]int32
}

LtMatmulHeuristicResult matches cublasLtMatmulHeuristicResult_t (96 bytes, 8-byte aligned).

type LtMatmulPrefAttr added in v0.1.1

type LtMatmulPrefAttr int32

LtMatmulPrefAttr matches cublasLtMatmulPreferenceAttributes_t.

type LtMatmulPreference added in v0.1.1

type LtMatmulPreference uintptr

LtMatmulPreference is an opaque cublasLtMatmulPreference_t.

type LtMatrixLayout added in v0.1.1

type LtMatrixLayout uintptr

LtMatrixLayout is an opaque cublasLtMatrixLayout_t.

type LtPlan added in v0.1.1

type LtPlan struct {
	Desc          LtMatmulDesc
	ADesc         LtMatrixLayout
	BDesc         LtMatrixLayout
	DDesc         LtMatrixLayout
	Algo          LtMatmulAlgo
	WorkspaceSize uintptr
	HasBias       bool
}

LtPlan holds pre-created cuBLASLt descriptors and heuristic algorithm for a fixed GEMM shape/epilogue. Not safe for concurrent mutation of its bias pointer; callers synchronize per-handle.

type LtPlanKey added in v0.1.1

type LtPlanKey struct {
	M, N, K     int32 // column-major dims: D[M, N] = op(A)[M, K] * op(B)[K, N]
	TransA      Operation
	TransB      Operation
	AType       DataType
	BType       DataType
	DType       DataType
	BiasType    DataType
	ComputeType ComputeType
	Epilogue    LtEpilogue
}

LtPlanKey uniquely identifies a cached cuBLASLt matmul plan (excluding runtime pointers).

type MathMode

type MathMode int32

MathMode represents cublasMath_t.

const (
	DefaultMath  MathMode = 0
	TensorOpMath MathMode = 1
)

type Operation

type Operation int32

Operation represents cublasOperation_t.

const (
	OpN Operation = 0 // non-transpose
	OpT Operation = 1 // transpose
	OpC Operation = 2 // conjugate transpose
)

type Status

type Status int32

Status represents cublasStatus_t.

const (
	StatusSuccess        Status = 0
	StatusNotInitialized Status = 1
	StatusAllocFailed    Status = 3
	StatusInvalidValue   Status = 7
	StatusArchMismatch   Status = 8
	StatusMappingError   Status = 11
	StatusExecutionFail  Status = 13
	StatusInternalError  Status = 14
	StatusNotSupported   Status = 15
	StatusLicenseError   Status = 16
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL