Altifigence Academy

13 / 20 · Concept

Tiling and boundary padding

Map larger matrices onto a smaller grid and handle zero padding and output masks.

Tile output space first

An N×N grid handles a larger M×P result using ceil(M/N)×ceil(P/N) spatial tiles. Our baseline retains the entire reduction K within each tile and clears between output tiles. The wrapper stores tile origin r0,c0; local PE(i,j) maps to global C(r0+i,c0+j). Skew depends on local coordinates.

Take N=2 and M=P=K=3. Let A=[[1,2,3],[4,5,6],[7,8,9]] and B=[[1,0,2],[0,1,0],[2,0,1]]. Their product is [[7,2,5],[16,5,14],[25,8,23]]. The four tile origins are (0,0), (0,2), (2,0) and (2,2).

Pad operands, mask stores

Supply out-of-range A rows and B columns as valid zero tokens. Each PE still consumes K terms, preserving the simple completion contract. Invalidating padded terms instead can leave some counts below K forever. Separately mask result stores to prevent writes outside the real matrix.

The final tile uses A=[[7,8,9],[0,0,0]] and B=[[2,0],[0,0],[1,0]]. Its local result is [[23,0],[0,0]], but only the top-left value may be written to C(2,2). A numerical zero does not make an out-of-range address safe.

Each tile uses five advance edges, totaling twenty for four sequential tiles, excluding clear, loading and output transfer. The grid executes forty-eight padded MACs; only twenty-seven belong to the real 3×3 product.

Reduction tiling needs retained sums

Splitting K requires combining partial sums for the same output. C(0,0)=1×1+2×0+3×2=7 splits into partials one and six for K=2+1. Clearing the final accumulator between those reductions leaves only six. Retain the accumulator or combine wide partial sums elsewhere. Quantizing each partial before combination can differ from quantizing the complete sum once.

The capstone begins with spatial tiling and full K. Test single-element boundaries, dimensions divisible by N, a final tile with one real output, valid padded zeros, and output masks. Key the reference scoreboard by global coordinates so changing tile order cannot change the expected result.

Try it yourself

For the (0,2) tile in the 3×3 example, give the output mask and local result. What are C(0,2)'s partial sums when K splits into 2+1?

Read the explanation

The local result is [[5,0],[14,0]] and mask [[1,0],[1,0]]. C(0,2)=1×2+2×0+3×1 has partial sums two and three, totaling five.

Your choice applies to this browser. Change it any time using the footer.