DEV Community

Building a Full-Stack Trace for Neural Networks on RISC-V

I recently open-sourced coresample, a project that maps the execution of a neural network from high-level model code down to the specific hardware pipeline stalls on a custom RISC-V core.

The Problem

I wanted to understand exactly how a neural network consumes cycles on a CPU. Standard profilers often hide the hardware-level details, and simulators can be black boxes. I wanted to see the instruction-level impact of a quantized CNN on a 5-stage pipeline.

What I Built

  • Model: A Rust-based simulator for int8 CNNs.
  • Compiler: A tool that maps network operations to RV32IM instructions.
  • CPU: A RISC-V core implemented in SystemVerilog, verified against Spike and standard RISC-V test suites.
  • Inspector: A web-based tool that visualizes the execution trace, showing every cycle accounted for.

How it Works

Everything is built to be verifiable. The CPU is tested against riscv-tests and riscv-arch-test. The network simulator matches PyTorch results, and the compiler ensures the generated instructions map correctly to the model's layers.

You can see the full trace of an int8 CNN running on 48 images, including where the pipeline stalls.

Next Steps

I am currently working on adding a GPT-style transformer block to the simulator and tracing its tokens through the pipeline. If you are interested in computer architecture, RISC-V, or hardware-software co-design, I would love to hear your thoughts on the approach or the tooling used. You can check out the repository to run the simulations yourself.

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.