Network-on-chip topologies are usually hand-written RTL or vendor GUI exports. Both make early exploration and global validation difficult.
The problem
Mesh topology in SystemVerilog tangles instantiation with routing and timing:
genvar i, j;
generate
for (i = 0; i < ROWS; i++) begin
for (j = 0; j < COLS; j++) begin
router #(.ID(i*COLS+j)) r (.clk, .rst);
end
end
endgenerateA declarative DSL lets the compiler own the lowering. The designer specifies what, the topology, routing function, and timing constraints, and the compiler generates the structural RTL.
Spec surface (sketch)
A minimal topology DSL needs to express:
- Topology family, mesh, torus, tree, butterfly, custom graph
- Link parameters, width, clock domain, flow control
- Routing function, deterministic or adaptive, with deadlock constraints
- QoS requirements, latency bounds, bandwidth guarantees
Compiler outputs: RTL structure, SDC timing constraints, deadlock freedom proof.
A first slice: what Hermes does today
Hermes is where this sketch meets code. It is a Haskell library that takes hardware constraints and produces a Bluespec NoC. There is no surface syntax yet. The “spec” is an embedded Haskell record, and it is revealing that it describes what the chip can afford, not the topology:
ButterflyConstraints
{ targetBandwidth = 2.0 -- GBytes/s the network must deliver
, signalBandwidth = 1.0 -- Gbit/s each pin can signal at
, maxPinsPerChip = 150 -- I/O pins available
, totalEndpoints = 64 -- sources and sinks to connect
, overheadSignals = 2 -- control wires per channel (valid/ready)
}The compiler pipeline is a straight line, and every stage is an ordinary Haskell function:
constraints
-> solveTopology -> NetworkSpec {radix, stages}
-> generateBluespec -> HermesNoc.bsv
-> computeMetrics -> hops, bandwidth, router count
Solving for the topology
The solver is four lines of arithmetic. Run on the record above:
| Step | Rule | Result |
|---|---|---|
| Data wires per channel | \(\lceil 2.0 \times 8 / 1.0 \rceil\) | 16 |
| Channel width | data + overhead | 18 pins |
| Channels the pins allow | \(\lfloor 150 / 18 \rfloor\) | 8 |
| Radix \(k\) | largest power of 2 \(\le 8/2\) (each router needs an input and an output channel per port) | 4 |
| Stages \(s\) | \(\lceil \log_k N \rceil = \lceil \log_4 64 \rceil\) | 3 |
That is a 4-ary 3-fly: \(3 \times 4^2 = 48\) routers, and destination addresses of \(s \log_2 k = 6\) bits. Nobody chose “radix 4”. It fell out of a pin budget, which is the point: the designer states the constraint, the compiler owns the decision.
Lowering to Bluespec
generateBluespec writes a complete package: one Put ingress and one Get egress per endpoint, \(s \cdot k^{s-1}\) router instances, and the wiring between stages. Output port \(p\) of router \(r\) at stage \(t\) connects to a computed router and input port:
stride = k ^ (numStages - 2 - t)
destR = (r - r `mod` (k*stride)) + p*stride + (r `mod` stride)
destPort = (r `div` stride) `mod` kFor the example above, the four outputs of stage-0 router 1 land on routers 1, 5, 9 and 13, all at input port 0. That is the butterfly shuffle, and it is the part a human gets wrong by hand.
The router itself is not generated. It is a hand-written Bluespec library, and the split is deliberate: Haskell decides structure (how many routers, how they connect), while Bluespec decides behaviour (how one router moves packets). A packet is a stream of phits, Header then Payload* then Null, and the header carries the full multi-stage address. Each router reads one digit of it, addr[stage*log2(k) +: log2(k)], to choose its output port. Two details matter for a DSL:
- Wormhole locking. A per-output arbiter holds its grant for a whole packet, from
HeadertoNull, and each ingress port remembers its locked output in aroute_lockregister. - Static rule indices. The forwarding step is written as \(k^2\) rules with compile-time indices \((j, i)\), so the Bluespec scheduler can prove rules for different port pairs never conflict and fire them in the same cycle. The generator and the router library are cooperating with the compiler’s scheduler, and the DSL will need to preserve that property.
What the compiler can already say
Because the topology is a small closed-form object, performance comes before any RTL:
=== Butterfly NoC Performance Metrics ===
Hop count (stages) : 3
Analytical latency (hops) : 3
Total router instances : 48
Bisection bandwidth : 4.0 GBytes/s
Theoretical throughput : 8.0 GBytes/s
==========================================
These are analytical (derived from the parameters, not from simulation), so they are lower bounds on latency and upper bounds on throughput. They are cheap enough to sit in an exploration loop.
What Hermes teaches the DSL
- Constraints are a better entry point than topologies. A designer often knows a pin budget and a bandwidth target long before knowing a radix. The surface language should accept a constraint set and a topology family, and let the solver fill in the rest.
- Address width is a topology property. \(s \log_2 k\) bits flows from the solved spec into every type, as
Phit#(6). Today the router library only checks that the address is wide enough for one digit, and the generator is trusted to size it correctly. This is exactly where a stronger type discipline could close the gap. - A butterfly gets deadlock freedom for free, and that is not yet checked. It is feed-forward, so the channel dependency graph has no cycles, and the router uses stall-based backpressure with no dropped phits. But Hermes tests today check the generated text and the arithmetic (radix 4, 3 stages, 48 routers), not deadlock freedom. For a mesh or torus, with wraparound links, this becomes a real proof obligation the compiler would have to discharge.
- Keep the library and the generator separate. Structure from the compiler, microarchitecture from a reviewed library. It keeps the generated code small enough to read, and keeps the hard verification effort on one module instead of every generated network.
A possible surface syntax
Nothing below is implemented. It is the same record as above, written the way I would want to author it:
noc fabric {
endpoints 64
bandwidth 2.0 GB/s
pin_rate 1.0 Gb/s
pin_budget 150
control 2 wires // valid + ready
family butterfly // or: auto
}
Open questions
- Minimal calculus for topology + routing that remains synthesizable?
- Static verification of deadlock freedom at spec time, not post-layout? For a butterfly it holds by construction. What is the smallest extension (torus, fat tree) where it needs a real proof?
- How much of the routing function can be verified by type? The address width and the digit extraction are the first candidates.
- Which topology families admit a closed-form solver like the butterfly’s, and which need search?
- How far can analytical metrics be trusted before simulation is needed, and can the compiler say when it has reached that point?
Hermes is the working prototype of this idea, a NoC generator from a spec, and both share the view of hardware as a compiler target.