Sign compare warning fixes batch 2

This commit is contained in:
Tare Gaskin 2020-06-16 03:51:57 +00:00
parent caf465347e
commit e0b43845d7
16 changed files with 113 additions and 79 deletions

View File

@ -255,7 +255,8 @@ void GraphMemory::InferFromTrace(const StepStats& timeline) {
std::unordered_set<const LiveTensor*> live_at_peak;
size_t current = 0;
std::unordered_set<const LiveTensor*> currently_live;
for (int i = 0; i < events.size(); ++i) {
int events_size = events.size();
for (int i = 0; i < events_size; ++i) {
const auto& event = events[i];
if (event.allocated) {
@ -271,7 +272,7 @@ void GraphMemory::InferFromTrace(const StepStats& timeline) {
current -= event.tensor->memory_used;
currently_live.erase(event.tensor);
}
if (i + 1 == events.size() ||
if (i + 1 == events_size ||
event.timestamp != events[i + 1].timestamp) {
if (current > peak) {
peak = current;

View File

@ -363,7 +363,7 @@ void VerboseLogUnknownDimensionSources(
std::vector<ShapeHandle> ReplaceUnknownDimFromConstWithUnknownDim(
InferenceContext* ic, const std::vector<ShapeHandle>& shapes) {
std::vector<ShapeHandle> converted_shapes(shapes.size());
for (int i = 0; i < shapes.size(); i++) {
for (int i = 0, shapes_size = shapes.size(); i < shapes_size; i++) {
const auto& shape = shapes[i];
if (!ic->RankKnown(shape)) {
converted_shapes[i] = shape;
@ -502,7 +502,7 @@ class TopoQueue {
const std::vector<const NodeDef*>& topo_order) const {
absl::flat_hash_map<const NodeDef*, int> map;
map.reserve(topo_order.size());
for (int i = 0; i < topo_order.size(); ++i) {
for (int i = 0, topo_order_size = topo_order.size(); i < topo_order_size; ++i) {
map.emplace(topo_order[i], i);
}
return map;
@ -680,14 +680,16 @@ class SymbolicShapeRefiner {
", shape: ", ic->DebugString(ic->input(i)),
", tensor: ");
Tensor t1;
if (input_tensor_protos.size() > i &&
int input_tensor_protos_size = input_tensor_protos.size();
if (input_tensor_protos_size > i &&
input_tensor_protos.at(i) != nullptr &&
t1.FromProto(*input_tensor_protos.at(i))) {
absl::StrAppend(&output, t1.DebugString(), ", tensor_as_shape: ");
} else {
absl::StrAppend(&output, " null, tensor_as_shape: ");
}
if (input_tensors_as_shapes_to_propagate.size() > i) {
int input_tensors_as_shapes_to_propagate_size = input_tensors_as_shapes_to_propagate.size();
if (input_tensors_as_shapes_to_propagate_size > i) {
absl::StrAppend(
&output,
StringifyShapeHandle(input_tensors_as_shapes_to_propagate.at(i)),
@ -702,14 +704,16 @@ class SymbolicShapeRefiner {
", shape: ", ic->DebugString(ic->output(i)),
", tensor: ");
Tensor t2;
if (output_tensor_protos.size() > i &&
int output_tensor_protos_size = output_tensor_protos.size();
if (output_tensor_protos_size > i &&
output_tensor_protos.at(i) != nullptr &&
t2.FromProto(*output_tensor_protos.at(i))) {
absl::StrAppend(&output, t2.DebugString(), ", tensor_as_shape: ");
} else {
absl::StrAppend(&output, " null, tensor_as_shape: ");
}
if (output_tensors_as_shapes.size() > i) {
int output_tensors_as_shapes_size = output_tensors_as_shapes.size();
if (output_tensors_as_shapes_size > i) {
absl::StrAppend(&output,
StringifyShapeHandle(output_tensors_as_shapes.at(i)),
"\n");
@ -779,7 +783,7 @@ class SymbolicShapeRefiner {
MutableGraphView gv(&grappler_function_item.graph);
// Forward shapes from function input nodes to argument nodes.
for (int i = 0; i < grappler_function_item.inputs().size(); ++i) {
for (int i = 0, iter_limit = grappler_function_item.inputs().size(); i < iter_limit; ++i) {
auto& fun_input = grappler_function_item.input(i);
NodeDef* fun_node = gv.GetNode(fun_input.node_name);
const TensorId input_tensor = ParseTensorName(function_node->input(i));
@ -858,13 +862,13 @@ class SymbolicShapeRefiner {
if (IsConstant(*input_node)) {
TF_CHECK_OK(
ReplaceInputWithConst(*input_node, i, &grappler_function_item));
} else if (ctx->input_tensor_protos.size() > i &&
} else if (static_cast<int>(ctx->input_tensor_protos.size()) > i &&
ctx->input_tensor_protos[i] != nullptr) {
NodeDef const_input_node = MakeConstNodeDefFromTensorProto(
ic, *ctx->input_tensor_protos[i], ctx->input_types[i]);
TF_CHECK_OK(ReplaceInputWithConst(const_input_node, i,
&grappler_function_item));
} else if (ic->input_tensors_as_shapes().size() > i &&
} else if (static_cast<int>(ic->input_tensors_as_shapes().size()) > i &&
IsShapeFullyDefinedIntegerVectorOrScalar(
ic, ic->input(i), ic->input_tensors_as_shapes()[i],
ctx->input_types[i])) {
@ -912,7 +916,8 @@ class SymbolicShapeRefiner {
}
auto output_properties = gp.GetOutputProperties(retnode->name());
if (out_tensor.index() >= output_properties.size()) {
int output_properties_size = output_properties.size();
if (out_tensor.index() >= output_properties_size) {
return errors::InvalidArgument(
out_tensor.ToString(), " has invalid position ", out_tensor.index(),
" (output_properties.size() = ", output_properties.size(), ").");
@ -975,12 +980,12 @@ class SymbolicShapeRefiner {
// NodeContext:
// output_tensor_protos to input_tensor_protos and input_tensors, and
// output_tensors_as_shapes to input_tensors_as_shapes.
if (src_ctx->output_tensors_as_shapes.size() > src_output) {
if (static_cast<int>(src_ctx->output_tensors_as_shapes.size()) > src_output) {
ctx->input_tensors_as_shapes_to_propagate[dst_input] =
src_ctx->output_tensors_as_shapes[src_output];
}
if (src_ctx->output_tensor_protos.size() > src_output) {
if (static_cast<int>(src_ctx->output_tensor_protos.size()) > src_output) {
const auto* tensor_proto = src_ctx->output_tensor_protos[src_output];
if (tensor_proto != nullptr) {
ctx->input_tensor_protos[dst_input] = tensor_proto;
@ -1233,7 +1238,7 @@ class SymbolicShapeRefiner {
if (st1.size() != st2.size()) {
return false;
}
for (int i = 0; i < st1.size(); ++i) {
for (int i = 0, st1_size = st1.size(); i < st1_size; ++i) {
const ShapeAndType& s1 = st1[i];
const ShapeAndType& s2 = st2[i];
if (s1.dtype != s2.dtype) {
@ -1268,13 +1273,13 @@ class SymbolicShapeRefiner {
return Status::OK();
}
if (grappler_function_item.inputs().size() > function_node->input_size()) {
if (static_cast<int>(grappler_function_item.inputs().size()) > function_node->input_size()) {
return errors::FailedPrecondition(
"Function input size should be smaller than node input size.");
}
for (int i = grappler_function_item.inputs().size();
i < function_node->input_size(); ++i) {
for (int i = grappler_function_item.inputs().size(), iter_limit = function_node->input_size();
i < iter_limit; ++i) {
const string& input = function_node->input(i);
if (!IsControlInput(input)) {
return errors::FailedPrecondition(
@ -1357,18 +1362,20 @@ class SymbolicShapeRefiner {
// Returns true if all the output tensors have known values.
bool AllOutputValuesKnown(NodeContext* c) {
InferenceContext* ic = c->inference_context.get();
if (c->output_tensors_as_shapes.size() < ic->num_outputs() &&
c->output_tensor_protos.size() < ic->num_outputs()) {
int c_output_tensors_as_shapes_size = c->output_tensors_as_shapes.size();
int c_output_tensor_protos_size = c->output_tensor_protos.size();
if (c_output_tensors_as_shapes_size < ic->num_outputs() &&
c_output_tensor_protos_size < ic->num_outputs()) {
return false;
} else {
// Checks if we can get output value via either output_tensor_proto or
// output_tensors_as_shapes.
for (int i = 0; i < ic->num_outputs(); i++) {
if (c->output_tensor_protos.size() > i &&
if (c_output_tensor_protos_size > i &&
c->output_tensor_protos[i] != nullptr) {
continue;
}
if (c->output_tensors_as_shapes.size() > i &&
if (c_output_tensors_as_shapes_size > i &&
ic->FullyDefined(c->output_tensors_as_shapes[i])) {
bool no_unknown_dim_from_const = true;
for (int32 j = 0; j < ic->Rank(c->output_tensors_as_shapes[i]); ++j) {
@ -1539,7 +1546,7 @@ class SymbolicShapeRefiner {
&resource_mgr_, &outputs));
c->output_tensors_as_shapes.resize(outputs.size());
c->output_tensor_protos.resize(outputs.size(), nullptr);
for (int k = 0; k < outputs.size(); k++) {
for (int k = 0, outputs_size = outputs.size(); k < outputs_size; k++) {
const auto& t = outputs[k];
// Override output shape.
ShapeHandle output_shape;
@ -2297,7 +2304,7 @@ Status GraphProperties::UpdateEnqueue(
// TODO(bsteiner): handle EnqueueMany as well.
std::vector<ShapeAndType> shapes_and_types;
for (int i = 1; i < ctx->input_types.size(); ++i) {
for (int i = 1, iter_limit = ctx->input_types.size(); i < iter_limit; ++i) {
GraphView::InputPort inp(enqueue_node, i);
GraphView::OutputPort fanin = shape_refiner->graph().GetRegularFanin(inp);
InferenceContext* in = shape_refiner->GetContext(fanin.node);
@ -2490,10 +2497,10 @@ Status GraphProperties::InferStatically(bool assume_valid_feeds,
const TensorProto& raw_val =
fanin.node->attr().at("value").tensor();
*input_properties[i].mutable_value() = raw_val;
} else if (ctx->input_tensor_protos.size() > i &&
} else if (static_cast<int>(ctx->input_tensor_protos.size()) > i &&
ctx->input_tensor_protos[i] != nullptr) {
*input_properties[i].mutable_value() = *ctx->input_tensor_protos[i];
} else if (ic->input_tensors_as_shapes().size() > i &&
} else if (static_cast<int>(ic->input_tensors_as_shapes().size()) > i &&
IsShapeFullyDefinedIntegerVectorOrScalar(
ic, ic->input(i), ic->input_tensors_as_shapes()[i],
ctx->input_types[i])) {
@ -2525,11 +2532,11 @@ Status GraphProperties::InferStatically(bool assume_valid_feeds,
// TODO(rmlarsen): Eliminate this copy.
const TensorProto& raw_val = node.attr().at("value").tensor();
*output_properties[i].mutable_value() = raw_val;
} else if (ctx->output_tensor_protos.size() > i &&
} else if (static_cast<int>(ctx->output_tensor_protos.size()) > i &&
ctx->output_tensor_protos[i] != nullptr) {
*output_properties[i].mutable_value() =
*ctx->output_tensor_protos[i];
} else if (converted_output_tensors_as_shapes.size() > i &&
} else if (static_cast<int>(converted_output_tensors_as_shapes.size()) > i &&
IsShapeFullyDefinedIntegerVectorOrScalar(
ic, ic->output(i),
converted_output_tensors_as_shapes[i],

View File

@ -1470,8 +1470,8 @@ Costs OpLevelCostEstimator::PredictEinsum(const OpContext& op_context) const {
(a_input.shape().dim_size() < matrix_rank) ||
(b_input.shape().dim_size() < matrix_rank);
if (a_input_str.size() != a_input_shape.dim_size() ||
b_input_str.size() != b_input_shape.dim_size()) {
if (a_input_str.size() != static_cast<size_t>(a_input_shape.dim_size()) ||
b_input_str.size() != static_cast<size_t>(b_input_shape.dim_size())) {
VLOG(1) << "Missing accurate estimator for op: " << op_info.op()
<< ", equation subscripts don't match tensor rank.";
return PredictCostOfAnUnknownOp(op_context);
@ -1513,7 +1513,7 @@ Costs OpLevelCostEstimator::PredictEinsum(const OpContext& op_context) const {
n_dim.set_size(1);
k_dim.set_size(1);
for (int i_idx = 0; i_idx < a_input_str.size(); ++i_idx) {
for (int i_idx = 0, a_input_str_size = a_input_str.size(); i_idx < a_input_str_size; ++i_idx) {
if (b_input_str.find(a_input_str[i_idx]) == std::string::npos) {
if (rhs_str.find(a_input_str[i_idx]) == std::string::npos) {
VLOG(1) << "Missing accurate estimator for op: " << op_info.op();
@ -1533,7 +1533,7 @@ Costs OpLevelCostEstimator::PredictEinsum(const OpContext& op_context) const {
*(a_matrix_shape->add_dim()) = a_input_shape.dim(i_idx);
*(b_matrix_shape->add_dim()) = a_input_shape.dim(i_idx);
}
for (int i_idx = 0; i_idx < b_input_str.size(); ++i_idx) {
for (int i_idx = 0, b_input_str_size = b_input_str.size(); i_idx < b_input_str_size; ++i_idx) {
if (a_input_str.find(b_input_str[i_idx]) == std::string::npos) {
if (rhs_str.find(b_input_str[i_idx]) == std::string::npos) {
VLOG(1) << "Missing accurate estimator for op: " << op_info.op();

View File

@ -522,8 +522,8 @@ Status SchedulerState::Init(const GrapplerItem* item,
if (IsPersistent(*curr_node)) {
auto& device_state = device_[curr_node_device];
for (int port_num = 0;
port_num < curr_node_state.output_properties.size(); ++port_num) {
for (int port_num = 0, port_num_iter_limit = curr_node_state.output_properties.size();
port_num < port_num_iter_limit; ++port_num) {
device_state.persistent_nodes.insert(
std::make_pair(curr_node, port_num));
}
@ -795,7 +795,8 @@ void SchedulerState::GetOutputNodes(const NodeDef* node,
// Execute a node as soon as all its inputs are ready. Merge nodes are
// special since they run as soon as one of their inputs becomes
// available.
if (output_state.num_inputs_ready == output_state.inputs.size() ||
int output_state_inputs_size = output_state.inputs.size();
if (output_state.num_inputs_ready == output_state_inputs_size ||
IsMerge(*output_node)) {
// This output node is now ready.
output_state.time_ready = curr_time;
@ -900,8 +901,9 @@ std::vector<const NodeDef*> SchedulerState::MarkNodeExecuted(
auto port = input_port.second;
auto& input_state = node_map_[input];
input_state.num_outputs_executed[port]++;
if (input_state.num_outputs_executed[port] ==
input_state.outputs[port].size() &&
int input_state_outputs_size_ = input_state.outputs[port].size();
if (input_state.num_outputs_executed[port] == input_state_outputs_size_
&&
!IsPersistent(*input)) {
// All the outputs are executed; no reference to this output port of
// input node.
@ -1119,7 +1121,7 @@ void SchedulerState::GenerateRunMetadata(RunMetadata* metadata) {
const NodeState& nodestate = node_map_.at(node_def);
NodeExecStats* node_stats = device_stepstats->add_node_stats();
uint64 total_output_size = 0;
for (int slot = 0; slot < nodestate.output_properties.size(); slot++) {
for (int slot = 0, slot_iter_limit = nodestate.output_properties.size(); slot < slot_iter_limit; slot++) {
const auto& properties = nodestate.output_properties[slot];
NodeOutput* no = node_stats->add_output();
no->set_slot(slot);

View File

@ -73,7 +73,7 @@ class UniqueNodes {
if (it == memoized_signatures_.end()) return;
std::vector<NodeDef*>& candidates = rep_[it->second];
for (int i = 0; i < candidates.size(); ++i) {
for (int i = 0, candidates_size = candidates.size(); i < candidates_size; ++i) {
if (candidates[i] == node) {
std::swap(candidates[i], candidates[candidates.size() - 1]);
candidates.resize(candidates.size() - 1);

View File

@ -63,7 +63,7 @@ Status DebugStripper::Optimize(Cluster* cluster, const GrapplerItem& item,
node.mutable_attr()->swap(new_attr);
// As Identity op only takes one input, mark redundant inputs as control
// input.
for (size_t i = 1; i < node.input_size(); ++i) {
for (int i = 1, node_input_size = node.input_size(); i < node_input_size; ++i) {
if (!IsControlInput(node.input(i))) {
*node.mutable_input(i) = AsControlDependency(NodeName(node.input(i)));
}

View File

@ -438,8 +438,8 @@ bool HasUnusedOutputs(const NodeDef& func_node, const FunctionDef& func,
int num_outputs = func.signature().output_arg_size();
const absl::flat_hash_set<int> active_outputs =
GetActiveOutputs(func_node, ctx, /*size_hind*/ num_outputs);
return active_outputs.size() != num_outputs;
int active_outputs_size = active_outputs.size();
return active_outputs_size != num_outputs;
}
// Return pruned FunctionDefLibrary with functions that are reachable from
@ -563,7 +563,8 @@ void RemoveUnusedOutputsTypes(const FunctionSpecialization& specialization,
if (tout == nullptr || !tout->has_list()) return;
// Nothing to do if all outputs are active.
if (specialization.active_outputs.size() == tout->list().type_size()) return;
int specialization_active_outputs_size = specialization.active_outputs.size();
if (specialization_active_outputs_size == tout->list().type_size()) return;
// Clear input types for the specialized node.
auto* attr = specialized_func_node->mutable_attr();
@ -1142,7 +1143,8 @@ void AddFrameForwardingControlEdge(const std::vector<ControlFlowInfo>& info,
Node* caller, Graph* g) {
// All nodes added to the graph by v2 control flow lowering and function
// inlining are guaranteed to have control edges to nested function calls.
if (caller->id() >= info.size()) return;
int info_size = info.size();
if (caller->id() >= info_size ) return;
// Check if a lowered node is executing inside a while loop.
const Node* frame = info[caller->id()].frame;

View File

@ -401,9 +401,10 @@ Status SplitIdentityNInputs(GraphDef* graph,
}
const int num_non_control_inputs = NumNonControlInputs(*node);
int terminal_second_size = terminal.second.size();
if (node->attr().count("T") == 0 ||
node->attr().at("T").list().type_size() != num_non_control_inputs ||
terminal.second.size() >= num_non_control_inputs) {
terminal_second_size >= num_non_control_inputs) {
continue;
}

View File

@ -107,7 +107,8 @@ Status IsNodeOutputPortHostFriendly(const GraphView& graph,
/*include_tensor_values=*/false));
}
const auto& output_properties = properties->GetOutputProperties(node.name());
if (port_id >= output_properties.size()) {
int output_properties_size = output_properties.size();
if (port_id >= output_properties_size) {
LOG(WARNING) << "port_id=" << port_id
<< " but output_properties.size()=" << output_properties.size()
<< "\n"

View File

@ -99,7 +99,8 @@ Status ShapeOptimizer::Optimize(Cluster* cluster, const GrapplerItem& item,
}
const auto& prop =
properties.GetOutputProperties(reduce_indices.node->name());
if (prop.size() <= reduce_indices.port_id) {
int prop_size = prop.size();
if (prop_size <= reduce_indices.port_id) {
continue;
}
const TensorShapeProto& reduction_indices_shape =

View File

@ -357,7 +357,7 @@ void PermuteNodesInPlace(GraphDef* graph, std::vector<int>* permutation,
}
permutation->swap(inv_perm);
}
for (std::size_t n = 0; n + 1 < permutation->size(); ++n) {
for (int n = 0, permutation_size = permutation->size(); n + 1 < permutation_size; ++n) {
while (n != (*permutation)[n]) {
std::size_t r = (*permutation)[n];
graph->mutable_node()->SwapElements(n, r);

View File

@ -63,7 +63,7 @@ bool NodeView::HasFanout(const FaninView& fanout) const {
return false;
} else if (fanout.index() == Graph::kControlSlot) {
return view->fanins_set_.contains({this->node(), Graph::kControlSlot});
} else if (fanout.index() >= view->regular_fanins_.size()) {
} else if (fanout.index() >= static_cast<int>(view->regular_fanins_.size())) {
return false;
}
return view->regular_fanins_[fanout.index()].node_index_ == node_index_;
@ -152,7 +152,8 @@ Status GraphView::CheckAndAddFaninsInternal(NodeView* node_view) {
Graph::kControlSlot);
has_observed_control = true;
} else {
if (fanin_node_view.regular_fanouts_by_port_.size() <
int fanin_node_view_regular_fanouts_by_port_size = fanin_node_view.regular_fanouts_by_port_.size();
if (fanin_node_view_regular_fanouts_by_port_size <
fanin_id.index() + 1) {
fanin_node_view.regular_fanouts_by_port_.resize(fanin_id.index() + 1);
}
@ -197,7 +198,7 @@ bool MutableNodeView::HasFanout(const MutableFaninView& fanout) const {
return false;
} else if (fanout.index() == Graph::kControlSlot) {
return view->fanins_count_.contains({this->node(), Graph::kControlSlot});
} else if (fanout.index() >= view->regular_fanins_.size()) {
} else if (fanout.index() >= static_cast<int>(view->regular_fanins_.size())) {
return false;
}
return view->regular_fanins_[fanout.index()].node_index_ == node_index_;
@ -279,7 +280,8 @@ void Mutation::AddMutation(
void Mutation::RemoveNode(MutableNodeView* node) {
auto& update_index = node->update_index_;
if (update_index != internal::kMissingIndex) {
if (update_index < updated_nodes_.size() - 1) {
int updated_nodes_size = updated_nodes_.size();
if (update_index < updated_nodes_size - 1) {
graph_view_->nodes_[updated_nodes_.back().node_index].update_index_ =
update_index;
std::swap(updated_nodes_[update_index], updated_nodes_.back());
@ -574,7 +576,8 @@ void MutableGraphView::AddFaninsInternal(
--last_pos;
}
} else {
if (fanin_node_view.regular_fanouts_by_port_.size() <
int fanin_node_view_regular_fanouts_by_port_size = fanin_node_view.regular_fanouts_by_port_.size();
if (fanin_node_view_regular_fanouts_by_port_size <
fanin_id.index() + 1) {
fanin_node_view.regular_fanouts_by_port_.resize(fanin_id.index() + 1);
}
@ -852,8 +855,8 @@ template <typename T>
void MutableGraphView::ReplaceNodeFanouts(MutableNodeView* node, T* fanouts) {
node->num_regular_fanouts_ = fanouts->num_regular_fanouts_;
node->regular_fanouts_by_port_ = std::move(fanouts->regular_fanouts_by_port_);
for (int i = 0; i < node->regular_fanouts_by_port_.size(); ++i) {
for (int j = 0; j < node->regular_fanouts_by_port_[i].size(); ++j) {
for (int i = 0, i_max = node->regular_fanouts_by_port_.size(); i < i_max; ++i) {
for (int j = 0, j_max = node->regular_fanouts_by_port_[i].size(); j < j_max; ++j) {
auto& fanout = node->regular_fanouts_by_port_[i][j];
auto* fanout_node_view = fanout.node_view();
auto& fanout_fanin = fanout_node_view->regular_fanins_[fanout.index()];
@ -868,7 +871,7 @@ void MutableGraphView::ReplaceNodeFanouts(MutableNodeView* node, T* fanouts) {
}
}
node->controlled_fanouts_ = std::move(fanouts->controlled_fanouts_);
for (int i = 0; i < node->controlled_fanouts_.size(); ++i) {
for (int i = 0, i_max = node->controlled_fanouts_.size(); i < i_max; ++i) {
auto& fanout = node->controlled_fanouts_[i];
auto* fanout_node_view = fanout.node_view();
auto& fanout_fanin =
@ -1017,7 +1020,8 @@ inline void MutableGraphView::RemoveRegularFaninFanoutInternal(
{&graph_->node(fanin.node_index_), fanin.index()});
auto* fanin_node_view = fanin.node_view();
auto& fanouts = fanin_node_view->regular_fanouts_by_port_[fanin.index()];
if (fanin.fanout_index_ < fanouts.size() - 1) {
int fanouts_size = fanouts.size();
if (fanin.fanout_index_ < fanouts_size - 1) {
// Swap fanout with last fanout in vector, and update it's associated fanin
// index.
MutableFaninView& last_fanout = fanouts.back();
@ -1043,7 +1047,8 @@ inline void MutableGraphView::RemoveRegularFaninFanoutInternal(
break;
}
}
if (last_fanout_index < fanin_node_view->regular_fanouts_by_port_.size()) {
int fanin_node_view_regular_fanouts_by_port_size = fanin_node_view->regular_fanouts_by_port_.size();
if (last_fanout_index < fanin_node_view_regular_fanouts_by_port_size) {
fanin_node_view->regular_fanouts_by_port_.resize(last_fanout_index);
}
}
@ -1052,7 +1057,8 @@ inline void MutableGraphView::AddRegularFaninInternal(
MutableNodeView* node_view, const SafeTensorId& fanin_id) {
MutableNodeView* fanin_node_view = GetNode(fanin_id.node());
// Resize fanouts to include new output port index.
if (fanin_node_view->regular_fanouts_by_port_.size() < fanin_id.index() + 1) {
int fanin_node_view_regular_fanouts_by_port_size = fanin_node_view->regular_fanouts_by_port_.size();
if (fanin_node_view_regular_fanouts_by_port_size < fanin_id.index() + 1) {
fanin_node_view->regular_fanouts_by_port_.resize(fanin_id.index() + 1);
}
@ -1078,7 +1084,8 @@ inline void MutableGraphView::UpdateRegularFaninInternal(
MutableNodeView* fanin_node_view = GetNode(fanin_id.node());
// Resize fanouts to include new output port index.
if (fanin_node_view->regular_fanouts_by_port_.size() < fanin_id.index() + 1) {
int fanin_node_view_regular_fanouts_by_port_size = fanin_node_view->regular_fanouts_by_port_.size();
if (fanin_node_view_regular_fanouts_by_port_size < fanin_id.index() + 1) {
fanin_node_view->regular_fanouts_by_port_.resize(fanin_id.index() + 1);
}
@ -1110,8 +1117,9 @@ inline void MutableGraphView::RemoveControllingFaninFanoutInternal(
// controlled fanout in controlling fanin with controlled fanout to be
// removed.
auto* control_to_remove_view = control_to_remove.node_view();
int control_to_remove_view_controlled_fanouts_size = control_to_remove_view->controlled_fanouts_.size();
if (control_to_remove.fanout_index_ <
control_to_remove_view->controlled_fanouts_.size() - 1) {
control_to_remove_view_controlled_fanouts_size - 1) {
auto& control_to_remove_view_last_control =
control_to_remove_view->controlled_fanouts_.back();
control_to_remove_view_last_control.node_view()
@ -1137,7 +1145,8 @@ inline void MutableGraphView::RemoveControllingFaninInternal(
RemoveControllingFaninFanoutInternal(node_view, control_index);
// Swap last controlling fanin in node with controlling fanin to be removed.
if (control_index < node_view->controlling_fanins_.size() - 1) {
int node_view_controlling_fanins_size = node_view->controlling_fanins_.size();
if (control_index < node_view_controlling_fanins_size - 1) {
auto& last_control = node_view->controlling_fanins_.back();
auto* last_control_view = last_control.node_view();
last_control_view->controlled_fanouts_[last_control.fanout_index_]

View File

@ -172,7 +172,8 @@ class NodeViewInternal {
// Returns a regular fanin based on input index. If no such fanin exist, a
// missing fanin is returned, with no NodeView set and an index of -2.
const FanoutViewT& GetRegularFanin(int i) const {
if (i < 0 || i >= regular_fanins_.size()) {
int regular_fanins_size = regular_fanins_.size();
if (i < 0 || i >= regular_fanins_size) {
return GetMissingFanin();
}
return regular_fanins_[i];
@ -191,7 +192,8 @@ class NodeViewInternal {
// Returns a regular fanout(s) based on output index. If no such output index
// exists, no fanouts will be returned.
const std::vector<FaninViewT>& GetRegularFanout(int i) const {
if (i < 0 || i >= regular_fanouts_by_port_.size()) {
int regular_fanouts_by_port_size = regular_fanouts_by_port_.size();
if (i < 0 || i >= regular_fanouts_by_port_size) {
return GetMissingFanout();
}
return regular_fanouts_by_port_[i];
@ -289,14 +291,16 @@ class GraphViewInternal {
// Finds node by index in the graph. If no such node exists in the graph, a
// `nullptr` is returned.
const NodeViewT* GetNode(int node_index) const {
if (node_index < 0 || node_index >= nodes_.size()) {
int nodes_size = nodes_.size();
if (node_index < 0 || node_index >= nodes_size) {
return nullptr;
}
return &nodes_[node_index];
}
NodeViewT* GetNode(int node_index) {
if (node_index < 0 || node_index >= nodes_.size()) {
int nodes_size = nodes_.size();
if (node_index < 0 || node_index >= nodes_size) {
return nullptr;
}
return &nodes_[node_index];
@ -444,13 +448,14 @@ inline bool UpdateDevice(NodeViewDiff<GraphViewT>* diff,
template <typename T, typename U>
inline bool AddOrUpdateAtIndex(std::vector<T>* v, int i, const U& value,
const T& default_value) {
if (i > v->size()) {
int v_size = v->size();
if (i > v_size) {
// Resize to include `value`, filling the newly introduced gap with
// `default_value` for later checks of validity (gaps in vector).
v->reserve(i + 1);
v->resize(i, default_value);
v->push_back({value});
} else if (i == v->size()) {
} else if (i == v_size) {
// Vector is large enough, simply append `value` to the end.
v->push_back({value});
} else {
@ -494,7 +499,8 @@ inline bool AddOrUpdateRegularFanin(NodeViewDiff<GraphViewT>* diff, int index,
// index from beginning of regular fanins.
const int relative_removal_index = num_regular_fanins - index - 1;
// Check if at relative index fanin was already marked for removal.
if (relative_removal_index < diff->regular_inputs_to_remove.size() &&
int diff_regular_inputs_to_remove_size = diff->regular_inputs_to_remove.size();
if (relative_removal_index < diff_regular_inputs_to_remove_size &&
diff->regular_inputs_to_remove[relative_removal_index]) {
// Unmark fanin for removal.
diff->regular_inputs_to_remove[relative_removal_index] = false;
@ -543,7 +549,8 @@ inline bool RemoveRegularFanin(NodeViewDiff<GraphViewT>* diff, int index) {
} else {
// Relative index from end of regular fanins.
const int relative_add_index = index - num_regular_fanins;
if (relative_add_index >= diff->regular_inputs_to_add.size() ||
int diff_regular_inputs_to_add_size = diff->regular_inputs_to_add.size();
if (relative_add_index >= diff_regular_inputs_to_add_size ||
IsEmptyTensorId(diff->regular_inputs_to_add[relative_add_index])) {
// At relative index, appended regular fanin was already marked for
// removal.
@ -671,7 +678,8 @@ inline bool IsWellFormed(
const absl::flat_hash_map<absl::string_view, int>& updated_node_names) {
ResizeByTrimmingEndForValue(&diff->regular_inputs_to_remove, false);
ResizeByTrimmingEndForValue(&diff->regular_inputs_to_add, EmptyTensorId());
if (diff->regular_inputs_to_add.size() != diff->num_regular_inputs_to_add) {
int diff_regular_inputs_to_add_size = diff->regular_inputs_to_add.size();
if (diff_regular_inputs_to_add_size != diff->num_regular_inputs_to_add) {
// Missing regular fanins in between appended fanins.
return false;
} else if (diff->num_regular_inputs_to_add > 0 &&
@ -679,7 +687,7 @@ inline bool IsWellFormed(
// Appending new fanins while removing existing fanins, resulting in missing
// regular fanins in between.
return false;
} else if (diff->regular_inputs_to_remove.size() !=
} else if ( static_cast<int>(diff->regular_inputs_to_remove.size()) !=
diff->num_regular_inputs_to_remove) {
// Regular fanins exist in between removed fanins.
return false;
@ -830,7 +838,8 @@ inline void AddOrUpdateRegularFanin(NewNode<GraphViewT>* new_node, int index,
// remove existing fanins and updated/added fanins via AddOrUpdateRegularFanins.
template <typename GraphViewT>
inline void RemoveRegularFanin(NewNode<GraphViewT>* new_node, int index) {
if (index < 0 || index >= new_node->regular_fanins.size() ||
int new_node_regular_fanins_size = new_node->regular_fanins.size();
if (index < 0 || index >= new_node_regular_fanins_size ||
IsEmptyTensorId(new_node->regular_fanins[index])) {
return;
}
@ -874,7 +883,8 @@ inline bool IsWellFormed(
NewNode<GraphViewT>* new_node,
const absl::flat_hash_map<absl::string_view, int>& updated_node_names) {
ResizeByTrimmingEndForValue(&new_node->regular_fanins, EmptyTensorId());
if (new_node->regular_fanins.size() != new_node->num_regular_fanins) {
int new_node_regular_fanins_size = new_node->regular_fanins.size();
if (new_node_regular_fanins_size != new_node->num_regular_fanins) {
return false;
}

View File

@ -81,7 +81,7 @@ Status ComputeTopologicalOrder(
int ready_node = (*ready_nodes)[front];
for (int fanout : graph_view.GetFanout(ready_node)) {
++num_ready_inputs[fanout];
if (num_ready_inputs[fanout] == graph_view.GetFanin(fanout).size()) {
if (num_ready_inputs[fanout] == static_cast<int>(graph_view.GetFanin(fanout).size())) {
ready_nodes->push_back(fanout);
++back;
}
@ -95,7 +95,7 @@ Status ComputeTopologicalOrder(
"at node = "
<< graph.node(back).DebugString();
for (int i = 0; i < graph_view.num_nodes(); ++i) {
if (num_ready_inputs[i] != graph_view.GetFanin(i).size()) {
if (num_ready_inputs[i] != static_cast<int>(graph_view.GetFanin(i).size())) {
VLOG(1) << "Node not ready: " << graph.node(i).DebugString();
}
}

View File

@ -68,7 +68,7 @@ Status SqliteQueryConnection::GetNext(IteratorContext* ctx,
Status SqliteQueryConnection::PrepareQuery() {
TF_RETURN_IF_ERROR(db_->Prepare(query_, &stmt_));
int column_count = stmt_.ColumnCount();
size_t column_count = stmt_.ColumnCount();
if (column_count != output_types_.size()) {
stmt_ = SqliteStatement();
return errors::InvalidArgument(tensorflow::strings::Printf(

View File

@ -48,7 +48,7 @@ void ModelAnalyzer::PrintNodeInfo(const NodeDef* node,
if (properties.HasOutputProperties(node->name())) {
const std::vector<OpInfo::TensorProperties>& props =
properties.GetOutputProperties(node->name());
for (int i = 0; i < props.size(); ++i) {
for (int i = 0, props_size = props.size(); i < props_size; ++i) {
const OpInfo::TensorProperties& prop = props[i];
os << "\t"
<< "output " << i << " (" << DataTypeString(prop.dtype())
@ -88,7 +88,7 @@ void ModelAnalyzer::PrintNodeInfo(const NodeDef* node,
} else if (properties.HasInputProperties(node->name())) {
const std::vector<OpInfo::TensorProperties>& props =
properties.GetInputProperties(node->name());
for (int i = 0; i < props.size(); ++i) {
for (int i = 0, props_size = props.size(); i < props_size; ++i) {
const OpInfo::TensorProperties& prop = props[i];
if (prop.has_value()) {
os << "\t"