Skip to content

Commit

Permalink
Improve 'size_t' support for the tests (related to #3393)
Browse files Browse the repository at this point in the history
  • Loading branch information
CAHEK7 committed Dec 1, 2024
1 parent 6c4a0b3 commit 0d605e0
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 59 deletions.
110 changes: 62 additions & 48 deletions test/network_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,26 @@
#include <initializer_list>
#include <set>
#include <vector>
#include <type_traits>

#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 <typename T = int>
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<std::vector<int>> get_inputs(int n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR)
template <typename T = int>
inline std::set<std::vector<T>> 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 },
Expand Down Expand Up @@ -103,10 +103,11 @@ inline std::set<std::vector<int>> get_inputs(int n = MIOPEN_TEST_DEFAULT_BATCH_S
// clang-format on
}

inline std::set<std::vector<int>> get_weights(int n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR)
template <typename T = int>
inline std::set<std::vector<T>> 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 },
Expand Down Expand Up @@ -139,10 +140,11 @@ inline std::set<std::vector<int>> get_weights(int n = MIOPEN_TEST_DEFAULT_BATCH_
// clang-format on
}

inline std::set<std::vector<int>> get_immed_inputs(int n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR)
template <typename T = int>
inline std::set<std::vector<T>> 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 },
Expand All @@ -160,10 +162,11 @@ inline std::set<std::vector<int>> get_immed_inputs(int n = MIOPEN_TEST_DEFAULT_B
// clang-format on
}

inline std::set<std::vector<int>> get_immed_weights(int n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR)
template <typename T = int>
inline std::set<std::vector<T>> 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 },
Expand All @@ -182,11 +185,12 @@ inline std::set<std::vector<int>> get_immed_weights(int n = MIOPEN_TEST_DEFAULT_
// clang-format on
}

inline std::set<std::vector<int>>
get_3d_conv_input_shapes(int n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR)
template <typename T = int>
inline std::set<std::vector<T>>
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},
Expand All @@ -201,11 +205,12 @@ get_3d_conv_input_shapes(int n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR)
// clang-format on
}

inline std::set<std::vector<int>>
get_3d_conv_weight_shapes(int n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR)
template <typename T = int>
inline std::set<std::vector<T>>
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},
Expand All @@ -222,11 +227,11 @@ get_3d_conv_weight_shapes(int n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR)
// clang-format on
}

inline std::set<std::vector<int>>
get_bn_peract_inputs(int n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR)
template <typename T = int>
inline std::set<std::vector<T>> 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 },
Expand Down Expand Up @@ -268,11 +273,11 @@ get_bn_peract_inputs(int n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR)
// clang-format on
}

inline std::set<std::vector<int>>
get_bn_spatial_inputs(int n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR)
template <typename T = int>
inline std::set<std::vector<T>> 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 },
Expand Down Expand Up @@ -322,11 +327,11 @@ get_bn_spatial_inputs(int n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR)
// clang-format on
}

inline std::set<std::vector<int>>
get_3d_bn_peract_inputs(int n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR)
template <typename T = int>
inline std::set<std::vector<T>> 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 },
Expand All @@ -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
Expand All @@ -362,11 +367,12 @@ get_3d_bn_peract_inputs(int n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR)
// clang-format on
}

inline std::set<std::vector<int>>
get_3d_bn_spatial_inputs(int n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR)
template <typename T = int>
inline std::set<std::vector<T>>
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 },
Expand All @@ -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
Expand All @@ -401,7 +407,8 @@ get_3d_bn_spatial_inputs(int n = MIOPEN_TEST_DEFAULT_BATCH_SIZE_FACTOR)
// clang-format on
}

inline std::vector<std::vector<int>> get_sub_tensor()
template <typename T = int>
inline std::vector<std::vector<T>> get_sub_tensor()
{
return {{16, 4, 8, 1, 4},
{2, 4, 8, 8, 4},
Expand All @@ -414,11 +421,18 @@ inline std::vector<std::vector<int>> get_sub_tensor()
{4}};
}

inline std::vector<std::vector<int>> get_tensor_offsets()
template <typename T = int>
inline std::vector<std::vector<T>> get_tensor_offsets()
{
static_assert(std::is_signed_v<T>);
return {{0, 0}, {0, 2}, {4, 0}, {5, 7}};
}

inline std::vector<int> get_tensor_offset() { return {0, 1, 2, 3, 4, 5}; }
template <typename T = int>
inline std::vector<T> get_tensor_offset()
{
static_assert(std::is_signed_v<T>);
return {0, 1, 2, 3, 4, 5};
}

#endif
1 change: 1 addition & 0 deletions test/tensor_holder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ struct miopen_type<uint64_t> : std::integral_constant<miopenDataType_t, miopenIn
template <class T>
struct tensor
{
using value_type = T;
miopen::TensorDescriptor desc;
std::vector<T> data;

Expand Down
25 changes: 14 additions & 11 deletions test/tensor_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#ifndef GUARD_TENSOR_UTIL_HPP
#define GUARD_TENSOR_UTIL_HPP

#include <type_traits>

#include <miopen/miopen.h>
#include <miopen/filesystem.hpp>
#include <miopen/tensor.hpp>
Expand All @@ -35,30 +37,31 @@
namespace fs = miopen::fs;

// loop over sub-tensor, and operate on each data
template <typename T, template <typename> class data_operator_t>
template <typename T, template <typename> class data_operator_t, typename Container>
void operate_over_subtensor(const data_operator_t<T>& r_data_operator,
tensor<T>& rSuperTensor,
Container& rSuperTensor,
const miopen::TensorDescriptor& rSubDesc,
const int offset)
const int64_t offset)
{
static_assert(std::is_same_v<T, typename Container::value_type>);
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 <typename T, template <typename> class data_operator_t>
template <typename T, template <typename> class data_operator_t, typename Container>
void operate_over_subtensor_impl(const data_operator_t<T>& r_data_operator,
tensor<T>& 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<int>(rSubDesc.GetLengths().size() - 1);
auto current_stride = static_cast<int>(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)
{
Expand Down

0 comments on commit 0d605e0

Please sign in to comment.