Skip to content

Commit

Permalink
treewide: Package Python utilities (#177)
Browse files Browse the repository at this point in the history
Co-authored-by: Viviane Potocnik <[email protected]>
Co-authored-by: Luca Colagrande <[email protected]>
  • Loading branch information
3 people authored Aug 11, 2024
1 parent f0749fd commit 0fc8be0
Show file tree
Hide file tree
Showing 44 changed files with 148 additions and 182 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ jobs:
- uses: actions/checkout@v2
with:
submodules: 'recursive'
- name: Install local Python packages
run: pip install .
- name: Build Software
working-directory: target/snitch_cluster
run: |
Expand Down Expand Up @@ -81,6 +83,8 @@ jobs:
- uses: actions/checkout@v2
with:
submodules: 'recursive'
- name: Install local Python packages
run: pip install .
- name: Build Software
run: |
bender vendor init
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: true
- name: Install local Python packages
run: pip install .
- name: Generate opcodes
run: |
./util/generate-opcodes.sh
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ gmon.out
# Installation directories
/.venv/
/tools/
/build/
/snitch.egg-info/
3 changes: 3 additions & 0 deletions iis-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ TMPDIR=tmp pip install -r python-requirements.txt
TMPDIR=tmp pip install -r $($BENDER path idma)/requirements.txt
rm -rf tmp

# Install local packages in editable mode.
pip install -e .

# Install spike-dasm
mkdir tools/
cd tools/
Expand Down
19 changes: 19 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2023 ETH Zurich and University of Bologna.
# Solderpad Hardware License, Version 0.51, see LICENSE for details.
# SPDX-License-Identifier: SHL-0.51

[build-system]
requires = ["setuptools>=42"]
build-backend = "setuptools.build_meta"

[project]
name = "snitch"
authors = [
{name = "Luca Colagrande", email = "[email protected]"}
]
dynamic = ["version"]

[tool.setuptools.package-dir]
"snitch.dnn" = "sw/dnn"
"snitch.blas" = "sw/blas"
"snitch.util" = "util"
7 changes: 2 additions & 5 deletions sw/apps/atax/scripts/datagen.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@
# Luca Colagrande <[email protected]>

import numpy as np
import os
import sys

sys.path.append(os.path.join(os.path.dirname(__file__), "../../../../util/sim/"))
from data_utils import format_scalar_definition, format_array_definition, \
format_array_declaration, format_ifdef_wrapper, DataGen # noqa: E402
from snitch.util.sim.data_utils import format_scalar_definition, format_array_definition, \
format_array_declaration, format_ifdef_wrapper, DataGen


# AXI splits bursts crossing 4KB address boundaries. To minimize
Expand Down
4 changes: 1 addition & 3 deletions sw/apps/atax/scripts/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@

import numpy as np
import sys
from pathlib import Path
from datagen import AtaxDataGen

sys.path.append(str(Path(__file__).parent / '../../../util/sim/'))
from verif_utils import Verifier # noqa: E402
from snitch.util.sim.verif_utils import Verifier


class AtaxVerifier(Verifier):
Expand Down
7 changes: 2 additions & 5 deletions sw/apps/correlation/scripts/datagen.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@
# Luca Colagrande <[email protected]>

import numpy as np
import os
import sys

sys.path.append(os.path.join(os.path.dirname(__file__), "../../../../util/sim/"))
from data_utils import format_scalar_definition, format_array_definition, \
format_array_declaration, format_ifdef_wrapper, DataGen # noqa: E402
from snitch.util.sim.data_utils import format_scalar_definition, format_array_definition, \
format_array_declaration, format_ifdef_wrapper, DataGen


# AXI splits bursts crossing 4KB address boundaries. To minimize
Expand Down
4 changes: 1 addition & 3 deletions sw/apps/correlation/scripts/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@

import numpy as np
import sys
from pathlib import Path
from datagen import CorrelationDataGen

sys.path.append(str(Path(__file__).parent / '../../../util/sim/'))
from verif_utils import Verifier # noqa: E402
from snitch.util.sim.verif_utils import Verifier


class CorrelationVerifier(Verifier):
Expand Down
7 changes: 2 additions & 5 deletions sw/apps/covariance/scripts/datagen.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@
# Luca Colagrande <[email protected]>

import numpy as np
import os
import sys

sys.path.append(os.path.join(os.path.dirname(__file__), "../../../../util/sim/"))
from data_utils import format_scalar_definition, format_array_definition, \
format_array_declaration, format_ifdef_wrapper, DataGen # noqa: E402
from snitch.util.sim.data_utils import format_scalar_definition, format_array_definition, \
format_array_declaration, format_ifdef_wrapper, DataGen


# AXI splits bursts crossing 4KB address boundaries. To minimize
Expand Down
4 changes: 1 addition & 3 deletions sw/apps/covariance/scripts/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@

import numpy as np
import sys
from pathlib import Path
from datagen import CovarianceDataGen

sys.path.append(str(Path(__file__).parent / '../../../util/sim/'))
from verif_utils import Verifier # noqa: E402
from snitch.util.sim.verif_utils import Verifier


class CovarianceVerifier(Verifier):
Expand Down
9 changes: 9 additions & 0 deletions sw/blas/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright 2024 ETH Zurich and University of Bologna.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
#
# Luca Colagrande <[email protected]>

from . import gemm

__all__ = ['gemm']
6 changes: 2 additions & 4 deletions sw/blas/axpy/scripts/datagen.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
# Author: Luca Colagrande <[email protected]>

import numpy as np
import os
import sys

sys.path.append(os.path.join(os.path.dirname(__file__), "../../../../util/sim/"))
from data_utils import format_scalar_definition, format_array_definition, \
format_array_declaration, format_ifdef_wrapper, DataGen # noqa: E402
from snitch.util.sim.data_utils import format_scalar_definition, format_array_definition, \
format_array_declaration, format_ifdef_wrapper, DataGen


class AxpyDataGen(DataGen):
Expand Down
4 changes: 1 addition & 3 deletions sw/blas/axpy/scripts/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
# Luca Colagrande <[email protected]>

import sys
from pathlib import Path
from datagen import AxpyDataGen

sys.path.append(str(Path(__file__).parent / '../../../../util/sim/'))
from verif_utils import Verifier # noqa: E402
from snitch.util.sim.verif_utils import Verifier


class AxpyVerifier(Verifier):
Expand Down
6 changes: 2 additions & 4 deletions sw/blas/dot/scripts/datagen.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
# SPDX-License-Identifier: Apache-2.0

import numpy as np
import os
import sys

sys.path.append(os.path.join(os.path.dirname(__file__), "../../../../util/sim/"))
from data_utils import format_scalar_definition, format_array_definition, \
format_scalar_declaration, format_ifdef_wrapper, DataGen # noqa: E402
from snitch.util.sim.data_utils import format_scalar_definition, format_array_definition, \
format_scalar_declaration, format_ifdef_wrapper, DataGen


class DotDataGen(DataGen):
Expand Down
4 changes: 1 addition & 3 deletions sw/blas/dot/scripts/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
# SPDX-License-Identifier: Apache-2.0

import sys
from pathlib import Path
from datagen import DotDataGen

sys.path.append(str(Path(__file__).parent / '../../../../util/sim/'))
from verif_utils import Verifier # noqa: E402
from snitch.util.sim.verif_utils import Verifier


class DotVerifier(Verifier):
Expand Down
4 changes: 2 additions & 2 deletions sw/blas/gemm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
#
# Luca Colagrande <[email protected]>

from .scripts import datagen
from .scripts.datagen import GemmDataGen

__all__ = ['datagen']
__all__ = ['GemmDataGen']
8 changes: 3 additions & 5 deletions sw/blas/gemm/scripts/datagen.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@
# Luca Colagrande <[email protected]>

import numpy as np
import os
import re
import pyflexfloat as ff
import sys

sys.path.append(os.path.join(os.path.dirname(__file__), "../../../../util/sim/"))
import data_utils # noqa: E402
from data_utils import DataGen, format_array_declaration, format_struct_definition, \
format_array_definition, format_ifdef_wrapper # noqa: E402
from snitch.util.sim import data_utils
from snitch.util.sim.data_utils import DataGen, format_array_declaration, \
format_struct_definition, format_array_definition, format_ifdef_wrapper


np.random.seed(42)
Expand Down
6 changes: 2 additions & 4 deletions sw/blas/gemm/scripts/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@

import numpy as np
import sys
from pathlib import Path
from datagen import GemmDataGen

sys.path.append(str(Path(__file__).parent / '../../../../util/sim/'))
from verif_utils import Verifier # noqa: E402
from data_utils import ctype_from_precision_t # noqa: E402
from snitch.util.sim.verif_utils import Verifier
from snitch.util.sim.data_utils import ctype_from_precision_t


class GemmVerifier(Verifier):
Expand Down
10 changes: 3 additions & 7 deletions sw/dnn/batchnorm/scripts/datagen.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,11 @@
import argparse
import pathlib
import json5
import sys
import os
import torch

sys.path.append(os.path.join(os.path.dirname(__file__), "../../../../util/sim/"))
import data_utils # noqa: E402
from data_utils import emit_license, \
format_struct_definition, format_array_definition, \
format_array_declaration, format_ifdef_wrapper # noqa: E402
from snitch.util.sim import data_utils
from snitch.util.sim.data_utils import emit_license, format_struct_definition, \
format_array_definition, format_array_declaration, format_ifdef_wrapper

torch.manual_seed(42)

Expand Down
10 changes: 3 additions & 7 deletions sw/dnn/concat/scripts/datagen.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@
import numpy as np
import pathlib
import json5
import sys
import os
import torch

sys.path.append(os.path.join(os.path.dirname(__file__), "../../../../util/sim/"))
import data_utils # noqa: E402
from data_utils import emit_license, \
format_struct_definition, format_array_definition, \
format_array_declaration, format_ifdef_wrapper # noqa: E402
from snitch.util.sim import data_utils
from snitch.util.sim.data_utils import emit_license, format_struct_definition, \
format_array_definition, format_array_declaration, format_ifdef_wrapper

torch.manual_seed(42)

Expand Down
6 changes: 2 additions & 4 deletions sw/dnn/concat/scripts/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@

import sys
import torch
from pathlib import Path
from datagen import golden_model

sys.path.append(str(Path(__file__).parent / '../../../../util/sim/'))
from verif_utils import Verifier # noqa: E402
from data_utils import ctype_from_precision_t # noqa: E402
from snitch.util.sim.verif_utils import Verifier
from snitch.util.sim.data_utils import ctype_from_precision_t


class ConcatVerifier(Verifier):
Expand Down
10 changes: 3 additions & 7 deletions sw/dnn/conv2d/scripts/datagen.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@
import numpy as np
import pathlib
import hjson
import sys
import os
import torch

sys.path.append(os.path.join(os.path.dirname(__file__), "../../../../util/sim/"))
import data_utils # noqa: E402
from data_utils import emit_license, \
format_struct_definition, format_array_definition, \
format_array_declaration # noqa: E402
from snitch.util.sim import data_utils
from snitch.util.sim.data_utils import emit_license, format_struct_definition, \
format_array_definition, format_array_declaration

torch.manual_seed(42)

Expand Down
11 changes: 5 additions & 6 deletions sw/dnn/conv2d/scripts/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
import torch
from data.datagen import golden_model

sys.path.append(str(Path(__file__).parent / '../../../../util/sim/'))
import verification # noqa: E402
from elf import Elf # noqa: E402
from data_utils import from_buffer, ctype_from_precision_t, check_result # noqa: E402
from snitch.util.sim import verification
from snitch.util.sim.elf import Elf
from snitch.util.sim.data_utils import from_buffer, ctype_from_precision_t, check_result


ERR_THRESHOLD = 1E-6
Expand Down Expand Up @@ -77,8 +76,8 @@ def main():
fail, rel_err = check_result(output_golden, output_actual, rtol=ERR_THRESHOLD)
if fail:
verification.dump_results_to_csv(
[output_golden, output_actual, rel_err],
Path.cwd() / 'results.csv')
[output_golden, output_actual, rel_err],
Path.cwd() / 'results.csv')
print('Maximum relative error:', np.max(rel_err))

return int(fail)
Expand Down
Loading

0 comments on commit 0fc8be0

Please sign in to comment.