Examples
Programs the compiler already accepts
These .kina files live in tests/compiler/examples/. They are compile tests, not a standard library. Where a golden exists, the example page also shows the textual MLIR the OCaml compiler emits. storylm0_forward.kina is a tiny causal-attention forward graph.storylm0_nll.kina composes host log_softmax and take_along_axis; it is not training. The Python StoryLM lab under experiments/storylm/ is a separate Hugging Face evaluation harness.
ad_basic.kina
Restricted reverse-mode AD example
let f = fn(x: tensor<F32, [4, 4], @host>) -> tensor<F32, [4, 4], @host> {
let W = tensor<F32, [4, 4], @host> { 1.0 } in
let b = tensor<F32, [4, 4], @host> { 1.0 } in
let mm = W @ x in
let linear = mm + b in
let act = relu(linear) in
act
} in
let x_input = tensor<F32, [4, 4], @host> { 1.0 } in
handle f(x_input) with reverseModead_gather.kina
Restricted reverse-mode 2D gather VJP; I64 ids have no cotangent
let f = fn(
emb: tensor<F32, [8, 4], @host>,
ids: tensor<I64, [1, 4], @host>
) -> tensor<F32, [1, 4, 4], @host> {
let y = emb.gather(ids) in
y
…ad_log_softmax.kina
Restricted reverse-mode log_softmax VJP
let f = fn(x: tensor<F32, [2, 3], @host>) -> tensor<F32, [2, 3], @host> {
let y = x.log_softmax(axis=1) in
y
} in
let x = tensor<F32, [2, 3], @host> in
handle f(x) with reverseModead_matmul4.kina
Restricted reverse-mode rank-4 matmul VJP
let f = fn(
q: tensor<F32, [1, 2, 4, 2], @host>,
kt: tensor<F32, [1, 2, 2, 4], @host>
) -> tensor<F32, [1, 2, 4, 4], @host> {
let s = q @ kt in
s
…ad_mlp.kina
Restricted reverse-mode AD example
let mlp_forward = fn(x: tensor<F32, [2, 2], @host>, w1: tensor<F32, [2, 2], @host>, w2: tensor<F32, [2, 2], @host>) !{Diff} -> tensor<F32, [2, 2], @host> {
let active_w1 = perform Diff.active(w1) in
let active_w2 = perform Diff.active(w2) in
let hidden = x @ active_w1 in
let hidden_sq = hidden * hidden in
let out = hidden_sq @ active_w2 in
…ad_neg.kina
Restricted reverse-mode neg VJP; @main returns (primal, g)
let f = fn(x: tensor<F32, [2, 2], @host>) -> tensor<F32, [2, 2], @host> {
let y = -x in
y
} in
let x = tensor<F32, [2, 2], @host> in
handle f(x) with reverseModead_neg_grad.kina
reverseMode wrapper fn returning (primal, grad) from a .so
let f = fn(x: tensor<F32, [2, 2], @host>) -> tensor<F32, [2, 2], @host> {
let y = -x in
y
} in
let ad = fn(x: tensor<F32, [2, 2], @host>)
-> (tensor<F32, [2, 2], @host>, tensor<F32, [2, 2], @host>) {
handle f(x) with reverseMode
} in
let x = tensor<F32, [2, 2], @host> in
ad(x)ad_nll.kina
Restricted reverse-mode NLL VJP; @main returns (loss, g)
let nll = fn(logits: tensor<F32, [1, 4, 8], @host>) -> tensor<F32, [1, 4], @host> {
let targets = tensor<I64, [1, 4], @host> in
let log_probs = logits.log_softmax(axis=2) in
let picked = log_probs.take_along_axis(targets, axis=2) in
let loss = -picked in
loss
} in
let logits = tensor<F32, [1, 4, 8], @host> in
handle nll(logits) with reverseModead_reduce_sum.kina
Restricted reverse-mode keepdims reduce_sum VJP
let f = fn(x: tensor<F32, [2, 3], @host>) -> tensor<F32, [2, 1], @host> {
let y = x.reduce_keep(op=sum, axis=1) in
y
} in
let step = fn(x: tensor<F32, [2, 3], @host>) -> (
tensor<F32, [2, 1], @host>,
…ad_reshape.kina
Restricted reverse-mode reshape VJP
let f = fn(x: tensor<F32, [1, 4, 4], @host>) -> tensor<F32, [1, 4, 2, 2], @host> {
let y = x.reshape([1, 4, 2, 2]) in
y
} in
let grad = fn(x: tensor<F32, [1, 4, 4], @host>) -> tensor<F32, [1, 4, 4], @host> {
let (y, g) = handle f(x) with reverseMode in
g
} in
let x = tensor<F32, [1, 4, 4], @host> in
grad(x)ad_sgd_step.kina
Name reverseMode grads with let (y, g) and apply SGD
let f = fn(w: tensor<F32, [4, 8], @host>) -> tensor<F32, [4, 8], @host> {
let y = -w in
y
} in
let step = fn(
w: tensor<F32, [4, 8], @host>,
…ad_stdlib_test.kina
Restricted reverse-mode AD example
let x = tensor<F32, [1, 32, 64], @host> { 1.0 } in
let gamma = tensor<F32, [1, 1, 64], @host> { 1.0 } in
// Test RMSNorm Gradients
let out1 = handle rmsnorm(x, gamma) with reverseMode in
…adamw_step.kina
Functional AdamW as existing arithmetic; not a primitive
let adamw_step = fn( w: tensor<F32, [4, 8], @host>, g: tensor<F32, [4, 8], @host>, m: tensor<F32, [4, 8], @host>, v: tensor<F32, [4, 8], @host>, lr: tensor<F32, [1, 1], @host>, …
add_2d.kina
Compiler example
(tensor<F32, [2, 3]> + tensor<F32, [2, 3]>)
argmax_axis1.kina
Host reduce argmax; I64 result; lowest-index tie-break
tensor<F32, [2, 3]>.reduce(op=argmax, axis=1)
argmax_keep_axis1.kina
Host reduce argmax; I64 result; lowest-index tie-break
tensor<F32, [2, 3]>.reduce_keep(op=argmax, axis=1)
bitwise_and_i32.kina
Compiler example
tensor<I32, [2, 3]> & tensor<I32, [2, 3]>
broadcast_row.kina
Compiler example
tensor<F32, [1, 3]>.broadcast([2, 3])
cast_bool_i32.kina
Dtype cast
tensor<Bool, [2]>.cast(I32)
cast_f16_bf16.kina
Dtype cast
tensor<F16, [2, 2]>.cast(BF16)
cast_i32.kina
Dtype cast
tensor<F32, [2, 4]>.cast(I32)
cast_i8_i32.kina
Dtype cast
tensor<I8, [3]>.cast(I32)
concat_axis0.kina
Compiler example
tensor<F32, [2, 3]>.concat(axis=0, tensor<F32, [3, 3]>)
div_2d.kina
Compiler example
(tensor<F32, [2, 3]> / tensor<F32, [2, 3]>)
effects_test.kina
Early control-flow / effect example
let run = fn(val : tensor<F32, [], @host>) !{State} -> tensor<F32, [], @host> {
let current = perform State.get() in
let next = current + val in
next
} in
handle run(tensor<F32, [], @host>) with {
return(x) => x,
State.get(), k => k(tensor<F32, [], @host>)
}eq_f32.kina
Compiler example
(tensor<F32, [2, 2]> == tensor<F32, [2, 2]>)
frem_f32.kina
Compiler example
tensor<F32, [2, 3]> frem tensor<F32, [2, 3]>
frem_f8e4m3.kina
Compiler example
tensor<F8E4M3, [2, 3]> frem tensor<F8E4M3, [2, 3]>
gather_2d.kina
Compiler example
tensor<F32, [10, 20], @host>.gather(tensor<I64, [4, 5], @host>)
if_else.kina
Early control-flow / effect example
let relu_custom = fn(x: tensor<F32, [4, 4], @host>, scalar_cond: tensor<Bool, [], @host>) -> tensor<F32, [4, 4], @host> {
let zero = tensor<F32, [4, 4], @host> in
let final = if (scalar_cond) { x } else { zero } in
final
} in
let x_input = tensor<F32, [4, 4], @host> in
let cond = tensor<Bool, [], @host> in
relu_custom(x_input, cond)invalid_add_shape_mismatch.kina
Rejected by the type checker
(tensor<F32, [2, 3]> + tensor<F32, [2, 4]>)
invalid_argmax_bool.kina
Rejected by the type checker
tensor<Bool, [2, 3]>.reduce(op=argmax, axis=1)
invalid_argmax_device.kina
Rejected by the type checker
tensor<F32, [2, 3], @device(0)>.reduce(op=argmax, axis=1)
invalid_dim_zero.kina
Rejected by the type checker
tensor<F32, [0, 4]>
invalid_log_softmax_axis.kina
Rejected by the type checker
tensor<F32, [2, 3], @host>.log_softmax(axis=2)
invalid_log_softmax_dtype.kina
Rejected by the type checker
tensor<I32, [2, 3], @host>.log_softmax(axis=1)
invalid_mul_shape_mismatch.kina
Rejected by the type checker
(tensor<F32, [2, 3]> * tensor<F32, [2, 4]>)
invalid_reduce_mean_ad.kina
Rejected by the type checker
let f = fn(x: tensor<F32, [2, 3], @host>) -> tensor<F32, [2, 1], @host> {
let y = x.reduce_keep(op=mean, axis=1) in
y
} in
let x = tensor<F32, [2, 3], @host> in
handle f(x) with reverseModeinvalid_requires_mismatch.kina
Rejected by the type checker
requires [B = B_prime] compute {
tensor<F32, [B, M, K], @host> @ tensor<F32, [B_prime, K_prime, N], @host>
}invalid_reshape_volume_mismatch.kina
Rejected by the type checker
tensor<F32, [2, 3]>.reshape([4, 2])
invalid_reverse_mode_return.kina
Rejected by the type checker
let f = fn(x: tensor<F32, [2, 2], @host>) -> tensor<F32, [2, 2], @host> {
let y = -x in
y
} in
let ad = fn(x: tensor<F32, [2, 2], @host>) -> tensor<F32, [2, 2], @host> {
handle f(x) with reverseMode
} in
let x = tensor<F32, [2, 2], @host> in
ad(x)invalid_sgd_shape.kina
Rejected by the type checker
let w = tensor<F32, [4, 8], @host> in let g = tensor<F32, [4, 8], @host> in let lr = tensor<F32, [1, 1], @host> in w - lr * g
invalid_take_along_axis_axis.kina
Rejected by the type checker
tensor<F32, [1, 4, 8], @host>.take_along_axis(tensor<I64, [1, 4], @host>, axis=3)
invalid_take_along_axis_device.kina
Rejected by the type checker
tensor<F32, [2, 3], @device(0)>.take_along_axis(tensor<I64, [2], @device(0)>, axis=1)
invalid_take_along_axis_indices.kina
Rejected by the type checker
tensor<F32, [1, 4, 8], @host>.take_along_axis(tensor<I32, [1, 4], @host>, axis=2)
invalid_take_along_axis_rank.kina
Rejected by the type checker
tensor<F32, [4], @host>.take_along_axis(tensor<I64, [4], @host>, axis=0)
invalid_take_along_axis_shape.kina
Rejected by the type checker
tensor<F32, [1, 4, 8], @host>.take_along_axis(tensor<I64, [1, 3], @host>, axis=2)
invalid_tuple_let_arity.kina
Rejected by the type checker
let f = fn(w: tensor<F32, [4, 8], @host>) -> tensor<F32, [4, 8], @host> {
let y = -w in
y
} in
let w = tensor<F32, [4, 8], @host> in
let (y, g, extra) = handle f(w) with reverseMode in
yinvalid_tuple_let_duplicate.kina
Rejected by the type checker
let f = fn(w: tensor<F32, [4, 8], @host>) -> tensor<F32, [4, 8], @host> {
let y = -w in
y
} in
let w = tensor<F32, [4, 8], @host> in
let (g, g) = handle f(w) with reverseMode in
ginvalid_tuple_let_not_tuple.kina
Rejected by the type checker
let w = tensor<F32, [4, 8], @host> in let (y, g) = w in y
llm_generate.kina
Loop-carried matrix sketch, not token generation
let generate = fn(steps: tensor<I32, [], @host>, start_token: tensor<F32, [4, 4], @host>, init_kv: tensor<F32, [16, 4], @host>, start_pos: tensor<I32, [], @host>, step_size: tensor<I32, [], @host>) -> (tensor<F32, [4, 4], @host>, tensor<F32, [16, 4], @host>, tensor<I32, [], @host>) {
let final = while (pos < steps) [tok = start_token, kv = init_kv, pos = start_pos] {
let w = tensor<F32, [4, 4], @host> in
let next_tok = tok @ w in
let next_kv = kv + kv in
let next_pos = pos + step_size in
…log_softmax_axis0.kina
Stable log-softmax on a compile-time axis
tensor<F32, [2, 3], @host>.log_softmax(axis=0)
log_softmax_axis1.kina
Stable log-softmax on a compile-time axis
tensor<F32, [2, 3], @host>.log_softmax(axis=1)
log_softmax_rank3.kina
Stable log-softmax on a compile-time axis
tensor<F32, [1, 4, 8], @host>.log_softmax(axis=2)
matmul_2d.kina
Matrix multiply
(tensor<F32, [2, 3]> @ tensor<F32, [3, 4]>)
matmul_batch.kina
Matrix multiply
(tensor<F32, [1, 2, 3]> @ tensor<F32, [1, 3, 4]>)
max_f8e4m3.kina
Compiler example
max(tensor<F8E4M3, [2, 2]>, tensor<F8E4M3, [2, 2]>)
max_i32.kina
Compiler example
max(tensor<I32, [2, 3]>, tensor<I32, [2, 3]>)
min_f32.kina
Compiler example
min(tensor<F32, [1, 4]>, tensor<F32, [1, 4]>)
mlp_forward.kina
MLP forward compile example
requires [B = B_prime, In = In_prime, Hidden = Hidden_out] compute {
let x = tensor<F32, [B, In], @host> in
let w1 = tensor<F32, [In_prime, Hidden], @host> in
let w2 = tensor<F32, [Hidden_out, Out], @host> in
// First linear layer
…mlp_forward_gpu.kina
MLP forward compile example
let mlp_gpu = fn(x: tensor<F32, [128, 256], @device(0)>, w1: tensor<F32, [256, 512], @device(0)>, w2: tensor<F32, [512, 10], @device(0)>) -> tensor<F32, [128, 10], @device(0)> {
let h1 = x @ w1 in
let h1_relu = relu(h1) in
let out = h1_relu @ w2 in
out
} in
let x = tensor<F32, [128, 256], @device(0)> { 1.0 } in
let w1 = tensor<F32, [256, 512], @device(0)> { 1.0 } in
let w2 = tensor<F32, [512, 10], @device(0)> { 1.0 } in
mlp_gpu(x, w1, w2)mlp_forward_static.kina
MLP forward compile example
let mlp = fn(x: tensor<F32, [128, 256], @host>, w1: tensor<F32, [256, 512], @host>, w2: tensor<F32, [512, 10], @host>) -> tensor<F32, [128, 10], @host> {
let h1 = x @ w1 in
let h1_relu = relu(h1) in
let out = h1_relu @ w2 in
out
} in
let x = tensor<F32, [128, 256], @host> { 1.0 } in
let w1 = tensor<F32, [256, 512], @host> { 1.0 } in
let w2 = tensor<F32, [512, 10], @host> { 1.0 } in
mlp(x, w1, w2)mul_2d.kina
Compiler example
(tensor<F32, [2, 3]> * tensor<F32, [2, 3]>)
pow_f32.kina
Compiler example
(tensor<F32, [2, 2]> ** tensor<F32, [2, 2]>)
pow_f8e4m3.kina
Compiler example
(tensor<F8E4M3, [2, 2]> ** tensor<F8E4M3, [2, 2]>)
reduce_keep_mean_axis1.kina
Reduction
tensor<F32, [2, 3]>.reduce_keep(op=mean, axis=1)
reduce_max_axis1.kina
Reduction
tensor<F32, [2, 3]>.reduce(op=max, axis=1)
reduce_max_f8_axis0.kina
Reduction
tensor<F8E4M3, [2, 3]>.reduce(op=max, axis=0)
reduce_mean_f8_axis0.kina
Reduction
tensor<F8E4M3, [2, 3]>.reduce(op=mean, axis=0)
reduce_min_axis0.kina
Reduction
tensor<I32, [2, 3]>.reduce(op=min, axis=0)
reduce_sum_axis1.kina
Reduction
tensor<F32, [2, 3]>.reduce(op=sum, axis=1)
rem_i32.kina
Compiler example
(tensor<I32, [2, 4]> % tensor<I32, [2, 4]>)
repeat_interleave_axis0.kina
Compiler example
tensor<F32, [2, 3], @host>.repeat_interleave(axis=0, reps=2)
reshape_2d_to_3d.kina
Compiler example
tensor<F32, [2, 3]>.reshape([1, 2, 3])
scalar_bool.kina
Compiler example
tensor<Bool, []>
sgd_step.kina
Functional SGD as broadcast(lr)*g subtracted from w
let sgd_step = fn(
w: tensor<F32, [4, 8], @host>,
g: tensor<F32, [4, 8], @host>,
lr: tensor<F32, [1, 1], @host>
) -> tensor<F32, [4, 8], @host> {
let lr_b = lr.broadcast([4, 8]) in
…slice_axis0.kina
Compiler example
tensor<F32, [4, 5]>.slice(axis=0, start=0, stop=2)
softmax_axis1.kina
Compiler example
tensor<F32, [2, 3], @host>.softmax(axis=1)
state_effect.kina
Early control-flow / effect example
let f = fn(x : tensor<F32, []>) !{State} -> tensor<F32, []> {
let current = perform State.get() in
let new_val = current + x in
let dummy = perform State.set(new_val) in
new_val
} in
…static_2d.kina
Compiler example
tensor<F32, [2, 2]>
storylm0_ad_step.kina
Decoder graph + embedding SGD; not a trained model
let storylm0_fwd = fn( token_ids: tensor<I64, [1, 4], @host>, token_embedding: tensor<F32, [8, 4], @host>, causal_mask: tensor<F32, [1, 1, 4, 4], @host>, attention_scale: tensor<F32, [1, 1, 1, 1], @host>, wq: tensor<F32, [4, 4], @host>, …
storylm0_adamw_step.kina
NLL ∘ decoder + multi-weight AdamW; not a trained model
let adamw_e = fn( w: tensor<F32, [8, 4], @host>, g: tensor<F32, [8, 4], @host>, m: tensor<F32, [8, 4], @host>, v: tensor<F32, [8, 4], @host>, lr: tensor<F32, [1, 1], @host>, …
storylm0_forward.kina
Tiny causal-attention forward graph (not a trained model)
let storylm0_forward = fn( token_ids: tensor<I64, [1, 4], @host>, token_embedding: tensor<F32, [8, 4], @host>, causal_mask: tensor<F32, [1, 1, 4, 4], @host>, attention_scale: tensor<F32, [1, 1, 1, 1], @host>, wq: tensor<F32, [4, 4], @host>, …
storylm0_generate.kina
Host greedy loop over static-S decode; not while-grown cache
let decode_self = fn( token_ids: tensor<I64, [1, 1], @host>, token_embedding: tensor<F32, [8, 4], @host>, attention_scale: tensor<F32, [1, 1, 1, 1], @host>, wq: tensor<F32, [4, 4], @host>, wk: tensor<F32, [4, 4], @host>, …
storylm0_greedy.kina
Host greedy argmax on [B, T, V] logits; not sampling
let greedy = fn(logits: tensor<F32, [1, 4, 8], @host>) -> tensor<I64, [1, 4], @host> {
let tokens = logits.reduce(op=argmax, axis=2) in
tokens
} in
let logits = tensor<F32, [1, 4, 8], @host> in
greedy(logits)storylm0_kv_step.kina
One-step KV concat + attention; not a generation loop
let kv_step = fn( q_new: tensor<F32, [1, 2, 1, 2], @host>, k_past: tensor<F32, [1, 2, 2, 3], @host>, k_new: tensor<F32, [1, 2, 2, 1], @host>, v_past: tensor<F32, [1, 2, 3, 2], @host>, v_new: tensor<F32, [1, 2, 1, 2], @host>, …
storylm0_mean_nll_step.kina
Mean NLL ∘ decoder + multi-weight SGD; not reduce_mean
let storylm0_mean_nll = fn( token_ids: tensor<I64, [1, 4], @host>, targets: tensor<I64, [1, 4], @host>, token_embedding: tensor<F32, [8, 4], @host>, causal_mask: tensor<F32, [1, 1, 4, 4], @host>, attention_scale: tensor<F32, [1, 1, 1, 1], @host>, …
storylm0_nll.kina
Host NLL as -log_softmax.take_along_axis; not training
let nll = fn(
logits: tensor<F32, [1, 4, 8], @host>,
targets: tensor<I64, [1, 4], @host>
) -> tensor<F32, [1, 4], @host> {
let log_probs = logits.log_softmax(axis=2) in
let picked = log_probs.take_along_axis(targets, axis=2) in
…storylm0_nll_step.kina
NLL ∘ decoder + multi-weight SGD; not a trained model
let storylm0_nll = fn( token_ids: tensor<I64, [1, 4], @host>, targets: tensor<I64, [1, 4], @host>, token_embedding: tensor<F32, [8, 4], @host>, causal_mask: tensor<F32, [1, 1, 4, 4], @host>, attention_scale: tensor<F32, [1, 1, 1, 1], @host>, …
storylm0_prefill.kina
Prefill cache handoff plus one decode step; not T_max scratch
let prefill = fn( token_ids: tensor<I64, [1, 3], @host>, token_embedding: tensor<F32, [8, 4], @host>, causal_mask: tensor<F32, [1, 1, 3, 3], @host>, attention_scale: tensor<F32, [1, 1, 1, 1], @host>, wq: tensor<F32, [4, 4], @host>, …
storylm0_rollout.kina
Host 32-token rollout from a patterned fixture; not a trained model
let greedy_row = fn(
logits: tensor<F32, [1, 1, 8], @host>
) -> tensor<I64, [1, 1], @host> {
let tokens = logits.reduce(op=argmax, axis=2) in
tokens
} in
…storylm0_sample.kina
Host Gumbel-max sample; seed is the Uniform tensor
let sample = fn(
logits: tensor<F32, [1, 4, 8], @host>,
u: tensor<F32, [1, 4, 8], @host>,
temperature: tensor<F32, [1, 1], @host>
) -> tensor<I64, [1, 4], @host> {
let log_u = log(u) in
…storylm0_tmax.kina
Pad live KV to T_max with zeros, then slice the prefix
let pad_s3 = fn( k_live: tensor<F32, [1, 2, 2, 3], @host>, v_live: tensor<F32, [1, 2, 3, 2], @host>, zero: tensor<F32, [1, 1, 1, 1], @host> ) -> ( tensor<F32, [1, 2, 2, 5], @host>, …
storylm0_tp_heads.kina
2-way head-parallel attention; not @mesh or @sharded
let tp_heads = fn( q: tensor<F32, [1, 2, 4, 2], @host>, k_t: tensor<F32, [1, 2, 2, 4], @host>, v: tensor<F32, [1, 2, 4, 2], @host>, attention_scale: tensor<F32, [1, 1, 1, 1], @host>, causal_mask: tensor<F32, [1, 1, 4, 4], @host> …
storylm0_tp_proj.kina
2-way column-parallel QKV; not @mesh or @sharded
let proj_q0 = fn(
x: tensor<F32, [1, 4, 4], @host>,
wq: tensor<F32, [4, 4], @host>
) -> tensor<F32, [1, 1, 4, 2], @host> {
let wq0 = wq.slice(axis=1, start=0, stop=2) in
let wq0_b = wq0.broadcast([1, 4, 2]) in
…storylm0_tp_vocab.kina
2-way column-parallel lm_head; not @mesh or @sharded
let tp_logits = fn(
residual: tensor<F32, [1, 4, 4], @host>,
lm_head: tensor<F32, [4, 8], @host>
) -> tensor<F32, [1, 4, 8], @host> {
let lm0 = lm_head.slice(axis=1, start=0, stop=4) in
let lm1 = lm_head.slice(axis=1, start=4, stop=8) in
…sub_2d.kina
Compiler example
(tensor<F32, [2, 3]> - tensor<F32, [2, 3]>)
symbolic_3d.kina
Compiler example
tensor<BF16, [B, S, D]>
symbolic_requires.kina
Compiler example
requires [B = B_prime, K = K_prime] compute {
tensor<F32, [B, M, K], @host> @ tensor<F32, [B_prime, K_prime, N], @host>
}take_along_axis_interior.kina
Select along a compile-time axis (not 2D gather)
tensor<F32, [1, 8, 4], @host>.take_along_axis(tensor<I64, [1, 4], @host>, axis=1)
take_along_axis_last.kina
Select along a compile-time axis (not 2D gather)
tensor<F32, [1, 4, 8], @host>.take_along_axis(tensor<I64, [1, 4], @host>, axis=2)
transformer_ad.kina
Transformer block / restricted AD example
let fwd = fn( x: tensor<F32, [1, 32, 64], @host>, gamma1: tensor<F32, [1, 1, 64], @host>, wq: tensor<F32, [1, 64, 64], @host>, wk: tensor<F32, [1, 64, 64], @host>, wv: tensor<F32, [1, 64, 64], @host>, …
transformer_block.kina
Transformer block / restricted AD example
requires [B = B_p, Seq = Seq_p, D = D_p, D_ffn = D_ffn_p] compute {
let run_transformer = fn(
x: tensor<F32, [1, 32, 64], @host>,
gamma1: tensor<F32, [1, 1, 64], @host>,
wq: tensor<F32, [1, 64, 64], @host>,
wk: tensor<F32, [1, 64, 64], @host>,
…transpose_2d.kina
Compiler example
tensor<F32, [3, 4]>.transpose([1, 0])
unary_bitwise_not_i32.kina
Unary op
!(tensor<I32, [2, 3]>)
unary_exp_f8e4m3.kina
Unary op
exp(tensor<F8E4M3, [2, 3]>)
unary_gelu_f32.kina
Unary op
gelu(tensor<F32, [2, 3]>)
unary_log_f32.kina
Unary op
log(tensor<F32, [2, 3]>)
unary_neg_bool.kina
Unary op
-tensor<Bool, []>
unary_neg_i32.kina
Unary op
-tensor<I32, [2, 2]>
unary_relu.kina
Unary op
relu(tensor<F32, [2, 3]>)
unary_relu_f8e4m3.kina
Unary op
relu(tensor<F8E4M3, [2, 2]>)
unary_rsqrt_f32.kina
Unary op
rsqrt(tensor<F32, [2, 3]>)
unary_sigmoid_f32.kina
Unary op
sigmoid(tensor<F32, [2, 3]>)
unary_sigmoid_f8e4m3.kina
Unary op
sigmoid(tensor<F8E4M3, [1, 2]>)
unary_silu_f32.kina
Unary op
silu(tensor<F32, [2, 3]>)
unary_sqrt_f32.kina
Unary op
sqrt(tensor<F32, [2, 3]>)
unary_tanh_f32.kina
Unary op
tanh(tensor<F32, [2, 3]>)
while_checkpoint.kina
Early control-flow / effect example
let loop_checkpoint_test = fn(steps: tensor<I32, [], @host>, init_val: tensor<F32, [4, 4], @host>, i_init: tensor<I32, [], @host>, step: tensor<I32, [], @host>) -> (tensor<F32, [4, 4], @host>, tensor<I32, [], @host>) {
let final_val = @checkpoint(k=4) while (i < steps) [val = init_val, i = i_init] {
let next_val = val + val in
let next_i = i + step in
(next_val, next_i)
} in
…while_loop.kina
Early control-flow / effect example
let loop_test = fn(steps: tensor<I32, [], @host>, init_val: tensor<F32, [4, 4], @host>, i_init: tensor<I32, [], @host>, step: tensor<I32, [], @host>) -> (tensor<F32, [4, 4], @host>, tensor<I32, [], @host>) {
let final_val = while (i < steps) [val = init_val, i = i_init] {
let next_val = val + val in
let next_i = i + step in
(next_val, next_i)
} in
…