cccl icon indicating copy to clipboard operation
cccl copied to clipboard

[FEA]: Use `CUB_IF_CONSTEXPR` in checks on compile-time constants

Open Nyrio opened this issue 1 year ago • 2 comments

Is this a duplicate?

  • [X] I confirmed there appear to be no duplicate issues for this request and that I agree to the Code of Conduct

Area

CUB

Is your feature request related to a problem? Please describe.

There are many checks in the codebase that only depend on compile-time parameters.

A few examples: https://github.com/NVIDIA/cccl/blob/7c53bbd8991effb05707583474c3b59756812678/cub/cub/device/dispatch/dispatch_radix_sort.cuh#L659 https://github.com/NVIDIA/cccl/blob/7c53bbd8991effb05707583474c3b59756812678/cub/cub/agent/agent_merge_sort.cuh#L178 https://github.com/NVIDIA/cccl/blob/7c53bbd8991effb05707583474c3b59756812678/cub/cub/agent/agent_scan.cuh#L357

Describe the solution you'd like

When compiling with C++17 or newer, if constexpr can be used to specify that the branch should be evaluated at compile time. The cub macro CUB_IF_CONSTEXPR uses if constexpr when supported.

Describe alternatives you've considered

No response

Additional context

No response

Nyrio avatar Mar 22 '24 12:03 Nyrio

Note, we should also move this to a central place inside the __cccl folder inside libcu++ as this is a generic facility that should be reused throughout the whole project.

We could even consider expanding support for clang / msvc or other compiler that allow using this feature in earlier standard modes

miscco avatar Mar 22 '24 12:03 miscco

I have opened #1562 to consolidate our if constexpr handling

miscco avatar Mar 22 '24 13:03 miscco