[FEA]: Improve Environment Diagnostic
- Dominant language
- C++
- Stars
- 2.5k
- Forks
- 486
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 295
Description
### Is this a duplicate?
- [x] I confirmed there appear to be no [duplicate issues](https://github.com/NVIDIA/cccl/issues) for this request and that I agree to the [Code of Conduct](CODE_OF_CONDUCT.md)
### 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 https://github.com/NVIDIA/cccl/pull/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:
```c++
struct get_tag_t { // target tag
template EnvT>
constexpr auto operator()(const EnvT &env) const noexcept {
return env.query(*this);
}
};
get_tag_t get_tag;
template
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) {
// So we are only able to validate return type for when we know tag is there
static_assert(std::is_same_v>);
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 instead
```
### Describe 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` 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::prop` extended to advertise the list of tags in supports
- `cuda::std::execution::env` extended to concatenate the list of tags that underlying envionments support and advertises it
- `cuda::stream_ref` and 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::DeviceReduce` doesn't require env path to answer any specific queries
- `cub::DeviceReduce` static asserts that advertised tags return correct values (`cuda::get_stream` returns proper stream etc.)
- `cub::DeviceReduce` requires object to answer at least one of the required queries (`cuda::get_stream` etc.)
- verification helper is implemented
- `auto safe_env = cuda::valid_env{env}` (name is tbd) overrides the set of tags that env extension advertises
- implementations static assert that env answers queries advertised in the `valid_env` list
### Describe alternatives you've considered
_No response_
### Additional context
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.