From 80f0668a9882ca77b5217b2b80aa232b8ddf1364 Mon Sep 17 00:00:00 2001 From: Li Lao Date: Sun, 16 Oct 2022 12:48:59 -0700 Subject: [PATCH] Pretty print TFRT and RunHandlerWorkQueue options. Otherwise, the options are shown as binary data byte-by-byte. PiperOrigin-RevId: 481494878 --- tensorflow/compiler/mlir/tfrt/BUILD | 1 + .../tfrt/translate/tfrt_compile_options.cc | 36 +++++++++++++++++++ .../tfrt/translate/tfrt_compile_options.h | 3 ++ .../graph_executor/graph_execution_options.cc | 15 ++++++++ .../graph_executor/graph_execution_options.h | 5 +++ .../core/tfrt/run_handler_thread_pool/BUILD | 1 + .../run_handler_concurrent_work_queue.cc | 30 +++++++++++++++- .../run_handler_concurrent_work_queue.h | 7 +++- 8 files changed, 96 insertions(+), 2 deletions(-) diff --git a/tensorflow/compiler/mlir/tfrt/BUILD b/tensorflow/compiler/mlir/tfrt/BUILD index 1a9bfcd9955..75f7994f871 100644 --- a/tensorflow/compiler/mlir/tfrt/BUILD +++ b/tensorflow/compiler/mlir/tfrt/BUILD @@ -584,6 +584,7 @@ cc_library( name = "tfrt_compile_options", srcs = ["translate/tfrt_compile_options.cc"], hdrs = ["translate/tfrt_compile_options.h"], + deps = ["@com_google_absl//absl/strings"], ) cc_library( diff --git a/tensorflow/compiler/mlir/tfrt/translate/tfrt_compile_options.cc b/tensorflow/compiler/mlir/tfrt/translate/tfrt_compile_options.cc index b15f8b434ef..87cd5f3a51e 100644 --- a/tensorflow/compiler/mlir/tfrt/translate/tfrt_compile_options.cc +++ b/tensorflow/compiler/mlir/tfrt/translate/tfrt_compile_options.cc @@ -16,6 +16,10 @@ limitations under the License. #include "tensorflow/compiler/mlir/tfrt/translate/tfrt_compile_options.h" #include +#include +#include + +#include "absl/strings/str_join.h" namespace tensorflow { @@ -32,4 +36,36 @@ std::ostream& operator<<(std::ostream& os, TfrtTpuInfraTarget tpu_target) { } } +std::ostream& operator<<(std::ostream& os, const TfrtCompileOptions& options) { + return os << "{" + << "variable_device = " << options.variable_device + << ", default_device = " << options.default_device + << ", enable_optimizer = " << options.enable_optimizer + << ", enable_native_ops = " << options.enable_native_ops + << ", enable_grappler = " << options.enable_grappler + << ", force_data_format = " << options.force_data_format + << ", tpu_target = " << options.tpu_target + << ", tpu_fuse_ops = " << options.tpu_fuse_ops + << ", tpu_move_resource_gather_to_host = " + << options.tpu_move_resource_gather_to_host + << ", tpu_gather_table_width_threshold_bytes = " + << options.tpu_gather_table_width_threshold_bytes + << ", use_tpu_host_allocator_for_inputs = " + << options.use_tpu_host_allocator_for_inputs + << ", hoist_invariant_ops = " << options.hoist_invariant_ops + << ", enable_while_parallel_iterations = " + << options.enable_while_parallel_iterations + << ", auto_fusion_oplist = [" + << absl::StrJoin(options.auto_fusion_oplist, ",") << "]" + << ", auto_fusion_min_cluster_size = " + << options.auto_fusion_min_cluster_size + << ", cost_threshold = " << options.cost_threshold + << ", upper_cost_threshold = " << options.upper_cost_threshold + << ", merge_inter_dependent_streams = " + << options.merge_inter_dependent_streams + << ", decompose_resource_ops = " << options.decompose_resource_ops + << ", compile_to_sync_tfrt_dialect = " + << options.compile_to_sync_tfrt_dialect << "}"; +} + } // namespace tensorflow diff --git a/tensorflow/compiler/mlir/tfrt/translate/tfrt_compile_options.h b/tensorflow/compiler/mlir/tfrt/translate/tfrt_compile_options.h index 7b59d640129..d8cbfc57bfa 100644 --- a/tensorflow/compiler/mlir/tfrt/translate/tfrt_compile_options.h +++ b/tensorflow/compiler/mlir/tfrt/translate/tfrt_compile_options.h @@ -17,6 +17,7 @@ limitations under the License. #define TENSORFLOW_COMPILER_MLIR_TFRT_TRANSLATE_TFRT_COMPILE_OPTIONS_H_ #include +#include #include #include @@ -131,6 +132,8 @@ struct TfrtCompileOptions { bool compile_to_sync_tfrt_dialect = false; }; +std::ostream& operator<<(std::ostream& os, const TfrtCompileOptions& options); + } // namespace tensorflow #endif // TENSORFLOW_COMPILER_MLIR_TFRT_TRANSLATE_TFRT_COMPILE_OPTIONS_H_ diff --git a/tensorflow/core/tfrt/graph_executor/graph_execution_options.cc b/tensorflow/core/tfrt/graph_executor/graph_execution_options.cc index 3d15a240d55..50be83e0299 100644 --- a/tensorflow/core/tfrt/graph_executor/graph_execution_options.cc +++ b/tensorflow/core/tfrt/graph_executor/graph_execution_options.cc @@ -14,6 +14,8 @@ limitations under the License. ==============================================================================*/ #include "tensorflow/core/tfrt/graph_executor/graph_execution_options.h" +#include + #include "tensorflow/core/protobuf/rewriter_config.pb.h" // TODO(b/200579737): using FunctionRegistry is simpler than the OSS trick. #include "tensorflow/core/tfrt/utils/bridge_graph_analysis.h" @@ -76,5 +78,18 @@ void UpdateTpuTargetByBridgeCompatibility( LOG(INFO) << "TFRT uses TPU target " << options.compile_options.tpu_target; } +std::ostream& operator<<(std::ostream& os, + const GraphExecutionOptions& options) { + return os << "{" + << "run_placer_grappler_on_functions = " + << options.run_placer_grappler_on_functions + << ", enable_grappler_function_optimizer = " + << options.enable_grappler_function_optimizer + << ", enable_tfrt_gpu = " << options.enable_tfrt_gpu + << ", runtime = " << options.runtime + << ", model_metadata = " << options.model_metadata.DebugString() + << ", compile_options = " << options.compile_options << "}"; +} + } // namespace tfrt_stub } // namespace tensorflow diff --git a/tensorflow/core/tfrt/graph_executor/graph_execution_options.h b/tensorflow/core/tfrt/graph_executor/graph_execution_options.h index 9d1afc0ce7c..b88745878bd 100644 --- a/tensorflow/core/tfrt/graph_executor/graph_execution_options.h +++ b/tensorflow/core/tfrt/graph_executor/graph_execution_options.h @@ -15,6 +15,8 @@ limitations under the License. #ifndef TENSORFLOW_CORE_TFRT_GRAPH_EXECUTOR_GRAPH_EXECUTION_OPTIONS_H_ #define TENSORFLOW_CORE_TFRT_GRAPH_EXECUTOR_GRAPH_EXECUTION_OPTIONS_H_ +#include + #include "absl/types/optional.h" #include "tensorflow/compiler/mlir/tfrt/translate/tfrt_compile_options.h" #include "tensorflow/core/protobuf/config.pb.h" @@ -52,6 +54,9 @@ struct GraphExecutionOptions { tensorflow::TfrtCompileOptions compile_options; }; +std::ostream& operator<<(std::ostream& os, + const GraphExecutionOptions& options); + // Per-request options for graph execution. struct GraphExecutionRunOptions { absl::optional deadline; diff --git a/tensorflow/core/tfrt/run_handler_thread_pool/BUILD b/tensorflow/core/tfrt/run_handler_thread_pool/BUILD index a5a1ffe9ee4..1bc2bbf904a 100644 --- a/tensorflow/core/tfrt/run_handler_thread_pool/BUILD +++ b/tensorflow/core/tfrt/run_handler_thread_pool/BUILD @@ -98,6 +98,7 @@ cc_library( ":run_handler", "//tensorflow/core/platform:strcat", "//tensorflow/core/tfrt/runtime:work_queue_interface", + "@com_google_absl//absl/strings", "@llvm-project//llvm:Support", "@tf_runtime//:hostcontext", "@tf_runtime//:support", diff --git a/tensorflow/core/tfrt/run_handler_thread_pool/run_handler_concurrent_work_queue.cc b/tensorflow/core/tfrt/run_handler_thread_pool/run_handler_concurrent_work_queue.cc index f085bd733af..97c5356edb3 100644 --- a/tensorflow/core/tfrt/run_handler_thread_pool/run_handler_concurrent_work_queue.cc +++ b/tensorflow/core/tfrt/run_handler_thread_pool/run_handler_concurrent_work_queue.cc @@ -15,12 +15,14 @@ limitations under the License. #include "tensorflow/core/tfrt/run_handler_thread_pool/run_handler_concurrent_work_queue.h" #include +#include +#include +#include "absl/strings/str_join.h" #include "tensorflow/core/tfrt/run_handler_thread_pool/run_handler.h" #include "tfrt/host_context/async_dispatch.h" // from @tf_runtime #include "tfrt/host_context/async_value.h" // from @tf_runtime #include "tfrt/host_context/execution_context.h" // from @tf_runtime -#include "tfrt/support/error_util.h" // from @tf_runtime namespace tfrt { namespace tf { @@ -106,5 +108,31 @@ bool RunHandlerThreadWorkQueue::IsInWorkerThread() const { return true; } +std::ostream& operator<<(std::ostream& strm, + const RunHandlerThreadWorkQueue::Options& options) { + return strm << "{" + << "num_main_threads = " << options.num_main_threads + << ", num_complementary_threads = " + << options.num_complementary_threads + << ", init_timeout_ms = " << options.init_timeout_ms + << ", max_concurrent_handler = " << options.max_concurrent_handler + << ", num_sub_thread_pool = " << options.num_sub_thread_pool + << ", num_threads_in_sub_thread_pool = [" + << absl::StrJoin(options.num_threads_in_sub_thread_pool, ",") + << "]" + << ", sub_thread_request_percentage = [" + << absl::StrJoin(options.sub_thread_request_percentage, ",") + << "]" + << ", non_blocking_threads_sleep_time_micro_sec = " + << options.non_blocking_threads_sleep_time_micro_sec + << ", blocking_threads_max_sleep_time_micro_sec = " + << options.blocking_threads_max_sleep_time_micro_sec + << ", use_adaptive_waiting_time = " + << options.use_adaptive_waiting_time + << ", wait_if_no_active_request = " + << options.wait_if_no_active_request + << ", enable_wake_up = " << options.enable_wake_up << "}"; +} + } // namespace tf } // namespace tfrt diff --git a/tensorflow/core/tfrt/run_handler_thread_pool/run_handler_concurrent_work_queue.h b/tensorflow/core/tfrt/run_handler_thread_pool/run_handler_concurrent_work_queue.h index 446a30609d2..a3f572deb49 100644 --- a/tensorflow/core/tfrt/run_handler_thread_pool/run_handler_concurrent_work_queue.h +++ b/tensorflow/core/tfrt/run_handler_thread_pool/run_handler_concurrent_work_queue.h @@ -16,6 +16,9 @@ limitations under the License. #define TENSORFLOW_CORE_TFRT_RUN_HANDLER_THREAD_POOL_RUN_HANDLER_CONCURRENT_WORK_QUEUE_H_ #include +#include +#include +#include #include "tensorflow/core/platform/strcat.h" #include "tensorflow/core/tfrt/run_handler_thread_pool/run_handler.h" @@ -77,7 +80,7 @@ class RunHandlerThreadWorkQueue }; explicit RunHandlerThreadWorkQueue(const Options& options); - ~RunHandlerThreadWorkQueue() override {} + ~RunHandlerThreadWorkQueue() override = default; std::string name() const override { return tensorflow::strings::StrCat( @@ -130,6 +133,8 @@ class RunHandlerThreadWorkQueue blocking_work_queue_; }; +std::ostream& operator<<(std::ostream& strm, + const RunHandlerThreadWorkQueue::Options& options); } // namespace tf } // namespace tfrt