Skip to main content

Module tensor

Module tensor 

Source
Expand description

Tensor-extension intrinsics: TensorLoad, TensorLoadB, TensorFMA32, TensorStore, and TensorWait, all encoded as RISC-V CSR writes. Tensor-extension intrinsics for the ET-SoC-1 Minion core.

All tensor instructions on the ET-SoC-1 are encoded as standard RISC-V csrrw xd, <csr>, xs writes (see PRM Chapter 9). No custom opcode or target-feature extension is required: riscv64imac suffices because the operand registers are ordinary integer GPRs (the source value xs is an integer register; the FP register file is accessed implicitly by the tensor co-processor hardware, not by the instruction encoding).

§Concurrency model

The tensor co-processor operates independently of the RISC-V hart’s integer pipeline. Issuing a tensor instruction initiates an asynchronous operation; the hart must call [tensor_wait] with the appropriate [TensorEvent] before reading results or reusing the scratchpad. The ordering guarantees are:

  • TensorWait(Load0) before tensor_fma32: scratchpad A is populated.
  • TensorWait(Fma) before tensor_store: FP register file holds final C.
  • fence rw, rw (via crate::fence) after tensor_store: stores are visible to other Minions and the DMA engine before the kernel returns.

§Scratchpad layout

Each Minion has a private 48-line L1 scratchpad (3 072 bytes). Only the primary hart of the Minion (hart 0, i.e. mhartid & 1 == 0) should issue tensor load/store/FMA instructions; the companion hart (hart 1) must not touch the same scratchpad lines concurrently.

Structs§

TensorError
Tensor co-processor error status, returned by check_tensor_error.

Enums§

TensorEvent
Tensor co-processor synchronisation events for tensor_wait.

Constants§

CSR_TENSOR_ERROR
TensorError CSR (tensor_error): latched error flags from the co-processor. (PRM Table 9-1: 0x808, not 0x831)
CSR_TENSOR_FMA
TensorFMA CSR (tensor_fma): selects the FMA variant via xs bits 3:1. (PRM Table 9-7: TensorFMA32 = 3:1 000, TensorFMA16A32 = 001, …)
CSR_TENSOR_LOAD
TensorLoad / TensorLoadB CSR (tensor_load): load from memory to the L1 scratchpad (xs bit 52 = 0) or to the TenB register file (bit 52 = 1).
CSR_TENSOR_LOAD_L2
TensorLoadL2Scp CSR: loads rows from memory to the shire L2 cache without consuming any L1 scratchpad lines. Useful for prefetching A strips while the current k-loop tile executes, so the subsequent tensor_load (L1 fill) completes from L2 rather than DRAM.
CSR_TENSOR_MASK
TensorMask CSR (tensor_mask): per-row enable bits for the A tile. (PRM Table 9-1: 0x805, not 0x832)
CSR_TENSOR_STORE
TensorStore CSR (tensor_store): store from FP registers (bit 48 = 0) or from the L1 scratchpad (bit 48 = 1 = TensorStoreFromScp) to memory. (PRM Table 9-7: 0x87F, not 0x83E)
CSR_TENSOR_WAIT
TensorWait CSR (tensor_wait): stalls the hart until the requested event.

Functions§

check_tensor_error
Check the tensor co-processor error register and return a typed result.
fma32_xs
Build the xs value for a TensorFMA32 instruction.
set_tensor_mask
Write the per-row enable mask for the next TensorFMA.
tensor_error
Read the tensor co-processor error status register.
tensor_fma32
Initiate an asynchronous TensorFMA32.
tensor_load
Initiate an asynchronous TensorLoad from memory into the L1 scratchpad.
tensor_load_b
Initiate an asynchronous TensorLoadB from memory into the TenB register file.
tensor_load_l2
Initiate an asynchronous TensorLoadL2Scp from memory into the shire L2 cache.
tensor_store
Initiate an asynchronous TensorStore from the FP register file to memory.
tensor_wait
Stall the hart until the specified tensor co-processor event fires.