-
Notifications
You must be signed in to change notification settings - Fork 769
[SYCL] Re-use OpenCL address space attributes for SYCL #1581
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
[SYCL] Re-use OpenCL address space attributes for SYCL #1581
Conversation
Today we re-use OpenCL parsed attributes, but have separate SYCL address space semantic attributes as current implementation of OpenCL semantics breaks valid C++. This patch enables re-use of OpenCL semantic attributes by allowing conversions between types qualified with OpenCL address spaces and type w/o address space qualifiers. Clang compiler (almost) always adds address space qualifiers in OpenCL mode, so it should not affect OpenCL mode. NOTE: this change also disables implicit conversion between the unqualified types and types qualified with `__attribute__((address_space(N)))`, enabled by one of the previous SYCL patches. Signed-off-by: Alexey Bader <[email protected]>
Signed-off-by: Mariya Podchishchaeva <[email protected]>
Signed-off-by: Mariya Podchishchaeva <[email protected]>
Signed-off-by: Mariya Podchishchaeva <[email protected]>
Signed-off-by: Mariya Podchishchaeva <[email protected]>
libdevice/spirv_vars.hpp
Outdated
@@ -26,9 +26,9 @@ SYCL_EXTERNAL size_t __spirv_LocalInvocationId_z(); | |||
#else // __SYCL_NVPTX__ | |||
|
|||
typedef size_t size_t_vec __attribute__((ext_vector_type(3))); | |||
extern "C" const __attribute__((opencl_constant)) | |||
extern "C" const __attribute__((opencl_global)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you clarify why this is changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once we re-use OpenCL address space attributes, we re-use diagnostics for them. It seems that OpenCL doesn't allow uninitialized variables in constant address space.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use default address space here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think yes. Such change doesn't break my local check-sycl
run on CPU device and I don't see any address space requirements in SPIR-V representation in LLVM IR doc .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was troubled by this as well. I couldn't find a requirement from the OpenCL environment spec.
@bashbaug shouldn't the env spec specify the storage class of builtin variables ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't the env spec specify the storage class of builtin variables ?
Yes, I believe it should. Would you mind filing an issue against the SPIR-V Environment spec on https://github.com/khronosgroup/opencl-docs to get this fixed?
Signed-off-by: Mariya Podchishchaeva <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot the justification for the change this is reverting (and now the justification for the revert...) but I remember being properly motivated the last time. The code itself looks fine.
@bader , should I fix clang-format fail? |
Yes formatting issues must be fixed. |
I'm a bit confused about the plans after this patch. And it seems like the future direction is important to understand whether using the same set of attributes for OCL and SYCL is a good idea. A couple of questions regarding the following example (for SYCL compiled with #include <type_traits>
#define __private __attribute__((opencl_private))
#define __local __attribute__((opencl_local))
//struct S { void f() __private; }; //should be OK?
void t() {
//__private int i1; //should be OK?
int i2;
static_assert(std::is_same_v<decltype(&i2), int*>); //intentional difference
__private int* p;
__local int* l;
p-l; //should be error "non-overlapping address spaces"?
} Why does it error where OpenCL for C++ doesn't and not error in cases where OpenCL does? To me the behavior of OpenCL makes much more sense in all three cases. Are these differences intentional? And if so why? Or are are they considered bugs? If so should those be fixed as part of this change or in follow up changes? On the other hand there are intentional differences like the one tested with the |
I can see errors in OpenCL for C++ (https://godbolt.org/z/3aaoVQ), but there is no errors in SYCL. It happens because the corresponding diagnostic is wrapped with llvm/clang/lib/Sema/SemaExpr.cpp Line 9705 in cece82e
Why it can be a problem? Do you have any examples/arguments? |
This introduce a semantic difference between SYCL and OpenCL that needs to be maintained. On the other hand, is it realistic (especially with the upstreaming objective) to clone the whole logic just because there is a few cases where the logic diverges ? Cloning the logic has plenty of other consequences, and I would personally be much more concerned about maintaining a fully cloned logic rather than maintaining a few and controlled differences. |
I think this difference happens because in OpenCL the compiler is intended to add address space qualifiers to all (at least almost all) pointers. AFAIK it is done during parsing, there is a good explanation #1039 (comment). We don't do this for SYCL because it can lead to problems in C++ code (I think @erichkeane can explain it much more better than me). |
Makes sense. |
SYCL doesn't define the attributes but it defines |
since the merge of this I get following errors on compiling a simple sycl program |
This is strange... |
Ah, yes, thanks for the hint! the compiler used outdated headers. Works fine after updating them |
Today we re-use OpenCL parsed attributes, but have separate SYCL address
space semantic attributes as current implementation of OpenCL semantics
breaks valid C++. This patch enables re-use of OpenCL semantic
attributes by allowing conversions between types qualified with OpenCL
address spaces and type w/o address space qualifiers. Clang compiler
(almost) always adds address space qualifiers in OpenCL mode, so it
should not affect OpenCL mode.
This is rebased and updated version of #1039