Codegen: indexing aliases of multidimensional memlets generates std::tuples
- Dominant language
- Python
- Stars
- 593
- Forks
- 163
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 60
Description
Consider the following tasklet:
```python
# Memlets:
# Input: values_full (entire slice of a 2D array)
# Output: result_item (single element of a 2D array)
values_alias = values_full
result_item = values_alias[1, 2]
```
The generated C++ code is the following:
```c++
auto values_alias = values_full;
result_item = values_alias[std::make_tuple(1, 2)];
```
However, what's expected is that DaCe generates the linear index:
```c++
auto values_alias = values_full;
result_item = values_alias[1 * stride0 + 2 * stride1];
```
When the memlet `values_full` is accessed directly, the correct linear index expression is generated.
Possible solutions:
- disallow the usage of memlets in contexts not fully supported by codegen, like assignment
- treat AST subscripts with tuple expressions as indexing operations, and not tuples (where do you get the strides?)
- instead of raw pointers, use a small strided buffer `struct` that supports indexing by tuples and keep relying on `auto` in codegen
Context:
Generating the tasklet's code from an AST/IR (such as gt4py's internal IRs) is sometimes much simpler with little tricks like creating aliases as it can spare the trouble of doing passes on the whole IR. It's up to debate if DaCe should take this kind of workload instead of the users, but even if not, DaCe should at least reject the code before codegen.
Contributor guide
Assessment
This issue has not been assessed yet.