move to dynload directory

gangliao-patch-1
qijun 8 years ago
parent 9eeabe986d
commit 3567ea6d7c

@ -1,6 +1,6 @@
add_subdirectory(dynload)
nv_test(cuda_test SRCS cuda_test.cu) nv_test(cuda_test SRCS cuda_test.cu)
cc_library(place SRCS place.cc) cc_library(place SRCS place.cc)
cc_test(place_test SRCS place_test.cc DEPS place glog gflags) cc_test(place_test SRCS place_test.cc DEPS place glog gflags)
cc_library(dynamic_loader SRCS dynamic_loader.cc DEPS glog gflags)

@ -0,0 +1 @@
cc_library(dynamic_loader SRCS dynamic_loader.cc DEPS glog gflags)

@ -19,7 +19,7 @@ limitations under the License. */
namespace paddle { namespace paddle {
namespace platform { namespace platform {
namespace dyload { namespace dynload {
std::once_flag cublas_dso_flag; std::once_flag cublas_dso_flag;
void *cublas_dso_handle = nullptr; void *cublas_dso_handle = nullptr;
@ -32,17 +32,17 @@ void *cublas_dso_handle = nullptr;
* note: default dynamic linked libs * note: default dynamic linked libs
*/ */
#ifdef PADDLE_USE_DSO #ifdef PADDLE_USE_DSO
#define DYNAMIC_LOAD_CUBLAS_WRAP(__name) \ #define DYNAMIC_LOAD_CUBLAS_WRAP(__name) \
struct DynLoad__##__name { \ struct DynLoad__##__name { \
template <typename... Args> \ template <typename... Args> \
cublasStatus_t operator()(Args... args) { \ cublasStatus_t operator()(Args... args) { \
typedef cublasStatus_t (*cublasFunc)(Args...); \ typedef cublasStatus_t (*cublasFunc)(Args...); \
std::call_once(cublas_dso_flag, \ std::call_once(cublas_dso_flag, \
paddle::platform::dyload::GetCublasDsoHandle, \ paddle::platform::dynload::GetCublasDsoHandle, \
&cublas_dso_handle); \ &cublas_dso_handle); \
void *p_##__name = dlsym(cublas_dso_handle, #__name); \ void *p_##__name = dlsym(cublas_dso_handle, #__name); \
return reinterpret_cast<cublasFunc>(p_##__name)(args...); \ return reinterpret_cast<cublasFunc>(p_##__name)(args...); \
} \ } \
} __name; // struct DynLoad__##__name } __name; // struct DynLoad__##__name
#else #else
#define DYNAMIC_LOAD_CUBLAS_WRAP(__name) \ #define DYNAMIC_LOAD_CUBLAS_WRAP(__name) \
@ -99,6 +99,6 @@ CUBLAS_BLAS_ROUTINE_EACH(DYNAMIC_LOAD_CUBLAS_V2_WRAP)
#define CUBLAS_GETRF paddle::platform::dynload::cublasDgetrfBatched #define CUBLAS_GETRF paddle::platform::dynload::cublasDgetrfBatched
#define CUBLAS_GETRI paddle::platform::dynload::cublasDgetriBatched #define CUBLAS_GETRI paddle::platform::dynload::cublasDgetriBatched
#endif #endif
} // namespace dyload } // namespace dynload
} // namespace platform } // namespace platform
} // namespace paddle } // namespace paddle

@ -19,24 +19,24 @@ limitations under the License. */
namespace paddle { namespace paddle {
namespace platform { namespace platform {
namespace dyload { namespace dynload {
std::once_flag cudnn_dso_flag; std::once_flag cudnn_dso_flag;
void* cudnn_dso_handle = nullptr; void* cudnn_dso_handle = nullptr;
#ifdef PADDLE_USE_DSO #ifdef PADDLE_USE_DSO
#define DYNAMIC_LOAD_CUDNN_WRAP(__name) \ #define DYNAMIC_LOAD_CUDNN_WRAP(__name) \
struct DynLoad__##__name { \ struct DynLoad__##__name { \
template <typename... Args> \ template <typename... Args> \
auto operator()(Args... args) -> decltype(__name(args...)) { \ auto operator()(Args... args) -> decltype(__name(args...)) { \
using cudnn_func = decltype(__name(args...)) (*)(Args...); \ using cudnn_func = decltype(__name(args...)) (*)(Args...); \
std::call_once(cudnn_dso_flag, \ std::call_once(cudnn_dso_flag, \
paddle::platform::dyload::GetCudnnDsoHandle, \ paddle::platform::dynload::GetCudnnDsoHandle, \
&cudnn_dso_handle); \ &cudnn_dso_handle); \
void* p_##__name = dlsym(cudnn_dso_handle, #__name); \ void* p_##__name = dlsym(cudnn_dso_handle, #__name); \
return reinterpret_cast<cudnn_func>(p_##__name)(args...); \ return reinterpret_cast<cudnn_func>(p_##__name)(args...); \
} \ } \
} __name; /* struct DynLoad__##__name */ } __name; /* struct DynLoad__##__name */
#else #else
@ -129,6 +129,6 @@ CUDNN_DNN_ROUTINE_EACH_R5(DYNAMIC_LOAD_CUDNN_WRAP)
#undef CUDNN_DNN_ROUTINE_EACH #undef CUDNN_DNN_ROUTINE_EACH
// clang-format on // clang-format on
} // namespace dyload } // namespace dynload
} // namespace platform } // namespace platform
} // namespace paddle } // namespace paddle

@ -19,21 +19,21 @@ limitations under the License. */
namespace paddle { namespace paddle {
namespace platform { namespace platform {
namespace dyload { namespace dynload {
std::once_flag curand_dso_flag; std::once_flag curand_dso_flag;
void *curand_dso_handle = nullptr; void *curand_dso_handle = nullptr;
#ifdef PADDLE_USE_DSO #ifdef PADDLE_USE_DSO
#define DYNAMIC_LOAD_CURAND_WRAP(__name) \ #define DYNAMIC_LOAD_CURAND_WRAP(__name) \
struct DynLoad__##__name { \ struct DynLoad__##__name { \
template <typename... Args> \ template <typename... Args> \
curandStatus_t operator()(Args... args) { \ curandStatus_t operator()(Args... args) { \
typedef curandStatus_t (*curandFunc)(Args...); \ typedef curandStatus_t (*curandFunc)(Args...); \
std::call_once(curand_dso_flag, \ std::call_once(curand_dso_flag, \
paddle::platform::dyload::GetCurandDsoHandle, \ paddle::platform::dynload::GetCurandDsoHandle, \
&curand_dso_handle); \ &curand_dso_handle); \
void *p_##__name = dlsym(curand_dso_handle, #__name); \ void *p_##__name = dlsym(curand_dso_handle, #__name); \
return reinterpret_cast<curandFunc>(p_##__name)(args...); \ return reinterpret_cast<curandFunc>(p_##__name)(args...); \
} \ } \
} __name; /* struct DynLoad__##__name */ } __name; /* struct DynLoad__##__name */
#else #else
#define DYNAMIC_LOAD_CURAND_WRAP(__name) \ #define DYNAMIC_LOAD_CURAND_WRAP(__name) \
@ -60,6 +60,6 @@ CURAND_RAND_ROUTINE_EACH(DYNAMIC_LOAD_CURAND_WRAP)
#undef CURAND_RAND_ROUTINE_EACH #undef CURAND_RAND_ROUTINE_EACH
#undef DYNAMIC_LOAD_CURAND_WRAP #undef DYNAMIC_LOAD_CURAND_WRAP
} // namespace dyload } // namespace dynload
} // namespace platform } // namespace platform
} // namespace paddle } // namespace paddle

@ -36,7 +36,7 @@ DEFINE_string(lapack_dir, "", "Specify path for loading liblapack.so.");
namespace paddle { namespace paddle {
namespace platform { namespace platform {
namespace dyload { namespace dynload {
static inline std::string join(const std::string& part1, static inline std::string join(const std::string& part1,
const std::string& part2) { const std::string& part2) {
@ -164,6 +164,6 @@ void GetLapackDsoHandle(void** dso_handle) {
#endif #endif
} }
} // namespace dyload } // namespace dynload
} // namespace platform } // namespace platform
} // namespace paddle } // namespace paddle

@ -16,7 +16,7 @@ limitations under the License. */
namespace paddle { namespace paddle {
namespace platform { namespace platform {
namespace dyload { namespace dynload {
/** /**
* @brief load the DSO of CUBLAS * @brief load the DSO of CUBLAS
@ -58,6 +58,6 @@ void GetWarpCTCDsoHandle(void** dso_handle);
*/ */
void GetLapackDsoHandle(void** dso_handle); void GetLapackDsoHandle(void** dso_handle);
} // namespace dyload } // namespace dynload
} // namespace platform } // namespace platform
} // namespace paddle } // namespace paddle
Loading…
Cancel
Save