[CMake][libclc] Improve dependencies to avoid build errors (#95018)
With the Makefile generator and particularly high build parallelism some intermediate dependencies may be generated redundantly and concurrently, leading to build failures. To fix this, arrange for libclc's add_custom_commands to depend on targets in addition to files. This follows CMake documentation's[^1] guidance on add_custom_command: > Do not list the output in more than one independent target that may > build in parallel or the instances of the rule may conflict. Instead, > use the add_custom_target() command to drive the command and make the > other targets depend on that one. Eliminating the redundant commands also improves build times. [^1]: https://cmake.org/cmake/help/v3.29/command/add_custom_command.html
This commit is contained in:
@@ -374,15 +374,21 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
|
||||
OUTPUT ${output_file}
|
||||
EXTRA_OPTS "${mcpu}" -fno-builtin -nostdlib
|
||||
"${build_flags}" -I${PROJECT_SOURCE_DIR}/${file_dir}
|
||||
DEPENDENCIES generate_convert.cl clspv-generate_convert.cl
|
||||
)
|
||||
list( APPEND bytecode_files ${output_file} )
|
||||
endforeach()
|
||||
|
||||
set( builtins_link_lib_tgt builtins.link.${arch_suffix} )
|
||||
set( builtins_comp_lib_tgt builtins.comp.${arch_suffix} )
|
||||
add_custom_target( ${builtins_comp_lib_tgt}
|
||||
DEPENDS ${bytecode_files}
|
||||
)
|
||||
|
||||
set( builtins_link_lib_tgt builtins.link.${arch_suffix} )
|
||||
link_bc(
|
||||
TARGET ${builtins_link_lib_tgt}
|
||||
INPUTS ${bytecode_files}
|
||||
DEPENDENCIES ${builtins_comp_lib_tgt}
|
||||
)
|
||||
|
||||
set( builtins_link_lib $<TARGET_PROPERTY:${builtins_link_lib_tgt},TARGET_FILE> )
|
||||
@@ -391,7 +397,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
|
||||
set( spv_suffix ${arch_suffix}.spv )
|
||||
add_custom_command( OUTPUT ${spv_suffix}
|
||||
COMMAND libclc::llvm-spirv ${spvflags} -o ${spv_suffix} ${builtins_link_lib}
|
||||
DEPENDS ${builtins_link_lib}
|
||||
DEPENDS ${builtins_link_lib} ${builtins_link_lib_tgt}
|
||||
)
|
||||
add_custom_target( "prepare-${spv_suffix}" ALL DEPENDS "${spv_suffix}" )
|
||||
install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${spv_suffix}
|
||||
@@ -403,7 +409,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
|
||||
add_custom_command( OUTPUT ${builtins_opt_lib_tgt}.bc
|
||||
COMMAND libclc::opt ${opt_flags} -o ${builtins_opt_lib_tgt}.bc
|
||||
${builtins_link_lib}
|
||||
DEPENDS libclc::opt ${builtins_link_lib}
|
||||
DEPENDS libclc::opt ${builtins_link_lib} ${builtins_link_lib_tgt}
|
||||
)
|
||||
add_custom_target( ${builtins_opt_lib_tgt}
|
||||
ALL DEPENDS ${builtins_opt_lib_tgt}.bc
|
||||
@@ -418,7 +424,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
|
||||
set( obj_suffix ${arch_suffix}.bc )
|
||||
add_custom_command( OUTPUT ${obj_suffix}
|
||||
COMMAND prepare_builtins -o ${obj_suffix} ${builtins_opt_lib}
|
||||
DEPENDS ${builtins_opt_lib} prepare_builtins )
|
||||
DEPENDS ${builtins_opt_lib} ${builtins_opt_lib_tgt} prepare_builtins )
|
||||
add_custom_target( prepare-${obj_suffix} ALL DEPENDS ${obj_suffix} )
|
||||
|
||||
# nvptx-- targets don't include workitem builtins
|
||||
|
||||
@@ -80,11 +80,13 @@ endfunction()
|
||||
# Custom target to create
|
||||
# * INPUT <string> ...
|
||||
# List of bytecode files to link together
|
||||
# * DEPENDENCIES <string> ...
|
||||
# List of extra dependencies to inject
|
||||
function(link_bc)
|
||||
cmake_parse_arguments(ARG
|
||||
""
|
||||
"TARGET"
|
||||
"INPUTS"
|
||||
"INPUTS;DEPENDENCIES"
|
||||
${ARGN}
|
||||
)
|
||||
|
||||
@@ -106,7 +108,7 @@ function(link_bc)
|
||||
add_custom_command(
|
||||
OUTPUT ${ARG_TARGET}.bc
|
||||
COMMAND libclc::llvm-link -o ${ARG_TARGET}.bc ${LINK_INPUT_ARG}
|
||||
DEPENDS libclc::llvm-link ${ARG_INPUTS} ${RSP_FILE}
|
||||
DEPENDS libclc::llvm-link ${ARG_DEPENDENCIES} ${ARG_INPUTS} ${RSP_FILE}
|
||||
)
|
||||
|
||||
add_custom_target( ${ARG_TARGET} ALL DEPENDS ${ARG_TARGET}.bc )
|
||||
|
||||
Reference in New Issue
Block a user