NVlabs / timeloop

Timeloop performs modeling, mapping and code-generation for tensor algebra workloads on various accelerator architectures.
https://timeloop.csail.mit.edu/
BSD 3-Clause "New" or "Revised" License
325 stars 101 forks source link

Timeloop mapper .txt output to .yaml error #116

Closed agarwal-ayushi closed 2 years ago

agarwal-ayushi commented 2 years ago

I am facing an issue while trying to convert the mapper output map.txt file to .yaml format for the timeloop-model. I am specifically working on the tutorial example: timeloop-accelergy-exercises/workspace/exercises/2020.ispass/timeloop/06-mapper-convlayer-eyeriss

For the mapping given in ref-output: timeloop-mapper.map.txt: here Motivation for my work: I want to use sparse-opt in the timeloop-model on a particular mapping to study impact of sparsity. timeloop-model uses map.yaml. Hence, this effort. I wrote a map.yaml file:

mapping:
- target: DRAM
type: temporal
factors: Q=4 M=4 C=8 P=1 R=1 S=1 N=1
permutation: CMQPRSN

- target: shared_glb
type: temporal
factors: M=4 P=56 Q=1 R=1 S=1 C=1 N=1
permutation: QMPRSCN

- target: shared_glb
type: spatial
factors: Q=14 M=1 P=1 C=1 R=1 S=1 N=1
permutation: QMPCRSN
split: 1

- target: DummyBuffer
type: temporal
factors: Q=1 M=1 C=1 S=1 P=1 R=1 N=1
permutation: MSCQPRN

- target: DummyBuffer
type: spatial
factors: Q=1 C=4 S=3 P=1 R=1 N=1 M=1
permutation: PRNMQSC
split: 4

- target: ifmap_spad
type: temporal
factors: Q=1 M=1 C=1 S=1 P=1 R=1 N=1
permutation: CMQSPRN

- target: weights_spad
type: temporal
factors: R=3 C=4 N=1 S=1 P=1 Q=1 M=1
permutation: CRNSPQM

- target: psum_spad
type: temporal
factors: M=16 R=1 C=1 N=1 S=1 P=1 Q=1
permutation: MRCNSPQ

However when I run: timeloop-model arch/eyeriss_like.yaml arch/components/*.yaml prob/VGG02_layer5.yaml trial_map.yaml I get this error: I have been unable to figure out the problem in my mapping. Any help would be great. No other files have been modified.

Sparse optimization configuration complete.
ERROR: couldn't map level psum_spad: mapped tile size 33 exceeds buffer capacity 16
angshuman-parashar commented 2 years ago

@nellie-wu could you take a look?

nellie-wu commented 2 years ago

@agarwal-ayushi Was the run involving any sparse-opt input (if so, would you please provide your input) or are we trying to do dense modeling as an initial attempt to reproduce the optimal mapping's performance with timeloop-model?

agarwal-ayushi commented 2 years ago

@nellie-wu As of now there is no sparse-opt input provided. I am first trying to attempt the dense-modeling with timeloop-model. This needs converting the timeloop-mapper .txt output to the required .yaml format. I have provided my attempt to write a .yaml mapping above for the optimal mapping provided in ref-output/timeloop-mapper.map.txt: here

nellie-wu commented 2 years ago

@agarwal-ayushi I see. So I think you are missing the bypass specifications.

By default, timeloop-model will try to keep all tensors in all storage. For example, in psum_spad, the default will assume all tensors will be stored, so the tize is: 16 (output) + 16 (weight) + 1 (input) = 33. However, in the actual mapping, we only want to keep the Output tensor, which is indicated by the brackets next to the storage name in the mapping (e.g., line 29) in the specific txt mapping file you are looking at.

To make sure we bypass correctly, please include the bypass blocks in your mapping, more specifically, line 8-26 in here.

agarwal-ayushi commented 2 years ago

Ok @nellie-wu. I understand my mistake. So to pass these constraints I was giving the complete timeloop-mapper constraints from constraints/ folder. But that kept giving me an error saying that the mapping fails the architecture constraints.

For timeloop-model, I suppose since we are modeling for a particular mapping, we only need to provide the bypassing constraints and not the mapping constraints. Is this understanding correct?

For completion of this post, I added the below to my .yaml and it worked.

  - target: psum_spad
    type: bypass
    bypass: [Inputs, Weights]
    keep: [Outputs]
  - target: weights_spad
    type: bypass
    bypass: [Inputs, Outputs]
    keep: [Weights]
  - target: ifmap_spad
    type: bypass
    bypass: [Weights, Outputs]
    keep: [Inputs]
  - target: DummyBuffer
    type: bypass
    bypass: [Inputs, Outputs, Weights]
  - target: shared_glb
    type: bypass
    bypass: [Weights]
    keep: [Inputs, Outputs]
angshuman-parashar commented 2 years ago

When using timeloop-model technically you are providing mapping "directives", not "constraints". The mapping directives need to completely and un-ambiguously describe what is going on in the mapping, you cannot ask timeloop-model to find one among multiple alternatives. That is why you have to describe all the bypassing directives in addition to all the other factors and permutations. Does that make sense?

agarwal-ayushi commented 2 years ago

@angshuman-parashar Yes. Makes sense now. It makes sense to me now why it kept giving an error when I provided it with the constraints. It also clarifies difference between the timeloop-mapper and the timeloop-model. Thank you for your help. Much appreciated.

FishSeeker commented 2 years ago

@agarwal-ayushi Hi may I know how to get the permutation that can be used in the timeloop-model from the timeloop-mapper.map.txt file?

angshuman-parashar commented 2 years ago

@FishSeeker timeloop-mapper also emits the optimal mapping as a libconfig .cfg file timeloop-mapper.map.cfg that can be directly fed back into timeloop-model. This is a recent update -- previously it would emit a set of constraints that resolve to that same mapping, but those constraints needed to be run with timeloop-mapper, not timeloop-model.

At the moment we are unable to emit yaml format, but timeloop (either model or mapper) will happily accept libconfig input as well. We do want to emit yaml in future and deprecate libconfig.

FishSeeker commented 2 years ago

@FishSeeker timeloop-mapper also emits the optimal mapping as a libconfig .cfg file timeloop-mapper.map.cfg that can be directly fed back into timeloop-model. This is a recent update -- previously it would emit a set of constraints that resolve to that same mapping, but those constraints needed to be run with timeloop-mapper, not timeloop-model.

At the moment we are unable to emit yaml format, but timeloop (either model or mapper) will happily accept libconfig input as well. We do want to emit yaml in future and deprecate libconfig.

Thank you.