Documentation
¶
Overview ¶
Package ptx manages embedded precompiled CUDA PTX/fatbin modules and caches loaded CUmodule / CUfunction handles per CUDA DeviceContext.
Index ¶
- Constants
- func BinaryOpCode(op compute.OpType) (uint32, bool)
- func CmpOpCode(op compute.OpType) (uint32, bool)
- func DTypeCode(dt dtypes.DType) (uint32, bool)
- func DTypeSuffix(dt dtypes.DType) (string, bool)
- func Grid1D(n uint64, blockSize uint32) uint32
- func PredOpCode(op compute.OpType) (uint32, bool)
- func QuantDTypeCode(dt dtypes.DType) (uint32, bool)
- func RowMajorStrides(dims []int) [MaxBroadcastRank]uint64
- func UnaryOpCode(op compute.OpType) (uint32, bool)
- type BroadcastSpec
- type ConvDirectSpec
- type DynamicSliceSpec
- type GatherSpec
- type Im2Col2DNHWCSpec
- type Im2ColSpec
- type InlineI64Spec
- type PadSpec
- type QuantDenseSpec
- type QuantGatherSpec
- type ReduceSpec
- type ReduceWindowSpec
- type Registry
- type RoPESpec
- type SDPASpec
- type ScatterSpec
- type SelectAndScatterSpec
- type SplitMultiSpec
- type StridedCopySpec
- type TernaryBroadcastSpec
Constants ¶
const ( ReduceOpSum uint32 = 0 ReduceOpProd uint32 = 1 ReduceOpMax uint32 = 2 ReduceOpMin uint32 = 3 ReduceOpBitAnd uint32 = 4 ReduceOpBitOr uint32 = 5 ReduceOpBitXor uint32 = 6 ReduceOpLogAnd uint32 = 7 ReduceOpLogOr uint32 = 8 ReduceOpLogXor uint32 = 9 )
ReduceOp matches enum ReduceOp in kernels/gomlx/reduce.cu.
const ( ScanOpCumSum uint32 = 0 ScanOpCumMax uint32 = 1 )
ScanOp matches scan_op in kernels/gomlx/reduce.cu.
const ( ModuleBootstrap = "bootstrap" ModuleUnary = "unary" ModuleBinary = "binary" ModuleConvert = "convert" ModuleShape = "shape" ModuleReduce = "reduce" ModuleDot = "dot" ModuleConvPoolBN = "conv_pool_bn" ModuleFused = "fused" ModuleQuant = "quant" )
Module names registered in embeddedModules.
const ( ScatterOpSum uint32 = 0 ScatterOpMax uint32 = 1 ScatterOpMin uint32 = 2 )
ScatterOp matches enum ScatterOp in kernels/gomlx/shape.cu.
const DefaultBlockSize uint32 = 256
DefaultBlockSize is the default 1D CUDA thread block size for element-wise kernels.
const MaxBroadcastRank = 8
MaxBroadcastRank is the maximum tensor rank supported by inline value-passed BroadcastSpec. Must stay synchronized with MAX_BCAST_RANK in kernels/gomlx/*.cu.
const MaxSpatialRank = 6
MaxSpatialRank is the maximum spatial dimensionality supported by ConvGeneral kernels.
const QuantWarpBlockSize uint32 = 128
QuantWarpBlockSize is the block size (4 warps = 128 threads) used by warp-per-output quantized dense kernels.
const SDPABlockSize uint32 = 128
SDPABlockSize matches SDPA_BLOCK_SIZE in kernels/gomlx/fused.cu.
const SDPAMaxHeadDim = 1024
SDPAMaxHeadDim matches SDPA_MAX_HEAD_DIM in kernels/gomlx/fused.cu.
const TopKMaxKernelK = 64
TopKMaxKernelK matches TOPK_MAX_K in kernels/gomlx/fused.cu.
Variables ¶
This section is empty.
Functions ¶
func BinaryOpCode ¶
BinaryOpCode maps compute.OpType to kernels/gomlx/binary.cu enum BinaryOp.
func DTypeSuffix ¶
DTypeSuffix returns the kernel symbol suffix for a compute dtype (e.g., Float32 -> "f32").
func PredOpCode ¶
PredOpCode maps float predicate ops to kernels/gomlx/unary.cu enum PredOp.
func QuantDTypeCode ¶
QuantDTypeCode maps compute dtypes to the QDT_* constants in kernels/gomlx/quant.cu.
func RowMajorStrides ¶
func RowMajorStrides(dims []int) [MaxBroadcastRank]uint64
RowMajorStrides computes contiguous row-major element strides for dims.
Types ¶
type BroadcastSpec ¶
type BroadcastSpec struct {
Dims [MaxBroadcastRank]uint64
LHSStrides [MaxBroadcastRank]uint64
RHSStrides [MaxBroadcastRank]uint64
Rank uint32
// contains filtered or unexported fields
}
BroadcastSpec matches struct BroadcastSpec in kernels/gomlx/bootstrap.cu (200 bytes, 8-byte aligned).
func BuildBroadcastSpec ¶
func BuildBroadcastSpec(lhs, rhs, out shapes.Shape) (BroadcastSpec, bool, error)
BuildBroadcastSpec builds a BroadcastSpec for binary broadcasting between lhs and rhs into out. Returns needsBcast=false when lhs, rhs, and out have identical dimensions (contiguous fast path).
type ConvDirectSpec ¶
type ConvDirectSpec struct {
OutDims [MaxBroadcastRank]uint64
InStrides [MaxBroadcastRank]uint64
KStrides [MaxBroadcastRank]uint64
InSpDims [MaxSpatialRank]uint64
KSpDims [MaxSpatialRank]uint64
Strides [MaxSpatialRank]uint64
PadLow [MaxSpatialRank]int64
InDilations [MaxSpatialRank]uint64
KDilations [MaxSpatialRank]uint64
KSpSize uint64
KInChans uint64
OutBatchSize uint64
OutChansPerCGroup uint64
OutChansPerBGroup uint64
Rank uint32
SpatialRank uint32
InBatchAxis uint32
InChanAxis uint32
KInChanAxis uint32
KOutChanAxis uint32
OutBatchAxis uint32
OutChanAxis uint32
InSpAxes [MaxSpatialRank]uint32
KSpAxes [MaxSpatialRank]uint32
OutSpAxes [MaxSpatialRank]uint32
ChanGroups uint32
BatchGroups uint32
}
ConvDirectSpec matches struct ConvDirectSpec in kernels/gomlx/conv_pool_bn.cu.
type DynamicSliceSpec ¶
type DynamicSliceSpec struct {
OpDims [MaxBroadcastRank]uint64
OpStrides [MaxBroadcastRank]uint64
SliceDims [MaxBroadcastRank]uint64
IdxPtrs [MaxBroadcastRank]uint64
Rank uint32
IdxDT uint32
}
DynamicSliceSpec matches struct DynamicSliceSpec in kernels/gomlx/shape.cu.
type GatherSpec ¶
type GatherSpec struct {
OutDims [MaxBroadcastRank]uint64
OpDims [MaxBroadcastRank]uint64
OpStrides [MaxBroadcastRank]uint64
SliceSizes [MaxBroadcastRank]uint64
IdxBatchStrides [MaxBroadcastRank]uint64
IdxVecStride uint64
OutToOpOffsetAxis [MaxBroadcastRank]int32
StartIndexMap [MaxBroadcastRank]int32
OutRank uint32
OpRank uint32
IdxVecLen uint32
IdxDT uint32
}
GatherSpec matches struct GatherSpec in kernels/gomlx/shape.cu.
type Im2Col2DNHWCSpec ¶ added in v0.1.1
type Im2Col2DNHWCSpec struct {
Batch uint32
InH uint32
InW uint32
CIn uint32
OutH uint32
OutW uint32
KH uint32
KW uint32
StrideH uint32
StrideW uint32
PadH int32
PadW int32
InDilH uint32
InDilW uint32
KDilH uint32
KDilW uint32
}
Im2Col2DNHWCSpec matches struct Im2Col2DNHWCSpec in kernels/gomlx/conv_pool_bn.cu (56 bytes, 4-byte aligned).
type Im2ColSpec ¶
type Im2ColSpec struct {
OutSpatialDims [MaxSpatialRank]uint64
KSpatialDims [MaxSpatialRank]uint64
InSpatialDims [MaxSpatialRank]uint64
InSpatialStrides [MaxSpatialRank]uint64
Strides [MaxSpatialRank]uint64
PadLow [MaxSpatialRank]int64
InDilations [MaxSpatialRank]uint64
KDilations [MaxSpatialRank]uint64
InBatchStride uint64
InChanStride uint64
BatchOut uint64
OutSpSize uint64
KSpSize uint64
CInPerGroup uint64
SpatialRank uint32
ChanGroups uint32
}
Im2ColSpec matches struct Im2ColSpec in kernels/gomlx/conv_pool_bn.cu.
type InlineI64Spec ¶
type InlineI64Spec struct {
Vals [MaxBroadcastRank]int64
}
InlineI64Spec matches struct InlineI64Spec in kernels/gomlx/shape.cu.
type PadSpec ¶
type PadSpec struct {
OutDims [MaxBroadcastRank]uint64
InDims [MaxBroadcastRank]uint64
InStrides [MaxBroadcastRank]uint64
Start [MaxBroadcastRank]int64
InteriorStep [MaxBroadcastRank]uint64
Rank uint32
// contains filtered or unexported fields
}
PadSpec matches struct PadSpec in kernels/gomlx/shape.cu.
type QuantDenseSpec ¶
type QuantDenseSpec struct {
M uint64
K uint64
N uint64
WSRowBlk uint64
WSColBlk uint64
WSNumColBlks uint64
WZRowBlk uint64
WZColBlk uint64
WZNumColBlks uint64
XSColBlk uint64
XSNumColBlks uint64
XZColBlk uint64
XZNumColBlks uint64
OSColBlk uint64
OSNumColBlks uint64
OZColBlk uint64
OZNumColBlks uint64
WBytesPerRow uint64
XBytesPerRow uint64
Scheme uint32
GGMLWType uint32
GGMLXType uint32
VPB uint32
BPBW uint32
BPBX uint32
WeightLayout uint32
XDT uint32
WDT uint32
WSDT uint32
WZDT uint32
XSDT uint32
XZDT uint32
BiasDT uint32
OSDT uint32
OZDT uint32
OutDT uint32
ActType uint32
HasWZP uint32
XSKind uint32
XZKind uint32
HasBias uint32
BiasIsI32 uint32
HasOutQuant uint32
OSKind uint32
OZKind uint32
// contains filtered or unexported fields
}
QuantDenseSpec matches struct QuantDenseSpec in kernels/gomlx/quant.cu (264 bytes, 8-byte aligned).
type QuantGatherSpec ¶
type QuantGatherSpec struct {
NumRowsOut uint64
VocabSize uint64
K uint64
ScaleRowBlk uint64
ScaleColBlk uint64
ScaleNumColBlks uint64
ZPRowBlk uint64
ZPColBlk uint64
ZPNumColBlks uint64
Scheme uint32
XDT uint32
IdxDT uint32
ScaleDT uint32
ZPDT uint32
OutDT uint32
HasZP uint32
// contains filtered or unexported fields
}
QuantGatherSpec matches struct QuantGatherSpec in kernels/gomlx/quant.cu (104 bytes, 8-byte aligned).
type ReduceSpec ¶
type ReduceSpec struct {
OutDims [MaxBroadcastRank]uint64
OutInStrides [MaxBroadcastRank]uint64
RedDims [MaxBroadcastRank]uint64
RedInStrides [MaxBroadcastRank]uint64
RedSize uint64
OutRank uint32
RedRank uint32
}
ReduceSpec matches struct ReduceSpec in kernels/gomlx/reduce.cu.
type ReduceWindowSpec ¶
type ReduceWindowSpec struct {
OutDims [MaxBroadcastRank]uint64
InDims [MaxBroadcastRank]uint64
InStrides [MaxBroadcastRank]uint64
WinDims [MaxBroadcastRank]uint64
Strides [MaxBroadcastRank]uint64
BaseDilations [MaxBroadcastRank]uint64
WinDilations [MaxBroadcastRank]uint64
PadLow [MaxBroadcastRank]int64
WinSize uint64
Rank uint32
Op uint32
}
ReduceWindowSpec matches struct ReduceWindowSpec in kernels/gomlx/conv_pool_bn.cu.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry lazily loads embedded PTX modules into a single CUDA DeviceContext and caches CUmodule and CUfunction handles for fast, lock-free lookup on the hot path.
func NewRegistry ¶
func NewRegistry(devCtx *driver.DeviceContext) *Registry
NewRegistry creates a new PTX module/function cache bound to devCtx.
func (*Registry) GetFunctionInContext ¶
GetFunctionInContext returns the cached CUfunction for (moduleName, kernelName), lazily loading the module if needed. Caller MUST already be executing inside devCtx.WithContext.
func (*Registry) PreloadModulesInContext ¶ added in v0.1.1
PreloadModulesInContext ensures all specified embedded PTX modules are loaded into the CUDA context (no-op for already-loaded modules). Called before cuStreamBeginCapture so cuModuleLoadDataEx never runs during stream capture.
type RoPESpec ¶ added in v0.1.1
type RoPESpec struct {
OuterDims [MaxBroadcastRank]uint64
CosRowStrides [MaxBroadcastRank]uint64
TotalRows uint64
HeadDim uint64
DimStart uint64
RotaryHalfDim uint64
OuterRank uint32
Interleaved uint32
Inverse uint32
CosIsF32 uint32
}
RoPESpec matches struct RoPESpec in kernels/gomlx/fused.cu (176 bytes, 8-byte aligned).
type SDPASpec ¶
type SDPASpec struct {
BatchSize uint64
NumHeads uint64
NumKVHeads uint64
SeqLen uint64
KVLen uint64
HeadDim uint64
QBatchStride uint64
QHeadStride uint64
QSeqStride uint64
KVBatchStride uint64
KVHeadStride uint64
KVSeqStride uint64
MaskBatchStride uint64
MaskHeadStride uint64
MaskSeqStride uint64
MaskKVStride uint64
BiasBatchStride uint64
BiasHeadStride uint64
BiasSeqStride uint64
BiasKVStride uint64
Scale float64
Causal uint32
MaskMode uint32 // 0=none, 1=bool, 2=additive
HasBias uint32
HasSeqLens uint32
}
SDPASpec matches struct SDPASpec in kernels/gomlx/fused.cu (184 bytes, 8-byte aligned).
type ScatterSpec ¶
type ScatterSpec struct {
UpdDims [MaxBroadcastRank]uint64
OpDims [MaxBroadcastRank]uint64
OpStrides [MaxBroadcastRank]uint64
IdxBatchStrides [MaxBroadcastRank]uint64
IdxVecStride uint64
UpdToOpWindowAxis [MaxBroadcastRank]int32
ScatterToOpAxis [MaxBroadcastRank]int32
UpdRank uint32
OpRank uint32
IdxVecLen uint32
IdxDT uint32
}
ScatterSpec matches struct ScatterSpec in kernels/gomlx/shape.cu.
type SelectAndScatterSpec ¶
type SelectAndScatterSpec struct {
SrcDims [MaxBroadcastRank]uint64
OpDims [MaxBroadcastRank]uint64
OpStrides [MaxBroadcastRank]uint64
WinDims [MaxBroadcastRank]uint64
Strides [MaxBroadcastRank]uint64
PadLow [MaxBroadcastRank]int64
WinSize uint64
Rank uint32
IsMin uint32
}
SelectAndScatterSpec matches struct SelectAndScatterSpec in kernels/gomlx/conv_pool_bn.cu.
type SplitMultiSpec ¶ added in v0.1.1
type SplitMultiSpec struct {
OutPtrs [4]uint64
BiasPtrs [4]uint64
Offsets [4]uint64
Dims [4]uint64
NumRows uint64
TotalOut uint64
Count uint32
// contains filtered or unexported fields
}
SplitMultiSpec matches struct SplitMultiSpec in kernels/gomlx/fused.cu (152 bytes, 8-byte aligned).
type StridedCopySpec ¶
type StridedCopySpec struct {
Dims [MaxBroadcastRank]uint64
Strides [MaxBroadcastRank]int64
BaseOffset int64
Rank uint32
// contains filtered or unexported fields
}
StridedCopySpec matches struct StridedCopySpec in kernels/gomlx/shape.cu.
type TernaryBroadcastSpec ¶
type TernaryBroadcastSpec struct {
Dims [MaxBroadcastRank]uint64
S0 [MaxBroadcastRank]uint64
S1 [MaxBroadcastRank]uint64
S2 [MaxBroadcastRank]uint64
Rank uint32
// contains filtered or unexported fields
}
TernaryBroadcastSpec matches struct TernaryBroadcastSpec in kernels/gomlx/common.cuh (264 bytes).
func BuildTernaryBroadcastSpec ¶
func BuildTernaryBroadcastSpec(s0, s1, s2, out shapes.Shape) (TernaryBroadcastSpec, bool, error)
BuildTernaryBroadcastSpec constructs a 3-operand broadcast spec for Where / Clamp. Returns needsBcast=false if all three inputs already match out's dimensions.