diff --git a/.crumb b/.crumb index f82176156..75e7cabc9 100644 --- a/.crumb +++ b/.crumb @@ -87,14 +87,14 @@ "purpose": "Directory spec. Purpose not yet described by a human." }, { - "digest": "8979f28ba007e73c18d12f0a2a26b3a4b91c9eaaadcd8e35de14424bbd2c0165", - "last_commit": "d9457e55", + "digest": "e68f3e4b6e3f06cf4344bf8e57eb0b1d14e8ccefc9e0047bca02e4e68954840e", + "last_commit": "fa60e89a", "name": "src", "purpose": "Directory src. Purpose not yet described by a human." }, { - "digest": "77baf947bf422344b099c312f5895e8491f5d91c97758ff2ed1a7672dc408114", - "last_commit": "d9457e55", + "digest": "0713f610eacc8c4279a0f58379d061a1ec57ca60efd1595fb6fc91868fda5c23", + "last_commit": "fa60e89a", "name": "tests", "purpose": "Directory tests. Purpose not yet described by a human." }, @@ -105,15 +105,15 @@ "purpose": "Directory tools. Purpose not yet described by a human." } ], - "children_root": "sha256:fb999b2f5cbdc5418bdc94f84e76def14aaf9a3e292d55340b66adc0ecf50c34", - "compiled_at": "2026-10-11T19:30:27Z", + "children_root": "sha256:39a1eb06a2eff06139365aa02b6136288c2b6fb58f7301d376943b64b6160445", + "compiled_at": "2026-10-12T05:17:54Z", "compiler": "crumb-compile/1", - "digest": "sha256:9d820a868a485dc258c4fd7f55e61d86cc72013e304d546518b193f34936f62b", + "digest": "sha256:66f21b04513a8f6d947c440633c416039a7be2126ed0b6056c7356e9dc4184c6", "evidence_files": 7245, "evidence_root": "sha256:035beef5cdb99afaefd1743640f5e7eeaaed13c4a5ec6c8b4b6a4cb0c528407a", "files": 9732, - "generated_at_commit": "8507ac948f46e305d1108520cabaed75f110695d", - "source_tree": "sha256:b40e5da20ac4e6c3f57e2b4bb2502fd8bf7cb3dd6b5398c1b4497c23df07ff32" + "generated_at_commit": "6e6f1c8e27b4f3a511bb284e7f51f2a957863ded", + "source_tree": "sha256:2525062496c1e32058276076772ebca47d19e3bee1d0566050226e6d5934f9ae" }, "owner_lane": "", "provenance": { diff --git a/calibration/.crumb b/calibration/.crumb index 3b8c3da72..53062b041 100644 --- a/calibration/.crumb +++ b/calibration/.crumb @@ -34,43 +34,43 @@ "children": [ { "digest": "e2e9d7d77533c89d8cc919746832ad00529cb86d65c996217bc5348e521dabc7", - "last_commit": "ae1dd00", + "last_commit": "ae1dd00a", "name": "docs", "purpose": "Directory calibration/docs. Purpose not yet described by a human." }, { "digest": "6b36741c5f34a363b7e8cd3c29f8b3f0d43acbb3c2cddd3f5b9ebbade3f85d25", - "last_commit": "1cff526", + "last_commit": "1cff5260", "name": "preregistration", "purpose": "Directory calibration/preregistration. Purpose not yet described by a human." }, { "digest": "8af50fb73adf0c6bc10d02dfdcac403b5c3039d35fd6b46061fe324f38f411d8", - "last_commit": "92750b5", + "last_commit": "92750b58", "name": "profiles", "purpose": "Directory calibration/profiles. Purpose not yet described by a human." }, { "digest": "d3e110eae40e5c48b4242c0a3e3d595178cd822cc0510bdb09ce2bfc29146ba3", - "last_commit": "c803862", + "last_commit": "c803862f", "name": "schemas", "purpose": "Directory calibration/schemas. Purpose not yet described by a human." }, { "digest": "7da9b50a75b326141d535cf9e56e31d51437da93d85bf0556e6f61720810a430", - "last_commit": "87f3e8b", + "last_commit": "87f3e8b8", "name": "scripts", "purpose": "Directory calibration/scripts. Purpose not yet described by a human." } ], "children_root": "sha256:e58b9cc78de81a51c7ed21c725616ddb80bd3d24d171b24a189e8f7132499433", - "compiled_at": "2026-10-04T13:47:05Z", + "compiled_at": "2026-10-12T05:17:54Z", "compiler": "crumb-compile/1", "digest": "sha256:fb7cc6e608fdbe68a9735a1313285782b9717ff12bde17343f8ce635de3644f6", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 110, - "generated_at_commit": "834ee93e4314a42c1127a2fcda8b29cf3b511245", + "generated_at_commit": "6e6f1c8e27b4f3a511bb284e7f51f2a957863ded", "source_tree": "sha256:b39f40915ce2ed4092ade2a38665d99f6daab78fd462433177cdd0aec5f00bd7" }, "owner_lane": "", diff --git a/docs/.crumb b/docs/.crumb index 3f24fdb1e..17a27d1cb 100644 --- a/docs/.crumb +++ b/docs/.crumb @@ -118,13 +118,13 @@ } ], "children_root": "sha256:97cd6e4730ccdf9dd75f0481c7506cb88dd2b5c66d140438973edd3fbfbb1e9e", - "compiled_at": "2026-10-10T03:04:12Z", + "compiled_at": "2026-10-12T05:17:54Z", "compiler": "crumb-compile/1", "digest": "sha256:24d7c03a26a7ffe9b181b73585480b5801289accbdf63146edbc36cf3e1cf21f", "evidence_files": 34, "evidence_root": "sha256:589d8b3706e6d7a202ab20b278dac5fc5bafc973f1c2a867b2668aa7210b65cc", "files": 118, - "generated_at_commit": "6637b32b6bf9942ab624ec7e95fd1576f3abe909", + "generated_at_commit": "6e6f1c8e27b4f3a511bb284e7f51f2a957863ded", "source_tree": "sha256:22bb817cd659d6a4345b0d411cb903b0300bc2150117e1c1a1f120e76163f077" }, "owner_lane": "", diff --git a/docs/estimation/.crumb b/docs/estimation/.crumb index 795b246ae..fcd45cb12 100644 --- a/docs/estimation/.crumb +++ b/docs/estimation/.crumb @@ -18,19 +18,19 @@ "children": [ { "digest": "09ae7f9b04e4639bc444223a5566e755c4eadcd517cc57a95a454e9f27c34edf", - "last_commit": "f6390e8", + "last_commit": "f6390e88", "name": "reviews", "purpose": "Directory docs/estimation/reviews. Purpose not yet described by a human." } ], "children_root": "sha256:35cd3af03e079556db7f3ebcfd7590fa68659e84dd603795ae6b5b048dc2af0d", - "compiled_at": "2026-10-05T15:40:51Z", + "compiled_at": "2026-10-12T05:17:54Z", "compiler": "crumb-compile/1", "digest": "sha256:56a5a999ce726e90d89c1c88b9e20c81857c8e6ee82af8d651ac80ea70e2c46d", "evidence_files": 34, "evidence_root": "sha256:589d8b3706e6d7a202ab20b278dac5fc5bafc973f1c2a867b2668aa7210b65cc", "files": 47, - "generated_at_commit": "25311c0c2aee4eb4991052115d9ad91f5b4d2a1e", + "generated_at_commit": "6e6f1c8e27b4f3a511bb284e7f51f2a957863ded", "source_tree": "sha256:67ae8d20aca3ae36b8cf0d75c6939058cc9ff8762c977f70d6963c545e3215d8" }, "owner_lane": "", diff --git a/research/.crumb b/research/.crumb index 60eb8236f..02ccd14e3 100644 --- a/research/.crumb +++ b/research/.crumb @@ -22,7 +22,7 @@ "children": [ { "digest": "027eb4c8d53b989a45c9e586c8d7969ae6ebd5a64eb29014d041751cf6ea7fa5", - "last_commit": "0863d99e", + "last_commit": "c02b278c", "name": "atemporal", "purpose": "AT-0 Clock-Free Universe research program: relational (Page-Wootters) quantum models with no ext" }, @@ -34,13 +34,13 @@ } ], "children_root": "sha256:54838f75d8f7fecca1b4510a4a96e342b98d9ffdcd24b211c890673c2b3744f2", - "compiled_at": "2026-10-10T06:28:38Z", + "compiled_at": "2026-10-12T05:17:54Z", "compiler": "crumb-compile/1", "digest": "sha256:2aa8396144fa241f695a99c882fc347425604ac4822d5162be9c3ad80354fc9f", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 538, - "generated_at_commit": "0863d99ec730f261951b90ec984e9e3924e64c57", + "generated_at_commit": "6e6f1c8e27b4f3a511bb284e7f51f2a957863ded", "source_tree": "sha256:2b75722935643d20739b1553a1dca48917714a788be7eef82940ac28cb4aaf91" }, "owner_lane": "", diff --git a/research/atemporal/.crumb b/research/atemporal/.crumb index 85a16bb55..7e5042cab 100644 --- a/research/atemporal/.crumb +++ b/research/atemporal/.crumb @@ -10,13 +10,13 @@ } ], "children_root": "sha256:f7bd1d7019a69ef57140cd019f86634f3cb80c1e31ca3063dfdf73ac9deef7c6", - "compiled_at": "2026-10-10T06:28:38Z", + "compiled_at": "2026-10-12T05:17:54Z", "compiler": "crumb-compile/1", "digest": "sha256:027eb4c8d53b989a45c9e586c8d7969ae6ebd5a64eb29014d041751cf6ea7fa5", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 392, - "generated_at_commit": "0863d99ec730f261951b90ec984e9e3924e64c57", + "generated_at_commit": "6e6f1c8e27b4f3a511bb284e7f51f2a957863ded", "source_tree": "sha256:31b6cfb5b0eb744d75c1830a0108d73210ba64af139b84882cfc9eb48054ec35" } }, diff --git a/research/m15/spbm/.crumb b/research/m15/spbm/.crumb index 51098e03e..0a477f636 100644 --- a/research/m15/spbm/.crumb +++ b/research/m15/spbm/.crumb @@ -13,13 +13,13 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-04T18:19:24Z", + "compiled_at": "2026-10-12T05:17:54Z", "compiler": "crumb-compile/1", "digest": "sha256:baf4a6094854fe437a8880b2c90733bbf9048212af7f7b45381db4050d8e128c", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 129, - "generated_at_commit": "cfd67162853eb0c0fbb73758e3dfb9837676e2a2", + "generated_at_commit": "6e6f1c8e27b4f3a511bb284e7f51f2a957863ded", "source_tree": "sha256:4b183d9ff80e7d0e7c8ab2925b20c1a8072ffbfa3c6d14d3c1024c1796eb3f5c" }, "owner_lane": "", diff --git a/src/.crumb b/src/.crumb index f193dd2e7..5508890c5 100644 --- a/src/.crumb +++ b/src/.crumb @@ -140,7 +140,7 @@ }, { "digest": "224f473d0d4da21fb7bcd75d22e70a892679a7271e949a5ee07e3f36cbdb7442", - "last_commit": "d9457e55", + "last_commit": "781e98d8", "name": "runtime", "purpose": "Directory src/runtime. Purpose not yet described by a human." }, @@ -176,14 +176,14 @@ } ], "children_root": "sha256:ce7e4b528bec54e15d5f9525026d958e6eab78b88614c65b8e7c51d44c0243af", - "compiled_at": "2026-10-11T19:30:27Z", + "compiled_at": "2026-10-12T05:08:10Z", "compiler": "crumb-compile/1", - "digest": "sha256:8979f28ba007e73c18d12f0a2a26b3a4b91c9eaaadcd8e35de14424bbd2c0165", + "digest": "sha256:e68f3e4b6e3f06cf4344bf8e57eb0b1d14e8ccefc9e0047bca02e4e68954840e", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 451, - "generated_at_commit": "8507ac948f46e305d1108520cabaed75f110695d", - "source_tree": "sha256:a8baea783661d7614b6663e0806910d9f6cbae24a0657f6883a34d5e64b21d6b" + "generated_at_commit": "fa60e89a1e349a9cb33e6b0d7b548190496b2c40", + "source_tree": "sha256:f756c580cf486797b0ba4cb905f784fa68004d7249e302704a9112dac908ab0b" }, "owner_lane": "", "provenance": { diff --git a/src/omega_blackwell_codegen.c b/src/omega_blackwell_codegen.c index 1ed52ba13..162b23c31 100644 --- a/src/omega_blackwell_codegen.c +++ b/src/omega_blackwell_codegen.c @@ -735,6 +735,19 @@ static int encode_single_insn(const BlackwellIRInsn *insn, const OmegaRegAlloc * w[3] = insn->control ? insn->control : 0x000fec00; break; + case BW_IR_LDS128: { + /* LDS.128 Rd..Rd+3, [Ra+imm]. nvcc 13.0.88 -arch=sm_121 words (fixtures below): + * LDS.128 R4, [R20] ; 0x0000000014047984 0x000fe80000000c00 + * LDS.128 R8, [R20+0x40] ; 0x0000400014087984 0x000e280000000c00 + * imm = byte offset at w[1] bits 8..31; size field 6 (128) at w[2] bits 9..11. */ + if (insn->imm >= (1u << 23)) return -1; + w[0] = 0x7984U | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24); + w[1] = (insn->imm & 0xffffffU) << 8; + w[2] = 0x00000c00U; + w[3] = insn->control ? insn->control : 0x000fe800; + break; + } + case BW_IR_LDS32: /* LDS Rd, [Ra+URZ] (32-bit), the src/omega_numeric.c:886 form. */ w[0] = 0x7984U | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24); @@ -859,6 +872,11 @@ int omega_blackwell_verify_codegen_fixtures_fragmm(void) { { BW_IR_LDG_E_128, 20, 32, -1, -1, 8, 0x1000, 0, 0x20147981U, 0x00100008U, 0x0c1e1d00U, 0, "LDG.E.128 R20, desc[UR8][R32.64+0x1000]" }, { BW_IR_HMMA_BF16, 8, 12, 6, 8, -1, 0, 0, 0x0c08723cU, 0x00000006U, 0x00041808U, 0, "HMMA.16816.F32.BF16 R8, R12, R6, R8" }, { BW_IR_NOP, -1, -1, -1, -1, -1, 0, 0x000fdc00U, 0x00007918U, 0, 0, 0x000fdc00U, "NOP (stall 14)" }, + /* LDS.128 with an immediate offset (attention batched loads, 2026-10-12): nvcc 13.0.88 -arch=sm_121 on + * float4 shared reads at register + constant offsets (fixture source in the omega speed/attention-batched-loads PR) */ + { BW_IR_LDS128, 4, 20, -1, -1, -1, 0, 0, 0x14047984U, 0x00000000U, 0x00000c00U, 0, "LDS.128 R4, [R20]" }, + { BW_IR_LDS128, 8, 20, -1, -1, -1, 0x40, 0, 0x14087984U, 0x00004000U, 0x00000c00U, 0, "LDS.128 R8, [R20+0x40]" }, + { BW_IR_LDS128, 12, 20, -1, -1, -1, 0x100, 0, 0x140c7984U, 0x00010000U, 0x00000c00U, 0, "LDS.128 R12, [R20+0x100]" }, }; for (int i = 0; i < (int)(sizeof fx / sizeof fx[0]); i++) { BlackwellIRInsn in; diff --git a/src/omega_blackwell_codegen.h b/src/omega_blackwell_codegen.h index 2ac9b8186..bfbde3e7e 100644 --- a/src/omega_blackwell_codegen.h +++ b/src/omega_blackwell_codegen.h @@ -97,7 +97,10 @@ typedef enum { * -arch=sm_121 (omega_blackwell_verify_codegen_fixtures_fragmm). imm = signed byte offset, * -2^23 .. 2^23-1; dst is a register pair (64) or an aligned quad (128). */ BW_IR_LDG_E_64, /* LDG.E.64 Rd:Rd+1, desc[URd][Ra.64+imm] */ - BW_IR_LDG_E_128 /* LDG.E.128 Rd..Rd+3, desc[URd][Ra.64+imm] */ + BW_IR_LDG_E_128, /* LDG.E.128 Rd..Rd+3, desc[URd][Ra.64+imm] */ + /* Batched attention loads (2026-10-12). Words matched against nvcc 13.0.88 -arch=sm_121 + * (omega_blackwell_verify_codegen_fixtures_fragmm). imm = unsigned byte offset < 2^23; dst an aligned quad. */ + BW_IR_LDS128 /* LDS.128 Rd..Rd+3, [Ra+imm] */ } BlackwellIROpcode; /* Barrier (reconvergence) registers: the sm_121 BSSY/BSYNC words carry a 4-bit barrier id diff --git a/src/omega_gpu_attention_api.c b/src/omega_gpu_attention_api.c index 28dc99bf2..eca045bc9 100644 --- a/src/omega_gpu_attention_api.c +++ b/src/omega_gpu_attention_api.c @@ -46,6 +46,9 @@ #define SB_GPR 0u #define SB_RD 1u #define SB_UGPR 2u +#define SB_LD2 4u /* second scoreboard for batched loads (the matmul kernel's B-load word, omega #328) */ +#define SB_LD3 3u /* third: phase B keeps shared loads and the two halves of the V loads on separate scoreboards */ +#define AT_BATCH_MAX 4 /* loads in flight per scoreboard: 4 complete on the chip, 8 never did (omega #328) */ enum { K_FIXED, K_PRED, K_VAR, K_UVAR, K_STORE, K_SYNC, K_EXIT, K_BRA, K_BSSY, K_BSYNC }; @@ -53,6 +56,8 @@ enum { K_FIXED, K_PRED, K_VAR, K_UVAR, K_STORE, K_SYNC, K_EXIT, K_BRA, K_BSSY, K typedef struct { BlackwellIRProgram *p; uint32_t pending; + uint32_t batch; /* scoreboards the open load batch is filling (no wait on them inside the batch) */ + int batch_n[8]; /* loads issued per scoreboard in the open batch */ int err; int loop_start[AT_MAX_LOOPS], loop_end[AT_MAX_LOOPS]; int n_loops, depth, stack[AT_MAX_LOOPS]; @@ -62,6 +67,7 @@ typedef struct { static void emit(Em *e, BlackwellIRInsn in, int kind) { uint32_t wait = e->pending; + e->batch = 0; memset(e->batch_n, 0, sizeof e->batch_n); /* an ordinary instruction waits on the whole batch */ switch (kind) { case K_FIXED: in.control = CW(6, SB_NONE, SB_NONE, wait); e->pending = 0; break; case K_PRED: in.control = CW(13, SB_NONE, SB_NONE, wait); e->pending = 0; break; @@ -81,6 +87,7 @@ static void emit(Em *e, BlackwellIRInsn in, int kind) { static int V(Em *e) { int v = omega_bw_ir_alloc_vreg(e->p); if (v < 0) e->err = -1; return v; } static int V64(Em *e) { int v = omega_bw_ir_alloc_vreg64(e->p); if (v < 0) e->err = -1; return v; } +static int V128(Em *e) { int v = omega_bw_ir_alloc_vreg128(e->p); if (v < 0) e->err = -1; return v; } static int UV64(Em *e) { int v = omega_bw_ir_alloc_uvreg64(e->p); if (v < 0) e->err = -1; return v; } static int here(const Em *e) { return (int)e->p->count; } @@ -108,7 +115,38 @@ static void shri(Em *e, int dst, int a, uint32_t imm) { BlackwellIRInsn i = I0(B /* dst64 = idx * imm + base64 (byte address) */ static void wide(Em *e, int dst64, int idx, uint32_t imm, int base64) { BlackwellIRInsn i = I0(BW_IR_IMAD_WIDE); i.dst_vreg = dst64; i.src1_vreg = idx; i.imm = imm; i.src3_vreg = base64; emit(e, i, K_FIXED); } static void ldg(Em *e, int dst, int addr64, int udesc) { BlackwellIRInsn i = I0(BW_IR_LDG_E); i.dst_vreg = dst; i.src1_vreg = addr64; i.ureg = udesc; emit(e, i, K_VAR); } -static void ldg16(Em *e, int dst, int addr64, int udesc) { BlackwellIRInsn i = I0(BW_IR_LDG_E_U16); i.dst_vreg = dst; i.src1_vreg = addr64; i.ureg = udesc; emit(e, i, K_VAR); } +/* Batched loads (2026-10-12, long-context finding): every load above waits on the previous one, so + * phase A paid one global latency per dim pair and phase B one per token (~6 GB/s at 1268 ctx). A + * batched load sets `sb` and waits on every pending scoreboard except the ones the open batch is + * filling (and SB_RD, its read barrier), so up to AT_BATCH_MAX loads per scoreboard are in flight. + * The next ordinary instruction (emit) waits on all of them. SB_RD covers the address register: the + * allocator may hand that register to a later load's data before this load has read it. */ +static void emit_batched(Em *e, BlackwellIRInsn in, uint32_t sb) { + if (sb >= 8 || e->batch_n[sb] >= AT_BATCH_MAX) { e->err = -1; return; } + in.control = CW(4, sb, SB_RD, e->pending & ~e->batch) | CW_YIELD; + e->batch |= (1u << sb) | (1u << SB_RD); e->batch_n[sb]++; + e->pending |= (1u << sb) | (1u << SB_RD); + if (omega_bw_ir_append(e->p, &in) < 0) e->err = -1; +} +/* A fixed-latency instruction inside an open load batch: it waits on the batch's read barrier (its + * destination may be a load's address register, which the load may read late) but not on the loads' + * data, so the address of the next load is computed while the earlier loads are in flight. Only for + * instructions that read no result of the open batch. */ +static void emit_fixed_in_batch(Em *e, BlackwellIRInsn in) { + uint32_t wait = (e->pending & ~e->batch) | (e->batch ? (1u << SB_RD) : 0u); + in.control = CW(6, SB_NONE, SB_NONE, wait); + if (omega_bw_ir_append(e->p, &in) < 0) e->err = -1; +} +static void ldg128_b(Em *e, int dst128, int addr64, uint32_t imm, int udesc, uint32_t sb) { BlackwellIRInsn i = I0(BW_IR_LDG_E_128); i.dst_vreg = dst128; i.src1_vreg = addr64; i.imm = imm; i.ureg = udesc; emit_batched(e, i, sb); } +static void ldg_b(Em *e, int dst, int addr64, int udesc, uint32_t sb) { BlackwellIRInsn i = I0(BW_IR_LDG_E); i.dst_vreg = dst; i.src1_vreg = addr64; i.ureg = udesc; emit_batched(e, i, sb); } +static void ldg16_b(Em *e, int dst, int addr64, int udesc, uint32_t sb) { BlackwellIRInsn i = I0(BW_IR_LDG_E_U16); i.dst_vreg = dst; i.src1_vreg = addr64; i.ureg = udesc; emit_batched(e, i, sb); } +static void lds128_b(Em *e, int dst128, int addr, uint32_t imm, uint32_t sb) { BlackwellIRInsn i = I0(BW_IR_LDS128); i.dst_vreg = dst128; i.src1_vreg = addr; i.imm = imm; emit_batched(e, i, sb); } +/* sub-register operands of a quad */ +static void e_ffma_s(Em *e, int d, int a, int as, int b, int bs, int c) { BlackwellIRInsn i = I0(BW_IR_FFMA); i.dst_vreg = d; i.src1_vreg = a; i.src1_subreg = (uint8_t)as; i.src2_vreg = b; i.src2_subreg = (uint8_t)bs; i.src3_vreg = c; emit(e, i, K_FIXED); } +static void imadi_s(Em *e, int dst, int a, int as, uint32_t imm, int c) { BlackwellIRInsn i = I0(BW_IR_IMAD); i.dst_vreg = dst; i.src1_vreg = a; i.src1_subreg = (uint8_t)as; i.imm = imm; i.src3_vreg = c; emit(e, i, K_FIXED); } +static void lop3andi_s(Em *e, int dst, int a, int as, uint32_t imm) { BlackwellIRInsn i = I0(BW_IR_LOP3_AND); i.dst_vreg = dst; i.src1_vreg = a; i.src1_subreg = (uint8_t)as; i.imm = imm; emit(e, i, K_FIXED); } +static void wide_s(Em *e, int dst64, int idx, int is, uint32_t imm, int base64) { BlackwellIRInsn i = I0(BW_IR_IMAD_WIDE); i.dst_vreg = dst64; i.src1_vreg = idx; i.src1_subreg = (uint8_t)is; i.imm = imm; i.src3_vreg = base64; emit(e, i, K_FIXED); } +static void wide_s_b(Em *e, int dst64, int idx, int is, uint32_t imm, int base64) { BlackwellIRInsn i = I0(BW_IR_IMAD_WIDE); i.dst_vreg = dst64; i.src1_vreg = idx; i.src1_subreg = (uint8_t)is; i.imm = imm; i.src3_vreg = base64; emit_fixed_in_batch(e, i); } static void stg(Em *e, int addr64, int val, int udesc) { BlackwellIRInsn i = I0(BW_IR_STG_E); i.src1_vreg = addr64; i.src2_vreg = val; i.ureg = udesc; emit(e, i, K_STORE); } static void e_fadd(Em *e, int d, int a, int b) { BlackwellIRInsn i = I0(BW_IR_FADD); i.dst_vreg = d; i.src1_vreg = a; i.src2_vreg = b; emit(e, i, K_FIXED); } static void e_fsub(Em *e, int d, int a, int b) { BlackwellIRInsn i = I0(BW_IR_FSUB); i.dst_vreg = d; i.src1_vreg = a; i.src2_vreg = b; emit(e, i, K_FIXED); } @@ -227,7 +265,6 @@ typedef struct { bool f32; uint32_t log2bs, log2gqa; int mutant; int divergent; static void gen_attention(Em *e, const KSpec *k) { const uint32_t elem = k->f32 ? 4u : 2u; - const uint32_t kstep = k->f32 ? 8u : 4u; /* bytes per inner iteration: two dims */ const uint32_t HD = k->hd, SH_S = HD * 4u, SH_O = HD * 8u, SH_R = HD * 12u; /* warps per CTA: HD / 32 */ int udesc = UV64(e), A = V64(e), B = V64(e), C = V64(e), D = V64(e); int tid = V(e), h = V(e), seq = V(e); @@ -297,7 +334,7 @@ static void gen_attention(Em *e, const KSpec *k) { /* ---------------- chunk loop ---------------- */ int j = V(e), s = V(e), koff = V(e); int bi = V(e), sl = V(e), ta = V64(e), blk = V(e), ka = V64(e), dot = V(e), d = V(e); - int x = V(e), lo = V(e), hi = V(e), qa = V(e), qb = V(e), q0 = V(e), q1 = V(e), ka2 = V64(e), j1 = V(e); + int lo = V(e), hi = V(e), qa = V(e), j1 = V(e); int dneg = V(e), over = V(e), ot = V(e), ctxm1 = V(e), cm1 = V(e), cninf = V(e), nb = V(e), ns = V(e); movi(e, cm1, 0xFFFFFFFFu); iadd3(e, ctxm1, ctx, cm1); movi(e, cninf, F32_NEG_INF); loop_begin(e); @@ -345,27 +382,39 @@ static void gen_attention(Em *e, const KSpec *k) { iadd3(e, koff, koff, kvoff); wide(e, ka, koff, 1, B); } + /* phase A inner loop (batched, 2026-10-12): two 128-bit global loads of K per pass on SB_GPR (16 dims + * bf16, 8 dims f32) with the first half of the matching q slice as 128-bit shared loads on SB_LD2, one + * wait; then the second half of q, one more (short) wait. The serial loop before paid one global + * latency per dim pair. Two halves keep the pass inside AT_GPR_BUDGET (the whole slice at once is + * 65 to 76 registers). qa = d * 4 is the shared byte offset of q[d]. */ + const uint32_t dims = k->f32 ? 8u : 16u; /* dims per pass: 32 bytes of K either way */ + const uint32_t nq = dims / 4u; /* q quads per pass, loaded in two halves */ + int kx[2], qq[4]; + kx[0] = V128(e); kx[1] = V128(e); + for (uint32_t i = 0; i < nq; i++) qq[i] = V128(e); movrz(e, dot); movrz(e, d); loop_begin(e); int Lin = here(e); - if (k->f32) { - ldg(e, lo, ka, udesc); - wide(e, ka2, c1, 4, ka); - ldg(e, hi, ka2, udesc); - } else { - ldg(e, x, ka, udesc); - imadi(e, lo, x, 0x10000u, NOREG); /* low bf16 -> f32: bits << 16 */ - lop3andi(e, hi, x, 0xffff0000u); /* high bf16 -> f32: keep the top half */ + imadi(e, qa, d, 4, NOREG); + ldg128_b(e, kx[0], ka, 0u, udesc, SB_GPR); + ldg128_b(e, kx[1], ka, 16u, udesc, SB_GPR); + for (int h = 0; h < 2; h++) { + for (uint32_t i = 0; i < nq / 2u; i++) { uint32_t qi = (uint32_t)h * (nq / 2u) + i; lds128_b(e, qq[qi], qa, qi * 16u, SB_LD2); } + if (k->f32) { + for (int s = 0; s < 4; s++) e_ffma_s(e, dot, qq[h], s, kx[h], s, dot); /* dim h*4+s */ + } else { + for (int s = 0; s < 4; s++) { + int pi = h * 4 + s; /* bf16 pair: dims 2*pi (low half) and 2*pi+1 (high half) */ + imadi_s(e, lo, kx[h], s, 0x10000u, NOREG); /* low bf16 -> f32: bits << 16 */ + lop3andi_s(e, hi, kx[h], s, 0xffff0000u); /* high bf16 -> f32: keep the top half */ + e_ffma_s(e, dot, qq[pi / 2], (pi % 2) * 2, lo, 0, dot); + e_ffma_s(e, dot, qq[pi / 2], (pi % 2) * 2 + 1, hi, 0, dot); + } + } } - imadi(e, qa, d, 8, NOREG); - lds32(e, q0, qa); - iadd3(e, qb, qa, c4); - lds32(e, q1, qb); - e_ffma(e, dot, q0, lo, dot); - e_ffma(e, dot, q1, hi, dot); - wide(e, ka, c1, kstep, ka); - iadd3(e, d, d, c1); - isetp_ge_u32(e, d, c32); + wide(e, ka, c1, 32u, ka); + imadi(e, d, c1, dims, d); + isetp_ge_u32(e, d, c64); bra_back_if_not_p0(e, Lin); loop_end(e); e_fmul(e, s, dot, scale); @@ -412,8 +461,16 @@ static void gen_attention(Em *e, const KSpec *k) { e_ffma(e, L, L, alpha, lc); if (k->mutant != OMEGA_GPU_ATTN_MUTANT_NO_RESCALE) e_fmul(e, acc, acc, alpha); - /* phase B: dimension tid over the chunk's tokens */ - int kk = V(e), tt = V(e), oa = V(e), ko = V(e), pa = V(e), pv = V(e), va = V64(e), v = V(e); + /* phase B (batched, 2026-10-12): dimension tid over the chunk's tokens, AT_TOK tokens per pass. The + * token offsets of a pass come in two 128-bit shared loads (SB_LD2, one wait), then each V address is + * computed into one register pair while the earlier V loads are in flight (emit_fixed_in_batch: the + * read barrier orders the overwrite after the load has read it) and its load issued on SB_GPR or + * SB_LD3; the p values follow as two more shared loads on SB_LD2; one wait for all of it. A token past + * ctx inside a pass has p = 0 and the offset of a real token (phase A), so it adds exactly 0. */ + enum { AT_TOK = 8 }; + int kk = V(e), tt = V(e), oa = V(e), pa = V(e), ko4[2], pv4[2], va = V64(e), v[AT_TOK]; + for (int i = 0; i < 2; i++) { ko4[i] = V128(e); pv4[i] = V128(e); } + for (int i = 0; i < AT_TOK; i++) v[i] = V(e); movrz(e, kk); loop_begin(e); int LB = here(e); @@ -421,14 +478,20 @@ static void gen_attention(Em *e, const KSpec *k) { isetp_ge_u32(e, tt, ctx); int bB = bra_fwd_if_p0(e); imadi(e, oa, kk, 4, c512); - lds32(e, ko, oa); imadi(e, pa, kk, 4, c256); - lds32(e, pv, pa); - wide(e, va, ko, 1, vb); - if (k->f32) ldg(e, v, va, udesc); - else { ldg16(e, v, va, udesc); imadi(e, v, v, 0x10000u, NOREG); } - e_ffma(e, acc, pv, v, acc); - iadd3(e, kk, kk, c1); + for (int i = 0; i < 2; i++) lds128_b(e, ko4[i], oa, (uint32_t)i * 16u, SB_LD2); + for (int i = 0; i < AT_TOK; i++) { + if (i == 0) wide_s(e, va, ko4[0], 0, 1, vb); /* ordinary: waits for the offsets */ + else wide_s_b(e, va, ko4[i / 4], i % 4, 1, vb); + uint32_t sb = (i < AT_TOK / 2) ? SB_GPR : SB_LD3; + if (k->f32) ldg_b(e, v[i], va, udesc, sb); else ldg16_b(e, v[i], va, udesc, sb); + } + for (int i = 0; i < 2; i++) lds128_b(e, pv4[i], pa, (uint32_t)i * 16u, SB_LD2); + for (int i = 0; i < AT_TOK; i++) { + if (!k->f32) imadi(e, v[i], v[i], 0x10000u, NOREG); + e_ffma_s(e, acc, pv4[i / 4], i % 4, v[i], 0, acc); + } + imadi(e, kk, c1, AT_TOK, kk); isetp_ge_u32(e, kk, c64); bra_back_if_not_p0(e, LB); loop_end(e); diff --git a/tests/.crumb b/tests/.crumb index 26189c2ed..6cbe22ba9 100644 --- a/tests/.crumb +++ b/tests/.crumb @@ -260,7 +260,7 @@ }, { "digest": "befa6601937d28b7c058b3abc4c12c90cbe8f2fce3f9498a3e67cd522391b61c", - "last_commit": "d9457e55", + "last_commit": "781e98d8", "name": "runtime", "purpose": "Directory tests/runtime. Purpose not yet described by a human." }, @@ -290,14 +290,14 @@ } ], "children_root": "sha256:9c94c5a57dda7727107b9e1271460c33b2cde72e796459e1ae401d4d4aeaec78", - "compiled_at": "2026-10-11T19:30:27Z", + "compiled_at": "2026-10-12T05:17:54Z", "compiler": "crumb-compile/1", - "digest": "sha256:77baf947bf422344b099c312f5895e8491f5d91c97758ff2ed1a7672dc408114", + "digest": "sha256:0713f610eacc8c4279a0f58379d061a1ec57ca60efd1595fb6fc91868fda5c23", "evidence_files": 16, "evidence_root": "sha256:96d08097822ad95f4e562c19e0ba5df5a035774c48632f1832912c40a27bd27a", "files": 1022, - "generated_at_commit": "8507ac948f46e305d1108520cabaed75f110695d", - "source_tree": "sha256:98ea82ec4a88290e4598dc1b065bcba1b688784c347c24cd505db86c09a989be" + "generated_at_commit": "6e6f1c8e27b4f3a511bb284e7f51f2a957863ded", + "source_tree": "sha256:cc16869b090d52a5aec3b189c098bcd9e658f778f9857ddecb4d06d316754afc" }, "owner_lane": "", "provenance": { diff --git a/tests/bw_warp_sim.h b/tests/bw_warp_sim.h index 328094cb0..3e98e8545 100644 --- a/tests/bw_warp_sim.h +++ b/tests/bw_warp_sim.h @@ -104,6 +104,9 @@ static uint32_t ws_rd(const WsLane *l, int v, const BlackwellIRProgram *p) { if static uint64_t ws_rd64(const WsLane *l, int v, const BlackwellIRProgram *p) { if (v < 0) return 0; int ph = p->regalloc.vreg_to_phys[v] & 0xff; return (uint64_t)l->r[ph] | ((uint64_t)l->r[(ph + 1) & 0xff] << 32); } static void ws_wr(WsLane *l, int v, uint32_t x, const BlackwellIRProgram *p) { if (v < 0) return; int ph = p->regalloc.vreg_to_phys[v]; if (ph >= 0) l->r[ph & 0xff] = x; } static void ws_wr64(WsLane *l, int v, uint64_t x, const BlackwellIRProgram *p) { if (v < 0) return; int ph = p->regalloc.vreg_to_phys[v] & 0xff; l->r[ph] = (uint32_t)x; l->r[(ph + 1) & 0xff] = (uint32_t)(x >> 32); } +/* sub-register operands (quad/pair lanes, BlackwellIRInsn.*_subreg) */ +static uint32_t ws_rds(const WsLane *l, int v, unsigned sub, const BlackwellIRProgram *p) { if (v < 0) return 0; int ph = p->regalloc.vreg_to_phys[v]; return ph < 0 ? 0 : l->r[(ph + sub) & 0xff]; } +static void ws_wrs(WsLane *l, int v, unsigned sub, uint32_t x, const BlackwellIRProgram *p) { if (v < 0) return; int ph = p->regalloc.vreg_to_phys[v]; if (ph >= 0) l->r[(ph + sub) & 0xff] = x; } static float ws_u2f(uint32_t u) { float f; memcpy(&f, &u, 4); return f; } static uint32_t ws_f2u(float f) { uint32_t u; memcpy(&u, &f, 4); return u; } static uint32_t ws_lut3(uint32_t lut, uint32_t a, uint32_t b, uint32_t c) { @@ -125,39 +128,41 @@ static int ws_popc(uint32_t m) { return __builtin_popcount(m); } /* One lane, one non-control instruction. */ static void ws_lane_exec(WsSim *s, WsLane *l, const BlackwellIRInsn *in, int pc, uint32_t tid, uint32_t cx, uint32_t cy) { const BlackwellIRProgram *p = s->p; - uint32_t a = ws_rd(l, in->src1_vreg, p), b = ws_rd(l, in->src2_vreg, p), c = ws_rd(l, in->src3_vreg, p); + uint32_t a = ws_rds(l, in->src1_vreg, in->src1_subreg, p), b = ws_rds(l, in->src2_vreg, in->src2_subreg, p), c = ws_rds(l, in->src3_vreg, in->src3_subreg, p); switch (in->op) { case BW_IR_NOP: break; - case BW_IR_S2R: ws_wr(l, in->dst_vreg, in->imm == BW_SR_TID_X ? tid : in->imm == BW_SR_CTAID_X ? cx : in->imm == BW_SR_CTAID_Y ? cy : 0, p); break; - case BW_IR_LDC: ws_wr(l, in->dst_vreg, s->cbank[(in->imm / 4) & 0xff], p); break; + case BW_IR_S2R: ws_wrs(l, in->dst_vreg, in->dst_subreg, in->imm == BW_SR_TID_X ? tid : in->imm == BW_SR_CTAID_X ? cx : in->imm == BW_SR_CTAID_Y ? cy : 0, p); break; + case BW_IR_LDC: ws_wrs(l, in->dst_vreg, in->dst_subreg, s->cbank[(in->imm / 4) & 0xff], p); break; case BW_IR_LDC64: ws_wr64(l, in->dst_vreg, (uint64_t)s->cbank[(in->imm / 4) & 0xff] | ((uint64_t)s->cbank[(in->imm / 4 + 1) & 0xff] << 32), p); break; case BW_IR_LDCU64: case BW_IR_LDCU: break; /* memory descriptor: not modelled */ - case BW_IR_MOV_IMM: ws_wr(l, in->dst_vreg, in->imm, p); break; - case BW_IR_MOV_RZ: ws_wr(l, in->dst_vreg, 0, p); break; - case BW_IR_IMAD: ws_wr(l, in->dst_vreg, in->src2_vreg >= 0 ? a * b + c : a * in->imm + c, p); break; + case BW_IR_MOV_IMM: ws_wrs(l, in->dst_vreg, in->dst_subreg, in->imm, p); break; + case BW_IR_MOV_RZ: ws_wrs(l, in->dst_vreg, in->dst_subreg, 0, p); break; + case BW_IR_IMAD: ws_wrs(l, in->dst_vreg, in->dst_subreg, in->src2_vreg >= 0 ? a * b + c : a * in->imm + c, p); break; case BW_IR_IMAD_WIDE: ws_wr64(l, in->dst_vreg, (uint64_t)a * in->imm + ws_rd64(l, in->src3_vreg, p), p); break; - case BW_IR_IMAD_HI_U32: ws_wr(l, in->dst_vreg, (uint32_t)(((uint64_t)a * b) >> 32) + c, p); break; - case BW_IR_IADD3: ws_wr(l, in->dst_vreg, a + b, p); break; /* the encoder's IADD3 has Rc = RZ */ - case BW_IR_SHF_R: ws_wr(l, in->dst_vreg, a >> (in->imm & 31), p); break; - case BW_IR_SHF_L_U32: if (b >= 32) { ws_fail(s, WS_E_SHIFT, pc, "SHF.L.U32 amount >= 32 (not chip-verified)"); return; } ws_wr(l, in->dst_vreg, a << b, p); break; - case BW_IR_LOP3_AND: ws_wr(l, in->dst_vreg, a & in->imm, p); break; - case BW_IR_LOP3_XOR: ws_wr(l, in->dst_vreg, a ^ b, p); break; - case BW_IR_LOP3_LUT: ws_wr(l, in->dst_vreg, ws_lut3(in->imm & 0xff, a, b, c), p); break; + case BW_IR_IMAD_HI_U32: ws_wrs(l, in->dst_vreg, in->dst_subreg, (uint32_t)(((uint64_t)a * b) >> 32) + c, p); break; + case BW_IR_IADD3: ws_wrs(l, in->dst_vreg, in->dst_subreg, a + b, p); break; /* the encoder's IADD3 has Rc = RZ */ + case BW_IR_SHF_R: ws_wrs(l, in->dst_vreg, in->dst_subreg, a >> (in->imm & 31), p); break; + case BW_IR_SHF_L_U32: if (b >= 32) { ws_fail(s, WS_E_SHIFT, pc, "SHF.L.U32 amount >= 32 (not chip-verified)"); return; } ws_wrs(l, in->dst_vreg, in->dst_subreg, a << b, p); break; + case BW_IR_LOP3_AND: ws_wrs(l, in->dst_vreg, in->dst_subreg, a & in->imm, p); break; + case BW_IR_LOP3_XOR: ws_wrs(l, in->dst_vreg, in->dst_subreg, a ^ b, p); break; + case BW_IR_LOP3_LUT: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_lut3(in->imm & 0xff, a, b, c), p); break; case BW_IR_ISETP_GE_U32: l->p0 = a >= b; break; - case BW_IR_LDG_E: { uint64_t ad = ws_rd64(l, in->src1_vreg, p); if (!ws_mem_ok(s, ad, 4, pc)) return; uint32_t x; memcpy(&x, (const void *)(uintptr_t)ad, 4); ws_wr(l, in->dst_vreg, x, p); break; } - case BW_IR_LDG_E_U16: { uint64_t ad = ws_rd64(l, in->src1_vreg, p); if (!ws_mem_ok(s, ad, 2, pc)) return; uint16_t x; memcpy(&x, (const void *)(uintptr_t)ad, 2); ws_wr(l, in->dst_vreg, x, p); break; } + case BW_IR_LDG_E: { uint64_t ad = ws_rd64(l, in->src1_vreg, p); if (!ws_mem_ok(s, ad, 4, pc)) return; uint32_t x; memcpy(&x, (const void *)(uintptr_t)ad, 4); ws_wrs(l, in->dst_vreg, in->dst_subreg, x, p); break; } + case BW_IR_LDG_E_U16: { uint64_t ad = ws_rd64(l, in->src1_vreg, p); if (!ws_mem_ok(s, ad, 2, pc)) return; uint16_t x; memcpy(&x, (const void *)(uintptr_t)ad, 2); ws_wrs(l, in->dst_vreg, in->dst_subreg, x, p); break; } case BW_IR_STG_E: { uint64_t ad = ws_rd64(l, in->src1_vreg, p); if (!ws_mem_ok(s, ad, 4, pc)) return; memcpy((void *)(uintptr_t)ad, &b, 4); break; } - case BW_IR_LDS32: { uint32_t *m = ws_smem(s, a, pc); if (!m) return; ws_wr(l, in->dst_vreg, *m, p); break; } + case BW_IR_LDG_E_64: case BW_IR_LDG_E_128: { unsigned n = in->op == BW_IR_LDG_E_64 ? 8u : 16u; uint64_t ad = ws_rd64(l, in->src1_vreg, p) + (uint64_t)(int64_t)(int32_t)in->imm; if (!ws_mem_ok(s, ad, n, pc)) return; if (ad & (n - 1)) { ws_fail(s, WS_E_MEM, pc, "wide global load not naturally aligned"); return; } uint32_t x[4]; memcpy(x, (const void *)(uintptr_t)ad, n); for (unsigned i = 0; i < n / 4; i++) ws_wrs(l, in->dst_vreg, i, x[i], p); break; } + case BW_IR_LDS128: { uint32_t ad = a + in->imm; if (ad & 15u) { ws_fail(s, WS_E_SMEM, pc, "LDS.128 address not 16-byte aligned"); return; } for (unsigned i = 0; i < 4; i++) { uint32_t *m = ws_smem(s, ad + 4u * i, pc); if (!m) return; ws_wrs(l, in->dst_vreg, i, *m, p); } break; } + case BW_IR_LDS32: { uint32_t *m = ws_smem(s, a, pc); if (!m) return; ws_wrs(l, in->dst_vreg, in->dst_subreg, *m, p); break; } case BW_IR_STS32: { uint32_t *m = ws_smem(s, a, pc); if (!m) return; *m = b; break; } - case BW_IR_FADD: ws_wr(l, in->dst_vreg, ws_f2u(ws_u2f(a) + ws_u2f(b)), p); break; - case BW_IR_FSUB: ws_wr(l, in->dst_vreg, ws_f2u(ws_u2f(a) - ws_u2f(b)), p); break; - case BW_IR_FMUL: ws_wr(l, in->dst_vreg, ws_f2u(ws_u2f(a) * ws_u2f(b)), p); break; - case BW_IR_FFMA: ws_wr(l, in->dst_vreg, ws_f2u(fmaf(ws_u2f(a), ws_u2f(b), ws_u2f(c))), p); break; - case BW_IR_FMNMX_MAX: ws_wr(l, in->dst_vreg, ws_f2u(fmaxf(ws_u2f(a), ws_u2f(b))), p); break; - case BW_IR_FMNMX_MIN: ws_wr(l, in->dst_vreg, ws_f2u(fminf(ws_u2f(a), ws_u2f(b))), p); break; - case BW_IR_MUFU_EX2: ws_wr(l, in->dst_vreg, ws_f2u(exp2f(ws_u2f(a))), p); break; - case BW_IR_MUFU_RCP: ws_wr(l, in->dst_vreg, ws_f2u(1.0f / ws_u2f(a)), p); break; - case BW_IR_MUFU_RSQ: ws_wr(l, in->dst_vreg, ws_f2u(1.0f / sqrtf(ws_u2f(a))), p); break; + case BW_IR_FADD: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(ws_u2f(a) + ws_u2f(b)), p); break; + case BW_IR_FSUB: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(ws_u2f(a) - ws_u2f(b)), p); break; + case BW_IR_FMUL: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(ws_u2f(a) * ws_u2f(b)), p); break; + case BW_IR_FFMA: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(fmaf(ws_u2f(a), ws_u2f(b), ws_u2f(c))), p); break; + case BW_IR_FMNMX_MAX: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(fmaxf(ws_u2f(a), ws_u2f(b))), p); break; + case BW_IR_FMNMX_MIN: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(fminf(ws_u2f(a), ws_u2f(b))), p); break; + case BW_IR_MUFU_EX2: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(exp2f(ws_u2f(a))), p); break; + case BW_IR_MUFU_RCP: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(1.0f / ws_u2f(a)), p); break; + case BW_IR_MUFU_RSQ: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(1.0f / sqrtf(ws_u2f(a))), p); break; default: ws_fail(s, WS_E_OP, pc, "opcode not modelled"); return; } } diff --git a/tests/gpu_attention_test.c b/tests/gpu_attention_test.c index 1368f5ada..2eac1d955 100644 --- a/tests/gpu_attention_test.c +++ b/tests/gpu_attention_test.c @@ -190,8 +190,8 @@ static void host_only(void) { CHECK(strcmp(omega_gpu_attention_rc_name(OMEGA_GPU_ATTN_UNWRITTEN), "UNWRITTEN") == 0, "rc name"); /* with --divergent the listing must also show the region ops (last two entries) */ - static const char *const must_bf16[] = { "MUFU.EX2", "MUFU.RCP", "FMNMX", "BAR.SYNC", "SHFL.DOWN", "@P0 BRA", "@!P0 BRA", "LDG.E.U16", "LDG.E ", "LDS R", "STS [R", "STG.E", "LOP3.LUT", "SHF.R.U32.HI", "BSSY", "BSYNC" }; - static const char *const must_f32[] = { "MUFU.EX2", "MUFU.RCP", "FMNMX", "BAR.SYNC", "SHFL.DOWN", "@P0 BRA", "@!P0 BRA", "LDG.E ", "LDS R", "STS [R", "STG.E", "BSSY", "BSYNC" }; + static const char *const must_bf16[] = { "MUFU.EX2", "MUFU.RCP", "FMNMX", "BAR.SYNC", "SHFL.DOWN", "@P0 BRA", "@!P0 BRA", "LDG.E.U16", "LDG.E ", "LDG.E.128", "LDS.128", "LDS R", "STS [R", "STG.E", "LOP3.LUT", "SHF.R.U32.HI", "BSSY", "BSYNC" }; + static const char *const must_f32[] = { "MUFU.EX2", "MUFU.RCP", "FMNMX", "BAR.SYNC", "SHFL.DOWN", "@P0 BRA", "@!P0 BRA", "LDG.E ", "LDG.E.128", "LDS.128", "LDS R", "STS [R", "STG.E", "BSSY", "BSYNC" }; for (int f32 = 0; f32 < 2; f32++) { const char *name = f32 ? "gqa_f32" : "paged_bf16"; OmegaBlackwellKernel k; memset(&k, 0, sizeof k); @@ -552,6 +552,8 @@ static uint32_t rd(const SimThr *t, int v, const BlackwellIRProgram *p) { if (v static uint64_t rd64(const SimThr *t, int v, const BlackwellIRProgram *p) { if (v < 0) return 0; int ph = p->regalloc.vreg_to_phys[v] & 0xff; return (uint64_t)t->r[ph] | ((uint64_t)t->r[ph + 1] << 32); } static void wr(SimThr *t, int v, uint32_t x, const BlackwellIRProgram *p) { if (v < 0) return; int ph = p->regalloc.vreg_to_phys[v]; if (ph >= 0) t->r[ph & 0xff] = x; } static void wr64(SimThr *t, int v, uint64_t x, const BlackwellIRProgram *p) { if (v < 0) return; int ph = p->regalloc.vreg_to_phys[v] & 0xff; t->r[ph] = (uint32_t)x; t->r[ph + 1] = (uint32_t)(x >> 32); } +static uint32_t rds(const SimThr *t, int v, unsigned sub, const BlackwellIRProgram *p) { if (v < 0) return 0; int ph = p->regalloc.vreg_to_phys[v]; return ph < 0 ? 0 : t->r[(ph + sub) & 0xff]; } +static void wrs(SimThr *t, int v, unsigned sub, uint32_t x, const BlackwellIRProgram *p) { if (v < 0) return; int ph = p->regalloc.vreg_to_phys[v]; if (ph >= 0) t->r[(ph + sub) & 0xff] = x; } static float u2f(uint32_t u) { float f; memcpy(&f, &u, 4); return f; } static uint32_t f2u_(float f) { uint32_t u; memcpy(&u, &f, 4); return u; } /* run one thread until it reaches a SHFL or BAR (not executed) or EXIT; returns 1 if parked at a sync op */ @@ -560,7 +562,7 @@ static int sim_step(SimThr *t, const BlackwellIRProgram *p, uint32_t tid, uint32 if (t->done) return 0; if (t->pc < 0 || (size_t)t->pc >= p->count) { g_sim_err = 1; t->done = 1; return 0; } const BlackwellIRInsn *in = &p->insns[t->pc]; - uint32_t a = rd(t, in->src1_vreg, p), b = rd(t, in->src2_vreg, p), c = rd(t, in->src3_vreg, p); + uint32_t a = rds(t, in->src1_vreg, in->src1_subreg, p), b = rds(t, in->src2_vreg, in->src2_subreg, p), c = rds(t, in->src3_vreg, in->src3_subreg, p); switch (in->op) { case BW_IR_SHFL_DOWN: case BW_IR_BAR_SYNC: return 1; case BW_IR_EXIT: if (!in->predicate_p0 || t->p0) { t->done = 1; return 0; } break; @@ -569,31 +571,33 @@ static int sim_step(SimThr *t, const BlackwellIRProgram *p, uint32_t tid, uint32 t->path = t->path * 1000003u + (((uint64_t)t->pc << 1) | (uint64_t)take); if (take) { if ((int32_t)in->imm == 0) { g_sim_err = 2; t->done = 1; return 0; } t->pc += (int32_t)in->imm; continue; } break; } - case BW_IR_MOV_IMM: wr(t, in->dst_vreg, in->imm, p); break; - case BW_IR_MOV_RZ: wr(t, in->dst_vreg, 0, p); break; - case BW_IR_S2R: wr(t, in->dst_vreg, in->imm == BW_SR_TID_X ? tid : in->imm == BW_SR_CTAID_X ? cx : in->imm == BW_SR_CTAID_Y ? cy : 0, p); break; - case BW_IR_LDC: wr(t, in->dst_vreg, sim_cbank[in->imm / 4], p); break; + case BW_IR_MOV_IMM: wrs(t, in->dst_vreg, in->dst_subreg, in->imm, p); break; + case BW_IR_MOV_RZ: wrs(t, in->dst_vreg, in->dst_subreg, 0, p); break; + case BW_IR_S2R: wrs(t, in->dst_vreg, in->dst_subreg, in->imm == BW_SR_TID_X ? tid : in->imm == BW_SR_CTAID_X ? cx : in->imm == BW_SR_CTAID_Y ? cy : 0, p); break; + case BW_IR_LDC: wrs(t, in->dst_vreg, in->dst_subreg, sim_cbank[in->imm / 4], p); break; case BW_IR_LDC64: wr64(t, in->dst_vreg, (uint64_t)sim_cbank[in->imm / 4] | ((uint64_t)sim_cbank[in->imm / 4 + 1] << 32), p); break; case BW_IR_LDCU64: break; /* memory descriptor: not modelled */ - case BW_IR_IMAD: wr(t, in->dst_vreg, in->src2_vreg >= 0 ? a * b + c : a * in->imm + c, p); break; + case BW_IR_IMAD: wrs(t, in->dst_vreg, in->dst_subreg, in->src2_vreg >= 0 ? a * b + c : a * in->imm + c, p); break; case BW_IR_IMAD_WIDE: wr64(t, in->dst_vreg, (uint64_t)a * in->imm + rd64(t, in->src3_vreg, p), p); break; - case BW_IR_IADD3: wr(t, in->dst_vreg, a + b, p); break; - case BW_IR_SHF_R: wr(t, in->dst_vreg, a >> (in->imm & 31), p); break; - case BW_IR_LOP3_AND: wr(t, in->dst_vreg, a & in->imm, p); break; - case BW_IR_LOP3_XOR: wr(t, in->dst_vreg, a ^ b, p); break; + case BW_IR_IADD3: wrs(t, in->dst_vreg, in->dst_subreg, a + b, p); break; + case BW_IR_SHF_R: wrs(t, in->dst_vreg, in->dst_subreg, a >> (in->imm & 31), p); break; + case BW_IR_LOP3_AND: wrs(t, in->dst_vreg, in->dst_subreg, a & in->imm, p); break; + case BW_IR_LOP3_XOR: wrs(t, in->dst_vreg, in->dst_subreg, a ^ b, p); break; case BW_IR_ISETP_GE_U32: t->p0 = a >= b; break; - case BW_IR_LDG_E: { uint32_t x; memcpy(&x, (const void *)(uintptr_t)rd64(t, in->src1_vreg, p), 4); wr(t, in->dst_vreg, x, p); break; } - case BW_IR_LDG_E_U16: { uint16_t x; memcpy(&x, (const void *)(uintptr_t)rd64(t, in->src1_vreg, p), 2); wr(t, in->dst_vreg, x, p); break; } + case BW_IR_LDG_E: { uint32_t x; memcpy(&x, (const void *)(uintptr_t)rd64(t, in->src1_vreg, p), 4); wrs(t, in->dst_vreg, in->dst_subreg, x, p); break; } + case BW_IR_LDG_E_U16: { uint16_t x; memcpy(&x, (const void *)(uintptr_t)rd64(t, in->src1_vreg, p), 2); wrs(t, in->dst_vreg, in->dst_subreg, x, p); break; } case BW_IR_STG_E: memcpy((void *)(uintptr_t)rd64(t, in->src1_vreg, p), &b, 4); break; - case BW_IR_LDS32: { uint32_t x; if (a + 4 > SIM_SMEM) { g_sim_err = 3; t->done = 1; return 0; } memcpy(&x, sim_shared + a, 4); wr(t, in->dst_vreg, x, p); break; } + case BW_IR_LDG_E_64: case BW_IR_LDG_E_128: { unsigned n = in->op == BW_IR_LDG_E_64 ? 8u : 16u; uint64_t ad = rd64(t, in->src1_vreg, p) + (uint64_t)(int64_t)(int32_t)in->imm; if (ad & (n - 1)) { g_sim_err = 5; t->done = 1; return 0; } uint32_t x[4]; memcpy(x, (const void *)(uintptr_t)ad, n); for (unsigned i = 0; i < n / 4; i++) wrs(t, in->dst_vreg, i, x[i], p); break; } + case BW_IR_LDS128: { uint32_t ad = a + in->imm; if ((ad & 15u) || ad + 16 > SIM_SMEM) { g_sim_err = 3; t->done = 1; return 0; } for (unsigned i = 0; i < 4; i++) { uint32_t x; memcpy(&x, sim_shared + ad + 4u * i, 4); wrs(t, in->dst_vreg, i, x, p); } break; } + case BW_IR_LDS32: { uint32_t x; if (a + 4 > SIM_SMEM) { g_sim_err = 3; t->done = 1; return 0; } memcpy(&x, sim_shared + a, 4); wrs(t, in->dst_vreg, in->dst_subreg, x, p); break; } case BW_IR_STS32: if (a + 4 > SIM_SMEM) { g_sim_err = 3; t->done = 1; return 0; } memcpy(sim_shared + a, &b, 4); break; - case BW_IR_FADD: wr(t, in->dst_vreg, f2u_(u2f(a) + u2f(b)), p); break; - case BW_IR_FSUB: wr(t, in->dst_vreg, f2u_(u2f(a) - u2f(b)), p); break; - case BW_IR_FMUL: wr(t, in->dst_vreg, f2u_(u2f(a) * u2f(b)), p); break; - case BW_IR_FFMA: wr(t, in->dst_vreg, f2u_(fmaf(u2f(a), u2f(b), u2f(c))), p); break; - case BW_IR_FMNMX_MAX: wr(t, in->dst_vreg, f2u_(fmaxf(u2f(a), u2f(b))), p); break; - case BW_IR_MUFU_EX2: wr(t, in->dst_vreg, f2u_(exp2f(u2f(a))), p); break; - case BW_IR_MUFU_RCP: wr(t, in->dst_vreg, f2u_(1.0f / u2f(a)), p); break; + case BW_IR_FADD: wrs(t, in->dst_vreg, in->dst_subreg, f2u_(u2f(a) + u2f(b)), p); break; + case BW_IR_FSUB: wrs(t, in->dst_vreg, in->dst_subreg, f2u_(u2f(a) - u2f(b)), p); break; + case BW_IR_FMUL: wrs(t, in->dst_vreg, in->dst_subreg, f2u_(u2f(a) * u2f(b)), p); break; + case BW_IR_FFMA: wrs(t, in->dst_vreg, in->dst_subreg, f2u_(fmaf(u2f(a), u2f(b), u2f(c))), p); break; + case BW_IR_FMNMX_MAX: wrs(t, in->dst_vreg, in->dst_subreg, f2u_(fmaxf(u2f(a), u2f(b))), p); break; + case BW_IR_MUFU_EX2: wrs(t, in->dst_vreg, in->dst_subreg, f2u_(exp2f(u2f(a))), p); break; + case BW_IR_MUFU_RCP: wrs(t, in->dst_vreg, in->dst_subreg, f2u_(1.0f / u2f(a)), p); break; default: g_sim_err = 100 + (int)in->op; t->done = 1; return 0; } if (g_trace && tid == 0 && cx == g_trace_cx && cy == 0 && g_trace_launch == 1) { uint32_t dv = rd(t, in->dst_vreg, p); printf("T pc=%d op=%d dst=v%d(r%d)=%08x f=%g p0=%d a=%08x b=%08x c=%08x\n", t->pc, (int)in->op, in->dst_vreg, in->dst_vreg >= 0 ? p->regalloc.vreg_to_phys[in->dst_vreg] : -1, dv, u2f(dv), t->p0, a, b, c); } @@ -904,16 +908,16 @@ static void hd128_checks(void) { } /* head_dim 64 byte-identity pin and head_dim 128 codegen facts (CPU only, no device, no simulator). - * The digests are SHA-256 of the encoded kernel bytes as emitted by origin/main c0369e6 (before head_dim - * 128 existed); any change to the head_dim 64 program changes a digest and fails here. */ + * The digests are SHA-256 of the encoded kernel bytes as emitted by the batched-load program of 2026-10-12 + * (speed/attention-batched-loads; before it, main c0369e6 was pinned at 160 instructions); any change to the head_dim 64 program changes a digest and fails here. */ typedef struct { bool f32; uint32_t log2bs, log2gqa; size_t insns; const char *sha256; } Pin; static const Pin k_pins64[] = { - { false, 4, 3, 160, "6e2b1ea2ca58327391287177e606a5317422e06301e5a8c75d2ce45eed20ff2b" }, - { false, 4, 2, 160, "230443d951335a363614bac31c5ce6be9f42ab6192e450851c7238efcc383868" }, - { false, 4, 0, 160, "a0629e402901f5ae4ee07f893f032793774c444f0646db8f40f0d8f943bf4c97" }, - { true, 12, 3, 160, "c3dc2fbbdfafc9ad0aee4213590bc75b21f122ade285d0f9ce3cbf9a76a23a30" }, - { true, 12, 2, 160, "90fb6c755be466a9b37fd3b817a6ae43016e15b0c35c45bb37da40aa73ca5ba4" }, - { true, 12, 0, 160, "a5443e2b274b2b9c620f54f9aa05aefef9e05956450144e0e31046d32a5b62a9" }, + { false, 4, 3, 216, "44d27fae78ea21ee77fd7a0ebd2ebfcac52e9e45a81de84b035868092e13e424" }, + { false, 4, 2, 216, "3bc79d4a54fd0d82024b376dfdb718e8326431917251f13f5c44be6ba8eb6f0c" }, + { false, 4, 0, 216, "83eca9872e32c17321d2f8ec6a6ec92638ed72b136d8958cda5cdfc451c01ef8" }, + { true, 12, 3, 184, "b6a25d8739185bbd944bfcc1ec174abb24ce46529f06c56f8d5ac77bf6883ddd" }, + { true, 12, 2, 184, "46a2b82ebcb55237f4a7585679b42ac9558c7a434e8e80ccef6cc0bfaed8fcb9" }, + { true, 12, 0, 184, "970db9533c836eca7c86783875a2ad898cd69bc3070cae418cc92b3ce2dbbd9c" }, }; static void hex_digest(const uint8_t d[32], char out[65]) { for (int i = 0; i < 32; i++) snprintf(out + 2 * i, 3, "%02x", d[i]); } static void hd_codegen_checks(void) { @@ -923,7 +927,7 @@ static void hd_codegen_checks(void) { OmegaBlackwellKernel k; memset(&k, 0, sizeof k); int rc = omega_gpu_attention_codegen_hd(p->f32, p->log2bs, p->log2gqa, 64, &k); hex_digest(k.code_digest, hex); - CHECK(rc == OMEGA_GPU_ATTN_OK && k.insn_count == p->insns && strcmp(hex, p->sha256) == 0, "hd64 %s log2bs %u log2gqa %u: encoded kernel is byte-identical to main c0369e6 (%zu insns, sha256 %.12s)", p->f32 ? "f32 " : "bf16", p->log2bs, p->log2gqa, k.insn_count, hex); + CHECK(rc == OMEGA_GPU_ATTN_OK && k.insn_count == p->insns && strcmp(hex, p->sha256) == 0, "hd64 %s log2bs %u log2gqa %u: encoded kernel is byte-identical to the pinned program (%zu insns, sha256 %s)", p->f32 ? "f32 " : "bf16", p->log2bs, p->log2gqa, k.insn_count, hex); free(k.code); /* the 4-argument entry point is the same kernel */ OmegaBlackwellKernel k4; memset(&k4, 0, sizeof k4); diff --git a/tests/r16_inventory/.crumb b/tests/r16_inventory/.crumb index 2148b51c9..42776332d 100644 --- a/tests/r16_inventory/.crumb +++ b/tests/r16_inventory/.crumb @@ -14,19 +14,19 @@ "children": [ { "digest": "3b8ee545f13c1a168892b617671eebf2ee65413994332269f5d2f2dcf492aba7", - "last_commit": "6fdc4c3", + "last_commit": "6fdc4c33", "name": "fixture", "purpose": "Directory tests/r16_inventory/fixture. Purpose not yet described by a human." } ], "children_root": "sha256:36bda09ce85e797adb7f7712504802354c0adb1e1fc65e0d2ebf6a252f6ee1f0", - "compiled_at": "2026-10-04T13:47:05Z", + "compiled_at": "2026-10-12T05:17:54Z", "compiler": "crumb-compile/1", "digest": "sha256:ba0c09f67d12b5d7de906129bdbe2f6e0a228e1a34236ecc4b779c523cb2061e", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 9, - "generated_at_commit": "834ee93e4314a42c1127a2fcda8b29cf3b511245", + "generated_at_commit": "6e6f1c8e27b4f3a511bb284e7f51f2a957863ded", "source_tree": "sha256:c5359714281d3aee892eff6e268df24c436e97d07a5ac36ca452894067359808" }, "owner_lane": "", diff --git a/tests/r16_inventory/fixture/.crumb b/tests/r16_inventory/fixture/.crumb index 5f62ff7e0..47297449a 100644 --- a/tests/r16_inventory/fixture/.crumb +++ b/tests/r16_inventory/fixture/.crumb @@ -30,19 +30,19 @@ "children": [ { "digest": "9bfb0d9ca42bc56414db9d1842488e657e7163a3804e9c82c4c5a6629cf94399", - "last_commit": "6fdc4c3", + "last_commit": "6fdc4c33", "name": "physics", "purpose": "Directory tests/r16_inventory/fixture/physics. Purpose not yet described by a human." } ], "children_root": "sha256:a7d5f146d5c99c75701c8f384732dbdf7158a8fcd7295d0c0761c1e84d2c4e9d", - "compiled_at": "2026-10-04T13:47:05Z", + "compiled_at": "2026-10-12T05:17:54Z", "compiler": "crumb-compile/1", "digest": "sha256:3b8ee545f13c1a168892b617671eebf2ee65413994332269f5d2f2dcf492aba7", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 8, - "generated_at_commit": "834ee93e4314a42c1127a2fcda8b29cf3b511245", + "generated_at_commit": "6e6f1c8e27b4f3a511bb284e7f51f2a957863ded", "source_tree": "sha256:be8537e95e5ed29a32f2e6267c290f8b999a1537c3dd5c7e4f691791eabb74b6" }, "owner_lane": "",