Documentation
¶
Index ¶
- Constants
- Variables
- func Apply[T gotype.Supported](backend *gobackend.Backend, act compute.ActivationType, data []T)
- func Execute[T gotype.Supported](backend *gobackend.Backend, act compute.ActivationType, in, out []T)
- func ExecuteSwiGLU[T gotype.Supported](backend *gobackend.Backend, in, out []T, numRows, hiddenDim int)
- func ExecuteSwiGLUVJP[T gotype.Supported](backend *gobackend.Backend, x, dOutput, dx []T, numRows, hiddenDim int)
- func ExecuteVJP[T gotype.Supported](backend *gobackend.Backend, act compute.ActivationType, y, x, dOutput, dx []T)
- func ExecuteVJPFromOutput[T gotype.Supported](backend *gobackend.Backend, act compute.ActivationType, y, dOutput, dz []T) error
- func GeluApproxNoSIMD[T float32 | float64](in, out []T)
- func GetKernelWithMetadata[T gotype.Supported](act compute.ActivationType) (KernelFn[T], *KernelMetadata)
- func GetSwiGLUVJPWithMetadata[T gotype.Supported]() (SwiGLUVJPFn[T], *KernelMetadata)
- func GetSwiGLUWithMetadata[T gotype.Supported]() (SwiGLUFn[T], *KernelMetadata)
- func GetVJPKernelWithMetadata[T gotype.Supported](act compute.ActivationType) (VJPKernelFn[T], *KernelMetadata)
- func GetWithMetadata[T gotype.Supported](act compute.ActivationType) (InPlaceFn[T], *KernelMetadata)
- func HardSigmoidNoSIMD[T float32 | float64](in, out []T)
- func HardSwishNoSIMD[T float32 | float64](in, out []T)
- func LeakyReluNoSIMD[T float32 | float64](in, out []T)
- func Register[T gotype.Supported](name string, act compute.ActivationType, fn InPlaceFn[T], ...)
- func RegisterKernel[T gotype.Supported](name string, act compute.ActivationType, fn KernelFn[T], ...)
- func RegisterSwiGLU[T gotype.Supported](name string, fn SwiGLUFn[T], priority gobackend.RegisterPriority, ...)
- func RegisterSwiGLUVJP[T gotype.Supported](name string, fn SwiGLUVJPFn[T], priority gobackend.RegisterPriority, ...)
- func RegisterVJPKernel[T gotype.Supported](name string, act compute.ActivationType, fn VJPKernelFn[T], ...)
- func ReluBF16NoSIMD(in, out []bfloat16.BFloat16)
- func ReluF16NoSIMD(in, out []float16.Float16)
- func ReluNoSIMD[T float32 | float64](in, out []T)
- func SeluNoSIMD[T float32 | float64](in, out []T)
- func SigmoidNoSIMD[T float32 | float64](in, out []T)
- func SiluBF16NoSIMD(in, out []bfloat16.BFloat16)
- func SiluF16NoSIMD(in, out []float16.Float16)
- func SiluNoSIMD[T float32 | float64](in, out []T)
- func TanhNoSIMD[T float32 | float64](in, out []T)
- type InPlaceFn
- type KernelFn
- type KernelMetadata
- type SwiGLUFn
- type SwiGLUVJPFn
- type VJPKernelFn
Constants ¶
const DefaultMinParallelChunk = 32768
DefaultMinParallelChunk is the default minimum number of elements per parallel worker chunk.
const PriorityNoSIMD = gobackend.PriorityGeneric
Variables ¶
var ( // NoSIMDSimpleMetadata holds metadata for lightweight element-wise non-SIMD kernels // (e.g., Relu, LeakyRelu, HardSigmoid, HardSwish). NoSIMDSimpleMetadata = KernelMetadata{MinParallelChunk: 8192} // NoSIMDTranscendentalMetadata holds metadata for transcendental non-SIMD kernels // (e.g., Gelu, Sigmoid, Tanh, Silu, Selu, SwiGLU) that call math.Erf / math.Exp / math.Tanh. NoSIMDTranscendentalMetadata = KernelMetadata{MinParallelChunk: 2048} )
var DefaultKernelMetadata = KernelMetadata{ MinParallelChunk: DefaultMinParallelChunk, }
DefaultKernelMetadata is the default metadata used when nil is passed to Register*.
Functions ¶
func Apply ¶
Apply applies the given activation function in-place across the slice. If the slice is large and workers are available, work is parallelized in chunks.
func Execute ¶
func Execute[T gotype.Supported](backend *gobackend.Backend, act compute.ActivationType, in, out []T)
Execute applies the given activation function from in to out (in and out can be the same slice).
func ExecuteSwiGLU ¶
func ExecuteSwiGLU[T gotype.Supported](backend *gobackend.Backend, in, out []T, numRows, hiddenDim int)
ExecuteSwiGLU applies SwiGLU activation across numRows rows of width 2*hiddenDim to out of width hiddenDim.
func ExecuteSwiGLUVJP ¶
func ExecuteSwiGLUVJP[T gotype.Supported](backend *gobackend.Backend, x, dOutput, dx []T, numRows, hiddenDim int)
ExecuteSwiGLUVJP applies SwiGLU VJP across numRows rows.
func ExecuteVJP ¶
func ExecuteVJP[T gotype.Supported](backend *gobackend.Backend, act compute.ActivationType, y, x, dOutput, dx []T)
ExecuteVJP applies the VJP of the given activation function:
dx = dOutput * f'(y or x)
Note: For activations where act.VJPRequiresInput() == false (e.g. Relu, Sigmoid, HardSigmoid, LeakyRelu, Selu, Tanh, None), the parameter x is optional (can be nil or empty), and the calculation will use only y.
func ExecuteVJPFromOutput ¶
func ExecuteVJPFromOutput[T gotype.Supported](backend *gobackend.Backend, act compute.ActivationType, y, dOutput, dz []T) error
ExecuteVJPFromOutput applies the VJP of an activation that only depends on the forward output y:
dz = dOutput * f'(y)
It requires that act.VJPRequiresInput() == false. dz and dOutput can be the same slice (in-place).
func GeluApproxNoSIMD ¶
func GetKernelWithMetadata ¶ added in v0.1.17
func GetKernelWithMetadata[T gotype.Supported](act compute.ActivationType) (KernelFn[T], *KernelMetadata)
GetKernelWithMetadata returns the registered kernel function and its metadata.
func GetSwiGLUVJPWithMetadata ¶ added in v0.1.17
func GetSwiGLUVJPWithMetadata[T gotype.Supported]() (SwiGLUVJPFn[T], *KernelMetadata)
GetSwiGLUVJPWithMetadata returns the registered SwiGLU VJP function and its metadata for data type T.
func GetSwiGLUWithMetadata ¶ added in v0.1.17
func GetSwiGLUWithMetadata[T gotype.Supported]() (SwiGLUFn[T], *KernelMetadata)
GetSwiGLUWithMetadata returns the registered SwiGLU function and its metadata for data type T.
func GetVJPKernelWithMetadata ¶ added in v0.1.17
func GetVJPKernelWithMetadata[T gotype.Supported](act compute.ActivationType) (VJPKernelFn[T], *KernelMetadata)
GetVJPKernelWithMetadata returns the registered VJP kernel function and its metadata.
func GetWithMetadata ¶ added in v0.1.17
func GetWithMetadata[T gotype.Supported](act compute.ActivationType) (InPlaceFn[T], *KernelMetadata)
GetWithMetadata returns the registered in-place activation function and its metadata. Returns (nil, nil) if activation is ActivationNone or if no implementation is registered.
func HardSigmoidNoSIMD ¶
func HardSwishNoSIMD ¶
func LeakyReluNoSIMD ¶
func Register ¶
func Register[T gotype.Supported](name string, act compute.ActivationType, fn InPlaceFn[T], priority gobackend.RegisterPriority, meta *KernelMetadata)
Register registers an in-place activation function for a specific activation type and data type. If an implementation is already registered with a higher priority, this call is ignored.
func RegisterKernel ¶
func RegisterKernel[T gotype.Supported](name string, act compute.ActivationType, fn KernelFn[T], priority gobackend.RegisterPriority, meta *KernelMetadata)
RegisterKernel registers a kernel function (supporting both in-place and out-of-place).
func RegisterSwiGLU ¶
func RegisterSwiGLU[T gotype.Supported](name string, fn SwiGLUFn[T], priority gobackend.RegisterPriority, meta *KernelMetadata)
RegisterSwiGLU registers a SwiGLU kernel for a specific data type.
func RegisterSwiGLUVJP ¶
func RegisterSwiGLUVJP[T gotype.Supported](name string, fn SwiGLUVJPFn[T], priority gobackend.RegisterPriority, meta *KernelMetadata)
RegisterSwiGLUVJP registers a SwiGLU VJP kernel for a specific data type.
func RegisterVJPKernel ¶
func RegisterVJPKernel[T gotype.Supported](name string, act compute.ActivationType, fn VJPKernelFn[T], priority gobackend.RegisterPriority, meta *KernelMetadata)
RegisterVJPKernel registers a VJP kernel function for a specific activation type and data type.
func ReluBF16NoSIMD ¶
func ReluF16NoSIMD ¶
func ReluNoSIMD ¶
func SeluNoSIMD ¶
func SigmoidNoSIMD ¶
func SiluBF16NoSIMD ¶
func SiluF16NoSIMD ¶
func SiluNoSIMD ¶
func TanhNoSIMD ¶
Types ¶
type InPlaceFn ¶
type InPlaceFn[T any] func(data []T)
InPlaceFn applies an activation function in-place to a contiguous slice of elements.
type KernelFn ¶
type KernelFn[T any] func(in, out []T)
KernelFn applies an activation function from in to out (in and out can be the same slice).
type KernelMetadata ¶ added in v0.1.17
type KernelMetadata struct {
// MinParallelChunk is the minimum number of elements per parallel worker chunk.
// If <= 0, DefaultMinParallelChunk is used.
MinParallelChunk int
}
KernelMetadata holds properties and platform-tunable parameters for a registered activation kernel. Because registrations store a *KernelMetadata pointer, package-level metadata structs can be initialized or adjusted at runtime for the target platform without re-registering kernels.
func (*KernelMetadata) EffectiveMinParallelChunk ¶ added in v0.1.17
func (m *KernelMetadata) EffectiveMinParallelChunk() int
EffectiveMinParallelChunk returns MinParallelChunk if positive, or DefaultMinParallelChunk.
type SwiGLUFn ¶
SwiGLUFn applies SwiGLU activation: out[m*H + j] = silu(gate[m*2H + j]) * val[m*2H + H + j].
type SwiGLUVJPFn ¶
SwiGLUVJPFn applies SwiGLU VJP: x: input of shape [numRows, 2*hiddenDim] dOutput: adjoint gradient of shape [numRows, hiddenDim] dx: resulting gradient of shape [numRows, 2*hiddenDim]
func GetSwiGLUVJP ¶
func GetSwiGLUVJP[T gotype.Supported]() SwiGLUVJPFn[T]
GetSwiGLUVJP returns the registered SwiGLU VJP function for data type T.
func MakeBF16SwiGLUVJPFromF32 ¶
func MakeBF16SwiGLUVJPFromF32(f32SwiGLUVJP SwiGLUVJPFn[float32]) SwiGLUVJPFn[bfloat16.BFloat16]
MakeBF16SwiGLUVJPFromF32 wraps a float32 SwiGLU VJP kernel for BFloat16.
func MakeF16SwiGLUVJPFromF32 ¶
func MakeF16SwiGLUVJPFromF32(f32SwiGLUVJP SwiGLUVJPFn[float32]) SwiGLUVJPFn[float16.Float16]
MakeF16SwiGLUVJPFromF32 wraps a float32 SwiGLU VJP kernel for Float16.
type VJPKernelFn ¶
type VJPKernelFn[T any] func(y, x, dOutput, dx []T)
VJPKernelFn applies the VJP of an activation: dx = dOutput * f'(y or x). Note: y and/or x may be empty/nil depending on whether the activation requires x.
func GetVJPKernel ¶
func GetVJPKernel[T gotype.Supported](act compute.ActivationType) VJPKernelFn[T]
GetVJPKernel returns the registered VJP kernel function for the given activation type and data type T.
func MakeBF16VJPKernelFromF32 ¶
func MakeBF16VJPKernelFromF32(f32Kernel VJPKernelFn[float32]) VJPKernelFn[bfloat16.BFloat16]
MakeBF16VJPKernelFromF32 wraps a float32 VJP kernel into a BFloat16 VJP kernel using chunked conversion.
func MakeF16VJPKernelFromF32 ¶
func MakeF16VJPKernelFromF32(f32Kernel VJPKernelFn[float32]) VJPKernelFn[float16.Float16]
MakeF16VJPKernelFromF32 wraps a float32 VJP kernel into a Float16 VJP kernel using chunked conversion.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package avx2 provides AVX2 SIMD implementations for activations.
|
Package avx2 provides AVX2 SIMD implementations for activations. |
|
Package avx512 provides AVX-512 SIMD implementations for activations.
|
Package avx512 provides AVX-512 SIMD implementations for activations. |