libcudacxx icon indicating copy to clipboard operation
libcudacxx copied to clipboard

C++20 std::numbers?

Open benchislett opened this issue 3 years ago • 1 comments

Hi! :wave:

Is there any roadmap describing planned support for newer, smaller headers? I want to use std::numbers in my CUDA application, but NVCC doesn't seem to support it (godbolt). Will I have to wait for NVCC to support this natively, or could such an implementation also live in libcu++?

I would be more than happy to implement the numbers header if so.

benchislett avatar Feb 20 '21 04:02 benchislett

Hi @benchislett! Good question!

For using std::numbers: It should be as simple as using a host compiler with the header and an NVCC that supports C++20 and concepts (this does not yet exist). Since it's only made up of constexpr variable templates it should work out of the box on both host and device.

For using cuda::std::numbers: I believe when we next pull from libcxx and update our local copy we will get it for free. I see that it's already implemented here: https://github.com/llvm/llvm-project/blob/main/libcxx/include/numbers

It's likely that we'll also get other language features as well with that drop, it would just be a matter of exposing them under cuda/std if applicable.

While the header itself is small, NVCC does not yet support C++20 concepts and it would be unfortunately unusable until then. Luckily, I think this header could be implemented slightly differently and we could then make it a C++14 backport. It should be implementable with variable templates alone.

Once the LLVM pull lands it would be a simple PR to add it under cuda/std along with tests and necessary adjustments to namespaces. It's something we would likely eventually get around to if we have the bandwidth.

I hope that answers your question, if you're interested in helping we would love to see a PR. :)

wmaxey avatar Feb 20 '21 05:02 wmaxey