Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

[C++4OpenCL] restrict keyword not accepted #39978

Closed Quuxplusone closed 3 years ago

Quuxplusone commented 5 years ago
Bugzilla Link PR41008
Status RESOLVED WONTFIX
Importance P enhancement
Reported by Kévin Petit (kevin.petit@arm.com)
Reported on 2019-03-08 03:42:39 -0800
Last modified on 2021-01-14 07:11:09 -0800
Version trunk
Hardware PC Linux
CC anastasia.stulova@arm.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
Trying to compile the following test program:

-------------------------------------------------------
kernel void test(__global int* restrict ptr)
{
}
-------------------------------------------------------

with the following command line (rev 355676):

clang -cc1 -triple spir64-unknown-unknown -emit-llvm -x cl -cl-std=c++ test.cl

leads to the following error:

-------------------------------------------------------
test.cl:2:41: error: expected ')'
kernel void test(__global int* restrict ptr)
                                        ^
test.cl:2:17: note: to match this '('
kernel void test(__global int* restrict ptr)
                ^
1 error generated.
-------------------------------------------------------
Quuxplusone commented 5 years ago

restrict is not a keyword in C++, and the word "restrict" does not appear in the OpenCL/C++ 2.2 specification (https://www.khronos.org/registry/OpenCL/specs/2.2/html/OpenCL_Cxx.html). So I think this is working correctly.

Clang permits use of __restrict to get restrict semantics in C++.

Quuxplusone commented 5 years ago

I guess the code just needs to be changed to use __restrict?

Quuxplusone commented 5 years ago

My understanding is that the goal of -cl-std=c++ is to maximise compatibility with OpenCL C whilst enabling C++ features to be used in conjunction with OpenCL.

restrict is rather common in OpenCL C programs. The first example that comes to mind is the SHOC benchmarks [1] but I've seen that in many other programs. I can see value in making this "just work" (easier to reuse and port code) if it doesn't create problems otherwise.

[1] https://github.com/vetter/shoc/blob/master/src/opencl/level1/spmv/spmv.cl

Quuxplusone commented 5 years ago

Yes, this is right! The idea is to accept as much OpenCL C code under -cl-std=c++ as possible without changes. But of course the other goal is also to minimize the divergence with C++ to avoid complicating compiler code base.

I will try to investigate why C++ didn't adopt this spelling in the first place to see if there are any wider implications of allowing it under C++ for OpenCL. Or perhaps Richards has some insights.

Thanks!

Quuxplusone commented 5 years ago

Makes sense, thank you!

Quuxplusone commented 3 years ago

Restrict is not supported by C++ for OpenCL v1.0, see section 2.2.1.3 (https://github.com/KhronosGroup/OpenCL-Docs/releases/tag/cxxforopencl-v1.0-r1)

It is possible that some other versions of the language will relax it however it doesn't seem easy at the moment with the C++ position on this. It is very easy to work around the issue by mapping to __restrict for use cases that guarantee to work correctly.