Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
e4c438f5
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看板
未验证
提交
e4c438f5
编写于
1月 06, 2023
作者:
H
HongyuJia
提交者:
GitHub
1月 06, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Custom device stream] Acquire custom_deivce stream, add unit test (#49571)
* acquire custom_deivce stream * regulate file name and unittest
上级
0093aaa6
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
36 addition
and
3 deletion
+36
-3
python/paddle/fluid/tests/custom_runtime/CMakeLists.txt
python/paddle/fluid/tests/custom_runtime/CMakeLists.txt
+1
-1
python/paddle/fluid/tests/custom_runtime/custom_op.cc
python/paddle/fluid/tests/custom_runtime/custom_op.cc
+22
-0
python/paddle/fluid/tests/custom_runtime/test_custom_op_setup.py
...paddle/fluid/tests/custom_runtime/test_custom_op_setup.py
+13
-2
未找到文件。
python/paddle/fluid/tests/custom_runtime/CMakeLists.txt
浏览文件 @
e4c438f5
...
...
@@ -28,5 +28,5 @@ if(WITH_CUSTOM_DEVICE AND NOT WITH_GPU)
set_tests_properties
(
test_custom_cpu_profiler_plugin PROPERTIES TIMEOUT 120
)
set_tests_properties
(
test_fleet_launch_custom_device PROPERTIES TIMEOUT 120
)
set_tests_properties
(
test_custom_cpu_to_static PROPERTIES TIMEOUT 120
)
set_tests_properties
(
test_custom_
device_relu
_setup PROPERTIES TIMEOUT 120
)
set_tests_properties
(
test_custom_
op
_setup PROPERTIES TIMEOUT 120
)
endif
()
python/paddle/fluid/tests/custom_runtime/custom_
relu_
op.cc
→
python/paddle/fluid/tests/custom_runtime/custom_op.cc
浏览文件 @
e4c438f5
...
...
@@ -16,6 +16,7 @@
#include <vector>
#include "paddle/extension.h"
#include "paddle/phi/backends/all_context.h"
#define CHECK_CPU_INPUT(x) PD_CHECK(x.is_cpu(), #x " must be a CPU Tensor.")
#define CHECK_CUSTOM_INPUT(x) \
...
...
@@ -191,3 +192,24 @@ PD_BUILD_DOUBLE_GRAD_OP(custom_relu)
.
Outputs
({
paddle
::
Grad
(
paddle
::
Grad
(
"Out"
))})
.
SetKernelFn
(
PD_KERNEL
(
ReluDoubleBackward
))
.
SetInferShapeFn
(
PD_INFER_SHAPE
(
ReluDoubleBackwardInferShape
));
std
::
vector
<
paddle
::
Tensor
>
StreamForward
(
const
paddle
::
Tensor
&
x
)
{
CHECK_CUSTOM_INPUT
(
x
);
auto
dev_ctx
=
paddle
::
experimental
::
DeviceContextPool
::
Instance
().
Get
(
x
.
place
());
auto
custom_ctx
=
static_cast
<
const
phi
::
CustomContext
*>
(
dev_ctx
);
void
*
stream
=
custom_ctx
->
stream
();
PD_CHECK
(
stream
!=
nullptr
);
std
::
cout
<<
"Check stream != nullptr successfully"
<<
std
::
endl
;
custom_ctx
->
Wait
();
std
::
cout
<<
"Check Wait successfully"
<<
std
::
endl
;
return
{
x
};
}
PD_BUILD_OP
(
custom_stream
)
.
Inputs
({
"X"
})
.
Outputs
({
"Out"
})
.
SetKernelFn
(
PD_KERNEL
(
StreamForward
));
python/paddle/fluid/tests/custom_runtime/test_custom_
device_relu
_setup.py
→
python/paddle/fluid/tests/custom_runtime/test_custom_
op
_setup.py
浏览文件 @
e4c438f5
...
...
@@ -177,14 +177,15 @@ class TestNewCustomOpSetUpInstall(unittest.TestCase):
)
custom_module
=
paddle
.
utils
.
cpp_extension
.
load
(
name
=
'custom_device
_relu
'
,
sources
=
[
'custom_
relu_
op.cc'
],
name
=
'custom_device'
,
sources
=
[
'custom_op.cc'
],
extra_include_paths
=
paddle_includes
,
# add for Coverage CI
extra_cxx_cflags
=
[
"-w"
,
"-g"
],
# test for cc flags
# build_directory=self.cur_dir,
verbose
=
True
,
)
self
.
custom_op
=
custom_module
.
custom_relu
self
.
custom_stream_op
=
custom_module
.
custom_stream
self
.
dtypes
=
[
"float32"
,
"float64"
]
self
.
device
=
"custom_cpu"
...
...
@@ -204,6 +205,7 @@ class TestNewCustomOpSetUpInstall(unittest.TestCase):
self
.
_test_dynamic
()
self
.
_test_double_grad_dynamic
()
self
.
_test_with_dataloader
()
self
.
_test_stream
()
def
_test_static
(
self
):
for
dtype
in
self
.
dtypes
:
...
...
@@ -317,6 +319,15 @@ class TestNewCustomOpSetUpInstall(unittest.TestCase):
if
batch_id
==
5
:
break
def
_test_stream
(
self
):
import
paddle
paddle
.
set_device
(
self
.
device
)
x
=
paddle
.
ones
([
2
,
2
],
dtype
=
'float32'
)
out
=
self
.
custom_stream_op
(
x
)
np
.
testing
.
assert_array_equal
(
x
.
numpy
(),
out
.
numpy
())
if
__name__
==
"__main__"
:
if
os
.
name
==
'nt'
or
sys
.
platform
.
startswith
(
'darwin'
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录