9#ifndef FZ_ANS_DIETGPU_UTILS_STATICUTILS_H
10#define FZ_ANS_DIETGPU_UTILS_STATICUTILS_H
20namespace fz {
namespace ans {
22template <
typename U,
typename V>
23constexpr __host__ __device__
auto divDown(U a, V b) ->
decltype(a + b) {
27template <
typename U,
typename V>
28constexpr __host__ __device__
auto divUp(U a, V b) ->
decltype(a + b) {
29 return (a + b - 1) / b;
32template <
typename U,
typename V>
33constexpr __host__ __device__
auto roundDown(U a, V b) ->
decltype(a + b) {
34 return divDown(a, b) * b;
37template <
typename U,
typename V>
38constexpr __host__ __device__
auto roundUp(U a, V b) ->
decltype(a + b) {
39 return divUp(a, b) * b;
43constexpr __host__ __device__
bool isEvenDivisor(T a, T b) {
44 return (a % b == 0) && ((a / b) >= 1);
48constexpr __host__ __device__ T pow(T n, T power) {
49 return (power > 0 ? n * pow(n, power - 1) : 1);
53constexpr __host__ __device__ T pow2(T n) {
58constexpr __host__ __device__
bool isPowerOf2(T v) {
59 return (v && !(v & (v - 1)));
62inline __host__ __device__
bool isPointerAligned(
const void* p,
int align) {
63 return reinterpret_cast<uintptr_t
>(p) % align == 0;
67inline __host__ __device__ uint32_t getAlignmentRoundUp(
const void* p) {
68 static_assert(isPowerOf2(Align),
"");
69 uint32_t diff = uint32_t(uintptr_t(p) & uintptr_t(Align - 1));
70 return diff == 0 ? 0 : uint32_t(Align) - diff;