Skip to content

Commit 42d6408

Browse files
authored
Merge pull request PaddlePaddle#1998 from emailweixu/fix_lapack
Fix dynamic loading of Lapack caused by PaddlePaddle#1958
2 parents a3e975d + b2f14e4 commit 42d6408

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

paddle/math/MathFunctions.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,20 @@ void* lapack_dso_handle = nullptr;
2929
*
3030
* note: default dynamic linked libs
3131
*/
32+
33+
// The argument for stringizing operator is not macro-expanded first.
34+
// We have to use two levels of macro to do the expansion.
35+
// See https://gcc.gnu.org/onlinedocs/cpp/Stringizing.html
36+
#define STR(x) #x
3237
#define DYNAMIC_LOAD_LAPACK_WRAP(__name) \
3338
struct DynLoad__##__name { \
3439
template <typename... Args> \
3540
auto operator()(Args... args) -> decltype(__name(args...)) { \
3641
using lapack_func = decltype(__name(args...)) (*)(Args...); \
3742
std::call_once(lapack_dso_flag, GetLapackDsoHandle, &lapack_dso_handle); \
38-
void* p_##__name = dlsym(lapack_dso_handle, #__name); \
43+
void* p_##__name = dlsym(lapack_dso_handle, STR(__name)); \
44+
CHECK(p_##__name) << "Cannot find symbol " << STR(__name) \
45+
<< " in liblapack.so"; \
3946
return reinterpret_cast<lapack_func>(p_##__name)(args...); \
4047
} \
4148
} __name; // struct DynLoad__##__name
@@ -51,7 +58,7 @@ void* lapack_dso_handle = nullptr;
5158
#define PADDLE_DGETRF LAPACKE_dgetrf
5259
#define PADDLE_SGETRI LAPACKE_sgetri
5360
#define PADDLE_DGETRI LAPACKE_dgetri
54-
#endif
61+
#endif
5562

5663
#define LAPACK_ROUTINE_EACH(__macro) \
5764
__macro(PADDLE_SGETRF) \

paddle/math/tests/test_matrixCompare.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,7 @@ TEST(Matrix, unary) {
237237
testMatrixRotate(height, width);
238238
}
239239
// inverse matrix
240-
void** dso_handler = nullptr;
241-
GetLapackDsoHandle(dso_handler);
242-
if (nullptr == *dso_handler) {
243-
LOG(WARNING) << "Failed to find liblapack.so, please specify its path "
244-
"using LD_LIBRARY_PATH.";
245-
} else {
246-
testMatrixInverse(height);
247-
}
240+
testMatrixInverse(height);
248241
}
249242
}
250243

paddle/utils/DynamicLoader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static inline std::string join(const std::string& part1,
5252
static inline void GetDsoHandleFromDefaultPath(std::string& dso_path,
5353
void** dso_handle,
5454
int dynload_flags) {
55-
VLOG(3) << "Try to find cuda library: " << dso_path
55+
VLOG(3) << "Try to find library: " << dso_path
5656
<< " from default system path.";
5757
// default search from LD_LIBRARY_PATH/DYLD_LIBRARY_PATH
5858
*dso_handle = dlopen(dso_path.c_str(), dynload_flags);

0 commit comments

Comments
 (0)