@@ -46,63 +46,100 @@ static inline std::string join(const std::string& part1, const std::string& part
46
46
return ret;
47
47
}
48
48
49
- static inline void GetDsoHandleWithSearchPath (
49
+ static inline void GetDsoHandleFromDefaultPath (
50
+ std::string& dso_path, void ** dso_handle, int dynload_flags) {
51
+ LOG (INFO) << " Try to find cuda library: " << dso_path
52
+ << " from default system path." ;
53
+ // default search from LD_LIBRARY_PATH/DYLD_LIBRARY_PATH
54
+ *dso_handle = dlopen (dso_path.c_str (), dynload_flags);
55
+
56
+ // DYLD_LIBRARY_PATH is disabled after Mac OS 10.11 to
57
+ // bring System Integrity Projection (SIP), if dso_handle
58
+ // is null, search from default package path in Mac OS.
59
+ #if defined(__APPLE__) or defined(__OSX__)
60
+ if (nullptr == *dso_handle) {
61
+ dso_path = join (" /usr/local/cuda/lib/" , dso_path);
62
+ *dso_handle = dlopen (dso_path.c_str (), dynload_flags);
63
+ if (nullptr == *dso_handle) {
64
+ if (dso_path == " libcudnn.dylib" ) {
65
+ LOG (FATAL) << " Note: [Recommend] copy cudnn into /usr/local/cuda/ \n "
66
+ << " For instance, sudo tar -xzf cudnn-7.5-osx-x64-v5.0-ga.tgz -C "
67
+ << " /usr/local \n sudo chmod a+r /usr/local/cuda/include/cudnn.h "
68
+ << " /usr/local/cuda/lib/libcudnn*" ;
69
+ }
70
+ }
71
+ }
72
+ #endif
73
+ }
74
+
75
+ static inline void GetDsoHandleFromSearchPath (
50
76
const std::string& search_root,
51
- const std::string& dso_path ,
77
+ const std::string& dso_name ,
52
78
void ** dso_handle) {
53
79
int dynload_flags = RTLD_LAZY | RTLD_LOCAL;
54
80
*dso_handle = nullptr ;
55
81
56
- std::string dlPath = dso_path ;
82
+ std::string dlPath = dso_name ;
57
83
if (search_root.empty ()) {
58
- // default search xxx.so from LD_LIBRARY_PATH
59
- *dso_handle = dlopen (dlPath.c_str (), dynload_flags);
84
+ GetDsoHandleFromDefaultPath (dlPath, dso_handle, dynload_flags);
60
85
} else {
61
86
// search xxx.so from custom path
62
- dlPath = join (search_root, dso_path );
87
+ dlPath = join (search_root, dso_name );
63
88
*dso_handle = dlopen (dlPath.c_str (), dynload_flags);
64
- // then, search xxx.so from LD_LIBRARY_PATH
65
- if (nullptr == *dso_handle) {
66
- *dso_handle = dlopen (dso_path.c_str (), dynload_flags);
89
+ // if not found, search from default path
90
+ if (nullptr == dso_handle) {
91
+ LOG (WARNING) << " Failed to find cuda library: " << dlPath;
92
+ dlPath = dso_name;
93
+ GetDsoHandleFromDefaultPath (dlPath, dso_handle, dynload_flags);
67
94
}
68
95
}
69
96
70
97
CHECK (nullptr != *dso_handle)
71
- << " For Gpu version of PaddlePaddle, it couldn't find CUDA library: "
72
- << dlPath.c_str () << " . Please make sure you already specify its path. "
73
- << " Note: for training data on Cpu using Gpu version of PaddlePaddle, "
74
- << " you must specify libcudart via export LD_LIBRARY_PATH for Linux or "
75
- << " export DYLD_LIBRARY_PATH for MAC OS." ;
98
+ << " Failed to find cuda library: " << dlPath << std::endl
99
+ << " Please specify its path correctly using one of the following ideas: \n "
100
+
101
+ << " Idea 1. set cuda and cudnn lib path at runtime. "
102
+ << " http://www.paddlepaddle.org/doc/ui/cmd_argument/argument_outline.html \n "
103
+ << " For instance, issue command: paddle train --use_gpu=1 "
104
+ << " --cuda_dir=/usr/local/cudnn/lib --cudnn_dir=/usr/local/cudnn/lib ...\n "
105
+
106
+ << " Idea 2. set environment variable LD_LIBRARY_PATH on Linux or "
107
+ << " DYLD_LIBRARY_PATH on Mac OS. \n "
108
+ << " For instance, issue command: export LD_LIBRARY_PATH=... \n "
109
+
110
+ << " Note: After Mac OS 10.11, using the DYLD_LIBRARY_PATH is impossible "
111
+ << " unless System Integrity Protection (SIP) is disabled. However, @Idea 1"
112
+ << " always work well." ;
76
113
}
77
114
78
115
void GetCublasDsoHandle (void ** dso_handle) {
79
116
#if defined(__APPLE__) || defined(__OSX__)
80
- GetDsoHandleWithSearchPath (FLAGS_cuda_dir, " libcublas.dylib" , dso_handle);
117
+ GetDsoHandleFromSearchPath (FLAGS_cuda_dir, " libcublas.dylib" , dso_handle);
81
118
#else
82
- GetDsoHandleWithSearchPath (FLAGS_cuda_dir, " libcublas.so" , dso_handle);
119
+ GetDsoHandleFromSearchPath (FLAGS_cuda_dir, " libcublas.so" , dso_handle);
83
120
#endif
84
121
}
85
122
86
123
void GetCudnnDsoHandle (void ** dso_handle) {
87
124
#if defined(__APPLE__) || defined(__OSX__)
88
- GetDsoHandleWithSearchPath (FLAGS_cudnn_dir, " libcudnn.dylib" , dso_handle);
125
+ GetDsoHandleFromSearchPath (FLAGS_cudnn_dir, " libcudnn.dylib" , dso_handle);
89
126
#else
90
- GetDsoHandleWithSearchPath (FLAGS_cudnn_dir, " libcudnn.so" , dso_handle);
127
+ GetDsoHandleFromSearchPath (FLAGS_cudnn_dir, " libcudnn.so" , dso_handle);
91
128
#endif
92
129
}
93
130
94
131
void GetCudartDsoHandle (void ** dso_handle) {
95
132
#if defined(__APPLE__) || defined(__OSX__)
96
- GetDsoHandleWithSearchPath (" " , " libcudart.dylib" , dso_handle);
133
+ GetDsoHandleFromSearchPath (" " , " libcudart.dylib" , dso_handle);
97
134
#else
98
- GetDsoHandleWithSearchPath (" " , " libcudart.so" , dso_handle);
135
+ GetDsoHandleFromSearchPath (" " , " libcudart.so" , dso_handle);
99
136
#endif
100
137
}
101
138
102
139
void GetCurandDsoHandle (void ** dso_handle) {
103
140
#if defined(__APPLE__) || defined(__OSX__)
104
- GetDsoHandleWithSearchPath (FLAGS_cuda_dir, " libcurand.dylib" , dso_handle);
141
+ GetDsoHandleFromSearchPath (FLAGS_cuda_dir, " libcurand.dylib" , dso_handle);
105
142
#else
106
- GetDsoHandleWithSearchPath (FLAGS_cuda_dir, " libcurand.so" , dso_handle);
143
+ GetDsoHandleFromSearchPath (FLAGS_cuda_dir, " libcurand.so" , dso_handle);
107
144
#endif
108
145
}
0 commit comments