mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Consolidate multiple implementations of divup/div_up/div_ceil.
This commit is contained in:
@@ -1341,6 +1341,19 @@ double ceil(const double &x) { return ::ceil(x); }
|
||||
#endif
|
||||
|
||||
|
||||
// Integer division with rounding up.
|
||||
// T is assumed to be an integer type with a>=0, and b>0
|
||||
template<typename T>
|
||||
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE EIGEN_CONSTEXPR
|
||||
T div_ceil(const T &a, const T &b)
|
||||
{
|
||||
EIGEN_STATIC_ASSERT((NumTraits<T>::IsInteger), THIS FUNCTION IS FOR INTEGER TYPES)
|
||||
eigen_assert(a >= 0);
|
||||
eigen_assert(b > 0);
|
||||
// Note: This form is used because it cannot overflow.
|
||||
return a == 0 ? 0 : (a - 1) / b + 1;
|
||||
}
|
||||
|
||||
/** Log base 2 for 32 bits positive integers.
|
||||
* Conveniently returns 0 for x==0. */
|
||||
inline int log2(int x)
|
||||
|
||||
@@ -90,8 +90,6 @@ class gemm_class {
|
||||
const Index a_stride, b_stride;
|
||||
const Index a_off, b_off;
|
||||
|
||||
static EIGEN_ALWAYS_INLINE constexpr int div_up(int a, int b) { return a == 0 ? 0 : (a - 1) / b + 1; }
|
||||
|
||||
EIGEN_ALWAYS_INLINE void prefetch_a(const Scalar *a_addr) {
|
||||
_mm_prefetch((char *)(a_prefetch_size + a_addr - a_shift), _MM_HINT_T0);
|
||||
}
|
||||
@@ -479,7 +477,7 @@ class gemm_class {
|
||||
*
|
||||
* const Scalar *cox = (idx == 0) ? co1 : co2;
|
||||
*
|
||||
* const int um_vecs = div_up(a_unroll, nelems_in_cache_line);
|
||||
* const int um_vecs = numext::div_ceil(a_unroll, nelems_in_cache_line);
|
||||
* scale_load_c<0, um_vecs, idx, a_unroll>(cox, alpha_reg);
|
||||
* write_c<0, um_vecs, idx, a_unroll>(cox);
|
||||
*
|
||||
@@ -498,7 +496,7 @@ class gemm_class {
|
||||
EIGEN_ALWAYS_INLINE void c_update_1count(Scalar *&cox) {
|
||||
if (pow >= 4) cox += ldc;
|
||||
|
||||
const int um_vecs = div_up(a_unroll, nelems_in_cache_line);
|
||||
const int um_vecs = numext::div_ceil(a_unroll, nelems_in_cache_line);
|
||||
auto &alpha_reg = zmm[alpha_load_reg];
|
||||
|
||||
scale_load_c<0, um_vecs, idx, a_unroll>(cox, alpha_reg);
|
||||
@@ -644,7 +642,7 @@ class gemm_class {
|
||||
template <int uk, int max_b_unroll, int a_unroll, int b_unroll, bool ktail, bool fetch_x, bool c_fetch, bool no_a_preload = false>
|
||||
EIGEN_ALWAYS_INLINE void innerkernel_1uk(const Scalar *&aa, const Scalar *const &ao, const Scalar *const &bo,
|
||||
Scalar *&co2, int &fetchA_idx, int &fetchB_idx) {
|
||||
const int um_vecs = div_up(a_unroll, nelems_in_cache_line);
|
||||
const int um_vecs = numext::div_ceil(a_unroll, nelems_in_cache_line);
|
||||
|
||||
if (max_b_unroll >= 1)
|
||||
innerkernel_1pow<uk, 1, 0, um_vecs, b_unroll, ktail, fetch_x, c_fetch>(aa, ao, bo, co2, fetchA_idx, fetchB_idx);
|
||||
@@ -729,7 +727,7 @@ class gemm_class {
|
||||
|
||||
template <int a_unroll, int b_unroll, int max_b_unroll>
|
||||
EIGEN_ALWAYS_INLINE void kloop(const Scalar *&aa, const Scalar *&ao, const Scalar *&bo, Scalar *&co1, Scalar *&co2) {
|
||||
const int um_vecs = div_up(a_unroll, nelems_in_cache_line);
|
||||
const int um_vecs = numext::div_ceil(a_unroll, nelems_in_cache_line);
|
||||
if (!use_less_a_regs && k > 1)
|
||||
a_loads<0, 2, 0, um_vecs, a_unroll>(ao);
|
||||
else
|
||||
|
||||
@@ -422,15 +422,6 @@ template<typename T> EIGEN_STRONG_INLINE void swap(T &a, T &b) { std::swap(a,b);
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
// Integer division with rounding up.
|
||||
// T is assumed to be an integer type with a>=0, and b>0
|
||||
template<typename T>
|
||||
EIGEN_DEVICE_FUNC
|
||||
T div_ceil(const T &a, const T &b)
|
||||
{
|
||||
return (a+b-1) / b;
|
||||
}
|
||||
|
||||
// Handle integer comparisons of different signedness.
|
||||
template <typename X, typename Y, bool XIsInteger = NumTraits<X>::IsInteger, bool XIsSigned = NumTraits<X>::IsSigned,
|
||||
bool YIsInteger = NumTraits<Y>::IsInteger, bool YIsSigned = NumTraits<Y>::IsSigned>
|
||||
|
||||
Reference in New Issue
Block a user