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

[libc++][HIP] call to 'sqrt' is ambiguous in lambda functions #119076

Open
AngryLoki opened this issue Dec 7, 2024 · 0 comments
Open

[libc++][HIP] call to 'sqrt' is ambiguous in lambda functions #119076

AngryLoki opened this issue Dec 7, 2024 · 0 comments
Labels
clang:headers Headers provided by Clang, e.g. for intrinsics

Comments

@AngryLoki
Copy link
Contributor

Here is the problematic HIP code (i. e. code is heavily affected by __clang_hip_runtime_wrapper.h), which compiles with libstdc++, but fails with libc++:

#include <cmath>

// This works both with libstdc++ and libc++
long double f1(long double arg) {
    return std::sqrt(arg);
}

// This fails with libc++
void f2() {
    auto f3 = [](long double arg) -> long double { return std::sqrt(arg); };
}

This code on godbolt: https://godbolt.org/z/jds86rzK9. Note that there it uses clang-17, as hip after that is affected by ROCm/clr#100. But after applying fix for clr the issue is reproducible with newer versions of clang:

$ clang-19 -x hip test.cpp -S -nogpulib -stdlib=libstdc++
# Ok!

$ clang-19 -x hip test.cpp -S -nogpulib -stdlib=libc++
test.cpp:8:59: error: call to 'sqrt' is ambiguous
    8 |     auto f3 = [](long double arg) -> long double { return std::sqrt(arg); };
      |                                                           ^~~~~~~~~
/usr/lib/llvm/19/bin/../../../../lib/clang/19/include/__clang_cuda_math_forward_declares.h:172:19: note: candidate function
  172 | __DEVICE__ double sqrt(double);
      |                   ^
/usr/lib/llvm/19/bin/../../../../lib/clang/19/include/__clang_hip_cmath.h:250:19: note: candidate function
  250 | __DEF_FUN1(float, sqrt)
      |                   ^
1 error generated when compiling for gfx906.

This affects other functions from cmath (sqrt/cbrt/hypot/isinf). Using sqrtl works, but this is not a solution for a templated code, and there is no functions like isinfl.

@github-actions github-actions bot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Dec 7, 2024
@philnik777 philnik777 added clang:headers Headers provided by Clang, e.g. for intrinsics and removed libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. labels Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:headers Headers provided by Clang, e.g. for intrinsics
Projects
None yet
Development

No branches or pull requests

2 participants