Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
5d700021
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
5d700021
编写于
10月 21, 2020
作者:
Z
Zhou Wei
提交者:
GitHub
10月 21, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix dynamic_loader more safe and error message on windows (#28117)
上级
446d184e
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
96 addition
and
45 deletion
+96
-45
CMakeLists.txt
CMakeLists.txt
+13
-14
cmake/cuda.cmake
cmake/cuda.cmake
+4
-1
cmake/cudnn.cmake
cmake/cudnn.cmake
+6
-5
paddle/fluid/platform/dynload/dynamic_loader.cc
paddle/fluid/platform/dynload/dynamic_loader.cc
+68
-24
paddle/fluid/platform/port.h
paddle/fluid/platform/port.h
+5
-1
未找到文件。
CMakeLists.txt
浏览文件 @
5d700021
...
...
@@ -193,10 +193,19 @@ if(WITH_BRPC_RDMA)
endif
()
endif
()
# lite subgraph compilation depends on CUDNN_ROOT,
# so include(cudnn) needs to be in front of include(third_party/lite)
include
(
cudnn
)
# set cudnn libraries, must before configure
include
(
third_party
)
# download, build, install third_party
if
(
WITH_GPU
)
include
(
cuda
)
# lite subgraph compilation depends on CUDNN_ROOT,
# so include(cudnn) needs to be in front of include(third_party/lite)
include
(
cudnn
)
# set cudnn libraries, must before configure
include
(
tensorrt
)
# there is no official support of nccl, cupti in windows
if
(
NOT WIN32
)
include
(
cupti
)
endif
()
endif
()
include
(
third_party
)
# download, build, install third_party, Contains about 20+ dependencies
if
(
WITH_DISTRIBUTE
)
if
(
WITH_GRPC
)
...
...
@@ -209,18 +218,8 @@ if(WITH_DISTRIBUTE)
endif
()
endif
()
# there is no official support of nccl, cupti in windows
if
(
NOT WIN32
)
include
(
cupti
)
endif
()
include
(
flags
)
# set paddle compile flags
if
(
WITH_GPU
)
include
(
cuda
)
include
(
tensorrt
)
endif
()
if
(
WITH_PROFILER
)
find_package
(
Gperftools REQUIRED
)
include_directories
(
${
GPERFTOOLS_INCLUDE_DIR
}
)
...
...
cmake/cuda.cmake
浏览文件 @
5d700021
...
...
@@ -198,7 +198,9 @@ elseif (${CMAKE_CUDA_COMPILER_VERSION} LESS 12.0) # CUDA 11.x
set
(
CMAKE_CUDA_FLAGS
"
${
CMAKE_CUDA_FLAGS
}
-D__STRICT_ANSI__"
)
endif
()
add_definitions
(
"-DPADDLE_CUDA_BINVER=
\"
${
CUDA_VERSION_MAJOR
}${
CUDA_VERSION_MINOR
}
\"
"
)
add_definitions
(
"-DCUDA_VERSION_MAJOR=
\"
${
CUDA_VERSION_MAJOR
}
\"
"
)
add_definitions
(
"-DCUDA_VERSION_MINOR=
\"
${
CUDA_VERSION_MINOR
}
\"
"
)
add_definitions
(
"-DCUDA_TOOLKIT_ROOT_DIR=
\"
${
CUDA_TOOLKIT_ROOT_DIR
}
\"
"
)
# setting nvcc arch flags
select_nvcc_arch_flags
(
NVCC_FLAGS_EXTRA
)
...
...
@@ -249,3 +251,4 @@ endif()
mark_as_advanced
(
CUDA_BUILD_CUBIN CUDA_BUILD_EMULATION CUDA_VERBOSE_BUILD
)
mark_as_advanced
(
CUDA_SDK_ROOT_DIR CUDA_SEPARABLE_COMPILATION
)
cmake/cudnn.cmake
浏览文件 @
5d700021
...
...
@@ -35,17 +35,18 @@ list(APPEND CUDNN_CHECK_LIBRARY_DIRS
${
CUDA_TOOLKIT_ROOT_DIR
}
/lib/x64
)
set
(
CUDNN_LIB_NAME
""
)
if
(
LINUX
)
set
(
CUDNN_LIB_NAME
"libcudnn.so"
)
set
(
CUDNN_LIB_NAME
"libcudnn.so"
)
endif
(
LINUX
)
if
(
WIN32
)
# only support cudnn7
set
(
CUDNN_LIB_NAME
"cudnn.lib"
"cudnn64_7.dll"
)
# only support cudnn7
set
(
CUDNN_LIB_NAME
"cudnn.lib"
"cudnn64_7.dll"
)
endif
(
WIN32
)
if
(
APPLE
)
set
(
CUDNN_LIB_NAME
"libcudnn.dylib"
"libcudnn.so"
)
set
(
CUDNN_LIB_NAME
"libcudnn.dylib"
"libcudnn.so"
)
endif
(
APPLE
)
find_library
(
CUDNN_LIBRARY NAMES
${
CUDNN_LIB_NAME
}
# libcudnn_static.a
...
...
@@ -88,7 +89,7 @@ macro(find_cudnn_version cudnn_header_file)
if
(
NOT CUDNN_MAJOR_VERSION
)
set
(
CUDNN_VERSION
"???"
)
else
()
add_definitions
(
"-D
PADDLE_CUDNN_BINVER
=
\"
${
CUDNN_MAJOR_VERSION
}
\"
"
)
add_definitions
(
"-D
CUDNN_MAJOR_VERSION
=
\"
${
CUDNN_MAJOR_VERSION
}
\"
"
)
math
(
EXPR CUDNN_VERSION
"
${
CUDNN_MAJOR_VERSION
}
* 1000 +
${
CUDNN_MINOR_VERSION
}
* 100 +
${
CUDNN_PATCHLEVEL_VERSION
}
"
)
...
...
paddle/fluid/platform/dynload/dynamic_loader.cc
浏览文件 @
5d700021
...
...
@@ -57,17 +57,26 @@ struct PathNode {
static
constexpr
char
cupti_lib_path
[]
=
CUPTI_LIB_PATH
;
// NOTE: In order to adapt to the default installation path of cuda on linux
static
constexpr
char
linux_cudnn_lib_path
[]
=
"/usr/local/cuda/lib64"
;
// NOTE: In order to adapt to the default installation path of cuda
#if defined(_WIN32) && defined(PADDLE_WITH_CUDA)
static
constexpr
char
cuda_lib_path
[]
=
CUDA_TOOLKIT_ROOT_DIR
"/bin"
;
#else
static
constexpr
char
cuda_lib_path
[]
=
"/usr/local/cuda/lib64"
;
#endif
static
PathNode
s_py_site_pkg_path
;
#if defined(_WIN32) && defined(PADDLE_WITH_CUDA)
static
constexpr
char
*
win_cublas_lib
=
"cublas64_"
PADDLE_CUDA_BINVER
".dll"
;
static
constexpr
char
*
win_curand_lib
=
"curand64_"
PADDLE_CUDA_BINVER
".dll"
;
static
constexpr
char
*
win_cudnn_lib
=
"cudnn64_"
PADDLE_CUDNN_BINVER
".dll"
;
static
constexpr
char
*
win_cublas_lib
=
"cublas64_"
CUDA_VERSION_MAJOR
CUDA_VERSION_MINOR
".dll;cublas64_"
CUDA_VERSION_MAJOR
".dll"
;
static
constexpr
char
*
win_curand_lib
=
"curand64_"
CUDA_VERSION_MAJOR
CUDA_VERSION_MINOR
".dll;curand64_"
CUDA_VERSION_MAJOR
".dll"
;
static
constexpr
char
*
win_cudnn_lib
=
"cudnn64_"
CUDNN_MAJOR_VERSION
".dll"
;
static
constexpr
char
*
win_cusolver_lib
=
"cusolver64_"
PADDLE_CUDA_BINVER
".dll"
;
"cusolver64_"
CUDA_VERSION_MAJOR
CUDA_VERSION_MINOR
".dll;cusolver64_"
CUDA_VERSION_MAJOR
".dll"
;
#endif
static
inline
std
::
string
join
(
const
std
::
string
&
part1
,
...
...
@@ -87,6 +96,24 @@ static inline std::string join(const std::string& part1,
return
ret
;
}
static
inline
std
::
vector
<
std
::
string
>
split
(
const
std
::
string
&
str
,
const
std
::
string
separator
=
" "
)
{
std
::
vector
<
std
::
string
>
str_list
;
std
::
string
::
size_type
firstPos
;
firstPos
=
str
.
find_first_not_of
(
separator
,
0
);
std
::
string
::
size_type
lastPos
;
lastPos
=
str
.
find_first_of
(
separator
,
firstPos
);
while
(
std
::
string
::
npos
!=
firstPos
&&
std
::
string
::
npos
!=
lastPos
)
{
str_list
.
push_back
(
str
.
substr
(
firstPos
,
lastPos
-
firstPos
));
firstPos
=
str
.
find_first_not_of
(
separator
,
lastPos
);
lastPos
=
str
.
find_first_of
(
separator
,
firstPos
);
}
if
(
std
::
string
::
npos
==
lastPos
)
{
str_list
.
push_back
(
str
.
substr
(
firstPos
,
lastPos
-
firstPos
));
}
return
str_list
;
}
void
SetPaddleLibPath
(
const
std
::
string
&
py_site_pkg_path
)
{
s_py_site_pkg_path
.
path
=
py_site_pkg_path
;
VLOG
(
3
)
<<
"Set paddle lib path : "
<<
py_site_pkg_path
;
...
...
@@ -147,26 +174,31 @@ static inline void* GetDsoHandleFromSearchPath(
#else
int
dynload_flags
=
0
;
#endif // !_WIN32
// 1. search in user config path by FLAGS
void
*
dso_handle
=
GetDsoHandleFromSpecificPath
(
config_path
,
dso_name
,
dynload_flags
);
// 2. search in system default path
if
(
nullptr
==
dso_handle
)
{
dso_handle
=
GetDsoHandleFromDefaultPath
(
dso_name
,
dynload_flags
);
}
// 3. search in extra paths
if
(
nullptr
==
dso_handle
)
{
for
(
auto
path
:
extra_paths
)
{
dso_handle
=
GetDsoHandleFromSpecificPath
(
path
,
dso_name
,
dynload_flags
);
std
::
vector
<
std
::
string
>
dso_names
=
split
(
dso_name
,
";"
);
void
*
dso_handle
=
nullptr
;
for
(
auto
dso
:
dso_names
)
{
// 1. search in user config path by FLAGS
dso_handle
=
GetDsoHandleFromSpecificPath
(
config_path
,
dso
,
dynload_flags
);
// 2. search in extra paths
if
(
nullptr
==
dso_handle
)
{
for
(
auto
path
:
extra_paths
)
{
VLOG
(
3
)
<<
"extra_paths: "
<<
path
;
dso_handle
=
GetDsoHandleFromSpecificPath
(
path
,
dso
,
dynload_flags
);
}
}
// 3. search in system default path
if
(
nullptr
==
dso_handle
)
{
dso_handle
=
GetDsoHandleFromDefaultPath
(
dso
,
dynload_flags
);
}
if
(
nullptr
!=
dso_handle
)
break
;
}
// 4. [If Failed] logging warning if exists
// 4. [If Failed
for All dso_names
] logging warning if exists
if
(
nullptr
==
dso_handle
&&
!
warning_msg
.
empty
())
{
LOG
(
WARNING
)
<<
warning_msg
;
}
// 5. [If Failed] logging or throw error info
// 5. [If Failed
for All dso_names
] logging or throw error info
if
(
nullptr
==
dso_handle
)
{
auto
error_msg
=
"The third-party dynamic library (%s) that Paddle depends on is not "
...
...
@@ -203,7 +235,8 @@ void* GetCublasDsoHandle() {
#if defined(__APPLE__) || defined(__OSX__)
return
GetDsoHandleFromSearchPath
(
FLAGS_cuda_dir
,
"libcublas.dylib"
);
#elif defined(_WIN32) && defined(PADDLE_WITH_CUDA)
return
GetDsoHandleFromSearchPath
(
FLAGS_cuda_dir
,
win_cublas_lib
);
return
GetDsoHandleFromSearchPath
(
FLAGS_cuda_dir
,
win_cublas_lib
,
true
,
{
cuda_lib_path
});
#else
return
GetDsoHandleFromSearchPath
(
FLAGS_cuda_dir
,
"libcublas.so"
);
#endif
...
...
@@ -220,10 +253,19 @@ void* GetCUDNNDsoHandle() {
return
GetDsoHandleFromSearchPath
(
FLAGS_cudnn_dir
,
"libcudnn.dylib"
,
false
,
{},
mac_warn_meg
);
#elif defined(_WIN32) && defined(PADDLE_WITH_CUDA)
return
GetDsoHandleFromSearchPath
(
FLAGS_cudnn_dir
,
win_cudnn_lib
);
std
::
string
win_warn_meg
(
"Note: [Recommend] copy cudnn into CUDA installation directory.
\n
"
"For instance, download cudnn-10.0-windows10-x64-v7.6.5.32.zip from "
"NVIDIA's official website,
\n
"
"then, unzip it and copy it into C:
\\
Program Files
\\
NVIDIA GPU Computing "
"Toolkit
\\
CUDA/v10.0
\n
"
"You should do this according to your CUDA installation directory and "
"CUDNN version."
);
return
GetDsoHandleFromSearchPath
(
FLAGS_cudnn_dir
,
win_cudnn_lib
,
true
,
{
cuda_lib_path
},
win_warn_meg
);
#else
return
GetDsoHandleFromSearchPath
(
FLAGS_cudnn_dir
,
"libcudnn.so"
,
false
,
{
linux_cudnn
_lib_path
});
{
cuda
_lib_path
});
#endif
}
...
...
@@ -241,7 +283,8 @@ void* GetCurandDsoHandle() {
#if defined(__APPLE__) || defined(__OSX__)
return
GetDsoHandleFromSearchPath
(
FLAGS_cuda_dir
,
"libcurand.dylib"
);
#elif defined(_WIN32) && defined(PADDLE_WITH_CUDA)
return
GetDsoHandleFromSearchPath
(
FLAGS_cuda_dir
,
win_curand_lib
);
return
GetDsoHandleFromSearchPath
(
FLAGS_cuda_dir
,
win_curand_lib
,
true
,
{
cuda_lib_path
});
#else
return
GetDsoHandleFromSearchPath
(
FLAGS_cuda_dir
,
"libcurand.so"
);
#endif
...
...
@@ -251,7 +294,8 @@ void* GetCusolverDsoHandle() {
#if defined(__APPLE__) || defined(__OSX__)
return
GetDsoHandleFromSearchPath
(
FLAGS_cuda_dir
,
"libcusolver.dylib"
);
#elif defined(_WIN32) && defined(PADDLE_WITH_CUDA)
return
GetDsoHandleFromSearchPath
(
FLAGS_cuda_dir
,
win_cusolver_lib
);
return
GetDsoHandleFromSearchPath
(
FLAGS_cuda_dir
,
win_cusolver_lib
,
true
,
{
cuda_lib_path
});
#else
return
GetDsoHandleFromSearchPath
(
FLAGS_cuda_dir
,
"libcusolver.so"
);
#endif
...
...
paddle/fluid/platform/port.h
浏览文件 @
5d700021
...
...
@@ -56,7 +56,11 @@ static void *dlopen(const char *filename, int flag) {
std
::
string
file_name
(
filename
);
HMODULE
hModule
=
LoadLibrary
(
file_name
.
c_str
());
if
(
!
hModule
)
{
throw
std
::
runtime_error
(
file_name
+
" not found."
);
if
(
flag
)
{
throw
std
::
runtime_error
(
file_name
+
" not found."
);
}
else
{
return
nullptr
;
}
}
return
reinterpret_cast
<
void
*>
(
hModule
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录