cmake: sitl_gazebo build use memory information from the system to estimate the parallel jobs

Using cmake_host_system_information, grabs AVAILABLE_PHYSICAL_MEMORY and adds another job for every 1.5GB of available memory.

This is tested on a single system with 16 logical cores and 16GB RAM (~11.5GB available, reported correctly by cmake).
This commit is contained in:
Guilherme Lawless 2021-11-07 20:37:48 +00:00 committed by GitHub
parent 68026eadeb
commit 47a191489e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 29 additions and 7 deletions

View File

@ -21,15 +21,37 @@ px4_add_git_submodule(TARGET git_jmavsim PATH "${PX4_SOURCE_DIR}/Tools/jMAVSim")
# Add support for external project building
include(ExternalProject)
include(ProcessorCount)
set(build_cores 1)
# Estimate an appropriate number of parallel jobs
cmake_host_system_information(RESULT AVAILABLE_PHYSICAL_MEMORY QUERY AVAILABLE_PHYSICAL_MEMORY)
cmake_host_system_information(RESULT NUMBER_OF_LOGICAL_CORES QUERY NUMBER_OF_LOGICAL_CORES)
ProcessorCount(N)
if(N GREATER_EQUAL 4)
math(EXPR build_cores "${N} - 2")
set(parallel_jobs 1)
if(NOT NUMBER_OF_LOGICAL_CORES)
include(ProcessorCount)
ProcessorCount(NUMBER_OF_LOGICAL_CORES)
endif()
if(NOT AVAILABLE_PHYSICAL_MEMORY AND NUMBER_OF_LOGICAL_CORES GREATER_EQUAL 4)
# Memory estimate unavailable, use N-2 jobs
math(EXPR parallel_jobs "${NUMBER_OF_LOGICAL_CORES} - 2")
endif()
if (AVAILABLE_PHYSICAL_MEMORY)
# Allow an additional job for every 1.5GB of available physical memory
math(EXPR parallel_jobs "${AVAILABLE_PHYSICAL_MEMORY}/(3*1024/2)")
else()
set(AVAILABLE_PHYSICAL_MEMORY "?")
endif()
if(parallel_jobs GREATER NUMBER_OF_LOGICAL_CORES)
set(parallel_jobs ${NUMBER_OF_LOGICAL_CORES})
endif()
message(DEBUG "${NUMBER_OF_LOGICAL_CORES} logical cores detected and ${AVAILABLE_PHYSICAL_MEMORY} megabytes of memory available.
Limiting sitl_gazebo and simulation-ignition concurrent jobs to ${parallel_jobs}")
# project to build sitl_gazebo if necessary
px4_add_git_submodule(TARGET git_gazebo PATH "${PX4_SOURCE_DIR}/Tools/sitl_gazebo")
ExternalProject_Add(sitl_gazebo
@ -45,7 +67,7 @@ ExternalProject_Add(sitl_gazebo
USES_TERMINAL_BUILD true
EXCLUDE_FROM_ALL true
BUILD_ALWAYS 1
BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> -- -j ${build_cores}
BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> -- -j ${parallel_jobs}
)
px4_add_git_submodule(TARGET git_ign_gazebo PATH "${PX4_SOURCE_DIR}/Tools/simulation-ignition")
@ -59,7 +81,7 @@ ExternalProject_Add(simulation-ignition
USES_TERMINAL_BUILD true
EXCLUDE_FROM_ALL true
BUILD_ALWAYS 1
BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> -- -j ${build_cores}
BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> -- -j ${parallel_jobs}
)
ExternalProject_Add(mavsdk_tests