Consider the kernel:
knl = lp.make_kernel(
"{[i, j, k]: 0<=i,j,k<10}",
"""
y[i] = 0 if sum(j, j) else sum(k, k)
""")
print(lp.generate_code_v2(knl).device_code())
which generates:
void loopy_kernel(double* x, double* y)
{
int acc_j;
double acc_k;
int tmp[10];
for (int i = 0; i <= 9; ++i)
{
acc_k = 0.0;
tmp[i] = i;
acc_j = 0;
if (!acc_j)
for (int k = 0; k <= 9; ++k)
acc_k = acc_k + x[10 * i + k];
for (int j = 0; j <= 9; ++j)
acc_j = acc_j + tmp[j];
y[i] = (acc_j ? 0.0 : acc_k);
}
}
Notice how acc_j is read before it is written. The reason being realize_reduction doesn't enforce dependencies between the statements during the transformation.
Consider the kernel:
which generates:
Notice how
acc_jis read before it is written. The reason beingrealize_reductiondoesn't enforce dependencies between the statements during the transformation.