Skip to content

Commit e73eac4

Browse files
author
M0stafaRady
committed
Merge branch 'main' of github.com:efabless/caravel-sim-infrastructure
2 parents 93953b4 + cbb3316 commit e73eac4

File tree

18 files changed

+1332
-170
lines changed

18 files changed

+1332
-170
lines changed

.github/workflows/caravel_cocotb.yml

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,39 @@ jobs:
1111
runs-on: ubuntu-latest
1212

1313
steps:
14-
- name: Checkout code
15-
uses: actions/checkout@v2
16-
17-
- name: Set up Python
18-
uses: actions/setup-python@v2
19-
with:
20-
python-version: 3.8
21-
- name: Set up QEMU
22-
uses: docker/setup-qemu-action@v1
23-
24-
- name: Set up Docker Buildx
25-
uses: docker/setup-buildx-action@v1
26-
27-
- name: Install dependencies
28-
run: |
29-
cd $GITHUB_WORKSPACE/cocotb
30-
python3 -m pip install --upgrade pip
31-
pip install -r requirements.txt
32-
python3 -m pip install --upgrade --no-cache-dir volare
33-
pip install flake8
34-
35-
- name: Run Flake8
36-
run: flake8 $GITHUB_WORKSPACE/cocotb --config $GITHUB_WORKSPACE/cocotb/.flake8
37-
38-
- name: download docker
39-
run: |
40-
docker pull efabless/dv:cocotb
41-
42-
- name: Install caravel_cocotb
43-
run: |
44-
cd $GITHUB_WORKSPACE/cocotb
45-
pip install .
46-
47-
- name: Run main.py
48-
run: |
49-
cd $GITHUB_WORKSPACE/cocotb/caravel_cocotb/CI
50-
python3 main.py
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Python
18+
uses: actions/setup-python@v2
19+
with:
20+
python-version: 3.8
21+
- name: Set up QEMU
22+
uses: docker/setup-qemu-action@v1
23+
24+
- name: Set up Docker Buildx
25+
uses: docker/setup-buildx-action@v1
26+
27+
- name: Install dependencies
28+
run: |
29+
cd $GITHUB_WORKSPACE/cocotb
30+
make venv
31+
32+
- name: Run Flake8
33+
run: |
34+
cd $GITHUB_WORKSPACE/cocotb
35+
make lint
36+
37+
- name: download docker
38+
run: |
39+
docker pull efabless/dv:cocotb
40+
41+
- name: Install caravel_cocotb
42+
run: |
43+
cd $GITHUB_WORKSPACE/cocotb
44+
pip install .
45+
46+
- name: Run main.py
47+
run: |
48+
cd $GITHUB_WORKSPACE/cocotb/caravel_cocotb/CI
49+
python3 main.py

.github/workflows/publish_pypi.yaml

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,34 @@ on:
66
branches:
77
- main
88
paths:
9-
- cocotb/caravel_cocotb/__version__.py # Trigger the workflow only if the VERSION file changes
9+
- cocotb/pyproject.toml # Trigger the workflow only if the VERSION file changes
1010

1111
jobs:
1212
publish:
1313
runs-on: ubuntu-latest
1414

1515
steps:
16-
- name: Checkout code
17-
uses: actions/checkout@v3
18-
19-
- name: Set up Python
20-
uses: actions/setup-python@v4
21-
with:
22-
python-version: 3.8
23-
24-
- name: Install dependencies
25-
run: |
26-
pip install --upgrade setuptools wheel twine
27-
28-
- name: Read version number
29-
id: read_version
30-
run: |
31-
VERSION_FILE=cocotb/caravel_cocotb/__version__.py
32-
NEW_VERSION=$(cat $VERSION_FILE)
33-
echo "New version: $NEW_VERSION"
34-
echo "version=$NEW_VERSION" >> $GITHUB_ENV
35-
36-
- name: Build package
37-
run: |
38-
cd cocotb
39-
python setup.py sdist bdist_wheel
40-
41-
- name: Publish
42-
if: ${{ env.NEW_TAG != 'NO_NEW_TAG' }}
43-
uses: pypa/gh-action-pypi-publish@release/v1
44-
with:
45-
password: ${{ secrets.PYPI_API_TOKEN }}
46-
packages-dir: cocotb/dist
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: 3.8
23+
24+
- name: Read version number
25+
id: read_version
26+
run: |
27+
echo "version=$(python3 cocotb/caravel_cocotb/__version__.py)" >> $GITHUB_ENV
28+
29+
- name: Build package
30+
run: |
31+
cd cocotb
32+
make dist
33+
34+
- name: Publish
35+
if: ${{ env.NEW_TAG != 'NO_NEW_TAG' }}
36+
uses: pypa/gh-action-pypi-publish@release/v1
37+
with:
38+
password: ${{ secrets.PYPI_API_TOKEN }}
39+
packages-dir: cocotb/dist

cocotb/.flake8

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
[flake8]
2-
ignore = E203,E266,E302,E501,W503,E731
2+
ignore = E203,E266,E302,E501,W503,E731
3+
exclude =
4+
.git/,
5+
venv/

cocotb/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ __pycache__
1717
/build
1818
/venv
1919
/dist
20-
/*.egg-info
20+
/*.egg-info
21+
/requirements_tmp.txt

cocotb/Makefile

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,43 @@
11
PACKAGE_NAME = caravel_cocotb
22

3-
.PHONY: clean test lint dist upload release
3+
PYTHON3 ?= python3
44

5-
clean:
6-
rm -rf dist build *.egg-info
7-
rm -rf caravel mgmt_core pdk_root user_project_root
8-
9-
test:
10-
pip install .
11-
python3 caravel_cocotb/CI/main.py
12-
13-
lint:
14-
flake8
15-
16-
dist: clean
17-
python3 setup.py sdist bdist_wheel
5+
all: dist
186

7+
.PHONY: upload
198
upload: dist
20-
twine upload dist/*
9+
./venv/bin/python3 -m pip install twine
10+
./venv/bin/twine upload dist/*
2111

22-
release: lint test dist upload
12+
.PHONY: dist
13+
dist: venv/manifest.txt
14+
./venv/bin/poetry build
2315

16+
.PHONY: lint
17+
lint: venv/manifest.txt
18+
./venv/bin/flake8 .
19+
20+
test: venv/manifest.txt
21+
./venv/bin/python3 -m pip install .
22+
./venv/bin/python3 caravel_cocotb/CI/main.py
23+
24+
venv: venv/manifest.txt
25+
venv/manifest.txt: ./pyproject.toml ./poetry.lock
26+
rm -rf venv
27+
python3 -m venv ./venv
28+
PYTHONPATH= ./venv/bin/python3 -m pip install --upgrade pip
29+
PYTHONPATH= ./venv/bin/python3 -m pip install --upgrade wheel poetry poetry-plugin-export
30+
PYTHONPATH= ./venv/bin/poetry export --with dev --without-hashes --format=requirements.txt --output=requirements_tmp.txt
31+
PYTHONPATH= ./venv/bin/python3 -m pip install --upgrade -r requirements_tmp.txt
32+
PYTHONPATH= ./venv/bin/python3 -m pip freeze > $@
33+
@echo ">> Venv prepared."
34+
35+
.PHONY: clean
36+
clean:
37+
rm -rf _nl2bench_antlr4*/
38+
rm -rf build/
39+
rm -rf dist/
40+
rm -rf htmlcov/
41+
rm -rf *.egg-info/
42+
rm -rf .antlr/
43+
rm -f .coverage
Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,41 @@
1-
__version__ = "1.3.2"
1+
# Copyright 2024 Efabless Corporation
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
import os
15+
import sys
16+
import importlib.metadata
17+
18+
19+
def __get_version():
20+
try:
21+
return importlib.metadata.version("caravel_cocotb")
22+
except importlib.metadata.PackageNotFoundError:
23+
import re
24+
25+
rx = re.compile(r"version\s*=\s*\"([^\"]+)\"")
26+
script_directory = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
27+
pyproject_path = os.path.join(script_directory, "pyproject.toml")
28+
try:
29+
match = rx.search(open(pyproject_path, encoding="utf8").read())
30+
assert match is not None, "pyproject.toml found, but without a version"
31+
return match[1]
32+
except FileNotFoundError:
33+
print("Warning: Failed to extract caravel cocotb version.", file=sys.stderr)
34+
return "UNKNOWN"
35+
36+
37+
__version__ = __get_version()
38+
39+
40+
if __name__ == "__main__":
41+
print(__version__, end="")

cocotb/caravel_cocotb/scripts/verify_cocotb/RunFlow.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,21 +146,21 @@ def set_paths(self, design_info):
146146
design_info["USER_PROJECT_ROOT"],
147147
SIM_PATH,
148148
)
149-
elif "CHEETAH_ROOT" in design_info:
149+
elif "FRIGATE_ROOT" in design_info:
150150
Paths = namedtuple(
151151
"Paths",
152-
"CHEETAH_ROOT MCW_ROOT PDK_ROOT PDK RUN_PATH VERILOG_PATH FIRMWARE_PATH USER_PROJECT_ROOT SIM_PATH",
152+
"FRIGATE_ROOT MCW_ROOT PDK_ROOT PDK RUN_PATH VERILOG_PATH FIRMWARE_PATH USER_PROJECT_ROOT SIM_PATH",
153153
)
154-
if not os.path.exists(design_info["CHEETAH_ROOT"]):
154+
if not os.path.exists(design_info["FRIGATE_ROOT"]):
155155
raise NotADirectoryError(
156-
f"CHEETAH_ROOT is not a correct directory CHEETAH_ROOT:{design_info['CHEETAH_ROOT']}"
156+
f"FRIGATE_ROOT is not a correct directory FRIGATE_ROOT:{design_info['FRIGATE_ROOT']}"
157157
)
158158
if not os.path.exists(design_info["MCW_ROOT"]):
159159
raise NotADirectoryError(
160160
f"MCW_ROOT is not a correct directory MCW_ROOT:{design_info['MCW_ROOT']}"
161161
)
162162
self.paths = Paths(
163-
design_info["CHEETAH_ROOT"],
163+
design_info["FRIGATE_ROOT"],
164164
design_info["MCW_ROOT"],
165165
design_info["PDK_ROOT"],
166166
design_info["PDK"],
@@ -242,10 +242,10 @@ def set_config_script(self, design_info):
242242
PDK_ROOT=f'{self.paths.PDK_ROOT}/{design_info["PDK"]}',
243243
)
244244
)
245-
elif "CHEETAH_ROOT" in self.paths._fields:
245+
elif "FRIGATE_ROOT" in self.paths._fields:
246246
design_configs.update(
247247
dict(
248-
CHEETAH_ROOT=self.paths.CHEETAH_ROOT,
248+
FRIGATE_ROOT=self.paths.FRIGATE_ROOT,
249249
MCW_ROOT=self.paths.MCW_ROOT,
250250
PDK_ROOT=f'{self.paths.PDK_ROOT}/{design_info["PDK"]}',
251251
)

cocotb/caravel_cocotb/scripts/verify_cocotb/RunRegression.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ def set_common_macros(self):
5252
]
5353
if "CARAVEL_ROOT" in self.paths._fields:
5454
paths_macros += [f'CARAVEL_ROOT=\\"{self.paths.CARAVEL_ROOT}\\"']
55-
elif "CHEETAH_ROOT" in self.paths._fields:
56-
paths_macros += [f'CHEETAH_ROOT=\\"{self.paths.CHEETAH_ROOT}\\"']
55+
elif "FRIGATE_ROOT" in self.paths._fields:
56+
paths_macros += [f'FRIGATE_ROOT=\\"{self.paths.FRIGATE_ROOT}\\"']
5757

5858
paths_macros.append(f'SIM_PATH=\\"{self.paths.SIM_PATH}/\\"')
5959
if self.args.pdk != "gf180":
@@ -329,8 +329,8 @@ def write_command_log(self):
329329
def write_git_log(self):
330330
file_name = f"{self.paths.SIM_PATH}/{self.args.tag}/repos_info.log"
331331
f = open(file_name, "w")
332-
f.write(f"{'#'*4} {'Caravel' if 'CARAVEL_ROOT' in self.paths._fields else 'Cheetah' if 'CHEETAH_ROOT' in self.paths._fields else None} repo info {'#'*4}\n")
333-
ROOT_REPO = self.paths.CARAVEL_ROOT if "CARAVEL_ROOT" in self.paths._fields else self.paths.CHEETAH_ROOT if "CHEETAH_ROOT" in self.paths._fields else None
332+
f.write(f"{'#'*4} {'Caravel' if 'CARAVEL_ROOT' in self.paths._fields else 'frigate' if 'FRIGATE_ROOT' in self.paths._fields else None} repo info {'#'*4}\n")
333+
ROOT_REPO = self.paths.CARAVEL_ROOT if "CARAVEL_ROOT" in self.paths._fields else self.paths.FRIGATE_ROOT if "FRIGATE_ROOT" in self.paths._fields else None
334334
url = "https://github.com/" + f"{run(f'cd {ROOT_REPO};git ls-remote --get-url', stdout=PIPE, stderr=PIPE, universal_newlines=True, shell=True).stdout}".replace(
335335
336336
).replace(

cocotb/caravel_cocotb/scripts/verify_cocotb/RunTest.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ def hex_riscv_command_gen(self):
4545
LINKER_SCRIPT = f"-Wl,-Bstatic,-T,{self.test.linker_script_file},--strip-debug "
4646
CPUFLAGS = "-O2 -g -march=rv32i_zicsr -mabi=ilp32 -D__vexriscv__ -ffreestanding -nostdlib"
4747
# CPUFLAGS = "-O2 -g -march=rv32imc_zicsr -mabi=ilp32 -D__vexriscv__ -ffreestanding -nostdlib"
48+
includes = [
49+
f"-I{ip}" for ip in self.get_ips_fw()
50+
] + [
51+
f"-I{self.paths.FIRMWARE_PATH}",
52+
f"-I{self.paths.FIRMWARE_PATH}/APIs",
53+
f"-I{self.paths.USER_PROJECT_ROOT}/verilog/dv/cocotb",
54+
f"-I{self.paths.VERILOG_PATH}/dv/generated",
55+
f"-I{self.paths.VERILOG_PATH}/dv/",
56+
f"-I{self.paths.VERILOG_PATH}/common/",
57+
]
4858
includes = f" -I{self.paths.FIRMWARE_PATH} -I{self.paths.FIRMWARE_PATH}/APIs -I{self.paths.VERILOG_PATH}/dv/generated -I{self.paths.VERILOG_PATH}/dv/ -I{self.paths.VERILOG_PATH}/common"
4959
includes += f" -I{self.paths.USER_PROJECT_ROOT}/verilog/dv/cocotb {' '.join([f'-I{ip}' for ip in self.get_ips_fw()])}"
5060
elf_command = (
@@ -185,11 +195,13 @@ def write_iverilog_includes_file(self):
185195
self.iverilog_dirs += f" -I {include_dir}"
186196

187197
def iverilog_compile(self):
198+
if os.path.isfile(f"{self.test.compilation_dir}/sim.vvp"):
199+
os.remove(f"{self.test.compilation_dir}/sim.vvp")
188200
macros = " -D" + " -D".join(self.test.macros)
189201
compile_command = (
190202
f"cd {self.test.compilation_dir} &&"
191-
f"iverilog -g2012 -Ttyp {macros} {self.iverilog_dirs} -o {self.test.compilation_dir}/sim.vvp"
192-
f" {self.paths.CARAVEL_VERILOG_PATH}/rtl/toplevel_cocotb.v -s caravel_top"
203+
f"iverilog -g2012 -Ttyp {macros} {self.iverilog_dirs} -o {self.test.compilation_dir}/sim.vvp -s caravel_top"
204+
f" {self.paths.CARAVEL_VERILOG_PATH}/rtl/toplevel_cocotb.v"
193205
)
194206
docker_compilation_command = self._iverilog_docker_command_str(compile_command)
195207
self.run_command_write_to_file(
@@ -238,8 +250,6 @@ def _iverilog_docker_command_str(self, command=""):
238250

239251
def find_symbolic_links(self, directory):
240252
sym_links = []
241-
if not os.path.exists(directory):
242-
return sym_links
243253
for root, dirs, files in os.walk(directory):
244254
for dir_name in dirs:
245255
dir_path = os.path.join(root, dir_name)
@@ -283,6 +293,8 @@ def write_vcs_includes_file(self):
283293
self.test.set_user_project()
284294

285295
def vcs_compile(self):
296+
if os.path.isfile(f"{self.test.compilation_dir}/simv"):
297+
os.remove(f"{self.test.compilation_dir}/simv")
286298
macros = " +define+" + " +define+".join(self.test.macros)
287299
vlogan_cmd = f"cd {self.test.compilation_dir}; vlogan -full64 -sverilog +error+30 {self.paths.CARAVEL_VERILOG_PATH}/rtl/toplevel_cocotb.v {self.vcs_dirs} {macros} -l {self.test.compilation_dir}/analysis.log -o {self.test.compilation_dir} "
288300
self.run_command_write_to_file(

0 commit comments

Comments
 (0)