Repository navigation
Description
We currently specify tunings in the new design like this (from tuning_reduce.cuh:
struct policy_selector {
[[nodiscard]] _CCCL_API constexpr auto operator()(::cuda::arch_id arch) const -> reduce_policy {
if (arch >= ::cuda::arch_id::sm_100)
return {...};
if (arch >= ::cuda::arch_id::sm_60)
return {...};
return {...}; // base case: SM50
}
};My rationale for using arch_id was that it allows us to differentiate arch-specific IDs from non-specific ones. E.g., we could provide a different tuning when we compile for sm100a (B200 only) vs. compiling for sm100 (B200, and whatever sm103 is).
@davebayer pointed out to me a while back that cuda::arch_id was not intended to be comparable, and in fact, comparison should fail to compile. For some reason it worked and that's what I implemented. The logic above is wrong though in the presence of arch-specific ids, since for example sm90a has a higher integral value as sm100, so if we would select a policy for sm90a we would get the sm100 tuning, which is surely wrong. This could be fixed by checking for arch specific ids, but this gets out of hand quickly:
struct policy_selector {
[[nodiscard]] _CCCL_API constexpr auto operator()(::cuda::arch_id arch) const -> reduce_policy {
// what if a future CTK introduces a new arch-specific id? all policy selectors would be broken.
if (arch == ::cuda::arch_id::sm_100a)
// now what? same as sm_100?
if (arch == ::cuda::arch_id::sm_90a)
// now what? same as sm_90?
if (arch >= ::cuda::arch_id::sm_100)
return {...};
if (arch >= ::cuda::arch_id::sm_60)
return {...};
return {...}; // base case: SM50
}
};This is not how I want our users and ourselves to write tunings.
The alternative is to switch from cuda::arch_id to cuda::compute_capability (CC). A CC has the advantage that it is truly an ordered type, so the logic from the first snipped does actually work. But would we loose anything from not being able to provide a tuning to an arch-specific-compiled kernel? Let's imagine we want to use a dedicated set of tuning values if we compile for sm100a exactly, and otherwise something else. We can write that with a compute capability as:
struct policy_selector {
[[nodiscard]] _CCCL_API constexpr auto operator()(::cuda::compute_capability cc) const -> reduce_policy {
if (cc == ::cuda::arch_id::sm_100)
return {...}; // applies to sm100 only
if (cc > ::cuda::arch_id::sm_100)
return {...}; // applies to anything Blackwell+ that is not exactly sm100
...
}
};But what if we would want to use different tunings for sm100a and sm100-without-a? This could make sense if a kernel would use arch-specific instructions if we compile for sm100a and otherwise not, and those would lead to different performance results and thus require different tunings. We would loose the ability to express that. However, we have never written a tuning that would require this.
As a workaround, reduce_policy could optionally contain arch specific values. Because nobody says that the values in reduce_policy would equally make sense for an arch-specific code path. Entirely different values may be used. So reduce_policy, if it ever needs to cover arch-specific tuning values, we could extend it to:
struct reduce_policy {
agent_reduce_policy reduce;
agent_reduce_policy single_tile;
agent_reduce_policy reduce_nondeterministic;
int sm100a_special_value; // only ever looked at when we actually compile for `sm100a`
};The policy selector would always set the value for sm100a_special_value if the compute capability is 10.0 (thus targetting sm100+), but the value would only be used by the kernel if it was compiled arch-specifically. I think this is a worthwhile trade-off to simplify the design.
Is CCCL currently broken? No. All cuda::arch_ids that we currently pass to a policy selector come from sources where they cannot be arch-specific. But they would be broken if we ever used an arch-specific id. And I think that's a strong indication that we should use a different type.
If we would switch from arch_id to compute_capability, the following rough changes would be necessary:
- Add an
__all_compute_capabilities()function like__all_arch_ids()to implementarch_dispatch. -
AddMoved to independent task: Publicly exposeptx_compute_capability(...)likeptx_arch_id(...)and their wrappers on the launcher factoriescub::detail::ptx_compute_capand deprecatecub::PtxVersion#8729 - Change all existing policy_selectors to use a CC instead of an
arch_id.
Activity
davebayer commentedon Feb 12, 2026
I think we could combine
switchandifin this case and do something like:bernhardmgruber commentedon Feb 12, 2026
Hmm. That's a lot more complex than the initial design. I think it may be forward compatible though. If we added a new
sm_106[a]tomorrow, it would take the path for wherevercompute_capability{10, 6}would go (construction of CC from arch_id discards thea)davebayer commentedon Feb 12, 2026
We could also allow the policy selector to be invocable with
arch_idorcompute_capability.arch_idwould be the prefered path. It could look something like:If the tuning depends only on compute capability and we later decide that we want to add an architecture specific tuning, we can just do:
bernhardmgruber commentedon Feb 12, 2026
The last suggestion is brilliant! Because it allows us to ship a design that uses
compute_capabilitynow while leaving the door open to addarch_idoverloads later, if we ever need them. Internally, we can always change from passing around CCs toarch_ids without breaking anybody. But at the API level, we can detect whether the policy has an overload with anarch_idand call it, and otherwise fallback to a CC. So we can always introduce arch-specific handling later without a breaking change.That makes me confident we should move ahead and change the use of
arch_idin all tuning APIs and dispatching logic to CC.jrhemstad commentedon Feb 12, 2026
Question: are we taking into account that beyond architecture specific features (
smXXa) there are also architecture family features (smXXf)?https://developer.nvidia.com/blog/nvidia-blackwell-and-nvidia-cuda-12-9-introduce-family-specific-architecture-features/
bernhardmgruber commentedon Feb 12, 2026
cuda::arch_iddoes not have any support for families. I am aware about them and I think the same reasoning applies. If we want to share a set of tuning values for a family, we can just return this set for multiple different CCs. And if we would want to return a different set of tuning values for whether we compile forsm100fvs.sm100, then we need a new kind of type to pass to a policy selector. it may bearch_idif we extend it to support families. However, I think again that we rarely want to have different tuning values between a family/arch-specific compilation and an ordinary compilation for that SM architecture. So we should continue to optimize the design for the common path.bernhardmgruber commentedon Feb 13, 2026
I asked @ahendriksen whether he sees a need for distinguishing
sm100andsm100aand he doesn't think so, since both kernels would be running on the same hardware.davebayer commentedon Feb 13, 2026
That's great! So we can start with the more simple compute capability based design and add the overloads for specific architectures if ever needed :)
fbusato commentedon Feb 13, 2026
yes, makes no sense to tune for
sm_XYZa/fif we support allsm_XYZ. They only define compatibility classes. We added a few examples in the CUDA prog guide.bernhardmgruber commentedon May 5, 2026
@davebayer did the bulk of the work already with #8728, but he says some things are left.