Skip to content

[BUG]: logb() for fp16/bf16 is used by libc++, but is not defined when compiled with clang & libc++ #2743

Closed

Description

@Artem-B

Is this a duplicate?

Type of Bug

Compile-time Error

Component

libcu++

Describe the bug

Attempt to perform division on cuda::std::complex<__half> or __nv_bfloat16 fails to compile, because there's no specialized logb() function, which results in ambiguous overload resolution between logb(float) and logb(double).

In file included from /opt/compiler-explorer/cuda/12.6.1//include/cuda/std/cmath:25:
/opt/compiler-explorer/cuda/12.6.1//include/cuda/std/detail/libcxx/include/cmath:835:10: error: call to 'logb' is ambiguous
  835 |   return ::logb(__x);
      |          ^~~~~~
/opt/compiler-explorer/cuda/12.6.1//include/cuda/std/detail/libcxx/include/complex:639:30: note: in instantiation of function template specialization 'cuda::std::__constexpr_logb<__half>' requested here
  639 |   _Tp __logbw  = _CUDA_VSTD::__constexpr_logb(
      |                              ^
/opt/compiler-explorer/cuda/12.6.1//include/cuda/std/detail/libcxx/include/complex:436:17: note: in instantiation of function template specialization 'cuda::std::operator/<__half>' requested here
  436 |   __lhs = __lhs / complex<_Tp>(__rhs.real(), __rhs.imag());
      |                 ^
/opt/compiler-explorer/cuda/12.6.1//include/cuda/std/detail/libcxx/include/complex:746:7: note: in instantiation of function template specialization 'cuda::std::operator/=<__half, __half>' requested here
  746 |   __t /= __y;
      |       ^
<source>:19:3: note: in instantiation of function template specialization 'test<__half>' requested here
   19 |   test<__half>();
      |   ^
/opt/compiler-explorer/clang-trunk-20241107/lib/clang/20/include/cuda_wrappers/cmath:35:37: note: candidate function
   35 | __attribute__((device)) long double logb(long double);
      |                                     ^
/opt/compiler-explorer/cuda/12.6.1//include/crt/math_functions.hpp:587:31: note: candidate function
  587 | __MATH_FUNCTIONS_DECL__ float logb(const float a)
      |                               ^
/opt/compiler-explorer/clang-trunk-20241107/lib/clang/20/include/__clang_cuda_math.h:184:19: note: candidate function
  184 | __DEVICE__ double logb(double __a) { return __nv_logb(__a); }
      |                   ^

How to Reproduce

See https://godbolt.org/z/zcKdxvsvx

Expected behavior

Division on cuda::std::complex<half> and cuda::std::complex<__nv_bfloat16> compiles and works.

Reproduction link

https://godbolt.org/z/zcKdxvsvx

Operating System

No response

nvidia-smi output

No response

NVCC version

No response

Activity

  1. linked a pull request that will close this issueStart reworking our math functions #2749on Nov 8, 2024
  2. miscco commented on Nov 8, 2024

    @miscco
    Contributor

    I found that a ton of our cmath implementation has issues.

    I started with log and fmin

  3. added 20 commits that reference this issue on Nov 8, 2024
  4. moved this from Todo to Done in CCCLon Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions