const BACKEND_METAL
pub const BACKEND_METAL = 1Purpose
Constant BACKEND_METAL, defining protocol or algorithm parameters.
#github.com/xulang-org/packages/gpuCross-platform unified GPU compute facade over Metal (macOS), CUDA (NVIDIA Linux/Windows), Vulkan (cross-platform SPIR-V compute), and pure-Xu CPU reference fallback.
github.com/xulang-org/packages · 1.17.2 · Install and use
const BACKEND_METALpub const BACKEND_METAL = 1Constant BACKEND_METAL, defining protocol or algorithm parameters.
const BACKEND_CUDApub const BACKEND_CUDA = 2Constant BACKEND_CUDA, defining protocol or algorithm parameters.
const BACKEND_VULKANpub const BACKEND_VULKAN = 3Constant BACKEND_VULKAN, defining protocol or algorithm parameters.
const BACKEND_CPUpub const BACKEND_CPU = 4Constant BACKEND_CPU, defining protocol or algorithm parameters.
struct Devicepub struct Device {
pub backend int
pub dev_name string
pub closed bool
}Structure encapsulating backend, dev_name, closed.
backend intdev_name stringclosed boolstruct F32Matrixpub struct F32Matrix {
pub backend int
pub n_rows int
pub n_cols int
pub closed bool
}Structure encapsulating backend, n_rows, n_cols, closed.
backend intn_rows intn_cols intclosed boolstruct Q4Matrixpub struct Q4Matrix {
pub backend int
pub n_rows int
pub n_cols int
pub closed bool
}Structure encapsulating backend, n_rows, n_cols, closed.
backend intn_rows intn_cols intclosed boolstruct Q8Matrixpub struct Q8Matrix {
pub backend int
pub n_rows int
pub n_cols int
pub closed bool
}Structure encapsulating backend, n_rows, n_cols, closed.
backend intn_rows intn_cols intclosed boolstruct Q4KMatrixpub struct Q4KMatrix {
pub backend int
pub n_rows int
pub n_cols int
pub closed bool
}Structure encapsulating backend, n_rows, n_cols, closed.
backend intn_rows intn_cols intclosed boolstruct Q5KMatrixpub struct Q5KMatrix {
pub backend int
pub n_rows int
pub n_cols int
pub closed bool
}Structure encapsulating backend, n_rows, n_cols, closed.
backend intn_rows intn_cols intclosed boolstruct Q6KMatrixpub struct Q6KMatrix {
pub backend int
pub n_rows int
pub n_cols int
pub closed bool
}Structure encapsulating backend, n_rows, n_cols, closed.
backend intn_rows intn_cols intclosed booldetect_backendspub fn detect_backends() []stringDetect backends.
No arguments are required.
[]string — slice result
backend_namepub fn backend_name(b int) stringBackend name.
b intstring — result string
open_autopub fn open_auto() DeviceOpen auto. Throws on failure; handle the error or propagate it to the caller.
No arguments are required.
Device — a value of this type
open_backendpub fn open_backend(name string) DeviceOpen backend. Throws on failure; handle the error or propagate it to the caller.
name stringDevice — a value of this type
(&Device) namepub fn (d &Device) name() stringExecute name on &Device.
d &DeviceDevice instance used by this call (borrow).string — result string
(&Device) backend_idpub fn (d &Device) backend_id() intOperation on &Device: backend id.
d &DeviceDevice instance used by this call (borrow).int — a value of this type
($&Device) closepub fn (d $&Device) close() intOperation on $&Device: close the resource.
d $&DeviceDevice instance used by this call (exclusive borrow).int — a value of this type
(&Device) matrix_f32pub fn (d &Device) matrix_f32(rows int, columns int) F32MatrixOperation on &Device: matrix f32. Throws on failure; handle the error or propagate it to the caller.
d &DeviceDevice instance used by this call (borrow).rows intcolumns intF32Matrix — a value of this type
(&F32Matrix) rowspub fn (m &F32Matrix) rows() intExecute rows on &F32Matrix.
m &F32MatrixF32Matrix instance used by this call (borrow).int — a value of this type
(&F32Matrix) columnspub fn (m &F32Matrix) columns() intExecute columns on &F32Matrix.
m &F32MatrixF32Matrix instance used by this call (borrow).int — a value of this type
($&F32Matrix) write_bitspub fn (m $&F32Matrix) write_bits(values &[]int) intOperation on $&F32Matrix: write bits. Throws on failure; handle the error or propagate it to the caller.
m $&F32MatrixF32Matrix instance used by this call (exclusive borrow).values &[]intint — a value of this type
($&F32Matrix) write_f32pub fn (m $&F32Matrix) write_f32(values &[]f32) intOperation on $&F32Matrix: write f32. Throws on failure; handle the error or propagate it to the caller.
m $&F32MatrixF32Matrix instance used by this call (exclusive borrow).values &[]f32int — a value of this type
(&F32Matrix) copy_bitspub fn (m &F32Matrix) copy_bits(out $&[]int) intOperation on &F32Matrix: copy bits. Throws on failure; handle the error or propagate it to the caller.
m &F32MatrixF32Matrix instance used by this call (borrow).out $&[]intint — a value of this type
(&F32Matrix) bitspub fn (m &F32Matrix) bits() []intExecute bits on &F32Matrix. Throws on failure; handle the error or propagate it to the caller.
m &F32MatrixF32Matrix instance used by this call (borrow).[]int — slice result
(&F32Matrix) to_f32pub fn (m &F32Matrix) to_f32() []f32Operation on &F32Matrix: convert to f32. Throws on failure; handle the error or propagate it to the caller.
m &F32MatrixF32Matrix instance used by this call (borrow).[]f32 — slice result
($&F32Matrix) closepub fn (m $&F32Matrix) close() intOperation on $&F32Matrix: close the resource.
m $&F32MatrixF32Matrix instance used by this call (exclusive borrow).int — a value of this type
(&Device) matrix_q4_0pub fn (d &Device) matrix_q4_0(rows int, columns int) Q4MatrixOperation on &Device: matrix q4 0. Throws on failure; handle the error or propagate it to the caller.
d &DeviceDevice instance used by this call (borrow).rows intcolumns intQ4Matrix — a value of this type
(&Q4Matrix) rowspub fn (m &Q4Matrix) rows() intExecute rows on &Q4Matrix.
m &Q4MatrixQ4Matrix instance used by this call (borrow).int — a value of this type
(&Q4Matrix) columnspub fn (m &Q4Matrix) columns() intExecute columns on &Q4Matrix.
m &Q4MatrixQ4Matrix instance used by this call (borrow).int — a value of this type
($&Q4Matrix) write_bytespub fn (m $&Q4Matrix) write_bytes(bytes &string) intOperation on $&Q4Matrix: write bytes. Throws on failure; handle the error or propagate it to the caller.
m $&Q4MatrixQ4Matrix instance used by this call (exclusive borrow).bytes &stringint — a value of this type
($&Q4Matrix) closepub fn (m $&Q4Matrix) close() intOperation on $&Q4Matrix: close the resource.
m $&Q4MatrixQ4Matrix instance used by this call (exclusive borrow).int — a value of this type
(&Device) matrix_q8_0pub fn (d &Device) matrix_q8_0(rows int, columns int) Q8MatrixOperation on &Device: matrix q8 0. Throws on failure; handle the error or propagate it to the caller.
d &DeviceDevice instance used by this call (borrow).rows intcolumns intQ8Matrix — a value of this type
(&Q8Matrix) rowspub fn (m &Q8Matrix) rows() intExecute rows on &Q8Matrix.
m &Q8MatrixQ8Matrix instance used by this call (borrow).int — a value of this type
(&Q8Matrix) columnspub fn (m &Q8Matrix) columns() intExecute columns on &Q8Matrix.
m &Q8MatrixQ8Matrix instance used by this call (borrow).int — a value of this type
($&Q8Matrix) write_bytespub fn (m $&Q8Matrix) write_bytes(bytes &string) intOperation on $&Q8Matrix: write bytes. Throws on failure; handle the error or propagate it to the caller.
m $&Q8MatrixQ8Matrix instance used by this call (exclusive borrow).bytes &stringint — a value of this type
($&Q8Matrix) closepub fn (m $&Q8Matrix) close() intOperation on $&Q8Matrix: close the resource.
m $&Q8MatrixQ8Matrix instance used by this call (exclusive borrow).int — a value of this type
(&Device) matrix_q4_kpub fn (d &Device) matrix_q4_k(rows int, columns int) Q4KMatrixOperation on &Device: matrix q4 k. Throws on failure; handle the error or propagate it to the caller.
d &DeviceDevice instance used by this call (borrow).rows intcolumns intQ4KMatrix — a value of this type
(&Q4KMatrix) rowspub fn (m &Q4KMatrix) rows() intExecute rows on &Q4KMatrix.
m &Q4KMatrixQ4KMatrix instance used by this call (borrow).int — a value of this type
(&Q4KMatrix) columnspub fn (m &Q4KMatrix) columns() intExecute columns on &Q4KMatrix.
m &Q4KMatrixQ4KMatrix instance used by this call (borrow).int — a value of this type
($&Q4KMatrix) write_bytespub fn (m $&Q4KMatrix) write_bytes(bytes &string) intOperation on $&Q4KMatrix: write bytes. Throws on failure; handle the error or propagate it to the caller.
m $&Q4KMatrixQ4KMatrix instance used by this call (exclusive borrow).bytes &stringint — a value of this type
($&Q4KMatrix) closepub fn (m $&Q4KMatrix) close() intOperation on $&Q4KMatrix: close the resource.
m $&Q4KMatrixQ4KMatrix instance used by this call (exclusive borrow).int — a value of this type
(&Device) matrix_q5_kpub fn (d &Device) matrix_q5_k(rows int, columns int) Q5KMatrixOperation on &Device: matrix q5 k. Throws on failure; handle the error or propagate it to the caller.
d &DeviceDevice instance used by this call (borrow).rows intcolumns intQ5KMatrix — a value of this type
(&Q5KMatrix) rowspub fn (m &Q5KMatrix) rows() intExecute rows on &Q5KMatrix.
m &Q5KMatrixQ5KMatrix instance used by this call (borrow).int — a value of this type
(&Q5KMatrix) columnspub fn (m &Q5KMatrix) columns() intExecute columns on &Q5KMatrix.
m &Q5KMatrixQ5KMatrix instance used by this call (borrow).int — a value of this type
($&Q5KMatrix) write_bytespub fn (m $&Q5KMatrix) write_bytes(bytes &string) intOperation on $&Q5KMatrix: write bytes. Throws on failure; handle the error or propagate it to the caller.
m $&Q5KMatrixQ5KMatrix instance used by this call (exclusive borrow).bytes &stringint — a value of this type
($&Q5KMatrix) closepub fn (m $&Q5KMatrix) close() intOperation on $&Q5KMatrix: close the resource.
m $&Q5KMatrixQ5KMatrix instance used by this call (exclusive borrow).int — a value of this type
(&Device) matrix_q6_kpub fn (d &Device) matrix_q6_k(rows int, columns int) Q6KMatrixOperation on &Device: matrix q6 k. Throws on failure; handle the error or propagate it to the caller.
d &DeviceDevice instance used by this call (borrow).rows intcolumns intQ6KMatrix — a value of this type
(&Q6KMatrix) rowspub fn (m &Q6KMatrix) rows() intExecute rows on &Q6KMatrix.
m &Q6KMatrixQ6KMatrix instance used by this call (borrow).int — a value of this type
(&Q6KMatrix) columnspub fn (m &Q6KMatrix) columns() intExecute columns on &Q6KMatrix.
m &Q6KMatrixQ6KMatrix instance used by this call (borrow).int — a value of this type
($&Q6KMatrix) write_bytespub fn (m $&Q6KMatrix) write_bytes(bytes &string) intOperation on $&Q6KMatrix: write bytes. Throws on failure; handle the error or propagate it to the caller.
m $&Q6KMatrixQ6KMatrix instance used by this call (exclusive borrow).bytes &stringint — a value of this type
($&Q6KMatrix) closepub fn (m $&Q6KMatrix) close() intOperation on $&Q6KMatrix: close the resource.
m $&Q6KMatrixQ6KMatrix instance used by this call (exclusive borrow).int — a value of this type
gemm_f32pub fn gemm_f32(dev $&Device, dst $&F32Matrix, a &F32Matrix, b &F32Matrix) intGemm f32. Throws on failure; handle the error or propagate it to the caller.
dev $&Devicedst $&F32Matrixa &F32Matrixb &F32Matrixint — a value of this type
gemm_f32_ntpub fn gemm_f32_nt(dev $&Device, dst $&F32Matrix, a &F32Matrix, b &F32Matrix) intGemm f32 nt. Throws on failure; handle the error or propagate it to the caller.
dev $&Devicedst $&F32Matrixa &F32Matrixb &F32Matrixint — a value of this type
gemm_f32_tnpub fn gemm_f32_tn(dev $&Device, dst $&F32Matrix, a &F32Matrix, b &F32Matrix) intGemm f32 tn. Throws on failure; handle the error or propagate it to the caller.
dev $&Devicedst $&F32Matrixa &F32Matrixb &F32Matrixint — a value of this type
add_f32pub fn add_f32(dev $&Device, dst $&F32Matrix, a &F32Matrix, b &F32Matrix) intAdd f32. Throws on failure; handle the error or propagate it to the caller.
dev $&Devicedst $&F32Matrixa &F32Matrixb &F32Matrixint — a value of this type
mul_f32pub fn mul_f32(dev $&Device, dst $&F32Matrix, a &F32Matrix, b &F32Matrix) intMul f32. Throws on failure; handle the error or propagate it to the caller.
dev $&Devicedst $&F32Matrixa &F32Matrixb &F32Matrixint — a value of this type
scale_f32pub fn scale_f32(dev $&Device, dst $&F32Matrix, x &F32Matrix, alpha f64) intScale f32. Throws on failure; handle the error or propagate it to the caller.
dev $&Devicedst $&F32Matrixx &F32Matrixalpha f64int — a value of this type
rmsnorm_f32pub fn rmsnorm_f32(dev $&Device, dst $&F32Matrix, x &F32Matrix, weight &F32Matrix, eps f64) intRmsnorm f32. Throws on failure; handle the error or propagate it to the caller.
dev $&Devicedst $&F32Matrixx &F32Matrixweight &F32Matrixeps f64int — a value of this type
softmax_f32pub fn softmax_f32(dev $&Device, dst $&F32Matrix, x &F32Matrix) intSoftmax f32. Throws on failure; handle the error or propagate it to the caller.
dev $&Devicedst $&F32Matrixx &F32Matrixint — a value of this type
swiglu_f32pub fn swiglu_f32(dev $&Device, dst $&F32Matrix, gate &F32Matrix, up &F32Matrix) intSwiglu f32. Throws on failure; handle the error or propagate it to the caller.
dev $&Devicedst $&F32Matrixgate &F32Matrixup &F32Matrixint — a value of this type
rope_f32pub fn rope_f32(dev $&Device, dst $&F32Matrix, x &F32Matrix, pos_offset int, head_dim int, theta f64) intRope f32. Throws on failure; handle the error or propagate it to the caller.
dev $&Devicedst $&F32Matrixx &F32Matrixpos_offset inthead_dim inttheta f64int — a value of this type
gemv_q4_0_f32pub fn gemv_q4_0_f32(dev $&Device, dst $&F32Matrix, x &F32Matrix, w &Q4Matrix) intGemv q4 0 f32. Throws on failure; handle the error or propagate it to the caller.
dev $&Devicedst $&F32Matrixx &F32Matrixw &Q4Matrixint — a value of this type
gemv_q8_0_f32pub fn gemv_q8_0_f32(dev $&Device, dst $&F32Matrix, x &F32Matrix, w &Q8Matrix) intGemv q8 0 f32. Throws on failure; handle the error or propagate it to the caller.
dev $&Devicedst $&F32Matrixx &F32Matrixw &Q8Matrixint — a value of this type
gemv_q4_k_f32pub fn gemv_q4_k_f32(dev $&Device, dst $&F32Matrix, x &F32Matrix, w &Q4KMatrix) intGemv q4 k f32. Throws on failure; handle the error or propagate it to the caller.
dev $&Devicedst $&F32Matrixx &F32Matrixw &Q4KMatrixint — a value of this type
gemv_q5_k_f32pub fn gemv_q5_k_f32(dev $&Device, dst $&F32Matrix, x &F32Matrix, w &Q5KMatrix) intGemv q5 k f32. Throws on failure; handle the error or propagate it to the caller.
dev $&Devicedst $&F32Matrixx &F32Matrixw &Q5KMatrixint — a value of this type
gemv_q6_k_f32pub fn gemv_q6_k_f32(dev $&Device, dst $&F32Matrix, x &F32Matrix, w &Q6KMatrix) intGemv q6 k f32. Throws on failure; handle the error or propagate it to the caller.
dev $&Devicedst $&F32Matrixx &F32Matrixw &Q6KMatrixint — a value of this type
f16_bits_to_f64pub fn f16_bits_to_f64(bits int) f64F16 bits to f64.
bits intf64 — a value of this type
cpu_gemm_f32pub fn cpu_gemm_f32(dst $&[]int, a &[]int, b &[]int, m int, n int, k int)Cpu gemm f32.
dst $&[]inta &[]intb &[]intm intn intk intThis call does not return a value.
cpu_gemm_f32_ntpub fn cpu_gemm_f32_nt(dst $&[]int, a &[]int, b &[]int, m int, n int, k int)Cpu gemm f32 nt.
dst $&[]inta &[]intb &[]intm intn intk intThis call does not return a value.
cpu_gemm_f32_tnpub fn cpu_gemm_f32_tn(dst $&[]int, a &[]int, b &[]int, m int, n int, k int)Cpu gemm f32 tn.
dst $&[]inta &[]intb &[]intm intn intk intThis call does not return a value.
cpu_add_f32pub fn cpu_add_f32(dst $&[]int, a &[]int, b &[]int)Cpu add f32.
dst $&[]inta &[]intb &[]intThis call does not return a value.
cpu_mul_f32pub fn cpu_mul_f32(dst $&[]int, a &[]int, b &[]int)Cpu mul f32.
dst $&[]inta &[]intb &[]intThis call does not return a value.
cpu_scale_f32pub fn cpu_scale_f32(dst $&[]int, x &[]int, alpha f64)Cpu scale f32.
dst $&[]intx &[]intalpha f64This call does not return a value.
cpu_rmsnorm_f32pub fn cpu_rmsnorm_f32(dst $&[]int, x &[]int, w &[]int, rows int, cols int, eps f64)Cpu rmsnorm f32.
dst $&[]intx &[]intw &[]introws intcols inteps f64This call does not return a value.
cpu_softmax_f32pub fn cpu_softmax_f32(dst $&[]int, x &[]int, rows int, cols int)Cpu softmax f32.
dst $&[]intx &[]introws intcols intThis call does not return a value.
cpu_swiglu_f32pub fn cpu_swiglu_f32(dst $&[]int, gate &[]int, up &[]int)Cpu swiglu f32.
dst $&[]intgate &[]intup &[]intThis call does not return a value.
cpu_rope_f32pub fn cpu_rope_f32(dst $&[]int, x &[]int, seq_len int, n_heads int, head_dim int, pos_off int, theta f64)Cpu rope f32.
dst $&[]intx &[]intseq_len intn_heads inthead_dim intpos_off inttheta f64This call does not return a value.
cpu_gemv_q4_0_f32pub fn cpu_gemv_q4_0_f32(dst $&[]int, x &[]int, w &string, rows int, cols int, m_cnt int)Cpu gemv q4 0 f32.
dst $&[]intx &[]intw &stringrows intcols intm_cnt intThis call does not return a value.
cpu_gemv_q8_0_f32pub fn cpu_gemv_q8_0_f32(dst $&[]int, x &[]int, w &string, rows int, cols int, m_cnt int)Cpu gemv q8 0 f32.
dst $&[]intx &[]intw &stringrows intcols intm_cnt intThis call does not return a value.
cpu_gemv_q4_k_f32pub fn cpu_gemv_q4_k_f32(dst $&[]int, x &[]int, w &string, rows int, cols int, m_cnt int)Cpu gemv q4 k f32.
dst $&[]intx &[]intw &stringrows intcols intm_cnt intThis call does not return a value.
cpu_gemv_q5_k_f32pub fn cpu_gemv_q5_k_f32(dst $&[]int, x &[]int, w &string, rows int, cols int, m_cnt int)Cpu gemv q5 k f32.
dst $&[]intx &[]intw &stringrows intcols intm_cnt intThis call does not return a value.
cpu_gemv_q6_k_f32pub fn cpu_gemv_q6_k_f32(dst $&[]int, x &[]int, w &string, rows int, cols int, m_cnt int)Cpu gemv q6 k f32.
dst $&[]intx &[]intw &stringrows intcols intm_cnt intThis call does not return a value.