Skip to content

Commit 9076967

Browse files
authored
Merge pull request #13133 from luotao1/library
add static and shared Library for analysis and IR
2 parents ab1f938 + ae44eff commit 9076967

File tree

9 files changed

+42
-57
lines changed

9 files changed

+42
-57
lines changed

cmake/inference_lib.cmake

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,13 @@ set(src_dir "${PADDLE_SOURCE_DIR}/paddle/fluid")
128128
set(dst_dir "${FLUID_INSTALL_DIR}/paddle/fluid")
129129
set(module "framework")
130130
if (NOT WIN32)
131-
copy(framework_lib DEPS framework_py_proto
132-
SRCS ${src_dir}/${module}/*.h ${src_dir}/${module}/details/*.h ${PADDLE_BINARY_DIR}/paddle/fluid/framework/framework.pb.h
133-
DSTS ${dst_dir}/${module} ${dst_dir}/${module}/details ${dst_dir}/${module}
134-
)
135-
else()
136-
copy(framework_lib
131+
set(framework_lib_deps framework_py_proto)
132+
endif(NOT WIN32)
133+
copy(framework_lib DEPS ${framework_lib_deps}
137134
SRCS ${src_dir}/${module}/*.h ${src_dir}/${module}/details/*.h ${PADDLE_BINARY_DIR}/paddle/fluid/framework/framework.pb.h
138-
DSTS ${dst_dir}/${module} ${dst_dir}/${module}/details ${dst_dir}/${module}
135+
${src_dir}/${module}/ir/*.h
136+
DSTS ${dst_dir}/${module} ${dst_dir}/${module}/details ${dst_dir}/${module} ${dst_dir}/${module}/ir
139137
)
140-
endif(NOT WIN32)
141138

142139
set(module "memory")
143140
copy(memory_lib
@@ -161,7 +158,8 @@ set(module "inference")
161158
copy(inference_lib DEPS ${inference_deps}
162159
SRCS ${src_dir}/${module}/*.h ${PADDLE_BINARY_DIR}/paddle/fluid/inference/libpaddle_fluid.*
163160
${src_dir}/${module}/api/paddle_inference_api.h ${src_dir}/${module}/api/demo_ci
164-
DSTS ${dst_dir}/${module} ${dst_dir}/${module} ${dst_dir}/${module} ${dst_dir}/${module}
161+
${PADDLE_BINARY_DIR}/paddle/fluid/inference/api/paddle_inference_pass.h
162+
DSTS ${dst_dir}/${module} ${dst_dir}/${module} ${dst_dir}/${module} ${dst_dir}/${module} ${dst_dir}/${module}
165163
)
166164

167165
set(module "platform")
Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,35 @@
1+
set(pass_file ${PADDLE_BINARY_DIR}/paddle/fluid/inference/api/paddle_inference_pass.h)
2+
file(WRITE ${pass_file} "// Generated by the paddle/fluid/framework/ir/CMakeLists.txt. DO NOT EDIT!\n\n")
3+
file(APPEND ${pass_file} "\#include \"paddle/fluid/framework/ir/pass.h\"\n")
4+
function(pass_library TARGET)
5+
set(options "")
6+
set(oneValueArgs "")
7+
set(multiValueArgs SRCS DEPS)
8+
cmake_parse_arguments(op_library "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
9+
cc_library(${TARGET} SRCS ${TARGET}.cc DEPS graph_pattern_detector pass)
10+
file(APPEND ${pass_file} "USE_PASS(${TARGET});\n")
11+
set(PASS_LIBRARY ${TARGET} ${PASS_LIBRARY} PARENT_SCOPE)
12+
endfunction()
13+
114
cc_library(node SRCS node.cc DEPS proto_desc)
215
cc_library(graph SRCS graph.cc DEPS node)
316
cc_library(graph_helper SRCS graph_helper.cc DEPS graph)
417
cc_library(pass SRCS pass.cc DEPS graph node graph_helper)
5-
cc_library(graph_viz_pass SRCS graph_viz_pass.cc DEPS graph pass graph_helper)
6-
cc_library(graph_to_program_pass SRCS graph_to_program_pass.cc DEPS graph pass graph_helper)
718
cc_library(graph_traits SRCS graph_traits.cc DEPS graph)
819
cc_library(graph_pattern_detector SRCS graph_pattern_detector.cc DEPS graph graph_helper graph_traits)
9-
cc_library(fc_fuse_pass SRCS fc_fuse_pass.cc DEPS graph graph_pattern_detector)
10-
cc_library(attention_lstm_fuse_pass SRCS attention_lstm_fuse_pass.cc DEPS graph graph_pattern_detector)
11-
cc_library(infer_clean_graph_pass SRCS infer_clean_graph_pass.cc DEPS graph pass)
12-
cc_library(fc_lstm_fuse_pass SRCS fc_lstm_fuse_pass.cc DEPS graph graph_pattern_detector)
13-
cc_library(seq_concat_fc_fuse_pass SRCS seq_concat_fc_fuse_pass.cc DEPS graph graph_pattern_detector)
20+
21+
pass_library(graph_to_program_pass)
22+
pass_library(graph_viz_pass)
23+
pass_library(fc_fuse_pass)
24+
pass_library(attention_lstm_fuse_pass)
25+
pass_library(infer_clean_graph_pass)
26+
pass_library(fc_lstm_fuse_pass)
27+
pass_library(seq_concat_fc_fuse_pass)
28+
set(GLOB_PASS_LIB ${PASS_LIBRARY} CACHE INTERNAL "Global PASS library")
1429

1530
cc_test(pass_test SRCS pass_test.cc DEPS graph pass graph_helper)
1631
cc_test(graph_test SRCS graph_test.cc DEPS graph graph_helper op_registry)
1732
cc_test(graph_helper_test SRCS graph_helper_test.cc DEPS graph graph_helper op_registry)
1833
cc_test(graph_to_program_pass_test SRCS graph_to_program_pass_test.cc DEPS graph_to_program_pass)
1934
cc_test(test_graph_pattern_detector SRCS graph_pattern_detector_tester.cc DEPS graph_pattern_detector)
20-
cc_test(test_fc_fuse_pass SRCS fc_fuse_pass_tester.cc DEPS fc_fuse_pass graph_pattern_detector graph pass graph_traits framework_proto)
35+
cc_test(test_fc_fuse_pass SRCS fc_fuse_pass_tester.cc DEPS fc_fuse_pass framework_proto)

paddle/fluid/inference/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ set(FLUID_CORE_MODULES proto_desc memory lod_tensor executor)
1010
# TODO(panyx0718): Should this be called paddle_fluid_inference_api_internal?
1111
cc_library(paddle_fluid_api
1212
SRCS io.cc
13-
DEPS ${FLUID_CORE_MODULES} ${GLOB_OP_LIB} graph_to_program_pass)
13+
DEPS ${FLUID_CORE_MODULES} ${GLOB_OP_LIB})
1414

1515
get_property(fluid_modules GLOBAL PROPERTY FLUID_MODULES)
1616

@@ -22,7 +22,7 @@ cc_library(paddle_fluid_origin DEPS ${fluid_modules} paddle_fluid_api)
2222
#endif()
2323

2424
# Create static library
25-
cc_library(paddle_fluid DEPS ${fluid_modules} paddle_fluid_api paddle_inference_api)
25+
cc_library(paddle_fluid DEPS ${fluid_modules} paddle_fluid_api paddle_inference_api analysis_predictor)
2626
if(NOT APPLE)
2727
# TODO(liuyiqu: Temporarily disable the link flag because it is not support on Mac.
2828
set(LINK_FLAGS "-Wl,--retain-symbols-file ${CMAKE_CURRENT_SOURCE_DIR}/paddle_fluid.sym")
@@ -32,6 +32,7 @@ endif()
3232
# Create shared library
3333
cc_library(paddle_fluid_shared SHARED
3434
SRCS io.cc ${CMAKE_CURRENT_SOURCE_DIR}/api/api.cc ${CMAKE_CURRENT_SOURCE_DIR}/api/api_impl.cc
35+
${CMAKE_CURRENT_SOURCE_DIR}/api/analysis_predictor.cc
3536
DEPS ${fluid_modules} paddle_fluid_api)
3637

3738
set_target_properties(paddle_fluid_shared PROPERTIES OUTPUT_NAME paddle_fluid)

paddle/fluid/inference/analysis/CMakeLists.txt

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function (inference_analysis_test TARGET)
3333
endif()
3434
cc_test(${TARGET}
3535
SRCS "${analysis_test_SRCS}"
36-
DEPS analysis graph fc_fuse_pass graph_viz_pass infer_clean_graph_pass graph_pattern_detector pass ${analysis_test_EXTRA_DEPS}
36+
DEPS analysis pass ${GLOB_PASS_LIB} ${analysis_test_EXTRA_DEPS}
3737
ARGS --inference_model_dir=${PYTHON_TESTS_DIR}/book/word2vec.inference.model ${mem_opt} ${analysis_test_ARGS})
3838
set_tests_properties(${TARGET} PROPERTIES DEPENDS test_word2vec)
3939
endif(WITH_TESTING)
@@ -56,25 +56,13 @@ if (NOT EXISTS ${DITU_INSTALL_DIR} AND WITH_TESTING)
5656
endif()
5757

5858
inference_analysis_test(test_analyzer SRCS analyzer_tester.cc
59-
EXTRA_DEPS paddle_inference_api paddle_fluid_api ir_pass_manager analysis
60-
analysis_predictor
61-
# ir
62-
fc_fuse_pass
63-
fc_lstm_fuse_pass
64-
seq_concat_fc_fuse_pass
65-
graph_viz_pass
66-
infer_clean_graph_pass
67-
graph_pattern_detector
68-
infer_clean_graph_pass
69-
attention_lstm_fuse_pass
70-
paddle_inference_api
71-
pass
59+
EXTRA_DEPS paddle_inference_api paddle_fluid_api ir_pass_manager analysis_predictor
7260
ARGS --infer_ditu_rnn_model=${DITU_INSTALL_DIR}/model
7361
--infer_ditu_rnn_data=${DITU_INSTALL_DIR}/data.txt)
7462

7563
inference_analysis_test(test_data_flow_graph SRCS data_flow_graph_tester.cc)
76-
inference_analysis_test(test_data_flow_graph_to_fluid_pass SRCS data_flow_graph_to_fluid_pass_tester.cc EXTRA_DEPS paddle_inference_api)
77-
inference_analysis_test(test_fluid_to_ir_pass SRCS fluid_to_ir_pass_tester.cc EXTRA_DEPS paddle_fluid)
64+
inference_analysis_test(test_data_flow_graph_to_fluid_pass SRCS data_flow_graph_to_fluid_pass_tester.cc)
65+
inference_analysis_test(test_fluid_to_ir_pass SRCS fluid_to_ir_pass_tester.cc)
7866
inference_analysis_test(test_fluid_to_data_flow_graph_pass SRCS fluid_to_data_flow_graph_pass_tester.cc)
7967
inference_analysis_test(test_subgraph_splitter SRCS subgraph_splitter_tester.cc)
8068
inference_analysis_test(test_dfg_graphviz_draw_pass SRCS dfg_graphviz_draw_pass_tester.cc)

paddle/fluid/inference/analysis/analyzer_tester.cc

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "paddle/fluid/inference/api/analysis_predictor.h"
2323
#include "paddle/fluid/inference/api/helper.h"
2424
#include "paddle/fluid/inference/api/paddle_inference_api.h"
25+
#include "paddle/fluid/inference/api/paddle_inference_pass.h"
2526
#include "paddle/fluid/inference/utils/singleton.h"
2627
#include "paddle/fluid/platform/profiler.h"
2728

@@ -368,10 +369,3 @@ TEST(Analyzer, DituRNN_with_analysis_with_IR) {
368369
} // namespace analysis
369370
} // namespace inference
370371
} // namespace paddle
371-
372-
USE_PASS(fc_fuse_pass);
373-
USE_PASS(seq_concat_fc_fuse_pass);
374-
USE_PASS(fc_lstm_fuse_pass);
375-
USE_PASS(graph_viz_pass);
376-
USE_PASS(infer_clean_graph_pass);
377-
USE_PASS(attention_lstm_fuse_pass);

paddle/fluid/inference/analysis/fluid_to_ir_pass_tester.cc

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include <gtest/gtest.h>
1818
#include "paddle/fluid/inference/analysis/ut_helper.h"
19+
#include "paddle/fluid/inference/api/paddle_inference_pass.h"
1920

2021
namespace paddle {
2122
namespace inference {
@@ -33,10 +34,3 @@ TEST(FluidToIrPass, Test) {
3334
} // namespace analysis
3435
} // namespace inference
3536
} // namespace paddle
36-
37-
USE_PASS(graph_viz_pass);
38-
USE_PASS(infer_clean_graph_pass);
39-
USE_PASS(attention_lstm_fuse_pass);
40-
USE_PASS(fc_lstm_fuse_pass);
41-
USE_PASS(seq_concat_fc_fuse_pass);
42-
USE_PASS(fc_fuse_pass);

paddle/fluid/inference/api/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ if(APPLE)
1818
endif(APPLE)
1919

2020

21-
set(inference_deps paddle_inference_api paddle_fluid_api analysis pass ir_pass_manager
22-
graph_viz_pass fc_fuse_pass
23-
infer_clean_graph_pass
24-
)
21+
set(inference_deps paddle_inference_api paddle_fluid_api analysis pass ir_pass_manager ${GLOB_PASS_LIB})
2522

2623
if(WITH_GPU AND TENSORRT_FOUND)
2724
set(inference_deps ${inference_deps} paddle_inference_tensorrt_subgraph_engine)

paddle/fluid/inference/api/analysis_predictor.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "paddle/fluid/framework/ir/pass.h"
1919
#include "paddle/fluid/framework/scope.h"
2020
#include "paddle/fluid/inference/api/paddle_inference_api.h"
21+
#include "paddle/fluid/inference/api/paddle_inference_pass.h"
2122
#include "paddle/fluid/inference/utils/singleton.h"
2223

2324
namespace paddle {
@@ -133,7 +134,3 @@ std::unique_ptr<PaddlePredictor> CreatePaddlePredictor<
133134
}
134135

135136
} // namespace paddle
136-
137-
USE_PASS(fc_fuse_pass);
138-
USE_PASS(graph_viz_pass);
139-
USE_PASS(infer_clean_graph_pass);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
global:
33
*paddle*;
4+
*Pass*;
45
local:
56
*;
67
};

0 commit comments

Comments
 (0)