MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / OptimizeGraph

Method OptimizeGraph

tensorflow/core/common_runtime/graph_execution_state.cc:737–879  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

735}
736
737Status GraphExecutionState::OptimizeGraph(
738 const BuildGraphOptions& options, std::unique_ptr<Graph>* optimized_graph,
739 std::unique_ptr<FunctionLibraryDefinition>* optimized_flib) {
740#ifndef IS_MOBILE_PLATFORM
741 if (session_options_->config.graph_options().place_pruned_graph()) {
742 return errors::InvalidArgument("Can't optimize a pruned graph");
743 }
744
745 if (grappler::MetaOptimizerEnabled(session_options_->config)) {
746 grappler::GrapplerItem item;
747 item.id = "tf_graph";
748 graph_->ToGraphDef(&item.graph);
749
750 // It's ok to skip invalid device annotations in Grappler.
751 for (const Device* d : device_set_->devices()) {
752 Status added_device = item.AddDevice(d->name());
753 if (!added_device.ok()) VLOG(3) << added_device.error_message();
754 }
755 VLOG(3) << "Grappler available devices: "
756 << absl::StrJoin(item.devices(), ", ");
757
758 // TODO(b/114748242): Add a unit test to test this bug fix.
759 if (flib_def_) {
760 *item.graph.mutable_library() = flib_def_->ToProto();
761 }
762
763 item.fetch.insert(item.fetch.end(),
764 options.callable_options.fetch().begin(),
765 options.callable_options.fetch().end());
766 item.fetch.insert(item.fetch.end(),
767 options.callable_options.target().begin(),
768 options.callable_options.target().end());
769
770 for (const TensorConnection& tensor_connection :
771 options.callable_options.tensor_connection()) {
772 item.fetch.push_back(tensor_connection.from_tensor());
773 }
774
775 if (!(options.callable_options.feed().empty() &&
776 options.callable_options.tensor_connection().empty())) {
777 std::unordered_set<string> feeds;
778 for (const string& feed : options.callable_options.feed()) {
779 TensorId id = ParseTensorName(feed);
780 if (id.second != 0) {
781 return errors::InvalidArgument("Unsupported feed: ", feed);
782 }
783 feeds.emplace(id.first);
784 }
785 for (const TensorConnection& tensor_connection :
786 options.callable_options.tensor_connection()) {
787 TensorId id = ParseTensorName(tensor_connection.to_tensor());
788 if (id.second != 0) {
789 return errors::InvalidArgument("Unsupported feed: ",
790 tensor_connection.to_tensor());
791 }
792 feeds.emplace(id.first);
793 }
794 for (const Node* node : graph_->nodes()) {

Callers

nothing calls this directly

Calls 15

InvalidArgumentFunction · 0.85
MetaOptimizerEnabledFunction · 0.85
ParseTensorNameFunction · 0.85
AllocatorAttributesClass · 0.85
RunMetaOptimizerFunction · 0.85
ConvertGraphDefToGraphFunction · 0.85
to_tensorMethod · 0.80
unknown_rankMethod · 0.80
AsTensorShapeMethod · 0.80
signatureMethod · 0.80
ReplaceFunctionMethod · 0.80

Tested by

no test coverage detected