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
Variadic Macros Support for OpenCL #50
Comments
+1, I've never understood why this restriction exists, either. At the very least it would be nice to support variadic macros via an offline compiler, say when compiling to SPIR-V. I suspect supporting variadic macros via an online compiler would require an extension, just to formalize that some implementations support this functionality, while others don't. |
I don't think compiler actually knows if it's offline or online compilation. Also I wouldn't like the code rejected differently depending on that. I would just allow it unconditionally. |
I think this depends what "the compiler" is. If it's a newer version of open source CLANG, I can see how it might not know if it is being used for offline or online compilation. However, we have been shipping snapshots of CLANG with our drivers for years, which only get used for online compilation (meaning: for programs created using
The extension would be a way to differentiate between online compilers that may report errors for variadic macros and online compilers where variadic macros are supported. |
I don't really see why it should be more difficult for an online compiler, therefore I'd propose to just allow it unconditionally. If they are concerns that some compilers cannot do it, then I'd go for the extension. |
That's really great that Intel compiler has such a feature! I suspect some other vendors might have it too. However, we probably won't want to force every vendor to implement the same? From the compiler design side I would also minimise divergence between online and offline mode to reduce the complexity. But what I am concerned most about that for the OpenCL application developers we will provide a language with inconsistent behaviour. It is not uncommon to develop kernel code using offline compiler (where you can see error reported easly) and then once it is ready for execution it's compiled with the online compilation flow. I think it would really be a pain if you need to change your code every time between phases. There are plenty of other use cases with mixing online and offline parsing flow. Unless we see a real value in doing this conditionally I would recommend to change it coherently for both. As a matter of fact do we even have separate language spec for offline and online mode? I also don't see it as any extension either but rather general update to the spec. It brings no compatibility issue for old code because we are lifting the restriction and not adding it. |
Sorry about that, I don't think I'm explaining very well. Let me try again.
Does this help? |
Thanks for clarification! I see what you mean now. However, I am just trying to understand why is this case different from the other similar bugs in the spec we are fixing. We don't create an extension for each of them typically and I don't think this is even helpful. As for the extensions I would vote against adding new ones in general as much as possible but especially for this case. I generally would like to minimize use of them because they are just extra complications for the application and tools developers. |
Since there is no objection to relax this in general the plan is to relax this restriction as a Clang extension and then potentially adopt in the language spec in some way. |
Clang change in review: https://reviews.llvm.org/D59492 |
Committed in r356987. This will be supported from clang9 onwards. I will keep this open until we decide what to do about the spec changes. |
Need conclusion on #65 to proceed. |
I am wondering why the OpenCL standard forbids variadic macros. They are actually allowed by a couple of OpenCL implementations I have been using, but they are disabled in clang (yielding "error: variadic macros not supported in OpenCL")
I do not understand the reasoning behind disabling variadic macros, in particular since OpenCL compilers usually are based on A C / C++ frontent, which usually has a preprocessor that would actually support variadic macros.
I agree variadic macros do not belong to a modern coding style in the direction of C++20, but I have some code where they are widely used, in particular when you try to have common code segments for different GPU APIs, where you do not have access to the full C++ feature set.
Prime examples are
My suggestion is to simply allow variadic macros in the code, since they do not increase compiler complexity anyway. At least, there could be an OpenCL extension or in case of clang a compile-time switch to allow variadic macros. My current workaround is to run the .cl file through the -std=c99 frontend of clang for the preprocessor phase and then I am giving the preprocessed file to clang again with -std=c++
The text was updated successfully, but these errors were encountered: