From 22146f8234e95874a19f92e4d7305ffb050d9ec0 Mon Sep 17 00:00:00 2001 From: yejianwu Date: Mon, 9 Apr 2018 10:00:32 +0800 Subject: [PATCH] update out_of_range unit test --- .../kernels/opencl/out_of_range_check_test.cc | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/mace/kernels/opencl/out_of_range_check_test.cc b/mace/kernels/opencl/out_of_range_check_test.cc index 16542a84..48ab6667 100644 --- a/mace/kernels/opencl/out_of_range_check_test.cc +++ b/mace/kernels/opencl/out_of_range_check_test.cc @@ -9,8 +9,6 @@ #include "mace/core/tensor.h" #include "mace/core/workspace.h" #include "mace/kernels/opencl/helper.h" -#include "mace/utils/tuner.h" -#include "mace/utils/utils.h" namespace mace { namespace kernels { @@ -121,31 +119,33 @@ class OutOfRangeCheckTest : public ::testing::Test { TEST(OutOfRangeCheckTest, RandomTest) { static unsigned int seed = time(NULL); - index_t batch = 11 + rand_r(&seed) % 10; - index_t height = 12 + rand_r(&seed) % 100; - index_t width = 13 + rand_r(&seed) % 100; - index_t channels = 14 + rand_r(&seed) % 50; - - std::vector buffer_shape = {batch, height, width, channels}; - Workspace ws; - Tensor *buffer = ws.CreateTensor("Buffer", - GetDeviceAllocator(DeviceType::OPENCL), - DataTypeToEnum::v()); - buffer->Resize(buffer_shape); - - std::vector image_shape; - Tensor *image = ws.CreateTensor("Image", - GetDeviceAllocator(DeviceType::OPENCL), - DataTypeToEnum::v()); - CalImage2DShape(buffer->shape(), IN_OUT_CHANNEL, &image_shape); - image->ResizeImage(buffer->shape(), image_shape); - ASSERT_FALSE(BufferToImageOpImpl(buffer, image, image_shape)); - - std::vector overflow_image_shape = image_shape; - for (int i = 0; i < overflow_image_shape.size(); ++i) { - overflow_image_shape[i] += 1; + for (int round = 0; round < 10; ++round) { + index_t batch = 11 + rand_r(&seed) % 10; + index_t height = 12 + rand_r(&seed) % 100; + index_t width = 13 + rand_r(&seed) % 100; + index_t channels = 14 + rand_r(&seed) % 50; + + std::vector buffer_shape = {batch, height, width, channels}; + Workspace ws; + Tensor *buffer = ws.CreateTensor("Buffer", + GetDeviceAllocator(DeviceType::OPENCL), + DataTypeToEnum::v()); + buffer->Resize(buffer_shape); + + std::vector image_shape; + Tensor *image = ws.CreateTensor("Image", + GetDeviceAllocator(DeviceType::OPENCL), + DataTypeToEnum::v()); + CalImage2DShape(buffer->shape(), IN_OUT_CHANNEL, &image_shape); + image->ResizeImage(buffer->shape(), image_shape); + ASSERT_FALSE(BufferToImageOpImpl(buffer, image, image_shape)); + + std::vector overflow_image_shape = image_shape; + for (int i = 0; i < overflow_image_shape.size(); ++i) { + overflow_image_shape[i] += 1; + } + ASSERT_TRUE(BufferToImageOpImpl(buffer, image, overflow_image_shape)); } - ASSERT_TRUE(BufferToImageOpImpl(buffer, image, overflow_image_shape)); } } // namespace kernels -- GitLab