Skip to content
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

Intel DPC++ and [[no_unique_address] #305

Open
wdx04 opened this issue Jan 2, 2024 · 4 comments
Open

Intel DPC++ and [[no_unique_address] #305

wdx04 opened this issue Jan 2, 2024 · 4 comments

Comments

@wdx04
Copy link

wdx04 commented Jan 2, 2024

Hi,

The latest Intel DPC++ compiler supports C++20 and [[no_unique_address]] attribute, however it does not support feature testing of the [[no_unique_address]] attribute.

When compiling SYCL source code using mdspan with DPC++ and /std:c++20,
MDSPAN_HAS_CXX_20 is true, but
((__has_cpp_attribute(no_unique_address) >= 201803L)) is false.

Because of this, _MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS and _MDSPAN_NO_UNIQUE_ADDRESS macros in __p0009_bits/config.hpp will not be correctly defined in SYCL host code, causing compilation errors.

Please see https://community.intel.com/t5/Intel-oneAPI-Data-Parallel-C/Failed-to-use-mdspan-in-SYCL-kernel-code/m-p/1542689 for discussion on the errors.

I think SYCL Unified Shared Memory (USM) is one of the most important use cases of mdspan, and DPC++ is one of the best SYCL compilers, so it would be nice to have a workaround for that compiler.

Thanks,

@crtrott
Copy link
Member

crtrott commented Jan 5, 2024

I added a comment in the Intel thread, but basically this is a serious compiler issue as far as I can tell. My understanding is that the issue is that the two macros in question end up being defined differently in host and device code, something which definitely should not happen. That said we do occasionally work around compiler bugs if you find a fix (I don't have a setup for windows SYCL) feel free to propose one.

@wdx04
Copy link
Author

wdx04 commented Jan 10, 2024

I added a comment in the Intel thread, but basically this is a serious compiler issue as far as I can tell. My understanding is that the issue is that the two macros in question end up being defined differently in host and device code, something which definitely should not happen. That said we do occasionally work around compiler bugs if you find a fix (I don't have a setup for windows SYCL) feel free to propose one.

Hi crtrott,

I don't think Intel will fix the compiler issue any time soon, and I have found a workaround for the compiler:

  1. Recognize the Intel DPC++ compiler via the predefined macro __INTEL_LLVM_COMPILER.
  2. When the Intel DPC++ compiler is present, enable the use of [[no_unique_address]] attribute if MDSPAN_HAS_CXX_20 is true, regardless of __has_cpp_attribute(no_unique_address).

The modified __p0009_bits/config.hpp is verified to work with the DPC++ 2024.0 compiler.

config.hpp.txt

Thanks,

@crtrott
Copy link
Member

crtrott commented Jan 11, 2024

Yeah we can do this or something similar. Possibly restricting this to when SYCL is enabled?

@wdx04
Copy link
Author

wdx04 commented Jan 12, 2024

We can use the SYCL_LANGUAGE_VERSION macro to check if SYCL is enabled:

// dpcpp only
#if defined(SYCL_LANGUAGE_VERSION) && defined (__INTEL_LLVM_COMPILER)
   // code specific for DPC++ compiler below
   // ... ...

   // example only
   std::cout << "SYCL_LANGUAGE_VERSION: " << SYCL_LANGUAGE_VERSION << std::endl;
   std::cout << "__INTEL_LLVM_COMPILER: " << __INTEL_LLVM_COMPILER << std::endl;
   std::cout << "__VERSION__: " << __VERSION__ << std::endl;
#endif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants