FZGPUModules 2.0
GPU-accelerated modular compression pipelines
Loading...
Searching...
No Matches
StaticUtils.h
1
9#ifndef FZ_ANS_DIETGPU_UTILS_STATICUTILS_H
10#define FZ_ANS_DIETGPU_UTILS_STATICUTILS_H
11
12#pragma once
13
14#include <cuda.h>
15#ifndef __host__
16#define __host__
17#define __device__
18#endif
19
20namespace fz { namespace ans {
21
22template <typename U, typename V>
23constexpr __host__ __device__ auto divDown(U a, V b) -> decltype(a + b) {
24 return (a / b);
25}
26
27template <typename U, typename V>
28constexpr __host__ __device__ auto divUp(U a, V b) -> decltype(a + b) {
29 return (a + b - 1) / b;
30}
31
32template <typename U, typename V>
33constexpr __host__ __device__ auto roundDown(U a, V b) -> decltype(a + b) {
34 return divDown(a, b) * b;
35}
36
37template <typename U, typename V>
38constexpr __host__ __device__ auto roundUp(U a, V b) -> decltype(a + b) {
39 return divUp(a, b) * b;
40}
41
42template <typename T>
43constexpr __host__ __device__ bool isEvenDivisor(T a, T b) {
44 return (a % b == 0) && ((a / b) >= 1);
45}
46
47template <class T>
48constexpr __host__ __device__ T pow(T n, T power) {
49 return (power > 0 ? n * pow(n, power - 1) : 1);
50}
51
52template <class T>
53constexpr __host__ __device__ T pow2(T n) {
54 return pow(2, (T)n);
55}
56
57template <typename T>
58constexpr __host__ __device__ bool isPowerOf2(T v) {
59 return (v && !(v & (v - 1)));
60}
61
62inline __host__ __device__ bool isPointerAligned(const void* p, int align) {
63 return reinterpret_cast<uintptr_t>(p) % align == 0;
64}
65
66template <int Align>
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;
71}
72
73}} // namespace fz::ans
74
75#endif // FZ_ANS_DIETGPU_UTILS_STATICUTILS_H
Definition dag.h:24