intel / llvm

Intel staging area for llvm.org contribution. Home for Intel LLVM-based projects.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`-fsycl` breaks `_OPENMP` preprocessor definition

j-stephan opened this issue · comments

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.

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

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!

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)

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