From 4fac98fbc731f742e0121fde561fcf6ed1203423 Mon Sep 17 00:00:00 2001 From: Mingsheng Hong Date: Mon, 26 Feb 2018 11:13:09 -0800 Subject: [PATCH] Added const to Node* in various parts of the code base. PiperOrigin-RevId: 187050526 --- tensorflow/compiler/tf2xla/const_analysis.cc | 4 ++-- tensorflow/compiler/tf2xla/graph_compiler.cc | 2 +- tensorflow/core/common_runtime/shape_refiner.cc | 4 ++-- tensorflow/core/distributed_runtime/scheduler.cc | 18 +++++++++--------- tensorflow/core/distributed_runtime/scheduler.h | 6 +++--- tensorflow/core/graph/costmodel.cc | 2 +- tensorflow/core/graph/graph.cc | 2 +- tensorflow/core/graph/graph.h | 2 +- tensorflow/core/graph/graph_constructor.cc | 2 +- tensorflow/core/graph/graph_partition.cc | 6 +++--- tensorflow/core/graph/node_builder.cc | 6 +++--- tensorflow/core/graph/node_builder.h | 6 +++--- tensorflow/core/graph/optimizer_cse.cc | 16 ++++++++-------- 13 files changed, 38 insertions(+), 38 deletions(-) diff --git a/tensorflow/compiler/tf2xla/const_analysis.cc b/tensorflow/compiler/tf2xla/const_analysis.cc index 8292372..6f46532 100644 --- a/tensorflow/compiler/tf2xla/const_analysis.cc +++ b/tensorflow/compiler/tf2xla/const_analysis.cc @@ -37,7 +37,7 @@ Status BackwardsConstAnalysis(const Graph& g, }; Status status; - std::unordered_set must_be_const; + std::unordered_set must_be_const; auto visit = [&status, &metadata_ops, &must_be_const, compile_time_const_args](Node* node) { if (!status.ok()) return; @@ -55,7 +55,7 @@ Status BackwardsConstAnalysis(const Graph& g, compile_time_const_args->at(index) = true; return; } - for (Node* pred : node->in_nodes()) { + for (const Node* pred : node->in_nodes()) { must_be_const.insert(pred); } return; diff --git a/tensorflow/compiler/tf2xla/graph_compiler.cc b/tensorflow/compiler/tf2xla/graph_compiler.cc index 058a1f2..b20c1ff 100644 --- a/tensorflow/compiler/tf2xla/graph_compiler.cc +++ b/tensorflow/compiler/tf2xla/graph_compiler.cc @@ -130,7 +130,7 @@ Status GraphCompiler::Compile() { // Set up inputs from outputs of previous nodes. for (auto* e : n->in_edges()) { if (e->IsControlEdge()) continue; - Node* src = e->src(); + const Node* src = e->src(); TF_RET_CHECK(src->id() < output_registry.size()); const NodeOutputs& src_outputs = output_registry[src->id()]; diff --git a/tensorflow/core/common_runtime/shape_refiner.cc b/tensorflow/core/common_runtime/shape_refiner.cc index 45cdab9..2acaa31 100644 --- a/tensorflow/core/common_runtime/shape_refiner.cc +++ b/tensorflow/core/common_runtime/shape_refiner.cc @@ -211,14 +211,14 @@ Status ShapeRefiner::AddNode(const Node* node) { // For each 'input' of this node, fetch the corresponding shape // from 'input's InferenceContext, and store into a vector // indexed by 'node's input. - std::vector input_nodes(node->num_inputs()); + std::vector input_nodes(node->num_inputs()); std::vector input_shapes(node->num_inputs()); std::vector>> input_handle_shapes_and_types(node->num_inputs()); for (const Edge* e : node->in_edges()) { if (e->IsControlEdge()) continue; - Node* input = e->src(); + const Node* input = e->src(); auto it = node_to_context_.find(input); if (it == node_to_context_.end()) { return errors::FailedPrecondition( diff --git a/tensorflow/core/distributed_runtime/scheduler.cc b/tensorflow/core/distributed_runtime/scheduler.cc index 9dae5b3..8403636 100644 --- a/tensorflow/core/distributed_runtime/scheduler.cc +++ b/tensorflow/core/distributed_runtime/scheduler.cc @@ -80,7 +80,7 @@ Microseconds SlackAnalysis::ComputeAsap(std::vector* asap_times) { std::vector pending_count(graph_->num_node_ids()); InitializePending(graph_, &pending_count); - std::deque queue; + std::deque queue; Node* srcNode = graph_->source_node(); queue.push_back(srcNode); (*asap_times)[srcNode->id()] = 0; @@ -92,7 +92,7 @@ Microseconds SlackAnalysis::ComputeAsap(std::vector* asap_times) { for (const Edge* out_edge : curr->out_edges()) { // The time needed for 'out' to get its input from 'curr'. Microseconds copy_time(0); - Node* out = out_edge->dst(); + const Node* out = out_edge->dst(); if (!out_edge->IsControlEdge() && curr->assigned_device_name() != out->assigned_device_name()) { // Add an arbitrary 10microsecs for each copy. @@ -137,7 +137,7 @@ Microseconds SlackAnalysis::ComputeAlap(std::vector* alap_times) { } } - std::deque queue; + std::deque queue; Node* sinkNode = graph_->sink_node(); queue.push_back(sinkNode); (*alap_times)[sinkNode->id()] = 0; @@ -148,7 +148,7 @@ Microseconds SlackAnalysis::ComputeAlap(std::vector* alap_times) { for (const Edge* in_edge : curr->in_edges()) { // The time needed for 'curr' to get its input from 'src'. Microseconds copy_time(0); - Node* src = in_edge->src(); + const Node* src = in_edge->src(); if (!in_edge->IsControlEdge() && src->assigned_device_name() != curr->assigned_device_name()) { // TODO(yuanbyu): Use the real cost model @@ -236,7 +236,7 @@ Microseconds GreedyScheduler::ComputeSchedule( for (const Edge* out_edge : event.node->out_edges()) { Microseconds copy_time(0); - Node* out = out_edge->dst(); + const Node* out = out_edge->dst(); if (!out_edge->IsControlEdge() && event.node->assigned_device_name() != out->assigned_device_name()) { // TODO(yuanbyu): Use below with the real cost model. @@ -277,11 +277,11 @@ Microseconds GreedyScheduler::ComputeSchedule( return max_completion; } -Node* GreedyScheduler::GetNodeWithHighestPriority( - const std::vector& nodes) { - Node* curr_node = nullptr; +const Node* GreedyScheduler::GetNodeWithHighestPriority( + const std::vector& nodes) { + const Node* curr_node = nullptr; int64 curr_priority = kint64max; - for (Node* n : nodes) { + for (const Node* n : nodes) { if ((*priority_)[n->id()] < curr_priority) { curr_node = n; curr_priority = (*priority_)[n->id()]; diff --git a/tensorflow/core/distributed_runtime/scheduler.h b/tensorflow/core/distributed_runtime/scheduler.h index ef87b98..bf9d0d1 100644 --- a/tensorflow/core/distributed_runtime/scheduler.h +++ b/tensorflow/core/distributed_runtime/scheduler.h @@ -57,11 +57,11 @@ class GreedyScheduler { struct Sim { int degree_parallelism; int num_running; - std::vector ready_nodes; + std::vector ready_nodes; }; struct Event { - Node* node; + const Node* node; Microseconds time; bool is_completion; @@ -79,7 +79,7 @@ class GreedyScheduler { private: // Returns the ready node with the highest priority for a sim. - Node* GetNodeWithHighestPriority(const std::vector& nodes); + const Node* GetNodeWithHighestPriority(const std::vector& nodes); const DeviceSet* devices_; const CostModel* cost_model_; diff --git a/tensorflow/core/graph/costmodel.cc b/tensorflow/core/graph/costmodel.cc index 4f3a6ec..1df45d9 100644 --- a/tensorflow/core/graph/costmodel.cc +++ b/tensorflow/core/graph/costmodel.cc @@ -427,7 +427,7 @@ static void AssignSizes(const Graph& g, CostModel* cost_model) { if (e->IsControlEdge()) { continue; } - Node* src = e->src(); + const Node* src = e->src(); // TODO(josh11b): Get an estimate from the Op Bytes size(1); diff --git a/tensorflow/core/graph/graph.cc b/tensorflow/core/graph/graph.cc index 9b56216..a7af5e2 100644 --- a/tensorflow/core/graph/graph.cc +++ b/tensorflow/core/graph/graph.cc @@ -339,7 +339,7 @@ Node* Graph::AddNode(const NodeDef& node_def, Status* status) { return node; } -Node* Graph::CopyNode(Node* node) { +Node* Graph::CopyNode(const Node* node) { DCHECK(!node->IsSource()); DCHECK(!node->IsSink()); Node* copy = AllocateNode(node->props_, node); diff --git a/tensorflow/core/graph/graph.h b/tensorflow/core/graph/graph.h index 9d96cd4..cbd58b0 100644 --- a/tensorflow/core/graph/graph.h +++ b/tensorflow/core/graph/graph.h @@ -422,7 +422,7 @@ class Graph { // Copies *node, which may belong to another graph, to a new node, // which is returned. Does not copy any edges. *this owns the // returned instance. - Node* CopyNode(Node* node); + Node* CopyNode(const Node* node); // Removes a node from this graph, including all edges from or to it. // *node should not be accessed after calling this function. diff --git a/tensorflow/core/graph/graph_constructor.cc b/tensorflow/core/graph/graph_constructor.cc index 0629ff3..6273090 100644 --- a/tensorflow/core/graph/graph_constructor.cc +++ b/tensorflow/core/graph/graph_constructor.cc @@ -1271,7 +1271,7 @@ void CopyGraph(const Graph& src, Graph* dest) { dest->set_versions(src.versions()); // Copy the nodes - std::unordered_map + std::unordered_map node_map; // "Node in src" -> "Node in *dest" node_map[src.source_node()] = dest->source_node(); node_map[src.sink_node()] = dest->sink_node(); diff --git a/tensorflow/core/graph/graph_partition.cc b/tensorflow/core/graph/graph_partition.cc index add80ed..17a1741 100644 --- a/tensorflow/core/graph/graph_partition.cc +++ b/tensorflow/core/graph/graph_partition.cc @@ -123,8 +123,8 @@ bool NeedSameDeviceSendRecv(const Edge* edge, const GraphInfo& info) { return false; } - Node* src = edge->src(); - Node* dst = edge->dst(); + const Node* src = edge->src(); + const Node* dst = edge->dst(); if (src->assigned_device_name() == dst->assigned_device_name()) { int src_port = edge->src_output(); int dst_port = edge->dst_input(); @@ -141,7 +141,7 @@ bool NeedSameDeviceSendRecv(const Edge* edge, const GraphInfo& info) { // Return true iff (dst, dst_input) is specified on host memory. bool IsDstInputOnHost(const Edge* edge, const GraphInfo& info) { - Node* dst = edge->dst(); + const Node* dst = edge->dst(); int dst_port = edge->dst_input(); if (info.device_types[dst->id()] != DEVICE_CPU) { if (edge->IsControlEdge()) return false; diff --git a/tensorflow/core/graph/node_builder.cc b/tensorflow/core/graph/node_builder.cc index 138952d..114962c 100644 --- a/tensorflow/core/graph/node_builder.cc +++ b/tensorflow/core/graph/node_builder.cc @@ -88,7 +88,7 @@ NodeBuilder& NodeBuilder::ControlInput(Node* src_node) { NodeBuilder& NodeBuilder::ControlInputs(gtl::ArraySlice src_nodes) { control_inputs_.insert(control_inputs_.end(), src_nodes.begin(), src_nodes.end()); - for (Node* src_node : src_nodes) { + for (const Node* src_node : src_nodes) { def_builder_.ControlInput(src_node->name()); } return *this; @@ -127,7 +127,7 @@ Status NodeBuilder::Finalize(Graph* graph, Node** created_node) const { return Status::OK(); } -void NodeBuilder::AddIndexError(Node* node, int i) { +void NodeBuilder::AddIndexError(const Node* node, int i) { if (node == nullptr) { errors_.emplace_back( strings::StrCat("Attempt to add nullptr Node to node with type ", @@ -140,7 +140,7 @@ void NodeBuilder::AddIndexError(Node* node, int i) { } } -bool NodeBuilder::GetOutputType(Node* node, int i, DataType* dt) { +bool NodeBuilder::GetOutputType(const Node* node, int i, DataType* dt) { bool error; *dt = SafeGetOutput(node, i, &error); if (error) AddIndexError(node, i); diff --git a/tensorflow/core/graph/node_builder.h b/tensorflow/core/graph/node_builder.h index 86647a4..f6b7b56 100644 --- a/tensorflow/core/graph/node_builder.h +++ b/tensorflow/core/graph/node_builder.h @@ -120,7 +120,7 @@ class NodeBuilder { const OpDef& op_def() const { return def_builder_.op_def(); } private: - static DataType SafeGetOutput(Node* node, int i, bool* error) { + static DataType SafeGetOutput(const Node* node, int i, bool* error) { if (node != nullptr && i >= 0 && i < node->num_outputs()) { *error = false; return node->output_type(i); @@ -131,11 +131,11 @@ class NodeBuilder { } // If SafeGetOutput indicates a range error, add it to errors_. - void AddIndexError(Node* node, int i); + void AddIndexError(const Node* node, int i); // Set *dt and returns true if i is in range. Combines // SafeGetOutput() and AddIndexError(). - bool GetOutputType(Node* node, int i, DataType* dt); + bool GetOutputType(const Node* node, int i, DataType* dt); NodeDefBuilder def_builder_; std::vector inputs_; diff --git a/tensorflow/core/graph/optimizer_cse.cc b/tensorflow/core/graph/optimizer_cse.cc index 6b452a1..4073255 100644 --- a/tensorflow/core/graph/optimizer_cse.cc +++ b/tensorflow/core/graph/optimizer_cse.cc @@ -65,8 +65,8 @@ class OptimizerCSE { }; static void FillInputs(const Node* n, - gtl::InlinedVector* control_edges, - gtl::InlinedVector, 4>* in) { + gtl::InlinedVector* control_edges, + gtl::InlinedVector, 4>* in) { DCHECK_EQ(in->size(), n->num_inputs()); control_edges->clear(); for (const Edge* e : n->in_edges()) { @@ -96,8 +96,8 @@ size_t OptimizerCSE::NodeHash(const Node* n) { const int N_in = n->num_inputs(); strings::StrAppend(&str_to_hash, N_in); - gtl::InlinedVector control_edges; - gtl::InlinedVector, 4> in(N_in); + gtl::InlinedVector control_edges; + gtl::InlinedVector, 4> in(N_in); FillInputs(n, &control_edges, &in); for (const auto& edge : in) { strings::StrAppend(&str_to_hash, edge.first->id(), edge.second); @@ -147,10 +147,10 @@ bool OptimizerCSE::Equivalent(const Node* a, const Node* b, // Compare input sources if (a->num_inputs() != b->num_inputs()) return false; const int N_in = a->num_inputs(); - gtl::InlinedVector a_control_edges; - gtl::InlinedVector b_control_edges; - gtl::InlinedVector, 4> a_in(N_in); - gtl::InlinedVector, 4> b_in(N_in); + gtl::InlinedVector a_control_edges; + gtl::InlinedVector b_control_edges; + gtl::InlinedVector, 4> a_in(N_in); + gtl::InlinedVector, 4> b_in(N_in); FillInputs(a, &a_control_edges, &a_in); FillInputs(b, &b_control_edges, &b_in); if (a_in != b_in) return false; -- 2.7.4