2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright 2017 The TensorFlow Authors. All Rights Reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include "kernels/TestUtils.h"
19 #include "luci_interpreter/test_models/maxpool2d/FloatMaxPool2DKernel.h"
20 #include "luci_interpreter/test_models/maxpool2d/NegMaxPool2DKernel.h"
22 #include "loader/ModuleLoader.h"
24 namespace luci_interpreter
29 using namespace testing;
31 class MaxPool2DTest : public ::testing::Test
37 std::vector<T> checkMaxPool2DKernel(test_kernel::TestDataBase<T> *test_data_base)
39 MemoryManager memory_manager{};
40 RuntimeModule runtime_module{};
41 bool dealloc_input = true;
43 // Load model with single op
44 auto *model_data_raw = reinterpret_cast<const char *>(test_data_base->get_model_ptr());
45 ModuleLoader::load(&runtime_module, &memory_manager, model_data_raw, dealloc_input);
47 auto *main_runtime_graph = runtime_module.getMainGraph();
48 assert(main_runtime_graph->getNumOfInputTensors() == 1);
52 auto *input_tensor_data = reinterpret_cast<T *>(main_runtime_graph->configureGraphInput(0));
53 std::copy(test_data_base->get_input_data_by_index(0).begin(),
54 test_data_base->get_input_data_by_index(0).end(), input_tensor_data);
57 runtime_module.execute();
59 assert(main_runtime_graph->getNumOfOutputTensors() == 1);
61 T *output_data = reinterpret_cast<T *>(main_runtime_graph->getOutputDataByIndex(0));
62 const size_t num_elements = (main_runtime_graph->getOutputDataSizeByIndex(0) / sizeof(T));
63 std::vector<T> output_data_vector(output_data, output_data + num_elements);
64 return output_data_vector;
67 TEST_F(MaxPool2DTest, Float_P)
69 test_kernel::TestDataFloatMaxPool2D test_data_kernel;
70 std::vector<float> output_data_vector = checkMaxPool2DKernel(&test_data_kernel);
71 EXPECT_THAT(output_data_vector, kernels::testing::FloatArrayNear(
72 test_data_kernel.get_output_data_by_index(0), 0.01f));
75 TEST_F(MaxPool2DTest, InputOutputTypeMismatch_NEG)
77 test_kernel::NegTestDataInputOutputTypeMismatchMaxPool2DKernel test_data_kernel;
79 MemoryManager memory_manager{};
80 RuntimeModule runtime_module{};
81 bool dealloc_input = true;
82 // Load model with single op
83 auto *model_data_raw = reinterpret_cast<const char *>(test_data_kernel.get_model_ptr());
84 EXPECT_DEATH(ModuleLoader::load(&runtime_module, &memory_manager, model_data_raw, dealloc_input),
88 TEST_F(MaxPool2DTest, Invalid_input_shape_NEG)
90 test_kernel::NegTestDataInvalidInputShapeMaxPool2DKernel test_data_kernel;
92 MemoryManager memory_manager{};
93 RuntimeModule runtime_module{};
94 bool dealloc_input = true;
95 // Load model with single op
96 auto *model_data_raw = reinterpret_cast<const char *>(test_data_kernel.get_model_ptr());
97 EXPECT_DEATH(ModuleLoader::load(&runtime_module, &memory_manager, model_data_raw, dealloc_input),
101 TEST_F(MaxPool2DTest, No_quant_params_NEG)
103 test_kernel::NegTestDataNoQuantParamsMaxPool2DKernel test_data_kernel;
105 MemoryManager memory_manager{};
106 RuntimeModule runtime_module{};
107 bool dealloc_input = true;
108 // Load model with single op
109 auto *model_data_raw = reinterpret_cast<const char *>(test_data_kernel.get_model_ptr());
110 EXPECT_DEATH(ModuleLoader::load(&runtime_module, &memory_manager, model_data_raw, dealloc_input),
114 // TODO: add S16 test
117 } // namespace luci_interpreter