Fix compile-time error caused by chip static asserts

This commit is contained in:
Antonio Sanchez 2024-01-22 13:19:10 -08:00 committed by Antonio Sánchez
parent 2c6b61c006
commit 2692fb2b71

View File

@ -24,7 +24,7 @@ using Eigen::internal::TiledEvaluation;
// Default assignment that does no use block evaluation or vectorization. // Default assignment that does no use block evaluation or vectorization.
// We assume that default coefficient evaluation is well tested and correct. // We assume that default coefficient evaluation is well tested and correct.
template <typename Dst, typename Expr> template <typename Dst, typename Expr>
static void DefaultAssign(Dst& dst, Expr expr) { void DefaultAssign(Dst& dst, Expr expr) {
using Assign = Eigen::TensorAssignOp<Dst, const Expr>; using Assign = Eigen::TensorAssignOp<Dst, const Expr>;
using Executor = Eigen::internal::TensorExecutor<const Assign, DefaultDevice, using Executor = Eigen::internal::TensorExecutor<const Assign, DefaultDevice,
/*Vectorizable=*/false, /*Vectorizable=*/false,
@ -35,7 +35,7 @@ static void DefaultAssign(Dst& dst, Expr expr) {
// Assignment with specified device and tiling strategy. // Assignment with specified device and tiling strategy.
template <bool Vectorizable, TiledEvaluation Tiling, typename Device, typename Dst, typename Expr> template <bool Vectorizable, TiledEvaluation Tiling, typename Device, typename Dst, typename Expr>
static void DeviceAssign(Device& d, Dst& dst, Expr expr) { void DeviceAssign(Device& d, Dst& dst, Expr expr) {
using Assign = Eigen::TensorAssignOp<Dst, const Expr>; using Assign = Eigen::TensorAssignOp<Dst, const Expr>;
using Executor = Eigen::internal::TensorExecutor<const Assign, Device, Vectorizable, Tiling>; using Executor = Eigen::internal::TensorExecutor<const Assign, Device, Vectorizable, Tiling>;
@ -52,7 +52,7 @@ static array<Index, NumDims> RandomDims(int min_dim = 1, int max_dim = 20) {
} }
template <typename T, int NumDims, typename Device, bool Vectorizable, TiledEvaluation Tiling, int Layout> template <typename T, int NumDims, typename Device, bool Vectorizable, TiledEvaluation Tiling, int Layout>
static void test_execute_unary_expr(Device d) { void test_execute_unary_expr(Device d) {
static constexpr int Options = 0 | Layout; static constexpr int Options = 0 | Layout;
// Pick a large enough tensor size to bypass small tensor block evaluation // Pick a large enough tensor size to bypass small tensor block evaluation
@ -77,7 +77,7 @@ static void test_execute_unary_expr(Device d) {
} }
template <typename T, int NumDims, typename Device, bool Vectorizable, TiledEvaluation Tiling, int Layout> template <typename T, int NumDims, typename Device, bool Vectorizable, TiledEvaluation Tiling, int Layout>
static void test_execute_binary_expr(Device d) { void test_execute_binary_expr(Device d) {
static constexpr int Options = 0 | Layout; static constexpr int Options = 0 | Layout;
// Pick a large enough tensor size to bypass small tensor block evaluation // Pick a large enough tensor size to bypass small tensor block evaluation
@ -105,7 +105,7 @@ static void test_execute_binary_expr(Device d) {
} }
template <typename T, int NumDims, typename Device, bool Vectorizable, TiledEvaluation Tiling, int Layout> template <typename T, int NumDims, typename Device, bool Vectorizable, TiledEvaluation Tiling, int Layout>
static void test_execute_broadcasting(Device d) { void test_execute_broadcasting(Device d) {
static constexpr int Options = 0 | Layout; static constexpr int Options = 0 | Layout;
auto dims = RandomDims<NumDims>(1, 10); auto dims = RandomDims<NumDims>(1, 10);
@ -134,92 +134,101 @@ static void test_execute_broadcasting(Device d) {
} }
template <typename T, int NumDims, typename Device, bool Vectorizable, TiledEvaluation Tiling, int Layout> template <typename T, int NumDims, typename Device, bool Vectorizable, TiledEvaluation Tiling, int Layout>
static void test_execute_chipping_rvalue(Device d) { struct test_execute_chipping_rvalue_runner {
auto dims = RandomDims<NumDims>(1, 10); template <int ChipDim>
Tensor<T, NumDims, Layout, Index> src(dims); static void run_dim(Device& d, const array<Index, NumDims>& dims, const Tensor<T, NumDims, Layout, Index>& src) {
src.setRandom(); const auto offset = internal::random<Index>(0, dims[(ChipDim)] - 1);
const auto expr = src.template chip<ChipDim>(offset);
#define TEST_CHIPPING(CHIP_DIM) \ Tensor<T, NumDims - 1, Layout, Index> golden;
if (NumDims > (CHIP_DIM)) { \ golden = expr;
const auto offset = internal::random<Index>(0, dims[(CHIP_DIM)] - 1); \
const auto expr = src.template chip<(CHIP_DIM)>(offset); \ Tensor<T, NumDims - 1, Layout, Index> dst(golden.dimensions());
\
Tensor<T, NumDims - 1, Layout, Index> golden; \ using Assign = TensorAssignOp<decltype(dst), const decltype(expr)>;
golden = expr; \ using Executor = internal::TensorExecutor<const Assign, Device, Vectorizable, Tiling>;
\
Tensor<T, NumDims - 1, Layout, Index> dst(golden.dimensions()); \ Executor::run(Assign(dst, expr), d);
\
using Assign = TensorAssignOp<decltype(dst), const decltype(expr)>; \ for (Index i = 0; i < dst.dimensions().TotalSize(); ++i) {
using Executor = internal::TensorExecutor<const Assign, Device, Vectorizable, Tiling>; \ VERIFY_IS_EQUAL(dst.coeff(i), golden.coeff(i));
\ }
Executor::run(Assign(dst, expr), d); \
\ // Recursively reduce chip dimension.
for (Index i = 0; i < dst.dimensions().TotalSize(); ++i) { \ run_dim<ChipDim - 1>(d, dims, src);
VERIFY_IS_EQUAL(dst.coeff(i), golden.coeff(i)); \
} \
} }
TEST_CHIPPING(0) template <>
TEST_CHIPPING(1) void run_dim<-1>(Device&, const array<Index, NumDims>&, const Tensor<T, NumDims, Layout, Index>&) {}
TEST_CHIPPING(2)
TEST_CHIPPING(3)
TEST_CHIPPING(4)
TEST_CHIPPING(5)
#undef TEST_CHIPPING static void run(Device d) {
auto dims = RandomDims<NumDims>(1, 10);
Tensor<T, NumDims, Layout, Index> src(dims);
src.setRandom();
run_dim<NumDims - 1>(d, dims, src);
}
};
template <typename T, int NumDims, typename Device, bool Vectorizable, TiledEvaluation Tiling, int Layout>
void test_execute_chipping_rvalue(Device d) {
test_execute_chipping_rvalue_runner<T, NumDims, Device, Vectorizable, Tiling, Layout>::run(d);
} }
template <typename T, int NumDims, typename Device, bool Vectorizable, TiledEvaluation Tiling, int Layout> template <typename T, int NumDims, typename Device, bool Vectorizable, TiledEvaluation Tiling, int Layout>
static void test_execute_chipping_lvalue(Device d) { struct test_execute_chipping_lvalue_runner {
auto dims = RandomDims<NumDims>(1, 10); template <int ChipDim>
static void run_dim(Device& d, const array<Index, NumDims>& dims) {
/* Generate random data that we'll assign to the chipped tensor dim. */
array<Index, NumDims - 1> src_dims;
for (int i = 0; i < NumDims - 1; ++i) {
int dim = i < (ChipDim) ? i : i + 1;
src_dims[i] = dims[dim];
}
#define TEST_CHIPPING(CHIP_DIM) \ Tensor<T, NumDims - 1, Layout, Index> src(src_dims);
if (NumDims > (CHIP_DIM)) { \ src.setRandom();
/* Generate random data that we'll assign to the chipped tensor dim. */ \
array<Index, NumDims - 1> src_dims; \ const auto offset = internal::random<Index>(0, dims[(ChipDim)] - 1);
for (int i = 0; i < NumDims - 1; ++i) { \
int dim = i < (CHIP_DIM) ? i : i + 1; \ Tensor<T, NumDims, Layout, Index> random(dims);
src_dims[i] = dims[dim]; \ random.setZero();
} \
\ Tensor<T, NumDims, Layout, Index> golden(dims);
Tensor<T, NumDims - 1, Layout, Index> src(src_dims); \ golden = random;
src.setRandom(); \ golden.template chip<(ChipDim)>(offset) = src;
\
const auto offset = internal::random<Index>(0, dims[(CHIP_DIM)] - 1); \ Tensor<T, NumDims, Layout, Index> dst(dims);
\ dst = random;
Tensor<T, NumDims, Layout, Index> random(dims); \ auto expr = dst.template chip<(ChipDim)>(offset);
random.setZero(); \
\ using Assign = TensorAssignOp<decltype(expr), const decltype(src)>;
Tensor<T, NumDims, Layout, Index> golden(dims); \ using Executor = internal::TensorExecutor<const Assign, Device, Vectorizable, Tiling>;
golden = random; \
golden.template chip<(CHIP_DIM)>(offset) = src; \ Executor::run(Assign(expr, src), d);
\
Tensor<T, NumDims, Layout, Index> dst(dims); \ for (Index i = 0; i < dst.dimensions().TotalSize(); ++i) {
dst = random; \ VERIFY_IS_EQUAL(dst.coeff(i), golden.coeff(i));
auto expr = dst.template chip<(CHIP_DIM)>(offset); \ }
\
using Assign = TensorAssignOp<decltype(expr), const decltype(src)>; \ run_dim<ChipDim - 1>(d, dims);
using Executor = internal::TensorExecutor<const Assign, Device, Vectorizable, Tiling>; \
\
Executor::run(Assign(expr, src), d); \
\
for (Index i = 0; i < dst.dimensions().TotalSize(); ++i) { \
VERIFY_IS_EQUAL(dst.coeff(i), golden.coeff(i)); \
} \
} }
TEST_CHIPPING(0) template <>
TEST_CHIPPING(1) void run_dim<-1>(Device&, const array<Index, NumDims>&) {}
TEST_CHIPPING(2)
TEST_CHIPPING(3)
TEST_CHIPPING(4)
TEST_CHIPPING(5)
#undef TEST_CHIPPING static void run(Device d) {
auto dims = RandomDims<NumDims>(1, 10);
run_dim<NumDims - 1>(d, dims);
}
};
template <typename T, int NumDims, typename Device, bool Vectorizable, TiledEvaluation Tiling, int Layout>
void test_execute_chipping_lvalue(Device d) {
test_execute_chipping_lvalue_runner<T, NumDims, Device, Vectorizable, Tiling, Layout>::run(d);
} }
template <typename T, int NumDims, typename Device, bool Vectorizable, TiledEvaluation Tiling, int Layout> template <typename T, int NumDims, typename Device, bool Vectorizable, TiledEvaluation Tiling, int Layout>
static void test_execute_shuffle_rvalue(Device d) { void test_execute_shuffle_rvalue(Device d) {
static constexpr int Options = 0 | Layout; static constexpr int Options = 0 | Layout;
auto dims = RandomDims<NumDims>(1, 10); auto dims = RandomDims<NumDims>(1, 10);
@ -255,7 +264,7 @@ static void test_execute_shuffle_rvalue(Device d) {
} }
template <typename T, int NumDims, typename Device, bool Vectorizable, TiledEvaluation Tiling, int Layout> template <typename T, int NumDims, typename Device, bool Vectorizable, TiledEvaluation Tiling, int Layout>
static void test_execute_shuffle_lvalue(Device d) { void test_execute_shuffle_lvalue(Device d) {
static constexpr int Options = 0 | Layout; static constexpr int Options = 0 | Layout;
auto dims = RandomDims<NumDims>(5, 10); auto dims = RandomDims<NumDims>(5, 10);
@ -289,7 +298,7 @@ static void test_execute_shuffle_lvalue(Device d) {
} }
template <typename T, int NumDims, typename Device, bool Vectorizable, TiledEvaluation Tiling, int Layout> template <typename T, int NumDims, typename Device, bool Vectorizable, TiledEvaluation Tiling, int Layout>
static void test_execute_reshape(Device d) { void test_execute_reshape(Device d) {
static_assert(NumDims >= 2, "NumDims must be greater or equal than 2"); static_assert(NumDims >= 2, "NumDims must be greater or equal than 2");
static constexpr int ReshapedDims = NumDims - 1; static constexpr int ReshapedDims = NumDims - 1;
@ -326,7 +335,7 @@ static void test_execute_reshape(Device d) {
} }
template <typename T, int NumDims, typename Device, bool Vectorizable, TiledEvaluation Tiling, int Layout> template <typename T, int NumDims, typename Device, bool Vectorizable, TiledEvaluation Tiling, int Layout>
static void test_execute_slice_rvalue(Device d) { void test_execute_slice_rvalue(Device d) {
static_assert(NumDims >= 2, "NumDims must be greater or equal than 2"); static_assert(NumDims >= 2, "NumDims must be greater or equal than 2");
static constexpr int Options = 0 | Layout; static constexpr int Options = 0 | Layout;
@ -362,7 +371,7 @@ static void test_execute_slice_rvalue(Device d) {
} }
template <typename T, int NumDims, typename Device, bool Vectorizable, TiledEvaluation Tiling, int Layout> template <typename T, int NumDims, typename Device, bool Vectorizable, TiledEvaluation Tiling, int Layout>
static void test_execute_slice_lvalue(Device d) { void test_execute_slice_lvalue(Device d) {
static_assert(NumDims >= 2, "NumDims must be greater or equal than 2"); static_assert(NumDims >= 2, "NumDims must be greater or equal than 2");
static constexpr int Options = 0 | Layout; static constexpr int Options = 0 | Layout;
@ -402,7 +411,7 @@ static void test_execute_slice_lvalue(Device d) {
} }
template <typename T, int NumDims, typename Device, bool Vectorizable, TiledEvaluation Tiling, int Layout> template <typename T, int NumDims, typename Device, bool Vectorizable, TiledEvaluation Tiling, int Layout>
static void test_execute_broadcasting_of_forced_eval(Device d) { void test_execute_broadcasting_of_forced_eval(Device d) {
static constexpr int Options = 0 | Layout; static constexpr int Options = 0 | Layout;
auto dims = RandomDims<NumDims>(1, 10); auto dims = RandomDims<NumDims>(1, 10);
@ -442,7 +451,7 @@ struct DummyGenerator {
}; };
template <typename T, int NumDims, typename Device, bool Vectorizable, TiledEvaluation Tiling, int Layout> template <typename T, int NumDims, typename Device, bool Vectorizable, TiledEvaluation Tiling, int Layout>
static void test_execute_generator_op(Device d) { void test_execute_generator_op(Device d) {
static constexpr int Options = 0 | Layout; static constexpr int Options = 0 | Layout;
auto dims = RandomDims<NumDims>(20, 30); auto dims = RandomDims<NumDims>(20, 30);
@ -470,7 +479,7 @@ static void test_execute_generator_op(Device d) {
} }
template <typename T, int NumDims, typename Device, bool Vectorizable, TiledEvaluation Tiling, int Layout> template <typename T, int NumDims, typename Device, bool Vectorizable, TiledEvaluation Tiling, int Layout>
static void test_execute_reverse_rvalue(Device d) { void test_execute_reverse_rvalue(Device d) {
static constexpr int Options = 0 | Layout; static constexpr int Options = 0 | Layout;
auto dims = RandomDims<NumDims>(1, numext::pow(1000000.0, 1.0 / NumDims)); auto dims = RandomDims<NumDims>(1, numext::pow(1000000.0, 1.0 / NumDims));
@ -502,7 +511,7 @@ static void test_execute_reverse_rvalue(Device d) {
} }
template <typename T, int NumDims, typename Device, bool Vectorizable, TiledEvaluation Tiling, int Layout> template <typename T, int NumDims, typename Device, bool Vectorizable, TiledEvaluation Tiling, int Layout>
static void test_async_execute_unary_expr(Device d) { void test_async_execute_unary_expr(Device d) {
static constexpr int Options = 0 | Layout; static constexpr int Options = 0 | Layout;
// Pick a large enough tensor size to bypass small tensor block evaluation // Pick a large enough tensor size to bypass small tensor block evaluation
@ -532,7 +541,7 @@ static void test_async_execute_unary_expr(Device d) {
} }
template <typename T, int NumDims, typename Device, bool Vectorizable, TiledEvaluation Tiling, int Layout> template <typename T, int NumDims, typename Device, bool Vectorizable, TiledEvaluation Tiling, int Layout>
static void test_async_execute_binary_expr(Device d) { void test_async_execute_binary_expr(Device d) {
static constexpr int Options = 0 | Layout; static constexpr int Options = 0 | Layout;
// Pick a large enough tensor size to bypass small tensor block evaluation // Pick a large enough tensor size to bypass small tensor block evaluation