From 0d605e0f3e627d1db4486b9f4247d604b778c0ff Mon Sep 17 00:00:00 2001 From: Aleksandr Eremin Date: Sun, 1 Dec 2024 04:19:02 +0200 Subject: [PATCH] Improve 'size_t' support for the tests (related to #3393) --- test/network_data.hpp | 110 +++++++++++++++++++++++------------------ test/tensor_holder.hpp | 1 + test/tensor_util.hpp | 25 +++++----- 3 files changed, 77 insertions(+), 59 deletions(-) diff --git a/test/network_data.hpp b/test/network_data.hpp index e0a39323e3..09ae13762f 100644 --- a/test/network_data.hpp +++ b/test/network_data.hpp @@ -30,26 +30,26 @@ #include #include #include +#include #ifndef MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR #define MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR 0 #endif -inline int pick_batch_size(int x, int y) +template +inline constexpr T pick_batch_size(T x, T y) { - if(y == 0 || y > x) - return 1; - else - return x / y; + return (y == 0 || y > x) ? 1 : x / y; } // Reduce tests execution time #define MIOPEN_TESTS_GET_INPUTS_ENABLE_HUGE_TENSORS 1 -inline std::set> get_inputs(int n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR) +template +inline std::set> get_inputs(T n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR) { // clang-format off - return + return { { pick_batch_size(32, n), 1, 14, 14 }, { pick_batch_size(100, n), 1, 8, 8 }, @@ -103,10 +103,11 @@ inline std::set> get_inputs(int n = MIOPEN_TEST_DEFAULT_BATCH_S // clang-format on } -inline std::set> get_weights(int n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR) +template +inline std::set> get_weights(T n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR) { // clang-format off - return + return { { pick_batch_size(1024, n),1024, 3, 3 }, { pick_batch_size(1024, n),512, 3, 3 }, @@ -139,10 +140,11 @@ inline std::set> get_weights(int n = MIOPEN_TEST_DEFAULT_BATCH_ // clang-format on } -inline std::set> get_immed_inputs(int n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR) +template +inline std::set> get_immed_inputs(T n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR) { // clang-format off - return + return { { pick_batch_size(32, n), 1, 14, 14 }, { pick_batch_size(256, n), 1, 27, 27 }, @@ -160,10 +162,11 @@ inline std::set> get_immed_inputs(int n = MIOPEN_TEST_DEFAULT_B // clang-format on } -inline std::set> get_immed_weights(int n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR) +template +inline std::set> get_immed_weights(T n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR) { // clang-format off - return + return { { pick_batch_size(208, n), 96, 3, 3 }, { pick_batch_size(24, n), 512, 1, 1 }, @@ -182,11 +185,12 @@ inline std::set> get_immed_weights(int n = MIOPEN_TEST_DEFAULT_ // clang-format on } -inline std::set> -get_3d_conv_input_shapes(int n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR) +template +inline std::set> +get_3d_conv_input_shapes(T n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR) { // clang-format off - return + return { { pick_batch_size(128, n), 1, 1, 2, 2}, { pick_batch_size(128, n), 64, 1, 1, 1}, @@ -201,11 +205,12 @@ get_3d_conv_input_shapes(int n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR) // clang-format on } -inline std::set> -get_3d_conv_weight_shapes(int n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR) +template +inline std::set> +get_3d_conv_weight_shapes(T n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR) { // clang-format off - return + return { { pick_batch_size( 128, n), 1, 1, 1, 1}, { pick_batch_size( 352, n), 128, 1, 1, 1}, @@ -222,11 +227,11 @@ get_3d_conv_weight_shapes(int n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR) // clang-format on } -inline std::set> -get_bn_peract_inputs(int n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR) +template +inline std::set> get_bn_peract_inputs(T n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR) { // clang-format off - return + return { { pick_batch_size(32, n), 4, 1024,2048}, //Making this much smaller { pick_batch_size(100, n), 3, 32, 32 }, @@ -268,11 +273,11 @@ get_bn_peract_inputs(int n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR) // clang-format on } -inline std::set> -get_bn_spatial_inputs(int n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR) +template +inline std::set> get_bn_spatial_inputs(T n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR) { // clang-format off - return + return { { pick_batch_size(32, n), 4, 1024,2048}, //Making this much smaller { pick_batch_size(32, n), 192, 256, 512 }, @@ -322,11 +327,11 @@ get_bn_spatial_inputs(int n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR) // clang-format on } -inline std::set> -get_3d_bn_peract_inputs(int n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR) +template +inline std::set> get_3d_bn_peract_inputs(T n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR) { // clang-format off - return + return { { pick_batch_size(32, n), 1, 32, 32, 32 }, // 32x32x32 based on VoxNet arch { pick_batch_size(32, n), 1, 14, 14, 14 }, @@ -336,20 +341,20 @@ get_3d_bn_peract_inputs(int n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR) { pick_batch_size(256, n), 1, 32, 32, 32 }, // 32x32x32 based on VoxNet arch { pick_batch_size(256, n), 32, 14, 14, 14 }, { pick_batch_size(256, n), 32, 12, 12, 12 }, - { pick_batch_size(256, n), 32, 6, 6, 6 }, + { pick_batch_size(256, n), 32, 6, 6, 6 }, { pick_batch_size(512, n), 1, 32, 32, 32 }, // 32x32x32 based on VoxNet arch { pick_batch_size(512, n), 32, 14, 14, 14 }, { pick_batch_size(512, n), 32, 12, 12, 12 }, - { pick_batch_size(512, n), 32, 6, 6, 6 }, + { pick_batch_size(512, n), 32, 6, 6, 6 }, { pick_batch_size(32, n), 2, 32, 57, 125 }, // Hand-gesture recognition CVPR 2015 paper High Res Net Path { pick_batch_size(32, n), 32, 14, 25, 59 }, { pick_batch_size(32, n), 32, 6, 10, 27 }, - { pick_batch_size(32, n), 32, 4, 6, 11 }, - { pick_batch_size(32, n), 32, 2, 2, 3 }, - { pick_batch_size(32, n), 32, 32, 28, 62 }, // Hand-gesture recognition CVPR 2015 paper Low Res Net Path + { pick_batch_size(32, n), 32, 4, 6, 11 }, + { pick_batch_size(32, n), 32, 2, 2, 3 }, + { pick_batch_size(32, n), 32, 32, 28, 62 }, // Hand-gesture recognition CVPR 2015 paper Low Res Net Path { pick_batch_size(32, n), 32, 14, 12, 29 }, - { pick_batch_size(32, n), 32, 6, 4, 12 }, - { pick_batch_size(32, n), 32, 4, 2, 2 }, + { pick_batch_size(32, n), 32, 6, 4, 12 }, + { pick_batch_size(32, n), 32, 4, 2, 2 }, { pick_batch_size(16, n), 32, 6, 50, 50 }, // Multi-view 3D convnet { pick_batch_size(1, n), 3, 8, 240, 320 }, // 3D convet on video { pick_batch_size(1, n), 3, 16, 240, 320 }, // 3D convet on video @@ -362,11 +367,12 @@ get_3d_bn_peract_inputs(int n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR) // clang-format on } -inline std::set> -get_3d_bn_spatial_inputs(int n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR) +template +inline std::set> +get_3d_bn_spatial_inputs(T n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR) { // clang-format off - return + return { { pick_batch_size(32, n), 1, 32, 32, 32 }, // 32x32x32 based on VoxNet arch { pick_batch_size(32, n), 1, 14, 14, 14 }, @@ -376,20 +382,20 @@ get_3d_bn_spatial_inputs(int n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR) { pick_batch_size(256, n), 1, 32, 32, 32 }, // 32x32x32 based on VoxNet arch { pick_batch_size(256, n), 32, 14, 14, 14 }, { pick_batch_size(256, n), 32, 12, 12, 12 }, - { pick_batch_size(256, n), 32, 6, 6, 6 }, + { pick_batch_size(256, n), 32, 6, 6, 6 }, { pick_batch_size(512, n), 1, 32, 32, 32 }, // 32x32x32 based on VoxNet arch { pick_batch_size(512, n), 32, 14, 14, 14 }, { pick_batch_size(512, n), 32, 12, 12, 12 }, - { pick_batch_size(512, n), 32, 6, 6, 6 }, + { pick_batch_size(512, n), 32, 6, 6, 6 }, { pick_batch_size(32, n), 2, 32, 57, 125 }, // Hand-gesture recognition CVPR 2015 paper High Res Net Path { pick_batch_size(32, n), 32, 14, 25, 59 }, { pick_batch_size(32, n), 32, 6, 10, 27 }, - { pick_batch_size(32, n), 32, 4, 6, 11 }, - { pick_batch_size(32, n), 32, 2, 2, 3 }, - { pick_batch_size(32, n), 32, 32, 28, 62 }, // Hand-gesture recognition CVPR 2015 paper Low Res Net Path + { pick_batch_size(32, n), 32, 4, 6, 11 }, + { pick_batch_size(32, n), 32, 2, 2, 3 }, + { pick_batch_size(32, n), 32, 32, 28, 62 }, // Hand-gesture recognition CVPR 2015 paper Low Res Net Path { pick_batch_size(32, n), 32, 14, 12, 29 }, - { pick_batch_size(32, n), 32, 6, 4, 12 }, - { pick_batch_size(32, n), 32, 4, 2, 2 }, + { pick_batch_size(32, n), 32, 6, 4, 12 }, + { pick_batch_size(32, n), 32, 4, 2, 2 }, { pick_batch_size(16, n), 32, 6, 50, 50 }, // Multi-view 3D convnet { pick_batch_size(1, n), 3, 8, 240, 320 }, // 3D convet on video { pick_batch_size(1, n), 3, 16, 240, 320 }, // 3D convet on video @@ -401,7 +407,8 @@ get_3d_bn_spatial_inputs(int n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR) // clang-format on } -inline std::vector> get_sub_tensor() +template +inline std::vector> get_sub_tensor() { return {{16, 4, 8, 1, 4}, {2, 4, 8, 8, 4}, @@ -414,11 +421,18 @@ inline std::vector> get_sub_tensor() {4}}; } -inline std::vector> get_tensor_offsets() +template +inline std::vector> get_tensor_offsets() { + static_assert(std::is_signed_v); return {{0, 0}, {0, 2}, {4, 0}, {5, 7}}; } -inline std::vector get_tensor_offset() { return {0, 1, 2, 3, 4, 5}; } +template +inline std::vector get_tensor_offset() +{ + static_assert(std::is_signed_v); + return {0, 1, 2, 3, 4, 5}; +} #endif diff --git a/test/tensor_holder.hpp b/test/tensor_holder.hpp index e1b03880b8..ff9566fe6c 100644 --- a/test/tensor_holder.hpp +++ b/test/tensor_holder.hpp @@ -145,6 +145,7 @@ struct miopen_type : std::integral_constant struct tensor { + using value_type = T; miopen::TensorDescriptor desc; std::vector data; diff --git a/test/tensor_util.hpp b/test/tensor_util.hpp index d14f0c806d..a2aeecb684 100644 --- a/test/tensor_util.hpp +++ b/test/tensor_util.hpp @@ -27,6 +27,8 @@ #ifndef GUARD_TENSOR_UTIL_HPP #define GUARD_TENSOR_UTIL_HPP +#include + #include #include #include @@ -35,30 +37,31 @@ namespace fs = miopen::fs; // loop over sub-tensor, and operate on each data -template class data_operator_t> +template class data_operator_t, typename Container> void operate_over_subtensor(const data_operator_t& r_data_operator, - tensor& rSuperTensor, + Container& rSuperTensor, const miopen::TensorDescriptor& rSubDesc, - const int offset) + const int64_t offset) { + static_assert(std::is_same_v); operate_over_subtensor_impl(r_data_operator, rSuperTensor, rSubDesc, 0, offset); } // loop over part of sub-tensor (dimensions lower than "current_dim"), and operate on // each data -template class data_operator_t> +template class data_operator_t, typename Container> void operate_over_subtensor_impl(const data_operator_t& r_data_operator, - tensor& rSuperTensor, + Container& rSuperTensor, const miopen::TensorDescriptor& rSubDesc, - const unsigned current_dim, - const int offset) + const size_t current_dim, + const int64_t offset) { - auto max_dim = static_cast(rSubDesc.GetLengths().size() - 1); - auto current_stride = static_cast(rSubDesc.GetStrides()[current_dim]); + const auto max_dim = rSubDesc.GetLengths().size() - 1; + const auto current_stride = rSubDesc.GetStrides()[current_dim]; - int index = offset; + int64_t index = offset; - for(int i = 0; i < rSubDesc.GetLengths()[current_dim]; ++i) + for(size_t i = 0; i < rSubDesc.GetLengths()[current_dim]; ++i) { if(current_dim == max_dim) {