On Thu, Jan 02, 2025 at 06:28:47PM -0800, Webb Xu wrote:
> Sorry, maybe I misled you. I have fused the "reshape" and its predominant
> elementwise for i2 in range 5: for j2 in range 2: for k2 in range 8: a[k2 +
> j2*8 + i2* 16] = input[k2 + j2*8 + i2* 16] b[i2, j2, k2] = a[k2 + j2*8 +
> i2* 16] The loop fusion has been done without isl. Following that, we
> utilized isl for loop tiling. The problem is how to express the schedule
> space. We are not sure that if the dims are [i, i2, j2, k2] or [i] or [i2,
> j2, k2].
If you expect the generated code to consist of three loops,
then you should use a 3-dimensional schedule space.
That's exactly what I showed before. Here it is again:
domain: "{ s0[0:79]; s1[0:4,0:1,0:7] }"
child:
schedule: "B[ \
{s0[i] -> [i//16]; s1[i,j,k] -> [i]}, \
{s0[i] -> [(i//8)%2]; s1[i,j,k] -> [j]}, \
{s0[i] -> [i%8]; s1[i,j,k] -> [k]} \
]"
child:
sequence:
- filter: "{ s0[*] }"
- filter: "{ s1[*,*,*] }"
If you prefer a map representation, then you should go for
something like
{ s0[i=0:79] -> B[i//16, (i//8)%2, i%8, 0];
s1[i=0:4,j=0:1,k=0:7] -> B[i, j, k, 1] }
However, if you intend to perform tiling, then a schedule tree
representation is more convenient.
See also Section 5.6 Schedule of
"Presburger Formulas and Polyhedral Compilation"
for more information about schedules.
> We adopt the scheduling as [i] or [i2, j2, k2] because they can
> either be expressed with the other. The 2 cases are listed as following:
> 1. The dim is i, the domain is supposed to be represented as:
> domain: {s0[i]: 0<= i <= 79;
> s1[ i2, j2, k2]: 0<= i2 <= 4 and 0<= j2 <= 1 and 0<= i2 <= 7 ;}
>
> 2. The dim is [i2, j2, k2], the domain is supposed to be represented as:
> domain: {s0[i ]: i = k2 + j2*8 + i2* 16 and 0<= i2 <= 4 and 0<= j2 <= 1 and
> 0<= i2 <= 7;
> s1[i2, j2, k2]: 0<= i2 <= 4 and 0<= j2 <= 1 and 0<= i2 <= 7 ;}
This is not a valid object since you didn't define k2, j2, and i2
in the first disjunct.
In any case, you shouldn't modify the domain;
you should define a schedule in terms of the original domain.
> If we take the second case as the example, the code reads:
> isl_ctx* ctx = isl_ctx_alloc();
> isl_set* cur_set;
>
> isl_val* i2_range = isl_val_int_from_si(ctx, 5);
> isl_val* j2_range = isl_val_int_from_si(ctx, 2);
> isl_val* k2_range = isl_val_int_from_si(ctx, 8);
>
> // exp1 space
> isl_space* exp1_space = isl_space_alloc(ctx, 0, 3, 1);
> isl_space_set_tuple_name(exp1_space, isl_dim_set, "exp1");
> isl_space_set_tuple_name(exp1_space, isl_dim_set, "exp1");
The first call to isl_space_set_tuple_name consumes exp1_space,
so you cannot pass the same value to the second call (or anywhere else).
At the same time, you should keep track of the return value
of the call(s) so that you can use or free the result later.
(It may happen that the return value is equal to the argument,
but this is by no means guaranteed.)
Also, for a map space, you should use isl_dim_in or isl_dim_out,
not isl_dim_set.
Finally, you are setting the same tuple name twice.
> // sch tree
> isl_schedule* schedule = isl_schedule_from_domain(domain);
You are creating an empty schedule tree here.
This doesn't define any order.
> The code yields: domain: "{ [i2, j2, k2] : 0 <= i2 <= 4and 0 <= j2 <= 1
> and 0<=k2<=7; reshape[i2, j2, k2] : 0 <= i2 <= 4and 0 <= j2 <= 1 and
> 0<=k2<=7}". The constraints are missing and space name of exp1 disappears.
You projected out the named tuple, so it makes sense
the name diappears.
It's not clear which constraints are supposed to be missing.
> Is our idea and the schedule correct?
No.
> Note that we would like to place exp1
> and reshape spaces within the same schedule dims such that they could be
> lying in the same nested loops.
For that, you should define a schedule as explained above.
skimo