tensorflow/core resolutions, set 2 of 3
This commit is contained in:
parent
3bb28df8d4
commit
8cf0585715
@ -785,8 +785,7 @@ class SymbolicShapeRefiner {
|
|||||||
MutableGraphView gv(&grappler_function_item.graph);
|
MutableGraphView gv(&grappler_function_item.graph);
|
||||||
|
|
||||||
// Forward shapes from function input nodes to argument nodes.
|
// Forward shapes from function input nodes to argument nodes.
|
||||||
for (int i = 0, iter_limit = grappler_function_item.inputs().size();
|
for (int i = 0, end = grappler_function_item.inputs().size(); i < end; ++i) {
|
||||||
i < iter_limit; ++i) {
|
|
||||||
auto& fun_input = grappler_function_item.input(i);
|
auto& fun_input = grappler_function_item.input(i);
|
||||||
NodeDef* fun_node = gv.GetNode(fun_input.node_name);
|
NodeDef* fun_node = gv.GetNode(fun_input.node_name);
|
||||||
const TensorId input_tensor = ParseTensorName(function_node->input(i));
|
const TensorId input_tensor = ParseTensorName(function_node->input(i));
|
||||||
@ -1284,8 +1283,7 @@ class SymbolicShapeRefiner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int i = grappler_function_item.inputs().size(),
|
for (int i = grappler_function_item.inputs().size(),
|
||||||
iter_limit = function_node->input_size();
|
end = function_node->input_size(); i < end; ++i) {
|
||||||
i < iter_limit; ++i) {
|
|
||||||
const string& input = function_node->input(i);
|
const string& input = function_node->input(i);
|
||||||
if (!IsControlInput(input)) {
|
if (!IsControlInput(input)) {
|
||||||
return errors::FailedPrecondition(
|
return errors::FailedPrecondition(
|
||||||
@ -2310,7 +2308,7 @@ Status GraphProperties::UpdateEnqueue(
|
|||||||
|
|
||||||
// TODO(bsteiner): handle EnqueueMany as well.
|
// TODO(bsteiner): handle EnqueueMany as well.
|
||||||
std::vector<ShapeAndType> shapes_and_types;
|
std::vector<ShapeAndType> shapes_and_types;
|
||||||
for (int i = 1, iter_limit = ctx->input_types.size(); i < iter_limit; ++i) {
|
for (int i = 1, end = ctx->input_types.size(); i < end; ++i) {
|
||||||
GraphView::InputPort inp(enqueue_node, i);
|
GraphView::InputPort inp(enqueue_node, i);
|
||||||
GraphView::OutputPort fanin = shape_refiner->graph().GetRegularFanin(inp);
|
GraphView::OutputPort fanin = shape_refiner->graph().GetRegularFanin(inp);
|
||||||
InferenceContext* in = shape_refiner->GetContext(fanin.node);
|
InferenceContext* in = shape_refiner->GetContext(fanin.node);
|
||||||
|
@ -523,8 +523,8 @@ Status SchedulerState::Init(const GrapplerItem* item,
|
|||||||
if (IsPersistent(*curr_node)) {
|
if (IsPersistent(*curr_node)) {
|
||||||
auto& device_state = device_[curr_node_device];
|
auto& device_state = device_[curr_node_device];
|
||||||
for (int port_num = 0,
|
for (int port_num = 0,
|
||||||
port_num_iter_limit = curr_node_state.output_properties.size();
|
port_num_end = curr_node_state.output_properties.size();
|
||||||
port_num < port_num_iter_limit; ++port_num) {
|
port_num < port_num_end; ++port_num) {
|
||||||
device_state.persistent_nodes.insert(
|
device_state.persistent_nodes.insert(
|
||||||
std::make_pair(curr_node, port_num));
|
std::make_pair(curr_node, port_num));
|
||||||
}
|
}
|
||||||
@ -1121,8 +1121,8 @@ void SchedulerState::GenerateRunMetadata(RunMetadata* metadata) {
|
|||||||
const NodeState& nodestate = node_map_.at(node_def);
|
const NodeState& nodestate = node_map_.at(node_def);
|
||||||
NodeExecStats* node_stats = device_stepstats->add_node_stats();
|
NodeExecStats* node_stats = device_stepstats->add_node_stats();
|
||||||
uint64 total_output_size = 0;
|
uint64 total_output_size = 0;
|
||||||
for (int slot = 0, slot_iter_limit = nodestate.output_properties.size();
|
for (int slot = 0, slot_end = nodestate.output_properties.size();
|
||||||
slot < slot_iter_limit; slot++) {
|
slot < slot_end; slot++) {
|
||||||
const auto& properties = nodestate.output_properties[slot];
|
const auto& properties = nodestate.output_properties[slot];
|
||||||
NodeOutput* no = node_stats->add_output();
|
NodeOutput* no = node_stats->add_output();
|
||||||
no->set_slot(slot);
|
no->set_slot(slot);
|
||||||
|
@ -92,7 +92,8 @@ void GraphAnalyzer::FindSubgraphs() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GraphAnalyzer::ExtendSubgraph(Subgraph* parent) {
|
void GraphAnalyzer::ExtendSubgraph(Subgraph* parent) {
|
||||||
bool will_complete = (parent->id().size() + 1 == subgraph_size_);
|
const int parent_id_size_plus_one = parent->id().size() + 1;
|
||||||
|
bool will_complete = (parent_id_size_plus_one == subgraph_size_);
|
||||||
SubgraphPtrSet& sg_set = will_complete ? result_ : partial_;
|
SubgraphPtrSet& sg_set = will_complete ? result_ : partial_;
|
||||||
|
|
||||||
const GenNode* last_all_or_none_node = nullptr;
|
const GenNode* last_all_or_none_node = nullptr;
|
||||||
@ -151,7 +152,8 @@ void GraphAnalyzer::ExtendSubgraphAllOrNone(Subgraph* parent,
|
|||||||
// point in growing it more, can just skip over the rest of the links.
|
// point in growing it more, can just skip over the rest of the links.
|
||||||
for (const auto& link : nbit->second) {
|
for (const auto& link : nbit->second) {
|
||||||
id.insert(link.node);
|
id.insert(link.node);
|
||||||
if (id.size() > subgraph_size_) {
|
const int id_size = id.size();
|
||||||
|
if (id_size > subgraph_size_) {
|
||||||
return; // Too big.
|
return; // Too big.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -177,7 +179,8 @@ void GraphAnalyzer::ExtendSubgraphPortAllOrNone(Subgraph* parent,
|
|||||||
// point in growing it more, can just skip over the rest of the links.
|
// point in growing it more, can just skip over the rest of the links.
|
||||||
for (const auto& link : nbit->second) {
|
for (const auto& link : nbit->second) {
|
||||||
id.insert(link.node);
|
id.insert(link.node);
|
||||||
if (id.size() > subgraph_size_) {
|
const int id_size = id.size();
|
||||||
|
if (id_size > subgraph_size_) {
|
||||||
return; // Too big.
|
return; // Too big.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -198,8 +201,8 @@ void GraphAnalyzer::AddExtendedSubgraph(Subgraph* parent,
|
|||||||
// This subgraph was already found by extending from a different path.
|
// This subgraph was already found by extending from a different path.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const int id_size = id.size();
|
||||||
if (id.size() != subgraph_size_) {
|
if (id_size != subgraph_size_) {
|
||||||
todo_.push_back(sg.get());
|
todo_.push_back(sg.get());
|
||||||
}
|
}
|
||||||
spec_sg_set.insert(std::move(sg));
|
spec_sg_set.insert(std::move(sg));
|
||||||
|
@ -113,7 +113,8 @@ void SigNode::ComputeTopoHash(int distance) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CHECK(topo_hash_.size() == distance);
|
const int64 topo_hash_size = topo_hash_.size();
|
||||||
|
CHECK(topo_hash_size == distance);
|
||||||
|
|
||||||
int prev = distance - 1;
|
int prev = distance - 1;
|
||||||
|
|
||||||
@ -154,7 +155,8 @@ void SigNode::ComputeTopoHash(int distance) {
|
|||||||
|
|
||||||
size_t SigNode::GetTopoHash(int distance) const {
|
size_t SigNode::GetTopoHash(int distance) const {
|
||||||
CHECK(!topo_hash_.empty());
|
CHECK(!topo_hash_.empty());
|
||||||
if (distance >= topo_hash_.size()) {
|
const int64 topo_hash_size = topo_hash_.size();
|
||||||
|
if (distance >= topo_hash_size) {
|
||||||
CHECK(hash_is_final_);
|
CHECK(hash_is_final_);
|
||||||
return topo_hash_.back();
|
return topo_hash_.back();
|
||||||
} else {
|
} else {
|
||||||
@ -393,7 +395,7 @@ void Signature::OrderLinks() {
|
|||||||
int first_idx = -1;
|
int first_idx = -1;
|
||||||
|
|
||||||
int idx;
|
int idx;
|
||||||
for (idx = 0; idx < node->hashed_peers_.size(); ++idx) {
|
for (idx = 0; idx < static_cast<int64>(node->hashed_peers_.size()); ++idx) {
|
||||||
auto& entry = node->hashed_peers_[idx];
|
auto& entry = node->hashed_peers_[idx];
|
||||||
if (entry.link_hash == cur_link_hash) {
|
if (entry.link_hash == cur_link_hash) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -147,7 +147,8 @@ bool SubgraphIterator::NextIfSamePort() {
|
|||||||
if (AtEnd()) {
|
if (AtEnd()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (link_idx_ + 1 < link_map_it_->second.size()) {
|
const int64 link_map_it_second_size = link_map_it_->second.size();
|
||||||
|
if (link_idx_ + 1 < link_map_it_second_size) {
|
||||||
++link_idx_;
|
++link_idx_;
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
@ -174,7 +175,8 @@ void SubgraphIterator::SkipNode() {
|
|||||||
|
|
||||||
bool SubgraphIterator::PropagateNext() {
|
bool SubgraphIterator::PropagateNext() {
|
||||||
// Loops are used to skip over the empty entries.
|
// Loops are used to skip over the empty entries.
|
||||||
while (link_idx_ >= link_map_it_->second.size()) {
|
const int64 link_map_it_second_size = link_map_it_->second.size();
|
||||||
|
while (link_idx_ >= link_map_it_second_size) {
|
||||||
++link_map_it_;
|
++link_map_it_;
|
||||||
while (link_map_it_ == (*id_it_)->links().end()) {
|
while (link_map_it_ == (*id_it_)->links().end()) {
|
||||||
if (++id_it_ == id_->end()) {
|
if (++id_it_ == id_->end()) {
|
||||||
|
@ -598,7 +598,7 @@ class AddOpsRewriteStage : public ArithmeticNodesGroupOptimizerStage {
|
|||||||
std::deque<InputAndShape> add_ops;
|
std::deque<InputAndShape> add_ops;
|
||||||
|
|
||||||
// Prepare leaf AddN nodes for inputs of equal shape
|
// Prepare leaf AddN nodes for inputs of equal shape
|
||||||
for (int i = 0, iter_limit = shapes.size(); i < iter_limit; ++i) {
|
for (int i = 0, end = shapes.size(); i < end; ++i) {
|
||||||
const auto node_name = leaf_node_name(i);
|
const auto node_name = leaf_node_name(i);
|
||||||
const auto& inputs = shape_sig_to_inputs[ShapeSignature(shapes[i])];
|
const auto& inputs = shape_sig_to_inputs[ShapeSignature(shapes[i])];
|
||||||
add_ops.push_back(AddInputsOfSymbolicallyEqualShape(*group.root_node,
|
add_ops.push_back(AddInputsOfSymbolicallyEqualShape(*group.root_node,
|
||||||
@ -750,8 +750,7 @@ class HoistCommonFactorOutOfAggregation : public ArithmeticOptimizerStage {
|
|||||||
ctx().node_map->AddOutput(new_add_node->name(), new_outer_node->name());
|
ctx().node_map->AddOutput(new_add_node->name(), new_outer_node->name());
|
||||||
|
|
||||||
// Hoist non-shared factors up into the new AddN node.
|
// Hoist non-shared factors up into the new AddN node.
|
||||||
for (int i = 0, iter_limit = unique_factors.size(); i < iter_limit;
|
for (int i = 0, end = unique_factors.size(); i < end; ++i) {
|
||||||
++i) {
|
|
||||||
const string& unique_factor_i = unique_factors[i];
|
const string& unique_factor_i = unique_factors[i];
|
||||||
new_add_node->set_input(i, unique_factor_i);
|
new_add_node->set_input(i, unique_factor_i);
|
||||||
ctx().node_map->AddOutput(unique_factor_i, new_add_node->name());
|
ctx().node_map->AddOutput(unique_factor_i, new_add_node->name());
|
||||||
@ -1203,7 +1202,7 @@ class RemoveIdentityTranspose : public ArithmeticOptimizerStage {
|
|||||||
if (a.size() != b.size()) {
|
if (a.size() != b.size()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (int i = 0, iter_limit = a.size(); i < iter_limit; ++i) {
|
for (int i = 0, end = a.size(); i < end; ++i) {
|
||||||
if (a[b[i]] != i) {
|
if (a[b[i]] != i) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1212,7 +1211,7 @@ class RemoveIdentityTranspose : public ArithmeticOptimizerStage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool IsIdentityPermutation(const std::vector<int64>& perm) {
|
bool IsIdentityPermutation(const std::vector<int64>& perm) {
|
||||||
for (int64 i = 0, iter_limit = perm.size(); i < iter_limit; ++i) {
|
for (int64 i = 0, end = perm.size(); i < end; ++i) {
|
||||||
if (i != perm[i]) {
|
if (i != perm[i]) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -3375,7 +3374,7 @@ class RemoveStackSliceSameAxis : public ArithmeticOptimizerStage {
|
|||||||
|
|
||||||
int begin_index = -1;
|
int begin_index = -1;
|
||||||
int64 begin_value = 0;
|
int64 begin_value = 0;
|
||||||
for (int i = 0, iter_limit = slice_begin_vec.size(); i < iter_limit; ++i) {
|
for (int i = 0, end = slice_begin_vec.size(); i < end; ++i) {
|
||||||
const int64 v = slice_begin_vec[i];
|
const int64 v = slice_begin_vec[i];
|
||||||
if (v != 0) {
|
if (v != 0) {
|
||||||
if (begin_index != -1) {
|
if (begin_index != -1) {
|
||||||
@ -3389,7 +3388,7 @@ class RemoveStackSliceSameAxis : public ArithmeticOptimizerStage {
|
|||||||
|
|
||||||
int end_index = -1;
|
int end_index = -1;
|
||||||
int64 end_value = 0;
|
int64 end_value = 0;
|
||||||
for (int i = 0, iter_limit = slice_begin_vec.size(); i < iter_limit; ++i) {
|
for (int i = 0, end = slice_begin_vec.size(); i < end; ++i) {
|
||||||
const int64 v = slice_end_vec[i];
|
const int64 v = slice_end_vec[i];
|
||||||
if (v != pack_output_shape.dim_size(i)) {
|
if (v != pack_output_shape.dim_size(i)) {
|
||||||
if (end_index != -1) {
|
if (end_index != -1) {
|
||||||
|
@ -642,12 +642,12 @@ Status ConstantFolding::MaterializeBroadcastGradientArgs(
|
|||||||
// These extra dims could be equal to 1, in which case there is no
|
// These extra dims could be equal to 1, in which case there is no
|
||||||
// broadcasting. It could also be greater than 1, in which case there would
|
// broadcasting. It could also be greater than 1, in which case there would
|
||||||
// be broadcasting. Since we don't know, we'll just punt.
|
// be broadcasting. Since we don't know, we'll just punt.
|
||||||
for (int i = common_dims, iter_limit = shape1.size(); i < iter_limit; ++i) {
|
for (int i = common_dims, end = shape1.size(); i < end; ++i) {
|
||||||
if (shape1[i] < 0) {
|
if (shape1[i] < 0) {
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = common_dims, iter_limit = shape2.size(); i < iter_limit; ++i) {
|
for (int i = common_dims, end = shape2.size(); i < end; ++i) {
|
||||||
if (shape2[i] < 0) {
|
if (shape2[i] < 0) {
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
@ -1463,7 +1463,7 @@ Status ConstantFolding::FoldNode(NodeDef* node, GraphDef* output_graph,
|
|||||||
VLOG(2) << "Folded node: " << SummarizeNodeDef(*node);
|
VLOG(2) << "Folded node: " << SummarizeNodeDef(*node);
|
||||||
|
|
||||||
NodeDef* constant_output = nullptr;
|
NodeDef* constant_output = nullptr;
|
||||||
for (int i = 0, iter_limit = const_nodes.size(); i < iter_limit; i++) {
|
for (int i = 0, end = const_nodes.size(); i < end; i++) {
|
||||||
NodeDef* const_node = &const_nodes[i];
|
NodeDef* const_node = &const_nodes[i];
|
||||||
VLOG(3) << "Generated constant node: " << SummarizeNodeDef(*const_node);
|
VLOG(3) << "Generated constant node: " << SummarizeNodeDef(*const_node);
|
||||||
if (const_node->name().empty()) {
|
if (const_node->name().empty()) {
|
||||||
|
@ -103,7 +103,7 @@ FunctionDef* CreateMapDefunWrapper(const NodeDef& map_node,
|
|||||||
|
|
||||||
// Set return values to match output names
|
// Set return values to match output names
|
||||||
string output_prefix = strings::StrCat(map_defun_node->name(), ":output:");
|
string output_prefix = strings::StrCat(map_defun_node->name(), ":output:");
|
||||||
for (size_t i = 0; i < vectorized_func->signature().output_arg_size(); ++i) {
|
for (size_t i = 0; i < static_cast<size_t>(vectorized_func->signature().output_arg_size()); ++i) {
|
||||||
const auto& output_arg = vectorized_func->signature().output_arg(i);
|
const auto& output_arg = vectorized_func->signature().output_arg(i);
|
||||||
(*vectorized_func->mutable_ret())[output_arg.name()] =
|
(*vectorized_func->mutable_ret())[output_arg.name()] =
|
||||||
strings::StrCat(output_prefix, i);
|
strings::StrCat(output_prefix, i);
|
||||||
@ -238,7 +238,7 @@ Status AddNewBatchNode(const NodeDef& old_batch_node, const NodeDef& input_node,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < input_shapes.size(); ++i) {
|
for (size_t i = 0, end = input_shapes.size(); i < end; ++i) {
|
||||||
// Note: We already checked earlier that input shapes are all fully defined.
|
// Note: We already checked earlier that input shapes are all fully defined.
|
||||||
TensorShapeProto* shape = output_shapes_attr.mutable_list()->add_shape();
|
TensorShapeProto* shape = output_shapes_attr.mutable_list()->add_shape();
|
||||||
TensorShapeProto_Dim* dim = shape->add_dim();
|
TensorShapeProto_Dim* dim = shape->add_dim();
|
||||||
|
@ -87,7 +87,7 @@ class ParseSingleExampleVectorizer : public Vectorizer {
|
|||||||
TF_RETURN_IF_ERROR(node_builder.Finalize(outer_scope, &new_node));
|
TF_RETURN_IF_ERROR(node_builder.Finalize(outer_scope, &new_node));
|
||||||
|
|
||||||
// Add output mappings
|
// Add output mappings
|
||||||
for (size_t i = 0; i < node.num_outputs(); ++i) {
|
for (int i = 0; i < node.num_outputs(); ++i) {
|
||||||
outputs->emplace_back(new_node, i, true);
|
outputs->emplace_back(new_node, i, true);
|
||||||
}
|
}
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
|
@ -251,7 +251,7 @@ Status Vectorization::AddConversionMapping(Node* op_node) {
|
|||||||
|
|
||||||
// The inputs for the node to be converted may already have been converted
|
// The inputs for the node to be converted may already have been converted
|
||||||
// themselves. For those that are not, we promote them to MapDefun outputs.
|
// themselves. For those that are not, we promote them to MapDefun outputs.
|
||||||
for (size_t i = 0; i < op_node->num_inputs(); ++i) {
|
for (int i = 0; i < op_node->num_inputs(); ++i) {
|
||||||
auto edge = input_edges[i];
|
auto edge = input_edges[i];
|
||||||
if (auto found = gtl::FindOrNull(conversion_map_,
|
if (auto found = gtl::FindOrNull(conversion_map_,
|
||||||
{edge->src(), edge->src_output()})) {
|
{edge->src(), edge->src_output()})) {
|
||||||
@ -279,15 +279,15 @@ Status Vectorization::AddConversionMapping(Node* op_node) {
|
|||||||
<< "\" failed with error: " << s;
|
<< "\" failed with error: " << s;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
const int64 op_node_num_outputs = op_node->num_outputs();
|
||||||
if (op_node->num_outputs() != outputs.size()) {
|
if (op_node_num_outputs != outputs.size()) {
|
||||||
return errors::Internal(
|
return errors::Internal(
|
||||||
"Number of vectorizer outputs does not match. Expected: ",
|
"Number of vectorizer outputs does not match. Expected: ",
|
||||||
op_node->num_outputs(), " Actual: ", outputs.size());
|
op_node->num_outputs(), " Actual: ", outputs.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add output mappings.
|
// Add output mappings.
|
||||||
for (size_t i = 0; i < op_node->num_outputs(); ++i) {
|
for (int i = 0; i < op_node->num_outputs(); ++i) {
|
||||||
conversion_map_.insert({{op_node, i}, outputs[i]});
|
conversion_map_.insert({{op_node, i}, outputs[i]});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -521,7 +521,7 @@ Status Vectorization::AddArgTensorMappings() {
|
|||||||
|
|
||||||
// Captured inputs. These are applied (without slicing) to every iteration of
|
// Captured inputs. These are applied (without slicing) to every iteration of
|
||||||
// the map function, hence are mapped to unstacked nodes.
|
// the map function, hence are mapped to unstacked nodes.
|
||||||
for (int i = num_args; i < map_defun_fn_->arg_nodes.size(); ++i) {
|
for (int i = num_args, end = map_defun_fn_->arg_nodes.size(); i < end; ++i) {
|
||||||
TF_RETURN_IF_ERROR(add_conversion(map_defun_fn_->arg_nodes[i], false));
|
TF_RETURN_IF_ERROR(add_conversion(map_defun_fn_->arg_nodes[i], false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,7 +242,7 @@ Status Transposer::CreateConstPermNode(TransposeContext* context,
|
|||||||
|
|
||||||
AttrValue attr_tensor;
|
AttrValue attr_tensor;
|
||||||
Tensor tensor(DT_INT32, TensorShape({4}));
|
Tensor tensor(DT_INT32, TensorShape({4}));
|
||||||
for (int i = 0, iter_limit = permutation.size(); i < iter_limit; i++) {
|
for (int i = 0, end = permutation.size(); i < end; i++) {
|
||||||
tensor.flat<int>()(i) = permutation[i];
|
tensor.flat<int>()(i) = permutation[i];
|
||||||
}
|
}
|
||||||
tensor.AsProtoTensorContent(attr_tensor.mutable_tensor());
|
tensor.AsProtoTensorContent(attr_tensor.mutable_tensor());
|
||||||
@ -1567,8 +1567,7 @@ Status StridedSliceTransposer::PermuteMask(TransposeContext* context,
|
|||||||
return errors::InvalidArgument("invalid mask value: ", mask_i);
|
return errors::InvalidArgument("invalid mask value: ", mask_i);
|
||||||
}
|
}
|
||||||
int result = 0;
|
int result = 0;
|
||||||
for (int i = 0, iter_limit = context->src_to_dst.size(); i < iter_limit;
|
for (int i = 0, end = context->src_to_dst.size(); i < end; i++) {
|
||||||
i++) {
|
|
||||||
const int final_pos = context->src_to_dst[i];
|
const int final_pos = context->src_to_dst[i];
|
||||||
const int position_mask = 1 << final_pos;
|
const int position_mask = 1 << final_pos;
|
||||||
const int bit_i = (mask_i & position_mask) >> final_pos;
|
const int bit_i = (mask_i & position_mask) >> final_pos;
|
||||||
|
@ -521,7 +521,7 @@ class UnaryElementwiseRewriter : public ScopedAllocatorOptimizer::Rewriter {
|
|||||||
|
|
||||||
// Add control edges from the ScopedAllocatorOp to all of the
|
// Add control edges from the ScopedAllocatorOp to all of the
|
||||||
// input nodes and mark them for allocation from backing tensor.
|
// input nodes and mark them for allocation from backing tensor.
|
||||||
for (int i = 0, iter_limit = inputs.size(); i < iter_limit; ++i) {
|
for (int i = 0, end = inputs.size(); i < end; ++i) {
|
||||||
auto& nd = inputs[i];
|
auto& nd = inputs[i];
|
||||||
if (IsArg(*nd.from_node_def)) {
|
if (IsArg(*nd.from_node_def)) {
|
||||||
return errors::Internal(
|
return errors::Internal(
|
||||||
@ -548,8 +548,7 @@ class UnaryElementwiseRewriter : public ScopedAllocatorOptimizer::Rewriter {
|
|||||||
std::vector<InputDesc> inputs_to_first;
|
std::vector<InputDesc> inputs_to_first;
|
||||||
LOG_WARNING_AND_RETURN_IF_ERROR(GetDataInputs(
|
LOG_WARNING_AND_RETURN_IF_ERROR(GetDataInputs(
|
||||||
graph, sa_opti->node_map(), nd.from_node_def, &inputs_to_first));
|
graph, sa_opti->node_map(), nd.from_node_def, &inputs_to_first));
|
||||||
for (int i = 0, iter_limit = inputs_to_first.size(); i < iter_limit;
|
for (int i = 0, end = inputs_to_first.size(); i < end; ++i) {
|
||||||
++i) {
|
|
||||||
if (fanout.find(inputs_to_first[i].from_node_def) != fanout.end()) {
|
if (fanout.find(inputs_to_first[i].from_node_def) != fanout.end()) {
|
||||||
VLOG(2) << "Found node " << inputs_to_first[i].from_node_def->name()
|
VLOG(2) << "Found node " << inputs_to_first[i].from_node_def->name()
|
||||||
<< " in the fanout of " << sa_name;
|
<< " in the fanout of " << sa_name;
|
||||||
@ -589,7 +588,7 @@ class UnaryElementwiseRewriter : public ScopedAllocatorOptimizer::Rewriter {
|
|||||||
VLOG(2) << "BuildSAConcatNode " << sac_name;
|
VLOG(2) << "BuildSAConcatNode " << sac_name;
|
||||||
// control input: edge name -> source node name
|
// control input: edge name -> source node name
|
||||||
absl::flat_hash_map<string, string> sac_ctl_inputs;
|
absl::flat_hash_map<string, string> sac_ctl_inputs;
|
||||||
for (int i = 0, iter_limit = ops.size(); i < iter_limit; ++i) {
|
for (int i = 0, end = ops.size(); i < end; ++i) {
|
||||||
NodeDef* old_op = ops[i];
|
NodeDef* old_op = ops[i];
|
||||||
for (const string& old_op_input : old_op->input()) {
|
for (const string& old_op_input : old_op->input()) {
|
||||||
int position = 0;
|
int position = 0;
|
||||||
|
@ -313,7 +313,8 @@ Status ReplaceInputWithConst(const NodeDef& input_const, int input_index,
|
|||||||
return errors::InvalidArgument("Input node is not a constant: ",
|
return errors::InvalidArgument("Input node is not a constant: ",
|
||||||
SummarizeNodeDef(input_const));
|
SummarizeNodeDef(input_const));
|
||||||
}
|
}
|
||||||
if (input_index < 0 || input_index >= item->input_size()) {
|
const int item_input_size = item->input_size();
|
||||||
|
if (input_index < 0 || input_index >= item_input_size) {
|
||||||
return errors::InvalidArgument(
|
return errors::InvalidArgument(
|
||||||
"Function input index is out of bound: index=", input_index,
|
"Function input index is out of bound: index=", input_index,
|
||||||
" input_size=", item->input_size());
|
" input_size=", item->input_size());
|
||||||
@ -354,7 +355,8 @@ Status RemoveFunctionOutputs(const absl::flat_hash_set<int>& remove_outputs,
|
|||||||
|
|
||||||
// Do some sanity checking of the removed outputs positions.
|
// Do some sanity checking of the removed outputs positions.
|
||||||
for (int remove_output : remove_outputs) {
|
for (int remove_output : remove_outputs) {
|
||||||
if (remove_output < 0 || remove_output >= item->output_size()) {
|
const int item_output_size = item->output_size();
|
||||||
|
if (remove_output < 0 || remove_output >= item_output_size) {
|
||||||
return errors::InvalidArgument(
|
return errors::InvalidArgument(
|
||||||
"Function output index is out of bound: index=", remove_output,
|
"Function output index is out of bound: index=", remove_output,
|
||||||
" output_size=", item->output_size());
|
" output_size=", item->output_size());
|
||||||
@ -366,7 +368,7 @@ Status RemoveFunctionOutputs(const absl::flat_hash_set<int>& remove_outputs,
|
|||||||
return remove_output_args.find(&output) != remove_output_args.end();
|
return remove_output_args.find(&output) != remove_output_args.end();
|
||||||
};
|
};
|
||||||
|
|
||||||
for (int i = 0; i < item->output_size(); ++i) {
|
for (int i = 0, end = item->output_size(); i < end; ++i) {
|
||||||
const OutputArgInstantiation& output = item->output(i);
|
const OutputArgInstantiation& output = item->output(i);
|
||||||
if (remove_outputs.contains(i)) {
|
if (remove_outputs.contains(i)) {
|
||||||
VLOG(3) << "Remove functions output: name=" << output.node_name
|
VLOG(3) << "Remove functions output: name=" << output.node_name
|
||||||
@ -580,7 +582,7 @@ Status MakeFunctionDef(const GrapplerFunctionItem& item,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Copy function arg attributes.
|
// Copy function arg attributes.
|
||||||
for (int i = 0; i < item.arg_attr().size(); ++i) {
|
for (int i = 0, end = item.arg_attr().size(); i < end; ++i) {
|
||||||
const auto* attr = item.arg_attr().at(i);
|
const auto* attr = item.arg_attr().at(i);
|
||||||
if (attr != nullptr) {
|
if (attr != nullptr) {
|
||||||
(*func->mutable_arg_attr())[i] = *attr;
|
(*func->mutable_arg_attr())[i] = *attr;
|
||||||
|
@ -424,7 +424,8 @@ void BoostedTreesEnsembleResource::PostPruneTree(const int32 current_tree,
|
|||||||
->mutable_post_pruned_nodes_meta();
|
->mutable_post_pruned_nodes_meta();
|
||||||
|
|
||||||
for (int32 i = 0; i < num_nodes; ++i) {
|
for (int32 i = 0; i < num_nodes; ++i) {
|
||||||
if (index_for_deleted < nodes_to_delete.size() &&
|
const int64 nodes_to_delete_size = nodes_to_delete.size();
|
||||||
|
if (index_for_deleted < nodes_to_delete_size &&
|
||||||
i == nodes_to_delete[index_for_deleted]) {
|
i == nodes_to_delete[index_for_deleted]) {
|
||||||
// Node i will get removed,
|
// Node i will get removed,
|
||||||
++index_for_deleted;
|
++index_for_deleted;
|
||||||
@ -455,7 +456,8 @@ void BoostedTreesEnsembleResource::PostPruneTree(const int32 current_tree,
|
|||||||
protobuf::RepeatedPtrField<boosted_trees::Node> new_nodes;
|
protobuf::RepeatedPtrField<boosted_trees::Node> new_nodes;
|
||||||
new_nodes.Reserve(old_to_new_ids.size());
|
new_nodes.Reserve(old_to_new_ids.size());
|
||||||
for (auto node : *(tree->mutable_nodes())) {
|
for (auto node : *(tree->mutable_nodes())) {
|
||||||
if (index_for_deleted < nodes_to_delete.size() &&
|
const int64 nodes_to_delete_size = nodes_to_delete.size();
|
||||||
|
if (index_for_deleted < nodes_to_delete_size &&
|
||||||
i == nodes_to_delete[index_for_deleted]) {
|
i == nodes_to_delete[index_for_deleted]) {
|
||||||
++index_for_deleted;
|
++index_for_deleted;
|
||||||
++i;
|
++i;
|
||||||
@ -570,7 +572,7 @@ void BoostedTreesEnsembleResource::RecursivelyDoPostPrunePreparation(
|
|||||||
if (node_metadata.has_original_leaf()) {
|
if (node_metadata.has_original_leaf()) {
|
||||||
parent_values = node_value(tree_id, node_id);
|
parent_values = node_value(tree_id, node_id);
|
||||||
}
|
}
|
||||||
for (int32 i = 0; i < parent_values.size(); ++i) {
|
for (int32 i = 0, end = parent_values.size(); i < end; ++i) {
|
||||||
nodes_meta->at(left_id).second.emplace_back(parent_values[i] -
|
nodes_meta->at(left_id).second.emplace_back(parent_values[i] -
|
||||||
left_child_values[i]);
|
left_child_values[i]);
|
||||||
nodes_meta->at(right_id).second.emplace_back(parent_values[i] -
|
nodes_meta->at(right_id).second.emplace_back(parent_values[i] -
|
||||||
|
@ -216,7 +216,7 @@ Status CreateShortCircuitInfo(OpKernelConstruction* ctx,
|
|||||||
last_use[indices[i]] = i;
|
last_use[indices[i]] = i;
|
||||||
}
|
}
|
||||||
can_move.resize(indices.size());
|
can_move.resize(indices.size());
|
||||||
for (int i = 0, iter_limit = indices.size(); i < iter_limit; ++i) {
|
for (int i = 0, end = indices.size(); i < end; ++i) {
|
||||||
can_move[i] = last_use[indices[i]] == i;
|
can_move[i] = last_use[indices[i]] == i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -663,8 +663,7 @@ Status CapturedFunction::Instantiate(
|
|||||||
inst_opts.composite_devices[it.first] = &it.second;
|
inst_opts.composite_devices[it.first] = &it.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0, iter_limit = fdef->signature().output_arg_size();
|
for (int i = 0, end = fdef->signature().output_arg_size(); i < end; ++i) {
|
||||||
i < iter_limit; ++i) {
|
|
||||||
inst_opts.output_devices.push_back(inst_opts.target);
|
inst_opts.output_devices.push_back(inst_opts.target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,7 +215,7 @@ Status CustomWriter::WriteTensors(const std::vector<Tensor>& tensors) {
|
|||||||
tensor_protos.reserve(num_complex_);
|
tensor_protos.reserve(num_complex_);
|
||||||
experimental::SnapshotTensorMetadata metadata;
|
experimental::SnapshotTensorMetadata metadata;
|
||||||
int64 total_size = 0;
|
int64 total_size = 0;
|
||||||
for (int i = 0; i < tensors.size(); ++i) {
|
for (int i = 0, end = tensors.size(); i < end; ++i) {
|
||||||
const Tensor& tensor = tensors[i];
|
const Tensor& tensor = tensors[i];
|
||||||
experimental::TensorMetadata* tensor_metadata =
|
experimental::TensorMetadata* tensor_metadata =
|
||||||
metadata.add_tensor_metadata();
|
metadata.add_tensor_metadata();
|
||||||
@ -239,7 +239,7 @@ Status CustomWriter::WriteTensors(const std::vector<Tensor>& tensors) {
|
|||||||
char* position = uncompressed.data();
|
char* position = uncompressed.data();
|
||||||
int buffer_index = 0;
|
int buffer_index = 0;
|
||||||
int proto_index = 0;
|
int proto_index = 0;
|
||||||
for (int i = 0; i < tensors.size(); ++i) {
|
for (int i = 0, end = tensors.size(); i < end; ++i) {
|
||||||
const auto& tensor_metadata = metadata.tensor_metadata(i);
|
const auto& tensor_metadata = metadata.tensor_metadata(i);
|
||||||
if (simple_tensor_mask_[i]) {
|
if (simple_tensor_mask_[i]) {
|
||||||
memcpy(position, tensor_buffers[buffer_index]->data(),
|
memcpy(position, tensor_buffers[buffer_index]->data(),
|
||||||
@ -514,7 +514,8 @@ class Reader::NestedDataset : public DatasetBase {
|
|||||||
Status GetNextInternal(IteratorContext* ctx,
|
Status GetNextInternal(IteratorContext* ctx,
|
||||||
std::vector<Tensor>* out_tensors,
|
std::vector<Tensor>* out_tensors,
|
||||||
bool* end_of_sequence) override {
|
bool* end_of_sequence) override {
|
||||||
*end_of_sequence = dataset()->datasets_.size() == index_;
|
const int64 dataset_datasets_size = dataset()->datasets_.size();
|
||||||
|
*end_of_sequence = dataset_datasets_size == index_;
|
||||||
if (!*end_of_sequence) {
|
if (!*end_of_sequence) {
|
||||||
Tensor tensor(DT_VARIANT, TensorShape({}));
|
Tensor tensor(DT_VARIANT, TensorShape({}));
|
||||||
|
|
||||||
@ -704,7 +705,7 @@ Status CustomReader::ReadTensors(std::vector<Tensor>* read_tensors) {
|
|||||||
|
|
||||||
int simple_index = 0;
|
int simple_index = 0;
|
||||||
int complex_index = 0;
|
int complex_index = 0;
|
||||||
for (int i = 0; i < simple_tensor_mask_.size(); ++i) {
|
for (int i = 0, end = simple_tensor_mask_.size(); i < end; ++i) {
|
||||||
if (simple_tensor_mask_[i]) {
|
if (simple_tensor_mask_[i]) {
|
||||||
read_tensors->push_back(std::move(simple_tensors[simple_index]));
|
read_tensors->push_back(std::move(simple_tensors[simple_index]));
|
||||||
simple_index++;
|
simple_index++;
|
||||||
@ -774,7 +775,7 @@ Status CustomReader::SnappyUncompress(
|
|||||||
std::vector<struct iovec> iov(num_tensors);
|
std::vector<struct iovec> iov(num_tensors);
|
||||||
int index = 0;
|
int index = 0;
|
||||||
int64 total_size = 0;
|
int64 total_size = 0;
|
||||||
for (int i = 0; i < simple_tensor_mask_.size(); ++i) {
|
for (int i = 0, end = simple_tensor_mask_.size(); i < end; ++i) {
|
||||||
const auto& tensor_metadata = metadata->tensor_metadata(i);
|
const auto& tensor_metadata = metadata->tensor_metadata(i);
|
||||||
if (simple_tensor_mask_[i]) {
|
if (simple_tensor_mask_[i]) {
|
||||||
TensorShape shape(tensor_metadata.tensor_shape());
|
TensorShape shape(tensor_metadata.tensor_shape());
|
||||||
@ -794,7 +795,8 @@ Status CustomReader::SnappyUncompress(
|
|||||||
total_size += iov[index].iov_len;
|
total_size += iov[index].iov_len;
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
if (size != total_size) {
|
const int64 size_int = size;
|
||||||
|
if (size_int != total_size) {
|
||||||
return errors::Internal("Uncompressed size mismatch. Snappy expects ", size,
|
return errors::Internal("Uncompressed size mismatch. Snappy expects ", size,
|
||||||
" whereas the tensor metadata suggests ",
|
" whereas the tensor metadata suggests ",
|
||||||
total_size);
|
total_size);
|
||||||
@ -905,7 +907,7 @@ Status DetermineOpState(const std::string& mode_string, bool file_exists,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (metadata->creation_timestamp() >=
|
if (metadata->creation_timestamp() >=
|
||||||
(static_cast<int64>(EnvTime::NowMicros()) -
|
static_cast<int64>(static_cast<int64>(EnvTime::NowMicros()) -
|
||||||
pending_snapshot_expiry_seconds * 1000000)) {
|
pending_snapshot_expiry_seconds * 1000000)) {
|
||||||
// Someone else is already writing and time has not expired.
|
// Someone else is already writing and time has not expired.
|
||||||
*mode = PASSTHROUGH;
|
*mode = PASSTHROUGH;
|
||||||
|
@ -84,7 +84,7 @@ void RangeSampler::SampleBatchGetExpectedCountAvoid(
|
|||||||
int num_tries;
|
int num_tries;
|
||||||
|
|
||||||
if (unique) {
|
if (unique) {
|
||||||
CHECK_LE(batch_size + avoided_values.size(), range_);
|
CHECK_LE( static_cast<int64>(batch_size + avoided_values.size()), range_);
|
||||||
std::unordered_set<int64> used(batch_size);
|
std::unordered_set<int64> used(batch_size);
|
||||||
used.insert(avoided_values.begin(), avoided_values.end());
|
used.insert(avoided_values.begin(), avoided_values.end());
|
||||||
int num_picked = 0;
|
int num_picked = 0;
|
||||||
|
@ -970,11 +970,10 @@ RemoteFusedGraphExecuteUtils::BuildRemoteFusedGraphExecuteOpNode(
|
|||||||
border_inputs, border_outputs, require_shape_type, &graph, &fused_node));
|
border_inputs, border_outputs, require_shape_type, &graph, &fused_node));
|
||||||
|
|
||||||
for (const Node* node : graph.nodes()) {
|
for (const Node* node : graph.nodes()) {
|
||||||
for (int i = 0, iter_limit = node->num_inputs(); i < iter_limit; ++i) {
|
for (int i = 0, end = node->num_inputs(); i < end; ++i) {
|
||||||
const Edge* edge = nullptr;
|
const Edge* edge = nullptr;
|
||||||
TF_RETURN_IF_ERROR(node->input_edge(i, &edge));
|
TF_RETURN_IF_ERROR(node->input_edge(i, &edge));
|
||||||
for (int j = 0, second_iter_limit = border_outputs.size();
|
for (int j = 0, second_end = border_outputs.size(); j < second_end; ++j) {
|
||||||
j < second_iter_limit; ++j) {
|
|
||||||
const string& output = border_outputs.at(j);
|
const string& output = border_outputs.at(j);
|
||||||
const TensorId tid = ParseTensorName(output);
|
const TensorId tid = ParseTensorName(output);
|
||||||
const string output_name(tid.first);
|
const string output_name(tid.first);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user