Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
c10dcff1
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
未验证
提交
c10dcff1
编写于
7月 15, 2020
作者:
G
GaoWei8
提交者:
GitHub
7月 15, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refine PADDLE_ENFORCE (#25456)
* Refine PADDLE_ENFORCE in paddle/fluid/platform test=develop
上级
6c0982b9
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
87 addition
and
72 deletion
+87
-72
paddle/fluid/platform/collective_helper.h
paddle/fluid/platform/collective_helper.h
+3
-3
paddle/fluid/platform/cpu_helper.cc
paddle/fluid/platform/cpu_helper.cc
+2
-2
paddle/fluid/platform/cuda_resource_pool.cc
paddle/fluid/platform/cuda_resource_pool.cc
+4
-4
paddle/fluid/platform/cudnn_helper.h
paddle/fluid/platform/cudnn_helper.h
+2
-2
paddle/fluid/platform/device_code.cc
paddle/fluid/platform/device_code.cc
+4
-4
paddle/fluid/platform/device_context.cc
paddle/fluid/platform/device_context.cc
+5
-5
paddle/fluid/platform/dynload/tensorrt.h
paddle/fluid/platform/dynload/tensorrt.h
+19
-15
paddle/fluid/platform/gpu_info.cc
paddle/fluid/platform/gpu_info.cc
+2
-2
paddle/fluid/platform/gpu_launch_param_config.h
paddle/fluid/platform/gpu_launch_param_config.h
+1
-1
paddle/fluid/platform/init.cc
paddle/fluid/platform/init.cc
+12
-8
paddle/fluid/platform/mkldnn_reuse.h
paddle/fluid/platform/mkldnn_reuse.h
+22
-16
paddle/fluid/platform/nccl_helper.h
paddle/fluid/platform/nccl_helper.h
+6
-4
paddle/fluid/platform/profiler.cc
paddle/fluid/platform/profiler.cc
+3
-4
paddle/fluid/platform/profiler_helper.h
paddle/fluid/platform/profiler_helper.h
+1
-1
paddle/fluid/platform/resource_pool.h
paddle/fluid/platform/resource_pool.h
+1
-1
未找到文件。
paddle/fluid/platform/collective_helper.h
浏览文件 @
c10dcff1
...
...
@@ -81,7 +81,7 @@ class NCCLCommContext {
PADDLE_ENFORCE_GT
(
comm_map_
.
count
(
ring_id
),
0
,
platform
::
errors
::
InvalidArgument
(
"Comunicator in ring id %d has not been initialized."
,
ring_id
));
"Com
m
unicator in ring id %d has not been initialized."
,
ring_id
));
PADDLE_ENFORCE_EQ
(
comm_map_
.
at
(
ring_id
).
size
(),
1
,
platform
::
errors
::
InvalidArgument
(
"One device id should be specified to retrieve from "
...
...
@@ -94,11 +94,11 @@ class NCCLCommContext {
PADDLE_ENFORCE_GT
(
comm_map_
.
count
(
ring_id
),
0
,
platform
::
errors
::
InvalidArgument
(
"Comunicator of ring id %d has not been initialized."
,
ring_id
));
"Com
m
unicator of ring id %d has not been initialized."
,
ring_id
));
PADDLE_ENFORCE_GT
(
comm_map_
.
at
(
ring_id
).
count
(
dev_id
),
0
,
platform
::
errors
::
InvalidArgument
(
"Comunicator at device id %d has not been initialized in ring %d."
,
"Com
m
unicator at device id %d has not been initialized in ring %d."
,
dev_id
,
ring_id
));
return
comm_map_
.
at
(
ring_id
).
at
(
dev_id
).
get
();
}
...
...
paddle/fluid/platform/cpu_helper.cc
浏览文件 @
c10dcff1
...
...
@@ -44,8 +44,8 @@ void SetNumThreads(int num_threads) {
omp_set_num_threads
(
real_num_threads
);
#else
PADDLE_THROW
(
platform
::
errors
::
Unimplemented
(
"Th
e library (except OPENBLAS, MKLML) is to be implemented, thus
"
"number of threads can
not be set."
));
"Th
is library (except OPENBLAS, MKLML) is not supported yet, so the
"
"number of threads cannot be set."
));
#endif
}
...
...
paddle/fluid/platform/cuda_resource_pool.cc
浏览文件 @
c10dcff1
...
...
@@ -50,11 +50,11 @@ std::shared_ptr<CudaStreamObject> CudaStreamResourcePool::New(int dev_idx) {
PADDLE_ENFORCE_GE
(
dev_idx
,
0
,
platform
::
errors
::
InvalidArgument
(
"
dev_idx should be not less than 0, but got %d
"
,
dev_idx
));
"
The dev_idx should be not less than 0, but got %d.
"
,
dev_idx
));
PADDLE_ENFORCE_LT
(
dev_idx
,
pool_
.
size
(),
platform
::
errors
::
OutOfRange
(
"
dev_idx should be less than device count %d, but got %d
"
,
"
The dev_idx should be less than device count %d, but got %d.
"
,
pool_
.
size
(),
dev_idx
));
return
pool_
[
dev_idx
]
->
New
();
}
...
...
@@ -89,11 +89,11 @@ std::shared_ptr<CudaEventObject> CudaEventResourcePool::New(int dev_idx) {
PADDLE_ENFORCE_GE
(
dev_idx
,
0
,
platform
::
errors
::
InvalidArgument
(
"
dev_idx should be not less than 0, but got %d
"
,
dev_idx
));
"
The dev_idx should be not less than 0, but got %d.
"
,
dev_idx
));
PADDLE_ENFORCE_LT
(
dev_idx
,
pool_
.
size
(),
platform
::
errors
::
OutOfRange
(
"
dev_idx should be less than device count %d, but got %d
"
,
"
The dev_idx should be less than device count %d, but got %d.
"
,
pool_
.
size
(),
dev_idx
));
return
pool_
[
dev_idx
]
->
New
();
}
...
...
paddle/fluid/platform/cudnn_helper.h
浏览文件 @
c10dcff1
...
...
@@ -142,8 +142,8 @@ inline ActivationMode StringToActivationMode(const std::string& str) {
}
else
if
(
str
==
"bandpass"
)
{
return
ActivationMode
::
kBandPass
;
}
else
{
PADDLE_THROW
(
platform
::
errors
::
Unimplemented
(
"Unknown
activation string: %s."
,
str
));
PADDLE_THROW
(
platform
::
errors
::
Unimplemented
(
"Unknown CUDNN
activation string: %s."
,
str
));
}
}
...
...
paddle/fluid/platform/device_code.cc
浏览文件 @
c10dcff1
...
...
@@ -60,10 +60,10 @@ platform::DeviceCode* DeviceCodePool::Get(const platform::Place& place,
}
DeviceCodePool
::
DeviceCodePool
(
const
std
::
vector
<
platform
::
Place
>&
places
)
{
PADDLE_ENFORCE_GT
(
places
.
size
(),
0
,
errors
::
InvalidArgument
(
"Expected the number of places >= 1. Expected %d."
,
places
.
size
()));
PADDLE_ENFORCE_GT
(
places
.
size
(),
0
,
errors
::
InvalidArgument
(
"Expected the number of places >= 1. But received %d."
,
places
.
size
()));
// Remove the duplicated places
std
::
set
<
Place
>
set
;
for
(
auto
&
p
:
places
)
{
...
...
paddle/fluid/platform/device_context.cc
浏览文件 @
c10dcff1
...
...
@@ -103,9 +103,9 @@ DeviceContextPool::DeviceContextPool(
#ifdef PADDLE_WITH_CUDA
EmplaceDeviceContext
<
CUDADeviceContext
,
CUDAPlace
>
(
&
device_contexts_
,
p
);
#else
PADDLE_THROW
(
platform
::
errors
::
Unimplemented
(
"'CUDAPlace is not supported. Please re-compile with WITH_GPU.
"
"option
"
));
PADDLE_THROW
(
platform
::
errors
::
Unimplemented
(
"CUDAPlace is not supported. Please
"
"re-compile with WITH_GPU option.
"
));
#endif
}
else
if
(
platform
::
is_cuda_pinned_place
(
p
))
{
#ifdef PADDLE_WITH_CUDA
...
...
@@ -113,8 +113,8 @@ DeviceContextPool::DeviceContextPool(
&
device_contexts_
,
p
);
#else
PADDLE_THROW
(
platform
::
errors
::
Unimplemented
(
"
'CUDAPlace' is not supported. Please re-compile with WITH_GPU.
"
"option"
));
"
CUDAPlace is not supported. Please re-compile with WITH_GPU
"
"option
.
"
));
#endif
}
}
...
...
paddle/fluid/platform/dynload/tensorrt.h
浏览文件 @
c10dcff1
...
...
@@ -30,21 +30,25 @@ namespace dynload {
extern
std
::
once_flag
tensorrt_dso_flag
;
extern
void
*
tensorrt_dso_handle
;
#define DECLARE_DYNAMIC_LOAD_TENSORRT_WRAP(__name) \
struct DynLoad__##__name { \
template <typename... Args> \
auto operator()(Args... args) -> DECLARE_TYPE(__name, args...) { \
using tensorrt_func = decltype(&::__name); \
std::call_once(tensorrt_dso_flag, []() { \
tensorrt_dso_handle = \
paddle::platform::dynload::GetTensorRtDsoHandle(); \
PADDLE_ENFORCE(tensorrt_dso_handle, "load tensorrt so failed"); \
}); \
static void* p_##__name = dlsym(tensorrt_dso_handle, #__name); \
PADDLE_ENFORCE(p_##__name, "load %s failed", #__name); \
return reinterpret_cast<tensorrt_func>(p_##__name)(args...); \
} \
}; \
#define DECLARE_DYNAMIC_LOAD_TENSORRT_WRAP(__name) \
struct DynLoad__##__name { \
template <typename... Args> \
auto operator()(Args... args) -> DECLARE_TYPE(__name, args...) { \
using tensorrt_func = decltype(&::__name); \
std::call_once(tensorrt_dso_flag, []() { \
tensorrt_dso_handle = \
paddle::platform::dynload::GetTensorRtDsoHandle(); \
PADDLE_ENFORCE_NOT_NULL(tensorrt_dso_handle, \
platform::errors::Unavailable( \
"Load tensorrt %s failed", #__name)); \
}); \
static void* p_##__name = dlsym(tensorrt_dso_handle, #__name); \
PADDLE_ENFORCE_NOT_NULL( \
p_##__name, \
platform::errors::Unavailable("Load tensorrt %s failed", #__name)); \
return reinterpret_cast<tensorrt_func>(p_##__name)(args...); \
} \
}; \
extern DynLoad__##__name __name
#define TENSORRT_RAND_ROUTINE_EACH(__macro) \
...
...
paddle/fluid/platform/gpu_info.cc
浏览文件 @
c10dcff1
...
...
@@ -344,10 +344,10 @@ class RecordedCudaMallocHelper {
PADDLE_ENFORCE_GE
(
dev_id
,
0
,
platform
::
errors
::
OutOfRange
(
"Device id must be not less than 0, but got %d"
,
dev_id
));
"Device id must be not less than 0, but got %d
.
"
,
dev_id
));
PADDLE_ENFORCE_LT
(
dev_id
,
instances_
.
size
(),
platform
::
errors
::
OutOfRange
(
"Device id %d exceeds gpu card number %d"
,
platform
::
errors
::
OutOfRange
(
"Device id %d exceeds gpu card number %d
.
"
,
dev_id
,
instances_
.
size
()));
return
instances_
[
dev_id
].
get
();
}
...
...
paddle/fluid/platform/gpu_launch_param_config.h
浏览文件 @
c10dcff1
...
...
@@ -39,7 +39,7 @@ inline GpuLaunchParamConfig GetGpuLaunchConfig1D(
const
platform
::
CUDADeviceContext
&
context
,
int
element_count
)
{
PADDLE_ENFORCE_GT
(
element_count
,
0
,
platform
::
errors
::
InvalidArgument
(
"element count should greater than 0,"
" but received value is
:%d
"
,
" but received value is
%d.
"
,
element_count
));
const
int
theory_thread_count
=
element_count
;
...
...
paddle/fluid/platform/init.cc
浏览文件 @
c10dcff1
...
...
@@ -117,14 +117,18 @@ void InitCupti() {
#ifdef PADDLE_WITH_CUPTI
if
(
FLAGS_multiple_of_cupti_buffer_size
==
1
)
return
;
size_t
attrValue
=
0
,
attrValueSize
=
sizeof
(
size_t
);
#define MULTIPLY_ATTR_VALUE(attr) \
{ \
PADDLE_ENFORCE(!platform::dynload::cuptiActivityGetAttribute( \
attr, &attrValueSize, &attrValue)); \
attrValue *= FLAGS_multiple_of_cupti_buffer_size; \
LOG(WARNING) << "Set " #attr " " << attrValue << " byte"; \
PADDLE_ENFORCE(!platform::dynload::cuptiActivitySetAttribute( \
attr, &attrValueSize, &attrValue)); \
#define MULTIPLY_ATTR_VALUE(attr) \
{ \
PADDLE_ENFORCE_EQ( \
!platform::dynload::cuptiActivityGetAttribute(attr, &attrValueSize, \
&attrValue), \
true, platform::errors::Unavailable("Get cupti attribute failed.")); \
attrValue *= FLAGS_multiple_of_cupti_buffer_size; \
LOG(WARNING) << "Set " #attr " " << attrValue << " byte"; \
PADDLE_ENFORCE_EQ( \
!platform::dynload::cuptiActivitySetAttribute(attr, &attrValueSize, \
&attrValue), \
true, platform::errors::Unavailable("Set cupti attribute failed.")); \
}
MULTIPLY_ATTR_VALUE
(
CUPTI_ACTIVITY_ATTR_DEVICE_BUFFER_SIZE
);
MULTIPLY_ATTR_VALUE
(
CUPTI_ACTIVITY_ATTR_DEVICE_BUFFER_SIZE_CDP
);
...
...
paddle/fluid/platform/mkldnn_reuse.h
浏览文件 @
c10dcff1
...
...
@@ -500,17 +500,17 @@ class BinaryMKLDNNHandler : public platform::MKLDNNHandlerT<T, dnnl::binary> {
if
(
!
this
->
isCached
())
{
PADDLE_ENFORCE_EQ
(
x
->
layout
(),
DataLayout
::
kMKLDNN
,
platform
::
errors
::
InvalidArgument
(
"Wrong layout set for X tensor"
));
platform
::
errors
::
InvalidArgument
(
"Wrong layout set for X tensor
.
"
));
PADDLE_ENFORCE_NE
(
x
->
format
(),
MKLDNNMemoryFormat
::
undef
,
platform
::
errors
::
InvalidArgument
(
"Wrong format set for X tensor"
));
platform
::
errors
::
InvalidArgument
(
"Wrong format set for X tensor
.
"
));
PADDLE_ENFORCE_EQ
(
y
->
layout
(),
DataLayout
::
kMKLDNN
,
platform
::
errors
::
InvalidArgument
(
"Wrong layout set for Y tensor"
));
platform
::
errors
::
InvalidArgument
(
"Wrong layout set for Y tensor
.
"
));
PADDLE_ENFORCE_NE
(
y
->
format
(),
MKLDNNMemoryFormat
::
undef
,
platform
::
errors
::
InvalidArgument
(
"Wrong format set for Y tensor"
));
platform
::
errors
::
InvalidArgument
(
"Wrong format set for Y tensor
.
"
));
const
auto
src_x_tz
=
framework
::
vectorize
(
x
->
dims
());
const
auto
src_y_tz
=
framework
::
vectorize
(
y
->
dims
());
...
...
@@ -774,10 +774,10 @@ class PoolingMKLDNNHandler : public MKLDNNHandlerT<T, mkldnn::pooling_forward,
if
(
!
this
->
isCached
())
{
PADDLE_ENFORCE_EQ
(
input
->
layout
(),
DataLayout
::
kMKLDNN
,
platform
::
errors
::
InvalidArgument
(
"Wrong layout set for Input tensor"
));
"Wrong layout set for Input tensor
.
"
));
PADDLE_ENFORCE_NE
(
input
->
format
(),
MKLDNNMemoryFormat
::
undef
,
platform
::
errors
::
InvalidArgument
(
"Wrong format set for Input tensor"
));
"Wrong format set for Input tensor
.
"
));
const
std
::
string
pooling_type
=
ctx
.
Attr
<
std
::
string
>
(
"pooling_type"
);
...
...
@@ -795,15 +795,21 @@ class PoolingMKLDNNHandler : public MKLDNNHandlerT<T, mkldnn::pooling_forward,
ctx
.
Attr
<
std
::
string
>
(
"padding_algorithm"
);
// Only 2D pooling is supported now
PADDLE_ENFORCE_EQ
(
ksize
.
size
(),
2
,
platform
::
errors
::
InvalidArgument
(
"ksize must be 2D, i.e. 2D pooling"
));
PADDLE_ENFORCE_EQ
(
pooling_type
==
"max"
||
pooling_type
==
"avg"
,
true
,
platform
::
errors
::
InvalidArgument
(
"pooling_type must be 'max' or 'avg'"
));
PADDLE_ENFORCE_EQ
(
input
->
dims
().
size
(),
4
,
platform
::
errors
::
InvalidArgument
(
"Input dim must be with 4, i.e. NCHW"
));
PADDLE_ENFORCE_EQ
(
ksize
.
size
(),
2
,
platform
::
errors
::
InvalidArgument
(
"The ksize must be 2D, i.e. 2D pooling, but received %dD."
,
ksize
.
size
()));
PADDLE_ENFORCE_EQ
(
pooling_type
==
"max"
||
pooling_type
==
"avg"
,
true
,
platform
::
errors
::
InvalidArgument
(
"The pooling_type must be 'max' or 'avg', but received %s."
,
pooling_type
));
PADDLE_ENFORCE_EQ
(
input
->
dims
().
size
(),
4
,
platform
::
errors
::
InvalidArgument
(
"Input dim must be with 4, i.e. NCHW, but received %d."
,
input
->
dims
().
size
()));
const
auto
input_dims
=
input
->
dims
();
framework
::
DDim
data_dims
=
...
...
@@ -1421,7 +1427,7 @@ static std::shared_ptr<mkldnn::memory> SetDstMemory(
residual_param_data
,
platform
::
errors
::
PreconditionNotMet
(
"Residual parameter is required for "
"the DNNL conv+elementwise_add "
"fusion, but now it is missing"
));
"fusion, but now it is missing
.
"
));
std
::
shared_ptr
<
mkldnn
::
memory
>
user_residual_memory_p
=
handler
->
AcquireResidualDataMemory
(
user_residual_md
,
to_void_cast
<
T
>
(
residual_param_data
));
...
...
paddle/fluid/platform/nccl_helper.h
浏览文件 @
c10dcff1
...
...
@@ -96,8 +96,9 @@ struct NCCLContextMap {
explicit
NCCLContextMap
(
const
std
::
vector
<
platform
::
Place
>
&
places
,
ncclUniqueId
*
nccl_id
=
nullptr
,
size_t
num_trainers
=
1
,
size_t
trainer_id
=
0
)
{
PADDLE_ENFORCE_EQ
(
!
places
.
empty
(),
true
,
platform
::
errors
::
InvalidArgument
(
"The NCCL place is empty."
));
PADDLE_ENFORCE_EQ
(
!
places
.
empty
(),
true
,
platform
::
errors
::
InvalidArgument
(
"The NCCL place should not be empty."
));
order_
.
reserve
(
places
.
size
());
for
(
auto
&
p
:
places
)
{
int
dev_id
=
BOOST_GET_CONST
(
CUDAPlace
,
p
).
device
;
...
...
@@ -276,8 +277,9 @@ class NCCLCommunicator {
PADDLE_ENFORCE_GT
(
inter_trainers_num
,
1
,
platform
::
errors
::
InvalidArgument
(
"inter_trainers_num:%llu must > 1"
,
inter_trainers_num
));
platform
::
errors
::
InvalidArgument
(
"The inter_trainers_num:%llu should be larger than 1."
,
inter_trainers_num
));
int
inter_trainer_id
=
trainer_id
%
inter_trainers_num
;
for
(
size_t
i
=
0
;
i
<
inter_nccl_ids
.
size
();
i
++
)
{
...
...
paddle/fluid/platform/profiler.cc
浏览文件 @
c10dcff1
...
...
@@ -94,10 +94,9 @@ void MemEvenRecorder::PushMemRecord(const void *ptr, const Place &place,
if
(
g_state
==
ProfilerState
::
kDisabled
)
return
;
std
::
lock_guard
<
std
::
mutex
>
guard
(
mtx_
);
auto
&
events
=
address_memevent_
[
place
];
PADDLE_ENFORCE_EQ
(
events
.
count
(
ptr
),
0
,
platform
::
errors
::
InvalidArgument
(
"The Place can't exist in the stage of PushMemRecord"
));
PADDLE_ENFORCE_EQ
(
events
.
count
(
ptr
),
0
,
platform
::
errors
::
InvalidArgument
(
"The Place can't exist in the stage of PushMemRecord"
));
events
.
emplace
(
ptr
,
std
::
unique_ptr
<
RecordMemEvent
>
(
new
MemEvenRecorder
::
RecordMemEvent
(
place
,
size
)));
}
...
...
paddle/fluid/platform/profiler_helper.h
浏览文件 @
c10dcff1
...
...
@@ -570,7 +570,7 @@ void PrintProfiler(
}
else
{
PADDLE_THROW
(
platform
::
errors
::
InvalidArgument
(
"Except profiler state must to be one of ['CPU', 'GPU' 'ALL'], but "
"received Invalid profiler state"
));
"received Invalid profiler state
.
"
));
}
if
(
merge_thread
)
{
...
...
paddle/fluid/platform/resource_pool.h
浏览文件 @
c10dcff1
...
...
@@ -60,7 +60,7 @@ class ResourcePool : public std::enable_shared_from_this<ResourcePool<T>> {
obj
=
creator_
();
PADDLE_ENFORCE_NOT_NULL
(
obj
,
platform
::
errors
::
PermissionDenied
(
"The creator should not return nullptr"
));
"The creator should not return nullptr
.
"
));
VLOG
(
10
)
<<
"Create new instance "
<<
TypePtrName
();
}
else
{
obj
=
instances_
.
back
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录