This repository has been archived by the owner on Mar 21, 2024. It is now read-only.
Emit diagnostic when attempting to use extended device lambda in contexts that require querying the return type #1688
Labels
backend: CUDA
Related to the CUDA backend
compiler: nvcc
Specific to the NVCC compiler.
good first issue
Good for newcomers.
P1: should have
Necessary, but not critical.
release: breaking change
Include in "Breaking Changes" section of release notes.
type: enhancement
New feature or request.
Milestone
It is a very common pitfall of Thrust users to attempt to use a
__device__
lambda with Thrust algorithms or iterators that fails in silent or obscure ways.This is frequently due to the limitation that you cannot reliably query the return type of an extended lambda in host code. Specifically:
This means that any code in Thrust that relies on
std::invoke_result_t
orstd::result_of
or similar in host code will fail with a__device__
lambda, e.g.,thrust/thrust/system/cuda/detail/transform_scan.h
Line 58 in d35f44f
This will frequently fail silently or fail to compile with incredibly obscure compile errors. This is such a nuisance that I avoid
__device__
lambdas all together with Thrust.However, I recently learned that
nvcc
provides intrinsic type traits to query if a type is an extended lambda.This means Thrust can emit a useful diagnostic when a user attempts to use a
__device__
lambda in a situation where that would be problematic (e.g.,std::invoke_result_t
).One easy way to do this in thrust would be to introduce a consistent wrapper for
invoke_result_t
/result_of
that simplystatic_assert
s that the callable is not an extended lambda.There are likely many other useful ways Thrust could use these traits. Deducing (or at least verifying) execution space from the callable comes to mind.
The text was updated successfully, but these errors were encountered: