Alusus language bindings for the GGML tensor library.
import "Apm";
Apm.importPackage("Alusus/Ggml@0.2");
use Ggml;
See the Examples/ directory:
example.alusus- Basic matrix multiplication using contextbackend_example.alusus- Matrix multiplication using backend (Vulkan/CPU)
To enable Vulkan backend, pass the ggml_enable_vulkan option to Alusus compiler when running/compiling
your app:
alusus --opt ggml_enable_vulkan my_app.alusus
func getBuildDependencies(): Array[String];
A function that return an array of libraries and packages required to build a binary version of the application.
func init (params: InitParams): ref[Context]
func free (ctx: ref[Context])
func numaInit (numaStrategy: NumaStrategy)
func isNuma (): Bool
func getTensorOverhead (): ArchWord
func getTypeSize (type: Type): ArchWord
func getRowSize (type: Type, ne: Int[64]): ArchWord
func getGraphOverhead (): ArchWord
func setAbortCallback (cb: ptr[func(CharsPtr)]): ptr[func(CharsPtr)]
func abort (file: CharsPtr, line: Int, fmt: CharsPtr, ...any)
func fTypeToType (ftype: FType): Type
func statusToString (status: Status): CharsPtr
func fp16ToFp32 (v: Word[16]): Float
func fp16ToFp32 (src: ref[array[Word[16]]], dst: ref[array[Float]], len: Int[64])
func fp32ToFp16 (v: Float): Word[16]
func fp32ToFp16 (src: ref[array[Float]], dst: ref[array[Word[16]]], len: Int[64])
func fp32ToBf16 (v: Float): Word[16]
func fp32ToBf16 (src: ref[array[Float]], dst: ref[array[Word[16]]], len: Int[64])
func bf16ToFp32 (v: Word[16]): Float
func bf16ToFp32 (src: ref[array[Word[16]]], dst: ref[array[Float]], len: Int[64])
func buildForwardExpand (graph: ref[CGraph], tensor: ref[Tensor])
func buildBackwardExpand (context: ref[Context], graph: ref[CGraph], tensor: ref[ref[Tensor]])
ALLOC_FAILED(-2): Memory allocation failedFAILED(-1): Operation failedSUCCESS(0): Operation succeededABORTED(1): Operation aborted
F32(0): 32-bit floatF16(1): 16-bit floatQ4_0(2): 4-bit quantized (variant 0)Q4_1(3): 4-bit quantized (variant 1)Q5_0(6): 5-bit quantized (variant 0)Q5_1(7): 5-bit quantized (variant 1)Q8_0(8): 8-bit quantized (variant 0)Q8_1(9): 8-bit quantized (variant 1)Q2_K(10): 2-bit K-quantizedQ3_K(11): 3-bit K-quantizedQ4_K(12): 4-bit K-quantizedQ5_K(13): 5-bit K-quantizedQ6_K(14): 6-bit K-quantizedIQ2_XXS(16): IQ 2-bit extra extra smallIQ2_XS(17): IQ 2-bit extra smallIQ3_XXS(18): IQ 3-bit extra extra smallIQ1_S(19): IQ 1-bit smallIQ4_NL(20): IQ 4-bit non-linearIQ3_S(21): IQ 3-bit smallIQ2_S(22): IQ 2-bit smallIQ4_XS(23): IQ 4-bit extra smallI8(24): 8-bit integerI16(25): 16-bit integerI32(26): 32-bit integerI64(27): 64-bit integerF64(28): 64-bit floatIQ1_M(29): IQ 1-bit mediumBF16(30): Brain float 16-bit
UNKNOWN(-1)ALL_F32(0)MOSTLY_F16(1)MOSTLY_Q4_0(2)MOSTLY_Q4_1(3)MOSTLY_Q4_1_SOME_F16(4)MOSTLY_Q8_0(7)MOSTLY_Q5_0(8)MOSTLY_Q5_1(9)MOSTLY_Q2_K(10)MOSTLY_Q3_K(11)MOSTLY_Q4_K(12)MOSTLY_Q5_K(13)MOSTLY_Q6_K(14)MOSTLY_IQ2_XXS(15)MOSTLY_IQ2_XS(16)MOSTLY_IQ3_XXS(17)MOSTLY_IQ1_S(18)MOSTLY_IQ4_NL(19)MOSTLY_IQ3_S(20)MOSTLY_IQ2_S(21)MOSTLY_IQ4_XS(22)MOSTLY_IQ1_M(23)MOSTLY_BF16(24)MOSTLY_MXFP4(25)
DISABLED(0)DISTRIBUTE(1)ISOLATE(2)NUMACTL(3)MIRROR(4)COUNT(5)
class InitParams { def memSize: ArchWord; def memBuffer: ptr; def noAlloc: Bool; }
def memSize: ArchWord;
def memBuffer: ptr;
def noAlloc: Bool;
func newTensor (type: Type, nDims: Int, ne: ref[array[Int[64]]]): ref[Tensor]
func newTensor (type: Type, ne0: Int[64]): ref[Tensor]
func newTensor (type: Type, ne0: Int[64], ne1: Int[64]): ref[Tensor]
func newTensor (type: Type, ne0: Int[64], ne1: Int[64], ne2: Int[64]): ref[Tensor]
func newTensor (type: Type, ne0-3: Int[64]): ref[Tensor]
func dup (a: ref[Tensor]): ref[Tensor]
func dup (a: ref[CGraph], forceGrads: Bool): ref[CGraph]
func newGraph (): ref[CGraph]
func newGraph (size: ArchWord, grads: Bool): ref[CGraph]
func backendAllocTensors (backend: ref[Backend]): ref[BackendBuffer]
func add (a: ref[Tensor], b: ref[Tensor]): ref[Tensor]
func sub (a: ref[Tensor], b: ref[Tensor]): ref[Tensor]
func mul (a: ref[Tensor], b: ref[Tensor]): ref[Tensor]
func div (a: ref[Tensor], b: ref[Tensor]): ref[Tensor]
func log (t: ref[Tensor]): ref[Tensor]
func sum (a: ref[Tensor]): ref[Tensor]
func mean (a: ref[Tensor]): ref[Tensor]
func argmax (a: ref[Tensor]): ref[Tensor]
func norm (a: ref[Tensor]): ref[Tensor]
func rmsNorm (a: ref[Tensor], eps: Float): ref[Tensor]
func mulMat (a: ref[Tensor], b: ref[Tensor]): ref[Tensor]
func scale (a: ref[Tensor], alpha: Float): ref[Tensor]
func set (a: ref[Tensor], value: Float): ref[Tensor]
func cpy (src: ref[Tensor], dst: ref[Tensor]): ref[Tensor]
func cont (a: ref[Tensor]): ref[Tensor]
func reshape (a: ref[Tensor], b: ref[Tensor]): ref[Tensor]
func reshape (a: ref[Tensor], ne0: Int[64]): ref[Tensor]
func reshape (a: ref[Tensor], ne0-1: Int[64]): ref[Tensor]
func reshape (a: ref[Tensor], ne0-2: Int[64]): ref[Tensor]
func reshape (a: ref[Tensor], ne0-3: Int[64]): ref[Tensor]
func view (a: ref[Tensor], ne0: Int[64], offset: ArchWord): ref[Tensor]
func view (a: ref[Tensor], ne0-1: Int[64], nb1: ArchWord, offset: ArchWord): ref[Tensor]
func view (a: ref[Tensor], ne0-2: Int[64], nb1-2: ArchWord, offset: ArchWord): ref[Tensor]
func view (a: ref[Tensor], ne0-3: Int[64], nb1-3: ArchWord, offset: ArchWord): ref[Tensor]
func permute (a: ref[Tensor], axis1-4: Int): ref[Tensor]
func transpose (a: ref[Tensor]): ref[Tensor]
func getRows (a: ref[Tensor], b: ref[Tensor]): ref[Tensor]
func setRows (a: ref[Tensor], b: ref[Tensor], c: ref[Tensor]): ref[Tensor]
func diag (a: ref[Tensor]): ref[Tensor]
func diagMaskInf (a: ref[Tensor], nPast: Int): ref[Tensor]
func diagMaskInfInplace (a: ref[Tensor], nPast: Int): ref[Tensor]
func diagMaskZero (a: ref[Tensor], nPast: Int): ref[Tensor]
func diagMaskZeroInplace (a: ref[Tensor], nPast: Int): ref[Tensor]
func softMax (a: ref[Tensor]): ref[Tensor]
func rope (a: ref[Tensor], b: ref[Tensor], nDims: Int, mode: Int): ref[Tensor]
func pad (t: ref[Tensor], p0-3: Int): ref[Tensor]
func roll (t: ref[Tensor], shift0-3: Int): ref[Tensor]
func graphCompute (graph: ref[CGraph], nThreads: Int): Status
handler this.name: CharsPtr;
handler this.data: ptr;
handler this.dataF32: ref[array[Float]];
handler this.nElements: Int[64];
handler this.nRows: Int[64];
handler this.nBytes: ArchWord;
handler this.nBytesPad: ArchWord;
func setInput ()
func setOutput ()
func setParam ()
func setLoss ()
func backendSet (data: ptr, offset: ArchWord, size: ArchWord)
func backendGet (data: ptr, offset: ArchWord, size: ArchWord)
handler this.isCpu: Bool;
handler this.isVk: Bool;
func load (path: CharsPtr): ref[Reg]
func cpuLoad ();
func cpuLoad (exePath: CharsPtr);
Load the backend specific for running inference on the CPU. This should be called before initialization. The first form of this function looks for the backend library in the current path as well as in the Ggml library's path. This would cover both running in JIT mode as well as in pre-compilation mode, which is enough for most cases, but the second form is available for exceptional cases. The second form will look only within the provided path.
func vkLoad ();
func vkLoad (exePath: CharsPtr);
Load the backend specific fur running inference through Vulkan API. Use this instead of
cpuLoad if you want to run inference on the GPU.
The first form of this function looks for the backend library in the current path as well
as in the Ggml library's path. This would cover both running in JIT mode as well as in
pre-compilation mode, which is enough for most cases, but the second form is available for
exceptional cases. The second form will look only within the provided path.
func cpuInit (): ref[Backend]
func vkInit (devNum: ArchWord): ref[Backend]
func free (backend: ref[Backend])
func getDefaultBufferType (): ref[BackendBufferType]
func cpuSetNThreads (threads: Int)
func graphCompute (graph: ref[CGraph]): Status
func graphComputeAsync (graph: ref[CGraph]): Status
func plan (nThreads: Int, threadPool: ref[ThreadPool]): CPlan
func compute (cplan: ref[CPlan]): Status
func reset ()
func print ()
def workSize: ArchWord;
def workData: ref[array[Word[8]]];
def nThreads: Int;
def threadPool: ref[ThreadPool];
def abortCallback: ptr[function(ptr)];
def abortCallbackData: ptr;
func free (buffer: ref[BackendBuffer])
func new (backendBufferType: ref[BackendBufferType]): ref[Gallocr]
func free (gallocr: ref[Gallocr])
func allocGraph (graph: ref[CGraph]): Bool
nThreads: Int (property)
func new (params: ref[Params]): ref[ThreadPool]
func free (pool: ref[ThreadPool])
func pause ()
func resume ()
LOW(-1)NORMAL(0)MEDIUM(1)HIGH(2)REALTIME(3)
def cpuMask: array[Bool, 512];
def nThreads: Int;
def prio: Int;
def poll: Word;
def strictCpu: Bool;
def paused: Bool;
func init (nThreads: Int)
func getDefault (): Params
func match (a: ref[Params], b: ref[Params]): Bool
For detailed documentation of the underlying functions, refer to the GGML documentation.
This binding follows the GGML license (MIT). See the license file for details.