Skip to content

Tuning policy selectors should use the compute capability instead of cuda::arch_id #7654

Closed

Description

@bernhardmgruber

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:

Activity

  1. davebayer commented on Feb 12, 2026

    @davebayer
    Contributor

    I think we could combine switch and if in this case and do something like:

    switch (arch)
    {
      // handle all architectures that need specific tunings
      case arch_id::sm_90:
      case arch_id::sm_90a:
         return some_value;
      case arch_id::sm_100:
      case arch_id::sm_103:
      case arch_id::sm_103a:
         return some_other_value;
      case arch_id::sm_100a:
         return b200_specific_value;
    
      // handle the rest of the architectures by their compute capability
      default:
         if (cuda::compute_capability{arch} < cuda::compute_capability{8, 0})
         {
           return pre_ampere_default_value;
         }
         else
         {
           return post_ampere_default_value;
         }
    }
  2. bernhardmgruber commented on Feb 12, 2026

    @bernhardmgruber
    ContributorAuthor

    I think we could combine switch and if in this case and do something like:

    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 wherever compute_capability{10, 6} would go (construction of CC from arch_id discards the a)

  3. davebayer commented on Feb 12, 2026

    @davebayer
    Contributor

    We could also allow the policy selector to be invocable with arch_id or compute_capability. arch_id would be the prefered path. It could look something like:

    // 1. doesn't care about arch_id
    struct my_policy_selector_1
    {
      value_type operator()(cuda::compute_capability cc) const
      {
        return (cc > 90_cc) ? a : b;
      }
    };
    
    // 2. cares about arch_id
    struct my_policy_selector_1
    {
      value_type operator()(cuda::arch_id arch) const
      {
        switch (arch)
        {
          // ...
        }
      }
    };
    
    namespace cuda
    {
    template <class PolSel>
    auto get_policy(const PolSel& policy_selector, arch_id arch)
    {
      if constexpr (/*policy_selector-is-invocable-with-arch_id*/)
      {
        return policy_selector(arch);
      }
      else
      {
        return policy_selector(compute_capability{arch});
      }
    }

    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:

    struct my_policy_selector_1
    {
      value_type operator()(cuda::compute_capability cc) const
      {
        return (cc > 90_cc) ? a : b;
      }
    
      value_type operator()(cuda::arch_id arch) const
      {
        switch (arch)
        {
          case cuda::arch_id::sm_100a:
            return b200_specific_value;
          default:
            return (*this)(cuda::compute_capability{arch});
        }
      }
    };
  4. bernhardmgruber commented on Feb 12, 2026

    @bernhardmgruber
    ContributorAuthor

    The last suggestion is brilliant! Because it allows us to ship a design that uses compute_capability now while leaving the door open to add arch_id overloads later, if we ever need them. Internally, we can always change from passing around CCs to arch_ids without breaking anybody. But at the API level, we can detect whether the policy has an overload with an arch_id and 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_id in all tuning APIs and dispatching logic to CC.

  5. jrhemstad commented on Feb 12, 2026

    @jrhemstad
    Collaborator

    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/

  6. bernhardmgruber commented on Feb 12, 2026

    @bernhardmgruber
    ContributorAuthor

    Question: are we taking into account that beyond architecture specific features (smXXa) there are also architecture family features (smXXf)?

    cuda::arch_id does 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 for sm100f vs. sm100, then we need a new kind of type to pass to a policy selector. it may be arch_id if 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.

  7. bernhardmgruber commented on Feb 13, 2026

    @bernhardmgruber
    ContributorAuthor

    I asked @ahendriksen whether he sees a need for distinguishing sm100 and sm100a and he doesn't think so, since both kernels would be running on the same hardware.

  8. davebayer commented on Feb 13, 2026

    @davebayer
    Contributor

    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 :)

  9. fbusato commented on Feb 13, 2026

    @fbusato
    Contributor

    I asked @ahendriksen whether he sees a need for distinguishing sm100 and sm100a and he doesn't think so, since both kernels would be running on the same hardware.

    yes, makes no sense to tune for sm_XYZa/f if we support all sm_XYZ. They only define compatibility classes. We added a few examples in the CUDA prog guide.

  10. bernhardmgruber commented on May 5, 2026

    @bernhardmgruber
    ContributorAuthor

    @davebayer did the bulk of the work already with #8728, but he says some things are left.

  11. removed their assignment
    on May 5, 2026
  12. linked a pull request that will close this issue[cub] Rename remaining `arch` to `cc` #8860on May 11, 2026
  13. moved this from Todo to In Progress in CCCLon May 11, 2026
  14. linked a pull request that will close this issue[cub] Simplify arch dispatch #8861on May 11, 2026
  15. moved this from In Progress to Done in CCCLon May 11, 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