1 /* Copyright 2018 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 #include "tensorflow/lite/tools/benchmark/benchmark_params.h" 17 18 #include <string> 19 #include <unordered_map> 20 #include <vector> 21 22 #include "tensorflow/lite/tools/benchmark/logging.h" 23 24 namespace tflite { 25 namespace benchmark { 26 AssertHasSameType(BenchmarkParam::ParamType a,BenchmarkParam::ParamType b)27void BenchmarkParam::AssertHasSameType(BenchmarkParam::ParamType a, 28 BenchmarkParam::ParamType b) { 29 TFLITE_BENCHMARK_CHECK(a == b) << "Type mismatch while accessing parameter."; 30 } 31 32 template <> GetValueType()33BenchmarkParam::ParamType BenchmarkParam::GetValueType<int32_t>() { 34 return BenchmarkParam::ParamType::TYPE_INT32; 35 } 36 37 template <> GetValueType()38BenchmarkParam::ParamType BenchmarkParam::GetValueType<bool>() { 39 return BenchmarkParam::ParamType::TYPE_BOOL; 40 } 41 42 template <> GetValueType()43BenchmarkParam::ParamType BenchmarkParam::GetValueType<float>() { 44 return BenchmarkParam::ParamType::TYPE_FLOAT; 45 } 46 47 template <> GetValueType()48BenchmarkParam::ParamType BenchmarkParam::GetValueType<std::string>() { 49 return BenchmarkParam::ParamType::TYPE_STRING; 50 } 51 AssertParamExists(const std::string & name) const52void BenchmarkParams::AssertParamExists(const std::string& name) const { 53 TFLITE_BENCHMARK_CHECK(HasParam(name)) << name << " was not found."; 54 } 55 56 } // namespace benchmark 57 } // namespace tflite 58