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

Hello,
I want to learn from this link:
INSTALLING C++ DISTRIBUTIONS OF PYTORCH

How to create an application which will use the libTorch in order to inference my trained model which trained using the Torc Python APIs interface.

I successfully created the application based on the link instructions and successfully run it.

For further purposes I added one *.cu file because I want to add some CUDA logics which I will perform on the Tensor input before I will pass it to the model for the forward API.

I updated my CMake file with all CMake CUDA commands in order to find it and activate the CMake cache generation process to find all required CUDA include and libraries files.

The CMake cache is successfully generated.
But when I start the build process I immediately get the following error:

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

I found out that when I masked this CMake command:

target_link_libraries(${PROJECT_NAME} PUBLIC “${TORCH_LIBRARIES}”)

The nvcc error isn’t raised any more but then all torch symbols are unresolved so the linker fail and no *.exe is generated,

This is the value of the ${TORCH_LIBRARIES}:

TORCH_LIBRARIES = torch;torch_library;C:/libtorch/lib/c10.lib;C:/libtorch/lib/kineto.lib;C:\Program Files\NVIDIA Corporation\NvToolsExt/lib/x64/nvToolsExt64_1.lib;C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.4/lib/x64/cudart_static.lib;
C:/libtorch/lib/caffe2_nvrtc.lib;C:/libtorch/lib/c10_cuda.lib

My setup is:
OS - Microsoft Windows 10 Enterprise 2016 LTSB
GPU - Quadro M2000M
CUDA vers - 11.4
Visual Studio - 2019
Python - 3.6.8
libTorch 1.10.1

I can share my entire CMake file and source code if it required but as I described above my source code is exactly as detailed in the installing link.

Please advice.

Same error, with same behaviour, did you fix it somehow?

finally fixed this replaced ${TORCH_LIBRARIES} in target_link_libraries on “$ENV{LibTorch}/lib/*.lib” where $ENV{LibTorch} points to libtorch root

Thank you very much Yuriy for your sharing.
I tried to change my target_link_libraries input as you described above by doing this:

target_link_libraries(${PROJECT_NAME} PUBLIC "$ENV{THIRD_PARTIES_PATH}/libtorch/lib/*.lib")	

$ENV{THIRD_PARTIES_PATH} - Hold all my third parties installations in my PC.

CMake cache generation workings well but the build process raise this error:

C:\TorchTester\bin\x64-Release\ninja : error : ‘c:/ThirdParties/libtorch/lib/*.lib’, needed by ‘TorchTester.exe’, missing and no known rule to make it
Build All failed.

What is your CMake version?
What is your OS? IDE? Are you using CMake via Visual studio?

Thanks a lot!
Please advise.

Hi, Oron!
Im using CLion, CMake version 3.20 on Windows 10. To fix it try to use another cmake generator, im using visual studio 2019 generator. To do this run cmake with following option -G “Visual Studio 16 2019” or setup your cmake in CLion with following way


Sorry, i dont know how to setup cmake generator in visual studio. Hope it helps!

Great Yuriy,
I successfully built my tester using these CMake changes:
Was:

target_link_libraries(${PROJECT_NAME} PUBLIC ${TORCH_LIBRARIES})

Is:

file(GLOB_RECURSE TORCH_LIBS "$ENV{THIRD_PARTIES_PATH}/libtorch/lib/*.lib")
target_link_libraries(${PROJECT_NAME} PUBLIC "${TORCH_LIBS}")	

But now a new runtime problem was raised:
My trained model based on CUDA, it was moved to CUDA device before training was started.
Also, I exported it to torch script file using the command:

torch.jit.trace

And now when I want to inference it using the libtorch C++ first I loaded it using the command:

torch::jit::load(modelPath);

But it raised a runtime exception:

Could not run ‘aten::empty_strided’ with arguments from the ‘CUDA’ backend. This could be because the operator doesn’t exist for this backend, or was omitted during the selective/custom build process (if using custom build). If you are a Facebook employee using PyTorch on mobile, please visit Internal Login for possible resolutions. ‘aten::empty_strided’ is only available for these backends: [CPU, Meta, BackendSelect, Python, Named, Conjugate, Negative, ADInplaceOrView, AutogradOther, AutogradCPU, AutogradCUDA, AutogradXLA, AutogradLazy, AutogradXPU, AutogradMLC, AutogradHPU, AutogradNestedTensor, AutogradPrivateUse1, AutogradPrivateUse2, AutogradPrivateUse3, Tracer, UNKNOWN_TENSOR_TYPE_ID, Autocast, Batched, VmapMode].

Additionally, the command returned value is false:

torch::cuda::is_available()

But before the CMake changes, before I added any *.cu files while I still used the CMake command:

target_link_libraries(${PROJECT_NAME} PUBLIC ${TORCH_LIBRARIES})

The runtime worked OK and CUDA was correctly identified using the same exported model without any runtime exception.

Can you help me understand this issue please?
Why building with ${TORCH_LIBRARIES} identify the CUDA and now with the new CMake change I cannot identify the CUDA?

Thanks,

I dont know for sure, but if you print old ${TORCH_LIBRARIES} and new ${TORCH_LIBS} you’ll see difference in miss of cuda libs. For building *.cu this imports brokes everything, they already in nvcc, but for building your final executable they are necessary. So here my suggestions: move all your torch cuda extension with *.cu and their dependencies in some subdirectory, create new cmakelists.txt in there, compile it as library with new ${TORCH_LIBS}, then in your root cmakelists.txt use add_subdirectory, link this new library with your c++ executable with linking cuda libraries or old ${TORCH_LIBRARIES}. I’m pretty sure this should help.

Yuriy,
Your offer works, thanks!
When NVCC compiler operation is activated independently from the linker operation everything is working fine.

It means that all *.cu & *.cuh files shall be compiled to a separated library which further will be linked to the final application.

Still, it isn’t understood why working with ${TORCH_LIBS} disable any torch CUDA identification while working with ${TORCH_LIBRARIES} enable it…

Details:
${TORCH_LIBS} includes these libraries:
Caffe2_perfkernels_avx.lib;
Caffe2_perfkernels_avx2.lib;
Caffe2_perfkernels_avx512.lib;
XNNPACK.lib;
asmjit.lib;
c10.lib;
c10_cuda.lib;
caffe2_detectron_ops_gpu.lib;
caffe2_module_test_dynamic.lib;
caffe2_nvrtc.lib;
clog.lib;
cpuinfo.lib;
dnnl.lib;
fbgemm.lib;
fbjni.lib;
kineto.lib;
libprotobuf-lite.lib;
libprotobuf.lib;
libprotoc.lib;
mkldnn.lib;
pthreadpool.lib;
pytorch_jni.lib;
torch.lib;
torch_cpu.lib;
torch_cuda.lib;
torch_cuda_cpp.lib;
torch_cuda_cu.lib

${TORCH_LIBRARIES} includes these libraries:
torch;
torch_library;
c10.lib;
kineto.lib;
nvToolsExt64_1.lib;
cudart_static.lib;
caffe2_nvrtc.lib;
c10_cuda.lib

When I use ${TORCH_LIBRARIES} i added separately all other required libs such as cudart_static…

With both CMAKE variables the linker successfully completed but during runtime torch CUDA isn’t identified if I used ${TORCH_LIBRARIES}. It seams that only torch CPU was statically and dynamically linked.

Regards,

Hi, Oron

Im glad this helped