Skip to main content

Module codegen_tt

Module codegen_tt 

Source
Expand description

LOGOS → Tenstorrent (TT-Metalium) AOT codegen tier. Emits a complete single-Tensix-core TT-Metalium program — a host orchestrator plus a data-movement compute kernel that runs on one baby RISC-V core (DataMovementProcessor::RISCV_0) — for the scalar-compute fragment of the benchmark suite.

§Why the C backend is the compute source

A Tensix baby core is a RISC-V CPU and a TT-Metalium kernel is C++; the canonical add_2_integers_in_riscv kernel is literally dat0[0] = dat0[0] + dat1[0]. So the kernel’s compute body is the SAME self-contained C the crate::codegen_c backend already emits — which is byte-for-byte ≡ the VM (locked by assert_c_output). The Tenstorrent tier does not re-lower arithmetic; it wraps that proven compute in the TT-Metalium host/kernel split and routes Show to the host DPRINT stream. See wrap.

§What is verified, and when

  • Pre-hardware (now, no card): the compute is executably ≡ VM via the C oracle (TtArtifact::oracle_c, run through gcc exactly like the C tier), and the emitted host/kernel/CMake carry the correct TT-Metalium API surface.
  • On-hardware (Phase 5, gated on a Wormhole/Blackhole card + tt-metal SDK): the host+kernel build against tt-metal and run on the Tensix core, DPRINT output compared to the VM. That path is #[ignore]d until TT_METAL_HOME is present, so nothing here fabricates an on-silicon result.

§Totality discipline (mirrors the RISC-V / WASM tiers)

Any program using an op outside the single-baby-core fragment — CONCURRENCY (channels/tasks/select, which need a ucontext scheduler + multiple contexts; the genuine multi-baby-core mesh tier in concurrency_mesh lowers those) — returns TtLowerError::Unsupported: a SOUND refusal, never a miscompile. OFFLINE networking (TT_NET_OPS) is served on-core through the newlib-clean C net runtime (wrapped verbatim). The tenstorrent_op_coverage_lock ratchet forces the off-core set onto a shrink-only ledger so nothing is silently dropped.

Modules§

concurrency_mesh
LOGOS concurrency pattern RECOGNIZERS — the source-reading half of the concurrency tier.
matmul_lower
Genuine LOGOS → Tensix matrix-engine lowering — an AFFINE GEMM-idiom recognizer.

Structs§

TtArtifact
A complete single-Tensix-core TT-Metalium program emitted from a LOGOS program.

Enums§

TtLowerError
An op / shape outside the current phase’s single-baby-core fragment. The &str names what is not yet lowered. A refusal — the backend declines to emit rather than emit wrong code (mirrors crate::codegen_riscv::RiscVLowerError).

Constants§

KERNEL_FILE_NAME
The single canonical name of the generated kernel source (referenced by the host CreateKernel call and the CMake glue).
TT_HOST_TEMPLATE
The host orchestrator. Opens a 1x1 unit mesh on device 0, creates a program with a single data-movement kernel on RISCV_0, launches it, waits, and closes. Targets the current TT-Metalium MeshDevice API (as in the add_2_integers_in_riscv example). {KERNEL_FILE} is the kernel source path.
TT_KERNEL_PREAMBLE
Prepended to the LOGOS→C compute body to form the compute kernel. Brings in the TT-Metalium data-movement + DPRINT APIs and bridges the C backend’s printf/puts (how Show is emitted) to the host DPRINT stream, so kernel output is textually identical to the VM’s.
TT_NET_OPS
The OFFLINE NETWORKING ops the single Tensix baby core serves via the loopback transport (crate::codegen_c’s C_NET_RUNTIME, wrapped verbatim). Connect/Listen/Sync are no-ops, MakePeer is identity, Send/Stream enqueue a 64-bit message into a per-address FIFO, Await dequeues it. That runtime is newlib-clean (strcmp/strdup + static arrays — no ucontext, unlike the concurrency runtime), so it rides the SAME wrap the scalar body does and a single-node Send X to peer; Await … round-trips ≡ the VM’s offline NetInbox. Every op here is crate::aot_unsupported::Offload::Net; excluded from the refusal below (device-served, not host-only). The CUDA analogue is codegen_cuda::CUDA_NET_OPS; bound by tenstorrent_op_coverage_lock.

Functions§

codegen_program_tt
Emit program as a single-Tensix-core TT-Metalium program. oracle_c is the self-contained C translation of the SAME program (from crate::compile::compile_to_c); its compute body becomes the kernel. Returns TtLowerError::Unsupported if the program uses any op outside the single-baby-core fragment.
unsupported_reason
Returns Some(reason) if program uses an op that cannot run on a single Tensix baby core in this phase — concurrency (a Tensix mesh is SPMD, not a shared-memory thread pool with a scheduler; the concurrency runtime needs ucontext, which a baby core has no libc for). Everything else — including single-replica CRDT counters (in-memory maps in the C body) and the OFFLINE networking loopback (TT_NET_OPS, the newlib-clean C_NET_RUNTIME) — lowers through the proven C compute body. Sleep is virtual-time (a scheduler primitive) and is refused with the concurrency set.
wrap_as_tt
Build the TT-Metalium artifact from the self-contained C translation of the program. The C body is reused verbatim except: system #include <...> lines are dropped (the kernel preamble supplies the on-core headers) and main is renamed to logos_main, which kernel_main invokes.