Skip to content

Commit c548ce7

Browse files
authored
picked from develop. test=release/1.0.0 (#13797)
1 parent 31caa4f commit c548ce7

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

paddle/fluid/platform/dynload/cublas.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ extern void *cublas_dso_handle;
5555
struct DynLoad__##__name { \
5656
template <typename... Args> \
5757
inline cublasStatus_t operator()(Args... args) { \
58-
return __name(args...); \
58+
return ::__name(args...); \
5959
} \
6060
}; \
6161
extern DynLoad__##__name __name

paddle/fluid/platform/dynload/cudnn.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ See the License for the specific language governing permissions and
1313
limitations under the License. */
1414

1515
#pragma once
16+
#define GLOG_NO_ABBREVIATED_SEVERITIES
17+
#define GOOGLE_GLOG_DLL_DECL
18+
#include <glog/logging.h>
1619

1720
#include <cudnn.h>
1821
#include <mutex> // NOLINT
@@ -47,13 +50,13 @@ extern void EnforceCUDNNLoaded(const char* fn_name);
4750

4851
#else
4952

50-
#define DECLARE_DYNAMIC_LOAD_CUDNN_WRAP(__name) \
51-
struct DynLoad__##__name { \
52-
template <typename... Args> \
53-
auto operator()(Args... args) -> decltype(__name(args...)) { \
54-
return __name(args...); \
55-
} \
56-
}; \
53+
#define DECLARE_DYNAMIC_LOAD_CUDNN_WRAP(__name) \
54+
struct DynLoad__##__name { \
55+
template <typename... Args> \
56+
inline cudnnStatus_t operator()(Args... args) { \
57+
return ::__name(args...); \
58+
} \
59+
}; \
5760
extern DynLoad__##__name __name
5861

5962
#endif

paddle/fluid/platform/dynload/curand.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ extern void *curand_dso_handle;
4444
struct DynLoad__##__name { \
4545
template <typename... Args> \
4646
curandStatus_t operator()(Args... args) { \
47-
return __name(args...); \
47+
return ::__name(args...); \
4848
} \
4949
}; \
5050
extern DynLoad__##__name __name

paddle/fluid/platform/dynload/dynamic_loader.cc

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@ static inline void* GetDsoHandleFromDefaultPath(const std::string& dso_path,
107107
static inline void* GetDsoHandleFromSearchPath(const std::string& search_root,
108108
const std::string& dso_name,
109109
bool throw_on_error = true) {
110+
#if !defined(_WIN32)
110111
int dynload_flags = RTLD_LAZY | RTLD_LOCAL;
112+
#else
113+
int dynload_flags = 0;
114+
#endif // !_WIN32
111115
void* dso_handle = nullptr;
112116

113117
std::string dlPath = dso_name;
@@ -117,10 +121,15 @@ static inline void* GetDsoHandleFromSearchPath(const std::string& search_root,
117121
// search xxx.so from custom path
118122
dlPath = join(search_root, dso_name);
119123
dso_handle = dlopen(dlPath.c_str(), dynload_flags);
124+
#if !defined(_WIN32)
125+
auto errorno = dlerror();
126+
#else
127+
auto errorno = GetLastError();
128+
#endif // !_WIN32
120129
// if not found, search from default path
121130
if (nullptr == dso_handle) {
122131
LOG(WARNING) << "Failed to find dynamic library: " << dlPath << " ("
123-
<< dlerror() << ")";
132+
<< errorno << ")";
124133
if (dlPath.find("nccl") != std::string::npos) {
125134
std::cout
126135
<< "You may need to install 'nccl2' from NVIDIA official website: "
@@ -139,10 +148,15 @@ static inline void* GetDsoHandleFromSearchPath(const std::string& search_root,
139148
"export LD_LIBRARY_PATH=... \n Note: After Mac OS 10.11, "
140149
"using the DYLD_LIBRARY_PATH is impossible unless System "
141150
"Integrity Protection (SIP) is disabled.";
151+
#if !defined(_WIN32)
152+
auto errorno = dlerror();
153+
#else
154+
auto errorno = GetLastError();
155+
#endif // !_WIN32
142156
if (throw_on_error) {
143-
PADDLE_ENFORCE(nullptr != dso_handle, error_msg, dlPath, dlerror());
157+
PADDLE_ENFORCE(nullptr != dso_handle, error_msg, dlPath, errorno);
144158
} else if (nullptr == dso_handle) {
145-
LOG(WARNING) << string::Sprintf(error_msg, dlPath, dlerror());
159+
LOG(WARNING) << string::Sprintf(error_msg, dlPath, errorno);
146160
}
147161

148162
return dso_handle;

0 commit comments

Comments
 (0)