Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
db6242e9
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
db6242e9
编写于
9月 08, 2021
作者:
L
Leo Chen
提交者:
GitHub
9月 08, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[NPU] release gil before op run (#35370)
* release gil before op run * support npu grad test * fix op_test
上级
3dab2e20
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
38 addition
and
15 deletion
+38
-15
paddle/fluid/pybind/pybind.cc
paddle/fluid/pybind/pybind.cc
+17
-4
paddle/fluid/pybind/tensor_py.h
paddle/fluid/pybind/tensor_py.h
+20
-1
python/paddle/fluid/tests/unittests/op_test.py
python/paddle/fluid/tests/unittests/op_test.py
+1
-10
未找到文件。
paddle/fluid/pybind/pybind.cc
浏览文件 @
db6242e9
...
...
@@ -1849,19 +1849,32 @@ All parameter, weight, gradient are variables in Paddle.
})
.
def
(
"run"
,
[](
OperatorBase
&
self
,
const
Scope
&
scope
,
const
platform
::
CPUPlace
&
place
)
{
self
.
Run
(
scope
,
place
);
})
const
platform
::
CPUPlace
&
place
)
{
pybind11
::
gil_scoped_release
release
;
self
.
Run
(
scope
,
place
);
})
.
def
(
"run"
,
[](
OperatorBase
&
self
,
const
Scope
&
scope
,
const
platform
::
XPUPlace
&
place
)
{
self
.
Run
(
scope
,
place
);
})
const
platform
::
XPUPlace
&
place
)
{
pybind11
::
gil_scoped_release
release
;
self
.
Run
(
scope
,
place
);
})
.
def
(
"run"
,
[](
OperatorBase
&
self
,
const
Scope
&
scope
,
const
platform
::
NPUPlace
&
place
)
{
self
.
Run
(
scope
,
place
);
})
const
platform
::
NPUPlace
&
place
)
{
pybind11
::
gil_scoped_release
release
;
self
.
Run
(
scope
,
place
);
})
.
def
(
"run"
,
[](
OperatorBase
&
self
,
const
Scope
&
scope
,
const
platform
::
CUDAPlace
&
place
)
{
self
.
Run
(
scope
,
place
);
})
const
platform
::
CUDAPlace
&
place
)
{
pybind11
::
gil_scoped_release
release
;
self
.
Run
(
scope
,
place
);
})
.
def
(
"run"
,
[](
OperatorBase
&
self
,
const
Scope
&
scope
,
const
platform
::
CUDAPinnedPlace
&
place
)
{
pybind11
::
gil_scoped_release
release
;
self
.
Run
(
scope
,
place
);
})
.
def
(
"type"
,
...
...
paddle/fluid/pybind/tensor_py.h
浏览文件 @
db6242e9
...
...
@@ -216,6 +216,7 @@ T TensorGetElement(const framework::Tensor &self, size_t offset) {
PADDLE_ENFORCE_LT
(
offset
,
self
.
numel
(),
platform
::
errors
::
InvalidArgument
(
"The offset exceeds the size of tensor."
));
T
b
=
static_cast
<
T
>
(
0
);
if
(
platform
::
is_cpu_place
(
self
.
place
()))
{
b
=
self
.
data
<
T
>
()[
offset
];
...
...
@@ -231,8 +232,17 @@ T TensorGetElement(const framework::Tensor &self, size_t offset) {
auto
p
=
BOOST_GET_CONST
(
platform
::
CUDAPlace
,
self
.
place
());
paddle
::
memory
::
Copy
(
platform
::
CPUPlace
(),
&
b
,
p
,
a
+
offset
,
sizeof
(
T
),
nullptr
);
#endif
}
else
if
(
platform
::
is_npu_place
(
self
.
place
()))
{
#if defined(PADDLE_WITH_ASCEND_CL)
const
T
*
a
=
self
.
data
<
T
>
();
auto
p
=
BOOST_GET_CONST
(
platform
::
NPUPlace
,
self
.
place
());
paddle
::
memory
::
Copy
(
platform
::
CPUPlace
(),
&
b
,
p
,
a
+
offset
,
sizeof
(
T
),
nullptr
);
#endif
}
VLOG
(
10
)
<<
"TensorGetElement, place: "
<<
self
.
place
()
<<
", offset: "
<<
offset
<<
", element: "
<<
b
;
return
b
;
}
...
...
@@ -241,6 +251,8 @@ void TensorSetElement(framework::Tensor *self, size_t offset, T elem) {
PADDLE_ENFORCE_LT
(
offset
,
self
->
numel
(),
platform
::
errors
::
InvalidArgument
(
"The offset exceeds the size of tensor."
));
VLOG
(
10
)
<<
"TensorSetElement, place: "
<<
self
->
place
()
<<
", offset: "
<<
offset
<<
", element: "
<<
elem
;
if
(
platform
::
is_cpu_place
(
self
->
place
()))
{
self
->
mutable_data
<
T
>
(
self
->
place
())[
offset
]
=
elem
;
}
else
if
(
platform
::
is_xpu_place
(
self
->
place
()))
{
...
...
@@ -255,6 +267,13 @@ void TensorSetElement(framework::Tensor *self, size_t offset, T elem) {
T
*
a
=
self
->
mutable_data
<
T
>
(
p
);
paddle
::
memory
::
Copy
(
p
,
a
+
offset
,
platform
::
CPUPlace
(),
&
elem
,
sizeof
(
T
),
nullptr
);
#endif
}
else
if
(
platform
::
is_npu_place
(
self
->
place
()))
{
#if defined(PADDLE_WITH_ASCEND_CL)
auto
p
=
BOOST_GET_CONST
(
platform
::
NPUPlace
,
self
->
place
());
T
*
a
=
self
->
mutable_data
<
T
>
(
p
);
paddle
::
memory
::
Copy
(
p
,
a
+
offset
,
platform
::
CPUPlace
(),
&
elem
,
sizeof
(
T
),
nullptr
);
#endif
}
}
...
...
@@ -676,7 +695,7 @@ inline py::array TensorToPyArray(const framework::Tensor &tensor,
size_t
numel
=
1
;
for
(
int
i
=
tensor_dims
.
size
()
-
1
;
i
>=
0
;
--
i
)
{
py_dims
[
i
]
=
(
size_t
)
tensor_dims
[
i
]
;
py_dims
[
i
]
=
static_cast
<
size_t
>
(
tensor_dims
[
i
])
;
py_strides
[
i
]
=
sizeof_dtype
*
numel
;
numel
*=
py_dims
[
i
];
}
...
...
python/paddle/fluid/tests/unittests/op_test.py
浏览文件 @
db6242e9
...
...
@@ -1491,18 +1491,9 @@ class OpTest(unittest.TestCase):
if
not
type
(
output_names
)
is
list
:
output_names
=
[
output_names
]
# FIXME: Replace numeric_place with place to calculate numeric_grads.
# NOTE(liym27): There is an unknown error when call op.run() on NPUPlace, which
# needs to be fixed.
if
hasattr
(
self
.
__class__
,
"use_npu"
)
and
self
.
__class__
.
use_npu
==
True
:
numeric_place
=
paddle
.
CPUPlace
()
else
:
numeric_place
=
place
numeric_grads
=
user_defined_grads
or
[
get_numeric_gradient
(
numeric_
place
,
place
,
self
.
scope
,
self
.
op
,
self
.
inputs
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录