Added const to Node* in various parts of the code base.
PiperOrigin-RevId: 187050526
This commit is contained in:
parent
5a9343b2ac
commit
4fac98fbc7
tensorflow
compiler/tf2xla
core
common_runtime
distributed_runtime
graph
@ -37,7 +37,7 @@ Status BackwardsConstAnalysis(const Graph& g,
|
||||
};
|
||||
|
||||
Status status;
|
||||
std::unordered_set<Node*> must_be_const;
|
||||
std::unordered_set<const Node*> 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;
|
||||
|
@ -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()];
|
||||
|
||||
|
@ -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<Node*> input_nodes(node->num_inputs());
|
||||
std::vector<const Node*> input_nodes(node->num_inputs());
|
||||
std::vector<ShapeHandle> input_shapes(node->num_inputs());
|
||||
std::vector<std::unique_ptr<std::vector<ShapeAndType>>>
|
||||
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(
|
||||
|
@ -80,7 +80,7 @@ Microseconds SlackAnalysis::ComputeAsap(std::vector<Microseconds>* asap_times) {
|
||||
std::vector<int> pending_count(graph_->num_node_ids());
|
||||
InitializePending(graph_, &pending_count);
|
||||
|
||||
std::deque<Node*> queue;
|
||||
std::deque<const Node*> queue;
|
||||
Node* srcNode = graph_->source_node();
|
||||
queue.push_back(srcNode);
|
||||
(*asap_times)[srcNode->id()] = 0;
|
||||
@ -92,7 +92,7 @@ Microseconds SlackAnalysis::ComputeAsap(std::vector<Microseconds>* 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<Microseconds>* alap_times) {
|
||||
}
|
||||
}
|
||||
|
||||
std::deque<Node*> queue;
|
||||
std::deque<const Node*> queue;
|
||||
Node* sinkNode = graph_->sink_node();
|
||||
queue.push_back(sinkNode);
|
||||
(*alap_times)[sinkNode->id()] = 0;
|
||||
@ -148,7 +148,7 @@ Microseconds SlackAnalysis::ComputeAlap(std::vector<Microseconds>* 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<Node*>& nodes) {
|
||||
Node* curr_node = nullptr;
|
||||
const Node* GreedyScheduler::GetNodeWithHighestPriority(
|
||||
const std::vector<const Node*>& 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()];
|
||||
|
@ -57,11 +57,11 @@ class GreedyScheduler {
|
||||
struct Sim {
|
||||
int degree_parallelism;
|
||||
int num_running;
|
||||
std::vector<Node*> ready_nodes;
|
||||
std::vector<const Node*> 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<Node*>& nodes);
|
||||
const Node* GetNodeWithHighestPriority(const std::vector<const Node*>& nodes);
|
||||
|
||||
const DeviceSet* devices_;
|
||||
const CostModel* cost_model_;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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.
|
||||
|
@ -1271,7 +1271,7 @@ void CopyGraph(const Graph& src, Graph* dest) {
|
||||
dest->set_versions(src.versions());
|
||||
|
||||
// Copy the nodes
|
||||
std::unordered_map<Node*, Node*>
|
||||
std::unordered_map<const Node*, Node*>
|
||||
node_map; // "Node in src" -> "Node in *dest"
|
||||
node_map[src.source_node()] = dest->source_node();
|
||||
node_map[src.sink_node()] = dest->sink_node();
|
||||
|
@ -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;
|
||||
|
@ -88,7 +88,7 @@ NodeBuilder& NodeBuilder::ControlInput(Node* src_node) {
|
||||
NodeBuilder& NodeBuilder::ControlInputs(gtl::ArraySlice<Node*> 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);
|
||||
|
@ -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<NodeOut> inputs_;
|
||||
|
@ -65,8 +65,8 @@ class OptimizerCSE {
|
||||
};
|
||||
|
||||
static void FillInputs(const Node* n,
|
||||
gtl::InlinedVector<Node*, 4>* control_edges,
|
||||
gtl::InlinedVector<std::pair<Node*, int>, 4>* in) {
|
||||
gtl::InlinedVector<const Node*, 4>* control_edges,
|
||||
gtl::InlinedVector<std::pair<const Node*, int>, 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<Node*, 4> control_edges;
|
||||
gtl::InlinedVector<std::pair<Node*, int>, 4> in(N_in);
|
||||
gtl::InlinedVector<const Node*, 4> control_edges;
|
||||
gtl::InlinedVector<std::pair<const Node*, int>, 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<Node*, 4> a_control_edges;
|
||||
gtl::InlinedVector<Node*, 4> b_control_edges;
|
||||
gtl::InlinedVector<std::pair<Node*, int>, 4> a_in(N_in);
|
||||
gtl::InlinedVector<std::pair<Node*, int>, 4> b_in(N_in);
|
||||
gtl::InlinedVector<const Node*, 4> a_control_edges;
|
||||
gtl::InlinedVector<const Node*, 4> b_control_edges;
|
||||
gtl::InlinedVector<std::pair<const Node*, int>, 4> a_in(N_in);
|
||||
gtl::InlinedVector<std::pair<const Node*, int>, 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;
|
||||
|
Loading…
Reference in New Issue
Block a user