Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
834face8
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 2 年 前同步成功
通知
2325
Star
20933
Fork
5424
代码
文件
提交
分支
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看板
未验证
提交
834face8
编写于
9月 08, 2020
作者:
W
wawltor
提交者:
GitHub
9月 08, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix the CudaPinMemory bug for the compare op
fix the CudaPinMemory bug for the equal op, add the branch for the CudaPinnedMemory
上级
a8e355af
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
42 addition
and
2 deletion
+42
-2
paddle/fluid/operators/controlflow/compare_op.cc
paddle/fluid/operators/controlflow/compare_op.cc
+10
-2
python/paddle/fluid/tests/unittests/test_compare_op.py
python/paddle/fluid/tests/unittests/test_compare_op.py
+32
-0
未找到文件。
paddle/fluid/operators/controlflow/compare_op.cc
浏览文件 @
834face8
...
@@ -111,8 +111,16 @@ class CompareOp : public framework::OperatorWithKernel {
...
@@ -111,8 +111,16 @@ class CompareOp : public framework::OperatorWithKernel {
framework
::
OpKernelType
kt
=
OperatorWithKernel
::
GetExpectedKernelType
(
ctx
);
framework
::
OpKernelType
kt
=
OperatorWithKernel
::
GetExpectedKernelType
(
ctx
);
// CompareOp kernel's device type is decided by input tensor place
// CompareOp kernel's device type is decided by input tensor place
bool
force_cpu
=
ctx
.
Attr
<
bool
>
(
"force_cpu"
);
bool
force_cpu
=
ctx
.
Attr
<
bool
>
(
"force_cpu"
);
kt
.
place_
=
force_cpu
?
platform
::
CPUPlace
()
if
(
force_cpu
)
{
:
ctx
.
Input
<
framework
::
LoDTensor
>
(
"X"
)
->
place
();
kt
.
place_
=
platform
::
CPUPlace
();
}
else
{
if
(
ctx
.
Input
<
framework
::
LoDTensor
>
(
"X"
)
->
place
().
type
()
!=
typeid
(
platform
::
CUDAPinnedPlace
))
{
kt
.
place_
=
ctx
.
Input
<
framework
::
LoDTensor
>
(
"X"
)
->
place
();
}
else
{
kt
.
place_
=
ctx
.
GetPlace
();
}
}
return
kt
;
return
kt
;
}
}
};
};
...
...
python/paddle/fluid/tests/unittests/test_compare_op.py
浏览文件 @
834face8
...
@@ -38,6 +38,7 @@ def create_test_class(op_type, typename, callback):
...
@@ -38,6 +38,7 @@ def create_test_class(op_type, typename, callback):
self
.
check_output
()
self
.
check_output
()
def
test_errors
(
self
):
def
test_errors
(
self
):
paddle
.
enable_static
()
with
program_guard
(
Program
(),
Program
()):
with
program_guard
(
Program
(),
Program
()):
x
=
fluid
.
layers
.
data
(
name
=
'x'
,
shape
=
[
2
],
dtype
=
'int32'
)
x
=
fluid
.
layers
.
data
(
name
=
'x'
,
shape
=
[
2
],
dtype
=
'int32'
)
y
=
fluid
.
layers
.
data
(
name
=
'y'
,
shape
=
[
2
],
dtype
=
'int32'
)
y
=
fluid
.
layers
.
data
(
name
=
'y'
,
shape
=
[
2
],
dtype
=
'int32'
)
...
@@ -80,6 +81,7 @@ def create_paddle_case(op_type, callback):
...
@@ -80,6 +81,7 @@ def create_paddle_case(op_type, callback):
self
.
place
=
paddle
.
CUDAPlace
(
0
)
self
.
place
=
paddle
.
CUDAPlace
(
0
)
def
test_api
(
self
):
def
test_api
(
self
):
paddle
.
enable_static
()
with
program_guard
(
Program
(),
Program
()):
with
program_guard
(
Program
(),
Program
()):
x
=
fluid
.
data
(
name
=
'x'
,
shape
=
[
4
],
dtype
=
'int64'
)
x
=
fluid
.
data
(
name
=
'x'
,
shape
=
[
4
],
dtype
=
'int64'
)
y
=
fluid
.
data
(
name
=
'y'
,
shape
=
[
4
],
dtype
=
'int64'
)
y
=
fluid
.
data
(
name
=
'y'
,
shape
=
[
4
],
dtype
=
'int64'
)
...
@@ -92,6 +94,7 @@ def create_paddle_case(op_type, callback):
...
@@ -92,6 +94,7 @@ def create_paddle_case(op_type, callback):
self
.
assertEqual
((
res
==
self
.
real_result
).
all
(),
True
)
self
.
assertEqual
((
res
==
self
.
real_result
).
all
(),
True
)
def
test_broadcast_api_1
(
self
):
def
test_broadcast_api_1
(
self
):
paddle
.
enable_static
()
with
program_guard
(
Program
(),
Program
()):
with
program_guard
(
Program
(),
Program
()):
x
=
paddle
.
static
.
data
(
x
=
paddle
.
static
.
data
(
name
=
'x'
,
shape
=
[
1
,
2
,
1
,
3
],
dtype
=
'int32'
)
name
=
'x'
,
shape
=
[
1
,
2
,
1
,
3
],
dtype
=
'int32'
)
...
@@ -108,6 +111,7 @@ def create_paddle_case(op_type, callback):
...
@@ -108,6 +111,7 @@ def create_paddle_case(op_type, callback):
self
.
assertEqual
((
res
==
real_result
).
all
(),
True
)
self
.
assertEqual
((
res
==
real_result
).
all
(),
True
)
def
test_attr_name
(
self
):
def
test_attr_name
(
self
):
paddle
.
enable_static
()
with
program_guard
(
Program
(),
Program
()):
with
program_guard
(
Program
(),
Program
()):
x
=
fluid
.
layers
.
data
(
name
=
'x'
,
shape
=
[
4
],
dtype
=
'int32'
)
x
=
fluid
.
layers
.
data
(
name
=
'x'
,
shape
=
[
4
],
dtype
=
'int32'
)
y
=
fluid
.
layers
.
data
(
name
=
'y'
,
shape
=
[
4
],
dtype
=
'int32'
)
y
=
fluid
.
layers
.
data
(
name
=
'y'
,
shape
=
[
4
],
dtype
=
'int32'
)
...
@@ -130,6 +134,7 @@ create_paddle_case('not_equal', lambda _a, _b: _a != _b)
...
@@ -130,6 +134,7 @@ create_paddle_case('not_equal', lambda _a, _b: _a != _b)
class
TestCompareOpError
(
unittest
.
TestCase
):
class
TestCompareOpError
(
unittest
.
TestCase
):
def
test_errors
(
self
):
def
test_errors
(
self
):
paddle
.
enable_static
()
with
program_guard
(
Program
(),
Program
()):
with
program_guard
(
Program
(),
Program
()):
# The input x and y of compare_op must be Variable.
# The input x and y of compare_op must be Variable.
x
=
fluid
.
layers
.
data
(
name
=
'x'
,
shape
=
[
1
],
dtype
=
"float32"
)
x
=
fluid
.
layers
.
data
(
name
=
'x'
,
shape
=
[
1
],
dtype
=
"float32"
)
...
@@ -140,6 +145,7 @@ class TestCompareOpError(unittest.TestCase):
...
@@ -140,6 +145,7 @@ class TestCompareOpError(unittest.TestCase):
class
API_TestElementwise_Equal
(
unittest
.
TestCase
):
class
API_TestElementwise_Equal
(
unittest
.
TestCase
):
def
test_api
(
self
):
def
test_api
(
self
):
paddle
.
enable_static
()
with
fluid
.
program_guard
(
fluid
.
Program
(),
fluid
.
Program
()):
with
fluid
.
program_guard
(
fluid
.
Program
(),
fluid
.
Program
()):
label
=
fluid
.
layers
.
assign
(
np
.
array
([
3
,
3
],
dtype
=
"int32"
))
label
=
fluid
.
layers
.
assign
(
np
.
array
([
3
,
3
],
dtype
=
"int32"
))
limit
=
fluid
.
layers
.
assign
(
np
.
array
([
3
,
2
],
dtype
=
"int32"
))
limit
=
fluid
.
layers
.
assign
(
np
.
array
([
3
,
2
],
dtype
=
"int32"
))
...
@@ -159,5 +165,31 @@ class API_TestElementwise_Equal(unittest.TestCase):
...
@@ -159,5 +165,31 @@ class API_TestElementwise_Equal(unittest.TestCase):
self
.
assertEqual
((
res
==
np
.
array
([
True
,
True
])).
all
(),
True
)
self
.
assertEqual
((
res
==
np
.
array
([
True
,
True
])).
all
(),
True
)
class
TestCompareOpPlace
(
unittest
.
TestCase
):
def
test_place_1
(
self
):
paddle
.
enable_static
()
place
=
paddle
.
CPUPlace
()
if
core
.
is_compiled_with_cuda
():
place
=
paddle
.
CUDAPlace
(
0
)
label
=
fluid
.
layers
.
assign
(
np
.
array
([
3
,
3
],
dtype
=
"int32"
))
limit
=
fluid
.
layers
.
assign
(
np
.
array
([
3
,
2
],
dtype
=
"int32"
))
out
=
fluid
.
layers
.
less_than
(
label
,
limit
,
force_cpu
=
True
)
exe
=
fluid
.
Executor
(
place
)
res
,
=
exe
.
run
(
fetch_list
=
[
out
])
self
.
assertEqual
((
res
==
np
.
array
([
False
,
False
])).
all
(),
True
)
def
test_place_2
(
self
):
place
=
paddle
.
CPUPlace
()
data_place
=
place
if
core
.
is_compiled_with_cuda
():
place
=
paddle
.
CUDAPlace
(
0
)
data_place
=
paddle
.
CUDAPinnedPlace
()
paddle
.
disable_static
(
place
)
data
=
np
.
array
([
9
],
dtype
=
"int64"
)
data_tensor
=
paddle
.
to_tensor
(
data
,
place
=
data_place
)
result
=
data_tensor
==
0
self
.
assertEqual
((
result
.
numpy
()
==
np
.
array
([
False
])).
all
(),
True
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录