Repository navigation
Description
Is this a duplicate?
- I confirmed there appear to be no duplicate issues for this request and that I agree to the Code of Conduct
Area
libcu++
Is your feature request related to a problem? Please describe.
New environment API in CUB has to support open set of tags. This approach leads to silent issues, like this one #7266. When user passes a value associated with a given tag, they expect this value to have an effect. But if there's an issue somewhere on the env implementation side, incorrect query is silently ignored. For instance:
struct get_tag_t { // target tag
template <queriable_with<get_tag_t> EnvT>
constexpr auto operator()(const EnvT &env) const noexcept {
return env.query(*this);
}
};
get_tag_t get_tag;
template <class EnvT>
void api(EnvT env) {
// We don't know if env should answer a query or not here, because we have defaults
if constexpr (std::is_invocable_v<get_tag_t, EnvT>) {
// So we are only able to validate return type for when we know tag is there
static_assert(std::is_same_v<int, std::invoke_result_t<get_tag_t, EnvT>>);
int value = get_tag(env);
std::cout << "value: " << value << std::endl;
}
else {
std::cout << "default: " << 42 << std::endl;
}
}
cuda::std::execution::prop env{get_tag, 24};
api(env); // OK - prints 24
struct custom_env_t {
int query(/* forgot const */ get_tag_t &) const { return 84; }
};
// user expects `api` to consume 84
custom_env_t custom_env;
api(custom_env); // ERROR - default value of 42 is used insteadDescribe the solution you'd like
We have to improve diagnostics on the API side. To achieve that, we'd like to check if the environment is valid. @ericniebler suggested to add a query that returns the list of all the tags that a given environment holds. With that query, we can implement a concept like valid_env<EnvT> that makes sure that we can query all the tags in the returned list on a given env and provide a proper compile-time error to the user otherwise.
This issue can be closed when:
- environments extended
- env extension that advertises the list of tags is designed
cuda::std::execution::propextended to advertise the list of tags in supportscuda::std::execution::envextended to concatenate the list of tags that underlying envionments support and advertises itcuda::stream_refand memory resources are extended to advertise the list of tags in supports
- processing of env and objects is split in
cub::DeviceReduce- environment extension is used to distringuish env (i.e.
cuda::stream_ref,cuda::std::execution::prop) from objects (cudaStream). cub::DeviceReducedoesn't require env path to answer any specific queriescub::DeviceReducestatic asserts that advertised tags return correct values (cuda::get_streamreturns proper stream etc.)cub::DeviceReducerequires object to answer at least one of the required queries (cuda::get_streametc.)
- environment extension is used to distringuish env (i.e.
- verification helper is implemented
auto safe_env = cuda::valid_env<cuda::get_stream_t, cuda::get_memory_resource_t>{env}(name is tbd) overrides the set of tags that env extension advertises- implementations static assert that env answers queries advertised in the
valid_envlist
Describe alternatives you've considered
No response
Additional context
No response
Activity
gevtushenko commentedon Sep 11, 2026
Might be related https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3482r1.html#stdexecutionproperty_key_list