Repository navigation
Neural-RX - #143
Draft
mbertuletti wants to merge 77 commits into
Draft
Neural-RX#143mbertuletti wants to merge 77 commits into
mbertuletti wants to merge 77 commits into
Conversation
Add fused depthwise and pointwise layer conv2d_f16
- Move attention_block into kernels/baremetal/mempool_attention_f16.h. - Multi-cluster: inline the layernorm and conv wrappers and at_cluster, move the VERIFY helpers into verify.h, add the section banners of the single-cluster app. - Single-cluster: size the L1 buffers with the TILESHIFT formulas also without TILESHIFT.
The runtime contains the headers of its default multi-cluster configuration (tensorpool, 256 cores, 16 RedMulE 8x32) in runtime/multi_cluster/arch. For other configurations, generate them with pulp/chips/mc_pool/common/utils/config.py in GVSoC and pass them with MC_ARCH_DIR. The build checks that the headers match num_cores and num_redmule_tiles, and takes the L1 bank size from them.
With -DCHECKSUM, core 0 fills l2_I and l2_F with deterministic fp16 values and prints a checksum of the output of every layer, to compare the results of two builds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- __VFCPKAHS wrote its result into the pointer argument, so the softmax constants (1, 0.5, 0.167) were uninitialized registers. - softmax and layernorm: pv.shuffle2.h with mask 0x00030002 is the identity, so the row maximum, sum and variance were not reduced across the two lanes. [a b] => [b a] is 0x00020003. - layernorm: the loads of the normalization loop were mislabeled, so elements j + 2, j + 3 of row i were normalized with the statistics of row i + 1 and stored to the other row. - permute_qkv read the QKV projection, [Beam][3 * Embed][tdSamples], as (b * Embed + e) * 3 * tdSamples: K and V of most channels came from the next beam, which the pipelined convolution may not have computed yet, so V depended on the timing. The rows of Q, K and V are b * 3 * Embed + e, + Embed, + 2 * Embed. With -DCHECKSUM, the serial and the pipelined (one attention round) builds now give the same output. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With -DVFEXP, both fp16 softmax kernels compute exp with vfexp.h (exp of each fp16 lane, 1000111 00001 rs1 010 rd 0110011) instead of the cubic Taylor series, 4 instructions instead of 28 per 4 x 2 elements. The softmax gets within 0.11% of the exact one (Taylor: 6.8% on inputs in [-1, 0]). l1_transformer_f16: 150,788 -> 145,540 cycles (-3.5%) (512 cores, 64 O-POPE 8x8, gvsoc; PIPELINED TILESHIFT ATTENTION_ROUNDS=2 LOG_BARRIER=5 VFEXP, B=128 E=32 T=32). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
conv1d_pipelined_im2col_f16 takes the im2col of a chunk as a callback (conv1d_pipelined_f16 passes the dense one). The pipelined output projection gathers its im2col directly from the attention output layout (im2col_att_ebt, im2col_att_tbe), so the "Permute result" pass is gone. Without RedMulEs, the callback now transforms the whole input before the GEMMs. l1_transformer_f16: 145,540 -> 142,901 cycles (-1.8%) (512 cores, 64 O-POPE 8x8, gvsoc; PIPELINED TILESHIFT ATTENTION_ROUNDS=2 LOG_BARRIER=5 VFEXP, B=128 E=32 T=32). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
layernorm_im2col_w3_parallel_2x4_f16vec writes the layernorm output as the 1D im2col (Wf = 3) of the convolution. With PIPELINED, l1_transformer passes it as the im2col callback of the QKV projection and of the FFN up-projection: the layernorm of a chunk overlaps with the GEMMs of the previous one, and the layernorm and im2col passes are gone. The output of these convolutions shares l1_arena with their input, so conv1d_pipelined_im2col_f16 now goes from the last chunk to the first when Co > Ci (from the first to the last otherwise): a chunk's output never overwrites input that is not transformed yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
conv1d_pipelined_f16 computes S convolutions, each reading the output of the previous one beam by beam, as one pipeline: the GEMM tasks are numbered stage by stage, chunk by chunk (one beam per RedMulE), and in round k the RedMulEs compute task k - 1 while the cores compute the im2col of task k. Consecutive stages only touch different chunks of a shared buffer within a round. With -DFUSE_CHAIN, l1_transformer_f16 runs the output projection, the FFN up-projection, the FFN down-projection (its im2col applies the gelu) and the QKV projection and permutation of the next layer as one chain (chain()): the pipeline fills and drains once per layer instead of once per convolution. attention() returns the attention output; the second one skips its input transfer and QKV projection. The weights of a layer are in l1_Fw. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With -DATTENTION_SOFTMAX_ONLINE, attention_block_f16 computes the softmax with softmax_online_parallel_2x4_f16vec: one pass for the running maximum and sum of exp(x - max), one for the output. It reads the scores twice instead of three times and writes Aw once instead of twice, which matters when the softmax runs next to the RedMulE jobs of the pipelined attention. l1_transformer_f16 with -DFUSE_CHAIN: 103,138 -> 97599 cycles (1024 cores, 64 O-POPE 8x8, gvsoc; PIPELINED TILESHIFT ATTENTION_ROUNDS=2 LOG_BARRIER=5 VFEXP, B=128 E=32 T=32). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mbertuletti
force-pushed
the
mbertuletti/neural_rx
branch
from
November 23, 2026 14:47
f9e81ea to
e21d1ea
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds software to run heterogeneous network layers and full neural receivers on TensorPool.
Added
nnlayersl1_transformer)Changed
blas,gnb,nnapplicationsChecklist