-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUILD] Add caching to CMake #8373
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. One tip: 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. Since Ubuntu 20 still uses ccache 3.x, it's hightly possible that users may need to manually install 4.0+.
Can we add that to the documentation on the option? |
@electriclilies this is great! thanks for adding this feature. |
@mbrookhart Added it :) |
This PR has failed a few times on the windows build. I'm not sure if this is caused by this PR or not; we should keep an eye on it and perhaps set the default behavior to not cache if it is causing flaky tests. |
Thanks Lily for the great work! Yeah I am using ccache a lot as well when working on the TVM project, but with a more global flag, like set(CMAKE_C_COMPILER_LAUNCHER /path/to/ccache)
set(CMAKE_CXX_COMPILER_LAUNCHER /path/to/ccache)
set(CMAKE_CUDA_COMPILER_LAUNCHER /path/to/ccache) What's the difference between your approach ( |
Thanks @electriclilies . One thing that might be helpful here is to streamline the option definition. The current proposed option is closer to Here are how we interpret values to keep things consistent with our previous options:
We should also look a bit into which way is more standard, since I also see The use of ccache will likely cause the history cache growing problem in the CI when the node disk space is limited. Because the cost of build is normally smaller compared to testing, we will likely want to disable ccache in the CI setups in the task_config_build_xyz.sh https://github.com/apache/tvm/blob/main/tests/scripts/task_config_build_arm.sh |
I agree with @tqchen about the CI. It's better to always build from scratch in CI. |
Thanks for the feedback @tqchen @junrushao1994. I'll change the default to AUTO, as suggested, and disable this option in CI. |
Thanks @electriclilies , by standard options, I actually meant we should implement the auto feature(please see the suggested comments) via
seems they are two ways to do the same thing(see some related issues Tencent/rapidjson#1794 seems to indicate that we should use the other one), but we are not sure |
CMakeLists.txt
Outdated
find_program(CCACHE_FOUND ccache) | ||
if(CCACHE_FOUND) | ||
message(STATUS "Enabling ccache") | ||
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be grgeat to check if we can use set CXX_COMPILER_LAUNCHER here and get the same goal
CMakeLists.txt
Outdated
|
||
if(USE_CCACHE) | ||
find_program(CCACHE_FOUND ccache) | ||
if(CCACHE_FOUND) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to feed the result of find_program to the variable, in case ccache is not in path but find_program manages to find it
After some thought, I think that it is actually better to model the options in this case after the options for ROCM runtime, which looks like this:
How does this sound for the possible options?
|
I agree, in the case of rocm runtime, an error will be raised if rocm is ON and we did not found the runtime. So the current behavior is still closer to AUTO.
|
@tqchen @junrushao1994 I updated the options and changed the method of setting the path to ccache to |
message(STATUS "Setting ccache path to " "${PATH_TO_CCACHE}") | ||
endif() | ||
# Set the flag for ccache | ||
set(CXX_COMPILER_LAUNCHER PATH_TO_CCACHE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should probably check if these are already set so you don't override user options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do I do that? Also if it is already set, do I just not set it? Or somehow try to concatenate user input with the path to ccache?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In our specific case I think overriding CXX_COMPILER_LAUNCHER
should not be a bad expected behavior, so we can leave it as it is for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @electriclilies ! One last minor comment and we are good to go
CMakeLists.txt
Outdated
else() | ||
message(STATUS "Didn't find the path to CCACHE, disabling ccache") | ||
endif(CCACHE_FOUND) | ||
elseif("${USE_CCACHE}" STREQUAL "ON") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change to use
Line 86 in 8131364
set(IS_TRUE_PATTERN "^[Oo][Nn]$|^[1-9][0-9]*$|^[Tt][Rr][Uu][Ee]$|^[Yy][Ee][Ss]$|^[Yy]$") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see
tvm/cmake/utils/FindEthosN.cmake
Line 64 in 8131364
if(${USE_ETHOSN_HW} MATCHES ${IS_TRUE_PATTERN}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tqchen Done!
dfc9ed4
to
7b76703
Compare
70280c4
to
dbd8782
Compare
@tqchen @junrushao1994 This is passing, could you take a look and make sure I addressed all the comments? |
I think the PR is in pretty good state. Just one question: Is it intended behavior to disable ccache in our CI? I thought we are using it right now |
@tqchen said:
Based on this, it is my understanding that we do want to disable ccache in CI. I'm not sure whether we are using it right now. I think it would be good to double check that this is the intended behavior before it goes in given all the issues we've had with CI in the last week 😎 |
@tqchen @junrushao1994 Additionally, if I do make this change and we don't update the CI docker images, will ccache just be enabled on CI until the docker images are updated? That might be suboptimal if it does cause the memory usage to go up |
Thanks Lily for the explanation! The PR looks good to me :-) |
* 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
* 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
In this PR I add code to
cmake/config.cmake
andCMakeLists.txt
to cache builds. This makes switching between branches less painful because you don't have to build from scratch every time you switch branches.@mbrookhart @tkonolige @csullivan Please take a look!