Pregunta

Since I did not have access to a nVIDIA card, I was using GPUOcelot to compile and run my programs. Since I had separated out my cuda kernel and the C++ programs in two separate files (since I was using C++11 features) I was doing the following to run my program.

  • nvcc -c my_kernel.cu -arch=sm_20
  • g++ -std=c++0x -c my_main.cpp
  • g++ my_kernel.o my_main.o -o latest_output.o 'OcelotConfig -l'

I have recently been given access to a Windows box which has a nVIDIA card. I downloaded the CUDA toolkit for windows and mingw g++. Now I run

  • nvcc -c my_kernel.cu -arch=sm_20
  • g++ -std=c++0x -c my_main.cpp

The nvcc call now instead of producing my_kernel.o produces my_kernel.obj. And when I try to link them and run using g++ as I did before

  • g++ my_kernel.obj my_main.o -o m

I get the following error:

my_kernel.obj: file not recognized: File format not recognized
collect2.exe: error: ld returned 1 status

Could you please resolve the problem? Thanks.

¿Fue útil?

Solución

nvcc is a compiler wrapper that invokes the device compiler and the host compiler under the hood (it can also invoke the host linker, but you're using -c so not doing linking). On Windows, the supported host compiler is cl.exe from Visual Studio.

Linking two object files created with two different C++ compilers is typically not possible, even if you are just using CPU only. This is because the ABI is different. The error message you are seeing is simply telling you that the object file format from cl.exe (via nvcc) is incompatible with g++.

You need to compile my_main.cpp with cl.exe, if that's producing errors then that's a different question!

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top