Reputation: 3957
I am trying to compile Cuda code (in the form of .cu files) in Qt Creator 4.8.0 on a 32-bit Windows 7 system, and I am currently failing.
I put together the following project file:
TARGET = TestCUDA
DESTDIR = release
OBJECTS_DIR = release/obj
CUDA_OBJECTS_DIR = release/cuda
SOURCES += main.cpp
CUDA_SOURCES += test.cu
CUDA_SDK = "C:/ProgramData/NVIDIA Corporation/NVIDIA GPU Computing SDK 4.2/C" # Path to cuda SDK install
CUDA_DIR = "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v4.2" # Path to cuda toolkit install
INCLUDEPATH += $$CUDA_DIR/include \
$$CUDA_SDK/common/inc/ \
$$CUDA_SDK/../shared/inc/
QMAKE_LIBDIR += $$CUDA_DIR/lib/Win32 \
$$CUDA_SDK/common/lib/Win32 \
$$CUDA_SDK/../shared/lib/Win32
LIBS += -lcuda -lcudart
CUDA_INC = $$join(INCLUDEPATH,'" -I"','-I"','"') # this is to put quotes around paths with spaces
cuda.input = CUDA_SOURCES
cuda.output = $$CUDA_OBJECTS_DIR/${QMAKE_FILE_BASE}_cuda.ptx
cuda.commands = $$CUDA_DIR/bin/nvcc.exe $$CUDA_INC $$LIBS --machine 32 -ptx -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
cuda.dependency_type = TYPE_C
QMAKE_EXTRA_COMPILERS += cuda
This is supposed to produce a test_cuda.ptx module in the release/cuda/ folder. Incidentally, that's exactly what it does, hurrah! BUT it also gives a LNK1107 error:
C:\path\to\release\cuda\test_cuda.ptx:-1: error: LNK1107: invalid or corrupt file: cannot read at 0xFCC
I do not know why this happens, nor how to solve it. The location indicated in this error is somewhere in the middle of the test_cuda.ptx
file, but that's not of any help. What's also strange is that this same file works perfectly when I import it in another Cuda application, so the file is not corrupt. The main.cpp
is completely empty:
int main(int argc, char* argv []) {}
so that's not where the linker could go wrong. It seems like the linker is linking stuff it shouldn't link, but I don't know why, or how to stop this. Anyone an idea?
Upvotes: 2
Views: 1134
Reputation: 27809
As mentioned by @asm you are compiling to PTX intermediate files and then trying to link them as object files. But counter to @asm's suggestion, you should not compile to cubin, but to object files. To do so, you want the -c
option rather than the -ptx
option:
cuda.input = CUDA_SOURCES
cuda.output = $$CUDA_OBJECTS_DIR/${QMAKE_FILE_BASE}_cuda.o
cuda.commands = $$CUDA_DIR/bin/nvcc.exe $$CUDA_INC $$LIBS --machine 32 -c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
Caveat: not a QMAKE user so the above might not be exactly right. I second the recommendation for CMake.
Upvotes: 2