macrogrok-harness
Rust harness for MACROGROK fixed-point macro-models and Transformer-X CUDA (Tensor Core WMMA, attention memory, Tavily RAG).
Architecture
- Rust host (
tokio,cudarc 0.11,reqwest,half) + CUDAcudarc/ custom kernels - Attention β Tensor Core
WMMA 16x16x16(mma.syncpath available), explicitAttentionMemoryKV-cache (contiguous/paged), FlashAttention online-softmax tiling - MACROGROK β
Q1.14/Q3.12fixed-point INFER4 harness (src/macrogrok/) - Tavily β async HTTP RAG (
POST https://api.tavily.com/search,search_depth=advanced) - X algorithm β sparse/hybrid attention hook inside
attention_tc.cu(insert sparsity mask / linear state / IndexPool before/after WMMA)
Layout
Cargo.toml
src/
main.rs β tokio main, Transformer load, AttentionMemory, Tavily loop
memory.rs β AttentionMemory {k_cache, v_cache} [layers, heads, max_seq, head_dim]
attention.rs β TensorCoreAttention {forward()} (WMMA)
transformer.rs β TransformerConfig / Block / forward
tavily.rs β TavilyClient::search()
macrogrok/mod.rs β Q-format INFER4 Rust port (mirrors MACROGROK/src/sim.py)
cuda/
attention_tc.cu β WMMA kernel (QK^T + softmax + PV, head_dim tiling, smem)
tma_mbarrier.ptx β Hopper TMA + mbarrier bulk tensor (2D shared::cluster)
src/macrogrok/tests β fixed-point vectors
Build
# Cargo.toml excerpt
[dependencies]
cudarc = { version = "0.11", features = ["cuda-12000"] }
anyhow = "1"
tokio = { version = "1", features = ["full"] }
reqwest = { version = "0.12", features = ["json"] }
serde = { version = "1", features = ["derive"] }
half = "2"
bytemuck = "1"
cargo build --release
cargo test
# CUDA kernels: nvcc -arch=sm_80 -ptx cuda/attention_tc.cu -o attention_tc.ptx
# Run
TAVILY_API_KEY=... cargo run --release -- --prompt "hello"
python -m pytest # if Python harness tests
MACROGROK Harness
use macrogrok_harness::macrogrok::{infer4, Q1_14};
let input = [Q1_14(16384), Q1_14(0), Q1_14(0), Q1_14(0)];
let (output, score, flags) = infer4(input); // Q1.14, Q3.12, flags
Matches MACROGROK/examples/infer4.asm semantics: Q1.14*Q1.14>>4 accum Q3.24 β >>12 β +BIAS_Q3_12 β SAT β THRESHOLD β UPDATE_STATE_3_4 (3*STATE+TARGET)/4.
Transformer-X Loop
tokenize β Transformer::forward (QKV proj GEMM β TensorCoreAttention::forward β MLP)
β if tool call JSON β TavilyClient::search β inject β continue
β AttentionMemory grows (reset on overflow)
CUDA Notes
halfinputs,floataccumulator,scale=1/sqrt(head_dim), causal mask,__shfl_xormax/sum reductions,__float2halfstore viasmem_out(wmma::store_matrix_syncβ shared βhalf).- Head-dim tiling required for
head_dim>16(64/128): outerd_tileloops forQK^Treduction andAV. - Hopper TMA:
cp.async.bulk.tensor.2d.shared::cluster.global.mbarrier::complete_tx::bytes+mbarrier.init/arrive.expect_tx/try_wait(seecuda/tma_mbarrier.ptx). On Hoppercuda::memcpy_asynclowers to TMA when16-bytealigned + barrier in SMEM.
License
BSL-1.1 / AGPL-3.0 / MPL-2.0 β Patent Pending, BEL ESPRIT D ACCORD TRUST HOLDINGS INC.
Inference Providers NEW
This model isn't deployed by any Inference Provider. π Ask for provider support