Skip to content

Commit 7802f25

Browse files
committed
Only have once source of truth for the backend extraction
1 parent 9555466 commit 7802f25

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

libcudacxx/include/cuda/std/__execution/policy.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,13 @@ struct __execution_policy_base
6060
//! @brief Extracts the execution policy from the stored _Policy
6161
[[nodiscard]] _CCCL_API static constexpr __execution_policy __get_policy() noexcept
6262
{
63-
constexpr uint32_t __policy_mask{0x000000FF};
64-
return __execution_policy{_Policy & __policy_mask};
63+
return __policy_to_execution_policy<_Policy>;
6564
}
6665

6766
//! @brief Extracts the execution backend from the stored _Policy
6867
[[nodiscard]] _CCCL_API static constexpr __execution_backend __get_backend() noexcept
6968
{
70-
constexpr uint32_t __backend_mask{0x0000FF00};
71-
return __execution_backend{(_Policy & __backend_mask) >> 8};
69+
return __policy_to_execution_backend<_Policy>;
7270
}
7371
};
7472

libcudacxx/include/cuda/std/__fwd/execution_policy.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ enum class __execution_policy : uint8_t
3737
__parallel_unsequenced = __execution_policy::__parallel | __execution_policy::__unsequenced,
3838
};
3939

40+
//! @brief Extracts the execution policy from the stored _Policy
41+
template <uint32_t _Policy>
42+
inline constexpr __execution_policy __policy_to_execution_policy = __execution_policy{(_Policy & uint32_t{0x000000FF})};
43+
4044
//! @brief Enumerates the different backends we support
4145
//! @note Not an enum class because a user might specify multiple backends
4246
enum __execution_backend : uint8_t
@@ -56,9 +60,10 @@ enum __execution_backend : uint8_t
5660

5761
//! @brief Extracts the execution backend from the stored _Policy
5862
template <uint32_t _Policy>
59-
inline constexpr __execution_backend __to_backend = __execution_backend{(_Policy & uint32_t{0x0000FF00}) >> 8};
63+
inline constexpr __execution_backend __policy_to_execution_backend =
64+
__execution_backend{(_Policy & uint32_t{0x0000FF00}) >> 8};
6065

61-
template <uint32_t _Policy, __execution_backend _Backend = __to_backend<_Policy>>
66+
template <uint32_t _Policy, __execution_backend _Backend = __policy_to_execution_backend<_Policy>>
6267
struct __execution_policy_base;
6368

6469
_CCCL_END_NAMESPACE_CUDA_STD_EXECUTION

0 commit comments

Comments
 (0)