1D-CNN's problem.yaml configuration
xpww opened this issue · 2 comments
Hello! I recently started working with timeloop, and I noticed that both construct_workloads.py
and cnn_layers.py
in timeloop-accelergy-exercises/workspace/baseline_designs/scripts
are configuration files for CONV2D
.
I consider CONV1D
as a special case of CONV2D
. For a one-dimensional convolution with ifmap=(1,3600)
, kernel size=(8,7)
, stride=2
, and ofmap=(8,1802)
, I configured it in cnn_layers.py
as follows:
# W, H, C, N, M, S, R, Wpad, Hpad, Wstride, Hstride
cnn_layers = [ (3600, 1, 1, 1, 8, 1, 7, 5, 0, 2, 0) ]
My question is, is it appropriate to set H
and S
to 1
, and Hpad
and Hstride
to 0
? Because in order to make this code run, I had to change the original code in construct_workloads.py
from:
q = int((w - s + 2 * wpad) / wstride) + 1
p = int((h - r + 2 * hpad) / hstride) + 1
to:
p = int((w - r + 2 * wpad) / wstride) + 1
if hstride != 0:
q = int((h - s + 2 * hpad) / hstride) + 1
else:
q = 1
In addition, the reason why q = int((w - s + 2 * wpad) / wstride) + 1
is changed to q = int((h - s + 2 * hpad) / hstride) + 1
is to match the official tutorial corresponds to the pictures in the tutorial.pdf
.In fact, if do not make any changes and just add the judgment condition if hstride != 0
, then run python3 run_example_designs.py --architecture eyeriss_like --problem 1d_cnn_layers.yaml
, the original 3600 inputs will be recognized as 7 inputs. mistake in timeloop-mapper.map.txt
.
I am concerned that changing the source code provided by the official repository may introduce errors.
Some of those scripts (e.g., construct_workloads.py) are just helpers scripts and aren't as well-tested as the main codebase. Please feel free to modify them and submit bugfixes.
That said, I don't believe we have stride=0 in any of our regression tests for the main codebase either. The recommended way to model 1D conv is to have a separate problem spec. However, you are correct that configuring it as a special case of 2D conv should work. Does it work after your script changes? You can also try directly invoking the Timeloop binary from hand-written YAMLs.
Some of those scripts (e.g., construct_workloads.py) are just helpers scripts and aren't as well-tested as the main codebase. Please feel free to modify them and submit bugfixes.
That said, I don't believe we have stride=0 in any of our regression tests for the main codebase either. The recommended way to model 1D conv is to have a separate problem spec. However, you are correct that configuring it as a special case of 2D conv should work. Does it work after your script changes? You can also try directly invoking the Timeloop binary from hand-written YAMLs.
hi, sfter modifying construct_workloads.py, the generated yaml file is as follows:
problem:
instance:
C: 1
Hdilation: 1
Hstride: 0
M: 8
N: 1
P: 1802
Q: 1
R: 7
S: 1
Wdilation: 1
Wstride: 2
shape:
coefficients:
- default: 1
name: Wstride
- default: 1
name: Hstride
- default: 1
name: Wdilation
- default: 1
name: Hdilation
data_spaces:
- name: Weights
projection:
- - - C
- - - M
- - - R
- - - S
- name: Inputs
projection:
- - - N
- - - C
- - - R
- Wdilation
- - P
- Wstride
- - - S
- Hdilation
- - Q
- Hstride
- name: Outputs
projection:
- - - N
- - - M
- - - Q
- - - P
read_write: true
dimensions:
- C
- M
- R
- S
- N
- P
- Q
name: CNN_Layer
version: 0.4
After executing python3 run_example_designs.py --clear_outputs --architecture eyeriss_like --problem 1dcnn.yaml
on this yaml file, the content of the generated timeloop-mapper.map.txt file is as follows:
DRAM [ Weights:56 (56) Inputs:3609 (3609) Outputs:14416 (14416) ]
-----------------------------------------------------------------
| for P in [0:1802)
shared_glb [ Inputs:7 (7) Outputs:8 (8) ]
inter_PE_column_spatial [ ]
---------------------------
| for M in [0:2) (Spatial-X)
inter_PE_spatial [ ]
--------------------
| for M in [0:4) (Spatial-Y)
ifmap_spad [ Inputs:7 (7) ]
weights_spad [ Weights:7 (7) ]
------------------------------
| for R in [0:7)
psum_spad [ Outputs:1 (1) ]
---------------------------
| << Compute >>
I can't quite understand the other generated files at the moment, but as far as timeloop-mapper.map.txt
is concerned, the number of weight, input, ofmap, and Loop mapping modifications seem to be correct.