xref: /aosp_15_r20/external/pytorch/aten/src/ATen/ceil_div.h (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1 #pragma once
2 #include <c10/macros/Macros.h>
3 #include <type_traits>
4 
5 namespace at {
6 
7 /**
8    Computes ceil(a / b)
9 */
10 template <typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
ceil_div(T a,T b)11 C10_ALWAYS_INLINE C10_HOST_DEVICE T ceil_div(T a, T b) {
12   return (a + b - 1) / b;
13 }
14 
15 /**
16    Computes ceil(a / b) * b; i.e., rounds up `a` to the next highest
17    multiple of b
18 */
19 template <typename T>
round_up(T a,T b)20 C10_ALWAYS_INLINE C10_HOST_DEVICE T round_up(T a, T b) {
21   return ceil_div(a, b) * b;
22 }
23 
24 } // namespace at
25