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

Adding both openexr and cuda to cmakelist compiles with an error #1897

Open
neross666 opened this issue Oct 25, 2024 · 5 comments
Open

Adding both openexr and cuda to cmakelist compiles with an error #1897

neross666 opened this issue Oct 25, 2024 · 5 comments

Comments

@neross666
Copy link

I'm using cmake as a configuration tool for my project, adding both openexr and cuda to cmakelist, and compiling with the error:

nvcc fatal: A single input file is required for a non-link phase when outputfile is specified.

My cmakelist is as follows:

cmkae_minimun_required(VERSION 3.18)
SET(CMAKE_CXX_STANDARD 17)

enable_language(CUDA)

find(OpenEXR REQUIRED)
find(CUDAToolkit REQUIRED)

add_executable(mytarget main.cpp kernel.cpp)

tartget_link_libraries(mytarget 
PRIVATE
OpenEXR::OpenEXR
CUDA::cudart
)

I searched for a similar example, see https://gitlab.kitware.com/cmake/cmake/-/issues/25565

@meshula
Copy link
Contributor

meshula commented Oct 25, 2024

I'm assuming the typos are not the source of your issue, and you've retyped some portion of your cmakelist.txt.

some suggetions

# Define the executable and explicitly mark kernel.cpp as a CUDA source
add_executable(mytarget main.cpp kernel.cu)  # Change kernel.cpp to kernel.cu if needed

also

# Add CUDA separable compilation if needed
set_target_properties(mytarget PROPERTIES CUDA_SEPARABLE_COMPILATION ON)

Don't know if this will fix things, but a couple fo things to try.

@neross666
Copy link
Author

I'm assuming the typos are not the source of your issue, and you've retyped some portion of your cmakelist.txt.

some suggetions

# Define the executable and explicitly mark kernel.cpp as a CUDA source
add_executable(mytarget main.cpp kernel.cu)  # Change kernel.cpp to kernel.cu if needed

also

# Add CUDA separable compilation if needed
set_target_properties(mytarget PROPERTIES CUDA_SEPARABLE_COMPILATION ON)

Don't know if this will fix things, but a couple fo things to try.

I apologize for the many spelling errors in my cmakelist file, which now reads as follows:

cmake_minimum_required(VERSION 3.18)
SET(CMAKE_CXX_STANDARD 17)

enable_language(CUDA)

find_package(OpenEXR REQUIRED)
find_package(CUDAToolkit REQUIRED)

add_executable(mytarget main.cpp kernel.cu)

set_target_properties(mytarget 
PROPERTIES CUDA_SEPARABLE_COMPILATION ON)

target_link_libraries(mytarget 
PRIVATE
OpenEXR::OpenEXR
CUDA::cudart
)

Then, when compiling, the error still occurs:

nvcc fatal: A single input file is required for a non-link phase when outputfile is specified.

I checked the compilation directive as follows:

“C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.6\bin\nvcc.exe“ -gencode=arch=compute_52,code=\”compute_52,compute_52\” -gencode =arch=compute_52,code=\\“sm_52,compute_52\” --use-local-env -ccbin “C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools \MSVC\14.29.30133\bin\HostX64\x64” -x cu -rdc=true -I ‘C:\Src\vcpkg\installed\x64-windows\include’ -I ”C:\Src\vcpkg\installed\x64-windows \include\OpenEXR” -I ‘C:\Src\vcpkg\installed\x64-windows\include\Imath’ -I ”C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.6\ include” -I ‘C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.6\include’ --keep-dir x64\Debug -maxrregcount=0 --machine 64 --compile - cudart static /EHsc -std=c++17 -Xcompiler=“/EHsc -Zi -Ob0” -g -D_WINDOWS -DOPENEXR_DLL -DIMATH_DLL -D “CMAKE_INTDIR=\”Debug\“” -DWIN32 -D_ WINDOWS -DOPENEXR_DLL -DIMATH_DLL -D “CMAKE_INTDIR=\”Debug\“” -D_MBCS -Xcompiler “/EHsc /W1 /nologo /Od /FS /Zi /RTC1 /MDd /GR” -Xcompiler “/ Fdmytarget.dir\Debug\vc142.pdb” -o mytarget.dir\Debug\kernel.obj ”C:\Users\86135\source\repos\CMakeProject1\CMakeProject1\kernel.cu” 

Also, I get the same error when using openVDB in a cuda project, which I assume is caused by openVDB's dependency on openEXR.

@meshula
Copy link
Contributor

meshula commented Oct 28, 2024

I was hoping CUDA_SEPARABLE_COMPILATION would solve it. Maybe someone who works more regularly with Cuda has some suggestions?

@neross666
Copy link
Author

neross666 commented Oct 28, 2024

I was hoping CUDA_SEPARABLE_COMPILATION would solve it. Maybe someone who works more regularly with Cuda has some suggestions?

If I remove the '/EHsc' tag from the nvcc command and modify it as follows:

“C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.6\bin\nvcc.exe“ -gencode=arch=compute_52,code=\”compute_52,compute_52\” -gencode =arch=compute_52,code=\\“sm_52,compute_52\” --use-local-env -ccbin “C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools \MSVC\14.29.30133\bin\HostX64\x64” -x cu -rdc=true -I ‘C:\Src\vcpkg\installed\x64-windows\include’ -I ”C:\Src\vcpkg\installed\x64-windows \include\OpenEXR” -I ‘C:\Src\vcpkg\installed\x64-windows\include\Imath’ -I ”C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.6\ include” -I ‘C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.6\include’ --keep-dir x64\Debug -maxrregcount=0 --machine 64 --compile - cudart static -std=c++17 -Xcompiler=“/EHsc -Zi -Ob0” -g -D_WINDOWS -DOPENEXR_DLL -DIMATH_DLL -D “CMAKE_INTDIR=\”Debug\“” -DWIN32 -D_ WINDOWS -DOPENEXR_DLL -DIMATH_DLL -D “CMAKE_INTDIR=\”Debug\“” -D_MBCS -Xcompiler “/EHsc /W1 /nologo /Od /FS /Zi /RTC1 /MDd /GR” -Xcompiler “/ Fdmytarget.dir\Debug\vc142.pdb” -o mytarget.dir\Debug\kernel.obj ”C:\Users\86135\source\repos\CMakeProject1\CMakeProject1\kernel.cu” 

The error is eliminated at this point:

nvcc fatal: A single input file is required for a non-link phase when outputfile is specified.

My guess is that openEXR imported the '/EHsc' command tag externally to cause the problem

@meshula
Copy link
Contributor

meshula commented Oct 29, 2024

Good detective work! You are right.

set(_openexr_extra_flags "/EHsc" "/MP")

It's hard to trace beyond this commit four years ago, but if I remember correctly, /EHsc used to generate measurably faster code in OpenEXR. Now that the core has been switched to C, I bet it is irrelevant.

https://github.com/AcademySoftwareFoundation/openexr/blame/81b931f7b3b227893afac569d34019a59410b42f/cmake/LibraryDefine.cmake

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

No branches or pull requests

2 participants