libcudacxx
libcudacxx copied to clipboard
Update `cuda::std::invoke_result` to emit diagnostic when attempting to query return type of extended lambda in host code
https://github.com/NVIDIA/thrust/issues/1688 made me think we should put this check directly into cuda::std::invoke_result
.
#if defined(__NVCC__) && defined(__CUDACC_EXTENDED_LAMBDA__) && !defined(__CUDA_ARCH__)
static_assert(!__nv_is_extended_device_lambda_closure_type(F),
"Attempt to use an extended __device__ lambda in a context "
"that requires querying its return type. Use a named "
"function object or a __host__ __device__ lambda instead.");
)
#endif
This may be slightly controversial to put something in the cuda::std
layer that is so CUDA (and nvcc) specific like this, but I don't see how it would harm anyone doing the right thing or not using nvcc.
The fact that it would help eliminate a lot of potential bugs outweighs any of the misgivings I'd have about adding this check.
I'd like to address this for the following issue. If there are no objections, I assign it to myself.
Closed by https://github.com/NVIDIA/libcudacxx/pull/284