Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
b18ec378
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
337
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看板
未验证
提交
b18ec378
编写于
8月 09, 2020
作者:
H
HappyAngel
提交者:
GitHub
8月 09, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request
#150
from PaddlePaddle/develop
pull code
上级
962b186b
9b9245d9
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
121 addition
and
0 deletion
+121
-0
lite/kernels/huawei_ascend_npu/bridges/CMakeLists.txt
lite/kernels/huawei_ascend_npu/bridges/CMakeLists.txt
+2
-0
lite/kernels/huawei_ascend_npu/bridges/fc_op.cc
lite/kernels/huawei_ascend_npu/bridges/fc_op.cc
+110
-0
lite/kernels/huawei_ascend_npu/bridges/paddle_use_bridges.h
lite/kernels/huawei_ascend_npu/bridges/paddle_use_bridges.h
+1
-0
lite/tests/kernels/fc_compute_test.cc
lite/tests/kernels/fc_compute_test.cc
+8
-0
未找到文件。
lite/kernels/huawei_ascend_npu/bridges/CMakeLists.txt
浏览文件 @
b18ec378
...
...
@@ -16,6 +16,7 @@ lite_cc_library(subgraph_bridge_elementwise_ops_huawei_ascend_npu SRCS elementwi
lite_cc_library
(
subgraph_bridge_batch_norm_op_huawei_ascend_npu SRCS batch_norm_op.cc DEPS
${
huawei_ascend_npu_subgraph_bridge_deps
}
)
lite_cc_library
(
subgraph_bridge_softmax_op_huawei_ascend_npu SRCS softmax_op.cc DEPS
${
huawei_ascend_npu_subgraph_bridge_deps
}
)
lite_cc_library
(
subgraph_bridge_dropout_op_huawei_ascend_npu SRCS dropout_op.cc DEPS
${
huawei_ascend_npu_subgraph_bridge_deps
}
)
lite_cc_library
(
subgraph_bridge_fc_op_huawei_ascend_npu SRCS fc_op.cc DEPS
${
huawei_ascend_npu_subgraph_bridge_deps
}
)
set
(
huawei_ascend_npu_subgraph_bridges
subgraph_bridge_registry
...
...
@@ -30,4 +31,5 @@ set(huawei_ascend_npu_subgraph_bridges
subgraph_bridge_batch_norm_op_huawei_ascend_npu
subgraph_bridge_softmax_op_huawei_ascend_npu
subgraph_bridge_dropout_op_huawei_ascend_npu
subgraph_bridge_fc_op_huawei_ascend_npu
CACHE INTERNAL
"huawei_ascend_npu_subgraph_bridges"
)
lite/kernels/huawei_ascend_npu/bridges/fc_op.cc
0 → 100644
浏览文件 @
b18ec378
// Copyright (c) 2020 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/huawei_ascend_npu/bridges/graph.h"
#include "lite/kernels/huawei_ascend_npu/bridges/utility.h"
#include "lite/kernels/npu/bridges/registry.h"
namespace
paddle
{
namespace
lite
{
namespace
subgraph
{
namespace
huawei_ascend_npu
{
int
FCConverter
(
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
)
<<
"[HUAWEI_ASCEND_NPU] Converting "
+
op_type
+
"..."
;
// Get input data nodes
auto
input_name
=
op_info
->
Input
(
"Input"
).
front
();
auto
input
=
scope
->
FindTensor
(
input_name
);
auto
input_dims
=
input
->
dims
();
auto
w_name
=
op_info
->
Input
(
"W"
).
front
();
auto
w
=
scope
->
FindTensor
(
w_name
);
auto
w_dims
=
w
->
dims
();
CHECK_EQ
(
w_dims
.
size
(),
2UL
);
auto
out_name
=
op_info
->
Output
(
"Out"
).
front
();
auto
out
=
scope
->
FindTensor
(
out_name
);
auto
out_dims
=
out
->
dims
();
int
in_num_col_dims
=
op_info
->
GetAttr
<
int
>
(
"in_num_col_dims"
);
int
m
=
input_dims
.
Slice
(
0
,
in_num_col_dims
).
production
();
int
k
=
input_dims
.
Slice
(
in_num_col_dims
,
input_dims
.
size
()).
production
();
int
n
=
w_dims
[
1
];
CHECK_EQ
(
k
*
n
,
w_dims
.
production
());
VLOG
(
3
)
<<
"[HUAWEI_ASCEND_NPU] input_dims = "
<<
input_dims
.
repr
()
<<
", w_dims = "
<<
w_dims
.
repr
()
<<
", in_num_col_dims = "
<<
in_num_col_dims
<<
", m = "
<<
m
<<
", k = "
<<
k
<<
", n = "
<<
n
;
// Create input node
std
::
shared_ptr
<
Node
>
input_node
=
nullptr
;
if
(
graph
->
Has
(
input_name
))
{
input_node
=
graph
->
Get
(
input_name
);
}
else
{
input_node
=
graph
->
Add
(
input_name
,
*
input
);
}
// w_node, the ascend ddk will transpose the tensor of w
// if we set transpose attr to be true
auto
w_node
=
graph
->
Add
(
w_name
,
*
w
);
// fc node
auto
fc_node
=
graph
->
Add
<
ge
::
op
::
FullyConnection
>
(
out_name
);
auto
fc_op
=
fc_node
->
data
<
ge
::
op
::
FullyConnection
>
();
fc_op
->
set_input_x
(
*
input_node
->
data
());
fc_op
->
set_input_w
(
*
w_node
->
data
());
fc_op
->
set_attr_num_output
(
n
);
fc_op
->
set_attr_transpose
(
true
);
INPUT_UPDATE
(
fc_op
,
x
,
input_node
);
INPUT_UPDATE
(
fc_op
,
w
,
w_node
);
OUTPUT_UPDATE
(
fc_op
,
y
,
fc_node
);
if
(
HasInputArg
(
op_info
,
scope
,
"Bias"
))
{
std
::
shared_ptr
<
Node
>
bias_node
=
nullptr
;
auto
bias_name
=
op_info
->
Input
(
"Bias"
).
front
();
if
(
graph
->
Has
(
bias_name
))
{
bias_node
=
graph
->
Get
(
bias_name
);
}
else
{
auto
bias
=
scope
->
FindTensor
(
bias_name
);
auto
bias_dims
=
bias
->
dims
();
CHECK_EQ
(
bias_dims
.
production
(),
n
);
VLOG
(
3
)
<<
"[HUAWEI_ASCEND_NPU] bias_dims = "
<<
bias_dims
.
repr
();
bias_node
=
graph
->
Add
(
bias_name
,
*
bias
,
{
1
,
n
,
1
,
1
});
}
fc_op
->
set_input_b
(
*
bias_node
->
data
());
INPUT_UPDATE
(
fc_op
,
b
,
bias_node
);
}
return
REBUILD_WHEN_SHAPE_CHANGED
;
}
}
// namespace huawei_ascend_npu
}
// namespace subgraph
}
// namespace lite
}
// namespace paddle
REGISTER_SUBGRAPH_BRIDGE
(
fc
,
kHuaweiAscendNPU
,
paddle
::
lite
::
subgraph
::
huawei_ascend_npu
::
FCConverter
);
lite/kernels/huawei_ascend_npu/bridges/paddle_use_bridges.h
浏览文件 @
b18ec378
...
...
@@ -41,3 +41,4 @@ USE_SUBGRAPH_BRIDGE(fusion_elementwise_max_activation, kHuaweiAscendNPU);
USE_SUBGRAPH_BRIDGE
(
batch_norm
,
kHuaweiAscendNPU
);
USE_SUBGRAPH_BRIDGE
(
softmax
,
kHuaweiAscendNPU
);
USE_SUBGRAPH_BRIDGE
(
dropout
,
kHuaweiAscendNPU
);
USE_SUBGRAPH_BRIDGE
(
fc
,
kHuaweiAscendNPU
);
lite/tests/kernels/fc_compute_test.cc
浏览文件 @
b18ec378
...
...
@@ -111,6 +111,11 @@ class FcOPTest : public arena::TestCase {
}
auto
out_data
=
out
->
mutable_data
<
float
>
();
// must init out_data to be 0 firstly
for
(
int
i
=
0
;
i
<
out_dim
.
production
();
i
++
)
{
out_data
[
i
]
=
0
;
}
int
m
=
x
->
dims
().
count
(
0
,
in_num_col_dims_
);
CHECK_EQ
(
wdims_
[
0
],
x
->
dims
().
count
(
in_num_col_dims_
,
x
->
dims
().
size
()));
int
k
=
wdims_
[
0
];
...
...
@@ -279,6 +284,9 @@ TEST(FcOP, precision) {
abs_error
=
1e-4
;
#elif defined(LITE_WITH_ARM)
place
=
TARGET
(
kARM
);
#elif defined(LITE_WITH_HUAWEI_ASCEND_NPU)
place
=
TARGET
(
kHuaweiAscendNPU
);
abs_error
=
1e-2
;
// precision_mode default is force_fp16
#else
return
;
#endif
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录