Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
d2aaa751
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2305
Star
20932
Fork
5423
代码
文件
提交
分支
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看板
未验证
提交
d2aaa751
编写于
3月 22, 2022
作者:
Z
zyfncg
提交者:
GitHub
3月 22, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Optimize performance of C++ Api (part2) (#40729)
* optimize performance of C++ API * remove stop_data_transform flag temparily
上级
72a2bfe2
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
39 addition
and
27 deletion
+39
-27
paddle/phi/api/lib/backend_set.h
paddle/phi/api/lib/backend_set.h
+1
-1
paddle/phi/api/lib/data_transform.cc
paddle/phi/api/lib/data_transform.cc
+8
-9
paddle/phi/api/lib/data_type_set.h
paddle/phi/api/lib/data_type_set.h
+1
-1
paddle/phi/api/lib/kernel_dispatch.cc
paddle/phi/api/lib/kernel_dispatch.cc
+11
-2
paddle/phi/api/lib/kernel_dispatch.h
paddle/phi/api/lib/kernel_dispatch.h
+13
-10
paddle/phi/core/compat/convert_utils.cc
paddle/phi/core/compat/convert_utils.cc
+5
-4
未找到文件。
paddle/phi/api/lib/backend_set.h
浏览文件 @
d2aaa751
...
@@ -35,7 +35,7 @@ class BackendSet final {
...
@@ -35,7 +35,7 @@ class BackendSet final {
:
bitset_
(
b
==
Backend
::
UNDEFINED
?
0
:
1ULL
<<
(
static_cast
<
uint8_t
>
(
b
)
-
:
bitset_
(
b
==
Backend
::
UNDEFINED
?
0
:
1ULL
<<
(
static_cast
<
uint8_t
>
(
b
)
-
1
))
{}
1
))
{}
uint64_t
bitset
()
const
{
return
bitset_
;
}
inline
uint64_t
bitset
()
const
{
return
bitset_
;
}
bool
inline
Has
(
Backend
b
)
const
{
bool
inline
Has
(
Backend
b
)
const
{
PD_CHECK
(
b
!=
Backend
::
UNDEFINED
,
"Backend argument can't be UNDEFINED."
);
PD_CHECK
(
b
!=
Backend
::
UNDEFINED
,
"Backend argument can't be UNDEFINED."
);
...
...
paddle/phi/api/lib/data_transform.cc
浏览文件 @
d2aaa751
...
@@ -39,7 +39,7 @@ inline bool NeedTransformPlace(const paddle::platform::Place& input,
...
@@ -39,7 +39,7 @@ inline bool NeedTransformPlace(const paddle::platform::Place& input,
const
TransformFlag
&
transform_flag
)
{
const
TransformFlag
&
transform_flag
)
{
bool
ret
=
transform_flag
.
need_trans_backend
()
&&
bool
ret
=
transform_flag
.
need_trans_backend
()
&&
target
!=
Backend
::
ALL_BACKEND
&&
target
!=
Backend
::
ALL_BACKEND
&&
!
platform
::
is_same_place
(
input
,
phi
::
TransToPhiPlace
(
target
))
;
phi
::
TransToPhiBackend
(
input
)
!=
target
;
return
ret
;
return
ret
;
}
}
...
@@ -180,21 +180,20 @@ std::shared_ptr<phi::DenseTensor> PrepareData(
...
@@ -180,21 +180,20 @@ std::shared_ptr<phi::DenseTensor> PrepareData(
const
phi
::
TensorArgDef
&
target_args_def
,
const
phi
::
TensorArgDef
&
target_args_def
,
const
TransformFlag
&
transform_flag
)
{
const
TransformFlag
&
transform_flag
)
{
const
auto
&
tensor_in
=
input
.
impl
();
const
auto
&
tensor_in
=
input
.
impl
();
VLOG
(
6
)
<<
tensor_in
->
dtype
()
<<
"
\t
"
<<
target_args_def
.
dtype
;
phi
::
DenseTensor
&
dense_tensor
=
if
(
!
transform_flag
.
NeedTransform
()
||
!
tensor_in
->
initialized
()
||
*
static_cast
<
phi
::
DenseTensor
*>
(
tensor_in
.
get
());
if
(
!
transform_flag
.
NeedTransform
()
||
!
dense_tensor
.
initialized
()
||
(
!
NeedTransformPlace
(
(
!
NeedTransformPlace
(
tensor_in
->
place
(),
target_args_def
.
backend
,
transform_flag
)
&&
dense_tensor
.
place
(),
target_args_def
.
backend
,
transform_flag
)
&&
!
NeedTransformDataType
(
!
NeedTransformDataType
(
tensor_in
->
dtype
(),
target_args_def
.
dtype
,
transform_flag
)
&&
dense_tensor
.
dtype
(),
target_args_def
.
dtype
,
transform_flag
)
&&
!
NeedTransformLayout
(
!
NeedTransformLayout
(
tensor_in
->
layout
(),
target_args_def
.
layout
,
transform_flag
)))
{
dense_tensor
.
layout
(),
target_args_def
.
layout
,
transform_flag
)))
{
return
std
::
static_pointer_cast
<
phi
::
DenseTensor
>
(
tensor_in
);
return
std
::
static_pointer_cast
<
phi
::
DenseTensor
>
(
tensor_in
);
}
}
phi
::
DenseTensor
out
=
phi
::
DenseTensor
out
=
TransformData
(
*
(
static_cast
<
phi
::
DenseTensor
*>
(
tensor_in
.
get
())),
TransformData
(
dense_tensor
,
target_args_def
,
transform_flag
);
target_args_def
,
transform_flag
);
return
std
::
make_shared
<
phi
::
DenseTensor
>
(
std
::
move
(
out
));
return
std
::
make_shared
<
phi
::
DenseTensor
>
(
std
::
move
(
out
));
}
}
...
...
paddle/phi/api/lib/data_type_set.h
浏览文件 @
d2aaa751
...
@@ -30,7 +30,7 @@ class DataTypeSet final {
...
@@ -30,7 +30,7 @@ class DataTypeSet final {
?
0
?
0
:
1ULL
<<
(
static_cast
<
uint8_t
>
(
dtype
)
-
1
))
{}
:
1ULL
<<
(
static_cast
<
uint8_t
>
(
dtype
)
-
1
))
{}
uint64_t
bitset
()
const
{
return
bitset_
;
}
inline
uint64_t
bitset
()
const
{
return
bitset_
;
}
bool
inline
Has
(
DataType
dtype
)
const
{
bool
inline
Has
(
DataType
dtype
)
const
{
PD_CHECK
(
dtype
!=
DataType
::
UNDEFINED
,
PD_CHECK
(
dtype
!=
DataType
::
UNDEFINED
,
...
...
paddle/phi/api/lib/kernel_dispatch.cc
浏览文件 @
d2aaa751
...
@@ -16,13 +16,16 @@ limitations under the License. */
...
@@ -16,13 +16,16 @@ limitations under the License. */
#include "paddle/phi/api/include/context_pool.h"
#include "paddle/phi/api/include/context_pool.h"
#include "paddle/phi/core/compat/convert_utils.h"
#include "paddle/phi/core/compat/convert_utils.h"
#ifdef _MSC_VER
#include <intrin.h>
#endif
namespace
paddle
{
namespace
paddle
{
namespace
experimental
{
namespace
experimental
{
namespace
detail
{
namespace
detail
{
BackendSet
GetTensorBackendSet
(
const
Tensor
&
t
)
{
BackendSet
GetTensorBackendSet
(
const
phi
::
TensorBase
&
t
)
{
BackendSet
backend_set
(
phi
::
TransToPhiBackend
(
t
.
inner_
place
()));
BackendSet
backend_set
(
phi
::
TransToPhiBackend
(
t
.
place
()));
switch
(
t
.
layout
())
{
switch
(
t
.
layout
())
{
case
DataLayout
::
MKLDNN
:
case
DataLayout
::
MKLDNN
:
backend_set
=
backend_set
|
BackendSet
(
Backend
::
MKLDNN
);
backend_set
=
backend_set
|
BackendSet
(
Backend
::
MKLDNN
);
...
@@ -35,6 +38,11 @@ BackendSet GetTensorBackendSet(const Tensor& t) {
...
@@ -35,6 +38,11 @@ BackendSet GetTensorBackendSet(const Tensor& t) {
}
}
std
::
size_t
CountLeadingZeros
(
uint64_t
val
)
{
std
::
size_t
CountLeadingZeros
(
uint64_t
val
)
{
#if defined(__clang__) || defined(__GNUC__)
return
__builtin_clzl
(
val
);
#elif defined(_MSC_VER)
return
__lzcnt64
(
val
);
#else
if
(
val
==
0
)
{
if
(
val
==
0
)
{
return
64
;
return
64
;
}
}
...
@@ -48,6 +56,7 @@ std::size_t CountLeadingZeros(uint64_t val) {
...
@@ -48,6 +56,7 @@ std::size_t CountLeadingZeros(uint64_t val) {
}
}
}
}
return
zero_bits
;
return
zero_bits
;
#endif
}
}
}
// namespace detail
}
// namespace detail
...
...
paddle/phi/api/lib/kernel_dispatch.h
浏览文件 @
d2aaa751
...
@@ -33,7 +33,7 @@ namespace paddle {
...
@@ -33,7 +33,7 @@ namespace paddle {
namespace
experimental
{
namespace
experimental
{
namespace
detail
{
namespace
detail
{
BackendSet
GetTensorBackendSet
(
const
Tensor
&
t
);
BackendSet
GetTensorBackendSet
(
const
phi
::
TensorBase
&
t
);
std
::
size_t
CountLeadingZeros
(
uint64_t
val
);
std
::
size_t
CountLeadingZeros
(
uint64_t
val
);
}
// namespace detail
}
// namespace detail
...
@@ -93,11 +93,13 @@ struct KernelKeyParser : ArgsIterator<KernelKeyParser> {
...
@@ -93,11 +93,13 @@ struct KernelKeyParser : ArgsIterator<KernelKeyParser> {
// TODO(chenweihang): deal with multiple diff input Tensors
// TODO(chenweihang): deal with multiple diff input Tensors
// TODO(chenweihang): add global device guard method to set backend
// TODO(chenweihang): add global device guard method to set backend
void
operator
()(
const
Tensor
&
x
)
{
void
operator
()(
const
Tensor
&
x
)
{
key_set
.
backend_set
=
key_set
.
backend_set
|
detail
::
GetTensorBackendSet
(
x
);
const
phi
::
TensorBase
&
tensor
=
*
x
.
impl
();
// TODO(chenweihang): selecte multi layout and dtype
key_set
.
backend_set
=
key_set
.
layout
=
x
.
layout
();
key_set
.
backend_set
|
detail
::
GetTensorBackendSet
(
tensor
);
key_set
.
dtype
=
x
.
type
();
// TODO(chenweihang): select multi layout and dtype
dtype_set
=
dtype_set
|
DataTypeSet
(
x
.
dtype
());
key_set
.
layout
=
tensor
.
layout
();
key_set
.
dtype
=
tensor
.
dtype
();
dtype_set
=
dtype_set
|
DataTypeSet
(
key_set
.
dtype
);
auto
promote_result
=
PromoteTypes
(
dtype_set
);
auto
promote_result
=
PromoteTypes
(
dtype_set
);
if
(
promote_result
!=
DataType
::
UNDEFINED
)
{
if
(
promote_result
!=
DataType
::
UNDEFINED
)
{
key_set
.
dtype
=
promote_result
;
key_set
.
dtype
=
promote_result
;
...
@@ -105,11 +107,12 @@ struct KernelKeyParser : ArgsIterator<KernelKeyParser> {
...
@@ -105,11 +107,12 @@ struct KernelKeyParser : ArgsIterator<KernelKeyParser> {
}
}
void
operator
()(
const
std
::
vector
<
Tensor
>&
x
)
{
void
operator
()(
const
std
::
vector
<
Tensor
>&
x
)
{
const
phi
::
TensorBase
&
tensor
=
*
x
.
at
(
0
).
impl
();
key_set
.
backend_set
=
key_set
.
backend_set
=
key_set
.
backend_set
|
detail
::
GetTensorBackendSet
(
x
[
0
]
);
key_set
.
backend_set
|
detail
::
GetTensorBackendSet
(
tensor
);
// TODO(chenweihang): select
e
multi layout and dtype
// TODO(chenweihang): select multi layout and dtype
key_set
.
layout
=
x
[
0
]
.
layout
();
key_set
.
layout
=
tensor
.
layout
();
key_set
.
dtype
=
x
[
0
].
type
();
key_set
.
dtype
=
tensor
.
d
type
();
}
}
// skip other type args, these args don't used in kernel selection
// skip other type args, these args don't used in kernel selection
...
...
paddle/phi/core/compat/convert_utils.cc
浏览文件 @
d2aaa751
...
@@ -26,13 +26,14 @@ limitations under the License. */
...
@@ -26,13 +26,14 @@ limitations under the License. */
namespace
phi
{
namespace
phi
{
Backend
TransToPhiBackend
(
const
phi
::
Place
&
place
)
{
Backend
TransToPhiBackend
(
const
phi
::
Place
&
place
)
{
if
(
place
.
GetType
()
==
phi
::
AllocationType
::
CPU
)
{
auto
allocation_type
=
place
.
GetType
();
if
(
allocation_type
==
phi
::
AllocationType
::
CPU
)
{
return
Backend
::
CPU
;
return
Backend
::
CPU
;
}
else
if
(
place
.
GetType
()
==
phi
::
AllocationType
::
GPU
)
{
}
else
if
(
allocation_type
==
phi
::
AllocationType
::
GPU
)
{
return
Backend
::
GPU
;
return
Backend
::
GPU
;
}
else
if
(
place
.
GetType
()
==
phi
::
AllocationType
::
XPU
)
{
}
else
if
(
allocation_type
==
phi
::
AllocationType
::
XPU
)
{
return
Backend
::
XPU
;
return
Backend
::
XPU
;
}
else
if
(
place
.
GetType
()
==
phi
::
AllocationType
::
CUSTOM
)
{
}
else
if
(
allocation_type
==
phi
::
AllocationType
::
CUSTOM
)
{
return
static_cast
<
Backend
>
(
return
static_cast
<
Backend
>
(
static_cast
<
size_t
>
(
Backend
::
NUM_BACKENDS
)
+
static_cast
<
size_t
>
(
Backend
::
NUM_BACKENDS
)
+
GetOrRegisterGlobalDeviceTypeId
(
place
.
GetDeviceType
()));
GetOrRegisterGlobalDeviceTypeId
(
place
.
GetDeviceType
()));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录