From 728e7e88fb2c3467f6e28ef968b4e720d290b26c Mon Sep 17 00:00:00 2001 From: minqiyang Date: Mon, 17 Dec 2018 13:37:57 +0800 Subject: [PATCH] Use xxHash as scope's hash algorithm test=develop --- paddle/fluid/framework/CMakeLists.txt | 2 +- paddle/fluid/framework/scope.cc | 2 +- paddle/fluid/framework/scope.h | 26 ++++++++++++++++++++------ python/paddle/fluid/profiler.py | 2 +- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/paddle/fluid/framework/CMakeLists.txt b/paddle/fluid/framework/CMakeLists.txt index cea4a4485..5dca5ac59 100644 --- a/paddle/fluid/framework/CMakeLists.txt +++ b/paddle/fluid/framework/CMakeLists.txt @@ -82,7 +82,7 @@ cc_test(variable_test SRCS variable_test.cc) cc_library(threadpool SRCS threadpool.cc DEPS enforce) cc_test(threadpool_test SRCS threadpool_test.cc DEPS threadpool) -cc_library(scope SRCS scope.cc DEPS glog threadpool) +cc_library(scope SRCS scope.cc DEPS glog threadpool xxhash) cc_test(scope_test SRCS scope_test.cc DEPS scope) cc_library(data_device_transform SRCS data_device_transform.cc DEPS tensor) diff --git a/paddle/fluid/framework/scope.cc b/paddle/fluid/framework/scope.cc index b1abe75d7..4f79d9826 100644 --- a/paddle/fluid/framework/scope.cc +++ b/paddle/fluid/framework/scope.cc @@ -201,7 +201,7 @@ void Scope::RenameInternal(const std::string& origin_name, auto new_it = vars_.find(new_name); PADDLE_ENFORCE(new_it == vars_.end(), "The variable with name %s is already in the scope", new_name); - vars_[new_name].reset(origin_it.value().release()); + vars_[new_name].reset(origin_it->second.release()); vars_.erase(origin_it); } diff --git a/paddle/fluid/framework/scope.h b/paddle/fluid/framework/scope.h index b232d267d..77ef18414 100644 --- a/paddle/fluid/framework/scope.h +++ b/paddle/fluid/framework/scope.h @@ -14,15 +14,18 @@ limitations under the License. */ #pragma once +extern "C" { +#include +} + #include #include #include #include +#include #include #include -#include // NOLINT - #include "paddle/fluid/framework/rw_lock.h" #include "paddle/fluid/framework/variable.h" #include "paddle/fluid/platform/macros.h" @@ -35,6 +38,14 @@ bool IsFastEagerDeletionModeEnabled(); class Scope; +namespace inner { +struct KeyHasher { + std::size_t operator()(const std::string& key) const { + return XXH32(key.c_str(), key.size(), 1); + } +}; +} // namespace inner + /** * @brief Scope that manage all variables. * @@ -99,11 +110,14 @@ class Scope { std::string Rename(const std::string& origin_name) const; protected: - mutable tsl::robin_map< - std::string, std::unique_ptr, std::hash, - std::equal_to, - std::allocator>>, true> + mutable std::unordered_map, + inner::KeyHasher> vars_; + // mutable tsl::robin_map< + // std::string, std::unique_ptr, std::hash, + // std::equal_to, + // std::allocator>>, true> + // vars_; private: // Call Scope::NewScope for a sub-scope. diff --git a/python/paddle/fluid/profiler.py b/python/paddle/fluid/profiler.py index 8df2e01b0..78f7a6ac0 100644 --- a/python/paddle/fluid/profiler.py +++ b/python/paddle/fluid/profiler.py @@ -93,7 +93,7 @@ def cuda_profiler(output_file, output_mode=None, config=None): with open(config_file, 'wb') as fp: fp.writelines([six.b("%s\n" % item) for item in config]) #Comment this for nvprof - #core.nvprof_init(output_file, output_mode, config_file) + core.nvprof_init(output_file, output_mode, config_file) # Enables profiler collection by the active CUDA profiling tool. core.nvprof_start() yield -- GitLab