1 /* Copyright 2019 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 #ifndef TENSORFLOW_LITE_DELEGATES_NNAPI_ACCELERATION_TEST_UTIL_H_
16 #define TENSORFLOW_LITE_DELEGATES_NNAPI_ACCELERATION_TEST_UTIL_H_
17 
18 #include <optional>
19 
20 #include "tensorflow/lite/delegates/nnapi/nnapi_delegate_kernel.h"
21 
22 namespace tflite {
23 
24 // NNAPI specific configuration for the validation allowlist.
25 class NnapiAccelerationTestParams {
26  public:
27   // Content in nnapi_acceleration_test_list.cc.
28   static const char* const kAccelerationTestConfig;
29 
30   static NnapiAccelerationTestParams ParseConfigurationLine(
31       const std::string& conf_line);
32 
NnapiAccelerationTestParams(int min_android_sdk_version)33   explicit NnapiAccelerationTestParams(int min_android_sdk_version)
34       : min_android_sdk_version_{min_android_sdk_version} {};
35 
NnapiAccelerationTestParams()36   NnapiAccelerationTestParams()
37       : min_android_sdk_version_{delegate::nnapi::kMinSdkVersionForNNAPI} {};
38 
39   // Minimum SDK version to apply the acceleration validation to.
MinAndroidSdkVersion()40   int MinAndroidSdkVersion() { return min_android_sdk_version_; }
41 
42  private:
43   int min_android_sdk_version_;
44 };
45 
46 // Returns the NNAPI acceleration test configuration for the given test id.
47 std::optional<NnapiAccelerationTestParams> GetNnapiAccelerationTestParam(
48     std::string test_id);
49 
50 }  // namespace tflite
51 
52 #endif  // TENSORFLOW_LITE_DELEGATES_NNAPI_ACCELERATION_TEST_UTIL_H_
53