Search code examples
visual-c++cuda

CUDA compatibility with Visual Studio 2022 version 17.10


I have just upgraded Visual Studio 2022 to the latest version 17.10, and found that my program using CUDA v12.0 does not compile because of the error in NVIDIA GPU Computing Toolkit\CUDA\v12.0\include\crt\host_config.h:

#if _MSC_VER < 1910 || _MSC_VER >= 1940

#error -- unsupported Microsoft Visual Studio version! Only the versions between 2017 and 2022 (inclusive) are supported! The nvcc flag '-allow-unsupported-compiler' can be used to override this version check; however, using an unsupported host compiler may cause compilation failure or incorrect run time execution. Use at your own risk.

because _MSC_VER = 1940 in Visual Studio 2022 v17.10.

Is it safe to use compilation flag -allow-unsupported-compiler in my case or just patch host_config.h allowing for higher _MSC_VER, or Visual Studio 2022 v17.10 is actually and irreparably incompatible with CUDA 12.0 (and below)?


Solution

  • There are version requirements on both sides. For background info, see MSVC Toolset Minor Version Number 14.40 in VS 2022 v17.10, aka "we ran out of digits".

    • CUDA 12.4 was the first version to recognize and support MSVC 19.40 (aka VS 2022 17.10).
      • Note: It was definitely CUDA 12.4, not CUDA 12.5, that started allowing this.
      • CUDA 12.3 and older versions rejected MSVC 19.40. The nvcc compiler option --allow-unsupported-compiler can be used as an escape hatch.
    • MSVC 19.40 requires CUDA 12.4 or newer. Older versions will be rejected with error STL1002: "Unexpected compiler version, expected CUDA 12.4 or newer."
      • There's an escape hatch: Define _ALLOW_COMPILER_AND_STL_VERSION_MISMATCH project-wide.
      • This requirement was increased by microsoft/STL#4475.

    Note that when you activate these escape hatches, you're using a configuration that hasn't been tested by CUDA and MSVC, but things will probably work (as long as your CUDA version isn't extremely old; e.g. MSVC's previous requirement was CUDA 11.6.)

    enter image description here