ceil_div.h 751 B

1234567891011121314151617181920212223242526272829
  1. #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
  2. #pragma once
  3. #include <c10/macros/Macros.h>
  4. #include <type_traits>
  5. namespace at {
  6. /**
  7. Computes ceil(a / b)
  8. */
  9. template <typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
  10. C10_ALWAYS_INLINE C10_HOST_DEVICE T ceil_div(T a, T b) {
  11. return (a + b - 1) / b;
  12. }
  13. /**
  14. Computes ceil(a / b) * b; i.e., rounds up `a` to the next highest
  15. multiple of b
  16. */
  17. template <typename T>
  18. C10_ALWAYS_INLINE C10_HOST_DEVICE T round_up(T a, T b) {
  19. return ceil_div(a, b) * b;
  20. }
  21. } // namespace at
  22. #else
  23. #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
  24. #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)