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
3 changes: 2 additions & 1 deletion src/main/scala/alu/mma/cu/controlUnit.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ class ControlUnit(val n: Int = 8) extends Module {
val cbus_out = Output(Vec(n * n, new NCoreMMALUCtrlBundle()))
val cbus_dat_clct = Output(Bool())
val cbus_use_accum = Output(Bool())
val clct = Output(Bool())
})
// Assign each element with diagnal control signal
val reg = RegInit(VecInit(Seq.fill(2*n-1)(0.U.asTypeOf(new NCoreMMALUCtrlBundle()))))
// val clct = Wire(Bool())
val or_g = Module{new ORGate(2*n-1)}
io.cbus_dat_clct :<>= or_g.io.out

io.clct :<>= reg(2 * n - 2).busy
io.cbus_use_accum :<>= reg(2 * n - 2).use_accum

// 1D systolic array for control
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/alu/mma/mma.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import chisel3._
val ctrl_array = Module(new cu.ControlUnit(n))
ctrl_array.io.cbus_in := io.ctrl
dclct.io.dat_clct <> ctrl_array.io.cbus_dat_clct
io.clct <> ctrl_array.io.cbus_dat_clct
io.clct <> ctrl_array.io.clct
dclct.io.use_accum <> ctrl_array.io.cbus_use_accum

val sarray = Module(new sa.SystolicArray2D(n, nbits))
Expand Down
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
1 change: 1 addition & 0 deletions src/main/scala/isa/micro_op/MMALUMicroCode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ import chisel3.util._
class NCoreMMALUCtrlBundle () extends Bundle {
val keep = Bool()
val use_accum = Bool()
val busy = Bool()
}
Loading