Skip to content

Commit

Permalink
Merge pull request #3 from PAICookers/dev
Browse files Browse the repository at this point in the history
v0.0.4
  • Loading branch information
KafCoppelia authored Apr 3, 2023
2 parents 6a31935 + 738497f commit 3efcb53
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ jobs:
name: ${{ env.TAG_NAME }}
tag: ${{ env.TAG_NAME }}
publish: true
env:
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }}
22 changes: 10 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,36 @@

## 📦 版本

[v0.0.3](https://github.com/PAICookers/PAITest/releases/tag/v0.0.3)
[v0.0.4](https://github.com/PAICookers/PAITest/releases/tag/v0.0.4)

## 🛠️ 使用

生成配置帧及对应测试输入帧,以实现硬件通路的简单测试,后续将芯片实际测试输出帧与预期结果进行对比即可。

由于配置帧/测试帧I型需要配合UART配置使用,因此目前仅采用**配置/测试帧II型**方案,且 `chip_addr` 固定为 `(0, 0)`
由于配置帧/测试帧I型需要配合UART配置使用,因此目前仅采用**配置/测试帧II型**方案,且 `chip_addr` `core*_addr` 均固定为 `(0, 0)`

各参数含义如下:

1. `save_path`:保存配置及测试帧文件的路径;
2. `groups`:生成 `N` 组配置-测试用例组合。每次配置包含3帧,而相应配置的测试仅1帧
2. `groups`:生成 `N` 组配置-测试用例组合。**每组**配置包含3帧,相应配置的测试帧仅1帧
3. `direction`:PC相对于PAICORE的位置,测试输出帧将从此方向输出。配置-测试用例中,单块PAICORE芯片地址将随机生成,但相对位置将不变,具体有如下几个选项:

```python
TestChipDirection.EAST
TestChipDirection.SOUTH
TestChipDirection.WEST
TestCHipDirection.NORTH
```
4. 应用示例(可参考 `main.py` ):
- 东:"EAST"、“East”、"east";
- 南:“SOUTH”、"South"、"south";
- 西:"WEST"、"West"、"west";
- 北:"NORTH"、“North”、"north";
4. 应用示例(也可参考 `main.py` ):

```python
from pathlib import Path
from paitest.paitest import GenTestCases, TestChipDirection
from paitest.paitest import GenTestCases

'''Path to store the config & test frames'''
save_path = Path.cwd() / "test"
'''N groups(3 frames in each group) of configuration frames to generated'''
groups = 1
'''PC direction relative to the CORE'''
direction = TestChipDirection.EAST
direction = "EAST"

GenTestCases(save_path, direction, groups)
```
Expand Down
12 changes: 8 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
from pathlib import Path
from paitest.paitest import GenTestCases, TestChipDirection
from paitest.paitest import GenTestCases


if __name__ == "__main__":
'''Here is a simple exmaple'''
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("-p", "--path", type=str,
default="./test", help="path to store test frames")
parser.add_argument("-g", "--groups", type=int,
default=1, help="how many groups of test frames to be generated")
parser.add_argument("-d", "--direction", type=TestChipDirection,
default=TestChipDirection.EAST, help="Test chip direction relative to the location of core")
parser.add_argument("-d", "--direction", type=str,
default="EAST", help="Test chip direction relative to the location of core")

args = parser.parse_args()

save_path = Path(args.path)
direction = args.direction
groups = args.groups

GenTestCases(save_path, direction, groups, False)
GenTestCases(save_path, direction, groups)

# Then, run "python main.py -p ./test -g 10 -d EAST" in your environment.
19 changes: 13 additions & 6 deletions paitest/paitest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .frames.frame import FrameGen
from .frames.frame_params import *
from pathlib import Path
from typing import Union
from typing import Union, Literal
import random


Expand All @@ -14,7 +14,11 @@

def GenTestCases(
save_dir: Union[str, Path] = ...,
direction: TestChipDirection = ...,
direction: Literal[
"EAST", "East", "east",
"SOUTH", "South", "south",
"WEST", "West", "west",
"NORTH", "North", "north"] = ...,
groups: int = 1,
random_chip_addr: bool = False
) -> None:
Expand All @@ -27,14 +31,16 @@ def GenTestCases(
if not frames_dir.exists():
frames_dir.mkdir(parents=True, exist_ok=True)

test_chip_dirc: TestChipDirection = TestChipDirection[direction.upper()]

with open(frames_dir / "config.bin", "wb") as fc, \
open(frames_dir / "testin.bin", "wb") as fi, \
open(frames_dir / "testout.bin", "wb") as fo:

for i in range(groups):
chip_addr: int = 0
chip_addr_x, chip_addr_y = 0, 0

# Need UART configuration when enable random_chip_addr
if random_chip_addr:
chip_addr_x, chip_addr_y = random.randrange(
Expand All @@ -45,15 +51,15 @@ def GenTestCases(
0, 2**5), random.randrange(0, 2**5)
core_addr: int = (core_addr_x << 5) | core_addr_y

core_star_addr_x, core_star_addr_y = random.randrange(
0, 2**5), random.randrange(0, 2**5)
# Random core* address is not supported
core_star_addr_x, core_star_addr_y = 0, 0
core_star_addr: int = (core_star_addr_x << 5) | core_star_addr_y

config_frames_group: List[int] = []
test_outframe_group: List[int] = []

test_chip_addr_x, test_chip_addr_y = chip_addr_x + \
direction.value[0], chip_addr_y + direction.value[1]
test_chip_dirc.value[0], chip_addr_y + test_chip_dirc.value[1]
test_chip_addr: int = (test_chip_addr_x << 5) | test_chip_addr_y

weight_width_type = random.choice(list(WeightPrecisionTypes))
Expand Down Expand Up @@ -92,6 +98,7 @@ def GenTestCases(
print("#12 SNN enable: %s" %
("True" if target_lcn else "False"))
print("#13 Target LCN: 0x%x" % target_lcn)
print("#14 Test chip addr: 0x%x, %s" % (test_chip_addr, direction.upper()))
print(f"----- Configuration frame: {i+1}/{groups} End -----")

config_frames_group, test_outframe_group = FrameGen.GenConfig2FrameGroup(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "PAITest"
version = "0.0.3"
version = "0.0.4"
description = "Test module for PAICORE 2.0"
authors = ["KafCoppelia <[email protected]>"]
license = "AGPL v3.0"
Expand Down

0 comments on commit 3efcb53

Please sign in to comment.