Skip to content

Commit b3a2d35

Browse files
authored
Merge pull request #955 from antmicro/migrate-ci
Add pyflow test
2 parents 6305041 + 02550bb commit b3a2d35

File tree

4 files changed

+255
-25
lines changed

4 files changed

+255
-25
lines changed

.github/scripts/code_fixup.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/usr/bin/env python3
2+
import argparse
3+
import re
4+
5+
# =============================================================================
6+
7+
class AssemblyLine:
8+
"""
9+
Simple assembly line representation
10+
"""
11+
12+
RE_INSTR = re.compile(r"(?P<mnemonic>\S+)\s+(?P<operands>.*)")
13+
14+
def __init__(self, text):
15+
self.text = text
16+
self.mnemonic = None
17+
self.operands = None
18+
19+
# Strip label if any
20+
if ":" in text:
21+
text = text.split(":", maxsplit=1)[1]
22+
23+
# Strip comment if any
24+
if "#" in text:
25+
text = text.split("#", maxsplit=1)[0]
26+
27+
# Get instruction and operands
28+
m = self.RE_INSTR.match(text.strip())
29+
if m is not None:
30+
31+
if m.group("mnemonic")[0] == ".":
32+
return
33+
34+
self.mnemonic = m.group("mnemonic").lower()
35+
self.operands = [op.strip() for op in m.group("operands").split()]
36+
37+
def __str__(self):
38+
return self.text
39+
40+
# =============================================================================
41+
42+
43+
def main():
44+
parser = argparse.ArgumentParser()
45+
parser.add_argument(
46+
"-i",
47+
type=str,
48+
required=True,
49+
help="Input assembly file"
50+
)
51+
parser.add_argument(
52+
"-o",
53+
type=str,
54+
required=True,
55+
help="Output assembly file"
56+
)
57+
58+
args = parser.parse_args()
59+
60+
max_nops = 10
61+
62+
# Read and parse
63+
with open(args.i, "r") as fp:
64+
inp_lines = [AssemblyLine(l) for l in fp.readlines()]
65+
66+
# Identify a delayed write instruction followed by another one which writes
67+
# to the same register
68+
out_lines = []
69+
for i in range(len(inp_lines)):
70+
line = inp_lines[i]
71+
out_lines.append(line)
72+
73+
# Bypass
74+
if not line.mnemonic:
75+
continue
76+
77+
# Check if it is a delayed write. If not then bypass
78+
is_delayed = line.mnemonic in ["div", "divu", "rem", "remu", "lw"]
79+
if not is_delayed:
80+
continue
81+
82+
# Get next 2 instructions
83+
following = []
84+
for j in range(i+1, len(inp_lines)):
85+
if inp_lines[j].mnemonic is not None:
86+
following.append(inp_lines[j])
87+
if len(following) >= 2:
88+
break
89+
90+
# If any of the instructions targets the same register insert NOPs
91+
dst = line.operands[0]
92+
for j, l in enumerate(following):
93+
if l.operands and l.operands[0] == dst:
94+
nops = max(0, max_nops - j)
95+
for _ in range(nops):
96+
out_lines.append(" " * 18 + "nop # FIXME: A fixup not to make VeeR cancel a delayed write\n")
97+
break
98+
99+
# Write
100+
with open(args.o, "w") as fp:
101+
for l in out_lines:
102+
fp.write(str(l))
103+
104+
105+
if __name__ == "__main__":
106+
main()

.github/workflows/build-spike.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# https://github.com/chipsalliance/Cores-VeeR-EL2/blob/774510e43f5408ec2b818db8f865027bc9be97b8/.github/workflows/build-spike.yml
2+
3+
name: Spike Build
4+
5+
on:
6+
workflow_call:
7+
8+
jobs:
9+
verilator:
10+
name: Build Spike
11+
runs-on: ubuntu-latest
12+
env:
13+
TOOL_NAME: spike
14+
TOOL_VERSION: d70ea67d
15+
DEBIAN_FRONTEND: "noninteractive"
16+
17+
steps:
18+
- name: Setup Cache Metadata
19+
id: cache_metadata
20+
run: |
21+
cache_date=$(date +"%Y_%m_%d")
22+
cache_name=cache_${{ env.TOOL_NAME }}_${{ env.TOOL_VERSION }}
23+
echo "Cache date: "$cache_date
24+
echo "Cache name: "$cache_name
25+
echo "cache_date=$cache_date" >> "$GITHUB_ENV"
26+
echo "cache_name=$cache_name" >> "$GITHUB_ENV"
27+
28+
- name: Setup cache
29+
uses: actions/cache@v3
30+
id: cache
31+
timeout-minutes: 60
32+
with:
33+
path: |
34+
/opt/spike
35+
/opt/spike/.cache
36+
key: ${{ env.cache_name }}_${{ env.cache_date }}
37+
restore-keys: ${{ env.cache_name }}_
38+
39+
- name: Install prerequisities
40+
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
41+
run: |
42+
sudo apt -qqy update && sudo apt -qqy --no-install-recommends install \
43+
git build-essential cmake ccache device-tree-compiler
44+
45+
- name: Build Spike
46+
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
47+
run: |
48+
export CCACHE_DIR=/opt/spike/.cache
49+
ccache --show-config | grep cache_dir
50+
git clone https://github.com/riscv-software-src/riscv-isa-sim spike
51+
export CC="ccache gcc"
52+
export CXX="ccache g++"
53+
pushd spike
54+
git checkout ${{ env.TOOL_VERSION }}
55+
mkdir build
56+
cd build
57+
../configure --prefix=/opt/spike
58+
make -j`nproc`
59+
make install
60+
popd
61+
rm -rf /opt/spike/include # Remove include and lib to save space
62+
rm -rf /opt/spike/lib
63+

.github/workflows/metrics-regress.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

.github/workflows/run-tests.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: run-tests
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
build-spike:
9+
uses: ./.github/workflows/build-spike.yml
10+
test-pyflow:
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
test:
15+
- riscv_arithmetic_basic_test
16+
runs-on: ubuntu-latest
17+
needs: [build-spike]
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- name: Install dependencies
22+
run: sudo apt-get -qqy update && sudo apt-get -qqy install gcc-riscv64-linux-gnu device-tree-compiler
23+
24+
- name: Setup python
25+
# python dependencies cannot be properly downloaded with new versions of python
26+
uses: actions/setup-python@v4
27+
with:
28+
python-version: '3.9'
29+
30+
- name: Install python dependencies
31+
run: python3 -m pip install -r requirements.txt
32+
33+
- name: Setup Cache Metadata
34+
id: cache_metadata
35+
run: |
36+
date=$(date +"%Y_%m_%d")
37+
time=$(date +"%Y%m%d_%H%M%S_%N")
38+
cache_spike_restore_key=cache_spike_
39+
cache_spike_key=${cache_spike_restore_key}d70ea67d_${date}
40+
41+
echo "cache_spike_restore_key=$cache_spike_restore_key" | tee -a "$GITHUB_ENV"
42+
echo "cache_spike_key=$cache_spike_key" | tee -a "$GITHUB_ENV"
43+
44+
- name: Restore Spike cache
45+
id: cache-spike-restore
46+
uses: actions/cache/restore@v3
47+
with:
48+
path: |
49+
/opt/spike
50+
/opt/spike/.cache
51+
key: ${{ env.cache_spike_key }}
52+
restore-keys: ${{ env.cache_spike_restore_key }}
53+
54+
- name: Set variables
55+
run: |
56+
echo "RISCV_GCC=riscv64-linux-gnu-gcc" >> $GITHUB_ENV
57+
echo "RISCV_OBJCOPY=riscv64-linux-gnu-objcopy" >> $GITHUB_ENV
58+
echo "SPIKE_PATH=/opt/spike/bin" >> $GITHUB_ENV
59+
echo "PYTHONPATH=pygen" >> $GITHUB_ENV
60+
61+
- name: Generate Tests
62+
run: |
63+
set -eo pipefail
64+
python3 run.py --simulator pyflow \
65+
--test ${{ matrix.test }} --iss spike \
66+
--start_seed 999 --iterations 1 --batch_size 1 \
67+
--isa rv32imc --mabi ilp32 --steps gen -v -o test 2>&1 | tee test/generate.log
68+
69+
- name: Patch Tests
70+
run: find test/asm_test -name "*.S" -exec python3 .github/scripts/code_fixup.py -i {} -o {} \;
71+
72+
- name: Run tests
73+
run: |
74+
set -eo pipefail
75+
python3 run.py --simulator pyflow \
76+
--test ${{ matrix.test }} --iss spike --iss_timeout 60 \
77+
--start_seed 999 --iterations 1 --batch_size 1 \
78+
--isa rv32imc --mabi ilp32 --steps gcc_compile,iss_sim -v -o test 2>&1 | tee -a test/generate.log
79+
80+
- name: Upload logs
81+
uses: actions/upload-artifact@v3
82+
if: always()
83+
with:
84+
path: |
85+
test/asm_test/*.log
86+
test/*.log

0 commit comments

Comments
 (0)