Skip to content

Commit 5857fb3

Browse files
committed
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into develop
test=develop
2 parents 3e3599f + b8f36bd commit 5857fb3

40 files changed

+1201
-229
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
python/paddle/fluid/tests/unittests/reader_reset_test.recordio
12
paddle/operators/check_t.save
23
paddle/operators/check_tensor.ls
34
paddle/operators/tensor.save

AUTHORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
| QiJune | Jun Qi |
4343
| qingqing01 | Qing-Qing Dang |
4444
| reyoung | Yang Yu |
45+
| Sand3r- | Michal Gallus |
4546
| Superjom | Chun-Wei Yan |
4647
| tensor-tang | Jian Tang |
4748
| tianbingsz | Tian-Bing Xu |

cmake/inference_lib.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ copy(framework_lib DEPS ${framework_lib_deps}
166166

167167
set(module "memory")
168168
copy(memory_lib
169-
SRCS ${src_dir}/${module}/*.h ${src_dir}/${module}/detail/*.h
170-
DSTS ${dst_dir}/${module} ${dst_dir}/${module}/detail
169+
SRCS ${src_dir}/${module}/*.h ${src_dir}/${module}/detail/*.h ${src_dir}/${module}/allocation/*.h
170+
DSTS ${dst_dir}/${module} ${dst_dir}/${module}/detail ${dst_dir}/${module}/allocation
171171
)
172172

173173
set(inference_deps paddle_fluid_shared paddle_fluid)

paddle/fluid/framework/operator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class OperatorBase {
100100

101101
const std::string& Type() const { return type_; }
102102

103+
bool HasAttr(const std::string& name) const { return attrs_.count(name); }
103104
template <typename T>
104105
inline const T& Attr(const std::string& name) const {
105106
PADDLE_ENFORCE(attrs_.count(name) != 0, "%s should be in AttributeMap",

paddle/fluid/inference/analysis/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ set(analysis_deps # analysis_deps can be extended accross the project
77
add_subdirectory(ir_passes)
88
add_subdirectory(passes)
99

10-
cc_library(ir_pass_manager SRCS ir_pass_manager.cc DEPS graph pass ${INFER_IR_PASSES})
10+
cc_library(analysis_helper SRCS helper.cc DEPS framework_proto proto_desc graph paddle_fluid_api)
11+
12+
cc_library(ir_pass_manager SRCS ir_pass_manager.cc DEPS graph pass ${INFER_IR_PASSES} analysis_helper)
1113

1214
cc_library(argument SRCS argument.cc DEPS scope proto_desc)
1315
cc_library(analysis_pass SRCS analysis_pass.cc DEPS proto_desc)
1416

1517
cc_library(analysis SRCS
1618
analyzer.cc
17-
helper.cc
1819
analysis_pass
19-
DEPS ${analysis_deps}
20+
DEPS ${analysis_deps} analysis_helper
2021
)
2122

2223
cc_test(test_dot SRCS dot_tester.cc DEPS analysis)

paddle/fluid/inference/analysis/analyzer_tester.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ TEST(Analyzer, analysis_without_tensorrt) {
3030
Argument argument;
3131
argument.SetModelDir(FLAGS_inference_model_dir);
3232
argument.SetIrAnalysisPasses({"infer_clean_graph_pass"});
33+
argument.SetUseGPU(false);
3334

3435
Analyzer analyser;
3536
analyser.Run(&argument);
@@ -41,6 +42,7 @@ TEST(Analyzer, analysis_with_tensorrt) {
4142
argument.SetTensorRtWorkspaceSize(1 << 20);
4243
argument.SetModelDir(FLAGS_inference_model_dir);
4344
argument.SetIrAnalysisPasses({"infer_clean_graph_pass"});
45+
argument.SetUseGPU(false);
4446

4547
Analyzer analyser;
4648
analyser.Run(&argument);

paddle/fluid/inference/analysis/argument.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ struct Argument {
116116
std::vector<std::string>);
117117

118118
DECL_ARGUMENT_FIELD(use_gpu, UseGPU, bool);
119+
DECL_ARGUMENT_FIELD(gpu_device_id, GPUDeviceId, int);
119120
DECL_ARGUMENT_FIELD(use_tensorrt, UseTensorRT, bool);
120121
DECL_ARGUMENT_FIELD(tensorrt_node_teller, TensorRtNodeTeller,
121122
std::function<bool(const framework::ir::Node*)>);

paddle/fluid/inference/analysis/ir_passes/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ set(analysis_deps ${analysis_deps}
44
subgraph_detector tensorrt_subgraph_pass
55
CACHE INTERNAL "")
66

7+
set(pass_file ${PADDLE_BINARY_DIR}/paddle/fluid/inference/api/paddle_inference_pass.h)
8+
file(APPEND ${pass_file} "USE_PASS(tensorrt_subgraph_pass);\n")
79
set(INFER_IR_PASSES ${INFER_IR_PASSES} tensorrt_subgraph_pass CACHE INTERNAL "")

paddle/fluid/inference/analysis/passes/ir_graph_build_pass.cc

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,28 @@ void IrGraphBuildPass::RunImpl(Argument *argument) {
3030
if (!argument->scope_valid()) {
3131
argument->SetScope(new framework::Scope);
3232
}
33+
PADDLE_ENFORCE(argument->use_gpu_valid());
34+
35+
// The load program should run on the same device with the inference program,
36+
// so that the parameters will on the same device, or they will keep copying
37+
// between difference devices.
38+
platform::Place place;
39+
if (argument->use_gpu()) {
40+
PADDLE_ENFORCE(argument->gpu_device_id_valid());
41+
place = platform::CUDAPlace(argument->gpu_device_id());
42+
} else {
43+
place = platform::CPUPlace();
44+
}
3345

3446
if (argument->model_dir_valid()) {
35-
auto program = LoadModel(argument->model_dir(), argument->scope_ptr());
47+
auto program =
48+
LoadModel(argument->model_dir(), argument->scope_ptr(), place);
3649
argument->SetMainProgram(program.release());
3750
} else if (argument->model_program_path_valid() &&
3851
argument->model_params_path_valid()) {
3952
auto program =
4053
LoadModel(argument->model_program_path(), argument->model_params_path(),
41-
argument->scope_ptr());
54+
argument->scope_ptr(), place);
4255
argument->SetMainProgram(program.release());
4356
} else {
4457
PADDLE_THROW(
@@ -52,16 +65,15 @@ void IrGraphBuildPass::RunImpl(Argument *argument) {
5265
}
5366

5467
std::unique_ptr<framework::ProgramDesc> IrGraphBuildPass::LoadModel(
55-
const std::string &path, framework::Scope *scope) {
56-
platform::CPUPlace place;
68+
const std::string &path, framework::Scope *scope,
69+
const platform::Place &place) {
5770
framework::Executor exe(place);
5871
return Load(&exe, scope, path);
5972
}
6073

6174
std::unique_ptr<framework::ProgramDesc> IrGraphBuildPass::LoadModel(
6275
const std::string &program_path, const std::string &params_path,
63-
framework::Scope *scope) {
64-
platform::CPUPlace place;
76+
framework::Scope *scope, const platform::Place &place) {
6577
framework::Executor exe(place);
6678
return Load(&exe, scope, program_path, params_path);
6779
}

paddle/fluid/inference/analysis/passes/ir_graph_build_pass.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <string>
1818
#include "paddle/fluid/framework/scope.h"
1919
#include "paddle/fluid/inference/analysis/analysis_pass.h"
20+
#include "paddle/fluid/platform/place.h"
2021

2122
namespace paddle {
2223
namespace inference {
@@ -32,11 +33,12 @@ class IrGraphBuildPass : public AnalysisPass {
3233
std::string repr() const override;
3334

3435
private:
35-
std::unique_ptr<framework::ProgramDesc> LoadModel(const std::string &path,
36-
framework::Scope *scope);
36+
std::unique_ptr<framework::ProgramDesc> LoadModel(
37+
const std::string &path, framework::Scope *scope,
38+
const platform::Place &place);
3739
std::unique_ptr<framework::ProgramDesc> LoadModel(
3840
const std::string &program_path, const std::string &params_path,
39-
framework::Scope *scope);
41+
framework::Scope *scope, const platform::Place &place);
4042

4143
std::string model_binary_str_;
4244
};

0 commit comments

Comments
 (0)