-
Notifications
You must be signed in to change notification settings - Fork 756
Consider always discarding __device__ lambdas' results #779
Comments
I don't think there's a way to detect that it's a lambda. I'm not sure I understand why result_of doesn't work in this instance? Would decltype work? |
The issue is that Fortunately, we are able to distinguish Agency uses this inside its implementation of |
I'm going to start using this issue to track the various " The issues Jared mentioned above are documented here in the current toolkit documentation. Until we have a better system in place, users should stick with |
Just for completeness, the exact restriction is G.6.2p13:
I've stopped using |
@jaredhoberock said "device lambdas always return int". That can't be true, I have used device lambdas that return non-int before. I guess what Jared means is that |
Correct. The device lambda object is replaced with a placeholder object in host code, and that placeholder's API does not accurately represent the device lambda's actual call signature. |
Not necessarily, no. It's moreso that the return type of the callable (as determined from host code) cannot be relied upon to be correct. |
I just wanted reassurance that if I call a device lambda that returns float from a kernel, it doesn't return int. |
#1650 (comment) has a reproducer for an issue with both |
Thanks to NVIDIA/libcudacxx#284, we will automatically error at compile time in instances where we attempt to query the return type of an extended lambda in a context where that is not supported. |
Use __host__ __device__ lambdas instead of pure __device__ lambdas to avoid problems with their return type. See NVIDIA/thrust#779 (comment) In CUDA 12 one could use cuda::proclaim_return_type from libcu++ instead, but this wont work for earlier CUDA versions. Add -DCUDA_FORCE_CDP1_IF_SUPPORTED to allow the usage of legacy CUDA Dynamic Parallelism
Host functions can't rely on the result of
std::result_of
when it is instantiated with a__device__
lambda.If we have the means to detect their presence at compile time, then one option is to entirely ban them from
bulk_invoke
and friends. A more relaxed policy might be to always interpret their result to bevoid
. That would still allow them to be used, but it would not be possible to return results from them.The text was updated successfully, but these errors were encountered: