提交 b085ecc2 编写于 作者: Y Yihua Xu 提交者: Tao Luo

Avoid the string as the key of map to improve the jit performance (#21292)

* Avoid the string as the key of map to improve the jit performance.

test=develop

* Use map to replace unordered_map.

test=develop
上级 95250852
......@@ -22,9 +22,8 @@ namespace paddle {
namespace operators {
namespace jit {
std::unordered_map<std::string, std::shared_ptr<void>>& GetFuncCacheMap() {
static thread_local std::unordered_map<std::string, std::shared_ptr<void>>
g_func_cache_map;
std::map<size_t, std::shared_ptr<void>>& GetFuncCacheMap() {
static thread_local std::map<size_t, std::shared_ptr<void>> g_func_cache_map;
return g_func_cache_map;
}
......
......@@ -15,6 +15,7 @@
#pragma once
#include <iostream>
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
......@@ -176,8 +177,7 @@ typename KernelTuple::func_type GetDefaultBestFunc(
return funcs[0];
}
extern std::unordered_map<std::string, std::shared_ptr<void>>&
GetFuncCacheMap();
extern std::map<size_t, std::shared_ptr<void>>& GetFuncCacheMap();
template <typename KernelTuple, typename PlaceType>
class KernelFuncs {
......@@ -185,7 +185,7 @@ class KernelFuncs {
KernelFuncs() = default;
static KernelFuncs& Cache() {
auto& func_cache_map = GetFuncCacheMap();
std::string key = typeid(KernelFuncs<KernelTuple, PlaceType>).name();
auto key = typeid(KernelFuncs<KernelTuple, PlaceType>).hash_code();
auto iter = func_cache_map.find(key);
if (iter != func_cache_map.end()) {
return *(KernelFuncs<KernelTuple, PlaceType>*)(iter->second.get());
......
......@@ -21,9 +21,8 @@ namespace paddle {
namespace operators {
namespace jit {
std::unordered_map<std::string, std::shared_ptr<void>>& GetJITCodesMap() {
static thread_local std::unordered_map<std::string, std::shared_ptr<void>>
g_jit_codes_map;
std::map<size_t, std::shared_ptr<void>>& GetJITCodesMap() {
static thread_local std::map<size_t, std::shared_ptr<void>> g_jit_codes_map;
return g_jit_codes_map;
}
......
......@@ -14,6 +14,7 @@
#pragma once
#include <map>
#include <memory> // for unique_ptr
#include <string>
#include <unordered_map>
......@@ -28,7 +29,7 @@ namespace paddle {
namespace operators {
namespace jit {
extern std::unordered_map<std::string, std::shared_ptr<void>>& GetJITCodesMap();
extern std::map<size_t, std::shared_ptr<void>>& GetJITCodesMap();
template <KernelType KT>
class JitCodePool {
......@@ -39,7 +40,7 @@ class JitCodePool {
JitCodePool() = default;
static JitCodePool& Instance() {
auto& jit_codes_map = GetJITCodesMap();
std::string key = typeid(JitCodePool<KT>).name();
auto key = typeid(JitCodePool<KT>).hash_code();
auto iter = jit_codes_map.find(key);
if (iter != jit_codes_map.end()) {
return *(JitCodePool<KT>*)(iter->second.get());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册