Repository navigation
cub, libcu++: advertised properties + their checking in DeviceReduce. - #11577
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. Summary
Change: Feature Merge Risk:
|
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: NVIDIA/cccl/.coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 7ba1e3ba-a3d4-47cc-814e-13f61de96c7d
📒 Files selected for processing (10)
cub/benchmarks/bench/reduce/by_key.cucub/cub/detail/env_dispatch.cuhcub/test/catch2_test_device_reduce_env_api.cudocs/cub/environment.rstdocs/libcudacxx/extended_api/memory_resource/resource_utilities.rstlibcudacxx/include/cuda/__memory_resource/any_resource.hlibcudacxx/include/cuda/__memory_resource/get_memory_resource.hlibcudacxx/include/cuda/__memory_resource/memory_resource_base.hlibcudacxx/test/libcudacxx/cuda/execution/property_query.pass.cpplibcudacxx/test/libcudacxx/cuda/memory_resource/get_memory_resource/get_memory_resource.pass.cpp
🚧 Files skipped from review as they are similar to previous changes (3)
- docs/libcudacxx/extended_api/memory_resource/resource_utilities.rst
- docs/cub/environment.rst
- cub/cub/detail/env_dispatch.cuh
Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟠 Major · important: Restrict property_keys to asynchronous resource references. · any_resource.h:732-740
libcudacxx/include/cuda/__memory_resource/any_resource.h:732-740
🎯 Functional Correctness | 🟠 Major | ⚡ Quick winimportant: Restrict
property_keysto asynchronous resource references.
synchronous_resource_refaliasesbasic_resource_ref<_ResourceKind::_Synchronous, ...>, butbasic_resource_refunconditionally advertisesget_memory_resource_t. The PR's ownget_memory_resource.pass.cpp:70requiressynchronous_resource_ref<>to have noproperty_keys, so this change makes that test fail to compile. Expose the metadata andquery(get_memory_resource_t)only for_ResourceKind::_Asynchronous.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: NVIDIA/cccl/.coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 93e82c11-2ad7-46ae-bb87-02c3b523cb6e
📒 Files selected for processing (3)
cub/cub/detail/env_dispatch.cuhcub/test/catch2_test_memory_resources.hlibcudacxx/include/cuda/__execution/checked_env.h
Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review.
This comment has been minimized.
This comment has been minimized.
| reduction_op_t{}, | ||
| static_cast<OffsetT>(elements), | ||
| alloc); | ||
| cuda::mr::resource_ref<>{alloc}); |
There was a problem hiding this comment.
Q: Why do we need to change "user side" code?
There was a problem hiding this comment.
This is because the nature of get_memory_resource is... extremely weird. For some reason we decided that it should accept owning memory resources (#8404). But owning memory resources cannot possibly follow the env-like path through a query, because the env-like path is const qualified, and dealing with const-qualified memory resources is not very useful; so get_memory_resource got a non-const qualified overload to catch these... ...but that will never pass the env-like validation, because the env-like path REQUIRES environments to be const.
That change also led to some of the pstl code doing... const casts casting the constness of a reference away. It's a big mess. If at all possible, I'd like to remove the code added by the previous PR entirely, because the ownership semantics get very tangled very quickly.
For the code specifically here in the benchmark, cub_bench_env already does equivalent wrapping.
There are changes I can make in the general mechanism introduced in this PR to make this change unnecessary, buuuuuut I do not actually know if those are desired at all. I can special case the object matching a memory resource concept and in that case just accept it - but that would further blur the lines here I think; if we want to say that this is the environment based overload, we really should actually accept only environments, and not environments + some random assortment of other types that have explicit carveouts in the protocol.
There was a problem hiding this comment.
So, the PR here can introduce an API break?
There was a problem hiding this comment.
It does, but the cases where it does, the implementation is actually just ignoring the argument, so turning that into a compiler error is arguably a fix.
| static_assert(::cuda::std::__is_callable_v<::cuda::get_stream_t, const EnvT&> | ||
| || ::cuda::std::__is_callable_v<::cuda::mr::get_memory_resource_t, const EnvT&>, | ||
| "An object passed as a DeviceReduce environment must provide a stream or a memory resource."); |
There was a problem hiding this comment.
Remark: this is fine as a first step. We also have functions taking an env but also a temporary storage pointer and size&, so for those we would only check for it being a stream. Nothing needs to be done about this in this PR.
Co-authored-by: Bernhard Manfred Gruber <[email protected]>
This comment has been minimized.
This comment has been minimized.
|
/ok to test 7ca6d9e |
This comment has been minimized.
This comment has been minimized.
|
/ok to test 968ed9d |
This comment has been minimized.
This comment has been minimized.
|
This PR doesn't have the means to resolve all cases similar to the snippet #7797; there can be arbitrary misspelling. I believe providing a tool to help avoid them is the goal here. I believe the CPO callable vs query callable issue has now been resolved, narrowly within the mechanisms of this PR. @gonidelis please re-review. |
|
/ok to test 37555bb |
This comment has been minimized.
This comment has been minimized.
|
fix the conflicts otherwise lgtm |
|
/ok to test e75c885 |
This comment has been minimized.
This comment has been minimized.
|
/ok to test 319860b |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
|
/ok to test e91ff91 |
|
/ok to test 7bdccf0 |
🥳 CI Workflow Results🟩 Finished in 1h 24m: Pass: 100%/342 | Total: 3d 11h | Max: 1h 24m | Hits: 96%/782370See results here. |
Description
Resolves #7797.
An incorrectly implemented environment query can silently select a default in CUB. This PR lets environments advertise the customizations they provide and makes
cub::DeviceReducediagnose broken advertised queries.cuda::execution::property_keys_t<T>obtains a type's advertised query list. User-defined types supply that list throughT::property_keys, usingcuda::execution::property_key_list<...>. An entryproperty_query<Key, Args...>describes a CPO invocation with a const environment and the specified additional argument types; a bareKeyis shorthand for a nullary invocation.The advertisement is a nested typedef, so discovering it does not depend on dispatching another query. Standard-library types keep their metadata under a reserved implementation name, accessed through
property_keys_t, to allow a future standard property interface without a source-compatibility conflict.Metadata is supplied by
cuda::std::execution::{prop, env},cuda::stream_ref,cuda::mr::memory_resource_base, and asynchronous resource references.envcombines and deduplicates its components' advertisements while retaining first-matching-member lookup. Validation checks individual advertised contributions so another provider cannot hide a broken advertisement, including in nested and inherited environments.Validation checks the CPO invocation and instantiates its body without executing the query. Each advertised expression is checked separately so the failing query appears in the instantiation trace. Automatic CUB validation is limited to
DeviceReduce: environments with metadata have their advertised customizations checked, while objects without metadata must support a stream or memory-resource query. Working unadvertised customizations remain usable, and unavailable queries retain their defaults.cuda::checked_env<Queries...>(env)explicitly validates selected CPO invocations and returns a member-query-forwarding adaptor. It can also add metadata to a third-party environment or replace an existing advertised list.A requested invocation may use the CPO's default when the input does not advertise that customization. If the input advertises a requested customization, its member must be present. The adaptor advertises only the requested expressions backed by supplied members; default-only invocations are checked without being advertised or manufacturing a member. This lets a checked default compose with other environments without shadowing a later provider. Supported member queries outside the checked list remain forwarded.
Checklist