-
Notifications
You must be signed in to change notification settings - Fork 770
warn not error when SYCL_EXTERNAL applied to anonymous namespaces #1777
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
Comments
@jeffhammond, could you please elaborate, why do you need to have From SYCL 1.2.1 spec, section 6.9.1 SYCL Functions and methods linkage:
If you have function in anonymous namespace, you cannot call it from other translation units anyway and it is unclear to me why do you need Am I missing something? BTW, looking at the reproducer, I cannot find any |
@AlexeySachkov I'll make a reproducer. The commit after the one I shared added |
Basically, take https://github.com/jeffhammond/Quicksilver/blob/ae353aa8d178f2eef8f2c13ee4923633aba1d51b/src/dpct/MCT.cc and change |
MCVE $ dpcpp -std=c++14 -O3 -ferror-limit=1 -c bug.cc
bug.cc:5:5: error: 'sycl_device' attribute cannot be applied to a static function or function in an anonymous namespace
SYCL_EXTERNAL
^
<built-in>:735:38: note: expanded from here
#define SYCL_EXTERNAL __attribute__((sycl_device))
^
1 error generated. bug.cc#include <CL/sycl.hpp>
namespace
{
SYCL_EXTERNAL
int foo(int i) { return i*i; }
}
namespace Bar
{
SYCL_EXTERNAL
int bar(int i) { return foo(i) + 1; }
} |
The reason why this matters is that, when we use the DPCT, code labeled as device code will have the Relaxing the parser here is similar to how we do not require kernel names. It's a user convenience feature. I do not mine at all if it requires a flag like |
I guess compiler can just ignore SYCL_EXTERNAL applied to |
That would be nice. Thanks! And I don't mind a warning along the lines of |
Couldn't this also be fixed in DPCT? If the function declared as device code is static or in an anonymous namespace, arguably DPCT shouldn't be marking it as |
I'm not entirely sure that the DPCT added If I am forced to fix this manually, I'll have to find every single instance of |
I understand why this is frustrating, but I still think we should pay attention to how Marking every function as For example, SYCL 1.2.1 places restrictions on the definition of a |
The reason to relax the compiler check in this particular case is that C++ already says that Will the USM proposal relax the restriction on |
Sure. I'm just worried that
No, this is unrelated to USM. The issue here is that SYCL 1.2.1 address space inference rules can't work across a function call boundary. When an external function is compiled, it needs to know which address space its arguments are in. It can't be inferred from the callsite (because it's in a different translation unit). |
@jeffhammond, thanks for the background of the issue
I would vote for warning too: someone who just placed
I've just realized one more thing: this macro is optional and only defined by the SYCL implementation if it supports offline linking. But I guess it only matters if some portability is desired and from portability point of view it is probably better to avoid using this macro at all (or be ready to workaround SYCL spec limitations somehow) |
Actually it is possible to have Useful for metaprogramming or recycling old code like the case discussed here. Can someone create an internal spec issues to see if that makes sense before doing a 1.2.1 PR? |
Interesting. I didn't know about this -- thanks for pointing it out! I agree that it makes sense for |
LLNL Quicksilver (https://github.com/LLNL/Quicksilver) uses anonymous namespaces extensively for code that is only used within a single compilation unit, which is the modern C++ equivalent of static functions (https://stackoverflow.com/questions/154469/unnamed-anonymous-namespaces-vs-static-functions).
Given that anonymous namespaces only need to be resolved in a single compilation unit, I do not see why the compiler can't support these. We should support as a SYCL extension ASAP and propose to Khronos.
I just spent the last hour fixes ~20 instances of this warning.
I don't think you need a reproducer, but https://github.com/jeffhammond/Quicksilver/tree/29f799ed09d16145aa63753d7e8527946a901f6d has a non-minimal one.
The text was updated successfully, but these errors were encountered: