Skip to content

Commit

Permalink
[BUILD] Add caching to CMake (#8373)
Browse files Browse the repository at this point in the history
* ccache

* ccache

Fix formatting

Add comment about nvcc

Change default to AUTO

More progress

Add auto as a mode

Disable ccache in CI

add-cache-to-cmake

Fix typo

* Fix rebase

* flaky test
  • Loading branch information
electriclilies authored Aug 1, 2021
1 parent 887324f commit 9f29e2a
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 0 deletions.
29 changes: 29 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -655,3 +655,32 @@ if(APPLE AND TVM_IS_DEBUG_BUILD)
VERBATIM
)
endif()

#Caches the build.
#Note that ccache-3.x doesn't support nvcc well, so CUDA kernels may never hit the cache and still
#need to be re-compiled every time. Using ccache 4.0+ can resolve this issue.

if(USE_CCACHE) # True for AUTO, ON, /path/to/ccache
if("${USE_CCACHE}" STREQUAL "AUTO") # Auto mode
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
message(STATUS "Found the path to ccache, enabling ccache")
set(PATH_TO_CCACHE ccache)
else()
message(STATUS "Didn't find the path to CCACHE, disabling ccache")
endif(CCACHE_FOUND)
elseif("${USE_CCACHE}" MATCHES ${IS_TRUE_PATTERN})
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
message(STATUS "Found the path to ccache, enabling ccache")
set(PATH_TO_CCACHE ccache)
else()
message(FATAL_ERROR "Cannot find ccache. Set USE_CCACHE mode to AUTO or OFF to build without ccache. USE_CCACHE=" "${USE_CCACHE")
endif(CCACHE_FOUND)
else() # /path/to/ccache
set(PATH_TO_CCACHE USE_CCACHE)
message(STATUS "Setting ccache path to " "${PATH_TO_CCACHE}")
endif()
# Set the flag for ccache
set(CXX_COMPILER_LAUNCHER PATH_TO_CCACHE)
endif(USE_CCACHE)
12 changes: 12 additions & 0 deletions cmake/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,15 @@ set(USE_LIBBACKTRACE AUTO)
# not be included in the final executable. This would make the corresponding
# runtime functions to be unavailable to the program.
set(BUILD_STATIC_RUNTIME OFF)


# Caches the build so that building is faster when switching between branches.
# If you switch branches, build and then encounter a linking error, you may
# need to regenerate the build tree through "make .." (the cache will
# still provide significant speedups).
# Possible values:
# - AUTO: search for path to ccache, disable if not found.
# - ON: enable ccache by searching for the path to ccache, report an error if not found
# - OFF: disable ccache
# - /path/to/ccache: use specific path to ccache
set(USE_CCACHE AUTO)
1 change: 1 addition & 0 deletions tests/scripts/task_config_build_arm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ echo set\(USE_VTA_TSIM ON\) >> config.cmake
echo set\(USE_VTA_FSIM ON\) >> config.cmake
echo set\(USE_ARM_COMPUTE_LIB ON\) >> config.cmake
echo set\(USE_ARM_COMPUTE_LIB_GRAPH_EXECUTOR "/opt/acl"\) >> config.cmake
echo set\(USE_CCACHE OFF\) >> config.cmake
1 change: 1 addition & 0 deletions tests/scripts/task_config_build_cpu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ echo set\(USE_ETHOSN_HW OFF\) >> config.cmake
echo set\(USE_VITIS_AI ON\) >> config.cmake
echo set\(USE_VERILATOR ON\) >> config.cmake
echo set\(USE_LIBBACKTRACE ON\) >> config.cmake
echo set\(USE_CCACHE OFF\) >> config.cmake
1 change: 1 addition & 0 deletions tests/scripts/task_config_build_gpu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ echo set\(CMAKE_CXX_COMPILER g++\) >> config.cmake
echo set\(CMAKE_CXX_FLAGS -Werror\) >> config.cmake
echo set\(USE_TENSORRT_CODEGEN ON\) >> config.cmake
echo set\(USE_LIBBACKTRACE AUTO\) >> config.cmake
echo set\(USE_CCACHE OFF\) >> config.cmake
1 change: 1 addition & 0 deletions tests/scripts/task_config_build_gpu_vulkan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ echo set\(USE_MICRO ON\) >> config.cmake
echo set\(USE_PROFILER ON\) >> config.cmake
echo set\(USE_LIBBACKTRACE OFF\) >> config.cmake
echo set\(CMAKE_CXX_FLAGS -Werror\) >> config.cmake
echo set\(USE_CCACHE OFF\) >> config.cmake
2 changes: 2 additions & 0 deletions tests/scripts/task_config_build_i386.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ echo set\(CMAKE_CXX_FLAGS -Werror\) >> config.cmake
echo set\(USE_VTA_TSIM ON\) >> config.cmake
echo set\(USE_VTA_FSIM ON\) >> config.cmake
echo set\(USE_VERILATOR ON\) >> config.cmake
echo set\(USE_CCACHE OFF\) >> config.cmake

1 change: 1 addition & 0 deletions tests/scripts/task_config_build_qemu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ echo set\(USE_LLVM llvm-config-10\) >> config.cmake
echo set\(CMAKE_CXX_COMPILER g++\) >> config.cmake
echo set\(CMAKE_CXX_FLAGS -Werror\) >> config.cmake
echo set\(HIDE_PRIVATE_SYMBOLS ON\) >> config.cmake
echo set\(USE_CCACHE OFF\) >> config.cmake
1 change: 1 addition & 0 deletions tests/scripts/task_config_build_wasm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ echo set\(CMAKE_CXX_FLAGS -Werror\) >> config.cmake
echo set\(HIDE_PRIVATE_SYMBOLS ON\) >> config.cmake
echo set\(USE_VTA_TSIM ON\) >> config.cmake
echo set\(USE_VTA_FSIM ON\) >> config.cmake
echo set\(USE_CCACHE OFF\) >> config.cmake

0 comments on commit 9f29e2a

Please sign in to comment.