Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
041000c2
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看板
未验证
提交
041000c2
编写于
6月 02, 2022
作者:
光明和真理
提交者:
GitHub
6月 02, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[MLU]add mlu kernel for squeeze and squeeze2 (#43094)
Co-authored-by:
N
liupeiyu
<
liupeiyu@cambricon.com
>
上级
fe911a51
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
263 addition
and
0 deletion
+263
-0
paddle/fluid/operators/squeeze_op_mlu.cc
paddle/fluid/operators/squeeze_op_mlu.cc
+61
-0
python/paddle/fluid/tests/unittests/mlu/test_squeeze2_op_mlu.py
.../paddle/fluid/tests/unittests/mlu/test_squeeze2_op_mlu.py
+83
-0
python/paddle/fluid/tests/unittests/mlu/test_squeeze_op_mlu.py
...n/paddle/fluid/tests/unittests/mlu/test_squeeze_op_mlu.py
+119
-0
未找到文件。
paddle/fluid/operators/squeeze_op_mlu.cc
0 → 100644
浏览文件 @
041000c2
/* Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#ifdef PADDLE_WITH_MLU
#include <memory>
#include <string>
#include "paddle/fluid/operators/squeeze_op.h"
#include "paddle/fluid/platform/device/mlu/device_context.h"
namespace
ops
=
paddle
::
operators
;
namespace
plat
=
paddle
::
platform
;
REGISTER_OP_MLU_KERNEL
(
squeeze
,
ops
::
SqueezeKernel
<
plat
::
MLUDeviceContext
,
float
>
,
ops
::
SqueezeKernel
<
plat
::
MLUDeviceContext
,
double
>
,
ops
::
SqueezeKernel
<
plat
::
MLUDeviceContext
,
plat
::
float16
>
,
ops
::
SqueezeKernel
<
plat
::
MLUDeviceContext
,
bool
>
,
ops
::
SqueezeKernel
<
plat
::
MLUDeviceContext
,
int
>
,
ops
::
SqueezeKernel
<
plat
::
MLUDeviceContext
,
uint8_t
>
,
ops
::
SqueezeKernel
<
plat
::
MLUDeviceContext
,
int8_t
>
,
ops
::
SqueezeKernel
<
plat
::
MLUDeviceContext
,
int64_t
>
);
REGISTER_OP_MLU_KERNEL
(
squeeze_grad
,
ops
::
SqueezeGradKernel
<
plat
::
MLUDeviceContext
,
float
>
,
ops
::
SqueezeGradKernel
<
plat
::
MLUDeviceContext
,
double
>
,
ops
::
SqueezeGradKernel
<
plat
::
MLUDeviceContext
,
plat
::
float16
>
,
ops
::
SqueezeGradKernel
<
plat
::
MLUDeviceContext
,
bool
>
,
ops
::
SqueezeGradKernel
<
plat
::
MLUDeviceContext
,
int
>
,
ops
::
SqueezeGradKernel
<
plat
::
MLUDeviceContext
,
uint8_t
>
,
ops
::
SqueezeGradKernel
<
plat
::
MLUDeviceContext
,
int8_t
>
,
ops
::
SqueezeGradKernel
<
plat
::
MLUDeviceContext
,
int64_t
>
);
REGISTER_OP_MLU_KERNEL
(
squeeze2
,
ops
::
SqueezeKernel
<
plat
::
MLUDeviceContext
,
float
>
,
ops
::
SqueezeKernel
<
plat
::
MLUDeviceContext
,
double
>
,
ops
::
SqueezeKernel
<
plat
::
MLUDeviceContext
,
plat
::
float16
>
,
ops
::
SqueezeKernel
<
plat
::
MLUDeviceContext
,
bool
>
,
ops
::
SqueezeKernel
<
plat
::
MLUDeviceContext
,
int
>
,
ops
::
SqueezeKernel
<
plat
::
MLUDeviceContext
,
uint8_t
>
,
ops
::
SqueezeKernel
<
plat
::
MLUDeviceContext
,
int8_t
>
,
ops
::
SqueezeKernel
<
plat
::
MLUDeviceContext
,
int64_t
>
);
REGISTER_OP_MLU_KERNEL
(
squeeze2_grad
,
ops
::
Squeeze2GradKernel
<
plat
::
MLUDeviceContext
,
float
>
,
ops
::
Squeeze2GradKernel
<
plat
::
MLUDeviceContext
,
double
>
,
ops
::
Squeeze2GradKernel
<
plat
::
MLUDeviceContext
,
plat
::
float16
>
,
ops
::
Squeeze2GradKernel
<
plat
::
MLUDeviceContext
,
bool
>
,
ops
::
Squeeze2GradKernel
<
plat
::
MLUDeviceContext
,
int
>
,
ops
::
Squeeze2GradKernel
<
plat
::
MLUDeviceContext
,
uint8_t
>
,
ops
::
Squeeze2GradKernel
<
plat
::
MLUDeviceContext
,
int8_t
>
,
ops
::
Squeeze2GradKernel
<
plat
::
MLUDeviceContext
,
int64_t
>
);
#endif
python/paddle/fluid/tests/unittests/mlu/test_squeeze2_op_mlu.py
0 → 100755
浏览文件 @
041000c2
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
__future__
import
print_function
import
unittest
import
sys
sys
.
path
.
append
(
".."
)
import
numpy
as
np
import
paddle
from
op_test
import
OpTest
paddle
.
enable_static
()
# Correct: General.
class
TestSqueezeOp
(
OpTest
):
def
setUp
(
self
):
self
.
init_test_case
()
self
.
set_mlu
()
self
.
op_type
=
"squeeze2"
self
.
inputs
=
{
"X"
:
np
.
random
.
random
(
self
.
ori_shape
).
astype
(
"float32"
)}
self
.
init_attrs
()
self
.
outputs
=
{
"Out"
:
self
.
inputs
[
"X"
].
reshape
(
self
.
new_shape
),
"XShape"
:
np
.
random
.
random
(
self
.
ori_shape
).
astype
(
"float32"
)
}
def
set_mlu
(
self
):
self
.
__class__
.
use_mlu
=
True
self
.
place
=
paddle
.
device
.
MLUPlace
(
0
)
def
test_check_output
(
self
):
self
.
check_output_with_place
(
self
.
place
,
no_check_set
=
[
'XShape'
])
def
test_check_grad
(
self
):
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
],
'Out'
)
def
init_test_case
(
self
):
self
.
ori_shape
=
(
1
,
3
,
1
,
40
)
self
.
axes
=
(
0
,
2
)
self
.
new_shape
=
(
3
,
40
)
def
init_attrs
(
self
):
self
.
attrs
=
{
"axes"
:
self
.
axes
}
# Correct: There is mins axis.
class
TestSqueezeOp1
(
TestSqueezeOp
):
def
init_test_case
(
self
):
self
.
ori_shape
=
(
1
,
20
,
1
,
5
)
self
.
axes
=
(
0
,
-
2
)
self
.
new_shape
=
(
20
,
5
)
# Correct: No axes input.
class
TestSqueezeOp2
(
TestSqueezeOp
):
def
init_test_case
(
self
):
self
.
ori_shape
=
(
1
,
20
,
1
,
5
)
self
.
axes
=
()
self
.
new_shape
=
(
20
,
5
)
# Correct: Just part of axes be squeezed.
class
TestSqueezeOp3
(
TestSqueezeOp
):
def
init_test_case
(
self
):
self
.
ori_shape
=
(
6
,
1
,
5
,
1
,
4
,
1
)
self
.
axes
=
(
1
,
-
1
)
self
.
new_shape
=
(
6
,
5
,
1
,
4
)
if
__name__
==
"__main__"
:
unittest
.
main
()
python/paddle/fluid/tests/unittests/mlu/test_squeeze_op_mlu.py
0 → 100644
浏览文件 @
041000c2
# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
__future__
import
print_function
import
unittest
import
sys
sys
.
path
.
append
(
".."
)
import
numpy
as
np
import
paddle
import
paddle.fluid
as
fluid
from
paddle.fluid
import
compiler
,
Program
,
program_guard
from
op_test
import
OpTest
,
convert_float_to_uint16
import
paddle.fluid.core
as
core
paddle
.
enable_static
()
# Correct: General.
class
TestSqueezeOp
(
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
"squeeze"
self
.
init_test_case
()
self
.
set_mlu
()
self
.
inputs
=
{
"X"
:
np
.
random
.
random
(
self
.
ori_shape
).
astype
(
"float64"
)}
self
.
init_attrs
()
self
.
outputs
=
{
"Out"
:
self
.
inputs
[
"X"
].
reshape
(
self
.
new_shape
),
}
def
set_mlu
(
self
):
self
.
__class__
.
use_mlu
=
True
self
.
place
=
paddle
.
device
.
MLUPlace
(
0
)
def
test_check_output
(
self
):
self
.
check_output_with_place
(
self
.
place
)
def
test_check_grad
(
self
):
self
.
check_grad
([
"X"
],
"Out"
)
def
init_test_case
(
self
):
self
.
ori_shape
=
(
1
,
3
,
1
,
40
)
self
.
axes
=
(
0
,
2
)
self
.
new_shape
=
(
3
,
40
)
def
init_attrs
(
self
):
self
.
attrs
=
{
"axes"
:
self
.
axes
}
class
TestSqueezeBF16Op
(
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
"squeeze"
self
.
dtype
=
np
.
uint16
self
.
init_test_case
()
x
=
np
.
random
.
random
(
self
.
ori_shape
).
astype
(
"float32"
)
out
=
x
.
reshape
(
self
.
new_shape
)
self
.
inputs
=
{
"X"
:
convert_float_to_uint16
(
x
)}
self
.
init_attrs
()
self
.
outputs
=
{
"Out"
:
convert_float_to_uint16
(
out
)}
def
test_check_output
(
self
):
self
.
check_output
()
def
test_check_grad
(
self
):
self
.
check_grad
([
"X"
],
"Out"
)
def
init_test_case
(
self
):
self
.
ori_shape
=
(
1
,
3
,
1
,
40
)
self
.
axes
=
(
0
,
2
)
self
.
new_shape
=
(
3
,
40
)
def
init_attrs
(
self
):
self
.
attrs
=
{
"axes"
:
self
.
axes
}
# Correct: There is mins axis.
class
TestSqueezeOp1
(
TestSqueezeOp
):
def
init_test_case
(
self
):
self
.
ori_shape
=
(
1
,
3
,
1
,
40
)
self
.
axes
=
(
0
,
-
2
)
self
.
new_shape
=
(
3
,
40
)
# Correct: No axes input.
class
TestSqueezeOp2
(
TestSqueezeOp
):
def
init_test_case
(
self
):
self
.
ori_shape
=
(
1
,
20
,
1
,
5
)
self
.
axes
=
()
self
.
new_shape
=
(
20
,
5
)
# Correct: Just part of axes be squeezed.
class
TestSqueezeOp3
(
TestSqueezeOp
):
def
init_test_case
(
self
):
self
.
ori_shape
=
(
6
,
1
,
5
,
1
,
4
,
1
)
self
.
axes
=
(
1
,
-
1
)
self
.
new_shape
=
(
6
,
5
,
1
,
4
)
# Correct: The demension of axis is not of size 1 remains unchanged.
class
TestSqueezeOp4
(
TestSqueezeOp
):
def
init_test_case
(
self
):
self
.
ori_shape
=
(
6
,
1
,
5
,
1
,
4
,
1
)
self
.
axes
=
(
1
,
2
)
self
.
new_shape
=
(
6
,
5
,
1
,
4
,
1
)
if
__name__
==
"__main__"
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录