Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
cb73feea
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
cb73feea
编写于
7月 07, 2021
作者:
P
pangyoki
提交者:
GitHub
7月 07, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add Wait after TensorCopy (#34005)
上级
cbf22d65
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
14 addition
and
11 deletion
+14
-11
paddle/fluid/operators/uniform_random_op_npu.cc
paddle/fluid/operators/uniform_random_op_npu.cc
+10
-9
python/paddle/fluid/tests/unittests/npu/test_uniform_random_op_npu.py
...e/fluid/tests/unittests/npu/test_uniform_random_op_npu.py
+1
-1
python/paddle/fluid/tests/unittests/op_test.py
python/paddle/fluid/tests/unittests/op_test.py
+3
-1
未找到文件。
paddle/fluid/operators/uniform_random_op_npu.cc
浏览文件 @
cb73feea
...
@@ -56,10 +56,13 @@ class NPUUniformRandomKernel : public framework::OpKernel<T> {
...
@@ -56,10 +56,13 @@ class NPUUniformRandomKernel : public framework::OpKernel<T> {
"unsupport type: %s."
,
"unsupport type: %s."
,
framework
::
ToTypeName
(
out_var
->
Type
())));
framework
::
ToTypeName
(
out_var
->
Type
())));
}
}
T
*
data
=
tensor
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
tensor
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
int64_t
size
=
tensor
->
numel
();
int64_t
size
=
tensor
->
numel
();
std
::
unique_ptr
<
T
[]
>
data_cpu
(
new
T
[
size
]);
Tensor
cpu_tensor
(
tensor
->
type
());
cpu_tensor
.
Resize
(
tensor
->
dims
());
T
*
data_cpu
=
cpu_tensor
.
mutable_data
<
T
>
(
platform
::
CPUPlace
());
std
::
uniform_real_distribution
<
T
>
dist
(
std
::
uniform_real_distribution
<
T
>
dist
(
static_cast
<
T
>
(
ctx
.
Attr
<
float
>
(
"min"
)),
static_cast
<
T
>
(
ctx
.
Attr
<
float
>
(
"min"
)),
static_cast
<
T
>
(
ctx
.
Attr
<
float
>
(
"max"
)));
static_cast
<
T
>
(
ctx
.
Attr
<
float
>
(
"max"
)));
...
@@ -90,12 +93,10 @@ class NPUUniformRandomKernel : public framework::OpKernel<T> {
...
@@ -90,12 +93,10 @@ class NPUUniformRandomKernel : public framework::OpKernel<T> {
}
}
// copy to NPU
// copy to NPU
auto
stream
=
framework
::
TensorCopy
(
ctx
.
template
device_context
<
paddle
::
platform
::
NPUDeviceContext
>()
cpu_tensor
,
ctx
.
GetPlace
(),
.
stream
();
ctx
.
template
device_context
<
platform
::
DeviceContext
>(),
tensor
);
memory
::
Copy
(
BOOST_GET_CONST
(
platform
::
NPUPlace
,
ctx
.
GetPlace
()),
data
,
ctx
.
template
device_context
<
paddle
::
platform
::
NPUDeviceContext
>().
Wait
();
platform
::
CPUPlace
(),
reinterpret_cast
<
void
*>
(
data_cpu
.
get
()),
size
*
sizeof
(
T
),
stream
);
}
}
};
};
...
...
python/paddle/fluid/tests/unittests/npu/test_uniform_random_op_npu.py
浏览文件 @
cb73feea
...
@@ -67,7 +67,7 @@ class TestNPUUniformRandomOp(OpTest):
...
@@ -67,7 +67,7 @@ class TestNPUUniformRandomOp(OpTest):
self
.
dtype
=
np
.
float32
self
.
dtype
=
np
.
float32
def
test_check_output
(
self
):
def
test_check_output
(
self
):
self
.
check_output_customized
(
self
.
verify_output
)
self
.
check_output_customized
(
self
.
verify_output
,
self
.
place
)
def
verify_output
(
self
,
outs
):
def
verify_output
(
self
,
outs
):
hist
,
prob
=
self
.
output_hist
(
np
.
array
(
outs
[
0
]))
hist
,
prob
=
self
.
output_hist
(
np
.
array
(
outs
[
0
]))
...
...
python/paddle/fluid/tests/unittests/op_test.py
浏览文件 @
cb73feea
...
@@ -1357,8 +1357,10 @@ class OpTest(unittest.TestCase):
...
@@ -1357,8 +1357,10 @@ class OpTest(unittest.TestCase):
if
self
.
op_type
not
in
compile_vs_runtime_white_list
.
COMPILE_RUN_OP_WHITE_LIST
:
if
self
.
op_type
not
in
compile_vs_runtime_white_list
.
COMPILE_RUN_OP_WHITE_LIST
:
self
.
check_compile_vs_runtime
(
fetch_list
,
outs
)
self
.
check_compile_vs_runtime
(
fetch_list
,
outs
)
def
check_output_customized
(
self
,
checker
):
def
check_output_customized
(
self
,
checker
,
custom_place
=
None
):
places
=
self
.
_get_places
()
places
=
self
.
_get_places
()
if
custom_place
:
places
.
append
(
custom_place
)
for
place
in
places
:
for
place
in
places
:
outs
=
self
.
calc_output
(
place
)
outs
=
self
.
calc_output
(
place
)
outs
=
[
np
.
array
(
out
)
for
out
in
outs
]
outs
=
[
np
.
array
(
out
)
for
out
in
outs
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录