cconvey commented on code in PR #11189:
URL: https://github.com/apache/tvm/pull/11189#discussion_r864952809


##########
CMakeLists.txt:
##########
@@ -509,6 +510,103 @@ set(LIBINFO_FILE 
${CMAKE_CURRENT_LIST_DIR}/src/support/libinfo.cc)
 add_lib_info(${LIBINFO_FILE})
 list(REMOVE_ITEM COMPILER_SRCS ${LIBINFO_FILE})
 
+# 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.
+#
+# NOTE: CMAKE_C[XX]_COMPILER_LAUNCHER only affects build targets that we add 
*later*.
+# So we want this logic to appear towards the top of thet this CMakeLists.txt 
file.
+if(USE_CCACHE) # True for AUTO, ON, /path/to/ccache
+
+  
#-------------------------------------------------------------------------------------------------
+  # Determine which requested policy.
+  # If ccache is required but can't be found, fail with an error message.
+  
#-------------------------------------------------------------------------------------------------
+  if("${USE_CCACHE}" STREQUAL "AUTO") # Auto mode
+      set(CCACHE_PROGRAM_CANDIDATE ccache)
+      set(CCACHE_REQUIRED FALSE)
+  elseif("${USE_CCACHE}" MATCHES ${IS_TRUE_PATTERN})
+      set(CCACHE_PROGRAM_CANDIDATE ccache)
+      set(CCACHE_REQUIRED TRUE)
+  else() # /path/to/ccache
+      set(CCACHE_PROGRAM_CANDIDATE "${USE_CCACHE}")
+      set(CCACHE_REQUIRED TRUE)
+  endif()
+
+  find_program(CCACHE_PROGRAM "${CCACHE_PROGRAM_CANDIDATE}")
+  if (CCACHE_PROGRAM)
+      message(STATUS "Found ccache program: '${CCACHE_PROGRAM}'")
+  else()
+      # Note: Once we require cmake >= 3.18, we can simplify this logic using
+      # `find_program(... REQUIRED)`.
+      if (CCACHE_REQUIRED)
+          message(FATAL_ERROR "Unable to find ccache program: 
'${CCACHE_PROGRAM_CANDIDATE}'")
+      else()
+          message(STATUS "Unable to find ccache program: 
'${CCACHE_PROGRAM_CANDIDATE}'")

Review Comment:
   Good question.  I think the basic issue is that we can't distinguish the two 
causes of `USE_CCACHE=AUTO`:
   - the user explicitly set it that way, vs.
   - the user left the default value in place, perhaps unwittingly.
   
   If we knew that the user explicitly set it to `AUTO`, I think `WARNING` is a 
better choice than `STATUS`.
   
   Since we don't know either way, my personal preference is to bias towards 
clean builds.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to