New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[OpenMP] outlined functions for target regions in header files not always uniquely named #52707
Comments
Would it be sufficient and doable to take the line number in the resulting file, not the original one (here the header)? |
If I understand the suggestion, it doesn't seem like that would work. For example if "c.inc" was included from another include "foo.h" which was included from the main source.
It seems no matter what line number is used there would be a problem. Plus (I suspect) 99.9% of functions in include files would not be different, so by encoding this info we could be generating a ton of extra functions with the same text and different names. |
I don't get it. So, there is one main source file, let's call it How does the foo code snipped contradict that? |
Any include could have two or more targets, so if c.inc has two they would both be on the same source line in main. Sorry I didn't provide a full example.
foo.h
c.inc
This produces four kernels, none of which have a single single unique line number: If you mean the line number in a preprocessed file would be unique, sure, but I don't think we actually have that information. If we do we'd still have the problem of matching exactly preprocessed files across the host and device compile. |
I get your point now, and yes, I meant preprocessed file. That said, I agree the matching is a problem. (One could argue target regions should be in both, but I guess that is not a great solution.) What if we number them per line then? So foo1_5_1, foo1_5_2, ... |
My impression is that any sort of numbering system could be broken by differences in macros between the host and device compile. But if we think we can ignore that possibility, and we think we'll see the same target regions in the same order during host and device codegen, maybe we can get the same name in both. I haven't looked at this code much so that's mostly speculation. |
Even without macros we can create mismatches. TBH, I think there is no "perfect" solution and the standard is not clear what should happen. We need to support the most common cases, so, if they match we need to get it right, but we can allow missing ones on either side. |
Proposed fix is here: https://reviews.llvm.org/D134816 |
The offloaded region is outlined to functions expecting DeviceID, FileID, ParentName, and LineNum to uniquely identify them. They are registered in CGOpenMPRuntime with:
But some users use macros to generate different code across the include file like this:
c.inc
Two functions are created on the host, but only one is used in the device compile.
This would result in silently executing the wrong code (incrementing i by 1 twice in the above example).
The text was updated successfully, but these errors were encountered: