Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
239d716b
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看板
提交
239d716b
编写于
4月 16, 2019
作者:
S
superjomn
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
init optimizer and kernel_executor
上级
cdb12e59
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
169 addition
and
20 deletion
+169
-20
paddle/fluid/lite/api/CMakeLists.txt
paddle/fluid/lite/api/CMakeLists.txt
+1
-1
paddle/fluid/lite/api/cxx_api.h
paddle/fluid/lite/api/cxx_api.h
+1
-1
paddle/fluid/lite/api/cxx_api_test.cc
paddle/fluid/lite/api/cxx_api_test.cc
+1
-1
paddle/fluid/lite/core/CMakeLists.txt
paddle/fluid/lite/core/CMakeLists.txt
+4
-2
paddle/fluid/lite/core/kernel_executor.cc
paddle/fluid/lite/core/kernel_executor.cc
+19
-0
paddle/fluid/lite/core/kernel_executor.h
paddle/fluid/lite/core/kernel_executor.h
+50
-0
paddle/fluid/lite/core/mir/CMakeLists.txt
paddle/fluid/lite/core/mir/CMakeLists.txt
+1
-0
paddle/fluid/lite/core/mir/graph_visualize_pass.cc
paddle/fluid/lite/core/mir/graph_visualize_pass.cc
+3
-1
paddle/fluid/lite/core/mir/pass_manager.cc
paddle/fluid/lite/core/mir/pass_manager.cc
+0
-2
paddle/fluid/lite/core/mir/ssa_graph.h
paddle/fluid/lite/core/mir/ssa_graph.h
+4
-3
paddle/fluid/lite/core/mir/ssa_graph_test.cc
paddle/fluid/lite/core/mir/ssa_graph_test.cc
+5
-5
paddle/fluid/lite/core/op_executor.cc
paddle/fluid/lite/core/op_executor.cc
+0
-0
paddle/fluid/lite/core/op_executor.h
paddle/fluid/lite/core/op_executor.h
+3
-3
paddle/fluid/lite/core/op_executor_test.cc
paddle/fluid/lite/core/op_executor_test.cc
+1
-1
paddle/fluid/lite/core/optimizer.cc
paddle/fluid/lite/core/optimizer.cc
+13
-0
paddle/fluid/lite/core/optimizer.h
paddle/fluid/lite/core/optimizer.h
+63
-0
未找到文件。
paddle/fluid/lite/api/CMakeLists.txt
浏览文件 @
239d716b
cc_library
(
cxx_api_lite SRCS cxx_api.cc DEPS scope_lite executor_lite host_kernels ops_lite
)
cc_library
(
cxx_api_lite SRCS cxx_api.cc DEPS scope_lite
op_
executor_lite host_kernels ops_lite
)
cc_test
(
test_cxx_api_lite SRCS cxx_api_test.cc DEPS cxx_api_lite model_parser_lite
)
paddle/fluid/lite/api/cxx_api.h
浏览文件 @
239d716b
...
...
@@ -13,7 +13,7 @@
// limitations under the License.
#pragma once
#include "paddle/fluid/lite/core/executor.h"
#include "paddle/fluid/lite/core/
op_
executor.h"
#include "paddle/fluid/lite/core/op_lite.h"
#include "paddle/fluid/lite/model_parser/model_parser.h"
...
...
paddle/fluid/lite/api/cxx_api_test.cc
浏览文件 @
239d716b
...
...
@@ -14,7 +14,7 @@
#include "paddle/fluid/lite/api/cxx_api.h"
#include <gtest/gtest.h>
#include "paddle/fluid/lite/core/executor.h"
#include "paddle/fluid/lite/core/
op_
executor.h"
#include "paddle/fluid/lite/core/op_registry.h"
namespace
paddle
{
...
...
paddle/fluid/lite/core/CMakeLists.txt
浏览文件 @
239d716b
...
...
@@ -5,16 +5,18 @@ cc_library(variable_lite SRCS variable.cc)
cc_library
(
op_registry_lite SRCS op_registry.cc
)
cc_library
(
scope_lite SRCS scope.cc
)
cc_library
(
op_lite SRCS op_lite.cc DEPS scope_lite op_registry_lite
)
cc_library
(
executor_lite SRCS
executor.cc DEPS scope_lite tensor_lite op_lite op_registry_lite
cc_library
(
op_executor_lite SRCS op_
executor.cc DEPS scope_lite tensor_lite op_lite op_registry_lite
#TODO(Superjomn) remove these dependencies from original framework
proto_desc
)
cc_library
(
kernel_executor_lite SRCS kernel_executor.cc DEPS mir_ssa_graph kernel_lite
)
cc_library
(
type_system SRCS type_system.cc DEPS tensor_lite
)
cc_library
(
optimizer_lite SRCS optimizer.cc DEPS mir_pass_manager
)
cc_test
(
test_scope_lite SRCS scope_test.cc DEPS scope_lite
)
cc_test
(
test_kernel_lite SRCS kernel_test.cc DEPS target_wrapper_x86
)
cc_test
(
test_op_lite SRCS op_lite_test.cc DEPS op_lite
)
cc_test
(
test_tensor_lite SRCS tensor_test.cc
)
cc_test
(
test_
executor_lite SRCS executor_test.cc DEPS
executor_lite ops_lite host_kernels
)
cc_test
(
test_
op_executor_lite SRCS op_executor_test.cc DEPS op_
executor_lite ops_lite host_kernels
)
cc_test
(
test_type_system SRCS type_system_test.cc DEPS type_system
)
add_subdirectory
(
mir
)
paddle/fluid/lite/core/kernel_executor.cc
0 → 100644
浏览文件 @
239d716b
// 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 "paddle/fluid/lite/core/kernel_executor.h"
namespace
paddle
{
namespace
lite
{}
// namespace lite
}
// namespace paddle
\ No newline at end of file
paddle/fluid/lite/core/kernel_executor.h
0 → 100644
浏览文件 @
239d716b
// 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.
#pragma once
#include "paddle/fluid/lite/core/mir/ssa_graph.h"
namespace
paddle
{
namespace
lite
{
/*
* KernelExecutor executes a list of kernels.
*/
class
KernelExecutorBase
{
public:
KernelExecutorBase
(
std
::
unique_ptr
<
mir
::
Program
>&&
program
);
// Prepare runtime context.
void
PrepareWorkspace
();
void
Run
();
private:
lite
::
Scope
*
scope_
{};
lite
::
Scope
*
exec_scope_
{};
};
/*
* KernelExecutor executes the kernels without concurrency, works in X86 place.
*/
class
SerialKernelExecutor
:
public
KernelExecutorBase
{};
/*
* KernelExecutor executes the kernels with CUDA like stream parallel support,
* works in CUDA like devices.
*/
class
StreamKernelExecutor
:
public
KernelExecutorBase
{};
}
// namespace lite
}
// namespace paddle
paddle/fluid/lite/core/mir/CMakeLists.txt
浏览文件 @
239d716b
...
...
@@ -17,4 +17,5 @@ cc_test(test_ssa_graph SRCS ssa_graph_test.cc DEPS
proto_desc ops_lite
host_kernels
mir_passes
mir_pass_manager
)
paddle/fluid/lite/core/mir/graph_visualize_pass.cc
浏览文件 @
239d716b
...
...
@@ -20,6 +20,8 @@ namespace paddle {
namespace
lite
{
namespace
mir
{
using
inference
::
analysis
::
Dot
;
void
GraphVisualizePass
::
Apply
(
std
::
unique_ptr
<
mir
::
SSAGraph
>&
graph
)
{
Visualize
(
graph
.
get
());
}
...
...
@@ -39,7 +41,7 @@ std::string Visualize(mir::SSAGraph* graph) {
}
if
(
node
.
IsInstruct
())
{
dot
.
AddNode
(
key
,
{});
dot
.
AddNode
(
key
,
{
Dot
::
Attr
(
"shape"
,
"box"
)
});
for
(
auto
&
x
:
node
.
inlinks
)
{
auto
name
=
x
->
AsArgument
().
name
;
if
(
!
exists_args
.
count
(
name
))
{
...
...
paddle/fluid/lite/core/mir/pass_manager.cc
浏览文件 @
239d716b
...
...
@@ -24,5 +24,3 @@ PassManager::PassManager() {}
}
// namespace mir
}
// namespace lite
}
// namespace paddle
USE_MIR_PASS
(
demo
);
paddle/fluid/lite/core/mir/ssa_graph.h
浏览文件 @
239d716b
...
...
@@ -30,9 +30,10 @@ namespace mir {
// - main block, which is a list of OpLite
// - scope: which contains all the weights
struct
Program
{
std
::
list
<
std
::
string
>
inputs
;
std
::
list
<
std
::
string
>
tmp_vars
;
std
::
list
<
std
::
string
>
weights
;
std
::
list
<
std
::
unique_ptr
<
OpLite
>>
ops
;
std
::
unique_ptr
<
lite
::
Scope
>
scope
;
lite
::
Scope
*
scope
;
};
// An Graph for MIR. It is built from a list of Op and a scope.
...
...
@@ -44,7 +45,7 @@ class SSAGraph : GraphBase {
// @param valid_places: the valid places user set for the system.
void
Build
(
const
Program
&
program
,
const
std
::
vector
<
Place
>
&
valid_places
)
{
// create inputs
for
(
const
auto
&
name
:
program
.
input
s
)
{
for
(
const
auto
&
name
:
program
.
tmp_var
s
)
{
node_storage_
.
emplace_back
();
auto
&
new_node
=
node_storage_
.
back
();
auto
&
arg
=
new_node
.
AsArgument
();
...
...
paddle/fluid/lite/core/mir/ssa_graph_test.cc
浏览文件 @
239d716b
...
...
@@ -34,7 +34,7 @@ void BuildFc(framework::ProgramDesc* desc, const std::string& x,
Program
FakeProgram
()
{
Program
program
;
program
.
scope
.
reset
(
new
lite
::
Scope
)
;
program
.
scope
=
new
lite
::
Scope
;
auto
add_fc
=
[
&
](
int
id
,
std
::
string
x
)
{
// create variables
...
...
@@ -55,12 +55,12 @@ Program FakeProgram() {
desc
.
Flush
();
// add to input
program
.
input
s
.
push_back
(
w1
);
program
.
input
s
.
push_back
(
b1
);
program
.
tmp_var
s
.
push_back
(
w1
);
program
.
tmp_var
s
.
push_back
(
b1
);
auto
fc_op
=
LiteOpRegistry
::
Global
().
Create
(
"fc"
);
fc_op
->
PickKernel
({
Place
{
TARGET
(
kHost
),
PRECISION
(
kFloat
)}});
fc_op
->
Attach
(
desc
,
program
.
scope
.
get
()
);
fc_op
->
Attach
(
desc
,
program
.
scope
);
program
.
ops
.
emplace_back
(
std
::
move
(
fc_op
));
w1v
->
Resize
({
100
,
100
});
...
...
@@ -74,7 +74,7 @@ Program FakeProgram() {
// out1, w2, b2 -fc-> out2
std
::
string
x
=
"x"
;
program
.
input
s
.
push_back
(
x
);
program
.
tmp_var
s
.
push_back
(
x
);
auto
*
xv
=
program
.
scope
->
Var
(
x
)
->
GetMutable
<
Tensor
>
();
xv
->
Resize
({
100
,
100
});
...
...
paddle/fluid/lite/core/executor.cc
→
paddle/fluid/lite/core/
op_
executor.cc
浏览文件 @
239d716b
文件已移动
paddle/fluid/lite/core/executor.h
→
paddle/fluid/lite/core/
op_
executor.h
浏览文件 @
239d716b
...
...
@@ -24,7 +24,7 @@ namespace lite {
// The Executor is used to run the operators.
class
Executor
{
public:
Executor
(
lite
::
Scope
*
scope
,
const
std
::
vector
<
OpLite
::
Place
>&
valid_places
)
Executor
(
lite
::
Scope
*
scope
,
const
std
::
vector
<
Place
>&
valid_places
)
:
scope_
(
scope
),
valid_places_
(
valid_places
)
{}
// Create temporary variables.
...
...
@@ -52,7 +52,7 @@ class Executor {
ops_
.
emplace_back
(
LiteOpRegistry
::
Global
().
Create
(
op_type
));
// pick initial kernel
ops_
.
back
()
->
PickKernel
(
valid_places_
);
ops_
.
back
()
->
Attach
Impl
(
*
op_desc
,
exec_scope_
);
ops_
.
back
()
->
Attach
(
*
op_desc
,
exec_scope_
);
}
}
...
...
@@ -73,7 +73,7 @@ class Executor {
private:
std
::
vector
<
std
::
unique_ptr
<
OpLite
>>
ops_
;
lite
::
Scope
*
scope_
{};
std
::
vector
<
OpLite
::
Place
>
valid_places_
;
std
::
vector
<
Place
>
valid_places_
;
lite
::
Scope
*
exec_scope_
{};
};
...
...
paddle/fluid/lite/core/executor_test.cc
→
paddle/fluid/lite/core/
op_
executor_test.cc
浏览文件 @
239d716b
...
...
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "paddle/fluid/lite/core/executor.h"
#include "paddle/fluid/lite/core/
op_
executor.h"
#include <gtest/gtest.h>
#include <vector>
...
...
paddle/fluid/lite/core/optimizer.cc
0 → 100644
浏览文件 @
239d716b
// 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.
paddle/fluid/lite/core/optimizer.h
0 → 100644
浏览文件 @
239d716b
// 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.
#pragma once
#include <string>
#include <vector>
#include "paddle/fluid/lite/core/mir/pass_manager.h"
#include "paddle/fluid/lite/core/mir/pass_manager.h"
#include "paddle/fluid/lite/core/mir/ssa_graph.h"
namespace
paddle
{
namespace
lite
{
/*
* lite::Optimizer optimize a program. It utilize the mir passes to analysis the
* program and export an optimized program.
*/
class
Optimizer
{
public:
void
Run
(
std
::
unique_ptr
<
mir
::
Program
>&&
program
,
const
std
::
vector
<
Place
>&
valid_places
,
const
std
::
vector
<
std
::
string
>&
passes
=
{})
{
CHECK
(
!
graph_
)
<<
"duplicate optimize found"
;
graph_
.
reset
(
new
mir
::
SSAGraph
);
graph_
->
Build
(
*
program
,
valid_places
);
RunPasses
();
}
// Generate a new program based on the mir graph.
std
::
unique_ptr
<
mir
::
Program
>
GenProgram
()
{}
// Generate C++ code which combines the inference program, model and weights.
void
GenCode
(
const
std
::
string
&
code_dir
);
const
mir
::
SSAGraph
&
ssa_graph
()
const
{
CHECK
(
graph_
);
return
*
graph_
;
}
protected:
// Run the default passes registered in the PassManager.
void
RunPasses
()
{
mir
::
PassManager
::
Global
().
Run
();
}
// Specify the passes and run them.
void
RunPasses
(
std
::
vector
<
std
::
string
>&
passes
);
private:
std
::
unique_ptr
<
mir
::
SSAGraph
>
graph_
;
};
}
// namespace lite
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录