Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
11bac0c9
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
331
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
11bac0c9
编写于
12月 24, 2019
作者:
Z
zhupengyang
提交者:
hong19860320
12月 24, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[XPU] matmul bridge and unit test (#2666)
上级
a386ed11
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
108 addition
and
10 deletion
+108
-10
lite/kernels/xpu/bridges/CMakeLists.txt
lite/kernels/xpu/bridges/CMakeLists.txt
+2
-0
lite/kernels/xpu/bridges/matmul_op.cc
lite/kernels/xpu/bridges/matmul_op.cc
+88
-0
lite/kernels/xpu/bridges/paddle_use_bridges.h
lite/kernels/xpu/bridges/paddle_use_bridges.h
+1
-0
lite/tests/kernels/matmul_compute_test.cc
lite/tests/kernels/matmul_compute_test.cc
+17
-10
未找到文件。
lite/kernels/xpu/bridges/CMakeLists.txt
浏览文件 @
11bac0c9
...
...
@@ -23,6 +23,7 @@ lite_cc_library(subgraph_bridge_transpose_op_xpu SRCS transpose_op.cc DEPS ${xpu
lite_cc_library
(
subgraph_bridge_reshape_op_xpu SRCS reshape_op.cc DEPS
${
xpu_subgraph_bridge_deps
}
)
lite_cc_library
(
subgraph_bridge_layer_norm_op_xpu SRCS layer_norm_op.cc DEPS
${
xpu_subgraph_bridge_deps
}
)
lite_cc_library
(
subgraph_bridge_dropout_op_xpu SRCS dropout_op.cc DEPS
${
xpu_subgraph_bridge_deps
}
)
lite_cc_library
(
subgraph_bridge_matmul_op_xpu SRCS matmul_op.cc DEPS
${
xpu_subgraph_bridge_deps
}
)
set
(
xpu_subgraph_bridges
subgraph_bridge_registry
...
...
@@ -44,6 +45,7 @@ set(xpu_subgraph_bridges
subgraph_bridge_reshape_op_xpu
subgraph_bridge_layer_norm_op_xpu
subgraph_bridge_dropout_op_xpu
subgraph_bridge_matmul_op_xpu
CACHE INTERNAL
"xpu_subgraph_bridges"
)
message
(
STATUS
"+++++ xpu_subgraph_bridges:
${
xpu_subgraph_bridges
}
"
)
lite/kernels/xpu/bridges/matmul_op.cc
0 → 100644
浏览文件 @
11bac0c9
// 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.
#include "lite/kernels/npu/bridges/registry.h"
#include "lite/kernels/xpu/bridges/graph.h"
#include "lite/kernels/xpu/bridges/utility.h"
namespace
paddle
{
namespace
lite
{
namespace
subgraph
{
namespace
xpu
{
int
MatmulConverter
(
void
*
ctx
,
OpLite
*
op
,
KernelBase
*
kernel
)
{
CHECK
(
ctx
!=
nullptr
);
CHECK
(
op
!=
nullptr
);
auto
graph
=
static_cast
<
Graph
*>
(
ctx
);
auto
op_info
=
op
->
op_info
();
auto
op_type
=
op_info
->
Type
();
auto
scope
=
op
->
scope
();
VLOG
(
3
)
<<
"[XPU] Converting "
+
op_type
+
"..."
;
// Get input and output vars and op attributes
auto
x_name
=
op_info
->
Input
(
"X"
).
front
();
auto
x_type
=
kernel
->
GetInputDeclType
(
"X"
);
CHECK
(
x_type
->
precision
()
==
PRECISION
(
kFloat
));
CHECK
(
x_type
->
layout
()
==
DATALAYOUT
(
kNCHW
));
auto
x
=
scope
->
FindMutableTensor
(
x_name
);
auto
x_dims
=
x
->
dims
();
auto
y_name
=
op_info
->
Input
(
"Y"
).
front
();
auto
y_type
=
kernel
->
GetInputDeclType
(
"Y"
);
CHECK
(
y_type
->
precision
()
==
PRECISION
(
kFloat
));
CHECK
(
y_type
->
layout
()
==
DATALAYOUT
(
kNCHW
));
auto
y
=
scope
->
FindMutableTensor
(
y_name
);
auto
y_dims
=
y
->
dims
();
auto
out_name
=
op_info
->
Output
(
"Out"
).
front
();
auto
out_type
=
kernel
->
GetOutputDeclType
(
"Out"
);
CHECK
(
out_type
->
precision
()
==
PRECISION
(
kFloat
));
CHECK
(
out_type
->
layout
()
==
DATALAYOUT
(
kNCHW
));
auto
transpose_x
=
op_info
->
GetAttr
<
bool
>
(
"transpose_X"
);
CHECK
(
!
transpose_x
)
<<
"XPU only support transpose_x == true now"
;
auto
transpose_y
=
op_info
->
GetAttr
<
bool
>
(
"transpose_Y"
);
auto
alpha
=
op_info
->
GetAttr
<
float
>
(
"alpha"
);
// X node
std
::
shared_ptr
<
xtcl
::
xExpr
>
x_node
=
nullptr
;
if
(
graph
->
HasNode
(
x_name
))
{
x_node
=
graph
->
GetNode
(
x_name
);
}
else
{
x_node
=
graph
->
AddNode
(
x_name
,
x_dims
);
}
// Y node
std
::
shared_ptr
<
xtcl
::
xExpr
>
y_node
=
nullptr
;
if
(
graph
->
HasNode
(
y_name
))
{
y_node
=
graph
->
GetNode
(
y_name
);
}
else
{
y_node
=
graph
->
AddNode
(
y_name
,
y_dims
);
}
auto
matmul_node
=
graph
->
builder_
.
CreateMatmul2D
(
*
x_node
,
*
y_node
,
transpose_y
);
graph
->
AddNode
(
out_name
,
graph
->
builder_
.
CreateScale
(
matmul_node
,
alpha
));
return
SUCCESS
;
}
}
// namespace xpu
}
// namespace subgraph
}
// namespace lite
}
// namespace paddle
REGISTER_SUBGRAPH_BRIDGE
(
XPU
,
matmul
,
paddle
::
lite
::
subgraph
::
xpu
::
MatmulConverter
);
lite/kernels/xpu/bridges/paddle_use_bridges.h
浏览文件 @
11bac0c9
...
...
@@ -35,3 +35,4 @@ USE_SUBGRAPH_BRIDGE(XPU, reshape2);
USE_SUBGRAPH_BRIDGE
(
XPU
,
layer_norm
);
USE_SUBGRAPH_BRIDGE
(
XPU
,
gelu
);
USE_SUBGRAPH_BRIDGE
(
XPU
,
dropout
);
USE_SUBGRAPH_BRIDGE
(
XPU
,
matmul
);
lite/tests/kernels/matmul_compute_test.cc
浏览文件 @
11bac0c9
...
...
@@ -502,13 +502,16 @@ void test_matmulnxn_transpose(Place place) {
}
TEST
(
Matmul2x2
,
precision
)
{
#ifdef LITE_WITH_X86
Place
place
(
TARGET
(
kX86
));
Place
place
;
#if defined(LITE_WITH_ARM)
place
=
TARGET
(
kARM
);
#elif defined(LITE_WITH_XPU)
place
=
TARGET
(
kXPU
);
#else
return
;
#endif
#ifdef LITE_WITH_ARM
Place
place
(
TARGET
(
kARM
));
test_matmul2x2_no_transform
(
place
);
#endif
}
TEST
(
Matmul2x2_x_transpose
,
precision
)
{
...
...
@@ -520,14 +523,18 @@ TEST(Matmul2x2_x_transpose, precision) {
test_matmul2x2_x_transpose
(
place
);
#endif
}
TEST
(
Matmul2x2_y_transpose
,
precision
)
{
#ifdef LITE_WITH_X86
Place
place
(
TARGET
(
kX86
));
Place
place
;
#if defined(LITE_WITH_ARM)
place
=
TARGET
(
kARM
);
#elif defined(LITE_WITH_XPU)
place
=
TARGET
(
kXPU
);
#else
return
;
#endif
#ifdef LITE_WITH_ARM
Place
place
(
TARGET
(
kARM
));
test_matmul2x2_y_transpose
(
place
);
#endif
}
TEST
(
Matmul2x2_transpose
,
precision
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录