MIND Core v1 Cookbook

A collection of short, practical recipes demonstrating how to use Core v1 in real workflows.

Recipe 1 — Simple arithmetic (CPU)

fn main(x: tensor<f32>[4]) -> tensor<f32>[4] { return x * 2.0 }

Run (the runtime CLI ships with MIND Enterprise):

mindc scale.mind -o scale.ir
runtime run scale.ir --input x=[1,2,3,4]

Recipe 2 — Autodiff of a loss function

fn main(x: tensor<f32>[3]) -> tensor<f32>[1] {
  let y = sum(x * x)
  return y
}

Gradient IR:

mindc loss.mind --grad --func main -o loss.grad.ir

Expected gradient: 2 * x.

Recipe 3 — MLIR lowering for CPU

mindc scale.mind --mlir -o scale.mlir

Recipe 4 — GPU profile: correct error handling

mindc main.mind --target gpu

Expected result (Core v1-stable):

error[runtime]: backend 'gpu' unavailable

Recipe 5 — Host embedding via the runtime API

let rt = MindRuntime::new_cpu()?;
let inp = rt.allocate(&tensor_desc_f32(&[2]))?;
rt.write_tensor(inp, &[1.0, 3.0])?;

let out = rt.allocate(&tensor_desc_f32(&[1]))?;
rt.run_op("sum", &[inp], &[out])?;

let result = rt.read_tensor(out)?;

Output: 4.0.

Recipe 6 — Running the official conformance suite

CPU baseline:

mindc conformance --profile cpu

GPU profile:

mindc conformance --profile gpu

Recipe 7 — Using the pure-MIND standard library (RFC 0005)

std.vec, std.string, std.map, and std.io are bundled into mindc since v0.4.2 — a project that says use std.vecresolves with zero external file dependency. The std-surface feature is the shipped default (since v0.7.1); enable cross-module-imports to resolve cross-module use paths:

# cross-module-imports is the only extra gate needed; std-surface ships by default.
cargo run --features "cross-module-imports" --bin mindc -- demo.mind --emit-ir

A minimal demo.mind exercising std.vec:

use std.vec;

fn main() -> i64 {
    let v = vec_new();
    let v = vec_push(v, 10);
    let v = vec_push(v, 20);
    let v = vec_push(v, 30);

    let n = vec_len(v);          // 3
    let x = vec_get(v, 1);       // 20

    vec_free(v);
    return x;
}

Every operation returns the (possibly reallocated) Vechandle — there is no hidden mutation. Modules are resolved last-write-wins, so a user crate MAY define its own std.vec to shadow the bundled one.

See the per-module pages for the full API: std.vec, std.string, std.map, std.io. The seven host intrinsics they bottom out in (__mind_alloc, __mind_realloc, __mind_free, __mind_load_i64, __mind_store_i64, __mind_read, __mind_write) are ratified by mind-spec v1.0 (stdlib.md).

Beyond std — crypto & protocol primitives

The source tree also carries a pure-MIND cryptography and protocol primitive library: AES-128-GCM, SHA-256, HKDF, X25519, SHA-3/SHAKE (FIPS 202), RSA-PSS, ECDSA-P256, ML-KEM-768 (FIPS 203), X.509 parsing and verification, the TLS 1.3 key schedule, record layer, Finished MAC and handshake crypto (verified by RFC 8448 replay), HPACK (RFC 7541), and HTTP/2 framing (RFC 9113). Every primitive is verified against RFC and NIST known-answer tests.

Honest scope: this is a verified primitive library, not a working TLS client or server — there is no socket-driven handshake state machine yet, certificate-chain path validation is not implemented, and HPACK is decode-only. The primitives are correctness-first, not speed-optimized.