libcudacxx icon indicating copy to clipboard operation
libcudacxx copied to clipboard

Update `cuda::std::invoke_result` to emit diagnostic when attempting to query return type of extended lambda in host code

Open jrhemstad opened this issue 2 years ago • 1 comments

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.

jrhemstad avatar May 13 '22 14:05 jrhemstad

I'd like to address this for the following issue. If there are no objections, I assign it to myself.

gevtushenko avatar Jun 07 '22 14:06 gevtushenko

Closed by https://github.com/NVIDIA/libcudacxx/pull/284

jrhemstad avatar Dec 06 '22 17:12 jrhemstad