NVIDIA / cccl

CUDA Core Compute Libraries
Other
1.1k stars 128 forks source link

Add `cuda::std::variant`, `cuda::std::visit`, and `cuda::std::monostate` #981

Closed aschaffer closed 8 months ago

aschaffer commented 3 years ago

It would be helpful to have discriminated union functionality, equivalent to C++17 standard std::variant, std::visit, std::monostate, but available in device code.

See a nice summary of that functionality, for example, in "C++17, The Complete Guide", by N. Josuttis, 2019, Chapter 16.

maxpkatz commented 3 years ago

@brycelelbach I second the request for std::variant and friends in device code, or equivalent functionality with a similar API. This comes up commonly in some of the DOE multiphysics simulation codes where they want to represent multiple variants of some physics, such as an equation of state or radiation opacity for different materials in a simulation domain. singularity-eos and singularity-opac are examples from Los Alamos National Lab that use this today, and the ECP ExaStar project would use it for a similar approach if it were available. This also comes up in the context of having multiple kinds of solvers, for example variants on ODE solvers or root finding routines, or picking higher or lower resolution versions of a given algorithm.

brycelelbach commented 3 years ago

Tentatively scheduled for 2.1.0, but don't be surprised if that gets pushed back.

ericniebler commented 1 year ago

@griwes Are you working on a cuda::variant? Can I assign this to you?

griwes commented 1 year ago

I'm going to do that myself for this and optional.

mhoemmen commented 1 year ago

I'm interested in both variant and optional.

griwes commented 1 year ago

<optional> is now up for review in NVIDIA/libcudacxx#437.

mhoemmen commented 1 year ago

The Kokkos project is also interested in cuda::std::variant: https://github.com/kokkos/kokkos/issues/5652

ajpowelsnl commented 8 months ago

Hi @mhoemmen - HNY! Do we have a cuda::std::variant merged 😄

mhoemmen commented 7 months ago

@ajpowelsnl Greetings! : - D

Do we have a cuda::std::variant merged

Yes, indeed! libcu++ has a cuda::std::variant.

https://github.com/NVIDIA/cccl/blob/main/libcudacxx/include/cuda/std/variant