Skip to content

Conversation

@Lunderberg
Copy link
Contributor

This mimics the behavior in MakePackedAPI, and is assumed to be the case for some codegens.

@Mousius
Copy link
Member

Mousius commented Sep 26, 2022

@Lunderberg I think we make use of this in following passes and I'm unsure why make packed API decides to clear it?

@Mousius Mousius self-assigned this Sep 26, 2022
@Lunderberg
Copy link
Contributor Author

Lunderberg commented Sep 26, 2022

@Mousius Thank you, and it looks like that's also being caught in the tests, as this breaks pretty much every ethos-u test at this line. (Also why I intentionally marked this as a draft PR, to catch any impact to workflows that I'm not as familiar with.)

To me, the buffer_map is an indicator for how a function should later be lowered, and what buffers should be defined as part of the lowered function. Once it has been used, then it makes sense for the resulting function to have an empty buffer_map, because no further lowering is required. After #9727, the buffer shape/size could still be accessed by later passes find finding the BufferLoad or BufferStore object that makes use of a parameter, rather than searching in the buffer_map itself, or the passes could be moved to an earlier stage of lowering.

@Lunderberg
Copy link
Contributor Author

@Mousius Can you check the latest commit on this PR? I didn't try to re-order the passes, but reading from the BufferStore/BufferLoad objects instead of the buffer_map resolved the test cases I ran locally.

@Mousius
Copy link
Member

Mousius commented Sep 26, 2022

To me, the buffer_map is an indicator for how a function should later be lowered, and what buffers should be defined as part of the lowered function. Once it has been used, then it makes sense for the resulting function to have an empty buffer_map, because no further lowering is required. After #9727, the buffer shape/size could still be accessed by later passes find finding the BufferLoad or BufferStore object that makes use of a parameter, rather than searching in the buffer_map itself, or the passes could be moved to an earlier stage of lowering.

Aha! Makes perfect sense, thanks for the explanation! I figured that was why it was in draft, being a bit nosey as I remember wondering about it when I was writing MakeUnpackedAPI 😸

Copy link
Member

@Mousius Mousius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mousius Can you check the latest commit on this PR? I didn't try to re-order the passes, but reading from the BufferStore/BufferLoad objects instead of the buffer_map resolved the test cases I ran locally.

The fix makes sense to me, can we either make use of get_loads and get_stores or move the collect_buffer_map function to utils.py?

Also can we add to the documentation of the Pass the intention behind clearing it?

@Lunderberg
Copy link
Contributor Author

The fix makes sense to me, can we either make use of get_loads and get_stores or move the collect_buffer_map function to utils.py?

Certainly. It is now pulled out and documented, with defined behavior for buffers that share a backing Var.

@Lunderberg
Copy link
Contributor Author

I figured that was why it was in draft, being a bit nosey as I remember wondering about it when I was writing MakeUnpackedAPI 😸

No worries at all, and I wouldn't consider it nosey, either. It's the exact type of comment I was hoping for, as there wasn't an immediately obvious reason for the asymmetry between packed and unpacked.

Also can we add to the documentation of the Pass the intention behind clearing it?

Good call, and will do.

if buffer_info[param].btype == BufferType.constant:
continue
buffer = primfunc.buffer_map[param]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just chatted with @ekalda around this and we're not sure why the extra buffer appears, it appears to be an unused intermediary buffer and for the tests I ran this fixes it:

Suggested change
if param not in buffer_map:
base_addresses.append(
util.BaseAddress(
param.name.replace("-", "_"),
idx,
_get_region(buffer_info[param].btype, param, scratch_region_map),
0,
)
)
idx += 1
continue

I can tidy this loop up afterwards 😸

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works for me locally, on to the CI! Thank you on the ethos-u debugging, and it helps quite a bit.

This mimics the behavior in `MakePackedAPI`, and is assumed to be the
case for some codegens.
This previously relied on `MakeUnpackedAPI` preserving the
`PrimFunc::buffer_map`, even after it had been used for lowering.  It
now reads from the `BufferLoad` and `BufferStore` nodes to determine
buffer shapes.
@Lunderberg Lunderberg force-pushed the unpacked_api_buffer_map branch from 297ceb6 to 17ce8c3 Compare September 27, 2022 15:26
@Lunderberg Lunderberg marked this pull request as ready for review September 27, 2022 18:01
@Mousius Mousius merged commit bec9f16 into apache:main Sep 27, 2022
@Mousius
Copy link
Member

Mousius commented Sep 27, 2022

Thanks for making the API that little bit more consistent @Lunderberg 😸

@Lunderberg Lunderberg deleted the unpacked_api_buffer_map branch September 27, 2022 22:30
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 25, 2022
* [TIR][Transform] Clear buffer_map during MakeUnpackedAPI

This mimics the behavior in `MakePackedAPI`, and is assumed to be the
case for some codegens.

* Remove read of buffer_map  in ethosu.tir_to_cs_translator

This previously relied on `MakeUnpackedAPI` preserving the
`PrimFunc::buffer_map`, even after it had been used for lowering.  It
now reads from the `BufferLoad` and `BufferStore` nodes to determine
buffer shapes.

* Added more documentation for MakePackedAPI/MakeUnpackedAPI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants