• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_DEPTH_TO_SPACE_TESTER_H_
17 #define TENSORFLOW_LITE_DELEGATES_XNNPACK_DEPTH_TO_SPACE_TESTER_H_
18 
19 #include <cstdint>
20 #include <vector>
21 
22 #include <gtest/gtest.h>
23 #include "tensorflow/lite/c/common.h"
24 #include "tensorflow/lite/interpreter.h"
25 #include "tensorflow/lite/schema/schema_generated.h"
26 
27 namespace tflite {
28 namespace xnnpack {
29 
30 class DepthToSpaceTester {
31  public:
32   DepthToSpaceTester() = default;
33   DepthToSpaceTester(const DepthToSpaceTester&) = delete;
34   DepthToSpaceTester& operator=(const DepthToSpaceTester&) = delete;
35 
BatchSize(int32_t batch_size)36   inline DepthToSpaceTester& BatchSize(int32_t batch_size) {
37     EXPECT_GT(batch_size, 0);
38     batch_size_ = batch_size;
39     return *this;
40   }
41 
BatchSize()42   inline int32_t BatchSize() const { return batch_size_; }
43 
InputChannels()44   inline int32_t InputChannels() const {
45     return OutputChannels() * BlockSize() * BlockSize();
46   }
47 
OutputChannels(int32_t output_channels)48   inline DepthToSpaceTester& OutputChannels(int32_t output_channels) {
49     EXPECT_GT(output_channels, 0);
50     output_channels_ = output_channels;
51     return *this;
52   }
53 
OutputChannels()54   inline int32_t OutputChannels() const { return output_channels_; }
55 
InputHeight(int32_t input_height)56   inline DepthToSpaceTester& InputHeight(int32_t input_height) {
57     EXPECT_GT(input_height, 0);
58     input_height_ = input_height;
59     return *this;
60   }
61 
InputHeight()62   inline int32_t InputHeight() const { return input_height_; }
63 
InputWidth(int32_t input_width)64   inline DepthToSpaceTester& InputWidth(int32_t input_width) {
65     EXPECT_GT(input_width, 0);
66     input_width_ = input_width;
67     return *this;
68   }
69 
InputWidth()70   inline int32_t InputWidth() const { return input_width_; }
71 
OutputWidth()72   inline int32_t OutputWidth() const { return InputWidth() * BlockSize(); }
73 
OutputHeight()74   inline int32_t OutputHeight() const { return InputHeight() * BlockSize(); }
75 
BlockSize(int32_t block_size)76   inline DepthToSpaceTester& BlockSize(int32_t block_size) {
77     EXPECT_GT(block_size, 1);
78     block_size_ = block_size;
79     return *this;
80   }
81 
BlockSize()82   inline int32_t BlockSize() const { return block_size_; }
83 
84   template <class T>
85   void Test(TensorType tensor_type, Interpreter* delegate_interpreter,
86             Interpreter* default_interpreter) const;
87 
88   void Test(TensorType tensor_type, TfLiteDelegate* delegate) const;
89 
90  private:
91   std::vector<char> CreateTfLiteModel(TensorType tensor_type) const;
92 
93   int32_t batch_size_ = 1;
94   int32_t input_height_ = 1;
95   int32_t input_width_ = 1;
96   int32_t output_channels_ = 1;
97   int32_t block_size_ = 2;
98 };
99 
100 }  // namespace xnnpack
101 }  // namespace tflite
102 
103 #endif  // TENSORFLOW_LITE_DELEGATES_XNNPACK_DEPTH_TO_SPACE_TESTER_H_
104