Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
b74b616f
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看板
提交
b74b616f
编写于
5月 30, 2018
作者:
L
liuruilong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
format files
上级
c9c6562e
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
69 addition
and
58 deletion
+69
-58
src/common/types.h
src/common/types.h
+14
-14
src/framework/operator.h
src/framework/operator.h
+9
-8
src/framework/program/program-optimize/node.cpp
src/framework/program/program-optimize/node.cpp
+17
-10
src/framework/program/program-optimize/program_optimize.cpp
src/framework/program/program-optimize/program_optimize.cpp
+1
-1
src/io.cpp
src/io.cpp
+10
-10
src/io.h
src/io.h
+4
-2
src/operators/fusion_conv_add_relu_op.h
src/operators/fusion_conv_add_relu_op.h
+2
-1
src/operators/fusion_fc_op.h
src/operators/fusion_fc_op.h
+2
-1
src/operators/kernel/arm/relu_kernel.cpp
src/operators/kernel/arm/relu_kernel.cpp
+0
-1
src/operators/relu_op.cpp
src/operators/relu_op.cpp
+2
-1
src/operators/relu_op.h
src/operators/relu_op.h
+1
-1
test/executor_for_test.h
test/executor_for_test.h
+1
-1
test/framework/test_load.cpp
test/framework/test_load.cpp
+1
-1
test/framework/test_optimize.cpp
test/framework/test_optimize.cpp
+2
-2
test/operators/test_batchnorm_op.cpp
test/operators/test_batchnorm_op.cpp
+1
-2
test/test_helper.h
test/test_helper.h
+1
-1
test/test_include.h
test/test_include.h
+1
-1
未找到文件。
src/common/types.h
浏览文件 @
b74b616f
...
...
@@ -15,8 +15,8 @@ limitations under the License. */
#pragma once;
#include <string>
#include <utility>
#include <unordered_map>
#include <utility>
namespace
paddle_mobile
{
enum
class
Precision
:
int
{
FP32
=
0
};
...
...
@@ -94,18 +94,18 @@ static const std::string G_OP_TYPE_FEED = "feed";
static
const
std
::
string
G_OP_TYPE_FETCH
=
"fetch"
;
static
std
::
unordered_map
<
std
::
string
,
std
::
pair
<
std
::
vector
<
std
::
string
>
,
std
::
vector
<
std
::
string
>>>
op_input_output_key
=
{{
G_OP_TYPE_CONV
,
{{
"Input"
},
{
"Output"
}}},
{
G_OP_TYPE_RELU
,
{{
"X"
},
{
"Out"
}}},
{
G_OP_TYPE_SOFTMAX
,
{{
"X"
},
{
"Out"
}}},
{
G_OP_TYPE_MUL
,
{{
"X"
},
{
"Out"
}}},
{
G_OP_TYPE_ELEMENTWISE_ADD
,
{{
"X"
,
"Y"
},
{
"Out"
}}},
{
G_OP_TYPE_POOL2D
,
{{
"X"
},
{
"Out"
}}},
{
G_OP_TYPE_BATCHNORM
,
{{
"X"
},
{
"Y"
}}},
{
G_OP_TYPE_LRN
,
{{
"X"
},
{
"Out"
}}},
{
G_OP_TYPE_CONCAT
,
{{
"X"
},
{
"Out"
}}},
{
G_OP_TYPE_SPLIT
,
{{
"X"
},
{
"Out"
}}},
{
G_OP_TYPE_FEED
,
{{
"X"
},
{
"Out"
}}},
{
G_OP_TYPE_FETCH
,
{{
"X"
},
{
"Out"
}}}};
std
::
string
,
std
::
pair
<
std
::
vector
<
std
::
string
>
,
std
::
vector
<
std
::
string
>>>
op_input_output_key
=
{{
G_OP_TYPE_CONV
,
{{
"Input"
},
{
"Output"
}}},
{
G_OP_TYPE_RELU
,
{{
"X"
},
{
"Out"
}}},
{
G_OP_TYPE_SOFTMAX
,
{{
"X"
},
{
"Out"
}}},
{
G_OP_TYPE_MUL
,
{{
"X"
},
{
"Out"
}}},
{
G_OP_TYPE_ELEMENTWISE_ADD
,
{{
"X"
,
"Y"
},
{
"Out"
}}},
{
G_OP_TYPE_POOL2D
,
{{
"X"
},
{
"Out"
}}},
{
G_OP_TYPE_BATCHNORM
,
{{
"X"
},
{
"Y"
}}},
{
G_OP_TYPE_LRN
,
{{
"X"
},
{
"Out"
}}},
{
G_OP_TYPE_CONCAT
,
{{
"X"
},
{
"Out"
}}},
{
G_OP_TYPE_SPLIT
,
{{
"X"
},
{
"Out"
}}},
{
G_OP_TYPE_FEED
,
{{
"X"
},
{
"Out"
}}},
{
G_OP_TYPE_FETCH
,
{{
"X"
},
{
"Out"
}}}};
}
// namespace paddle_mobile
src/framework/operator.h
浏览文件 @
b74b616f
...
...
@@ -19,20 +19,20 @@ limitations under the License. */
#include <utility>
#include <vector>
#include "common/types.h"
#include "common/enforce.h"
#include "common/variant.h"
#include "framework/scope.h"
#include "framework/tensor.h"
#include "framework/op_info.h"
#include "common/type_define.h"
#include "framework/variable.h"
#include "common/types.h"
#include "common/variant.h"
#include "framework/attribute.h"
#include "framework/op_
registry
.h"
#include "framework/op_
info
.h"
#include "framework/op_kernel_type.h"
#include "framework/
program/block_desc
.h"
#include "framework/
op_registry
.h"
#include "framework/paddle_mobile_object.h"
#include "framework/program/block_desc.h"
#include "framework/program/program-optimize/node.h"
#include "framework/scope.h"
#include "framework/tensor.h"
#include "framework/variable.h"
namespace
paddle_mobile
{
namespace
framework
{
...
...
@@ -77,6 +77,7 @@ class OperatorBase : PaddleMobileObject {
* @b 根据输入形状和参数计算出输出形状
* */
virtual
void
InferShape
()
const
=
0
;
protected:
std
::
shared_ptr
<
Scope
>
scope_
;
std
::
string
type_
;
...
...
src/framework/program/program-optimize/node.cpp
浏览文件 @
b74b616f
...
...
@@ -82,11 +82,14 @@ void Node::OpDescs(std::vector<std::shared_ptr<framework::OpDesc>> *op_desc,
DLOG
<<
"当前 op desc 输出数不为 1 "
;
can_add_split
=
false
;
}
for
(
const
auto
&
output
:
outputs_
)
{
if
(
op_input_output_key
.
find
(
output
->
op_desc_
->
type_
)
!=
op_input_output_key
.
end
())
{
for
(
const
auto
&
output
:
outputs_
)
{
if
(
op_input_output_key
.
find
(
output
->
op_desc_
->
type_
)
!=
op_input_output_key
.
end
())
{
auto
inputs_and_outputs
=
op_input_output_key
[
output
->
op_desc_
->
type_
];
auto
outputs_of_output
=
output
->
op_desc_
->
Output
(
inputs_and_outputs
.
second
[
0
]);
auto
inputs_of_output
=
output
->
op_desc_
->
Input
(
inputs_and_outputs
.
first
[
0
]);
auto
outputs_of_output
=
output
->
op_desc_
->
Output
(
inputs_and_outputs
.
second
[
0
]);
auto
inputs_of_output
=
output
->
op_desc_
->
Input
(
inputs_and_outputs
.
first
[
0
]);
for
(
int
i
=
0
;
i
<
inputs_of_output
.
size
();
++
i
)
{
std
::
string
input_of_output
=
inputs_of_output
[
i
];
for
(
int
j
=
0
;
j
<
outputs_of_output
.
size
();
++
j
)
{
...
...
@@ -121,13 +124,17 @@ void Node::OpDescs(std::vector<std::shared_ptr<framework::OpDesc>> *op_desc,
if
(
can_add_split
)
{
adding_thread
=
true
;
std
::
shared_ptr
<
class
OpDesc
>
split_op_desc
=
std
::
make_shared
<
class
OpDesc
>
();
std
::
shared_ptr
<
class
OpDesc
>
split_op_desc
=
std
::
make_shared
<
class
OpDesc
>
();
split_op_desc
->
type_
=
G_OP_TYPE_SPLIT
;
auto
outputs
=
this
->
op_desc_
->
Output
(
op_input_output_key
[
this
->
op_desc_
->
Type
()].
second
[
0
]);
split_op_desc
->
inputs_
=
{{
op_input_output_key
[
G_OP_TYPE_SPLIT
].
first
[
0
],
outputs
}};
auto
&
split_outputs
=
split_op_desc
->
outputs_
[
op_input_output_key
[
G_OP_TYPE_SPLIT
].
second
[
0
]];
for
(
const
auto
&
output
:
outputs_
)
{
auto
outputs
=
this
->
op_desc_
->
Output
(
op_input_output_key
[
this
->
op_desc_
->
Type
()].
second
[
0
]);
split_op_desc
->
inputs_
=
{
{
op_input_output_key
[
G_OP_TYPE_SPLIT
].
first
[
0
],
outputs
}};
auto
&
split_outputs
=
split_op_desc
->
outputs_
[
op_input_output_key
[
G_OP_TYPE_SPLIT
].
second
[
0
]];
for
(
const
auto
&
output
:
outputs_
)
{
split_outputs
.
push_back
(
outputs
[
0
]);
}
DLOG
<<
"add split"
;
...
...
src/framework/program/program-optimize/program_optimize.cpp
浏览文件 @
b74b616f
...
...
@@ -19,7 +19,7 @@ namespace paddle_mobile {
namespace
framework
{
//std::shared_ptr<ProgramDesc> ProgramOptimize::Optimize() {}
//
std::shared_ptr<ProgramDesc> ProgramOptimize::Optimize() {}
std
::
shared_ptr
<
ProgramDesc
>
ProgramOptimize
::
FushionOptimize
(
std
::
shared_ptr
<
ProgramDesc
>
ori_des
)
{
...
...
src/io.cpp
浏览文件 @
b74b616f
...
...
@@ -18,15 +18,14 @@ limitations under the License. */
#include "common/log.h"
#include "common/enforce.h"
#include "common/enforce.h"
#include "framework/scope.h"
#include "framework/tensor.h"
#include "framework/operator.h"
#include "framework/lod_tensor.h"
#include "framework/framework.pb-c.h"
#include "framework/
program/var_desc
.h"
#include "framework/
program/program_desc
.h"
#include "framework/
lod_tensor
.h"
#include "framework/
operator
.h"
#include "framework/program/program-optimize/program_optimize.h"
#include "framework/program/program_desc.h"
#include "framework/program/var_desc.h"
#include "framework/scope.h"
#include "framework/tensor.h"
namespace
paddle_mobile
{
using
framework
::
Variable
;
...
...
@@ -202,7 +201,6 @@ const framework::Program<Dtype, P> Loader<Dtype, P>::Load(
// DLOG << "var name-- " << var_desc->Name();
auto
var
=
scope
->
Var
(
var_desc
->
Name
());
if
(
var_desc
->
Type
()
==
framework
::
VARTYPE_TYPE_LOD_TENSOR
)
{
if
(
var_desc
->
Persistable
()
&&
var_desc
->
Type
()
!=
framework
::
VARTYPE_TYPE_FEED_MINIBATCH
&&
...
...
@@ -226,7 +224,8 @@ const framework::Program<Dtype, P> Loader<Dtype, P>::Load(
if
(
optimize
)
{
framework
::
ProgramOptimize
program_optimize
;
program
.
optimizeProgram
=
program_optimize
.
FushionOptimize
(
originProgramDesc
);
program
.
optimizeProgram
=
program_optimize
.
FushionOptimize
(
originProgramDesc
);
}
paddle_mobile__framework__proto__program_desc__free_unpacked
(
c_program
,
NULL
);
...
...
@@ -238,7 +237,8 @@ template class Loader<CPU, Precision::FP32>;
#pragma mark - executor
template
<
typename
Dtype
,
Precision
P
>
Executor
<
Dtype
,
P
>::
Executor
(
const
framework
::
Program
<
Dtype
>
p
,
int
batch_size
,
bool
use_optimize
)
Executor
<
Dtype
,
P
>::
Executor
(
const
framework
::
Program
<
Dtype
>
p
,
int
batch_size
,
bool
use_optimize
)
:
program_
(
p
),
batch_size_
(
batch_size
),
use_optimize_
(
use_optimize
)
{
if
(
use_optimize_
)
{
to_predict_program_
=
program_
.
optimizeProgram
;
...
...
src/io.h
浏览文件 @
b74b616f
...
...
@@ -30,7 +30,8 @@ namespace paddle_mobile {
template
<
typename
Dtype
,
Precision
P
=
Precision
::
FP32
>
class
Loader
:
PaddleMobileObject
{
public:
const
framework
::
Program
<
Dtype
,
P
>
Load
(
const
std
::
string
&
dirname
,
bool
optimize
=
true
);
const
framework
::
Program
<
Dtype
,
P
>
Load
(
const
std
::
string
&
dirname
,
bool
optimize
=
true
);
private:
void
LoadVar
(
framework
::
Variable
*
variable
,
...
...
@@ -45,7 +46,8 @@ class Executor {
Executor
()
=
default
;
Executor
(
const
framework
::
Program
<
Dtype
>
p
,
int
batch_size
=
1
,
bool
use_optimize
=
true
);
Executor
(
const
framework
::
Program
<
Dtype
>
p
,
int
batch_size
=
1
,
bool
use_optimize
=
true
);
// std::shared_ptr<framework::Tensor> Predict(framework::Tensor &t);
...
...
src/operators/fusion_conv_add_relu_op.h
浏览文件 @
b74b616f
...
...
@@ -31,7 +31,8 @@ class FushionConvAddReluOpMatcher : public framework::FusionOpMatcher {
void
FolderNodes
(
framework
::
Node
&
node
)
{
std
::
vector
<
std
::
shared_ptr
<
framework
::
OpDesc
>>
origin_descs
=
node
.
OpDescs
(
node_
.
Depth
());
node
.
Folder
(
node_
.
Depth
(),
Type
(),
{{
G_OP_TYPE_ELEMENTWISE_ADD
,
{
"Y"
,
"Z"
}}});
node
.
Folder
(
node_
.
Depth
(),
Type
(),
{{
G_OP_TYPE_ELEMENTWISE_ADD
,
{
"Y"
,
"Z"
}}});
}
std
::
string
Type
()
{
return
G_OP_TYPE_FUSION_CONV_ADD_RELU
;
}
};
...
...
src/operators/fusion_fc_op.h
浏览文件 @
b74b616f
...
...
@@ -35,7 +35,8 @@ class FusionFcMatcher : public framework::FusionOpMatcher {
void
FolderNodes
(
framework
::
Node
&
node
)
{
vector
<
std
::
shared_ptr
<
framework
::
OpDesc
>>
origin_descs
=
node
.
OpDescs
(
node_
.
Depth
());
node
.
Folder
(
node_
.
Depth
(),
Type
(),
{{
G_OP_TYPE_ELEMENTWISE_ADD
,
{
"Y"
,
"Z"
}}});
node
.
Folder
(
node_
.
Depth
(),
Type
(),
{{
G_OP_TYPE_ELEMENTWISE_ADD
,
{
"Y"
,
"Z"
}}});
}
std
::
string
Type
()
{
return
G_OP_TYPE_FC
;
}
...
...
src/operators/kernel/arm/relu_kernel.cpp
浏览文件 @
b74b616f
...
...
@@ -20,7 +20,6 @@ limitations under the License. */
namespace
paddle_mobile
{
namespace
operators
{
template
<
typename
T
>
struct
ReluFunctor
{
inline
T
operator
()(
T
in
)
const
{
return
in
>
0
?
in
:
0
;
}
...
...
src/operators/relu_op.cpp
浏览文件 @
b74b616f
...
...
@@ -27,7 +27,8 @@ template class ReluOp<CPU, float>;
/*
* @b 每一个 op 都需要注册一下的,
* USE_OP的参数 和 REGISTER_OPERATOR的第一个参数 都是需要和model中类型对应起来的
* USE_OP的参数 和 REGISTER_OPERATOR的第一个参数
* 都是需要和model中类型对应起来的
* */
namespace
ops
=
paddle_mobile
::
operators
;
USE_OP
(
relu
);
...
...
src/operators/relu_op.h
浏览文件 @
b74b616f
...
...
@@ -38,7 +38,7 @@ class ReluOp : public framework::OperatorWithKernel<DeviceType> {
scope
),
param_
(
inputs
,
outputs
,
attrs
,
*
scope
)
{}
/*
/*
* @b op 进行运算, 调用相应的 kernel 进行运算
* */
void
RunImpl
()
const
{
...
...
test/executor_for_test.h
浏览文件 @
b74b616f
...
...
@@ -17,9 +17,9 @@ limitations under the License. */
#include <string>
#include <vector>
#include "io.h"
#include "common/log.h"
#include "framework/op_registry.h"
#include "io.h"
#include "operators/conv_op.h"
#include "operators/elementwise_add_op.h"
#include "operators/pool_op.h"
...
...
test/framework/test_load.cpp
浏览文件 @
b74b616f
...
...
@@ -12,8 +12,8 @@ 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 "io.h"
#include "../test_helper.h"
#include "io.h"
int
main
()
{
paddle_mobile
::
Loader
<
paddle_mobile
::
CPU
>
loader
;
...
...
test/framework/test_optimize.cpp
浏览文件 @
b74b616f
...
...
@@ -12,17 +12,17 @@ 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 "io.h"
#include "../test_helper.h"
#include "framework/program/program-optimize/node.h"
#include "framework/program/program-optimize/program_optimize.h"
#include "io.h"
int
main
()
{
paddle_mobile
::
Loader
<
paddle_mobile
::
CPU
>
loader
;
// "../../../test/models/googlenet"
auto
program
=
loader
.
Load
(
g_googlenet
);
paddle_mobile
::
framework
::
ProgramOptimize
optimize
;
// program.originProgram->Description("origin");
// program.originProgram->Description("origin");
auto
optimize_program
=
optimize
.
FushionOptimize
(
program
.
originProgram
);
if
(
optimize_program
!=
nullptr
)
{
optimize_program
->
Description
(
"optimize"
);
...
...
test/operators/test_batchnorm_op.cpp
浏览文件 @
b74b616f
...
...
@@ -128,8 +128,7 @@ int main() {
DLOG
<<
"----------**********----------"
;
DLOG
<<
"begin to run BatchNormOp Test"
;
paddle_mobile
::
Loader
<
paddle_mobile
::
CPU
>
loader
;
auto
program
=
loader
.
Load
(
std
::
string
(
g_resnet
));
auto
program
=
loader
.
Load
(
std
::
string
(
g_resnet
));
/// input x (4,10,2,2)
paddle_mobile
::
framework
::
Tensor
inputx1
;
...
...
test/test_helper.h
浏览文件 @
b74b616f
...
...
@@ -15,8 +15,8 @@ limitations under the License. */
#pragma once
#include <chrono>
#include <random>
#include <fstream>
#include <random>
#include "common/log.h"
#include "framework/ddim.h"
...
...
test/test_include.h
浏览文件 @
b74b616f
...
...
@@ -20,7 +20,6 @@ limitations under the License. */
#include "./test_helper.h"
#include "common/enforce.h"
#include "io.h"
#include "common/log.h"
#include "framework/lod_tensor.h"
#include "framework/operator.h"
...
...
@@ -30,3 +29,4 @@ limitations under the License. */
#include "framework/scope.h"
#include "framework/tensor.h"
#include "framework/variable.h"
#include "io.h"
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录