From ae07801dd8d295657f28b006e1e4999edf835052 Mon Sep 17 00:00:00 2001 From: Eugene Zhulenev Date: Wed, 18 Dec 2019 20:07:00 +0000 Subject: Tensor block evaluation cost model --- unsupported/test/cxx11_tensor_block_access.cpp | 119 ++++++++++++------------- unsupported/test/cxx11_tensor_block_eval.cpp | 3 +- unsupported/test/cxx11_tensor_block_io.cpp | 10 ++- 3 files changed, 65 insertions(+), 67 deletions(-) (limited to 'unsupported/test') diff --git a/unsupported/test/cxx11_tensor_block_access.cpp b/unsupported/test/cxx11_tensor_block_access.cpp index 33dc2535a..5fb12e0e0 100644 --- a/unsupported/test/cxx11_tensor_block_access.cpp +++ b/unsupported/test/cxx11_tensor_block_access.cpp @@ -21,6 +21,7 @@ using Eigen::RowMajor; using Eigen::ColMajor; using Eigen::internal::TensorBlockShapeType; +static TensorOpCost zeroCost() { return {0, 0, 0}; } template static const T& choose(int layout, const T& col, const T& row) { @@ -73,7 +74,7 @@ static void test_block_mapper_sanity() // Test uniform blocks. TensorBlockMapper uniform_block_mapper( - tensor_dims, {TensorBlockShapeType::kUniformAllDims, 100}); + tensor_dims, {TensorBlockShapeType::kUniformAllDims, 100, zeroCost()}); VERIFY_IS_EQUAL(uniform_block_mapper.blockCount(), 100); VERIFY_IS_EQUAL(uniform_block_mapper.blockTotalSize(), 100); @@ -85,7 +86,7 @@ static void test_block_mapper_sanity() // Test skewed to inner dims blocks. TensorBlockMapper skewed_block_mapper( - tensor_dims, {TensorBlockShapeType::kSkewedInnerDims, 100}); + tensor_dims, {TensorBlockShapeType::kSkewedInnerDims, 100, zeroCost()}); VERIFY_IS_EQUAL(skewed_block_mapper.blockCount(), 100); VERIFY_IS_EQUAL(skewed_block_mapper.blockTotalSize(), 100); @@ -130,7 +131,8 @@ static void test_block_mapper_maps_every_element() { std::set coeff_set; // Try different combinations of block types and sizes. - TensorBlockMapper block_mapper(dims, {RandomShape(), RandomTargetSize(dims)}); + TensorBlockMapper block_mapper( + dims, {RandomShape(), RandomTargetSize(dims), zeroCost()}); for (int i = 0; i < block_mapper.blockCount(); ++i) { auto block = block_mapper.blockDescriptor(i); @@ -233,9 +235,8 @@ static void test_uniform_block_shape() // Test shape 'UniformAllDims' with uniform 'max_coeff count'. DSizes dims(11, 5, 6, 17, 7); const Index max_coeff_count = 5 * 5 * 5 * 5 * 5; - TensorBlockMapper - block_mapper(dims, {TensorBlockShapeType::kUniformAllDims, - max_coeff_count}); + TensorBlockMapper block_mapper(dims, {TensorBlockShapeType::kUniformAllDims, + max_coeff_count, zeroCost()}); TensorBlock block = block_mapper.blockDescriptor(0); for (int i = 0; i < 5; ++i) { VERIFY_IS_EQUAL(5, block.dimensions()[i]); @@ -248,9 +249,8 @@ static void test_uniform_block_shape() if (Layout == ColMajor) { DSizes dims(11, 5, 6, 17, 7); const Index max_coeff_count = 7 * 5 * 5 * 5 * 5; - TensorBlockMapper - block_mapper(dims, {TensorBlockShapeType::kUniformAllDims, - max_coeff_count}); + TensorBlockMapper block_mapper(dims, {TensorBlockShapeType::kUniformAllDims, + max_coeff_count, zeroCost()}); TensorBlock block = block_mapper.blockDescriptor(0); VERIFY_IS_EQUAL(7, block.dimensions()[0]); for (int i = 1; i < 5; ++i) { @@ -260,9 +260,8 @@ static void test_uniform_block_shape() } else { DSizes dims(11, 5, 6, 17, 7); const Index max_coeff_count = 5 * 5 * 5 * 5 * 6; - TensorBlockMapper - block_mapper(dims, {TensorBlockShapeType::kUniformAllDims, - max_coeff_count}); + TensorBlockMapper block_mapper(dims, {TensorBlockShapeType::kUniformAllDims, + max_coeff_count, zeroCost()}); TensorBlock block = block_mapper.blockDescriptor(0); VERIFY_IS_EQUAL(6, block.dimensions()[4]); for (int i = 3; i >= 0; --i) { @@ -276,9 +275,8 @@ static void test_uniform_block_shape() if (Layout == ColMajor) { DSizes dims(11, 5, 6, 17, 7); const Index max_coeff_count = 11 * 5 * 5 * 5 * 5; - TensorBlockMapper - block_mapper(dims, {TensorBlockShapeType::kUniformAllDims, - max_coeff_count}); + TensorBlockMapper block_mapper(dims, {TensorBlockShapeType::kUniformAllDims, + max_coeff_count, zeroCost()}); TensorBlock block = block_mapper.blockDescriptor(0); VERIFY_IS_EQUAL(11, block.dimensions()[0]); for (int i = 1; i < 5; ++i) { @@ -288,9 +286,8 @@ static void test_uniform_block_shape() } else { DSizes dims(11, 5, 6, 17, 7); const Index max_coeff_count = 5 * 5 * 5 * 5 * 7; - TensorBlockMapper - block_mapper(dims, {TensorBlockShapeType::kUniformAllDims, - max_coeff_count}); + TensorBlockMapper block_mapper(dims, {TensorBlockShapeType::kUniformAllDims, + max_coeff_count, zeroCost()}); TensorBlock block = block_mapper.blockDescriptor(0); VERIFY_IS_EQUAL(7, block.dimensions()[4]); for (int i = 3; i >= 0; --i) { @@ -304,9 +301,8 @@ static void test_uniform_block_shape() if (Layout == ColMajor) { DSizes dims(7, 5, 6, 17, 7); const Index max_coeff_count = 7 * 5 * 6 * 7 * 5; - TensorBlockMapper - block_mapper(dims, {TensorBlockShapeType::kUniformAllDims, - max_coeff_count}); + TensorBlockMapper block_mapper(dims, {TensorBlockShapeType::kUniformAllDims, + max_coeff_count, zeroCost()}); TensorBlock block = block_mapper.blockDescriptor(0); VERIFY_IS_EQUAL(7, block.dimensions()[0]); VERIFY_IS_EQUAL(5, block.dimensions()[1]); @@ -317,9 +313,8 @@ static void test_uniform_block_shape() } else { DSizes dims(7, 5, 6, 9, 7); const Index max_coeff_count = 5 * 5 * 5 * 6 * 7; - TensorBlockMapper - block_mapper(dims, {TensorBlockShapeType::kUniformAllDims, - max_coeff_count}); + TensorBlockMapper block_mapper(dims, {TensorBlockShapeType::kUniformAllDims, + max_coeff_count, zeroCost()}); TensorBlock block = block_mapper.blockDescriptor(0); VERIFY_IS_EQUAL(7, block.dimensions()[4]); VERIFY_IS_EQUAL(6, block.dimensions()[3]); @@ -333,9 +328,8 @@ static void test_uniform_block_shape() if (Layout == ColMajor) { DSizes dims(7, 5, 6, 17, 7); const Index max_coeff_count = 7 * 5 * 6 * 17 * 7; - TensorBlockMapper - block_mapper(dims, {TensorBlockShapeType::kUniformAllDims, - max_coeff_count}); + TensorBlockMapper block_mapper(dims, {TensorBlockShapeType::kUniformAllDims, + max_coeff_count, zeroCost()}); TensorBlock block = block_mapper.blockDescriptor(0); VERIFY_IS_EQUAL(7, block.dimensions()[0]); VERIFY_IS_EQUAL(5, block.dimensions()[1]); @@ -346,9 +340,8 @@ static void test_uniform_block_shape() } else { DSizes dims(7, 5, 6, 9, 7); const Index max_coeff_count = 7 * 5 * 6 * 9 * 7; - TensorBlockMapper - block_mapper(dims, {TensorBlockShapeType::kUniformAllDims, - max_coeff_count}); + TensorBlockMapper block_mapper(dims, {TensorBlockShapeType::kUniformAllDims, + max_coeff_count, zeroCost()}); TensorBlock block = block_mapper.blockDescriptor(0); VERIFY_IS_EQUAL(7, block.dimensions()[4]); VERIFY_IS_EQUAL(9, block.dimensions()[3]); @@ -369,9 +362,9 @@ static void test_skewed_inner_dim_block_shape() if (Layout == ColMajor) { DSizes dims(11, 5, 6, 17, 7); const Index max_coeff_count = 10 * 1 * 1 * 1 * 1; - TensorBlockMapper - block_mapper(dims, {TensorBlockShapeType::kSkewedInnerDims, - max_coeff_count}); + TensorBlockMapper block_mapper( + dims, + {TensorBlockShapeType::kSkewedInnerDims, max_coeff_count, zeroCost()}); TensorBlock block = block_mapper.blockDescriptor(0); VERIFY_IS_EQUAL(10, block.dimensions()[0]); for (int i = 1; i < 5; ++i) { @@ -381,9 +374,9 @@ static void test_skewed_inner_dim_block_shape() } else { DSizes dims(11, 5, 6, 17, 7); const Index max_coeff_count = 1 * 1 * 1 * 1 * 6; - TensorBlockMapper - block_mapper(dims, {TensorBlockShapeType::kSkewedInnerDims, - max_coeff_count}); + TensorBlockMapper block_mapper( + dims, + {TensorBlockShapeType::kSkewedInnerDims, max_coeff_count, zeroCost()}); TensorBlock block = block_mapper.blockDescriptor(0); VERIFY_IS_EQUAL(6, block.dimensions()[4]); for (int i = 3; i >= 0; --i) { @@ -396,9 +389,9 @@ static void test_skewed_inner_dim_block_shape() if (Layout == ColMajor) { DSizes dims(11, 5, 6, 17, 7); const Index max_coeff_count = 11 * 1 * 1 * 1 * 1; - TensorBlockMapper - block_mapper(dims, {TensorBlockShapeType::kSkewedInnerDims, - max_coeff_count}); + TensorBlockMapper block_mapper( + dims, + {TensorBlockShapeType::kSkewedInnerDims, max_coeff_count, zeroCost()}); TensorBlock block = block_mapper.blockDescriptor(0); VERIFY_IS_EQUAL(11, block.dimensions()[0]); for (int i = 1; i < 5; ++i) { @@ -408,9 +401,9 @@ static void test_skewed_inner_dim_block_shape() } else { DSizes dims(11, 5, 6, 17, 7); const Index max_coeff_count = 1 * 1 * 1 * 1 * 7; - TensorBlockMapper - block_mapper(dims, {TensorBlockShapeType::kSkewedInnerDims, - max_coeff_count}); + TensorBlockMapper block_mapper( + dims, + {TensorBlockShapeType::kSkewedInnerDims, max_coeff_count, zeroCost()}); TensorBlock block = block_mapper.blockDescriptor(0); VERIFY_IS_EQUAL(7, block.dimensions()[4]); for (int i = 3; i >= 0; --i) { @@ -424,9 +417,9 @@ static void test_skewed_inner_dim_block_shape() if (Layout == ColMajor) { DSizes dims(11, 5, 6, 17, 7); const Index max_coeff_count = 11 * 3 * 1 * 1 * 1; - TensorBlockMapper - block_mapper(dims, {TensorBlockShapeType::kSkewedInnerDims, - max_coeff_count}); + TensorBlockMapper block_mapper( + dims, + {TensorBlockShapeType::kSkewedInnerDims, max_coeff_count, zeroCost()}); TensorBlock block = block_mapper.blockDescriptor(0); VERIFY_IS_EQUAL(11, block.dimensions()[0]); VERIFY_IS_EQUAL(3, block.dimensions()[1]); @@ -437,9 +430,9 @@ static void test_skewed_inner_dim_block_shape() } else { DSizes dims(11, 5, 6, 17, 7); const Index max_coeff_count = 1 * 1 * 1 * 15 * 7; - TensorBlockMapper - block_mapper(dims, {TensorBlockShapeType::kSkewedInnerDims, - max_coeff_count}); + TensorBlockMapper block_mapper( + dims, + {TensorBlockShapeType::kSkewedInnerDims, max_coeff_count, zeroCost()}); TensorBlock block = block_mapper.blockDescriptor(0); VERIFY_IS_EQUAL(7, block.dimensions()[4]); VERIFY_IS_EQUAL(15, block.dimensions()[3]); @@ -454,9 +447,9 @@ static void test_skewed_inner_dim_block_shape() if (Layout == ColMajor) { DSizes dims(11, 5, 6, 17, 7); const Index max_coeff_count = 11 * 5 * 5 * 1 * 1; - TensorBlockMapper - block_mapper(dims, {TensorBlockShapeType::kSkewedInnerDims, - max_coeff_count}); + TensorBlockMapper block_mapper( + dims, + {TensorBlockShapeType::kSkewedInnerDims, max_coeff_count, zeroCost()}); TensorBlock block = block_mapper.blockDescriptor(0); VERIFY_IS_EQUAL(11, block.dimensions()[0]); VERIFY_IS_EQUAL(5, block.dimensions()[1]); @@ -468,9 +461,9 @@ static void test_skewed_inner_dim_block_shape() } else { DSizes dims(11, 5, 6, 17, 7); const Index max_coeff_count = 1 * 1 * 5 * 17 * 7; - TensorBlockMapper - block_mapper(dims, {TensorBlockShapeType::kSkewedInnerDims, - max_coeff_count}); + TensorBlockMapper block_mapper( + dims, + {TensorBlockShapeType::kSkewedInnerDims, max_coeff_count, zeroCost()}); TensorBlock block = block_mapper.blockDescriptor(0); VERIFY_IS_EQUAL(7, block.dimensions()[4]); VERIFY_IS_EQUAL(17, block.dimensions()[3]); @@ -485,9 +478,9 @@ static void test_skewed_inner_dim_block_shape() if (Layout == ColMajor) { DSizes dims(11, 5, 6, 17, 7); const Index max_coeff_count = 11 * 5 * 6 * 17 * 7; - TensorBlockMapper - block_mapper(dims, {TensorBlockShapeType::kSkewedInnerDims, - max_coeff_count}); + TensorBlockMapper block_mapper( + dims, + {TensorBlockShapeType::kSkewedInnerDims, max_coeff_count, zeroCost()}); TensorBlock block = block_mapper.blockDescriptor(0); VERIFY_IS_EQUAL(11, block.dimensions()[0]); VERIFY_IS_EQUAL(5, block.dimensions()[1]); @@ -498,9 +491,9 @@ static void test_skewed_inner_dim_block_shape() } else { DSizes dims(11, 5, 6, 17, 7); const Index max_coeff_count = 11 * 5 * 6 * 17 * 7; - TensorBlockMapper - block_mapper(dims, {TensorBlockShapeType::kSkewedInnerDims, - max_coeff_count}); + TensorBlockMapper block_mapper( + dims, + {TensorBlockShapeType::kSkewedInnerDims, max_coeff_count, zeroCost()}); TensorBlock block = block_mapper.blockDescriptor(0); VERIFY_IS_EQUAL(7, block.dimensions()[4]); VERIFY_IS_EQUAL(17, block.dimensions()[3]); @@ -524,7 +517,8 @@ static void test_empty_dims(const internal::TensorBlockShapeType block_shape) DSizes dims(0); for (size_t max_coeff_count = 0; max_coeff_count < 2; ++max_coeff_count) { - TensorBlockMapper block_mapper(dims, {block_shape, max_coeff_count}); + TensorBlockMapper block_mapper( + dims, {block_shape, max_coeff_count, zeroCost()}); VERIFY_IS_EQUAL(block_mapper.blockCount(), 0); VERIFY(block_mapper.blockTotalSize() >= 1); } @@ -537,7 +531,8 @@ static void test_empty_dims(const internal::TensorBlockShapeType block_shape) for (int dim2 = 0; dim2 < 3; ++dim2) { DSizes dims(dim1, dim2); for (size_t max_coeff_count = 0; max_coeff_count < 2; ++max_coeff_count) { - TensorBlockMapper block_mapper(dims, {block_shape, max_coeff_count}); + TensorBlockMapper block_mapper( + dims, {block_shape, max_coeff_count, zeroCost()}); if (dim1 * dim2 == 0) { VERIFY_IS_EQUAL(block_mapper.blockCount(), 0); } diff --git a/unsupported/test/cxx11_tensor_block_eval.cpp b/unsupported/test/cxx11_tensor_block_eval.cpp index 4a785dcdc..81f0c90da 100644 --- a/unsupported/test/cxx11_tensor_block_eval.cpp +++ b/unsupported/test/cxx11_tensor_block_eval.cpp @@ -64,7 +64,8 @@ static TensorBlockParams SkewedInnerBlock( using BlockMapper = internal::TensorBlockMapper; BlockMapper block_mapper(dims, {internal::TensorBlockShapeType::kSkewedInnerDims, - internal::random(1, dims.TotalSize())}); + internal::random(1, dims.TotalSize()), + {0, 0, 0}}); Index total_blocks = block_mapper.blockCount(); Index block_index = internal::random(0, total_blocks - 1); diff --git a/unsupported/test/cxx11_tensor_block_io.cpp b/unsupported/test/cxx11_tensor_block_io.cpp index 25584433e..b8600eaea 100644 --- a/unsupported/test/cxx11_tensor_block_io.cpp +++ b/unsupported/test/cxx11_tensor_block_io.cpp @@ -75,8 +75,8 @@ static void test_block_io_copy_data_from_source_to_target() { // Construct a tensor block mapper. using TensorBlockMapper = internal::TensorBlockMapper; - TensorBlockMapper block_mapper(dims, {RandomBlockShape(), - RandomTargetBlockSize(dims)}); + TensorBlockMapper block_mapper( + dims, {RandomBlockShape(), RandomTargetBlockSize(dims), {0, 0, 0}}); // We will copy data from input to output through this buffer. Tensor block(block_mapper.blockDimensions()); @@ -146,8 +146,10 @@ static void test_block_io_copy_using_reordered_dimensions() { // NOTE: Tensor block mapper works with shuffled dimensions. using TensorBlockMapper = internal::TensorBlockMapper; - TensorBlockMapper block_mapper(output_tensor_dims, {RandomBlockShape(), - RandomTargetBlockSize(output_tensor_dims)}); + TensorBlockMapper block_mapper(output_tensor_dims, + {RandomBlockShape(), + RandomTargetBlockSize(output_tensor_dims), + {0, 0, 0}}); // We will copy data from input to output through this buffer. Tensor block(block_mapper.blockDimensions()); -- cgit v1.2.3