ceil_div.h 479 B

1234567891011121314151617181920212223
  1. #pragma once
  2. #include <c10/macros/Macros.h>
  3. namespace at {
  4. /**
  5. Computes ceil(a / b)
  6. */
  7. template <typename T, typename = std::enable_if_t<std::is_integral<T>::value>>
  8. C10_ALWAYS_INLINE C10_HOST_DEVICE T ceil_div(T a, T b) {
  9. return (a + b - 1) / b;
  10. }
  11. /**
  12. Computes ceil(a / b) * b; i.e., rounds up `a` to the next highest
  13. multiple of b
  14. */
  15. template <typename T>
  16. C10_ALWAYS_INLINE C10_HOST_DEVICE T round_up(T a, T b) {
  17. return ceil_div(a, b) * b;
  18. }
  19. } // namespace at