Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
f1711f24
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2310
Star
20933
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看板
未验证
提交
f1711f24
编写于
4月 20, 2022
作者:
C
Chen Weihang
提交者:
GitHub
4月 20, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[CustomOp] Fix custom op pinned input error (#41972)
* fix custom op pinned input error * fix compile error
上级
d70104e5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
40 addition
and
0 deletion
+40
-0
paddle/fluid/framework/custom_operator.cc
paddle/fluid/framework/custom_operator.cc
+12
-0
python/paddle/fluid/tests/custom_op/test_custom_relu_op_setup.py
...paddle/fluid/tests/custom_op/test_custom_relu_op_setup.py
+28
-0
未找到文件。
paddle/fluid/framework/custom_operator.cc
浏览文件 @
f1711f24
...
...
@@ -33,6 +33,7 @@ limitations under the License. */
#include "paddle/fluid/framework/operator.h"
#include "paddle/fluid/framework/phi_utils.h"
#include "paddle/fluid/framework/tensor.h"
#include "paddle/fluid/platform/device/gpu/gpu_info.h"
#include "paddle/fluid/platform/dynload/dynamic_loader.h"
#include "paddle/fluid/string/string_helper.h"
#include "paddle/phi/api/all.h"
...
...
@@ -160,7 +161,18 @@ static void RunKernelFunc(const framework::ExecutionContext& ctx,
"Input tensor (%s) is not initialized."
,
in_name
));
paddle
::
experimental
::
Tensor
custom_in
;
custom_in
.
set_impl
(
std
::
make_shared
<
phi
::
DenseTensor
>
(
*
x
));
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
if
(
custom_in
.
is_gpu_pinned
())
{
VLOG
(
3
)
<<
"Custom Operator: custom input is gpu pinned tensor"
;
auto
gpu_place
=
phi
::
GPUPlace
(
platform
::
GetCurrentDeviceId
());
auto
custom_gpu_in
=
custom_in
.
copy_to
(
gpu_place
,
true
);
kernel_ctx
.
EmplaceBackInput
(
std
::
move
(
custom_gpu_in
));
}
else
{
kernel_ctx
.
EmplaceBackInput
(
std
::
move
(
custom_in
));
}
#else
kernel_ctx
.
EmplaceBackInput
(
std
::
move
(
custom_in
));
#endif
}
}
...
...
python/paddle/fluid/tests/custom_op/test_custom_relu_op_setup.py
浏览文件 @
f1711f24
...
...
@@ -20,6 +20,7 @@ import paddle
import
paddle.static
as
static
import
subprocess
import
numpy
as
np
from
paddle.vision.transforms
import
Compose
,
Normalize
from
paddle.utils.cpp_extension.extension_utils
import
run_cmd
from
paddle.fluid.framework
import
_test_eager_guard
...
...
@@ -329,6 +330,33 @@ class TestNewCustomOpSetUpInstall(unittest.TestCase):
"custom op dx grad: {},
\n
paddle api dx grad: {}"
.
format
(
dx_grad
,
pd_dx_grad
))
def
test_with_dataloader
(
self
):
for
device
in
self
.
devices
:
paddle
.
set_device
(
device
)
# data loader
transform
=
Compose
(
[
Normalize
(
mean
=
[
127.5
],
std
=
[
127.5
],
data_format
=
'CHW'
)])
train_dataset
=
paddle
.
vision
.
datasets
.
MNIST
(
mode
=
'train'
,
transform
=
transform
)
train_loader
=
paddle
.
io
.
DataLoader
(
train_dataset
,
batch_size
=
64
,
shuffle
=
True
,
drop_last
=
True
,
num_workers
=
0
)
for
batch_id
,
(
image
,
_
)
in
enumerate
(
train_loader
()):
out
=
self
.
custom_ops
[
0
](
image
)
pd_out
=
paddle
.
nn
.
functional
.
relu
(
image
)
self
.
assertTrue
(
np
.
array_equal
(
out
,
pd_out
),
"custom op out: {},
\n
paddle api out: {}"
.
format
(
out
,
pd_out
))
if
batch_id
==
5
:
break
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录