Skip to content

Commit

Permalink
Compilation optimization (#44242)
Browse files Browse the repository at this point in the history
* Compilation optimization
  • Loading branch information
wanghuancoder authored Jul 14, 2022
1 parent e9b4d0b commit 4baf0db
Show file tree
Hide file tree
Showing 25 changed files with 3,420 additions and 2,663 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cc_library(
if(NOT (NOT WITH_PYTHON AND ON_INFER))
cc_library(
final_dygraph_node
SRCS nodes.cc
DEPS ${eager_deps} ${eager_manual_nodes})
SRCS nodes.cc ${eager_manual_nodes}
DEPS ${eager_deps})
add_dependencies(final_dygraph_node eager_final_state_codegen)
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cc_library(
if(NOT (NOT WITH_PYTHON AND ON_INFER))
cc_library(
final_dygraph_function
SRCS dygraph_functions.cc
DEPS ${eager_deps} ${eager_manual_functions})
SRCS dygraph_functions.cc ${eager_manual_functions}
DEPS ${eager_deps})
add_dependencies(final_dygraph_function eager_final_state_codegen)
endif()
17 changes: 2 additions & 15 deletions paddle/fluid/eager/api/manual/eager_manual/forwards/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
cc_library(
add_n_fwd_func
SRCS add_n_fwd_func.cc
DEPS ${eager_deps} ${fluid_deps} ${GLOB_OP_LIB} ${GLOB_OPERATOR_DEPS})

add_dependencies(add_n_fwd_func eager_codegen)

cc_library(
conv2d_fwd_function
SRCS conv2d_fwd_function.cc
DEPS ${eager_deps} ${fluid_deps} ${GLOB_OP_LIB} ${GLOB_OPERATOR_DEPS})

add_dependencies(conv2d_fwd_function eager_codegen)

set(eager_manual_functions
conv2d_fwd_function add_n_fwd_func
${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/manual/eager_manual/forwards/add_n_fwd_func.cc
${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/manual/eager_manual/forwards/conv2d_fwd_function.cc
PARENT_SCOPE)
13 changes: 2 additions & 11 deletions paddle/fluid/eager/api/manual/eager_manual/nodes/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
cc_library(
add_n_node
SRCS add_n_node.cc
DEPS ${eager_deps} ${fluid_deps})

cc_library(
conv2d_nodes
SRCS conv2d_nodes.cc
DEPS ${eager_deps} ${fluid_deps})

set(eager_manual_nodes
conv2d_nodes add_n_node
${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/manual/eager_manual/nodes/conv2d_nodes.cc
${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/manual/eager_manual/nodes/add_n_node.cc
PARENT_SCOPE)
29 changes: 3 additions & 26 deletions paddle/fluid/eager/api/manual/fluid_manual/forwards/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,5 @@
cc_library(
fused_gate_attention_fwd_func
SRCS fused_gate_attention_fwd_func.cc
DEPS ${eager_deps} ${fluid_deps} ${GLOB_OP_LIB} ${GLOB_OPERATOR_DEPS})

add_dependencies(fused_gate_attention_fwd_func eager_codegen
copy_dygraph_forward_functions)

cc_library(
fused_feedforward_fwd_func
SRCS fused_feedforward_fwd_func.cc
DEPS ${eager_deps} ${fluid_deps} ${GLOB_OP_LIB} ${GLOB_OPERATOR_DEPS})

add_dependencies(fused_feedforward_fwd_func eager_codegen
copy_dygraph_forward_functions)

cc_library(
fused_attention_fwd_func
SRCS fused_attention_fwd_func.cc
DEPS ${eager_deps} ${fluid_deps} ${GLOB_OP_LIB} ${GLOB_OPERATOR_DEPS})

add_dependencies(fused_attention_fwd_func eager_codegen
copy_dygraph_forward_functions)

set(fluid_manual_functions
fused_gate_attention_fwd_func fused_feedforward_fwd_func
fused_attention_fwd_func
${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/manual/fluid_manual/forwards/fused_gate_attention_fwd_func.cc
${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/manual/fluid_manual/forwards/fused_feedforward_fwd_func.cc
${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/manual/fluid_manual/forwards/fused_attention_fwd_func.cc
PARENT_SCOPE)
19 changes: 3 additions & 16 deletions paddle/fluid/eager/api/manual/fluid_manual/nodes/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
cc_library(
fused_gate_attention_node
SRCS fused_gate_attention_node.cc
DEPS ${eager_deps} ${fluid_deps})

cc_library(
fused_feedforward_node
SRCS fused_feedforward_node.cc
DEPS ${eager_deps} ${fluid_deps})

cc_library(
fused_attention_node
SRCS fused_attention_node.cc
DEPS ${eager_deps} ${fluid_deps})

set(fluid_manual_nodes
fused_gate_attention_node fused_feedforward_node fused_attention_node
${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/manual/fluid_manual/nodes/fused_gate_attention_node.cc
${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/manual/fluid_manual/nodes/fused_feedforward_node.cc
${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/manual/fluid_manual/nodes/fused_attention_node.cc
PARENT_SCOPE)
45 changes: 34 additions & 11 deletions paddle/fluid/eager/auto_code_generator/eager_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3083,27 +3083,44 @@ static std::string ConvertCoreOpsInfosToString(
return core_ops_returns_info_init_str;
}

static std::string GenerateCoreOpsReturnsInfo() {
static std::string GenerateCoreOpsArgsInfo() {
const char* Core_Ops_Returns_MAP_TEMPLATE =
"std::unordered_map<std::string, std::vector<std::string>> "
"core_ops_args_info = { %s };\n"
"std::unordered_map<std::string, std::vector<std::string>> "
"core_ops_args_type_info = { %s };\n"
"std::unordered_map<std::string, std::vector<std::string>> "
"core_ops_returns_info = { %s };\n";
"core_ops_args_info = { %s };\n";

std::string core_ops_args_info_init_str =
ConvertCoreOpsInfosToString(core_ops_args_info);

std::string core_ops_info_str = paddle::string::Sprintf(
Core_Ops_Returns_MAP_TEMPLATE, core_ops_args_info_init_str);

return core_ops_info_str;
}

static std::string GenerateCoreOpsArgsTypeInfo() {
const char* Core_Ops_Returns_MAP_TEMPLATE =
"std::unordered_map<std::string, std::vector<std::string>> "
"core_ops_args_type_info = { %s };\n";

std::string core_ops_args_type_info_init_str =
ConvertCoreOpsInfosToString(core_ops_args_type_info);

std::string core_ops_info_str = paddle::string::Sprintf(
Core_Ops_Returns_MAP_TEMPLATE, core_ops_args_type_info_init_str);

return core_ops_info_str;
}

static std::string GenerateCoreOpsReturnsInfo() {
const char* Core_Ops_Returns_MAP_TEMPLATE =
"std::unordered_map<std::string, std::vector<std::string>> "
"core_ops_returns_info = { %s };\n";

std::string core_ops_returns_info_init_str =
ConvertCoreOpsInfosToString(core_ops_returns_info);

std::string core_ops_info_str =
paddle::string::Sprintf(Core_Ops_Returns_MAP_TEMPLATE,
core_ops_args_info_init_str,
core_ops_args_type_info_init_str,
core_ops_returns_info_init_str);
std::string core_ops_info_str = paddle::string::Sprintf(
Core_Ops_Returns_MAP_TEMPLATE, core_ops_returns_info_init_str);

return core_ops_info_str;
}
Expand Down Expand Up @@ -3252,6 +3269,12 @@ static void DygraphCodeGeneration(const std::string& output_dir,

GenerateForwardDygraphFile(
output_dir + "/forwards/dygraph_forward_functions_args_info.tmp.cc",
GenerateCoreOpsArgsInfo());
GenerateForwardDygraphFile(
output_dir + "/forwards/dygraph_forward_functions_args_type_info.tmp.cc",
GenerateCoreOpsArgsTypeInfo());
GenerateForwardDygraphFile(
output_dir + "/forwards/dygraph_forward_functions_returns_info.tmp.cc",
GenerateCoreOpsReturnsInfo());

VLOG(6) << "-------- GenerateNodeCCFile -------";
Expand Down
17 changes: 15 additions & 2 deletions paddle/fluid/eager/auto_code_generator/generate_file_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ def GenerateFileStructureForIntermediateDygraph(eager_dir, split_count):
"nodes" + str(i + 1) + ".cc"))
empty_files.append(
os.path.join(forwards_dir, "dygraph_forward_functions_args_info.cc"))
empty_files.append(
os.path.join(forwards_dir,
"dygraph_forward_functions_args_type_info.cc"))
empty_files.append(
os.path.join(forwards_dir, "dygraph_forward_functions_returns_info.cc"))
for path in empty_files:
if not os.path.exists(path):
open(path, 'a').close()
Expand Down Expand Up @@ -125,7 +130,7 @@ def GenerateFileStructureForIntermediateDygraph(eager_dir, split_count):
f.write("cc_library(dygraph_node SRCS ")
for i in range(split_count):
f.write("nodes" + str(i + 1) + ".cc ")
f.write("DEPS ${eager_deps} ${fluid_deps} ${fluid_manual_nodes})\n")
f.write("${fluid_manual_nodes} DEPS ${eager_deps} ${fluid_deps})\n")
f.write("add_dependencies(dygraph_node copy_dygraph_node)")

with open(forwards_level_cmakelist_path, "w") as f:
Expand All @@ -143,15 +148,23 @@ def GenerateFileStructureForIntermediateDygraph(eager_dir, split_count):
f.write(
" COMMAND ${CMAKE_COMMAND} -E copy_if_different \"${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/generated/fluid_generated/forwards/dygraph_forward_functions_args_info.tmp.cc\" \"${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/generated/fluid_generated/forwards/dygraph_forward_functions_args_info.cc\"\n"
)
f.write(
" COMMAND ${CMAKE_COMMAND} -E copy_if_different \"${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/generated/fluid_generated/forwards/dygraph_forward_functions_args_type_info.tmp.cc\" \"${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/generated/fluid_generated/forwards/dygraph_forward_functions_args_type_info.cc\"\n"
)
f.write(
" COMMAND ${CMAKE_COMMAND} -E copy_if_different \"${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/generated/fluid_generated/forwards/dygraph_forward_functions_returns_info.tmp.cc\" \"${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/generated/fluid_generated/forwards/dygraph_forward_functions_returns_info.cc\"\n"
)
f.write(" DEPENDS eager_codegen\n")
f.write(" VERBATIM)\n")

f.write("cc_library(dygraph_function SRCS ")
for i in range(split_count):
f.write("dygraph_forward_functions" + str(i + 1) + ".cc ")
f.write("dygraph_forward_functions_args_info.cc ")
f.write("dygraph_forward_functions_args_type_info.cc ")
f.write("dygraph_forward_functions_returns_info.cc ")
f.write(
"DEPS ${eager_deps} ${fluid_deps} ${GLOB_OP_LIB} ${GLOB_OPERATOR_DEPS} ${fluid_manual_functions})\n"
"${fluid_manual_functions} DEPS ${eager_deps} ${fluid_deps} ${GLOB_OP_LIB} ${GLOB_OPERATOR_DEPS})\n"
)
f.write(
"add_dependencies(dygraph_function copy_dygraph_forward_functions)")
Expand Down
81 changes: 29 additions & 52 deletions paddle/fluid/framework/new_executor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
set(INTERPRETERCORE_DEPS
add_subdirectory(workqueue)
add_subdirectory(garbage_collector)

set(STANDALONE_EXECUTOR_SRCS
data_transfer.cc
new_executor_defs.cc
interpretercore_util.cc
event_manager.cc
stream_analyzer.cc
interpretercore.cc
standalone_executor.cc)

set(STANDALONE_EXECUTOR_DEPS
op_registry
device_context
scope
Expand All @@ -20,62 +32,33 @@ set(INTERPRETERCORE_DEPS
variable_helper
timer
monitor
nan_inf_utils)

add_subdirectory(workqueue)
add_subdirectory(garbage_collector)

cc_library(
data_transfer
SRCS data_transfer.cc
DEPS enforce scope glog)
cc_library(
new_executor_defs
SRCS new_executor_defs.cc
DEPS enforce glog scope)
cc_library(
interpretercore_util
SRCS interpretercore_util.cc
DEPS ${INTERPRETERCORE_DEPS} workqueue new_executor_defs data_transfer)
cc_library(
event_manager
SRCS event_manager.cc
DEPS ${DEVICE_EVENT_LIBS} glog new_executor_defs)
cc_library(
stream_analyzer
SRCS stream_analyzer.cc
DEPS ${DEVICE_EVENT_LIBS} glog device_context new_executor_defs)
nan_inf_utils
enforce
scope
glog
enforce
glog
scope
workqueue
interpretercore_event_garbage_collector
${DEVICE_EVENT_LIBS}
glog)

if(WITH_GPU OR WITH_ROCM)
cc_library(
interpretercore
SRCS interpretercore.cc
DEPS workqueue
${DEVICE_EVENT_LIBS}
interpretercore_util
interpretercore_event_garbage_collector
interpretercore_fast_garbage_collector
stream_analyzer
event_manager)
else()
cc_library(
interpretercore
SRCS interpretercore.cc
DEPS workqueue ${DEVICE_EVENT_LIBS} interpretercore_util
interpretercore_event_garbage_collector stream_analyzer event_manager)
set(STANDALONE_EXECUTOR_DEPS ${STANDALONE_EXECUTOR_DEPS}
interpretercore_fast_garbage_collector)
endif()

cc_library(
standalone_executor
SRCS standalone_executor.cc
DEPS interpretercore)
SRCS ${STANDALONE_EXECUTOR_SRCS}
DEPS ${STANDALONE_EXECUTOR_DEPS})

cc_library(
staticgraph_executor_statistics
SRCS executor_statistics.cc
DEPS enforce glog os_info)

# cc_binary(standalone_executor_test SRCS standalone_executor_test.cc DEPS interpretercore standalone_executor operator op_registry executor ${GLOB_OP_LIB} ${GLOB_OPERATOR_DEPS} profiler)
# skip win32 since wget is not installed by default on windows machine.
if(WITH_GPU
AND WITH_TESTING
Expand Down Expand Up @@ -120,13 +103,7 @@ if(WITH_GPU
cc_test(
standalone_executor_test
SRCS standalone_executor_test.cc
DEPS interpretercore
standalone_executor
operator
op_registry
executor
${OPS}
${OP_DEPS})
DEPS standalone_executor operator op_registry executor ${OPS} ${OP_DEPS})
set_tests_properties(standalone_executor_test PROPERTIES TIMEOUT 100)

add_dependencies(standalone_executor_test download_program)
Expand Down
19 changes: 7 additions & 12 deletions paddle/fluid/imperative/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cc_library(
cc_library(
var_helper
SRCS var_helper.cc
DEPS tensor phi_api)
DEPS tensor selected_rows)
if(WITH_XPU)
cc_library(
prepared_operator
Expand All @@ -20,8 +20,8 @@ if(WITH_XPU)
op_kernel_type
data_transform
nan_inf_utils
phi_api
phi_utils
scalar
int_array
var_helper
profiler)
else()
Expand All @@ -37,21 +37,16 @@ else()
op_kernel_type
data_transform
nan_inf_utils
phi_api
phi_utils
scalar
int_array
var_helper
profiler)
endif()
cc_library(
layer
SRCS layer.cc
DEPS prepared_operator
math_function
imperative_flag
variable_helper
op_registry
var_helper
phi_api)
DEPS prepared_operator math_function imperative_flag variable_helper
op_registry var_helper)
add_subdirectory(jit)
if(WITH_GPU)
cc_library(
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/operators/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ else()
cc_library(gather_scatter_kernel SRCS gather_scatter_kernel.cc gather_scatter_kernel.cu DEPS tensor)
endif()

set(OP_HEADER_DEPS ${OP_HEADER_DEPS} phi phi_api_utils gather_scatter_kernel)
set(OP_HEADER_DEPS ${OP_HEADER_DEPS} phi phi_api_utils gather_scatter_kernel backward_infermeta)

register_operators(EXCLUDES py_layer_op py_func_op warpctc_op dgc_op load_combine_op lstm_op run_program_op eye_op quantize_linear_op
recurrent_op save_combine_op sparse_attention_op sync_batch_norm_op spectral_op ${OP_MKL_DEPS} DEPS ${OP_HEADER_DEPS})
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/platform/device/gpu/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ nv_library(
nv_test(
cudnn_helper_test
SRCS cudnn_helper_test.cc
DEPS dynload_cuda phi)
DEPS dynload_cuda)
Loading

0 comments on commit 4baf0db

Please sign in to comment.