Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
b3a3e6f6
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
b3a3e6f6
编写于
11月 14, 2019
作者:
C
Chen Weihang
提交者:
Tao Luo
11月 14, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change cuda enforce & add example (#21142)
上级
37e0e7a9
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
61 addition
and
33 deletion
+61
-33
paddle/fluid/memory/allocation/cuda_device_context_allocator.h
...e/fluid/memory/allocation/cuda_device_context_allocator.h
+2
-1
paddle/fluid/platform/enforce.h
paddle/fluid/platform/enforce.h
+59
-32
未找到文件。
paddle/fluid/memory/allocation/cuda_device_context_allocator.h
浏览文件 @
b3a3e6f6
...
...
@@ -81,7 +81,8 @@ class CUDADeviceContextAllocator : public Allocator {
platform
::
CUDADeviceGuard
guard
(
place_
.
device
);
PADDLE_ENFORCE_CUDA_SUCCESS
(
cudaEventCreate
(
&
event_
,
cudaEventDisableTiming
),
"Create event failed in CUDADeviceContextAllocator"
);
platform
::
errors
::
External
(
"Create event failed in CUDADeviceContextAllocator"
));
}
~
CUDADeviceContextAllocator
()
{
...
...
paddle/fluid/platform/enforce.h
浏览文件 @
b3a3e6f6
...
...
@@ -373,6 +373,10 @@ struct EOFException : public std::exception {
inline
bool
is_error
(
cudaError_t
e
)
{
return
e
!=
cudaSuccess
;
}
inline
std
::
string
build_ex_string
(
cudaError_t
e
,
const
std
::
string
&
msg
)
{
return
msg
;
}
inline
void
throw_on_error
(
cudaError_t
e
,
const
std
::
string
&
msg
)
{
#ifndef REPLACE_ENFORCE_GLOG
throw
thrust
::
system_error
(
e
,
thrust
::
cuda_category
(),
msg
);
...
...
@@ -385,6 +389,11 @@ inline bool is_error(curandStatus_t stat) {
return
stat
!=
CURAND_STATUS_SUCCESS
;
}
inline
std
::
string
build_ex_string
(
curandStatus_t
stat
,
const
std
::
string
&
msg
)
{
return
msg
;
}
inline
void
throw_on_error
(
curandStatus_t
stat
,
const
std
::
string
&
msg
)
{
#ifndef REPLACE_ENFORCE_GLOG
throw
thrust
::
system_error
(
cudaErrorLaunchFailure
,
thrust
::
cuda_category
(),
...
...
@@ -398,11 +407,15 @@ inline bool is_error(cudnnStatus_t stat) {
return
stat
!=
CUDNN_STATUS_SUCCESS
;
}
inline
std
::
string
build_ex_string
(
cudnnStatus_t
stat
,
const
std
::
string
&
msg
)
{
return
msg
+
"
\n
["
+
platform
::
dynload
::
cudnnGetErrorString
(
stat
)
+
"]"
;
}
inline
void
throw_on_error
(
cudnnStatus_t
stat
,
const
std
::
string
&
msg
)
{
#ifndef REPLACE_ENFORCE_GLOG
throw
std
::
runtime_error
(
platform
::
dynload
::
cudnnGetErrorString
(
stat
)
+
msg
);
throw
std
::
runtime_error
(
msg
);
#else
LOG
(
FATAL
)
<<
platform
::
dynload
::
cudnnGetErrorString
(
stat
)
<<
msg
;
LOG
(
FATAL
)
<<
msg
;
#endif
}
...
...
@@ -410,31 +423,36 @@ inline bool is_error(cublasStatus_t stat) {
return
stat
!=
CUBLAS_STATUS_SUCCESS
;
}
inline
void
throw_on_error
(
cublasStatus_t
stat
,
const
std
::
string
&
msg
)
{
inline
std
::
string
build_ex_string
(
cublasStatus_t
stat
,
const
std
::
string
&
msg
)
{
std
::
string
err
;
if
(
stat
==
CUBLAS_STATUS_NOT_INITIALIZED
)
{
err
=
"CUBLAS: not initialized
,
"
;
err
=
"CUBLAS: not initialized
.
"
;
}
else
if
(
stat
==
CUBLAS_STATUS_ALLOC_FAILED
)
{
err
=
"CUBLAS: alloc failed
,
"
;
err
=
"CUBLAS: alloc failed
.
"
;
}
else
if
(
stat
==
CUBLAS_STATUS_INVALID_VALUE
)
{
err
=
"CUBLAS: invalid value
,
"
;
err
=
"CUBLAS: invalid value
.
"
;
}
else
if
(
stat
==
CUBLAS_STATUS_ARCH_MISMATCH
)
{
err
=
"CUBLAS: arch mismatch
,
"
;
err
=
"CUBLAS: arch mismatch
.
"
;
}
else
if
(
stat
==
CUBLAS_STATUS_MAPPING_ERROR
)
{
err
=
"CUBLAS: mapping error
,
"
;
err
=
"CUBLAS: mapping error
.
"
;
}
else
if
(
stat
==
CUBLAS_STATUS_EXECUTION_FAILED
)
{
err
=
"CUBLAS: execution failed
,
"
;
err
=
"CUBLAS: execution failed
.
"
;
}
else
if
(
stat
==
CUBLAS_STATUS_INTERNAL_ERROR
)
{
err
=
"CUBLAS: internal error
,
"
;
err
=
"CUBLAS: internal error
.
"
;
}
else
if
(
stat
==
CUBLAS_STATUS_NOT_SUPPORTED
)
{
err
=
"CUBLAS: not supported, "
;
}
else
if
(
stat
==
CUBLAS_STATUS_LICENSE_ERROR
)
{
err
=
"CUBLAS: license error
,
"
;
err
=
"CUBLAS: license error
.
"
;
}
return
msg
+
"
\n
["
+
err
+
"]"
;
}
inline
void
throw_on_error
(
cublasStatus_t
stat
,
const
std
::
string
&
msg
)
{
#ifndef REPLACE_ENFORCE_GLOG
throw
std
::
runtime_error
(
err
+
msg
);
throw
std
::
runtime_error
(
msg
);
#else
LOG
(
FATAL
)
<<
err
<<
msg
;
LOG
(
FATAL
)
<<
msg
;
#endif
}
...
...
@@ -443,11 +461,17 @@ inline bool is_error(ncclResult_t nccl_result) {
return
nccl_result
!=
ncclSuccess
;
}
inline
void
throw_on_error
(
ncclResult_t
stat
,
const
std
::
string
&
msg
)
{
inline
std
::
string
build_ex_string
(
ncclResult_t
nccl_result
,
const
std
::
string
&
msg
)
{
return
msg
+
"
\n
["
+
platform
::
dynload
::
ncclGetErrorString
(
nccl_result
)
+
"]"
;
}
inline
void
throw_on_error
(
ncclResult_t
nccl_result
,
const
std
::
string
&
msg
)
{
#ifndef REPLACE_ENFORCE_GLOG
throw
std
::
runtime_error
(
platform
::
dynload
::
ncclGetErrorString
(
stat
)
+
msg
);
throw
std
::
runtime_error
(
msg
);
#else
LOG
(
FATAL
)
<<
platform
::
dynload
::
ncclGetErrorString
(
stat
)
<<
msg
;
LOG
(
FATAL
)
<<
msg
;
#endif
}
#endif // __APPLE__ and windows
...
...
@@ -480,22 +504,25 @@ DEFINE_CUDA_STATUS_TYPE(ncclResult_t, ncclSuccess);
#endif // PADDLE_WITH_CUDA
#ifdef PADDLE_WITH_CUDA
#define PADDLE_ENFORCE_CUDA_SUCCESS(COND, ...) \
do { \
auto __cond__ = (COND); \
using __CUDA_STATUS_TYPE__ = decltype(__cond__); \
constexpr auto __success_type__ = \
::paddle::platform::details::CudaStatusType< \
__CUDA_STATUS_TYPE__>::kSuccess; \
if (UNLIKELY(__cond__ != __success_type__)) { \
try { \
::paddle::platform::throw_on_error( \
__cond__, ::paddle::string::Sprintf(__VA_ARGS__)); \
} catch (...) { \
throw ::paddle::platform::EnforceNotMet(std::current_exception(), \
__FILE__, __LINE__); \
} \
} \
#define PADDLE_ENFORCE_CUDA_SUCCESS(COND, ...) \
do { \
auto __cond__ = (COND); \
using __CUDA_STATUS_TYPE__ = decltype(__cond__); \
constexpr auto __success_type__ = \
::paddle::platform::details::CudaStatusType< \
__CUDA_STATUS_TYPE__>::kSuccess; \
if (UNLIKELY(__cond__ != __success_type__)) { \
try { \
::paddle::platform::throw_on_error( \
__cond__, \
::paddle::platform::build_ex_string( \
__cond__, \
::paddle::platform::ErrorSummary(__VA_ARGS__).ToString())); \
} catch (...) { \
throw ::paddle::platform::EnforceNotMet(std::current_exception(), \
__FILE__, __LINE__); \
} \
} \
} while (0)
#undef DEFINE_CUDA_STATUS_TYPE
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录