Skip to content

Raymond0715/psys-py-sim

Repository files navigation

Python prototype and scripts to generate simulation data. (原谅我英语很差, 一堆语法错)

1 Overview & Comman Commands

1.1 Command Commands

# feature map - python simulation
python data_convert.py \
--dir fmap_dat \
--filename base_4_56_f.dat \
--in_shape 4 1 1 56 \
--convert_shape 0 1 2 3 4 \
--output base_4_56.dat

# weight - python simulation
python data_convert.py \
--dir weight_dat \
--filename base_4_3_3_f.dat \
--in_shape 4 1 3 3 \
--convert_shape 0 1 2 3 4 \
--quantize shift \
--quantize_integer 4 \
--quantize_bitwidth 4 \
--output base_4_3_3.dat

# feature map - modelsim simulation
python data_convert.py \
--dir fmap_dat \
--filename base_4_56_f.dat \
--in_shape 4 1 1 56 \
--paral 4 \
--convert_shape 2 4 0 1 3 \
--output base_4_56.txt \
--sim_paral 4 \
--txt

# weight - modelsim simulation
python data_convert.py \
--dir weight_dat \
--filename base_4_3_3_f.dat \
--in_shape 4 1 3 3 \
--paral 4 \
--convert_shape 0 4 1 2 3 \
--quantize shift \
--quantize_integer 4 \
--quantize_bitwidth 4 \
--output base_4_3_3.txt \
--sim_paral 4 \
--txt

# feature map - on board test
python data_convert.py \
--dir fmap_dat \
--filename base_4_56_f.dat \
--in_shape 4 1 1 56 \
--paral 4 \
--convert_shape 2 4 0 1 3 \
--output base_4_56_p.dat

# conv.py
python conv.py \
--fmap base_4_56.dat \
--fmap_shape 4 56 \
--weight base_4_3_3.dat \
--weight_shape 4 3 3 \
--out base_4_3_58.dat

1.2 Data Preprocess

Overview

The original data is float32 and stored into binary file. The filename of the original data will be end with 'f'.

The modelsim simulation data is integer and is stored into text file as hexadecimal.

The python simulation data is integer and is stored into text file as hexadecimal.

Data for on-board test is integer and is stored into binary file.

Example:

  • base_4_56_f.dat is original filename template.
  • base_4_56.txt is modelsim simulation filename template.
  • base_4_56.dat is python simulation filename template.
  • base_4_56_p.dat is on-board filename template.

Generate

Generate corresponding data from original data with data_convert.py.

Detailed data format:

The original feature map data layout (4D):
  ( channels, 1, row, column )

The original weight data layout (4D):
  ( out_channel, in_channel, row, col )

The on-board test feature map data layout (5D):
  ( 1, row, channel/paral, column, paral )

The on-board test weight data layout (5D):
  ( out_channel/paral, in_channel, row, col, paral )

data_generate.py

Data is generated as float and stored into binary file.

data_convert.py

It is the script that quantize data (feature map or weight) and store data into text file for simulation or store data into binary file for on-board test.

2 Detailed Information

2.1 conv.py

Simulate computation process of PE_cluster.v. Take original data as input. The bit-width of the feature map is 8 bits and the bit-width of the weights is 4. Adopt shift as convolution operator.

Data Format

bit width domain shape
feature map, x 8 $x \in [-128, 128) \land x \in \mathbb{Z}$ $(fmap_ch,fmap_size)$
weight,w 4 $w \in [-7, 7] \land w \in \mathbb{Z}$ $(weight_ch,3,3)$

Shift Operator

For the shift network:

  • The activation value is represented by a normal form.
  • The weight part is currently shifted to the right uniformly, and the sign indicates whether to take the complement or not, which means, the sign bit and the value bit represent operations at different positions.

For example, $z = Shift(w, x) = ax\times 2^b$, a and b are weights, which $a$ indicates if sign is $+1$ or $-1$, $b$ indicates shift bits, and $b <= 0 \land b \in \mathbb{Z}$; $x$ indicates activation and calculate with $a$ in complement form.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published