module

MicroGPT::Backend

Instance methods

adam_step(param : Mat, grad : Mat, m : Mat, v : Mat, lr : Float64, t : Int32)
Source
add(a : Mat, b : Mat) : Mat
Source
add!(a : Mat, b : Mat)
Source
batched_matmul(a_list : Array(Mat), b_list : Array(Mat), transpose_a : Bool, transpose_b : Bool) : Array(Mat)
Source
bias_add(data : Mat, bias : Mat)
Source
causal_mask(scores : Mat)
Source
causal_mask_batched(scores : Mat, seq_len : Int32)
Source
fused_attn_softmax(scores : Mat, scale : Float64) : Mat

Fused attention: scale + causal mask + softmax in one pass Default implementation falls back to separate ops

Source
fused_attn_softmax_backward(s : Mat, ds : Mat, scale : Float64) : Mat
Source
fused_bias_relu(x : Mat, bias : Mat) : Tuple(Mat, Mat)

Fused bias + ReLU: add bias then apply ReLU in one pass Default falls back to separate ops

Source
gpu_alloc(size : UInt64) : Pointer(Void)

GPU memory management

Source
gpu_download(dst : Pointer(Void), src : Pointer(Void), size : UInt64)
Source
gpu_free(ptr : Pointer(Void))
Source
gpu_upload(dst : Pointer(Void), src : Pointer(Void), size : UInt64)
Source
layer_norm_backward(grad : Mat, norm : Mat, std_inv : Mat, gamma : Mat) : Tuple(Mat, Mat, Mat)
Source
layer_norm_forward(x : Mat, gamma : Mat, beta : Mat) : Tuple(Mat, Mat, Mat)
Source
matmul(a : Mat, b : Mat) : Mat

Core linear algebra

Source
matmul_into(a : Mat, b : Mat, dst : Mat)
Source
release(a : Mat)
Source
relu_backward(grad : Mat, mask : Mat) : Mat
Source
relu_forward(x : Mat) : Tuple(Mat, Mat)
Source
rope_apply(x : Mat, cos_cache : Mat, sin_cache : Mat)

RoPE: apply/inverse on GPU if available, default is no-op (handled by RoPE class on CPU)

Source
rope_apply_inverse(x : Mat, cos_cache : Mat, sin_cache : Mat)
Source
scale(a : Mat, scalar : Float32) : Mat
Source
scale!(a : Mat, scalar : Float32)
Source
softmax_backward(s : Mat, ds : Mat) : Mat
Source
softmax_rows(x : Mat) : Mat

Element-wise / reduction operations

Source
sync
Source
transpose(a : Mat) : Mat
Source