未验证 提交 6467ca0d 编写于 作者: J JingZhuangzhuang 提交者: GitHub

modify graph_pattern to thread_local (#43942)

* modify graph_pattern to thread_local

* modify graph_pattern to thread_local
上级 c2a5bb91
......@@ -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(
......
......@@ -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.
......
......@@ -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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册