Skip to content

[FEA]: Improve Environment Diagnostic #7797

Closed

Description

@gevtushenko

Is this a duplicate?

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 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<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::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<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_env list

Describe alternatives you've considered

No response

Additional context

No response

Activity

  1. moved this from Todo to In Progress in CCCLon Sep 15, 2026
  2. moved this from In Progress to In Review in CCCLon Sep 22, 2026
  3. moved this from In Review to In Progress in CCCLon Oct 27, 2026
  4. moved this from In Progress to In Review in CCCLon Nov 17, 2026
  5. moved this from In Review to Done in CCCLon Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions