libcudacxx icon indicating copy to clipboard operation
libcudacxx copied to clipboard

Add support for cmath

Open mnicely opened this issue 4 years ago • 3 comments
trafficstars

We should add support for cmath https://en.cppreference.com/w/cpp/header/cmath

mnicely avatar Jun 15 '21 12:06 mnicely

I would like to do this after the NVC++ rework. Currently we have the bare minimum exposed for complex.

wmaxey avatar Jun 15 '21 22:06 wmaxey

We'll need to coordinate with the CUDA math libraries team. I'll tentatively set it as a goal for 2.2.0, which would be early 2022.

brycelelbach avatar Jun 16 '21 23:06 brycelelbach

Usage of (present) cmath functions in Windows nvcc 11.2 causes error. nvcc -std=c++17 cmath_test.cu --expt-relaxed-constexpr

cmath_test.cu(4): error: calling a __host__ function("exp<int, (int)0> ") from a __global__ function("kernel") is not allowed
cmath_test.cu(4): error: identifier "exp<int, (int)0> " is undefined in device code

Code:

#include <cuda/std/cmath>
__global__ void kernel() {
    cuda::std::exp(int{0});
}

int main() {
  kernel<<<1,1>>>();
}

Right now, libcudacxx cmath uses std cmath. in Linux, functions in gnu std cmath are constexpr. In MSVC cmath, it's not.

karthikeyann avatar Oct 29 '21 13:10 karthikeyann