Skip to content

Commit c02ba51

Browse files
authored
Merge pull request #10191 from reyoung/feature/strict_dynload
Make dyload strictly use the same ABI in header
2 parents 5c500c6 + 3d53631 commit c02ba51

File tree

6 files changed

+11
-9
lines changed

6 files changed

+11
-9
lines changed

paddle/fluid/platform/dynload/cublas.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414

1515
#pragma once
1616

17+
#include <cublasXt.h>
1718
#include <cublas_v2.h>
1819
#include <cuda.h>
1920
#include <dlfcn.h>
2021
#include <mutex> // NOLINT
22+
#include <type_traits>
2123
#include "paddle/fluid/platform/dynload/dynamic_loader.h"
2224

2325
namespace paddle {
@@ -37,14 +39,14 @@ extern void *cublas_dso_handle;
3739
#ifdef PADDLE_USE_DSO
3840
#define DECLARE_DYNAMIC_LOAD_CUBLAS_WRAP(__name) \
3941
struct DynLoad__##__name { \
42+
using FUNC_TYPE = decltype(&::__name); \
4043
template <typename... Args> \
4144
inline cublasStatus_t operator()(Args... args) { \
42-
typedef cublasStatus_t (*cublasFunc)(Args...); \
4345
std::call_once(cublas_dso_flag, []() { \
4446
cublas_dso_handle = paddle::platform::dynload::GetCublasDsoHandle(); \
4547
}); \
4648
void *p_##__name = dlsym(cublas_dso_handle, #__name); \
47-
return reinterpret_cast<cublasFunc>(p_##__name)(args...); \
49+
return reinterpret_cast<FUNC_TYPE>(p_##__name)(args...); \
4850
} \
4951
}; \
5052
extern DynLoad__##__name __name
@@ -71,8 +73,8 @@ extern void *cublas_dso_handle;
7173
__macro(cublasDgemm_v2); \
7274
__macro(cublasHgemm); \
7375
__macro(cublasSgemmEx); \
74-
__macro(cublasSgeam_v2); \
75-
__macro(cublasDgeam_v2); \
76+
__macro(cublasSgeam); \
77+
__macro(cublasDgeam); \
7678
__macro(cublasCreate_v2); \
7779
__macro(cublasDestroy_v2); \
7880
__macro(cublasSetStream_v2); \

paddle/fluid/platform/dynload/cudnn.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extern void EnforceCUDNNLoaded(const char* fn_name);
3434
struct DynLoad__##__name { \
3535
template <typename... Args> \
3636
auto operator()(Args... args) -> decltype(__name(args...)) { \
37-
using cudnn_func = decltype(__name(args...)) (*)(Args...); \
37+
using cudnn_func = decltype(&::__name); \
3838
std::call_once(cudnn_dso_flag, []() { \
3939
cudnn_dso_handle = paddle::platform::dynload::GetCUDNNDsoHandle(); \
4040
}); \

paddle/fluid/platform/dynload/cupti.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ extern void *cupti_dso_handle;
4141
struct DynLoad__##__name { \
4242
template <typename... Args> \
4343
inline CUptiResult CUPTIAPI operator()(Args... args) { \
44-
typedef CUptiResult CUPTIAPI (*cuptiFunc)(Args...); \
44+
using cuptiFunc = decltype(&::__name); \
4545
std::call_once(cupti_dso_flag, []() { \
4646
cupti_dso_handle = paddle::platform::dynload::GetCUPTIDsoHandle(); \
4747
}); \

paddle/fluid/platform/dynload/curand.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ extern void *curand_dso_handle;
3030
struct DynLoad__##__name { \
3131
template <typename... Args> \
3232
curandStatus_t operator()(Args... args) { \
33-
typedef curandStatus_t (*curandFunc)(Args...); \
33+
using curandFunc = decltype(&::__name); \
3434
std::call_once(curand_dso_flag, []() { \
3535
curand_dso_handle = paddle::platform::dynload::GetCurandDsoHandle(); \
3636
}); \

paddle/fluid/platform/dynload/nccl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extern void* nccl_dso_handle;
3333
struct DynLoad__##__name { \
3434
template <typename... Args> \
3535
auto operator()(Args... args) -> decltype(__name(args...)) { \
36-
using nccl_func = decltype(__name(args...)) (*)(Args...); \
36+
using nccl_func = decltype(&::__name); \
3737
std::call_once(nccl_dso_flag, []() { \
3838
nccl_dso_handle = paddle::platform::dynload::GetNCCLDsoHandle(); \
3939
}); \

paddle/fluid/platform/dynload/warpctc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ extern void* warpctc_dso_handle;
3636
struct DynLoad__##__name { \
3737
template <typename... Args> \
3838
auto operator()(Args... args) -> decltype(__name(args...)) { \
39-
using warpctcFunc = decltype(__name(args...)) (*)(Args...); \
39+
using warpctcFunc = decltype(&::__name); \
4040
std::call_once(warpctc_dso_flag, []() { \
4141
warpctc_dso_handle = paddle::platform::dynload::GetWarpCTCDsoHandle(); \
4242
}); \

0 commit comments

Comments
 (0)