Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use dynamic programming in OpGraph::HasConsumersInOtherStage #5475

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions dali/pipeline/graph/graph_descr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -666,21 +666,25 @@ std::vector<TensorNodeId> OpGraph::FollowPassThroughUp(OpNodeId op, TensorNodeId


bool OpGraph::HasConsumersInOtherStage(const TensorNode &tensor, OpType this_stage) const {
auto it = has_consumers_in_other_stage_.find(tensor.id);
if (it != has_consumers_in_other_stage_.end())
return it->second;
bool &res = has_consumers_in_other_stage_[tensor.id];
for (const auto& cons_edge : tensor.consumers) {
// We found a consumer from different stage, this tensor is a stage output
const OpNode &cons_op = Node(cons_edge.node);
if (cons_op.op_type != this_stage) {
return true;
return (res = true);
}
const OpSchema &schema = cons_op.spec.GetSchema();
// note, that out_idxs may be empty
auto out_idxs = schema.GetPassThroughOutputIdx(cons_edge.index, cons_op.spec);
for (int out_idx : out_idxs) {
if (HasConsumersInOtherStage(Tensor(cons_op.children_tensors[out_idx]), this_stage))
return true;
return (res = true);
}
}
return false;
return (res = false);
}

std::vector<TensorNodeId> OpGraph::GetStageOutputs(OpType stage) const {
Expand Down
3 changes: 2 additions & 1 deletion dali/pipeline/graph/op_graph.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2017-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// Copyright (c) 2017-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -468,6 +468,7 @@ class DLL_PUBLIC OpGraph {
void RemoveOpNode(OpNodeId id);

std::map<std::string, TensorNodeId> tensor_name_to_id_;
mutable std::map<TensorNodeId, bool> has_consumers_in_other_stage_;

bool pass_through_computed_ = false;
};
Expand Down
Loading