Handling repated loop variables #812
Replies: 1 comment 1 reply
-
What you report is by design, where the goal is that, for transformation purposes (e.g. As far as I'm concerned, there's no easy win here: either loop identifiers become more complicated, or we disallow their repeated use. Fusing loops behind the user's back is not a good idea IMO, as it's quite likely to lead to non-equivalent code. The renaming solution you propose is also what I would call the "official" remedy. It is also what the "Fortran frontend" does under the hood, see this code here: loopy/loopy/frontend/fortran/translator.py Lines 765 to 787 in bf3091b |
Beta Was this translation helpful? Give feedback.
-
Hi All,
I am porting CEED BP5 (which is solving pressure Poisson equation using CG) with
nomp to GPUs. I am running into a case where there are repeated loop variables in C
kernels like the following gather-scatter kernel:
I am splitting
i
and tagging the resulting inames asg.0
andl.0
. Both thej
loops are serial loops.
If I use the above C-code as is, it is an error in
nomp
right now since the variablename
j
is repeated. As a workaround, I have renamed the secondj
loop tok
but I think this needs a better solution.
For example in the Ax kernel (which is the poisson operator), there will be about 12
loop variables if the user had to rename the loops:
https://github.com/nomp-org/benchmarks/blob/main/CEED/BP5/backends/bp5-backend-nomp.c#L126
Only solution we (@kaushikcfd and I) could think of other than asking the user to
use different loop variables for distinct loops is to assume the same loop variable
in C implies the same loop domain in loopy (so basically, we are fusing the loops
with same loop variables).
For the SEM/FEM code, I think it is an okay solution. We can document this as how
nomp
interprets code and ask the user to use different loop variables if they areactually different and wants to avoid fusing.
We would love to hear from the loopy community if there is a better solution to
resolve this matter in a more elegant manner.
Beta Was this translation helpful? Give feedback.
All reactions