Add EmitErrorReporter to bridge between ErrorReporter and context.
This bridges errors reported in TFLite via ErrorReporter and MLIR context emitErrors. PiperOrigin-RevId: 257013761
This commit is contained in:
parent
b9f8ebd7dd
commit
5ee1d63274
@ -364,7 +364,7 @@ cc_library(
|
||||
"flatbuffer_operator.h",
|
||||
],
|
||||
deps = [
|
||||
"//tensorflow/compiler/mlir/lite:tensorflow_lite",
|
||||
":tensorflow_lite",
|
||||
"//tensorflow/compiler/mlir/tensorflow",
|
||||
"//tensorflow/lite/schema:schema_fbs",
|
||||
"@com_google_absl//absl/container:flat_hash_map",
|
||||
@ -384,6 +384,20 @@ tf_native_cc_binary(
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "emit_error_reporter",
|
||||
srcs = [
|
||||
"emit_error_reporter.cc",
|
||||
],
|
||||
hdrs = [
|
||||
"emit_error_reporter.h",
|
||||
],
|
||||
deps = [
|
||||
"//tensorflow/lite/core/api",
|
||||
"@local_config_mlir//:IR",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "flatbuffer_translate_lib",
|
||||
srcs = [
|
||||
@ -394,8 +408,8 @@ cc_library(
|
||||
],
|
||||
deps = [
|
||||
":flatbuffer_tflite_operator_lib",
|
||||
"//tensorflow/compiler/mlir/lite:tensorflow_lite",
|
||||
"//tensorflow/compiler/mlir/lite:tensorflow_lite_dialect_registration",
|
||||
":tensorflow_lite",
|
||||
":tensorflow_lite_dialect_registration",
|
||||
"//tensorflow/compiler/mlir/tensorflow",
|
||||
"//tensorflow/compiler/mlir/tensorflow:convert_tensor",
|
||||
"//tensorflow/compiler/mlir/tensorflow:export_tf_dialect_op",
|
||||
|
27
tensorflow/compiler/mlir/lite/emit_error_reporter.cc
Normal file
27
tensorflow/compiler/mlir/lite/emit_error_reporter.cc
Normal file
@ -0,0 +1,27 @@
|
||||
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==============================================================================*/
|
||||
|
||||
#include "tensorflow/compiler/mlir/lite/emit_error_reporter.h"
|
||||
|
||||
namespace tflite {
|
||||
|
||||
int EmitErrorReporter::Report(const char* format, va_list args) {
|
||||
std::vector<char> buf(1 + snprintf(nullptr, 0, format, args));
|
||||
std::vsnprintf(buf.data(), buf.size(), format, args);
|
||||
module_.emitError() << std::string(buf.begin(), buf.end());
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace tflite
|
38
tensorflow/compiler/mlir/lite/emit_error_reporter.h
Normal file
38
tensorflow/compiler/mlir/lite/emit_error_reporter.h
Normal file
@ -0,0 +1,38 @@
|
||||
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==============================================================================*/
|
||||
|
||||
#ifndef TENSORFLOW_COMPILER_MLIR_LITE_EMIT_ERROR_REPORTER_H_
|
||||
#define TENSORFLOW_COMPILER_MLIR_LITE_EMIT_ERROR_REPORTER_H_
|
||||
|
||||
#include <cstdarg>
|
||||
|
||||
#include "mlir/IR/Module.h" // TF:local_config_mlir
|
||||
#include "tensorflow/lite/core/api/error_reporter.h"
|
||||
|
||||
namespace tflite {
|
||||
|
||||
// Error reporter that reports errors via the module's emitError.
|
||||
class EmitErrorReporter : public ErrorReporter {
|
||||
public:
|
||||
explicit EmitErrorReporter(mlir::Module module) : module_(module) {}
|
||||
int Report(const char* format, va_list args) override;
|
||||
|
||||
private:
|
||||
mlir::Module module_;
|
||||
};
|
||||
|
||||
} // namespace tflite
|
||||
|
||||
#endif // TENSORFLOW_COMPILER_MLIR_LITE_EMIT_ERROR_REPORTER_H_
|
Loading…
Reference in New Issue
Block a user