Skip to content

Commit

Permalink
Merge pull request #10 from PAICookers/dev
Browse files Browse the repository at this point in the history
v0.0.11
  • Loading branch information
KafCoppelia authored Apr 17, 2023
2 parents 6992606 + 670aa94 commit e60ce40
Show file tree
Hide file tree
Showing 14 changed files with 903 additions and 636 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/poetry-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Upload Python Package

on:
release:
types: [published]

permissions:
contents: read

jobs:
publish:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
ref: ${{ env.TAG_NAME }}

- name: Publish python poetry package
uses: JRubics/[email protected]
with:
python_version: "3.10"
pypi_token: ${{ secrets.PYPI_API_TOKEN }}
build_format: "wheel"
ignore_dev_requirements: "yes"
2 changes: 1 addition & 1 deletion .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ jobs:
tag: ${{ env.TAG_NAME }}
publish: true
env:
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }}
GITHUB_TOKEN: ${{ secrets.ORG_TOKEN }}
77 changes: 51 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,66 @@

## 📦 版本

[v0.0.10 Prerelease](https://github.com/PAICookers/PAITest/releases/tag/v0.0.10)
[v0.0.11 Prerelease](https://github.com/PAICookers/PAITest/releases/tag/v0.0.11)

## 🛠️ 使用
## 🛠️ 使用生成

生成配置帧及对应测试输入帧,以实现硬件通路的简单测试,后续将芯片实际测试输出帧与预期结果进行对比即可。由于配置帧/测试帧I型需要配合UART配置使用,因此目前仅采用**配置/测试帧II型**方案,且 `chip_addr``core*_addr` 均固定为 `(0, 0)`
配置帧及对应测试输入帧,以实现硬件通路的简单测试,后续将芯片实际测试输出帧与预期结果进行对比即可。

```python
from paitest import paitest
⚠️ 由于配置帧/测试帧I型需要配合串口配置使用,因此目前仅采用**配置/测试帧II型**方案,且 `CHIP_ADDR``CORE*_ADDR` 均固定为 `(0, 0)`

'''Path to store the config & test frames'''
save_path = Path.cwd() / "test"
'''N groups'''
groups = 1
'''PAITest instance'''
PAITestManager = paitest("EAST")
1. 实例化 `PAITest`

# Random test 'groups' cores with 'groups' different parameters
paitest.GetRandomCasesForNCores(groups, save_path)
```python
from paitest import paitest

# Random test 10 cores but don't use core (6, 6)
config_frames, testin_frames, testout_frames = \
PAITestManager.Get1CaseForNCores(10, save_dir=save_path, masked_core_coord=(6, 6))
# Define the direction of test chip
PAITestManager = paitest("EAST")
```

# Save frames in .bin file
PAITestManager.SaveFrames("./test/config_1.bin", config_frames)
```
2. `Get1GroupForNCoresWithNParams`,产生一组针对 `N` 个核的配置-测试帧,每个核配置不同参数。可以指定单个需要**屏蔽**的核坐标

生成的 `N` 组配置帧II型、测试输入帧II型及参考测试输出帧II型在 `save_path` 下:
```python
groups = 10 # Generate 10 groups
save_to_dir="./test" # Save frames into ./test directory

```python
save_path
├ config.bin
├ testin.bin
└ testout.bin
```
# Generate configuration frames, testin & testout frames
cf, ti, to = PAITestManager.Get1GroupForNCoresWithNParams(groups, save_dir=save_to_dir)

# Mask a cord coordinate so that avoid generating the same coordinate.
cf, ti, to = PAITestManager.Get1GroupForNCoresWithNParams(groups,
save_dir=save_to_dir, masked_core_coord=(12, 16))
```

3. `Get1GroupForNCoresWith1Param`,产生1组针对 `N` 个核的配置-测试帧,每个核配置相同参数。可以指定单个需要**屏蔽**的核坐标

```python
# Same as Get1GroupForNCoresWithNParams
cf, ti, to = PAITestManager.Get1GroupForNCoresWith1Param(10, save_dir="./test")
```

4. `GetNGroupsFor1CoreWithNParams`,产生 `N` 组针对1个核的配置-测试帧,每个核配置不同参数。可以指定单个需要**屏蔽**的核坐标

```python
# Same as Get1GroupForNCoresWithNParams
cf, ti, to = PAITestManager.GetNGroupsFor1CoreWithNParams(1, save_dir="./test")
```

5. `ReplaceCoreCoord`,替换单个或**一组**帧中的 `CORE_ADDR` 为指定坐标。

```python
# Replaced core coordinate with (9, 9)
replaced = PAITestManager.ReplaceCoreCoord(original_frames, (9, 9))
```

⚠️ 一组指一组完整的配置帧,包含3帧。对于测试输入帧,即为单帧。

6. `SaveFrames`,保存帧数据至 `.bin` 文件

```python
# Save into ./test/config.bin
PAITestManager.SaveFrames("./test/config.bin", replaced)
```

## 🗓️ TODO

Expand Down
43 changes: 43 additions & 0 deletions example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from paitest import paitest
from paitest.frames import FrameDecoder


if __name__ == "__main__":
"""Here are simple exmaples"""

# Path to store the config, test input and output frames
save_path = "./test"

# N groups
groups = 1

# PAITest instance
PAITestManager = paitest("EAST")

# 1. Generate 1 group for N cores with N parameters reg.
a_cf, a_ti, a_to = PAITestManager.Get1GroupForNCoresWithNParams(
3, save_dir="./test"
)
print(a_cf, a_ti, a_to)

# 2. Generate 1 group for N cores with the same 1 parameter reg.
a_cf, a_ti, a_to = PAITestManager.Get1GroupForNCoresWith1Param(1, save_dir="./test")
print(a_cf, a_ti, a_to)

# 3. Generate N groups for 1 core with N parameters reg.
a_cf, a_fi, a_fo = PAITestManager.GetNGroupsFor1CoreWithNParams(
3, save_dir="./test1"
)

# 3. Replace the core coordinate with (9, 9) then save in test/config_r.bin
a_cf_replaced = PAITestManager.ReplaceCoreCoord(a_cf[:3], (9, 9))
PAITestManager.SaveFrames("./test/config_r.bin", a_cf_replaced)
print(f"a_cf_replaced: {a_cf_replaced}")

# Then, decode the replaced frames to check whether the replacement is OK
decoder = FrameDecoder()
attr = decoder.decode(a_cf_replaced)

replaced_coord = attr.get("core_coord")
if replaced_coord == (9, 9):
print("Replacement OK")
18 changes: 10 additions & 8 deletions paitest/frames/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from .frame import \
Addr2Coord as Addr2Coord, \
Coord2Addr as Coord2Addr, \
FrameGen as FrameGen, \
Coord as Coord, \
Direction as Direction, \
FrameMask as FrameMask, \
FrameSubType as FrameSubType
from .frame import (
Addr2Coord as Addr2Coord,
Coord2Addr as Coord2Addr,
FrameGen as FrameGen,
Direction as Direction,
FrameMask as FrameMask,
FrameSubType as FrameSubType,
FrameDecoder as FrameDecoder,
)
from .coord import Coord as Coord
83 changes: 83 additions & 0 deletions paitest/frames/coord.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
from typing import Tuple, Union, Optional


class Coord:
"""Coordinate class"""

def __init__(
self, _x: Union[Tuple[int, int], int], _y: Optional[int] = None
) -> None:
if isinstance(_x, Tuple):
x, y = _x[0], _x[1]
if isinstance(_y, int):
raise ValueError(f"Wrong Argument: {_y}")
elif isinstance(_x, int):
if isinstance(_y, int):
x, y = _x, _y
else:
raise ValueError("Missing Argument: y")
else:
raise ValueError("Wrong Argument")

if not (0 <= x < 32 and 0 <= y < 32):
raise ValueError(f"0 <= x < 32, 0 <= y < 32: ({x}, {y})")

self.x, self.y = x, y

def __add__(self, other) -> "Coord":
return Coord(self.x + other.x, self.y + other.y)

def __sub__(self, other) -> "CoordOffset":
return CoordOffset(self.x - other.x, self.y - other.y)

def __eq__(self, other) -> bool:
if isinstance(other, Tuple):
return (self.x, self.y) == other

return self.x == other.x and self.y == other.y

def __ne__(self, other) -> bool:
return self.x != other.x or self.y != other.y

def __lt__(self, other) -> bool:
"""Whether on the left or below"""
return self.x < other.x or self.y < other.y

def __gt__(self, other) -> bool:
"""Whether on the right and above"""
return (
(self.x > other.x and self.y > other.y)
or (self.x == other.x and self.y > other.y)
or (self.x > other.x and self.y == other.y)
)

def __le__(self, other) -> bool:
return self.__lt__(other) or self.__eq__(other)

def __ge__(self, other) -> bool:
return self.__gt__(other) or self.__eq__(other)

def __str__(self) -> str:
return f"({self.x}, {self.y})"


class CoordOffset(Coord):
"""Coordinate offset class"""

def __init__(self, _x: int, _y: int) -> None:
if not (-32 < _x < 32 and -32 < _y < 32):
raise ValueError(f"-32 < x < 32, -32 < y < 32: ({_x}, {_y})")

self.x, self.y = _x, _y

def __add__(self, other):
if isinstance(other, CoordOffset):
return CoordOffset(self.x + other.x, self.y + other.y)
else:
return Coord(self.x + other.x, self.y + other.y)

def __sub__(self, other) -> "CoordOffset":
if isinstance(other, Coord):
raise TypeError("A CoordOffset cannot substract a Coord")

return CoordOffset(self.x - other.x, self.y - other.y)
25 changes: 25 additions & 0 deletions paitest/frames/coord.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from typing import overload, Tuple

class Coord:
x: int = ...
y: int = ...
@overload
def __init__(self, _x: Tuple[int, int]) -> None: ...
@overload
def __init__(self, _x: int, _y: int) -> None: ...
def __add__(self, other) -> Coord: ...
def __sub__(self, other) -> CoordOffset: ...
def __eq__(self, other) -> bool: ...
def __ne__(self, other) -> bool: ...
def __lt__(self, other) -> bool: ...
def __gt__(self, other) -> bool: ...
def __le__(self, other) -> bool: ...
def __ge__(self, other) -> bool: ...
def __str__(self) -> str: ...

__repr__ = __str__

class CoordOffset(Coord):
def __init__(self, _x: int, _y: int) -> None: ...
def __add__(self, other) -> CoordOffset | Coord: ...
def __sub__(self, other) -> CoordOffset: ...
Loading

0 comments on commit e60ce40

Please sign in to comment.