Putting more to the discussion. Here is one possible way to embed the logical-physical info (namely 2D memory flattening hint)
@R.function
def main_canonicalized(x: R.Tensor((4, 5, 128)):
# split on axis 1, this is also a default
lv1 = R.memory_axis_separator(x, axis=1)
...
# hint to split on axis 2 instead
lvn = R.memory_axis_separator(x, axis=2)
Then a pass FlattenLowAxisSepDimensions
will come and rewrite all tensor data into the format of A[i0, i1, ... i_n]
, where by default(i0, i1, i2.. i_{n-1}
are flattened to one dimension and i_n
get flattened into another dimension, and index rewrite the related TIR functions as well.
The main rationale is that even in the presence of ND, the lower dimension is usually desirable to be more regular(aka multiple of page size or in many cases good to be explicitly the page size). So the number of possible mapping is not that many. Additionally, being directly in physical canonical format makes scheduling and optimizing the TensorIR much easier.
The tradeoff here is that if the reasoning of flatten is related to one pass, or a few, having the pass to reason some related info would be simpler.
Coming back to high level, there are tradeoffs in when to put things into StructInfo. The advantage of StructInfo is of course every operator would need to think about (default) deduction of the information and a lot of pass would need to reason about them. The possible downside is also every pass and operators need to reason about the related information. The shape is in TensorStructInfo because it is being used in many passes and we want to by default recovering the info in all cases, additionally, users do think more about shape information when constructing kernels like te. We make an explicit choice for now to make logical to physical mapping mostly be in default (aka for 1D mem case it is flattening) so that the reasoning of local performance is easier, while making layout propagation.
We can start with something like pass based approach first, learn about possible lessons, and then think about strategies, the related lessons would help us to think about further steps