From ef069a5142f4d9a55a2a5830e1213fed58c4caaa Mon Sep 17 00:00:00 2001 From: KafCoppelia Date: Thu, 6 Apr 2023 21:34:57 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20enhancement:=20CORE=5FADDR?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E5=8F=AF=E4=BB=A5=E6=89=8B=E5=8A=A8=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 11 +++--- main.py | 18 ++++++++-- paitest/paitest.py | 89 ++++++++++++++++++++++++++++------------------ pyproject.toml | 2 +- 4 files changed, 78 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 7acc9d0..541a81b 100644 --- a/README.md +++ b/README.md @@ -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) ## 🛠️ 使用 @@ -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 @@ -38,7 +40,8 @@ direction = "EAST" GenTestCases(save_path, direction, groups) - ``` +``` + 5. 生成的 `N` 组配置帧II型、测试输入帧II型及参考测试输出帧II型在 `save_path` 下: ```python diff --git a/main.py b/main.py index adcfee2..ebc94e1 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,5 @@ from paitest.paitest import GenTestCases +from typing import Tuple if __name__ == "__main__": @@ -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. \ No newline at end of file + # Then, run "python main.py -p ./test -g 10 -d EAST -c 8 8 -v" in your environment. diff --git a/paitest/paitest.py b/paitest/paitest.py index ab11f1f..1c2925d 100644 --- a/paitest/paitest.py +++ b/paitest/paitest.py @@ -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[ @@ -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) @@ -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 @@ -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, diff --git a/pyproject.toml b/pyproject.toml index b37af58..ec126ff 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 "] license = "AGPL v3.0"