From dee3d3e6bf81886df0bdc45bac062e6cdaf1c9ef Mon Sep 17 00:00:00 2001 From: dongzhihong Date: Fri, 10 Nov 2017 09:12:51 -0800 Subject: [PATCH 1/2] "fix call once function" --- paddle/platform/call_once.h | 2 +- paddle/platform/dynload/cublas.h | 26 +++++++++++++------------- paddle/platform/dynload/cudnn.h | 26 +++++++++++++------------- paddle/pybind/pybind.cc | 4 ++-- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/paddle/platform/call_once.h b/paddle/platform/call_once.h index 248baf6613c5c..1625efd024847 100644 --- a/paddle/platform/call_once.h +++ b/paddle/platform/call_once.h @@ -38,7 +38,7 @@ inline void call_once(std::once_flag& flag, Callable&& f, Args&&... args) { } catch (const std::exception& e) { ex = e; } catch (...) { - ex = std::runtime_error("excption caught in call_once"); + ex = std::runtime_error("Exception caught in call_once."); } }); if (!good) { diff --git a/paddle/platform/dynload/cublas.h b/paddle/platform/dynload/cublas.h index 6b64539b0a9a4..726b4c495b669 100644 --- a/paddle/platform/dynload/cublas.h +++ b/paddle/platform/dynload/cublas.h @@ -16,7 +16,7 @@ limitations under the License. */ #include #include -#include +#include "paddle/platform/call_once.h" #include "paddle/platform/dynload/dynamic_loader.h" namespace paddle { @@ -34,18 +34,18 @@ extern void *cublas_dso_handle; * note: default dynamic linked libs */ #ifdef PADDLE_USE_DSO -#define DECLARE_DYNAMIC_LOAD_CUBLAS_WRAP(__name) \ - struct DynLoad__##__name { \ - template \ - inline cublasStatus_t operator()(Args... args) { \ - typedef cublasStatus_t (*cublasFunc)(Args...); \ - std::call_once(cublas_dso_flag, \ - paddle::platform::dynload::GetCublasDsoHandle, \ - &cublas_dso_handle); \ - void *p_##__name = dlsym(cublas_dso_handle, #__name); \ - return reinterpret_cast(p_##__name)(args...); \ - } \ - }; \ +#define DECLARE_DYNAMIC_LOAD_CUBLAS_WRAP(__name) \ + struct DynLoad__##__name { \ + template \ + inline cublasStatus_t operator()(Args... args) { \ + typedef cublasStatus_t (*cublasFunc)(Args...); \ + platform::call_once(cublas_dso_flag, \ + paddle::platform::dynload::GetCublasDsoHandle, \ + &cublas_dso_handle); \ + void *p_##__name = dlsym(cublas_dso_handle, #__name); \ + return reinterpret_cast(p_##__name)(args...); \ + } \ + }; \ extern DynLoad__##__name __name #else #define DECLARE_DYNAMIC_LOAD_CUBLAS_WRAP(__name) \ diff --git a/paddle/platform/dynload/cudnn.h b/paddle/platform/dynload/cudnn.h index b2d69da93bcd4..ddb99544795e3 100644 --- a/paddle/platform/dynload/cudnn.h +++ b/paddle/platform/dynload/cudnn.h @@ -16,7 +16,7 @@ limitations under the License. */ #include #include -#include +#include "paddle/platform/call_once.h" #include "paddle/platform/dynload/dynamic_loader.h" namespace paddle { @@ -28,18 +28,18 @@ extern void* cudnn_dso_handle; #ifdef PADDLE_USE_DSO -#define DECLARE_DYNAMIC_LOAD_CUDNN_WRAP(__name) \ - struct DynLoad__##__name { \ - template \ - auto operator()(Args... args) -> decltype(__name(args...)) { \ - using cudnn_func = decltype(__name(args...)) (*)(Args...); \ - std::call_once(cudnn_dso_flag, \ - paddle::platform::dynload::GetCudnnDsoHandle, \ - &cudnn_dso_handle); \ - void* p_##__name = dlsym(cudnn_dso_handle, #__name); \ - return reinterpret_cast(p_##__name)(args...); \ - } \ - }; \ +#define DECLARE_DYNAMIC_LOAD_CUDNN_WRAP(__name) \ + struct DynLoad__##__name { \ + template \ + auto operator()(Args... args) -> decltype(__name(args...)) { \ + using cudnn_func = decltype(__name(args...)) (*)(Args...); \ + platform::call_once(cudnn_dso_flag, \ + paddle::platform::dynload::GetCudnnDsoHandle, \ + &cudnn_dso_handle); \ + void* p_##__name = dlsym(cudnn_dso_handle, #__name); \ + return reinterpret_cast(p_##__name)(args...); \ + } \ + }; \ extern struct DynLoad__##__name __name #else diff --git a/paddle/pybind/pybind.cc b/paddle/pybind/pybind.cc index 0f906e0e470b7..c36f102bdcad6 100644 --- a/paddle/pybind/pybind.cc +++ b/paddle/pybind/pybind.cc @@ -14,7 +14,6 @@ limitations under the License. */ #include "paddle/pybind/protobuf.h" -#include // for call_once #include #include "gflags/gflags.h" #include "paddle/framework/backward.h" @@ -30,6 +29,7 @@ limitations under the License. */ #include "paddle/operators/cond_op.h" #include "paddle/operators/dynamic_recurrent_op.h" #include "paddle/operators/net_op.h" +#include "paddle/platform/call_once.h" #include "paddle/platform/enforce.h" #include "paddle/platform/place.h" #include "paddle/pybind/exception.h" @@ -53,7 +53,7 @@ std::once_flag gflags_init_flag; // TODO(qijun) move init gflags to init.cc void InitGflags(std::vector &argv) { - std::call_once(gflags_init_flag, [&]() { + platform::call_once(gflags_init_flag, [&]() { int argc = argv.size(); char **arr = new char *[argv.size()]; std::string line; From 6982482816adf7afd63e34dcc83eaac6eb2b4bd6 Mon Sep 17 00:00:00 2001 From: dongzhihong Date: Fri, 10 Nov 2017 09:18:18 -0800 Subject: [PATCH 2/2] "fix op_desc" --- paddle/framework/op_desc.cc | 4 ++-- paddle/platform/dynload/curand.h | 26 +++++++++++++------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/paddle/framework/op_desc.cc b/paddle/framework/op_desc.cc index 39c8def82e1eb..5a3748af6d15e 100644 --- a/paddle/framework/op_desc.cc +++ b/paddle/framework/op_desc.cc @@ -14,13 +14,13 @@ limitations under the License. */ #include "paddle/framework/op_desc.h" #include -#include #include #include "glog/logging.h" #include "paddle/framework/block_desc.h" #include "paddle/framework/operator.h" #include "paddle/framework/program_desc.h" #include "paddle/framework/shape_inference.h" +#include "paddle/platform/call_once.h" namespace paddle { namespace framework { @@ -292,7 +292,7 @@ void OpDescBind::Flush() { static std::once_flag init_infer_shape_funcs; static void InitInferShapeFuncs() { - std::call_once(init_infer_shape_funcs, [] { + platform::call_once(init_infer_shape_funcs, [] { auto &map = OpInfoMap::Instance(); auto &info_map = *map.mutable_map(); diff --git a/paddle/platform/dynload/curand.h b/paddle/platform/dynload/curand.h index 7bfe0778c78f6..ceade1302f736 100644 --- a/paddle/platform/dynload/curand.h +++ b/paddle/platform/dynload/curand.h @@ -16,7 +16,7 @@ limitations under the License. */ #include #include -#include +#include "paddle/platform/call_once.h" #include "paddle/platform/dynload/dynamic_loader.h" namespace paddle { @@ -25,18 +25,18 @@ namespace dynload { extern std::once_flag curand_dso_flag; extern void *curand_dso_handle; #ifdef PADDLE_USE_DSO -#define DECLARE_DYNAMIC_LOAD_CURAND_WRAP(__name) \ - struct DynLoad__##__name { \ - template \ - curandStatus_t operator()(Args... args) { \ - typedef curandStatus_t (*curandFunc)(Args...); \ - std::call_once(curand_dso_flag, \ - paddle::platform::dynload::GetCurandDsoHandle, \ - &curand_dso_handle); \ - void *p_##__name = dlsym(curand_dso_handle, #__name); \ - return reinterpret_cast(p_##__name)(args...); \ - } \ - }; \ +#define DECLARE_DYNAMIC_LOAD_CURAND_WRAP(__name) \ + struct DynLoad__##__name { \ + template \ + curandStatus_t operator()(Args... args) { \ + typedef curandStatus_t (*curandFunc)(Args...); \ + platform::call_once(curand_dso_flag, \ + paddle::platform::dynload::GetCurandDsoHandle, \ + &curand_dso_handle); \ + void *p_##__name = dlsym(curand_dso_handle, #__name); \ + return reinterpret_cast(p_##__name)(args...); \ + } \ + }; \ extern DynLoad__##__name __name #else #define DECLARE_DYNAMIC_LOAD_CURAND_WRAP(__name) \