Adding both openexr and cuda to cmakelist compiles with an error
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
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'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 neededalso
# 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.
I was hoping CUDA_SEPARABLE_COMPILATION would solve it. Maybe someone who works more regularly with Cuda has some suggestions?
I was hoping
CUDA_SEPARABLE_COMPILATIONwould 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
Good detective work! You are right.
https://github.com/AcademySoftwareFoundation/openexr/blob/b6fc6eccf991044d4990a5e8a3f580ec4c6b7149/cmake/LibraryDefine.cmake#L13
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