19 / 20 · Lab
Capstone: a tiled N×N verification model
Combine arbitrary N and K with padding and pauses and compare against an independent reference.
Lessons are free to read. Enroll to save your learning progress.
Assemble the complete model
The capstone accepts A of shape M×K and B of shape K×P on an N×N grid. Every spatial tile starts empty, padded operands are valid zeros, and stores are masked by coordinates. Only one job occupies a tile, and global pauses hold logical time. Output quantization remains a separate test after the wide sum.
Save this as capstone-lab.mjs and run node capstone-lab.mjs. No packages are required. Inputs are small integer fixtures within JavaScript Number's exact range; larger ranges need BigInt and explicit width checks. This checks a Node arithmetic/schedule model, independently of RTL or DDS execution.
import assert from 'node:assert/strict';
function golden(A,B){return A.map(r=>B[0].map((_,j)=>
r.reduce((s,a,k)=>s+a*B[k][j],0)));}
function solve(A,B,N,pauses=new Set()){
const M=A.length,K=A[0].length,P=B[0].length;
assert.ok(N>=1&&Number.isInteger(N)&&K>=1);assert.equal(B.length,K);
assert.ok(A.every(r=>r.length===K)&&B.every(r=>r.length===P));
const C=Array.from({length:M},()=>Array(P).fill(null));
let advances=0,physical=0;
for(let r0=0;r0<M;r0+=N)for(let c0=0;c0<P;c0+=N){
const job=r0*P+c0;
let g=Array.from({length:N},()=>Array.from({length:N},()=>
({a:null,b:null,acc:0,count:0})));
const token=(value,k)=>({value,k,job});let t=0,p=0;
while(t<K+2*N-2){
if(pauses.has(p)){p++;continue;}
const next=g.map(r=>r.map(pe=>({...pe})));
for(let i=0;i<N;i++)for(let j=0;j<N;j++){
const ka=t-i,kb=t-j;
const a=j?g[i][j-1].a:(ka>=0&&ka<K?
token(r0+i<M?A[r0+i][ka]:0,ka):null);
const b=i?g[i-1][j].b:(kb>=0&&kb<K?
token(c0+j<P?B[kb][c0+j]:0,kb):null);
const pe=next[i][j];pe.a=a;pe.b=b;
if(a&&b){assert.equal(a.job,b.job);assert.equal(a.k,b.k);
assert.equal(a.k,pe.count);pe.acc+=a.value*b.value;pe.count++;}}
g=next;t++;p++;
}
for(let i=0;i<N;i++)for(let j=0;j<N;j++){
assert.equal(g[i][j].count,K);
if(r0+i<M&&c0+j<P){assert.equal(C[r0+i][c0+j],null);
C[r0+i][c0+j]=g[i][j].acc;}}
advances+=t;physical+=p;
}
return {C,advances,physical};
}
const A=[[1,2,3],[4,5,6],[7,8,9]],B=[[1,0,2],[0,1,0],[2,0,1]];
for(const N of [1,2,3])assert.deepEqual(
solve(A,B,N,new Set([1,2])).C,golden(A,B));
const run=solve(A,B,2,new Set([1,2]));
assert.deepEqual(run.C,[[7,2,5],[16,5,14],[25,8,23]]);
assert.equal(run.advances,20);assert.equal(run.physical,28);
assert.deepEqual(solve([[2,-1],[0,3]],[[4,5],[-2,1]],2).C,
[[10,9],[-6,3]]);
assert.deepEqual(solve([[-128]],[[-128]],1).C,[[16384]]);
console.log('Capstone lab passed');The golden function knows only matrix arithmetic. The solver independently shifts tagged tokens, checks ordered terms and masks stores. For N=2, four tiles take twenty advance edges. Pausing physical edges one and two in each tile adds eight pauses, totaling twenty-eight physical edges. Initialization, memory loading and serialized output transfer are excluded.
Submit the log, one tile's consumed-k trace, signed-width analysis and a valid/ready result-wrapper design. Preserve the edge contract when translating to RTL. Start with N=1,K=1 and 2×2 before scaling. Add quantization, retained partial sums or double buffering one at a time with new explicit checks.
The three grid sizes exercise different mappings: N=1 repeats unskewed dot products, N=2 exercises four padded tiles, and N=3 uses one complete tile. All must produce the same mathematical matrix. Initializing C with null distinguishes a valid zero from an undelivered output and detects duplicate stores. The tile-derived job number is unique here; real RTL must define its tag width and reuse policy. As an extension, try M=2,K=3,P=1 with hand-calculated expected values. The internal grid remains square while the output matrix is rectangular. Check every tile consumes the full K and suppresses out-of-range stores.
Try it yourself
For the 3×3 example with N=3 and pauses on physical edges one and two, find advance and physical-edge counts. What if measurement includes one preceding clear edge?
Read the explanation
There are seven advance edges and nine compute-interval physical edges including two pauses. Including one preceding clear edge gives ten; loading and output transfer remain excluded.