- Notifications
You must be signed in to change notification settings - Fork0
yasnakateb/ChipyardIntegration
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
In this guide, I’ll take you through the (sometimes frustrating) journey of integrating a custom RoCC accelerator with Chipyard. Please make sure you’re referencingChipyard’s docs if you get stuck.
Warning: Be mindful of your Chipyard version. I’m usingv1.10.0—trust me, it matters. Plus I am using Ubuntu!
- Head over to theAnaconda installer list and grab the one that matches your OS.
- Open your terminal, and let’s run this:
bash~/Downloads/Anaconda3-<INSTALLER_VERSION>-Linux-x86_64.sh
- Type "yes" as needed (agree to that license, get your Anaconda initialized, etc.).
- The default install location? Right here:
PREFIX=/home/<USER>/anaconda3
source<PATH_TO_CONDA>/bin/activateconda init
source~/.bashrc
(By the way, still usingbashrc
? Notzshrc
? Are you sure you don’t wanna move on? Just saying...🤣🤣🤣)
(Optional: Want your shell to auto-activate Anaconda every time it opens? Here you go:)
conda config --set auto_activate_base True
conda install -n base conda-libmamba-solverconda config --set solver libmambaconda activate base
Clone the Chipyard repo and check out the right version:
git clone https://github.com/ucb-bar/chipyard.gitcd chipyardgit checkout 1.10.0
Run the setup script and skip the extras (because time is precious):
./build-setup.sh riscv-tools -s 6 -s 7 -s 8 -s 9
-s 6
: Skips FireSim (only if you don’t need it)-s 7
: Skips FireSim source pre-compilation (trust me, skip it)-s 8
: Skips FireMarshal (Fire what?)-s 9
: Skips FireMarshal Linux pre-compilation (we’ve got other things to do)
After all that, source the environment script every time:
source ./env.sh
(Pro tip: Save yourself the trouble by creating an alias in
.bashrc
, still usingbashrc
?)alias chip="cd /home/USER/chipyard/ && source env.sh"
Structure your project directory like this:
Takhol/ build.sbt src/main/scala/Takhol.scala
Add the project settings to
build.sbt
:organization:="edu.berkeley.cs"version:="1.0"name:="Takhol"scalaVersion:="2.12.13"
Add Takhol to Chipyard’s
generators/
directory:cd generators/git submodule add https://git-repository.com/Takhol.gitgit submodule update --recursive generators/Takhol
Link Takhol to Chipyard’s top-level
build.sbt
file:lazyvalTakhol= (project in file("generators/Takhol")) .dependsOn(rocketchip) .settings(libraryDependencies++= rocketLibDeps.value) .settings(commonSettings)
Add Takhol as a dependency in the sub-projects section:
lazyvalchipyard= (project in file("generators/chipyard")) .dependsOn(testchipip, rocketchip, boom, hwacha,Takhol, ...) .settings(libraryDependencies++= rocketLibDeps.value) .settings( libraryDependencies++=Seq("org.reflections"%"reflections"%"0.10.2" ) ) .settings(commonSettings)
sbt build
Find theRocketConfigs.scala
file (maybe inchipyard/generators/chipyard/src/main/scala/config/
) and add your custom config:
classTakholRocketConfigextendsConfig (newTakhol.WithTakhol++new freechips.rocketchip.subsystem.WithNBigCores(1)++// single rocket-corenew chipyard.config.AbstractConfig)
If the command above seems unclear, and you're unfamiliar with configuring settings in Chipyard or Chisel projects, let me provide a brief overview.
Imagine that in your Takhol.scala file, you define a set of parameters such as rows and columns. To manage these parameters more effectively, you can create a new file named config.scala. This file would look something like this:
packageTakholimportorg.chipsalliance.cde.config._classWithTakholextendsConfig((site, here, up)=> {caseTakholKey=>TakholParams( rows=4, columns=4 )})
Now, you can use these parameters directly in your Takhol.scala file. Your Takhol.scala might look something like this:
packageTakholimportchisel3._importchisel3.util._importorg.chipsalliance.cde.config._caseclassTakholParams(rows:Int,columns:Int)caseobjectTakholKeyextendsField[TakholParams]abstracttraitTakholParameters {implicitvalp:ParametersvaltakholParams= p(TakholKey)valrows= takholParams.rowsvalcolumns= takholParams.columns }
You now haverows
andcolumns
inTakhol.scala
that you can use them as you wish.
Inside
chipyard/sims/verilator
, create a folder for your program:mkdir srccd srctouch hello_world.c
Write your first RISC-V program in
hello_world.c
(simple and classic):#include<stdio.h>intmain(void) {printf("Hello, World!\n");return0;}
Build the program:
riscv64-unknown-elf-gcc -fno-common -fno-builtin-printf -specs=htif_nano.specs -c hello_world.criscv64-unknown-elf-gcc -static -specs=htif_nano.specs hello_world.o -o hello_world.riscvspike hello_world.riscv
If you are lazy like me, create a
run.sh
script to compile and test your code with all baremetal programs:#!/bin/bashif [-z"$1" ];thenecho"Usage: sh file.sh <filename.c>"exit 1fifilename=$(basename"$1" .c)echo"riscv64-unknown-elf-gcc -fno-common -fno-builtin-printf -specs=htif_nano.specs -c$filename.c"riscv64-unknown-elf-gcc -fno-common -fno-builtin-printf -specs=htif_nano.specs -c"$filename.c" -o"$filename.o"echo"riscv64-unknown-elf-gcc -static -specs=htif_nano.specs$filename.o -o$filename.riscv"riscv64-unknown-elf-gcc -static -specs=htif_nano.specs"$filename.o" -o"$filename.riscv"echo"spike$filename.riscv"spike"$filename.riscv"rm"$filename.o"%
and then run it:
chmod +x run.sh./run.sh hello_world.c
(If you get an error about
htif_nano.specs
, you missed sourcingenv.sh
earlier. Go back, fix it, and try again!)Run the simulation with VCD output (yes, you’ll want this):
make CONFIG=TakholRocketConfig BINARY=src/hello_world.riscv run-binary-debug
Check the output folder for simulation results, including the.vcd
file. If you see “Hello, World!” on your terminal, rejoice—everything works. If not... well, you know where to look.
Congrats! You’re now fully set up to experiment and debug your custom accelerator in Chipyard. Enjoy the chaos and the code!
About
😱 RoCC Accelerator Integration with Chipyard
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.