Skip to content

Commit

Permalink
Merge pull request #124 from zeroasiccorp/flake8
Browse files Browse the repository at this point in the history
apply flake8 linting
  • Loading branch information
volkamir authored Feb 28, 2024
2 parents 325b17c + c9eaf02 commit 4e8086a
Show file tree
Hide file tree
Showing 15 changed files with 151 additions and 150 deletions.
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length = 120
extend-ignore =
19 changes: 19 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Lint UMI
on:
pull_request:
workflow_dispatch:
push:
branches: main

jobs:
lint_python:
name: Lint Python Code
runs-on: ubuntu-latest
steps:
- name: Check out Git repository
uses: actions/checkout@v4
- name: Lint with Flake8
run: |
pip install --upgrade pip
pip install -r requirements.txt
flake8 --statistics .
1 change: 0 additions & 1 deletion docs/umi_waveforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,3 @@
}
""")
svg.saveas("_images/example_rw_xaction.svg")

35 changes: 15 additions & 20 deletions lumi/testbench/test_lumi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Copyright (C) 2023 Zero ASIC
# This code is licensed under Apache License 2.0 (see LICENSE for details)

import time
import random
import numpy as np
from pathlib import Path
Expand All @@ -12,19 +13,16 @@
from lambdalib import lambdalib


THIS_DIR = Path(__file__).resolve().parent


def build_testbench(topo="2d", trace=False):
dut = SbDut('testbench', trace=True, trace_type='fst', default_main=True)

EX_DIR = Path('..')

# Set up inputs
dut.input('testbench_lumi.sv')
if topo=='2d':
if topo == '2d':
print("### Running 2D topology ###")
elif topo=='3d':
elif topo == '3d':
print("### Running 3D topology ###")
else:
raise ValueError('Invalid topology')
Expand Down Expand Up @@ -57,12 +55,13 @@ def build_testbench(topo="2d", trace=False):
return dut


def main(topo="2d", vldmode="2", rdymode="2", trace=False, host2dut="host2dut_0.q", dut2host="dut2host_0.q", sb2dut="sb2dut_0.q", dut2sb="dut2sb_0.q"):
def main(topo="2d", vldmode="2", rdymode="2", trace=False,
host2dut="host2dut_0.q", dut2host="dut2host_0.q", sb2dut="sb2dut_0.q", dut2sb="dut2sb_0.q"):
# clean up old queues if present
for q in [host2dut, dut2host, sb2dut, dut2sb]:
delete_queue(q)

dut = build_testbench(topo,trace)
dut = build_testbench(topo, trace)

hostdly = random.randrange(500)
devdly = random.randrange(500)
Expand Down Expand Up @@ -96,9 +95,9 @@ def main(topo="2d", vldmode="2", rdymode="2", trace=False, host2dut="host2dut_0.
print(f"Read: 0x{val32:08x}")
assert val32 == 0x00000000

if topo=='2d':
if topo == '2d':
width = np.uint32(0x00000000)
if topo=='3d':
if topo == '3d':
width = np.uint32(0x00030000)

linkactive = 0
Expand All @@ -117,8 +116,7 @@ def main(topo="2d", vldmode="2", rdymode="2", trace=False, host2dut="host2dut_0.
sb.write(0x60000010, np.uint32(0x0), posted=True)
sb.write(0x70000010, np.uint32(0x0), posted=True)

import time
time.sleep (0.1)
time.sleep(0.1)

print("### disable Rx ###")
sb.write(0x70000014, np.uint32(0x0), posted=True)
Expand Down Expand Up @@ -157,26 +155,22 @@ def main(topo="2d", vldmode="2", rdymode="2", trace=False, host2dut="host2dut_0.
print("### Read loc Rx ctrl ###")
val32 = sb.read(0x70000014, np.uint32)
print(f"Read: 0x{val32:08x}")
#assert val32 == np.uint32(0x1) + width

print("### Read loc Tx ctrl ###")
val32 = sb.read(0x70000010, np.uint32)
print(f"Read: 0x{val32:08x}")
#assert val32 == np.uint32(0x11) + width

print("### Read rmt Rx ctrl ###")
val32 = sb.read(0x60000014, np.uint32)
print(f"Read: 0x{val32:08x}")
#assert val32 == np.uint32(0x1) + width

print("### Read rmt Tx ctrl ###")
val32 = sb.read(0x60000010, np.uint32)
print(f"Read: 0x{val32:08x}")
#assert val32 == np.uint32(0x11) + width

print("### UMI WRITES ###")

# host.write(0x70, np.arange(32, dtype=np.uint8), srcaddr=0x0000110000000000)
# host.write(0x70, np.arange(32, dtype=np.uint8), srcaddr=0x0000110000000000)
host.write(0x70, np.uint64(0xBAADD70DCAFEFACE), srcaddr=0x0000110000000000)
host.write(0x80, np.uint64(0xBAADD80DCAFEFACE), srcaddr=0x0000110000000000)
host.write(0x90, np.uint64(0xBAADD90DCAFEFACE), srcaddr=0x0000110000000000)
Expand Down Expand Up @@ -221,9 +215,6 @@ def main(topo="2d", vldmode="2", rdymode="2", trace=False, host2dut="host2dut_0.
print(f"Read: 0x{val8:08x}")
assert val8 == 0xBA

# import time
# time.sleep (5)

# 2 bytes
rdbuf = host.read(0x40, 2, np.uint16, srcaddr=0x0000110000000000)
val32 = rdbuf.view(np.uint32)[0]
Expand Down Expand Up @@ -262,6 +253,7 @@ def main(topo="2d", vldmode="2", rdymode="2", trace=False, host2dut="host2dut_0.

print("### TEST PASS ###")


if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument('--trace', action='store_true', default=False,
Expand All @@ -271,4 +263,7 @@ def main(topo="2d", vldmode="2", rdymode="2", trace=False, host2dut="host2dut_0.
parser.add_argument('--rdymode', default='2')
args = parser.parse_args()

main(topo=args.topo,vldmode=args.vldmode,rdymode=args.rdymode,trace=args.trace)
main(topo=args.topo,
vldmode=args.vldmode,
rdymode=args.rdymode,
trace=args.trace)
50 changes: 23 additions & 27 deletions lumi/testbench/test_lumi_rnd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Copyright (C) 2023 Zero ASIC
# This code is licensed under Apache License 2.0 (see LICENSE for details)

import time
import random
import numpy as np
from pathlib import Path
Expand All @@ -12,19 +13,16 @@
from lambdalib import lambdalib


THIS_DIR = Path(__file__).resolve().parent


def build_testbench(topo="2d", trace=False):
dut = SbDut('testbench', trace=True, trace_type='fst', default_main=True)

EX_DIR = Path('..')

# Set up inputs
dut.input('testbench_lumi.sv')
if topo=='2d':
if topo == '2d':
print("### Running 2D topology ###")
elif topo=='3d':
elif topo == '3d':
print("### Running 3D topology ###")
else:
raise ValueError('Invalid topology')
Expand All @@ -41,7 +39,6 @@ def build_testbench(topo="2d", trace=False):
# Verilator configuration
vlt_config = EX_DIR / 'testbench' / 'config.vlt'
dut.set('tool', 'verilator', 'task', 'compile', 'file', 'config', vlt_config)
# dut.set('option', 'relax', True)
dut.add('tool', 'verilator', 'task', 'compile', 'option', '--prof-cfuncs')
dut.add('tool', 'verilator', 'task', 'compile', 'option', '-CFLAGS')
dut.add('tool', 'verilator', 'task', 'compile', 'option', '-DVL_DEBUG')
Expand All @@ -52,12 +49,14 @@ def build_testbench(topo="2d", trace=False):

return dut

def main(topo="2d", vldmode="2", rdymode="2", trace=False, host2dut="host2dut_0.q", dut2host="dut2host_0.q", sb2dut="sb2dut_0.q", dut2sb="dut2sb_0.q"):

def main(topo="2d", vldmode="2", rdymode="2", trace=False,
host2dut="host2dut_0.q", dut2host="dut2host_0.q", sb2dut="sb2dut_0.q", dut2sb="dut2sb_0.q"):
# clean up old queues if present
for q in [host2dut, dut2host, sb2dut, dut2sb]:
delete_queue(q)

dut = build_testbench(topo,trace)
dut = build_testbench(topo, trace)

hostdly = random.randrange(500)
devdly = random.randrange(500)
Expand Down Expand Up @@ -90,12 +89,12 @@ def main(topo="2d", vldmode="2", rdymode="2", trace=False, host2dut="host2dut_0.
print(f"Read: 0x{val32:08x}")
assert val32 == 0x00000000

if topo=='2d':
if topo == '2d':
width = np.uint32(0x00000000)
crdt = np.uint32(0x001A001A)
if topo=='3d':
crdt = np.uint32(0x001A001A)
if topo == '3d':
width = np.uint32(0x00030000)
crdt = np.uint32(0x00070007)
crdt = np.uint32(0x00070007)

linkactive = 0
while (linkactive == 0):
Expand All @@ -113,8 +112,7 @@ def main(topo="2d", vldmode="2", rdymode="2", trace=False, host2dut="host2dut_0.
sb.write(0x60000010, np.uint32(0x0), posted=True)
sb.write(0x70000010, np.uint32(0x0), posted=True)

import time
time.sleep (0.1)
time.sleep(0.1)

print("### disable Rx ###")
sb.write(0x70000014, np.uint32(0x0), posted=True)
Expand Down Expand Up @@ -159,45 +157,40 @@ def main(topo="2d", vldmode="2", rdymode="2", trace=False, host2dut="host2dut_0.
print("### Read loc Rx ctrl ###")
val32 = sb.read(0x70000014, np.uint32)
print(f"Read: 0x{val32:08x}")
#assert val32 == np.uint32(0x1) + width

print("### Read loc Tx ctrl ###")
val32 = sb.read(0x70000010, np.uint32)
print(f"Read: 0x{val32:08x}")
#assert val32 == np.uint32(0x11) + width

print("### Read rmt Rx ctrl ###")
val32 = sb.read(0x60000014, np.uint32)
print(f"Read: 0x{val32:08x}")
#assert val32 == np.uint32(0x1) + width

print("### Read rmt Tx ctrl ###")
val32 = sb.read(0x60000010, np.uint32)
print(f"Read: 0x{val32:08x}")
#assert val32 == np.uint32(0x11) + width

print("### UMI WRITE/READ ###")

for count in range (100):
for count in range(100):
# length should not cross the DW boundary - umi_mem_agent limitation
length = np.random.randint(0,511)
dst_addr = 32*random.randrange(2**(10-5)-1) # sb limitation - should align to bus width
length = np.random.randint(0, 511)
dst_addr = 32*random.randrange(2**(10-5)-1) # sb limitation - should align to bus width
src_addr = 32*random.randrange(2**(10-5)-1)
data8 = np.random.randint(0,255,size=length,dtype=np.uint8)
data8 = np.random.randint(0, 255, size=length, dtype=np.uint8)
print(f"umi writing {length+1} bytes to addr 0x{dst_addr:08x}")
host.write(dst_addr, data8, srcaddr=src_addr)
print(f"umi read from addr 0x{dst_addr:08x}")
val8 = host.read(dst_addr, length, np.uint8, srcaddr=src_addr)
if ~((val8 == data8).all()):
print(f"ERROR umi read from addr 0x{dst_addr:08x}")
print(f"Expected:")
print(f"{data8}")
print(f"Actual:")
print(f"{val8}")
print(f"Expected: {data8}")
print(f"Actual: {val8}")
assert (val8 == data8).all()

print("### TEST PASS ###")


if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument('--trace', action='store_true', default=False,
Expand All @@ -207,4 +200,7 @@ def main(topo="2d", vldmode="2", rdymode="2", trace=False, host2dut="host2dut_0.
parser.add_argument('--rdymode', default='2')
args = parser.parse_args()

main(topo=args.topo,vldmode=args.vldmode,rdymode=args.rdymode,trace=args.trace)
main(topo=args.topo,
vldmode=args.vldmode,
rdymode=args.rdymode,
trace=args.trace)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
lambdalib==0.1.5
switchboard-hw
flake8 == 6.0.0
Loading

0 comments on commit 4e8086a

Please sign in to comment.