@@ -57,17 +57,26 @@ struct PathNode {
5757
5858static constexpr char cupti_lib_path[] = CUPTI_LIB_PATH;
5959
60- // NOTE: In order to adapt to the default installation path of cuda on linux
61- static constexpr char linux_cudnn_lib_path[] = " /usr/local/cuda/lib64" ;
60+ // NOTE: In order to adapt to the default installation path of cuda
61+ #if defined(_WIN32) && defined(PADDLE_WITH_CUDA)
62+ static constexpr char cuda_lib_path[] = CUDA_TOOLKIT_ROOT_DIR " /bin" ;
63+ #else
64+ static constexpr char cuda_lib_path[] = " /usr/local/cuda/lib64" ;
65+ #endif
6266
6367static PathNode s_py_site_pkg_path;
6468
6569#if defined(_WIN32) && defined(PADDLE_WITH_CUDA)
66- static constexpr char * win_cublas_lib = " cublas64_" PADDLE_CUDA_BINVER " .dll" ;
67- static constexpr char * win_curand_lib = " curand64_" PADDLE_CUDA_BINVER " .dll" ;
68- static constexpr char * win_cudnn_lib = " cudnn64_" PADDLE_CUDNN_BINVER " .dll" ;
70+ static constexpr char * win_cublas_lib =
71+ " cublas64_" CUDA_VERSION_MAJOR CUDA_VERSION_MINOR
72+ " .dll;cublas64_" CUDA_VERSION_MAJOR " .dll" ;
73+ static constexpr char * win_curand_lib =
74+ " curand64_" CUDA_VERSION_MAJOR CUDA_VERSION_MINOR
75+ " .dll;curand64_" CUDA_VERSION_MAJOR " .dll" ;
76+ static constexpr char * win_cudnn_lib = " cudnn64_" CUDNN_MAJOR_VERSION " .dll" ;
6977static constexpr char * win_cusolver_lib =
70- " cusolver64_" PADDLE_CUDA_BINVER " .dll" ;
78+ " cusolver64_" CUDA_VERSION_MAJOR CUDA_VERSION_MINOR
79+ " .dll;cusolver64_" CUDA_VERSION_MAJOR " .dll" ;
7180#endif
7281
7382static inline std::string join (const std::string& part1,
@@ -87,6 +96,24 @@ static inline std::string join(const std::string& part1,
8796 return ret;
8897}
8998
99+ static inline std::vector<std::string> split (
100+ const std::string& str, const std::string separator = " " ) {
101+ std::vector<std::string> str_list;
102+ std::string::size_type firstPos;
103+ firstPos = str.find_first_not_of (separator, 0 );
104+ std::string::size_type lastPos;
105+ lastPos = str.find_first_of (separator, firstPos);
106+ while (std::string::npos != firstPos && std::string::npos != lastPos) {
107+ str_list.push_back (str.substr (firstPos, lastPos - firstPos));
108+ firstPos = str.find_first_not_of (separator, lastPos);
109+ lastPos = str.find_first_of (separator, firstPos);
110+ }
111+ if (std::string::npos == lastPos) {
112+ str_list.push_back (str.substr (firstPos, lastPos - firstPos));
113+ }
114+ return str_list;
115+ }
116+
90117void SetPaddleLibPath (const std::string& py_site_pkg_path) {
91118 s_py_site_pkg_path.path = py_site_pkg_path;
92119 VLOG (3 ) << " Set paddle lib path : " << py_site_pkg_path;
@@ -147,26 +174,31 @@ static inline void* GetDsoHandleFromSearchPath(
147174#else
148175 int dynload_flags = 0 ;
149176#endif // !_WIN32
150- // 1. search in user config path by FLAGS
151- void * dso_handle =
152- GetDsoHandleFromSpecificPath (config_path, dso_name, dynload_flags);
153- // 2. search in system default path
154- if (nullptr == dso_handle) {
155- dso_handle = GetDsoHandleFromDefaultPath (dso_name, dynload_flags);
156- }
157- // 3. search in extra paths
158- if (nullptr == dso_handle) {
159- for (auto path : extra_paths) {
160- dso_handle = GetDsoHandleFromSpecificPath (path, dso_name, dynload_flags);
177+ std::vector<std::string> dso_names = split (dso_name, " ;" );
178+ void * dso_handle = nullptr ;
179+ for (auto dso : dso_names) {
180+ // 1. search in user config path by FLAGS
181+ dso_handle = GetDsoHandleFromSpecificPath (config_path, dso, dynload_flags);
182+ // 2. search in extra paths
183+ if (nullptr == dso_handle) {
184+ for (auto path : extra_paths) {
185+ VLOG (3 ) << " extra_paths: " << path;
186+ dso_handle = GetDsoHandleFromSpecificPath (path, dso, dynload_flags);
187+ }
188+ }
189+ // 3. search in system default path
190+ if (nullptr == dso_handle) {
191+ dso_handle = GetDsoHandleFromDefaultPath (dso, dynload_flags);
161192 }
193+ if (nullptr != dso_handle) break ;
162194 }
163195
164- // 4. [If Failed] logging warning if exists
196+ // 4. [If Failed for All dso_names ] logging warning if exists
165197 if (nullptr == dso_handle && !warning_msg.empty ()) {
166198 LOG (WARNING) << warning_msg;
167199 }
168200
169- // 5. [If Failed] logging or throw error info
201+ // 5. [If Failed for All dso_names ] logging or throw error info
170202 if (nullptr == dso_handle) {
171203 auto error_msg =
172204 " The third-party dynamic library (%s) that Paddle depends on is not "
@@ -203,7 +235,8 @@ void* GetCublasDsoHandle() {
203235#if defined(__APPLE__) || defined(__OSX__)
204236 return GetDsoHandleFromSearchPath (FLAGS_cuda_dir, " libcublas.dylib" );
205237#elif defined(_WIN32) && defined(PADDLE_WITH_CUDA)
206- return GetDsoHandleFromSearchPath (FLAGS_cuda_dir, win_cublas_lib);
238+ return GetDsoHandleFromSearchPath (FLAGS_cuda_dir, win_cublas_lib, true ,
239+ {cuda_lib_path});
207240#else
208241 return GetDsoHandleFromSearchPath (FLAGS_cuda_dir, " libcublas.so" );
209242#endif
@@ -220,10 +253,19 @@ void* GetCUDNNDsoHandle() {
220253 return GetDsoHandleFromSearchPath (FLAGS_cudnn_dir, " libcudnn.dylib" , false ,
221254 {}, mac_warn_meg);
222255#elif defined(_WIN32) && defined(PADDLE_WITH_CUDA)
223- return GetDsoHandleFromSearchPath (FLAGS_cudnn_dir, win_cudnn_lib);
256+ std::string win_warn_meg (
257+ " Note: [Recommend] copy cudnn into CUDA installation directory. \n "
258+ " For instance, download cudnn-10.0-windows10-x64-v7.6.5.32.zip from "
259+ " NVIDIA's official website, \n "
260+ " then, unzip it and copy it into C:\\ Program Files\\ NVIDIA GPU Computing "
261+ " Toolkit\\ CUDA/v10.0\n "
262+ " You should do this according to your CUDA installation directory and "
263+ " CUDNN version." );
264+ return GetDsoHandleFromSearchPath (FLAGS_cudnn_dir, win_cudnn_lib, true ,
265+ {cuda_lib_path}, win_warn_meg);
224266#else
225267 return GetDsoHandleFromSearchPath (FLAGS_cudnn_dir, " libcudnn.so" , false ,
226- {linux_cudnn_lib_path });
268+ {cuda_lib_path });
227269#endif
228270}
229271
@@ -241,7 +283,8 @@ void* GetCurandDsoHandle() {
241283#if defined(__APPLE__) || defined(__OSX__)
242284 return GetDsoHandleFromSearchPath (FLAGS_cuda_dir, " libcurand.dylib" );
243285#elif defined(_WIN32) && defined(PADDLE_WITH_CUDA)
244- return GetDsoHandleFromSearchPath (FLAGS_cuda_dir, win_curand_lib);
286+ return GetDsoHandleFromSearchPath (FLAGS_cuda_dir, win_curand_lib, true ,
287+ {cuda_lib_path});
245288#else
246289 return GetDsoHandleFromSearchPath (FLAGS_cuda_dir, " libcurand.so" );
247290#endif
@@ -251,7 +294,8 @@ void* GetCusolverDsoHandle() {
251294#if defined(__APPLE__) || defined(__OSX__)
252295 return GetDsoHandleFromSearchPath (FLAGS_cuda_dir, " libcusolver.dylib" );
253296#elif defined(_WIN32) && defined(PADDLE_WITH_CUDA)
254- return GetDsoHandleFromSearchPath (FLAGS_cuda_dir, win_cusolver_lib);
297+ return GetDsoHandleFromSearchPath (FLAGS_cuda_dir, win_cusolver_lib, true ,
298+ {cuda_lib_path});
255299#else
256300 return GetDsoHandleFromSearchPath (FLAGS_cuda_dir, " libcusolver.so" );
257301#endif
0 commit comments