Skip to content
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

[question] Configuring CUDA projects with Conan CMake toolchain fails #17289

Open
1 task done
JakubOchnik opened this issue Nov 7, 2024 · 2 comments
Open
1 task done
Assignees

Comments

@JakubOchnik
Copy link

JakubOchnik commented Nov 7, 2024

What is your question?

What is your question?
I'm developing a CUDA project using conan, CMake and MSVC build tools. After update from CUDA 11.x to CUDA 12.6, any project using conan CMake toolchain fails to configure during CUDA compiler test. It also reproduces in my more complex project GitHub actions Windows build job (example).

The problematic line in CUDA 12.6.targets is the following:

<Runtime Condition="'%(CudaCompile.Runtime)' == 'InheritFromHost'">@(CudaCompileHostRuntimeMap->Metadata('$(_CudaCompileHostRuntimeLibrary)'))</Runtime>

I suspect it has something to do with CMAKE_POLICY_DEFAULT_CMP0091="NEW" and runtime option - it looks like it's not propagated properly. Is there any way to work around this issue?

Environment details

  • OS: Windows 11 24H2
  • Conan: 2.9.1
  • CUDA: 12.6
  • Visual Studio 2022 17.11.5, MSVC 19.41.34123
  • CMake 3.30.5

conanfile.py:

from conan import ConanFile
from conan.tools.cmake import cmake_layout

class DummyProj(ConanFile):
    name = "dummy"
    generators = "CMakeDeps", "CMakeToolchain"
    settings = "os", "build_type", "compiler", "arch"
    build_policy = "missing"

    def layout(self):
        cmake_layout(self)

CMakeLists.txt:

cmake_minimum_required(VERSION 3.23)
project(dummy VERSION 0.1.0 LANGUAGES CUDA CXX)

Steps to reproduce:
conan install . -s build_type=Release --build=missing

======== Input profiles ========
Profile host:
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=14
compiler.runtime=dynamic
compiler.runtime_type=Release
compiler.version=193
os=Windows

Profile build:
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=14
compiler.runtime=dynamic
compiler.runtime_type=Release
compiler.version=193
os=Windows


======== Computing dependency graph ========
Graph root
    conanfile.py (dummy/None): C:\Users\Jakub\Desktop\Development\dummy_cuda\conanfile.py

======== Computing necessary packages ========

======== Installing packages ========

======== Finalizing install (deploy, generators) ========
conanfile.py (dummy/None): Writing generators to C:\Users\Jakub\Desktop\Development\dummy_cuda\build\generators
conanfile.py (dummy/None): Generator 'CMakeDeps' calling 'generate()'
conanfile.py (dummy/None): Generator 'CMakeToolchain' calling 'generate()'
conanfile.py (dummy/None): CMakeToolchain generated: conan_toolchain.cmake
conanfile.py (dummy/None): CMakeToolchain: Preset 'conan-default' added to CMakePresets.json.
    (cmake>=3.23) cmake --preset conan-default
    (cmake<3.23) cmake <path> -G "Visual Studio 17 2022" -DCMAKE_TOOLCHAIN_FILE=generators\conan_toolchain.cmake  -DCMAKE_POLICY_DEFAULT_CMP0091=NEW
conanfile.py (dummy/None): CMakeToolchain generated: C:\Users\Jakub\Desktop\Development\dummy_cuda\build\generators\CMakePresets.json
conanfile.py (dummy/None): CMakeToolchain generated: C:\Users\Jakub\Desktop\Development\dummy_cuda\CMakeUserPresets.json
conanfile.py (dummy/None): Generating aggregated env files
conanfile.py (dummy/None): Generated aggregated env files: ['conanbuild.bat', 'conanrun.bat']
Install finished successfully

cmake --preset conan-default

Preset CMake variables:

  CMAKE_POLICY_DEFAULT_CMP0091="NEW"
  CMAKE_TOOLCHAIN_FILE:FILEPATH="generators\conan_toolchain.cmake"

-- Using Conan toolchain: C:/Users/Jakub/Desktop/Development/dummy_cuda/build/generators/conan_toolchain.cmake
-- Conan toolchain: CMAKE_GENERATOR_TOOLSET=v143
-- Conan toolchain: Setting CMAKE_MSVC_RUNTIME_LIBRARY=$<$<CONFIG:Release>:MultiThreadedDLL>
-- Conan toolchain: C++ Standard 14 with extensions OFF
-- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.26100.
-- The CXX compiler identification is MSVC 19.41.34123.0
-- The CUDA compiler identification is NVIDIA 12.6.77
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.41.34120/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - failed
-- Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.6/bin/nvcc.exe
-- Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.6/bin/nvcc.exe - broken
CMake Error at C:/Program Files/CMake/share/cmake-3.30/Modules/CMakeTestCUDACompiler.cmake:59 (message):
  The CUDA compiler

    "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.6/bin/nvcc.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: 'C:/Users/Jakub/Desktop/Development/dummy_cuda/build/CMakeFiles/CMakeScratch/TryCompile-jhqlit'

    Run Build Command(s): "C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/amd64/MSBuild.exe" cmTC_0b9ce.vcxproj /p:Configuration=Debug /p:Platform=x64 /p:VisualStudioVersion=17.0 /v:n
    MSBuild version 17.11.9+a69bbaaf5 for .NET Framework
    Build started 11/7/2024 7:29:45 PM.

    Project "C:\Users\Jakub\Desktop\Development\dummy_cuda\build\CMakeFiles\CMakeScratch\TryCompile-jhqlit\cmTC_0b9ce.vcxproj" on node 1 (default targets).
    PrepareForBuild:
      Creating directory "cmTC_0b9ce.dir\Debug\".
      Structured output is enabled. The formatting of compiler diagnostics will reflect the error hierarchy. See https://aka.ms/cpp/structured-output for more details.
      Creating directory "C:\Users\Jakub\Desktop\Development\dummy_cuda\build\CMakeFiles\CMakeScratch\TryCompile-jhqlit\Debug\".
      Creating directory "cmTC_0b9ce.dir\Debug\cmTC_0b9ce.tlog\".
    InitializeBuildStatus:
      Creating "cmTC_0b9ce.dir\Debug\cmTC_0b9ce.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
      Touching "cmTC_0b9ce.dir\Debug\cmTC_0b9ce.tlog\unsuccessfulbuild".
    C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\BuildCustomizations\CUDA 12.6.targets(277,17): error MSB4023: Cannot evaluate the item metadata "%()". Parameter "metadataName" cannot have zero length. [C:\Users\Jakub\Desktop\Development\dummy_cuda\build\CMakeFiles\CMakeScratch\TryCompile-jhqlit\cmTC_0b9ce.vcxproj]
    Done Building Project "C:\Users\Jakub\Desktop\Development\dummy_cuda\build\CMakeFiles\CMakeScratch\TryCompile-jhqlit\cmTC_0b9ce.vcxproj" (default targets) -- FAILED.

    Build FAILED.

    "C:\Users\Jakub\Desktop\Development\dummy_cuda\build\CMakeFiles\CMakeScratch\TryCompile-jhqlit\cmTC_0b9ce.vcxproj" (default target) (1) ->
    (AddCudaCompileMetadata target) ->
      C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\BuildCustomizations\CUDA 12.6.targets(277,17): error MSB4023: Cannot evaluate the item metadata "%()". Parameter "metadataName" cannot have zero length. [C:\Users\Jakub\Desktop\Development\dummy_cuda\build\CMakeFiles\CMakeScratch\TryCompile-jhqlit\cmTC_0b9ce.vcxproj]

        0 Warning(s)
        1 Error(s)

    Time Elapsed 00:00:00.74





  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:2 (project)


-- Configuring incomplete, errors occurred!

CMake without conan toolchain works fine.
cmake .

-- Building for: Visual Studio 17 2022
-- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.26100.
-- The CXX compiler identification is MSVC 19.41.34123.0
-- The CUDA compiler identification is NVIDIA 12.6.77
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.41.34120/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - done
-- Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.6/bin/nvcc.exe - skipped
-- Detecting CUDA compile features
-- Detecting CUDA compile features - done
-- Configuring done (10.1s)
-- Generating done (0.0s)
-- Build files have been written to: C:/Users/Jakub/Desktop/Development/dummy_cuda

Have you read the CONTRIBUTING guide?

  • I've read the CONTRIBUTING guide
@memsharded
Copy link
Member

Hi @JakubOchnik

Thanks for your detailed report.

I suspect it has something to do with CMAKE_POLICY_DEFAULT_CMP0091="NEW" and runtime option - it looks like it's not propagated properly. Is there any way to work around this issue?

Could you please check this? If you could remove the CMAKE_POLICY_DEFAULT_CMP0091 both from the CMakePresets.json and conan_toolchain.cmake generated files before calling cmake --preset to check if it works, then do the same with the runtime-option (btw, what is this runtime option?)

Maybe @jcar87 who has more experience than me with CUDA could help too.

@JakubOchnik
Copy link
Author

Thanks for looking into it, @memsharded!

It worked after removing the runtime library-related code from generated conan_toolchain.cmake.
After some trial and error, it turned out that the minimal set of changes that solves the CUDA configuration failure is removing setting the runtime with CMAKE_MSVC_RUNTIME_LIBRARY from conan_toolchain.cmake:

set(CMAKE_MSVC_RUNTIME_LIBRARY "$<$<CONFIG:Release>:MultiThreadedDLL>")

So I tried to just use regular CMake with this option, and voila, it failed again.
CMakeLists.txt:

cmake_minimum_required(VERSION 3.23)
set(CMAKE_MSVC_RUNTIME_LIBRARY "$<$<CONFIG:Release>:MultiThreadedDLL>")
project(dummy VERSION 0.1.0 LANGUAGES CXX CUDA)

cmake .

-- Building for: Visual Studio 17 2022
-- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.26100.
-- The CXX compiler identification is MSVC 19.41.34123.0
-- The CUDA compiler identification is NVIDIA 12.6.77
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.41.34120/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - failed
-- Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.6/bin/nvcc.exe
-- Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.6/bin/nvcc.exe - broken
CMake Error at C:/Program Files/CMake/share/cmake-3.30/Modules/CMakeTestCUDACompiler.cmake:59 (message):
  The CUDA compiler

    "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.6/bin/nvcc.exe"

  is not able to compile a simple test program.
 ...
    "C:\Users\Jakub\Desktop\Development\dummy_cuda\CMakeFiles\CMakeScratch\TryCompile-7m8wyt\cmTC_554e7.vcxproj" (default target) (1) ->
    (AddCudaCompileMetadata target) ->
      C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\BuildCustomizations\CUDA 12.6.targets(277,17): error MSB4023: Cannot evaluate the item metadata "%()". Parameter "metadataName" cannot have zero length. [C:\Users\Jakub\Desktop\Development\dummy_cuda\CMakeFiles\CMakeScratch\TryCompile-7m8wyt\cmTC_554e7.vcxproj]
...

So it looks like an incompatibility between CMake and Visual Studio CUDA integration.

Is there any way to disable setting the CMAKE_MSVC_RUNTIME_LIBRARY in conan CMake toolchain (e.g. via conanfile.py)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants