Skip to content

Commit 03f366e

Browse files
authored
Fangrui/export systemc (#7)
* changed docker file * update to 24.04 & chisel 6.7.0 * update to chisel 6.7.0 * fix warning * update systemc * update make file
1 parent 83d61f4 commit 03f366e

14 files changed

Lines changed: 111 additions & 65 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ test_run_dir/
88
*.anno.json
99
site/
1010
.DS_Store
11-
.cache
11+
.cache
12+
*.fir
13+
systemc/

Makefile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export ARCH=`uname -m`
44
# Currently the image does not support arm64,
55
# We have to hard code the arch into amd64 as a workaround
66
# export ARCH=amd64
7-
export VER=0.2
7+
export VER=0.4
88

99
image:
1010
make image-${ARCH}
@@ -25,13 +25,18 @@ container:
2525
test:
2626
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
2727

28-
build:
28+
top.v:
2929
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
3030

31+
build: top.v
32+
33+
build-sc: top.v
34+
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
35+
3136
push:
3237
make push-image-${ARCH}
3338

34-
push-x86_64:
39+
push-image-x86_64:
3540
make push-image-amd64
3641

3742
push-image-amd64:

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ make container
2323
make test
2424
# Build verilog design from chisel
2525
make build
26+
# Build systemc
27+
make build-sc
2628
# Build docs, visit http://localhost:8000 to see the documentation
2729
make docs
2830
```

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ThisBuild / scalaVersion := "2.13.12"
44
ThisBuild / version := "0.1.0"
55
ThisBuild / organization := "%ORGANIZATION%"
66

7-
val chiselVersion = "5.1.0"
7+
val chiselVersion = "6.7.0"
88

99
lazy val root = (project in file("."))
1010
.settings(

docker/dockerfile

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM --platform=$TARGETPLATFORM ubuntu:22.04 AS base
1+
FROM --platform=$TARGETPLATFORM ubuntu:24.04 AS base
22

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

1212
FROM base AS base-amd64
13-
RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse\n" > /etc/apt/sources.list; \
14-
echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse\n" >> /etc/apt/sources.list; \
15-
echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse\n" >> /etc/apt/sources.list; \
16-
echo "deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse\n" >> /etc/apt/sources.list;
17-
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
13+
RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble main restricted universe multiverse\n" > /etc/apt/sources.list; \
14+
echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-updates main restricted universe multiverse\n" >> /etc/apt/sources.list; \
15+
echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-backports main restricted universe multiverse\n" >> /etc/apt/sources.list; \
16+
echo "deb http://security.ubuntu.com/ubuntu/ noble-security main restricted universe multiverse\n" >> /etc/apt/sources.list;
17+
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
18+
WORKDIR /workspace/
1819
# install firtool
19-
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/
20+
RUN mkdir circt && \
21+
wget -O - https://github.com/llvm/circt/releases/download/firtool-1.62.1/circt-full-sources.tar.gz | tar -xz -C circt && \
22+
cd /workspace/circt && \
23+
mkdir -p llvm/build && cd llvm/build && \
24+
cmake -G Ninja /workspace/circt/llvm/llvm \
25+
-DLLVM_ENABLE_PROJECTS="mlir" \
26+
-DLLVM_TARGETS_TO_BUILD="host" \
27+
-DCMAKE_JOB_POOLS="compile=8;link=1" \
28+
-DCMAKE_JOB_POOL_LINK="link" \
29+
-DCMAKE_JOB_POOL_COMPILE="compile" \
30+
-DLLVM_ENABLE_ASSERTIONS=ON \
31+
-DCMAKE_BUILD_TYPE=RELEASE \
32+
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON && ninja && \
33+
mkdir -p /workspace/circt/build && cd /workspace/circt/build && \
34+
sed -ie 's/"unknown git version"/"firtool-1.62.1"/g' /workspace/circt/cmake/modules/GenVersionFile.cmake && \
35+
cmake -G Ninja /workspace/circt \
36+
-DMLIR_DIR=/workspace/circt/llvm/build/lib/cmake/mlir \
37+
-DLLVM_DIR=/workspace/circt/llvm/build/lib/cmake/llvm \
38+
-DCMAKE_JOB_POOLS="compile=8;link=1" \
39+
-DCMAKE_JOB_POOL_LINK="link" \
40+
-DCMAKE_JOB_POOL_COMPILE="compile" \
41+
-DLLVM_ENABLE_ASSERTIONS=ON \
42+
-DCMAKE_BUILD_TYPE=RELEASE \
43+
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON && ninja && \
44+
mv /workspace/circt/build/bin/* /usr/local/bin/ && cd /workspace && rm -rf /workspace/circt
45+
2046

2147
FROM base AS base-arm64
22-
RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy main restricted universe multiverse" > /etc/apt/sources.list; \
23-
echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-updates main restricted universe multiverse" >> /etc/apt/sources.list; \
24-
echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-backports main restricted universe multiverse" >> /etc/apt/sources.list; \
25-
echo "deb http://ports.ubuntu.com/ubuntu-ports/ jammy-security main restricted universe multiverse" >> /etc/apt/sources.list;
26-
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
48+
RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ noble main restricted universe multiverse" > /etc/apt/sources.list; \
49+
echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ noble-updates main restricted universe multiverse" >> /etc/apt/sources.list; \
50+
echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ noble-backports main restricted universe multiverse" >> /etc/apt/sources.list; \
51+
echo "deb http://ports.ubuntu.com/ubuntu-ports/ noble-security main restricted universe multiverse" >> /etc/apt/sources.list;
52+
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
2753
WORKDIR /workspace/
2854
# install firtool
2955
RUN mkdir circt && \
30-
wget -O - https://github.com/llvm/circt/releases/download/firtool-1.38.0/circt-full-sources.tar.gz | tar -xz -C circt && \
56+
wget -O - https://github.com/llvm/circt/releases/download/firtool-1.62.1/circt-full-sources.tar.gz | tar -xz -C circt && \
3157
cd /workspace/circt && \
3258
mkdir -p llvm/build && cd llvm/build && \
3359
cmake -G Ninja /workspace/circt/llvm/llvm \
@@ -40,7 +66,7 @@ RUN mkdir circt && \
4066
-DCMAKE_BUILD_TYPE=RELEASE \
4167
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON && ninja && \
4268
mkdir -p /workspace/circt/build && cd /workspace/circt/build && \
43-
sed -ie 's/"unknown git version"/"firtool-1.38.0"/g' /workspace/circt/cmake/modules/GenVersionFile.cmake && \
69+
sed -ie 's/"unknown git version"/"firtool-1.62.1"/g' /workspace/circt/cmake/modules/GenVersionFile.cmake && \
4470
cmake -G Ninja /workspace/circt \
4571
-DMLIR_DIR=/workspace/circt/llvm/build/lib/cmake/mlir \
4672
-DLLVM_DIR=/workspace/circt/llvm/build/lib/cmake/llvm \
@@ -50,12 +76,12 @@ RUN mkdir circt && \
5076
-DLLVM_ENABLE_ASSERTIONS=ON \
5177
-DCMAKE_BUILD_TYPE=RELEASE \
5278
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON && ninja && \
53-
mv /workspace/circt/build/bin/firtool /usr/local/bin/ && cd /workspace && rm -rf /workspace/circt
79+
mv /workspace/circt/build/bin/* /usr/local/bin/ && cd /workspace && rm -rf /workspace/circt
5480

5581
FROM base-${TARGETARCH} AS env
5682

5783
WORKDIR /workspace/
58-
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
84+
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
5985

6086
WORKDIR /workspace/
6187

@@ -72,11 +98,22 @@ FROM env AS scala-arm64
7298
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
7399

74100
# build chisel
75-
FROM scala-${TARGETARCH}
101+
FROM scala-${TARGETARCH} AS final
76102
ENV PATH="${PATH}:/root/.local/share/coursier/bin/:/usr/local/bin/"
77-
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
103+
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
104+
105+
# install systemc 3.0.1
106+
FROM final
107+
WORKDIR /workspace
108+
RUN apt-get update && apt-get install libtool -y && apt-get clean -y
109+
RUN wget -O - https://github.com/accellera-official/systemc/archive/refs/tags/3.0.1.tar.gz | tar -xz && \
110+
cd /workspace/systemc-3.0.1 && mkdir build && cd build && \
111+
cmake -S .. -B . -DCMAKE_INSTALL_PREFIX=/opt/systemc -DBUILD_SHARED_LIBS=OFF && make -j8 && make install && cd /workspace && rm -rf systemc-3.0.1
78112

79113
# clean up chisel sources
80114
WORKDIR /workspace/
81115
ENV COURSIER_CACHE="/workspace/.cache/coursier/v1"
116+
ENV CHISEL_FIRTOOL_PATH=/usr/local/bin
117+
ENV SYSTEMC_INCLUDE=/opt/systemc/include
118+
ENV SYSTEMC_LIBDIR=/opt/systemc/lib
82119
CMD ["bash"]

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version = 1.8.2
1+
sbt.version = 1.9.7

src/main/scala/alu/mma/sa/dataCollector.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ class DataCollector(val n: Int = 8, val nbits: Int = 8) extends Module {
2626
val col = (cnt - i.U) % n.U
2727
if (i == n - 1) {
2828
when (io.use_accum){
29-
io.reg_out(i) := io.reg_in((i * n).U + col) + io.accum_in(i)
29+
io.reg_out(i) := io.reg_in((i * n).U(log2Ceil(n*n).W) + col) + io.accum_in(i)
3030
} .otherwise {
31-
io.reg_out(i) := io.reg_in((i * n).U + col)
31+
io.reg_out(i) := io.reg_in((i * n).U(log2Ceil(n*n).W) + col)
3232
}
3333
} else {
3434
buffer(i).io.enq.valid := true.B
35-
buffer(i).io.enq.bits := io.reg_in((i * n).U + col)
35+
buffer(i).io.enq.bits := io.reg_in((i * n).U(log2Ceil(n*n).W) + col)
3636
when (io.use_accum){
3737
io.reg_out(i) := buffer(i).io.deq.bits + io.accum_in(i)
3838
} .otherwise {

src/test/scala/alu/mma/MMALUSpec.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import alu.pe._
66
import testUtil._
77
import scala.util.Random
88
import chisel3._
9-
import chiseltest._
9+
import chisel3.simulator.EphemeralSimulator._
1010
import org.scalatest.flatspec.AnyFlatSpec
1111
import chisel3.experimental.BundleLiterals._
1212

13-
class MMALUSpec extends AnyFlatSpec with ChiselScalatestTester {
13+
class MMALUSpec extends AnyFlatSpec {
1414

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

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

189189
// systolic array will start to spit out after _n - 1 ticks for mat_c
190-
println("Tick @ " + i_tick + " clct signal " + dut.io.clct.peekInt().toInt)
190+
println("Tick @ " + i_tick + " clct signal " + dut.io.clct.peek().litValue.toInt)
191191
if (i_tick >= 2 * _n - 2 && i_tick < 3 * _n - 2) {
192192
for (_i <- 0 until _n) {
193-
_res_c(step * _n + _i) = dut.io.out(_i).peekInt().toInt
193+
_res_c(step * _n + _i) = dut.io.out(_i).peek().litValue.toInt
194194
println("Tick @ " + i_tick + " Mat C producing at location (" + _i + ", " + step + "): " + _res_c(step * _n + _i))
195195
dut.io.out(_i).expect(_expected_c(step * _n + _i))
196196
}
@@ -199,7 +199,7 @@ class MMALUSpec extends AnyFlatSpec with ChiselScalatestTester {
199199
// systolic array will start to generate again after 3 * _n - 2 ticks
200200
if (i_tick >= 3 * _n - 2 && i_tick < 4 * _n - 2){
201201
for (_i <- 0 until _n) {
202-
_res_f((step % _n) * _n + _i) = dut.io.out(_i).peekInt().toInt
202+
_res_f((step % _n) * _n + _i) = dut.io.out(_i).peek().litValue.toInt
203203
println("OUT Tick @ " + i_tick + " Mat F producing at location (" + _i + ", " + step % _n + "): " + _res_f((step % _n) * _n + _i))
204204
dut.io.out(_i).expect(_expected_f((step % _n) * _n + _i))
205205
}
@@ -215,7 +215,7 @@ class MMALUSpec extends AnyFlatSpec with ChiselScalatestTester {
215215
}
216216

217217
"MMALU" should "do a generic matrix multiplication" in {
218-
test(new MMALU(new MMPE(8, 32), 4, 8, 32)) { dut =>
218+
simulate(new MMALU(new MMPE(8, 32), 4, 8, 32)) { dut =>
219219
val print_helper = new testUtil.PrintHelper()
220220
val _n = dut.n
221221
val rand = new Random
@@ -293,7 +293,7 @@ class MMALUSpec extends AnyFlatSpec with ChiselScalatestTester {
293293
// systolic array will start to spit out after _n - 1 ticks
294294
if (i_tick >= 2 * _n - 2) {
295295
for (_i <- 0 until _n) {
296-
_res(step * _n + _i) = dut.io.out(_i).peekInt().toInt
296+
_res(step * _n + _i) = dut.io.out(_i).peek().litValue.toInt
297297
println("Tick @ " + i_tick + " producing at location (" + _i + ", " + step + "): " + _res(step * _n + _i))
298298
dut.io.out(_i).expect(_expected(step * _n + _i))
299299
}

src/test/scala/alu/mma/cu/CUSpec.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ package alu.mma.cu
55
import testUtil._
66
import scala.util.Random
77
import chisel3._
8-
import chiseltest._
8+
import chisel3.simulator.EphemeralSimulator._
99
import org.scalatest.flatspec.AnyFlatSpec
1010
import chisel3.experimental.BundleLiterals._
1111

12-
class CUSpec extends AnyFlatSpec with ChiselScalatestTester {
12+
class CUSpec extends AnyFlatSpec {
1313

1414
"CU" should "send control to 2D systolic array" in {
15-
test(new ControlUnit(4)) { dut =>
15+
simulate(new ControlUnit(4)) { dut =>
1616
val print_helper = new testUtil.PrintHelper()
1717
val _n = dut.n
1818
val rand = new Random

src/test/scala/alu/mma/sa/DataCollectorSpec.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ package alu.mma.sa
55
import testUtil._
66
import scala.util.Random
77
import chisel3._
8-
import chiseltest._
8+
import chisel3.simulator.EphemeralSimulator._
99
import org.scalatest.flatspec.AnyFlatSpec
1010
import chisel3.experimental.BundleLiterals._
1111

12-
class DataCollectorSpec extends AnyFlatSpec with ChiselScalatestTester {
12+
class DataCollectorSpec extends AnyFlatSpec{
1313

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

0 commit comments

Comments
 (0)