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

modify graph_pattern to thread_local #43942

Merged
merged 2 commits into from
Jun 30, 2022
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
6 changes: 6 additions & 0 deletions paddle/fluid/framework/ir/graph_pattern_detector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ using string::Style;

size_t PDPattern::id_ = 0UL;

#ifdef PADDLE_WITH_TENSORRT
namespace patterns {
thread_local std::unordered_map<std::string, size_t> KeyCounter::dic_;
}
#endif

PDNode *PDPattern::NewNode(const std::string &name) {
if (!name.empty()) {
PADDLE_ENFORCE_EQ(
Expand Down
8 changes: 8 additions & 0 deletions paddle/fluid/framework/ir/graph_pattern_detector.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,18 @@ struct KeyCounter {
return x;
}

#ifdef PADDLE_WITH_TENSORRT
static int IncCounter(const std::string& key) { return dic_[key]++; }
static void CleanCounter() { dic_.clear(); }

private:
static thread_local std::unordered_map<std::string, size_t> dic_;
#else
int IncCounter(const std::string& key) { return dic_[key]++; }

private:
std::unordered_map<std::string, size_t> dic_;
#endif
};

// Generate a unique PDNode's name with name_scope and id.
Expand Down
4 changes: 4 additions & 0 deletions paddle/fluid/inference/api/analysis_predictor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,10 @@ CreatePaddlePredictor<AnalysisConfig, PaddleEngineKind::kAnalysis>(
config.SetInValid();
auto predictor_p = dynamic_cast<AnalysisPredictor *>(predictor.get());

#ifdef PADDLE_WITH_TENSORRT
paddle::framework::ir::patterns::KeyCounter::Instance().CleanCounter();
#endif

if (!predictor_p->Init(nullptr)) {
return nullptr;
}
Expand Down