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

-fsycl breaks _OPENMP preprocessor definition #10711

Open
j-stephan opened this issue Aug 7, 2023 · 4 comments
Open

-fsycl breaks _OPENMP preprocessor definition #10711

j-stephan opened this issue Aug 7, 2023 · 4 comments
Labels
bug Something isn't working confirmed

Comments

@j-stephan
Copy link
Contributor

Describe the bug
Compiling a program which makes use of _OPENMP to check for the OpenMP version will result in a broken macro if -fsycl is used as a compilation flag.

To Reproduce

#include <iostream>

#if _OPENMP < 200203
#error Oops!
#endif

auto main() -> int
{
    std::cout << "OpenMP version: " << _OPENMP << std::endl;
}

Without SYCL:

icpx -std=c++17 -fiopenmp
OpenMP version: 201811

With SYCL:

icpx -std=c++17 -fsycl -fiopenmp
<source>:4:2: error: Oops!
#error Oops!
 ^
<source>:9:40: error: use of undeclared identifier '_OPENMP'
    std::cout << "OpenMP version: " << _OPENMP << std::endl;
                                       ^
2 errors generated.
Compiler returned: 1

See it here on godbolt.

@j-stephan j-stephan added the bug Something isn't working label Aug 7, 2023
@TApplencourt
Copy link
Contributor

TApplencourt commented Aug 15, 2023

AFAIK: It's expected due to the 2 pass compilation strategy used by DPCPP, you need to protect the OpenMP code to be not compiled during the SYCL pass

@bernhardmgruber
Copy link
Contributor

bernhardmgruber commented Sep 5, 2023

So, this effectively means that I cannot have OpenMP and SYCL code in the same translation unit? Is this a current implementation limitation or is there a fundamental reason why this cannot work? Is there any plan to support this in the future? Thx!

@TApplencourt
Copy link
Contributor

TApplencourt commented Sep 5, 2023

No, it works. You just need to play with pragma in the case when you rely on the presence of OpenMP macro. If you just use pragma, it will work out of the box.

applenco@x1921c0s1b0n0:~> cat test.cpp
#include <vector>
#include <sycl/sycl.hpp>
#include <iostream>

#include <iostream>

#if (_OPENMP < 200203) && !defined(SYCL_LANGUAGE_VERSION)
#error Oops!
#endif

int main()
{
#if defined(_OPENMP)
    std::cout << "OpenMP version: " << _OPENMP << std::endl;
#endif

    #pragma omp target
    {}

    sycl::queue Q;
    Q.single_task([](){});
}
applenco@x1921c0s1b0n0:~> icpx -fiopenmp -fopenmp-targets=spir64 -fsycl test.cpp
applenco@x1921c0s1b0n0:~> ./a.out
OpenMP version: 201811

You can even allocate memory in sycl and use it in OpenMP (https://github.com/argonne-lcf/HPC-Patterns/tree/main/sycl_omp_ze_interopt)

@bernhardmgruber
Copy link
Contributor

Thx a lot @TApplencourt, I think I understood how this works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working confirmed
Projects
None yet
Development

No branches or pull requests

4 participants