Skip to content

Commit

Permalink
Merge pull request #6 from PAICookers/dev
Browse files Browse the repository at this point in the history
🔖 v0.0.7
  • Loading branch information
KafCoppelia authored Apr 6, 2023
2 parents 8f41063 + ef069a5 commit 4e141fd
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 42 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

## 📦 版本

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

## 🛠️ 使用

Expand All @@ -24,9 +24,11 @@
- 南:“SOUTH”、"South"、"south";
- 西:"WEST"、"West"、"west";
- 北:"NORTH"、“North”、"north";
4. 应用示例(也可参考 `main.py` ):
4. `verbose``-v` 启用打印生成帧详细信息;
5. `core``-c 3, 4` 固定生成帧中的 `CORE_ADDR` 属性;
6. 应用示例(也可参考 `main.py` ):

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

Expand All @@ -38,7 +40,8 @@
direction = "EAST"

GenTestCases(save_path, direction, groups)
```
```

5. 生成的 `N` 组配置帧II型、测试输入帧II型及参考测试输出帧II型在 `save_path` 下:

```python
Expand Down
18 changes: 16 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from paitest.paitest import GenTestCases
from typing import Tuple


if __name__ == "__main__":
Expand All @@ -12,13 +13,26 @@
default=1, help="how many groups of test frames to be generated")
parser.add_argument("-d", "--direction", type=str,
default="EAST", help="Test chip direction relative to the location of the core")
parser.add_argument("-v", "--verbose", action="store_true", help="Display the log or silently")
parser.add_argument("-c", "--core", type=int, nargs="+",
default=0, help="Fix core address if you want")

args = parser.parse_args()

save_path = args.path
direction = args.direction
groups = args.groups
verbose = args.verbose
core_addr = args.core

GenTestCases(save_path, direction, groups)
GenTestCases(
save_path,
direction,
groups,
(0, 0),
# Optional for these parameters below
fixed_core_addr=tuple(core_addr),
verbose=verbose
)

# Then, run "python main.py -p ./test -g 10 -d EAST" in your environment.
# Then, run "python main.py -p ./test -g 10 -d EAST -c 8 8 -v" in your environment.
89 changes: 54 additions & 35 deletions paitest/paitest.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
from .frames.frame import FrameGen
from .frames.frame_params import *
from pathlib import Path
from typing import Union, Literal
from typing import List, Union, Literal, Tuple, Optional
import random


'''
1. Input configuration frame II
2. Input test frame II
3. Compare the test output frame II with expected
'''


def GenTestCases(
save_dir: Union[str, Path] = ...,
direction: Literal[
Expand All @@ -20,8 +13,23 @@ def GenTestCases(
"WEST", "West", "west",
"NORTH", "North", "north"] = ...,
groups: int = 1,
random_chip_addr: bool = False
fixed_chip_addr: Optional[Tuple[int, int]] = ...,
fixed_core_addr: Optional[Tuple[int, int]] = ...,
verbose: bool = True
) -> None:
'''
1. save_dir: Where to save the frames file
2. direction: Test chip direction relative to the location of the core
3. groups: How many groups of configuration-test frames to be generated
4. fixed_chip_addr: Fix the chip address, e.g. (1, 1) for fixing the CHIP_ADDR with (1, 1)
5. fixed_core_addr: Fix the core address, e.g. (3, 4) for fixing the CORE_ADDR with (3, 4)
6. verbose: Display the logs
Usages:
1. Input configuration frame II
2. Input test frame II
3. Compare the test output frame II with expected
'''

if isinstance(save_dir, str):
frames_dir = Path(save_dir)
Expand All @@ -42,13 +50,23 @@ def GenTestCases(
chip_addr_x, chip_addr_y = 0, 0

# Need UART configuration when enable random_chip_addr
if random_chip_addr:
if isinstance(fixed_chip_addr, Tuple):
chip_addr_x, chip_addr_y = fixed_chip_addr
else:
chip_addr_x, chip_addr_y = random.randrange(
0, 2**5), random.randrange(0, 2**5)
chip_addr: int = (chip_addr_x << 5) | chip_addr_y

core_addr_x, core_addr_y = random.randrange(
0, 2**5), random.randrange(0, 2**5)
chip_addr: int = (chip_addr_x << 5) | chip_addr_y

core_addr: int = 0
core_addr_x, core_addr_y = 0, 0

if isinstance(fixed_core_addr, Tuple):
core_addr_x, core_addr_y = fixed_core_addr
else:
core_addr_x, core_addr_y = random.randrange(
0, 2**5), random.randrange(0, 2**5)

core_addr: int = (core_addr_x << 5) | core_addr_y

# Random core* address is not supported
Expand Down Expand Up @@ -79,28 +97,29 @@ def GenTestCases(
snn_en = random.choice([0, 1])
target_lcn = random.randrange(0, 2**4)

print(f"----- Configuration frame: {i+1}/{groups} Start -----")
print("#1 Chip address: [0x%02x | 0x%02x]" % (
chip_addr_x, chip_addr_y))
print("#2 Core address: [0x%02x | 0x%02x]" % (
core_addr_x, core_addr_y))
print("#3 Core star address: [0x%02x | 0x%02x]" % (
core_star_addr_x, core_star_addr_y))
print("#4 Weight width: 0x%x" % weight_width_type.value)
print("#5 LCN: 0x%x" % lcn_type.value)
print("#6 Input width: 0x%x" % input_width_type.value)
print("#7 Spike width: 0x%x" % spike_width_type.value)
print("#8 Neuron num: %d" % neuron_num)
print("#9 Pool max enable: %s" %
("True" if target_lcn else "False"))
print("#10 Tick wait start: 0x%x" % tick_wait_start)
print("#11 Tick wait end: 0x%x" % tick_wait_end)
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 -----")
if verbose:
print(f"----- Configuration frame: {i+1}/{groups} Start -----")
print("#1 Chip address: [0x%02x | 0x%02x]" % (
chip_addr_x, chip_addr_y))
print("#2 Core address: [0x%02x | 0x%02x]" % (
core_addr_x, core_addr_y))
print("#3 Core star address: [0x%02x | 0x%02x]" % (
core_star_addr_x, core_star_addr_y))
print("#4 Weight width: 0x%x" % weight_width_type.value)
print("#5 LCN: 0x%x" % lcn_type.value)
print("#6 Input width: 0x%x" % input_width_type.value)
print("#7 Spike width: 0x%x" % spike_width_type.value)
print("#8 Neuron num: %d" % neuron_num)
print("#9 Pool max enable: %s" %
("True" if target_lcn else "False"))
print("#10 Tick wait start: 0x%x" % tick_wait_start)
print("#11 Tick wait end: 0x%x" % tick_wait_end)
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(
chip_addr,
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.6"
version = "0.0.7"
description = "Test module for PAICORE 2.0"
authors = ["KafCoppelia <[email protected]>"]
license = "AGPL v3.0"
Expand Down

0 comments on commit 4e141fd

Please sign in to comment.