Skip to content

Commit

Permalink
Merge pull request #13 from PAICookers/dev
Browse files Browse the repository at this point in the history
🔖 v1.0.1
  • Loading branch information
KafCoppelia authored Apr 26, 2023
2 parents 423ef05 + 741a2e9 commit 3d08e56
Show file tree
Hide file tree
Showing 15 changed files with 163 additions and 102 deletions.
4 changes: 2 additions & 2 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ categories:
label: "chore"
- title: "📝 documentation"
labels:
- "doc"
- "readme"
- "doc"
- "readme"

change-template: "- $TITLE @$AUTHOR (#$NUMBER)"
change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/poetry-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ jobs:
python_version: "3.10"
pypi_token: ${{ secrets.PYPI_API_TOKEN }}
build_format: "wheel"
ignore_dev_requirements: "yes"
ignore_dev_requirements: "yes"
3 changes: 2 additions & 1 deletion .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- master
- dev

pull_request:
types: [opened, reopened, synchronize]
Expand All @@ -21,7 +22,7 @@ jobs:
steps:
- uses: actions/checkout@v3
with:
ref: main
ref: master

- name: Setup Poetry
uses: Gr1N/setup-poetry@v8
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,4 @@ dmypy.json

*.bin
.vscode
test
test
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ repos:
- id: check-yaml
- id: check-added-large-files
- id: mixed-line-ending
- id: check-json
- id: check-json
35 changes: 23 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

## 📦 版本

[v1.0.0](https://github.com/PAICookers/PAITest/releases/tag/v1.0.0)
[v1.0.1](https://github.com/PAICookers/PAITest/releases/tag/v1.0.1)

✨支持 `.txt` 格式输出

## 🛠️ 使用生成

Expand All @@ -22,49 +24,58 @@
# Define the direction of test chip
PAITestManager = paitest("EAST")
```
2. `Get1GroupForNCoresWithNParams`,产生一组针对 `N` 个核的配置-测试帧,每个核配置不同参数。可以指定单个需要**屏蔽**的核坐标。`verbose=True` 以开启日志显示,默认关闭。

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

```python
groups = 10 # Generate 10 groups
save_to_dir="./test" # Save frames into ./test directory

# Generate configuration frames, testin & testout frames
cf, ti, to = PAITestManager.Get1GroupForNCoresWithNParams(groups, save_dir=save_to_dir)
cf, ti, to = PAITestManager.Get1GroupForNCoresWithNParams(groups, save_dir=save_to_dir, verbose=True)

# Mask a cord coordinate so that avoid generating the same coordinate.
# And enable verbose logging
cf, ti, to = PAITestManager.Get1GroupForNCoresWithNParams(groups,
save_dir=save_to_dir, masked_core_coord=(12, 16), verbose=True)
cf, ti, to = PAITestManager.Get1GroupForNCoresWithNParams(groups,
save_dir=save_to_dir, masked_core_coord=(12, 16), gen_txt=True)
```
3. `Get1GroupForNCoresWith1Param`,产生1组针对 `N` 个核的配置-测试帧,每个核配置相同参数。可以指定单个需要**屏蔽**的核坐标

⚠️ 指定 `verbose=True` 以开启日志显示,默认关闭;指定 `gen_txt=True` 以保存至 `.txt`,默认保存至 `.bin`

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

```python
# Same as Get1GroupForNCoresWithNParams
cf, ti, to = PAITestManager.Get1GroupForNCoresWith1Param(10, save_dir="./test")
```
4. `GetNGroupsFor1CoreWithNParams`,产生 `N` 组针对1个核的配置-测试帧,每个核配置不同参数。可以指定单个需要**屏蔽**的核坐标

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

```python
# Same as Get1GroupForNCoresWithNParams
cf, ti, to = PAITestManager.GetNGroupsFor1CoreWithNParams(1, save_dir="./test")
```
5. `ReplaceCoreCoord`,替换单个或**一组**帧中的 `CORE_ADDR` 为指定坐标。

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

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

⚠️ 一组指一组完整的配置帧,包含3帧。对于测试输入帧,即为单帧。
6. `SaveFrames`,保存帧数据至 `.bin` 文件

6. `SaveFrames`,默认保存帧数据至指定文件,支持 `.bin``.txt` 格式

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

# Or text files
PAITestManager.SaveFrames("./test/config.txt", replaced)
```

## 🗓️ TODO

- [X] 上板验证
- [x] 上板验证
- [ ] 参数检验
- [ ] 配置/测试帧III/IV型
14 changes: 7 additions & 7 deletions example.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from paitest import paitest
from paitest.frames import FrameDecoder


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

Expand All @@ -14,19 +13,20 @@
# PAITest instance
PAITestManager = paitest("EAST")

# 1. Generate 1 group for N cores with N parameters reg.
# 1. Generate 1 group for N cores with N **different** parameters reg.
a_cf, a_ti, a_to = PAITestManager.Get1GroupForNCoresWithNParams(
3, save_dir="./test", verbose=True
3, save_dir="./test", verbose=True # Turn on the verbose mode
)
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")
# 2. Generate 1 group for N cores with the **same** 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.
# 3. Generate N groups for 1 core with N **different** parameters reg.
a_cf, a_fi, a_fo = PAITestManager.GetNGroupsFor1CoreWithNParams(
3, save_dir="./test1"
3, save_dir="./test1", gen_txt=True # Can save into .txt file as well
)

# 3. Replace the core coordinate with (9, 9) then save in test/config_r.bin
Expand Down
16 changes: 7 additions & 9 deletions paitest/frames/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
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
from .frame import Addr2Coord as Addr2Coord
from .frame import Coord2Addr as Coord2Addr
from .frame import Direction as Direction
from .frame import FrameDecoder as FrameDecoder
from .frame import FrameGen as FrameGen
from .frame import FrameMask as FrameMask
from .frame import FrameSubType as FrameSubType
2 changes: 1 addition & 1 deletion paitest/frames/coord.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Tuple, Union, Optional
from typing import Optional, Tuple, Union


class Coord:
Expand Down
6 changes: 5 additions & 1 deletion paitest/frames/coord.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import overload, Tuple
from typing import Tuple, overload

class Coord:
x: int = ...
Expand All @@ -19,7 +19,11 @@ class Coord:

__repr__ = __str__

...

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

...
59 changes: 36 additions & 23 deletions paitest/frames/frame.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from .frame_params import (
FrameType as FT,
FrameSubType as FST,
FrameMask as FM,
ConfigFrameMask as CFM,
)
from .frame_params import *
from .coord import Coord
from typing import List, Tuple, Union, Dict, Optional, Any
import random
from typing import Any, Dict, List, Optional, Tuple, Union

from .coord import Coord
from .frame_params import ConfigFrameMask as CFM
from .frame_params import FrameMask as FM
from .frame_params import FrameSubType as FST
from .frame_params import FrameType as FT
from .frame_params import *


def Addr2Coord(addr: int) -> Coord:
Expand Down Expand Up @@ -117,9 +116,11 @@ def _GenParamReg(
if not is_legal:
# Don't care 'tick_wait_start' split in #1 and #2
for _ in range(2):
param_reg.append(random.randint(0, FM.GENERAL_PAYLOAD_MASK))
param_reg.append(random.randint(
0, FM.GENERAL_PAYLOAD_MASK))

param_reg[1] = (param_reg[1] & (~CFM.TEST_CHIP_ADDR_HIGH3_MASK)) | high3
param_reg[1] = (param_reg[1] & (
~CFM.TEST_CHIP_ADDR_HIGH3_MASK)) | high3
param_reg.append(low7 << CFM.TEST_CHIP_ADDR_LOW7_OFFSET)
else:
# Do legal geenration
Expand Down Expand Up @@ -346,12 +347,14 @@ def _general_info(self) -> None:

chip_coord = self._get_chip_coord()
print(
"#2 Chip coordinate: [0x%02x | 0x%02x]" % (chip_coord.x, chip_coord.y)
"#2 Chip coordinate: [0x%02x | 0x%02x]" % (
chip_coord.x, chip_coord.y)
)

core_coord = self._get_core_coord()
print(
"#3 Core coordinate: [0x%02x | 0x%02x]" % (core_coord.x, core_coord.y)
"#3 Core coordinate: [0x%02x | 0x%02x]" % (
core_coord.x, core_coord.y)
)

core_star_coord = self._get_core_star_coord()
Expand All @@ -362,18 +365,26 @@ def _general_info(self) -> None:

def _config2_info(self) -> None:
print("Info of parameter registers")
print("#1 Weight width: 0x%x" % self._param_reg_dict["weight_width"])
print("#1 Weight width: 0x%x" %
self._param_reg_dict["weight_width"])
print("#2 LCN: 0x%x" % self._param_reg_dict["LCN"])
print("#3 Input width: 0x%x" % self._param_reg_dict["input_width"])
print("#4 Spike width: 0x%x" % self._param_reg_dict["spike_width"])
print("#5 Neuron num: %d" % self._param_reg_dict["neuron_num"])
print("#3 Input width: 0x%x" %
self._param_reg_dict["input_width"])
print("#4 Spike width: 0x%x" %
self._param_reg_dict["spike_width"])
print("#5 Neuron num: %d" %
self._param_reg_dict["neuron_num"])
print("#6 Pool max enable: %d" % self._param_reg_dict["pool_max"])
print("#7 Tick wait start: 0x%x" % self._param_reg_dict["tick_wait_start"])
print("#8 Tick wait end: 0x%x" % self._param_reg_dict["tick_wait_end"])
print("#7 Tick wait start: 0x%x" %
self._param_reg_dict["tick_wait_start"])
print("#8 Tick wait end: 0x%x" %
self._param_reg_dict["tick_wait_end"])
print("#9 SNN enable: %d" % self._param_reg_dict["SNN_EN"])
print("#10 Target LCN: 0x%x" % self._param_reg_dict["target_LCN"])
print("#10 Target LCN: 0x%x" %
self._param_reg_dict["target_LCN"])

test_chip_coord: Coord = self._param_reg_dict["test_chip_coord"] # type: ignore
# type: ignore
test_chip_coord: Coord = self._param_reg_dict["test_chip_coord"]
print(
"#11 Test chip coord: [0x%02x | 0x%02x]"
% (test_chip_coord.x, test_chip_coord.y)
Expand Down Expand Up @@ -424,10 +435,12 @@ def _param_reg_parse(self) -> None:

high3 = self._frames_group[1] >> CFM.TEST_CHIP_ADDR_HIGH3_OFFSET
low7 = self._frames_group[2] >> CFM.TEST_CHIP_ADDR_LOW7_OFFSET
self._param_reg_dict["test_chip_coord"] = test_chip_addr_combine(high3, low7)
self._param_reg_dict["test_chip_coord"] = test_chip_addr_combine(
high3, low7)

def _decode_direction(self) -> Direction:
test_chip_coord: Coord = self._param_reg_dict["test_chip_coord"] # type: ignore
# type: ignore
test_chip_coord: Coord = self._param_reg_dict["test_chip_coord"]
offset = test_chip_coord - self._get_chip_coord()

try:
Expand Down
3 changes: 2 additions & 1 deletion paitest/frames/frame_params.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from enum import Flag, Enum, unique
from enum import Enum, Flag, unique

from .coord import CoordOffset


Expand Down
Loading

0 comments on commit 3d08e56

Please sign in to comment.