1 /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #ifndef TENSORFLOW_LITE_DELEGATES_XNNPACK_PRELU_TESTER_H_ 17 #define TENSORFLOW_LITE_DELEGATES_XNNPACK_PRELU_TESTER_H_ 18 19 #include <cstdint> 20 #include <vector> 21 22 #include <gtest/gtest.h> 23 #include "tensorflow/lite/c/common.h" 24 25 namespace tflite { 26 namespace xnnpack { 27 28 class PreluTester { 29 public: 30 PreluTester() = default; 31 PreluTester(const PreluTester&) = delete; 32 PreluTester& operator=(const PreluTester&) = delete; 33 InputShape(std::initializer_list<int32_t> shape)34 inline PreluTester& InputShape(std::initializer_list<int32_t> shape) { 35 for (auto it = shape.begin(); it != shape.end(); ++it) { 36 EXPECT_GT(*it, 0); 37 } 38 input_shape_ = std::vector<int32_t>(shape.begin(), shape.end()); 39 return *this; 40 } 41 InputShape()42 inline const std::vector<int32_t>& InputShape() const { return input_shape_; } 43 SlopeShape(std::initializer_list<int32_t> shape)44 inline PreluTester& SlopeShape(std::initializer_list<int32_t> shape) { 45 for (auto it = shape.begin(); it != shape.end(); ++it) { 46 EXPECT_GT(*it, 0); 47 } 48 slope_shape_ = std::vector<int32_t>(shape.begin(), shape.end()); 49 return *this; 50 } 51 SlopeShape()52 inline const std::vector<int32_t>& SlopeShape() const { return slope_shape_; } 53 OutputShape()54 inline const std::vector<int32_t>& OutputShape() const { 55 return InputShape(); 56 } 57 FP16Weights()58 inline PreluTester& FP16Weights() { 59 fp16_weights_ = true; 60 return *this; 61 } 62 FP16Weights()63 inline bool FP16Weights() const { return fp16_weights_; } 64 SparseWeights()65 inline PreluTester& SparseWeights() { 66 sparse_weights_ = true; 67 return *this; 68 } 69 SparseWeights()70 inline bool SparseWeights() const { return sparse_weights_; } 71 72 void Test(TfLiteDelegate* delegate) const; 73 74 private: 75 std::vector<char> CreateTfLiteModel() const; 76 77 static int32_t ComputeSize(const std::vector<int32_t>& shape); 78 79 std::vector<int32_t> input_shape_; 80 std::vector<int32_t> slope_shape_; 81 bool fp16_weights_ = false; 82 bool sparse_weights_ = false; 83 }; 84 85 } // namespace xnnpack 86 } // namespace tflite 87 88 #endif // TENSORFLOW_LITE_DELEGATES_XNNPACK_PRELU_TESTER_H_ 89