1 /* Copyright 2021 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_COMPILER_MLIR_LITE_METRICS_ERROR_COLLECTOR_H_ 16 #define TENSORFLOW_COMPILER_MLIR_LITE_METRICS_ERROR_COLLECTOR_H_ 17 18 #include <unordered_map> 19 #include <unordered_set> 20 #include <vector> 21 22 #include "tensorflow/compiler/mlir/lite/metrics/types_util.h" 23 #include "tensorflow/lite/python/metrics/converter_error_data.pb.h" 24 25 namespace mlir { 26 namespace TFL { 27 28 // A singleton to store errors collected by the instrumentation. 29 class ErrorCollector { 30 using ConverterErrorData = tflite::metrics::ConverterErrorData; 31 using ConverterErrorDataSet = 32 std::unordered_set<ConverterErrorData, ConverterErrorDataHash, 33 ConverterErrorDataComparison>; 34 35 public: CollectedErrors()36 const ConverterErrorDataSet &CollectedErrors() { return collected_errors_; } 37 ReportError(const ConverterErrorData & error)38 void ReportError(const ConverterErrorData &error) { 39 collected_errors_.insert(error); 40 } 41 42 // Clear the set of collected errors. Clear()43 void Clear() { collected_errors_.clear(); } 44 45 // Returns the global instance of ErrorCollector. 46 static ErrorCollector* GetErrorCollector(); 47 48 private: ErrorCollector()49 ErrorCollector() {} 50 51 ConverterErrorDataSet collected_errors_; 52 53 static ErrorCollector* error_collector_instance_; 54 }; 55 56 } // namespace TFL 57 } // namespace mlir 58 #endif // TENSORFLOW_COMPILER_MLIR_LITE_METRICS_ERROR_COLLECTOR_H_ 59