Change:
Here's the situation: Ideally, you'd say something like to make a build of PyTorch with a non-standard version of CUDA. When this happens, needs to find the correct copy of nvcc to use. If you are using ccache as per the instructions in you'll have set to your ccache binary, so that ccache happens. cmake will correctly respect this variable. However, here's the problem: ccache's nvcc will use your path to determine what the real nvcc to use is, this means that you'll pick up whatever nvcc is in your PATH, which is probably not the one you want, because you're trying to use a different nvcc. So in sum, you have to do the non-intuitive to get the whole shebang to work. The worst part is that it won't tell you if you've got it wrong, it will happily use the wrong nvcc. I haven't gone through user submitted issues to see if anyone has succumbed to this particular bug.
A long-term solution might be getting to work
works now.

Discussion:
return() endif() set(CAFFE2_FOUND_CUDA TRUE) <ins> message(STATUS "Caffe2: CUDA detected: " ${CUDA_VERSION}) message(STATUS "Caffe2: CUDA nvcc is: " ${CUDA_NVCC_EXECUTABLE}) message(STATUS "Caffe2: CUDA toolkit directory: " ${CUDA_TOOLKIT_ROOT_DIR}) if(CUDA_FOUND) # Sometimes, we may mismatch nvcc with the CUDA headers we are # compiling with, e.g., if a ccache nvcc is fed to us by CUDA_NVCC_EXECUTABLE # but the PATH is not consistent with CUDA_HOME.  It's better safe # than sorry: make sure everything is consistent. set(file "${PROJECT_BINARY_DIR}/detect_cuda_version.c") file(WRITE ${file} "" "#include <cuda.h>n" "#include <stdio.h>n" "int main() {n" "  printf("%d.%d", CUDA_VERSION / 1000, (CUDA_VERSION / 10) % 100);n" "  return 0;n" "}n" ) try_run(run_result compile_result ${PROJECT_BINARY_DIR} ${file} CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${CUDA_INCLUDE_DIRS}" LINK_LIBRARIES ${CUDA_LIBRARIES} RUN_OUTPUT_VARIABLE cuda_version_from_header COMPILE_OUTPUT_VARIABLE output_var ) if(NOT compile_result) message(FATAL_ERROR "Caffe2: Couldn't determine version from header: " ${output_var}) endif() message(STATUS "Caffe2: Header version is: " ${cuda_version_from_header}) if(NOT ${cuda_version_from_header} STREQUAL ${CUDA_VERSION}) # Force CUDA to be processed for again next time # TODO: I'm not sure if this counts as an implementation detail of # FindCUDA set(${cuda_version_from_findcuda} ${CUDA_VERSION}) unset(CUDA_TOOLKIT_ROOT_DIR_INTERNAL CACHE) # Not strictly necessary, but for good luck. unset(CUDA_VERSION CACHE) # Error out message(FATAL_ERROR "FindCUDA says CUDA version is ${cuda_version_from_findcuda} (usually determined by nvcc), " "but the CUDA headers say the version is ${cuda_version_from_header}.  This often occurs " "when you set both CUDA_HOME and CUDA_NVCC_EXECUTABLE to " "non-standard locations, without also setting PATH to point to the correct nvcc.  " "Perhaps, try re-running this command again with PATH=${CUDA_TOOLKIT_ROOT_DIR}/bin:$PATH.  " "See above log messages for more diagnostics, and see https://github.com/pytorch/pytorch/issues/8092 for more details.") endif() endif() </ins> # Find cuDNN. if(CAFFE2_STATIC_LINK_CUDA)

endif() # ---[ Exract versions <del> message(STATUS "Caffe2: CUDA detected: " ${CUDA_VERSION}) </del> if (CAFFE2_FOUND_CUDNN) # Get cuDNN version file(READ ${CUDNN_INCLUDE_DIR}/cudnn.h CUDNN_HEADER_CONTENTS)