Skip to content

compilation with -fno-sycl-rdc is broken due to __sycl_cmath_wrapper_impl.hpp (missing definition of SYCL_EXTERNAL) #21652

@romintomasetti

Description

@romintomasetti

Describe the bug

4f0afd5 introduced __sycl_cmath_wrapper_impl.hpp.

It seems that this file broke compilation with the -fno-sycl-rdc flag as soon as <cmath> is included and targeting CUDA (haven't tried AMD).
The code is as simple as:

#include <cmath>

int main() {}

And using icpx (2025.3.3.20260319) with compile command:

icpx -x c++ -fsycl -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend=nvptx64-nvidia-cuda --cuda-gpu-arch=sm_90 test.cpp

is fine but with:

icpx -x c++ -fsycl -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend=nvptx64-nvidia-cuda --cuda-gpu-arch=sm_90 -fno-sycl-rdc test.cpp

it fails with:

# [5/5] RUN icpx -x c++ -fsycl -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend=nvptx64-nvidia-cuda --cuda-gpu-arch=sm_86 -fno-sycl-rdc test.cpp
# 0.429 In file included from test.cpp:1:
# 0.429 In file included from /opt/intel/oneapi/compiler/2025.3/bin/compiler/../../include/sycl/stl_wrappers/cmath:41:
# 0.429 /opt/intel/oneapi/compiler/2025.3/bin/compiler/../../include/sycl/stl_wrappers/__sycl_cmath_wrapper_impl.hpp:225:12: error: unknown type name 'SYCL_EXTERNAL'
# 0.429   225 | extern "C" SYCL_EXTERNAL float __nv_nearbyintf(float);
# 0.429       |            ^
# 0.430 /opt/intel/oneapi/compiler/2025.3/bin/compiler/../../include/sycl/stl_wrappers/__sycl_cmath_wrapper_impl.hpp:226:12: error: unknown type name 'SYCL_EXTERNAL'
# 0.430   226 | extern "C" SYCL_EXTERNAL double __nv_nearbyint(double);
# 0.430       |            ^
# 0.487 2 errors generated.
# ERROR: process "/bin/sh -c icpx -x c++ -fsycl -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend=nvptx64-nvidia-cuda --cuda-gpu-arch=sm_86 -fno-sycl-rdc test.cpp" did not complete successfully: exit code: 1

Below I've put a Dockerfile to reproduce the issue, along with a typical output.

I think @npmiller @bader introduced that file. It may be related to:

To reproduce

The Dockerfile to reproduce.

FROM nvcr.io/nvidia/cuda:12.8.1-devel-ubuntu24.04

ARG COMPILER_VERSION=2025.3

RUN <<EOF
    set -ex

    apt update && apt --no-install-recommends --yes install wget gpg

    wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB \
        | gpg --dearmor | tee /usr/share/keyrings/oneapi-archive-keyring.gpg > /dev/null
    echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" \
        | tee /etc/apt/sources.list.d/oneAPI.list

    apt update

    apt --no-install-recommends --yes install intel-oneapi-compiler-dpcpp-cpp-${COMPILER_VERSION}
EOF

ENV PATH=/opt/intel/oneapi/compiler/${COMPILER_VERSION}/bin/:$PATH
ENV LD_LIBRARY_PATH=/opt/intel/oneapi/compiler/${COMPILER_VERSION}/lib:$LD_LIBRARY_PATH

COPY <<EOF test.cpp
#include <cmath>

int main() {}
EOF

RUN icpx --version

# Compiling without specifying "-fno-sycl-rdc" is fine.
RUN icpx -x c++ -fsycl -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend=nvptx64-nvidia-cuda --cuda-gpu-arch=sm_90 test.cpp

# Compiling with "-fno-sycl-rdc" is broken.
RUN icpx -x c++ -fsycl -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend=nvptx64-nvidia-cuda --cuda-gpu-arch=sm_90 -fno-sycl-rdc test.cpp

An example of output for:

docker buildx build --tag test --progress=plain - < repro.dockerfile

#0 building with "default" instance using docker driver

#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 2.41kB done
#1 DONE 0.0s

#2 [internal] load metadata for nvcr.io/nvidia/cuda:12.8.1-devel-ubuntu24.04
#2 DONE 1.1s

#3 [internal] load .dockerignore
#3 transferring context: 2B done
#3 DONE 0.0s

#4 [internal] preparing inline document
#4 DONE 0.0s

#5 [1/6] FROM nvcr.io/nvidia/cuda:12.8.1-devel-ubuntu24.04@sha256:520292dbb4f755fd360766059e62956e9379485d9e073bbd2f6e3c20c270ed66
#5 DONE 0.0s

#6 [2/6] RUN <<EOF (set -ex...)
#6 CACHED

#7 [3/6] COPY <<EOF test.cpp
#7 CACHED

#8 [4/6] RUN icpx --version
#8 0.229 Intel(R) oneAPI DPC++/C++ Compiler 2025.3.3 (2025.3.3.20260319)
#8 0.229 Target: x86_64-unknown-linux-gnu
#8 0.229 Thread model: posix
#8 0.229 InstalledDir: /opt/intel/oneapi/compiler/2025.3/bin/compiler
#8 0.229 Configuration file: /opt/intel/oneapi/compiler/2025.3/bin/compiler/../icpx.cfg
#8 DONE 0.3s

#9 [5/6] RUN icpx -x c++ -fsycl -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend=nvptx64-nvidia-cuda --cuda-gpu-arch=sm_90 test.cpp
#9 DONE 0.8s

#10 [6/6] RUN icpx -x c++ -fsycl -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend=nvptx64-nvidia-cuda --cuda-gpu-arch=sm_90 -fno-sycl-rdc test.cpp
#10 0.393 In file included from test.cpp:1:
#10 0.393 In file included from /opt/intel/oneapi/compiler/2025.3/bin/compiler/../../include/sycl/stl_wrappers/cmath:41:
#10 0.393 /opt/intel/oneapi/compiler/2025.3/bin/compiler/../../include/sycl/stl_wrappers/__sycl_cmath_wrapper_impl.hpp:225:12: error: unknown type name 'SYCL_EXTERNAL'
#10 0.393   225 | extern "C" SYCL_EXTERNAL float __nv_nearbyintf(float);
#10 0.393       |            ^
#10 0.394 /opt/intel/oneapi/compiler/2025.3/bin/compiler/../../include/sycl/stl_wrappers/__sycl_cmath_wrapper_impl.hpp:226:12: error: unknown type name 'SYCL_EXTERNAL'
#10 0.394   226 | extern "C" SYCL_EXTERNAL double __nv_nearbyint(double);
#10 0.394       |            ^
#10 0.436 2 errors generated.
#10 ERROR: process "/bin/sh -c icpx -x c++ -fsycl -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend=nvptx64-nvidia-cuda --cuda-gpu-arch=sm_90 -fno-sycl-rdc test.cpp" did not complete successfully: exit code: 1
------
 > [6/6] RUN icpx -x c++ -fsycl -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend=nvptx64-nvidia-cuda --cuda-gpu-arch=sm_90 -fno-sycl-rdc test.cpp:
0.393 In file included from test.cpp:1:
0.393 In file included from /opt/intel/oneapi/compiler/2025.3/bin/compiler/../../include/sycl/stl_wrappers/cmath:41:
0.393 /opt/intel/oneapi/compiler/2025.3/bin/compiler/../../include/sycl/stl_wrappers/__sycl_cmath_wrapper_impl.hpp:225:12: error: unknown type name 'SYCL_EXTERNAL'
0.393   225 | extern "C" SYCL_EXTERNAL float __nv_nearbyintf(float);
0.393       |            ^
0.394 /opt/intel/oneapi/compiler/2025.3/bin/compiler/../../include/sycl/stl_wrappers/__sycl_cmath_wrapper_impl.hpp:226:12: error: unknown type name 'SYCL_EXTERNAL'
0.394   226 | extern "C" SYCL_EXTERNAL double __nv_nearbyint(double);
0.394       |            ^
0.436 2 errors generated.
------
Dockerfile:46
--------------------
  44 |     # 0.487 2 errors generated.
  45 |     # ERROR: process "/bin/sh -c icpx -x c++ -fsycl -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend=nvptx64-nvidia-cuda --cuda-gpu-arch=sm_86 -fno-sycl-rdc test.cpp" did not complete successfully: exit code: 1
  46 | >>> RUN icpx -x c++ -fsycl -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend=nvptx64-nvidia-cuda --cuda-gpu-arch=sm_90 -fno-sycl-rdc test.cpp
  47 |     
--------------------
ERROR: failed to build: failed to solve: process "/bin/sh -c icpx -x c++ -fsycl -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend=nvptx64-nvidia-cuda --cuda-gpu-arch=sm_90 -fno-sycl-rdc test.cpp" did not complete successfully: exit code: 1

Environment

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions