2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @file RandomTestRunner.h
19 * @brief This file contains class for random input testing
22 #ifndef __NNFW_TFLITE_RANDOM_TEST_RUNNER_H__
23 #define __NNFW_TFLITE_RANDOM_TEST_RUNNER_H__
25 #include "tflite/interp/Builder.h"
27 #include <misc/RandomGenerator.h>
35 * @brief Structure for NNAPI correctness test
37 struct RandomTestParam
39 int verbose; //!< Verbosity of debug information
40 int tolerance; //!< Torlerance of value difference
41 int tensor_logging = 0; //!< Save logging to a file if not 0
42 std::string log_path = ""; //!< Path of log file, meaningful only when tensor_logging is 1
46 * @brief Class to define Random test runner
48 class RandomTestRunner
52 * @brief Construct a new RandomTestRunner object
53 * @param[in] seed Random seed value
54 * @param[in] param RandomTestParam object for test runner
55 * @param[in] quantization TfLiteQuantizationParams type to represent quantization value
57 RandomTestRunner(uint32_t seed, const RandomTestParam ¶m)
58 : _randgen{seed, 0.0f, 2.0f}, _param{param}
65 * @brief Run the random test runner
66 * @param[in] running_count Count to run tflite interpreter with NNAPI
67 * @return 0 if test succeeds, otherwise failure
69 int run(size_t running_count);
73 * @brief Get RandomGenerator reference
74 * @return RandomGenerator reference
76 nnfw::misc::RandomGenerator &generator() { return _randgen; };
80 * @brief Compile the random test runner
81 * @param[in] builder Interpreter Builder used to run
83 void compile(const nnfw::tflite::Builder &builder);
86 nnfw::misc::RandomGenerator _randgen;
87 const RandomTestParam _param;
88 std::unique_ptr<::tflite::Interpreter> _tfl_interp;
89 std::unique_ptr<::tflite::Interpreter> _nnapi;
93 * @brief Create a RandomTestRunner object
94 * @param[in] seed Random seed value
95 * @return RandomGenerator object
97 static RandomTestRunner make(uint32_t seed);
100 } // namespace tflite
103 #endif // __NNFW_TFLITE_RANDOM_TEST_RUNNER_H__