File size: 11,979 Bytes
b7e49b8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | // SPDX-License-Identifier: Apache-2.0
//
// DepthPro2 DEC megakernel: fixed ids shared by the three RISC kernels AND the host (plan.py parses every
// `constexpr uint32_t NAME = <int>;` line of this file; one definition per line, integer literals only).
// Everything shape dependent (maps, layers, unit decomposition) is the plan table in the compile-time args.
#pragma once
#include <cstdint>
namespace mdx {
// ---------------------------------------------------------------- circular buffers
constexpr uint32_t CB_W = 0; // bf16 weight ring (NCRISC -> TRISC), pages of PAGE_TILES tiles
constexpr uint32_t CB_BAND = 1; // raw: the unit's ROW_MAJOR input band (one page = the whole band; BRISC -> TRISC)
constexpr uint32_t CB_TAPA = 2; // bf16 view of CB_BAND's memory: RA A tiles (BRISC -> TRISC), full-capacity cycles
constexpr uint32_t CB_A = 3; // bf16 tilized A tiles of one k-block (TRISC internal), full-capacity cycles
constexpr uint32_t CB_RES = 4; // raw: one ROW_MAJOR residual band (one page; BRISC -> TRISC)
constexpr uint32_t CB_ACC = 5; // fp32 accumulators of one unit (TRISC internal, UnpackToDestFp32), full cycles
constexpr uint32_t CB_OUT = 6; // bf16 ROW_MAJOR output blocks (32 rows x NBW tiles; TRISC -> BRISC), 2 x 8 pages
constexpr uint32_t CB_CONST = 7; // bf16 constants (C_*)
constexpr uint32_t CB_SEL = 8; // bf16 HC bias selector tiles of the unit (BRISC -> TRISC), full-capacity cycles
constexpr uint32_t CB_Z = 9; // bf16 HC: relu(head.2) of one M tile, the 4 sub-pixel tiles (TRISC internal)
constexpr uint32_t CB_HO = 10; // fp32 HC: one output tile, rows 0..3 = sub-pixels (TRISC -> BRISC), 2 pages
constexpr uint32_t CB_SYNC = 11; // raw: sync words + BRISC staging
constexpr uint32_t CB_PLAN = 12; // raw: the plan table (BRISC loads it from DRAM at boot; every RISC reads it)
// ---------------------------------------------------------------- constants (CB_CONST tile index, bf16)
constexpr uint32_t C_E01 = 0; // ones in columns 0 and 1: in0 of a bias tile (rows 0 / 1 = bias hi / lo)
constexpr uint32_t C_I = 1; // identity
constexpr uint32_t C_W4H = 2; // 2 .. 5: head.4 weight hi in row s (s = sub-pixel 2a + b)
constexpr uint32_t C_W4L = 6; // 6 .. 9: head.4 weight lo in row s
constexpr uint32_t C_E4 = 10; // ones at (s, 0) and (s, 1) for s < 4: in0 of the head.4 bias
constexpr uint32_t C_B4T = 11; // column 0 = head.4 bias hi, column 1 = lo (all rows): in1 of the transposed matmul
constexpr uint32_t N_CONST = 12;
// ---------------------------------------------------------------- ops
constexpr uint32_t OP_RA = 0; // 1x1 conv on the tapped tokens (TILE) -> ROW_MAJOR map
constexpr uint32_t OP_C3 = 1; // 3x3 conv (stride L_S 1 or 2, pad 1) [+ residuals], ROW_MAJOR -> ROW_MAJOR
constexpr uint32_t OP_UP = 2; // per-pixel matmul + depth-to-space (k = L_S): conv-transpose k x k stride k
constexpr uint32_t OP_HC = 3; // composite head: head.1 (convT k2s2) o head.2 (3x3) + relu + head.4 (1x1) + relu
// layer flags
constexpr uint32_t F_RELU_IN = 1;
constexpr uint32_t F_RELU_OUT = 2;
constexpr uint32_t F_BIAS = 4;
// ---------------------------------------------------------------- plan table (compile-time args from MD_PB)
// header
constexpr uint32_t H_NL = 0; // layers
constexpr uint32_t H_NM = 1; // maps
constexpr uint32_t H_G = 2; // frames per group
constexpr uint32_t H_NGRP = 3; // frame groups
constexpr uint32_t H_PT = 4; // patch tiles per frame (Np / 32)
constexpr uint32_t H_N = 5; // patches per frame
constexpr uint32_t H_GW = 6; // token grid width
constexpr uint32_t H_HP = 7; // padded frame height (output)
constexpr uint32_t H_WP = 8; // padded frame width (output)
constexpr uint32_t H_RING = 9; // weight ring pages
constexpr uint32_t H_KX_HC = 10; // HC: x tiles per row (Sel tiles per row class)
constexpr uint32_t NHF = 16;
// map fields
constexpr uint32_t M_H = 0;
constexpr uint32_t M_W = 1;
constexpr uint32_t M_WP = 2; // storage pixels per image row (ceil32(W + 1): rows start on DRAM pages)
constexpr uint32_t M_C = 3; // channels (multiple of 32)
constexpr uint32_t M_B0 = 4; // storage pixel of (0, 0)
constexpr uint32_t M_FPG = 5; // pages per frame (32 storage pixels per page)
constexpr uint32_t M_ARG = 6; // common runtime arg holding the map's DRAM address
constexpr uint32_t NMF = 8;
// layer fields
constexpr uint32_t L_OP = 0;
constexpr uint32_t L_SRC = 1; // map id (RA: tap index)
constexpr uint32_t L_DST = 2; // map id (HC: unused)
constexpr uint32_t L_RES0 = 3; // residual map ids
constexpr uint32_t L_RES1 = 4;
constexpr uint32_t L_NRES = 5;
constexpr uint32_t L_FLAGS = 6;
constexpr uint32_t L_S = 7; // C3: stride; UP: k
constexpr uint32_t L_CT = 8; // input channel tiles (RA: tap K tiles)
constexpr uint32_t L_KC = 9; // channel tiles per k-block
constexpr uint32_t L_NKB = 10; // k-blocks
constexpr uint32_t L_N = 11; // output tiles (N)
constexpr uint32_t L_NBW = 12; // tiles per n-block
constexpr uint32_t L_NBO = 13; // n-block groups split over grid-row groups
constexpr uint32_t L_NBI = 14; // n-blocks per group, iterated inside a unit
constexpr uint32_t L_BH = 15; // unit rows (RA: M tiles per unit)
constexpr uint32_t L_BW = 16; // unit x tiles
constexpr uint32_t L_YB = 17; // row blocks per frame
constexpr uint32_t L_XB = 18; // x blocks per row
constexpr uint32_t L_U = 19; // units
constexpr uint32_t L_WPG = 20; // first weight-arena page of the layer
constexpr uint32_t L_BP0 = 21; // pages of the k-block 0 block (incl. bias / selector-bias tiles)
constexpr uint32_t L_BP = 22; // pages of the other k-blocks
constexpr uint32_t L_HO = 23; // output rows (C3 / HC: map rows; UP: input rows)
constexpr uint32_t L_WO = 24; // output width
constexpr uint32_t L_KXO = 25; // M tiles per output row (ceil(WO / 32))
constexpr uint32_t L_BANDP = 26; // band row pitch (bytes)
constexpr uint32_t L_NBIAS = 27; // bias tiles at the start of the k-block 0 block
constexpr uint32_t L_ACC = 28; // 1: fp32 L1 accumulators (CB_ACC); 0: pack straight from DST
constexpr uint32_t L_ROW0 = 29; // the layer runs on grid rows [ROW0, ROW0 + NROWS) (phase merging)
constexpr uint32_t L_NROWS = 30;
constexpr uint32_t L_BAR = 31; // 1: global barrier after the layer (end of its phase)
constexpr uint32_t L_PAIR = 32; // 1: kc == 1 k-blocks tilized in pairs (plan.pair_mode)
constexpr uint32_t L_BOFF = 33; // C3 / HC: byte offset of band row data (x = -1) after the left 2 KB edge chunk slack
constexpr uint32_t L_KPX = 34; // C3 / HC: pixels of one band edge chunk (>= 2 KB DRAM read)
constexpr uint32_t NLF = 40;
// ---------------------------------------------------------------- sync words (CB_SYNC, SYNC_STRIDE bytes apart)
constexpr uint32_t SYNC_STRIDE = 16;
constexpr uint32_t W_BAR = 0; // every core: global barrier generation (hub multicast)
constexpr uint32_t W_BCNT = 1; // hub: barrier arrivals (cumulative)
constexpr uint32_t W_WVAL = 2; // ring receiver: weight pages valid (feeder multicast, cumulative)
constexpr uint32_t W_CRED = 4; // feeder: 4 + x = pages receiver column x has room for (cumulative), x < 16
constexpr uint32_t W_SRC = 20; // 20 .. 23: local source words of the flag multicasts
constexpr uint32_t W_SRCV = 24; // 24 .. 31: the feeder's source words of the W_WVAL multicasts (ring of 8)
constexpr uint32_t N_SRCV = 8;
constexpr uint32_t W_DBG = 32; // 32 .. 47: abort diagnostics: +0 BRISC code, +1 its arg, +2 NCRISC code, +3 arg,
// +4/+5 TRISC unpack code/arg, +6/+7 pack code/arg, +8 BRISC layer, +9 unit
constexpr uint32_t N_SYNC = 48;
constexpr uint32_t SYNC_STG = 768; // byte offset of the BRISC staging area in CB_SYNC (2 KB debug page)
constexpr uint32_t SYNC_PROF = 2816; // byte offset of the PROF_WORDS profile words in CB_SYNC
constexpr uint32_t SYNC_BYTES = 3840;
constexpr uint32_t MIN_REQ = 2048; // every DRAM request of the map / output traffic is >= 2 KB (Blackhole SYS-1419)
constexpr uint32_t DBG_PAGE = 512; // uint32 words of one core's debug page (2 KB DRAM write)
// abort codes (a bounded wait gave up: the program finishes with garbage instead of hanging the device)
constexpr uint32_t AB_FRONT = 1; // wait for pages (arg: cb)
constexpr uint32_t AB_BACK = 2; // wait for room (arg: cb)
constexpr uint32_t AB_SYNC = 3; // sync word (arg: word)
constexpr uint32_t AB_PLAN = 4; // plan table
constexpr uint32_t AB_CRED = 5; // feeder credits
constexpr uint32_t AB_NOC = 6; // NoC barrier (arg: 1 reads, 2 write acks, 3 writes sent, 4 atomics)
constexpr uint32_t AB_PEER = 7; // another RISC of this core aborted (core abort word W_ABORT)
constexpr uint32_t W_ABORT = 44; // core abort word: any RISC that aborts sets it, every wait of every RISC polls it
constexpr uint32_t ABORT_MAGIC = 0xAB0A7E11u; // W_ABORT value (stale garbage from other programs never matches)
constexpr uint32_t W_EXIT = 45; // exit-hygiene outcome bits (BRISC 1 / NCRISC 2: final barriers timed out)
// ---------------------------------------------------------------- roles (A_ROLE bits)
constexpr uint32_t R_FEED = 1; // weight feeder of its grid row (column 0)
constexpr uint32_t R_HUB = 2; // global barrier hub
// ---------------------------------------------------------------- per-core runtime args
constexpr uint32_t A_IDX = 0;
constexpr uint32_t A_ROLE = 1;
constexpr uint32_t A_X = 2;
constexpr uint32_t A_Y = 3;
constexpr uint32_t A_ROWX0 = 4; // NoC x of logical columns 1 / C - 1 (feeder multicast rectangle)
constexpr uint32_t A_ROWX1 = 5;
constexpr uint32_t A_ROWY = 6; // NoC y of this core's row
constexpr uint32_t A_FX = 7; // NoC x / y of the row feeder
constexpr uint32_t A_FY = 8;
constexpr uint32_t N_RT_ARGS = 9;
// ---------------------------------------------------------------- common runtime args
constexpr uint32_t K_ALL_X0 = 0; // whole-grid rectangle (NoC)
constexpr uint32_t K_ALL_Y0 = 1;
constexpr uint32_t K_ALL_X1 = 2;
constexpr uint32_t K_ALL_Y1 = 3;
constexpr uint32_t K_N_ALL = 4;
constexpr uint32_t K_HUB_X = 5;
constexpr uint32_t K_HUB_Y = 6;
constexpr uint32_t K_NL = 7; // layers run (all = the whole stage; fewer = debug)
constexpr uint32_t K_WTS = 8; // weight arena (ROW_MAJOR pages of PAGE_TILES bf16 tiles)
constexpr uint32_t K_CONST = 9; // bf16 constants [N_CONST * 32, 32] TILE
constexpr uint32_t K_SEL = 10; // bf16 HC selector tiles [3 * KX_HC * 32, 32] TILE
constexpr uint32_t K_OUT = 11; // inverse depth fp32 [T, Hp, Wp] TILE
constexpr uint32_t K_TAP0 = 12; // 12 .. 15: taps [T * Np, C] bf16 TILE
constexpr uint32_t K_PLANA = 16; // plan table (uint32 ROW_MAJOR, one page)
constexpr uint32_t K_PLANB = 17; // plan table bytes
constexpr uint32_t K_DBG = 18; // uint32 [NC, DBG_PAGE] ROW_MAJOR (first DBG_WORDS used): per-core abort diagnostics (W_DBG words)
constexpr uint32_t K_SPIN = 19; // spin-wait bound (iterations) before a wait aborts (hang protection)
constexpr uint32_t K_PROF = 20; // uint32 [NC, PROF_WORDS] ROW_MAJOR: per-layer time stamps (MD_PROF builds)
constexpr uint32_t K_MAP0 = 21; // 21 .. : map addresses
constexpr uint32_t N_COMMON_FIXED = 21;
constexpr uint32_t PROF_WORDS = 256; // 8 per layer: brisc work done, barrier exit, trisc w_wait, in_wait, tilize,
// mm, epilogue (accumulated ticks), spare
constexpr uint32_t DBG_WORDS = 16;
// ---------------------------------------------------------------- compile-time args
constexpr uint32_t CT_ACC0 = 0; // TensorAccessorArgs (DRAM interleaved; page size given per use)
constexpr uint32_t PAGE_TILES = 8;
constexpr uint32_t T16 = 2048;
constexpr uint32_t T32 = 4096;
constexpr uint32_t OUT_CAP = 16; // CB_OUT pages (2 x the largest NBW)
} // namespace mdx
|