Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
ed9ec699
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看板
未验证
提交
ed9ec699
编写于
8月 18, 2023
作者:
W
wanghuancoder
提交者:
GitHub
8月 18, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix stride legacy inplace bug (#56418)
上级
e5b71671
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
64 addition
and
2 deletion
+64
-2
paddle/fluid/imperative/tracer.cc
paddle/fluid/imperative/tracer.cc
+10
-2
paddle/phi/api/lib/api_gen_utils.cc
paddle/phi/api/lib/api_gen_utils.cc
+50
-0
paddle/phi/api/lib/api_gen_utils.h
paddle/phi/api/lib/api_gen_utils.h
+4
-0
未找到文件。
paddle/fluid/imperative/tracer.cc
浏览文件 @
ed9ec699
...
@@ -410,6 +410,9 @@ void Tracer::TraceOp(const std::string& type,
...
@@ -410,6 +410,9 @@ void Tracer::TraceOp(const std::string& type,
VLOG
(
6
)
<<
"Running On Eager TraceOp with use_default_attr_map: "
VLOG
(
6
)
<<
"Running On Eager TraceOp with use_default_attr_map: "
<<
use_default_attr_map
;
<<
use_default_attr_map
;
std
::
map
<
phi
::
DenseTensor
*
,
phi
::
DenseTensor
*>
need_backup_inputs2outputs
;
std
::
map
<
phi
::
DenseTensor
*
,
phi
::
DenseTensor
*>
need_backup_inputs2outputs
;
std
::
map
<
phi
::
DenseTensor
*
,
std
::
shared_ptr
<
phi
::
Allocation
>>
need_backup_inputs2holder
;
std
::
map
<
phi
::
DenseTensor
*
,
phi
::
DDim
>
need_backup_inputs2strides
;
if
(
FLAGS_use_stride_kernel
)
{
if
(
FLAGS_use_stride_kernel
)
{
for
(
auto
&
iter
:
inplace_map
)
{
for
(
auto
&
iter
:
inplace_map
)
{
auto
inputs_iter
=
ins
.
find
(
iter
.
first
);
auto
inputs_iter
=
ins
.
find
(
iter
.
first
);
...
@@ -426,11 +429,12 @@ void Tracer::TraceOp(const std::string& type,
...
@@ -426,11 +429,12 @@ void Tracer::TraceOp(const std::string& type,
outputs_iter
->
second
[
i
]
outputs_iter
->
second
[
i
]
->
MutableVar
()
->
MutableVar
()
->
GetMutable
<
phi
::
DenseTensor
>
();
->
GetMutable
<
phi
::
DenseTensor
>
();
need_backup_inputs2holder
[
dense_tensor
]
=
dense_tensor
->
Holder
();
need_backup_inputs2strides
[
dense_tensor
]
=
dense_tensor
->
strides
();
}
}
}
}
}
}
}
}
TraceOpImpl
<
egr
::
EagerVariable
>
(
type
,
TraceOpImpl
<
egr
::
EagerVariable
>
(
type
,
ins
,
ins
,
outs
,
outs
,
...
@@ -443,7 +447,11 @@ void Tracer::TraceOp(const std::string& type,
...
@@ -443,7 +447,11 @@ void Tracer::TraceOp(const std::string& type,
auto
dev_ctx
=
paddle
::
platform
::
DeviceContextPool
::
Instance
().
Get
(
place
);
auto
dev_ctx
=
paddle
::
platform
::
DeviceContextPool
::
Instance
().
Get
(
place
);
for
(
auto
&
iter
:
need_backup_inputs2outputs
)
{
for
(
auto
&
iter
:
need_backup_inputs2outputs
)
{
paddle
::
experimental
::
TransStride
(
dev_ctx
,
iter
.
second
,
iter
.
first
);
iter
.
first
->
ResetHolder
(
need_backup_inputs2holder
[
iter
.
first
]);
iter
.
first
->
set_strides
(
need_backup_inputs2strides
[
iter
.
first
]);
paddle
::
experimental
::
TransStrideLegacy
(
dev_ctx
,
iter
.
second
,
iter
.
first
);
iter
.
second
->
ResetHolder
(
need_backup_inputs2holder
[
iter
.
first
]);
iter
.
second
->
set_strides
(
need_backup_inputs2strides
[
iter
.
first
]);
}
}
}
else
{
}
else
{
TraceOpImpl
<
egr
::
EagerVariable
>
(
type
,
TraceOpImpl
<
egr
::
EagerVariable
>
(
type
,
...
...
paddle/phi/api/lib/api_gen_utils.cc
浏览文件 @
ed9ec699
...
@@ -423,6 +423,56 @@ void TransStride(phi::DeviceContext* dev_ctx,
...
@@ -423,6 +423,56 @@ void TransStride(phi::DeviceContext* dev_ctx,
}
}
}
}
void
TransStrideLegacy
(
phi
::
DeviceContext
*
dev_ctx
,
phi
::
DenseTensor
*
from
,
phi
::
DenseTensor
*
to
)
{
if
(
to
)
{
auto
*
cpu_ctx
=
dynamic_cast
<
phi
::
CPUContext
*>
(
dev_ctx
);
if
(
cpu_ctx
)
{
PD_VISIT_ALL_TYPES
(
to
->
dtype
(),
"StridedCopyKernel"
,
([
&
]
{
phi
::
StridedCopyKernel
<
data_t
,
phi
::
CPUContext
>
(
*
cpu_ctx
,
*
from
,
phi
::
vectorize
<
int64_t
>
(
to
->
dims
()),
phi
::
vectorize
<
int64_t
>
(
to
->
strides
()),
to
->
offset
(),
to
);
}));
return
;
}
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
auto
*
gpu_ctx
=
dynamic_cast
<
phi
::
GPUContext
*>
(
dev_ctx
);
if
(
gpu_ctx
)
{
PD_VISIT_ALL_TYPES
(
to
->
dtype
(),
"StridedCopyKernel"
,
([
&
]
{
phi
::
StridedCopyKernel
<
data_t
,
phi
::
GPUContext
>
(
*
gpu_ctx
,
*
from
,
phi
::
vectorize
<
int64_t
>
(
to
->
dims
()),
phi
::
vectorize
<
int64_t
>
(
to
->
strides
()),
to
->
offset
(),
to
);
}));
return
;
}
#endif
#ifdef PADDLE_WITH_XPU
auto
*
xpu_ctx
=
dynamic_cast
<
phi
::
XPUContext
*>
(
dev_ctx
);
if
(
xpu_ctx
)
{
PD_VISIT_ALL_TYPES
(
to
->
dtype
(),
"StridedCopyKernel"
,
([
&
]
{
phi
::
StridedCopyKernel
<
data_t
,
phi
::
XPUContext
>
(
*
xpu_ctx
,
*
from
,
phi
::
vectorize
<
int64_t
>
(
to
->
dims
()),
phi
::
vectorize
<
int64_t
>
(
to
->
strides
()),
to
->
offset
(),
to
);
}));
return
;
}
#endif
}
}
void
TransStride
(
phi
::
DeviceContext
*
dev_ctx
,
void
TransStride
(
phi
::
DeviceContext
*
dev_ctx
,
const
std
::
vector
<
phi
::
DenseTensor
*>&
from
,
const
std
::
vector
<
phi
::
DenseTensor
*>&
from
,
const
std
::
vector
<
phi
::
DenseTensor
*>&
to
)
{
const
std
::
vector
<
phi
::
DenseTensor
*>&
to
)
{
...
...
paddle/phi/api/lib/api_gen_utils.h
浏览文件 @
ed9ec699
...
@@ -133,6 +133,10 @@ void TransStride(phi::DeviceContext* dev_ctx,
...
@@ -133,6 +133,10 @@ void TransStride(phi::DeviceContext* dev_ctx,
phi
::
SelectedRows
*
from
,
phi
::
SelectedRows
*
from
,
phi
::
SelectedRows
*
to
);
phi
::
SelectedRows
*
to
);
void
TransStrideLegacy
(
phi
::
DeviceContext
*
dev_ctx
,
phi
::
DenseTensor
*
from
,
phi
::
DenseTensor
*
to
);
#ifdef PADDLE_WITH_DISTRIBUTE
#ifdef PADDLE_WITH_DISTRIBUTE
/* ------------------ for auto parallel ----------------------- */
/* ------------------ for auto parallel ----------------------- */
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录