Compiling operator libraries with Unity build (#29130)
* Compiling operator libraries with Unity Build on Windows CPU. * Compiling operator libraries with Unity Build on Windows GPU, no_test, test=windows_ci * Add option in windows ci script, no_test, test=windows_ci * Optimize parallel compiling, test=develop * remove limit of parallel compile and skip some ops in UB, test=develop * remove changes of header file, test=develop * remove changes of header file, test=develop * fix test_eye_op unittest failed, test=develop * Compiling operator libraries with Unity Build on Linux, test=develop * set default WITH_UNITY_BUILD=OFF, test=develop * Move unity build rules into a single file and add comment, test=develop * optimize parallel compilation, test=develop * fix undefined reference error on coverage ci, test=developrevert-31562-mean
parent
6f2bb20e0a
commit
671555ed32
@ -0,0 +1,128 @@
|
|||||||
|
# Add the following code before all include to avoid compilation failure.
|
||||||
|
set(UNITY_BEFORE_CODE [[
|
||||||
|
#ifndef NOMINMAX
|
||||||
|
#define NOMINMAX
|
||||||
|
#endif
|
||||||
|
#ifndef _USE_MATH_DEFINES
|
||||||
|
#define _USE_MATH_DEFINES
|
||||||
|
#endif]])
|
||||||
|
|
||||||
|
# Group a list of source files that can be included together.
|
||||||
|
# This combination is just a guiding rule, and the source file of group
|
||||||
|
# do not have to exist.
|
||||||
|
# Here you need to specify the source type which belongs to cc or cu.
|
||||||
|
function(register_unity_group TYPE)
|
||||||
|
# Get UNITY_TARGET from CMAKE_CURRENT_SOURCE_DIR.
|
||||||
|
string(REPLACE "${PADDLE_SOURCE_DIR}/paddle/fluid/" "" UNITY_TARGET ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
string(REPLACE "/" "_" UNITY_TARGET ${UNITY_TARGET})
|
||||||
|
set(UNITY_TARGET "paddle_${UNITY_TARGET}_unity")
|
||||||
|
|
||||||
|
# Variable unity_group_index is used to record the number of UNITY_TARGET groups.
|
||||||
|
get_property(unity_group_index GLOBAL PROPERTY ${UNITY_TARGET}_${TYPE}_group_index)
|
||||||
|
if("${unity_group_index}" STREQUAL "")
|
||||||
|
set(unity_group_index 0)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Variable unity_group_sources is used to record the sources of one group.
|
||||||
|
set(unity_group_sources ${UNITY_TARGET}_${TYPE}_group_${unity_group_index}_sources)
|
||||||
|
set_property(GLOBAL PROPERTY ${unity_group_sources} "")
|
||||||
|
foreach(src ${ARGN})
|
||||||
|
# UB use absolute path of source.
|
||||||
|
if(NOT IS_ABSOLUTE ${src})
|
||||||
|
set(src ${CMAKE_CURRENT_SOURCE_DIR}/${src})
|
||||||
|
endif()
|
||||||
|
set_property(GLOBAL APPEND PROPERTY ${unity_group_sources} ${src})
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
# If unity_file does not exists, nv_library or cc_library will use
|
||||||
|
# dummy_file. Touch unity_file to avoid to use dummy file.
|
||||||
|
set(unity_file ${CMAKE_CURRENT_BINARY_DIR}/${UNITY_TARGET}_${unity_group_index}_${TYPE}.${TYPE})
|
||||||
|
if(NOT EXISTS ${unity_file})
|
||||||
|
file(TOUCH ${unity_file})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
math(EXPR unity_group_index "${unity_group_index} + 1")
|
||||||
|
set_property(GLOBAL PROPERTY ${UNITY_TARGET}_${TYPE}_group_index ${unity_group_index})
|
||||||
|
endfunction(register_unity_group)
|
||||||
|
|
||||||
|
# Combine the original source files used by `TARGET`, then use
|
||||||
|
# `unity_target_${TYPE}_sources` to get the combined source files.
|
||||||
|
# If the source file does not hit any registed groups, use itself.
|
||||||
|
# This function put the actual combination relationship in variables instead of
|
||||||
|
# writing the unity source file. The reason is that writing unity source file
|
||||||
|
# will change the timestampe and affect the effect of retaining the build
|
||||||
|
# directory on Windows.
|
||||||
|
# Here you need to specify the source type which belongs to cc or cu.
|
||||||
|
function(compose_unity_target_sources TARGET TYPE)
|
||||||
|
# Variable unity_target_sources represents the source file used in TARGET
|
||||||
|
set(unity_target_sources "")
|
||||||
|
get_property(unity_group_index_max GLOBAL PROPERTY ${TARGET}_${TYPE}_group_index)
|
||||||
|
foreach(src ${ARGN})
|
||||||
|
set(unity_file "")
|
||||||
|
# UB use absolute path of source.
|
||||||
|
if(IS_ABSOLUTE ${src})
|
||||||
|
set(src_absolute_path ${src})
|
||||||
|
else()
|
||||||
|
set(src_absolute_path ${CMAKE_CURRENT_SOURCE_DIR}/${src})
|
||||||
|
endif()
|
||||||
|
# If `unity_group_index_max` is empty, there is no combination
|
||||||
|
# relationship.
|
||||||
|
# TODO(Avin0323): Whether use target property `UNITY_BUILD` of CMAKE to
|
||||||
|
# combine source files.
|
||||||
|
if(NOT "${unity_group_index_max}" STREQUAL "")
|
||||||
|
# Search in each registed group.
|
||||||
|
foreach(unity_group_index RANGE ${unity_group_index_max})
|
||||||
|
if(${unity_group_index} GREATER_EQUAL ${unity_group_index_max})
|
||||||
|
break()
|
||||||
|
endif()
|
||||||
|
get_property(unity_group_sources GLOBAL PROPERTY ${TARGET}_${TYPE}_group_${unity_group_index}_sources)
|
||||||
|
if(${src_absolute_path} IN_LIST unity_group_sources)
|
||||||
|
set(unity_file ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_${unity_group_index}_${TYPE}.${TYPE})
|
||||||
|
set(unity_file_sources ${TARGET}_${TYPE}_file_${unity_group_index}_sources)
|
||||||
|
get_property(set_unity_file_sources GLOBAL PROPERTY ${unity_file_sources} SET)
|
||||||
|
if(NOT ${set_unity_file_sources})
|
||||||
|
# Add macro before include source files.
|
||||||
|
set_property(GLOBAL PROPERTY ${unity_file_sources} "// Generate by Unity Build")
|
||||||
|
set_property(GLOBAL APPEND PROPERTY ${unity_file_sources} ${UNITY_BEFORE_CODE})
|
||||||
|
endif()
|
||||||
|
set_property(GLOBAL APPEND PROPERTY ${unity_file_sources} "#include \"${src_absolute_path}\"")
|
||||||
|
set(unity_target_sources ${unity_target_sources} ${unity_file})
|
||||||
|
break()
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
endif()
|
||||||
|
# Use original source file.
|
||||||
|
if("${unity_file}" STREQUAL "")
|
||||||
|
set(unity_target_sources ${unity_target_sources} ${src})
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
set(unity_target_${TYPE}_sources ${unity_target_sources} PARENT_SCOPE)
|
||||||
|
endfunction(compose_unity_target_sources)
|
||||||
|
|
||||||
|
# Write the unity files used by `UNITY_TARGET`.
|
||||||
|
# Write dependent on whether the contents of the unity file have changed, which
|
||||||
|
# protects incremental compilation speed.
|
||||||
|
function(finish_unity_target TYPE)
|
||||||
|
# Get UNITY_TARGET from CMAKE_CURRENT_SOURCE_DIR.
|
||||||
|
string(REPLACE "${PADDLE_SOURCE_DIR}/paddle/fluid/" "" UNITY_TARGET ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
string(REPLACE "/" "_" UNITY_TARGET ${UNITY_TARGET})
|
||||||
|
set(UNITY_TARGET "paddle_${UNITY_TARGET}_unity")
|
||||||
|
|
||||||
|
get_property(unity_group_index_max GLOBAL PROPERTY ${UNITY_TARGET}_${TYPE}_group_index)
|
||||||
|
if(NOT "${unity_group_index_max}" STREQUAL "")
|
||||||
|
foreach(unity_group_index RANGE ${unity_group_index_max})
|
||||||
|
if(${unity_group_index} GREATER_EQUAL ${unity_group_index_max})
|
||||||
|
break()
|
||||||
|
endif()
|
||||||
|
get_property(unity_file_sources GLOBAL PROPERTY ${UNITY_TARGET}_${TYPE}_file_${unity_group_index}_sources)
|
||||||
|
set(unity_file_read_content "")
|
||||||
|
string(JOIN "\n" unity_file_write_content ${unity_file_sources})
|
||||||
|
set(unity_file ${CMAKE_CURRENT_BINARY_DIR}/${UNITY_TARGET}_${unity_group_index}_${TYPE}.${TYPE})
|
||||||
|
file(READ ${unity_file} unity_file_read_content)
|
||||||
|
if(NOT "${unity_file_read_content}" STREQUAL "${unity_file_write_content}")
|
||||||
|
file(WRITE ${unity_file} ${unity_file_write_content})
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
endif()
|
||||||
|
endfunction(finish_unity_target)
|
@ -1,2 +1,6 @@
|
|||||||
include(operators)
|
include(operators)
|
||||||
|
if(WITH_UNITY_BUILD)
|
||||||
|
# Load Unity Build rules for operators in paddle/fluid/operators/amp.
|
||||||
|
include(unity_build_rule.cmake)
|
||||||
|
endif()
|
||||||
register_operators()
|
register_operators()
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
# This file records the Unity Build compilation rules.
|
||||||
|
# The source files in a `register_unity_group` called are compiled in a unity
|
||||||
|
# file.
|
||||||
|
# Generally, the combination rules in this file do not need to be modified.
|
||||||
|
# If there are some redefined error in compiling with the source file which
|
||||||
|
# in combination rule, you can remove the source file from the following rules.
|
||||||
|
register_unity_group(cc
|
||||||
|
check_finite_and_unscale_op.cc
|
||||||
|
update_loss_scaling_op.cc)
|
||||||
|
register_unity_group(cu
|
||||||
|
check_finite_and_unscale_op.cu
|
||||||
|
update_loss_scaling_op.cu)
|
@ -0,0 +1,16 @@
|
|||||||
|
# This file records the Unity Build compilation rules.
|
||||||
|
# The source files in a `register_unity_group` called are compiled in a unity
|
||||||
|
# file.
|
||||||
|
# Generally, the combination rules in this file do not need to be modified.
|
||||||
|
# If there are some redefined error in compiling with the source file which
|
||||||
|
# in combination rule, you can remove the source file from the following rules.
|
||||||
|
register_unity_group(cc
|
||||||
|
compare_all_op.cc
|
||||||
|
compare_op.cc
|
||||||
|
conditional_block_infer_op.cc
|
||||||
|
feed_op.cc
|
||||||
|
fetch_op.cc
|
||||||
|
get_places_op.cc
|
||||||
|
logical_op.cc
|
||||||
|
tensor_array_read_write_op.cc
|
||||||
|
while_op.cc)
|
@ -0,0 +1,28 @@
|
|||||||
|
# This file records the Unity Build compilation rules.
|
||||||
|
# The source files in a `register_unity_group` called are compiled in a unity
|
||||||
|
# file.
|
||||||
|
# Generally, the combination rules in this file do not need to be modified.
|
||||||
|
# If there are some redefined error in compiling with the source file which
|
||||||
|
# in combination rule, you can remove the source file from the following rules.
|
||||||
|
register_unity_group(cc
|
||||||
|
elementwise_add_op.cc
|
||||||
|
mkldnn/elementwise_add_mkldnn_op.cc
|
||||||
|
elementwise_div_op.cc
|
||||||
|
elementwise_floordiv_op.cc
|
||||||
|
elementwise_max_op.cc
|
||||||
|
elementwise_min_op.cc
|
||||||
|
elementwise_mod_op.cc
|
||||||
|
elementwise_mul_op.cc
|
||||||
|
mkldnn/elementwise_mul_mkldnn_op.cc
|
||||||
|
elementwise_pow_op.cc
|
||||||
|
elementwise_sub_op.cc)
|
||||||
|
register_unity_group(cu
|
||||||
|
elementwise_add_op.cu
|
||||||
|
elementwise_div_op.cu
|
||||||
|
elementwise_floordiv_op.cu
|
||||||
|
elementwise_max_op.cu
|
||||||
|
elementwise_min_op.cu
|
||||||
|
elementwise_mod_op.cu
|
||||||
|
elementwise_mul_op.cu
|
||||||
|
elementwise_pow_op.cu
|
||||||
|
elementwise_sub_op.cu)
|
@ -0,0 +1,19 @@
|
|||||||
|
# This file records the Unity Build compilation rules.
|
||||||
|
# The source files in a `register_unity_group` called are compiled in a unity
|
||||||
|
# file.
|
||||||
|
# Generally, the combination rules in this file do not need to be modified.
|
||||||
|
# If there are some redefined error in compiling with the source file which
|
||||||
|
# in combination rule, you can remove the source file from the following rules.
|
||||||
|
register_unity_group(cc
|
||||||
|
fused_elemwise_activation_op.cc
|
||||||
|
fused_embedding_fc_lstm_op.cc
|
||||||
|
fused_embedding_seq_pool_op.cc
|
||||||
|
fusion_lstm_op.cc
|
||||||
|
fusion_repeated_fc_relu_op.cc
|
||||||
|
fusion_seqconv_eltadd_relu_op.cc
|
||||||
|
fusion_seqexpand_concat_fc_op.cc
|
||||||
|
fusion_seqpool_concat_op.cc
|
||||||
|
fusion_squared_mat_sub_op.cc
|
||||||
|
multi_gru_op.cc
|
||||||
|
mkldnn/multi_gru_mkldnn_op.cc
|
||||||
|
fusion_seqpool_cvm_concat_op.cc)
|
@ -1,2 +1,6 @@
|
|||||||
include(operators)
|
include(operators)
|
||||||
|
if(WITH_UNITY_BUILD)
|
||||||
|
# Load Unity Build rules for operators in paddle/fluid/operators/metrics.
|
||||||
|
include(unity_build_rule.cmake)
|
||||||
|
endif()
|
||||||
register_operators()
|
register_operators()
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
# This file records the Unity Build compilation rules.
|
||||||
|
# The source files in a `register_unity_group` called are compiled in a unity
|
||||||
|
# file.
|
||||||
|
# Generally, the combination rules in this file do not need to be modified.
|
||||||
|
# If there are some redefined error in compiling with the source file which
|
||||||
|
# in combination rule, you can remove the source file from the following rules.
|
||||||
|
register_unity_group(cc
|
||||||
|
accuracy_op.cc
|
||||||
|
auc_op.cc
|
||||||
|
precision_recall_op.cc)
|
||||||
|
register_unity_group(cu
|
||||||
|
accuracy_op.cu
|
||||||
|
auc_op.cu)
|
@ -1,2 +1,6 @@
|
|||||||
include(operators)
|
include(operators)
|
||||||
|
if(WITH_UNITY_BUILD)
|
||||||
|
# Load Unity Build rules for operators in paddle/fluid/operators/optimizers.
|
||||||
|
include(unity_build_rule.cmake)
|
||||||
|
endif()
|
||||||
register_operators()
|
register_operators()
|
||||||
|
@ -0,0 +1,40 @@
|
|||||||
|
# This file records the Unity Build compilation rules.
|
||||||
|
# The source files in a `register_unity_group` called are compiled in a unity
|
||||||
|
# file.
|
||||||
|
# Generally, the combination rules in this file do not need to be modified.
|
||||||
|
# If there are some redefined error in compiling with the source file which
|
||||||
|
# in combination rule, you can remove the source file from the following rules.
|
||||||
|
register_unity_group(cc
|
||||||
|
ftrl_op.cc
|
||||||
|
lars_momentum_op.cc
|
||||||
|
momentum_op.cc
|
||||||
|
sgd_op.cc)
|
||||||
|
register_unity_group(cc
|
||||||
|
adagrad_op.cc
|
||||||
|
adam_op.cc
|
||||||
|
adamax_op.cc
|
||||||
|
dgc_momentum_op.cc
|
||||||
|
proximal_gd_op.cc)
|
||||||
|
register_unity_group(cc
|
||||||
|
decayed_adagrad_op.cc
|
||||||
|
adadelta_op.cc
|
||||||
|
lamb_op.cc
|
||||||
|
dpsgd_op.cc
|
||||||
|
rmsprop_op.cc)
|
||||||
|
register_unity_group(cu
|
||||||
|
ftrl_op.cu
|
||||||
|
lars_momentum_op.cu
|
||||||
|
momentum_op.cu
|
||||||
|
sgd_op.cu)
|
||||||
|
register_unity_group(cu
|
||||||
|
adagrad_op.cu
|
||||||
|
adam_op.cu
|
||||||
|
adamax_op.cu)
|
||||||
|
register_unity_group(cu
|
||||||
|
decayed_adagrad_op.cu
|
||||||
|
adadelta_op.cu
|
||||||
|
lamb_op.cu
|
||||||
|
rmsprop_op.cu)
|
||||||
|
# The following groups are to make better use of `/MP` which MSVC's parallel
|
||||||
|
# compilation instruction when compiling in Unity Build.
|
||||||
|
register_unity_group(cu proximal_adagrad_op.cu)
|
@ -0,0 +1,25 @@
|
|||||||
|
# This file records the Unity Build compilation rules.
|
||||||
|
# The source files in a `register_unity_group` called are compiled in a unity
|
||||||
|
# file.
|
||||||
|
# Generally, the combination rules in this file do not need to be modified.
|
||||||
|
# If there are some redefined error in compiling with the source file which
|
||||||
|
# in combination rule, you can remove the source file from the following rules.
|
||||||
|
register_unity_group(cc
|
||||||
|
reduce_all_op.cc
|
||||||
|
reduce_any_op.cc
|
||||||
|
reduce_prod_op.cc
|
||||||
|
reduce_sum_op.cc)
|
||||||
|
register_unity_group(cu
|
||||||
|
reduce_all_op.cu
|
||||||
|
reduce_any_op.cu
|
||||||
|
reduce_prod_op.cu
|
||||||
|
reduce_prod_op.part.cu
|
||||||
|
reduce_sum_op.cu
|
||||||
|
reduce_sum_op.part.cu)
|
||||||
|
# The following groups are to make better use of `/MP` which MSVC's parallel
|
||||||
|
# compilation instruction when compiling in Unity Build.
|
||||||
|
register_unity_group(cu frobenius_norm_op.cu)
|
||||||
|
register_unity_group(cu logsumexp_op.cu)
|
||||||
|
register_unity_group(cu reduce_max_op.cu)
|
||||||
|
register_unity_group(cu reduce_mean_op.cu)
|
||||||
|
register_unity_group(cu reduce_min_op.cu)
|
@ -1,2 +1,6 @@
|
|||||||
include(operators)
|
include(operators)
|
||||||
|
if(WITH_UNITY_BUILD)
|
||||||
|
# Load Unity Build rules for operators in paddle/fluid/operators/sequence_ops.
|
||||||
|
include(unity_build_rule.cmake)
|
||||||
|
endif()
|
||||||
register_operators()
|
register_operators()
|
||||||
|
@ -0,0 +1,42 @@
|
|||||||
|
# This file records the Unity Build compilation rules.
|
||||||
|
# The source files in a `register_unity_group` called are compiled in a unity
|
||||||
|
# file.
|
||||||
|
# Generally, the combination rules in this file do not need to be modified.
|
||||||
|
# If there are some redefined error in compiling with the source file which
|
||||||
|
# in combination rule, you can remove the source file from the following rules.
|
||||||
|
register_unity_group(cc
|
||||||
|
sequence_concat_op.cc
|
||||||
|
sequence_conv_op.cc
|
||||||
|
sequence_enumerate_op.cc
|
||||||
|
sequence_erase_op.cc
|
||||||
|
sequence_expand_op.cc
|
||||||
|
sequence_mask_op.cc
|
||||||
|
sequence_pad_op.cc
|
||||||
|
sequence_pool_op.cc)
|
||||||
|
register_unity_group(cc
|
||||||
|
sequence_expand_as_op.cc
|
||||||
|
sequence_reshape_op.cc
|
||||||
|
sequence_reverse_op.cc
|
||||||
|
sequence_scatter_op.cc
|
||||||
|
sequence_slice_op.cc
|
||||||
|
sequence_softmax_op.cc
|
||||||
|
sequence_topk_avg_pooling_op.cc
|
||||||
|
sequence_unpad_op.cc)
|
||||||
|
register_unity_group(cc
|
||||||
|
sequence_concat_op.cu.cc
|
||||||
|
sequence_conv_op.cu.cc)
|
||||||
|
register_unity_group(cu
|
||||||
|
sequence_enumerate_op.cu
|
||||||
|
sequence_erase_op.cu
|
||||||
|
sequence_expand_op.cu
|
||||||
|
sequence_mask_op.cu
|
||||||
|
sequence_pad_op.cu
|
||||||
|
sequence_pool_op.cu)
|
||||||
|
register_unity_group(cu
|
||||||
|
sequence_expand_as_op.cu
|
||||||
|
sequence_reshape_op.cu
|
||||||
|
sequence_reverse_op.cu
|
||||||
|
sequence_slice_op.cu
|
||||||
|
sequence_softmax_cudnn_op.cu.cc
|
||||||
|
sequence_softmax_op.cu
|
||||||
|
sequence_unpad_op.cu)
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue