Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ test_run_dir/
*.anno.json
site/
.DS_Store
.cache
.cache
*.fir
systemc/
11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export ARCH=`uname -m`
# Currently the image does not support arm64,
# We have to hard code the arch into amd64 as a workaround
# export ARCH=amd64
export VER=0.2
export VER=0.4

image:
make image-${ARCH}
Expand All @@ -25,13 +25,18 @@ container:
test:
if [ ${ARCH} = "arm64" ]; then docker run -u $(id -u):$(id -g) --rm -it -v ${PWD}:/workspace/ fangruil/chisel-dev:arm64 sbt test; else docker run -u $(id -u):$(id -g) --rm -it -v ${PWD}:/workspace/ fangruil/chisel-dev:amd64 sbt test; fi

build:
top.v:
if [ ${ARCH} = "arm64" ]; then docker run -u $(id -u):$(id -g) --rm -it -v ${PWD}:/workspace/ fangruil/chisel-dev:arm64 sbt run; else docker run -u $(id -u):$(id -g) --rm -it -v ${PWD}:/workspace/ fangruil/chisel-dev:amd64 sbt run; fi

build: top.v

build-sc: top.v
if [ ${ARCH} = "arm64" ]; then docker run -u $(id -u):$(id -g) --rm -it -v ${PWD}:/workspace/ fangruil/chisel-dev:arm64 verilator top.v -sc -Mdir systemc; else docker run -u $(id -u):$(id -g) --rm -it -v ${PWD}:/workspace/ fangruil/chisel-dev:amd64 verilator top.v -sc -Mdir systemc; fi

push:
make push-image-${ARCH}

push-x86_64:
push-image-x86_64:
make push-image-amd64

push-image-amd64:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ make container
make test
# Build verilog design from chisel
make build
# Build systemc
make build-sc
# Build docs, visit http://localhost:8000 to see the documentation
make docs
```
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ThisBuild / scalaVersion := "2.13.12"
ThisBuild / version := "0.1.0"
ThisBuild / organization := "%ORGANIZATION%"

val chiselVersion = "5.1.0"
val chiselVersion = "6.7.0"

lazy val root = (project in file("."))
.settings(
Expand Down
73 changes: 55 additions & 18 deletions docker/dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=$TARGETPLATFORM ubuntu:22.04 AS base
FROM --platform=$TARGETPLATFORM ubuntu:24.04 AS base

# Chisel 3 docker image for Chip Dev
# ==========
Expand All @@ -10,24 +10,50 @@ USER root
RUN apt-get update && apt-get upgrade -y && apt install ca-certificates -y

FROM base AS base-amd64
RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse\n" > /etc/apt/sources.list; \
echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse\n" >> /etc/apt/sources.list; \
echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse\n" >> /etc/apt/sources.list; \
echo "deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse\n" >> /etc/apt/sources.list;
RUN apt-get update && apt-get install default-jdk sudo git make autoconf g++ flex bison curl wget gnupg ninja-build cmake -y && apt-get clean -y
RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble main restricted universe multiverse\n" > /etc/apt/sources.list; \
echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-updates main restricted universe multiverse\n" >> /etc/apt/sources.list; \
echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-backports main restricted universe multiverse\n" >> /etc/apt/sources.list; \
echo "deb http://security.ubuntu.com/ubuntu/ noble-security main restricted universe multiverse\n" >> /etc/apt/sources.list;
RUN apt-get update && apt-get install default-jdk sudo git make autoconf g++ flex bison curl wget gnupg ninja-build help2man cmake -y && apt-get clean -y
WORKDIR /workspace/
# install firtool
RUN wget -q -O - https://github.com/llvm/circt/releases/download/firtool-1.38.0/firrtl-bin-ubuntu-20.04.tar.gz | tar -zx && mv firtool-1.38.0/bin/firtool /usr/local/bin/
RUN mkdir circt && \
wget -O - https://github.com/llvm/circt/releases/download/firtool-1.62.1/circt-full-sources.tar.gz | tar -xz -C circt && \
cd /workspace/circt && \
mkdir -p llvm/build && cd llvm/build && \
cmake -G Ninja /workspace/circt/llvm/llvm \
-DLLVM_ENABLE_PROJECTS="mlir" \
-DLLVM_TARGETS_TO_BUILD="host" \
-DCMAKE_JOB_POOLS="compile=8;link=1" \
-DCMAKE_JOB_POOL_LINK="link" \
-DCMAKE_JOB_POOL_COMPILE="compile" \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DCMAKE_BUILD_TYPE=RELEASE \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON && ninja && \
mkdir -p /workspace/circt/build && cd /workspace/circt/build && \
sed -ie 's/"unknown git version"/"firtool-1.62.1"/g' /workspace/circt/cmake/modules/GenVersionFile.cmake && \
cmake -G Ninja /workspace/circt \
-DMLIR_DIR=/workspace/circt/llvm/build/lib/cmake/mlir \
-DLLVM_DIR=/workspace/circt/llvm/build/lib/cmake/llvm \
-DCMAKE_JOB_POOLS="compile=8;link=1" \
-DCMAKE_JOB_POOL_LINK="link" \
-DCMAKE_JOB_POOL_COMPILE="compile" \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DCMAKE_BUILD_TYPE=RELEASE \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON && ninja && \
mv /workspace/circt/build/bin/* /usr/local/bin/ && cd /workspace && rm -rf /workspace/circt


FROM base AS base-arm64
RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy main restricted universe multiverse" > /etc/apt/sources.list; \
echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-updates main restricted universe multiverse" >> /etc/apt/sources.list; \
echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-backports main restricted universe multiverse" >> /etc/apt/sources.list; \
echo "deb http://ports.ubuntu.com/ubuntu-ports/ jammy-security main restricted universe multiverse" >> /etc/apt/sources.list;
RUN apt-get update && apt-get install default-jdk sudo git make autoconf g++ flex bison curl wget gnupg ninja-build cmake -y && apt-get clean -y
RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ noble main restricted universe multiverse" > /etc/apt/sources.list; \
echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ noble-updates main restricted universe multiverse" >> /etc/apt/sources.list; \
echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ noble-backports main restricted universe multiverse" >> /etc/apt/sources.list; \
echo "deb http://ports.ubuntu.com/ubuntu-ports/ noble-security main restricted universe multiverse" >> /etc/apt/sources.list;
RUN apt-get update && apt-get install default-jdk sudo git make autoconf g++ flex bison curl wget gnupg ninja-build help2man cmake -y && apt-get clean -y
WORKDIR /workspace/
# install firtool
RUN mkdir circt && \
wget -O - https://github.com/llvm/circt/releases/download/firtool-1.38.0/circt-full-sources.tar.gz | tar -xz -C circt && \
wget -O - https://github.com/llvm/circt/releases/download/firtool-1.62.1/circt-full-sources.tar.gz | tar -xz -C circt && \
cd /workspace/circt && \
mkdir -p llvm/build && cd llvm/build && \
cmake -G Ninja /workspace/circt/llvm/llvm \
Expand All @@ -40,7 +66,7 @@ RUN mkdir circt && \
-DCMAKE_BUILD_TYPE=RELEASE \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON && ninja && \
mkdir -p /workspace/circt/build && cd /workspace/circt/build && \
sed -ie 's/"unknown git version"/"firtool-1.38.0"/g' /workspace/circt/cmake/modules/GenVersionFile.cmake && \
sed -ie 's/"unknown git version"/"firtool-1.62.1"/g' /workspace/circt/cmake/modules/GenVersionFile.cmake && \
cmake -G Ninja /workspace/circt \
-DMLIR_DIR=/workspace/circt/llvm/build/lib/cmake/mlir \
-DLLVM_DIR=/workspace/circt/llvm/build/lib/cmake/llvm \
Expand All @@ -50,12 +76,12 @@ RUN mkdir circt && \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DCMAKE_BUILD_TYPE=RELEASE \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON && ninja && \
mv /workspace/circt/build/bin/firtool /usr/local/bin/ && cd /workspace && rm -rf /workspace/circt
mv /workspace/circt/build/bin/* /usr/local/bin/ && cd /workspace && rm -rf /workspace/circt

FROM base-${TARGETARCH} AS env

WORKDIR /workspace/
RUN git clone --progress https://github.com/verilator/verilator && cd /workspace/verilator && git pull && git checkout v4.226 && autoconf && ./configure && make -j8 && make install && make clean && rm -rf /workspace/verilator
RUN git clone --progress https://github.com/verilator/verilator && cd /workspace/verilator && git pull && git checkout v5.036 && autoconf && ./configure && make -j8 && make install && make clean && rm -rf /workspace/verilator

WORKDIR /workspace/

Expand All @@ -72,11 +98,22 @@ FROM env AS scala-arm64
RUN curl -fL https://github.com/VirtusLab/coursier-m1/releases/latest/download/cs-aarch64-pc-linux.gz | gzip -d > cs && chmod +x cs && ./cs setup -y && rm -rf cs-aarch64-pc-linux.gz

# build chisel
FROM scala-${TARGETARCH}
FROM scala-${TARGETARCH} AS final
ENV PATH="${PATH}:/root/.local/share/coursier/bin/:/usr/local/bin/"
RUN git clone --progress https://github.com/chipsalliance/chisel.git && cd /workspace/chisel/ && git checkout v5.1.0 && sbt compile && sbt "unipublish / publishLocal" && rm -rf /workspace/chisel
RUN git clone --progress https://github.com/chipsalliance/chisel.git && cd /workspace/chisel/ && git checkout v6.7.0 && sbt compile && sbt "unipublish / publishLocal" && rm -rf /workspace/chisel

# install systemc 3.0.1
FROM final
WORKDIR /workspace
RUN apt-get update && apt-get install libtool -y && apt-get clean -y
RUN wget -O - https://github.com/accellera-official/systemc/archive/refs/tags/3.0.1.tar.gz | tar -xz && \
cd /workspace/systemc-3.0.1 && mkdir build && cd build && \
cmake -S .. -B . -DCMAKE_INSTALL_PREFIX=/opt/systemc -DBUILD_SHARED_LIBS=OFF && make -j8 && make install && cd /workspace && rm -rf systemc-3.0.1

# clean up chisel sources
WORKDIR /workspace/
ENV COURSIER_CACHE="/workspace/.cache/coursier/v1"
ENV CHISEL_FIRTOOL_PATH=/usr/local/bin
ENV SYSTEMC_INCLUDE=/opt/systemc/include
ENV SYSTEMC_LIBDIR=/opt/systemc/lib
CMD ["bash"]
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version = 1.8.2
sbt.version = 1.9.7
6 changes: 3 additions & 3 deletions src/main/scala/alu/mma/sa/dataCollector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ class DataCollector(val n: Int = 8, val nbits: Int = 8) extends Module {
val col = (cnt - i.U) % n.U
if (i == n - 1) {
when (io.use_accum){
io.reg_out(i) := io.reg_in((i * n).U + col) + io.accum_in(i)
io.reg_out(i) := io.reg_in((i * n).U(log2Ceil(n*n).W) + col) + io.accum_in(i)
} .otherwise {
io.reg_out(i) := io.reg_in((i * n).U + col)
io.reg_out(i) := io.reg_in((i * n).U(log2Ceil(n*n).W) + col)
}
} else {
buffer(i).io.enq.valid := true.B
buffer(i).io.enq.bits := io.reg_in((i * n).U + col)
buffer(i).io.enq.bits := io.reg_in((i * n).U(log2Ceil(n*n).W) + col)
when (io.use_accum){
io.reg_out(i) := buffer(i).io.deq.bits + io.accum_in(i)
} .otherwise {
Expand Down
20 changes: 10 additions & 10 deletions src/test/scala/alu/mma/MMALUSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import alu.pe._
import testUtil._
import scala.util.Random
import chisel3._
import chiseltest._
import chisel3.simulator.EphemeralSimulator._
import org.scalatest.flatspec.AnyFlatSpec
import chisel3.experimental.BundleLiterals._

class MMALUSpec extends AnyFlatSpec with ChiselScalatestTester {
class MMALUSpec extends AnyFlatSpec {

"MMALU" should "do a normal matrix multiplication" in {
test(new MMALU(new MMPE(8, 32), 4, 8, 32)) { dut =>
simulate(new MMALU(new MMPE(8, 32), 4, 8, 32)) { dut =>
val print_helper = new testUtil.PrintHelper()
val _n = dut.n
val rand = new Random
Expand Down Expand Up @@ -82,7 +82,7 @@ class MMALUSpec extends AnyFlatSpec with ChiselScalatestTester {
// systolic array will start to spit out after _n - 1 ticks
if (i_tick >= 2 * _n - 2) {
for (_i <- 0 until _n) {
_res(step * _n + _i) = dut.io.out(_i).peekInt().toInt
_res(step * _n + _i) = dut.io.out(_i).peek().litValue.toInt
println("Tick @ " + i_tick + " producing at location (" + _i + ", " + step + "): " + _res(step * _n + _i))
dut.io.out(_i).expect(_expected(step * _n + _i))
}
Expand All @@ -95,7 +95,7 @@ class MMALUSpec extends AnyFlatSpec with ChiselScalatestTester {
}

"MMALU" should "do a normal matrix multiplication in stream" in {
test(new MMALU(new MMPE(8, 32), 4, 8, 32)) { dut =>
simulate(new MMALU(new MMPE(8, 32), 4, 8, 32)) { dut =>
val print_helper = new testUtil.PrintHelper()
val _n = dut.n
val rand = new Random
Expand Down Expand Up @@ -187,10 +187,10 @@ class MMALUSpec extends AnyFlatSpec with ChiselScalatestTester {
dut.clock.step()

// systolic array will start to spit out after _n - 1 ticks for mat_c
println("Tick @ " + i_tick + " clct signal " + dut.io.clct.peekInt().toInt)
println("Tick @ " + i_tick + " clct signal " + dut.io.clct.peek().litValue.toInt)
if (i_tick >= 2 * _n - 2 && i_tick < 3 * _n - 2) {
for (_i <- 0 until _n) {
_res_c(step * _n + _i) = dut.io.out(_i).peekInt().toInt
_res_c(step * _n + _i) = dut.io.out(_i).peek().litValue.toInt
println("Tick @ " + i_tick + " Mat C producing at location (" + _i + ", " + step + "): " + _res_c(step * _n + _i))
dut.io.out(_i).expect(_expected_c(step * _n + _i))
}
Expand All @@ -199,7 +199,7 @@ class MMALUSpec extends AnyFlatSpec with ChiselScalatestTester {
// systolic array will start to generate again after 3 * _n - 2 ticks
if (i_tick >= 3 * _n - 2 && i_tick < 4 * _n - 2){
for (_i <- 0 until _n) {
_res_f((step % _n) * _n + _i) = dut.io.out(_i).peekInt().toInt
_res_f((step % _n) * _n + _i) = dut.io.out(_i).peek().litValue.toInt
println("OUT Tick @ " + i_tick + " Mat F producing at location (" + _i + ", " + step % _n + "): " + _res_f((step % _n) * _n + _i))
dut.io.out(_i).expect(_expected_f((step % _n) * _n + _i))
}
Expand All @@ -215,7 +215,7 @@ class MMALUSpec extends AnyFlatSpec with ChiselScalatestTester {
}

"MMALU" should "do a generic matrix multiplication" in {
test(new MMALU(new MMPE(8, 32), 4, 8, 32)) { dut =>
simulate(new MMALU(new MMPE(8, 32), 4, 8, 32)) { dut =>
val print_helper = new testUtil.PrintHelper()
val _n = dut.n
val rand = new Random
Expand Down Expand Up @@ -293,7 +293,7 @@ class MMALUSpec extends AnyFlatSpec with ChiselScalatestTester {
// systolic array will start to spit out after _n - 1 ticks
if (i_tick >= 2 * _n - 2) {
for (_i <- 0 until _n) {
_res(step * _n + _i) = dut.io.out(_i).peekInt().toInt
_res(step * _n + _i) = dut.io.out(_i).peek().litValue.toInt
println("Tick @ " + i_tick + " producing at location (" + _i + ", " + step + "): " + _res(step * _n + _i))
dut.io.out(_i).expect(_expected(step * _n + _i))
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/scala/alu/mma/cu/CUSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ package alu.mma.cu
import testUtil._
import scala.util.Random
import chisel3._
import chiseltest._
import chisel3.simulator.EphemeralSimulator._
import org.scalatest.flatspec.AnyFlatSpec
import chisel3.experimental.BundleLiterals._

class CUSpec extends AnyFlatSpec with ChiselScalatestTester {
class CUSpec extends AnyFlatSpec {

"CU" should "send control to 2D systolic array" in {
test(new ControlUnit(4)) { dut =>
simulate(new ControlUnit(4)) { dut =>
val print_helper = new testUtil.PrintHelper()
val _n = dut.n
val rand = new Random
Expand Down
8 changes: 4 additions & 4 deletions src/test/scala/alu/mma/sa/DataCollectorSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ package alu.mma.sa
import testUtil._
import scala.util.Random
import chisel3._
import chiseltest._
import chisel3.simulator.EphemeralSimulator._
import org.scalatest.flatspec.AnyFlatSpec
import chisel3.experimental.BundleLiterals._

class DataCollectorSpec extends AnyFlatSpec with ChiselScalatestTester {
class DataCollectorSpec extends AnyFlatSpec{

"SA Data Collector" should "collect correct matrix pattern" in {
test(new DataCollector(4)) { dut =>
simulate(new DataCollector(4)) { dut =>
val print_helper = new testUtil.PrintHelper()
val _n = dut.n
val rand = new Random
Expand Down Expand Up @@ -50,7 +50,7 @@ class DataCollectorSpec extends AnyFlatSpec with ChiselScalatestTester {
// show the output
var _in_str_out = ""
for (__i <- 0 until _n) {
_in_str_out += dut.io.reg_out(__i).peekInt().toInt.toString() + ","
_in_str_out += dut.io.reg_out(__i).peek().litValue.toInt.toString() + ","
}
println("Output Vector A tick @ " + i_tick + ": [" + _in_str_out + "]")

Expand Down
12 changes: 6 additions & 6 deletions src/test/scala/alu/mma/sa/DataFeederSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ package alu.mma.sa
import testUtil._
import scala.util.Random
import chisel3._
import chiseltest._
import chisel3.simulator.EphemeralSimulator._
import org.scalatest.flatspec.AnyFlatSpec
import chisel3.experimental.BundleLiterals._

class DataFeederSpec extends AnyFlatSpec with ChiselScalatestTester {
class DataFeederSpec extends AnyFlatSpec {

"SA Data Feeder" should "generate correct matrix pattern" in {
test(new DataFeeder(4)) { dut =>
simulate(new DataFeeder(4)) { dut =>
val print_helper = new testUtil.PrintHelper()
val _n = dut.n
val rand = new Random
Expand Down Expand Up @@ -76,9 +76,9 @@ class DataFeederSpec extends AnyFlatSpec with ChiselScalatestTester {
var _b_in_str_out = ""
var _c_in_str_out = ""
for (__i <- 0 until _n) {
_a_in_str_out += dut.io.reg_a_out(__i).peekInt().toInt.toString() + ","
_b_in_str_out += dut.io.reg_b_out(__i).peekInt().toInt.toString() + ","
_c_in_str_out += dut.io.reg_accum_out(__i).peekInt().toInt.toString() + ","
_a_in_str_out += dut.io.reg_a_out(__i).peek().litValue.toInt.toString() + ","
_b_in_str_out += dut.io.reg_b_out(__i).peek().litValue.toInt.toString() + ","
_c_in_str_out += dut.io.reg_accum_out(__i).peek().litValue.toInt.toString() + ","
}
println("Output Vector A tick @ " + i_tick + ": [" + _a_in_str_out + "]")
println("Output Vector B tick @ " + i_tick + ": [" + _b_in_str_out + "]")
Expand Down
Loading