How to Use Other C++ Compilers with Cuda on Windows

Compiling c++ and cuda code with MinGW in QTCreator

I'm a bit confused, are you using MinGW or Visual? The title seems to state that you are using MinGW but the project file seems to use a mix of both. You can't mix those two. If you compiled (or downloaded the binary directly from NVidia) CUDA with Visual Studio 2010, you HAVE to use VS10 to compile your project, otherwise it won't work.

I never used CUDA myself but it seems that the system requirements mention only Visual Studio 2008, 2010 and 2012. If you want to use it with Qt, it's possible, you just have to grab a Qt compiled with VS (there are builds for 32 and 64 bit for both on the download page. You can get Visual Studio Express for free as long as you don't create any commercial application with it.

To use QtCreator with the MSVC backend compiler go to Tools > Options > Build and Run > Kits and add a new Kit with the MSVC compiler, cdb as the debugger and the Qt version you just downloaded (it must have been compiled with the same Visual Studio version otherwise it won't work). Then open your project, go to the Projects tab (on the left) and select the Kit you just created. You should probably clean your .pro file as well before everything work smoothly.

On a side note, there are a few things that seems out of place in your linker line:

g++ -Wl,-s -Wl,-subsystem,windows -mthreads -o release\Cuda.exe release/cuda/vectorAddition_cuda.o release/obj/main.o  -lglu32 -lopengl32 -lgdi32 -luser32 -lmingw32 -lqtmain -LC:\Cuda\CudaToolkit\lib\Win32 -LC:\Cuda\CudaSamples\common\lib\Win32 -LC:\Cuda\CudaSamples\..\shared\lib\Win32 -LC:\CUDA\VS10\VC\lib -LQMAKE_LIBS -L+= -L-lmsvcrt -L-llibcmt -L-llibcpmt -lcuda -lcudart -LF:\Programs\Qt5.1.1\5.1.1\mingw48_32\lib -lQt5Gui -lQt5Core 

First this -L+=, which might be caused by the escaping backslash at the end of the QMAKE_LIBDIR.

Then the syntax -L-lmsvcrt seems wrong. It might be because you are using QMAKE_LIBS, I personally never had to use it, and according to the documentation you shouldn't either as it is an internal variable. Same goes for QMAKE_LIBDIR btw. I would just use the LIBS variable for any external dependency.

How to use Intel C++ Compiler with CUDA nvcc?

Unfortunately you cannot (or at least its HIGHLY unrecommended). The only compiler supported on windows is visual studio. Unless something has changed and they now support intel's compilers i wouldn't suggest using them

http://forums.nvidia.com/index.php?showtopic=153975

How can I override the C++ compiler CMake uses for CUDA?

CMake will not (for now) default to using your CMAKE_CXX_COMPILER as the C++ compiler for CUDA host-side code; there's a different setting for that. Run your build configuration like so:

cmake -DCMAKE_CUDA_HOST_COMPILER=/usr/bin/g++-9

(replace the path with to your chosen C++ compiler of course)

CUDA compile problems on Windows, Cmake error: No CUDA toolset found

I have tried it on a different PC now and it works fine. So I had absolutely no idea why it's not working on this one. As CUDA_PATH is correctly setup in my system variables.

Then looking into it further, by uninstalling the 'Build Tools' of Visual Studio and only having the Community IDE installed, CMake used the IDE instead of the Build Tools and then it started working fine.

Is it possible to compile CUDA C code for Linux on a Windows machine?

I'd go for virtual Ubunto Linux on top of Windows

You can do it using virtual box virtual machine

CUDA code compile on Linux but not in Windows ( Visual Studio 2012)

You won't be able to fix either of these problems just by changing compiler versions or anything like that.

The first issue is described here and here, it has nothing to do with CUDA except insofar as CUDA is making use of the host compiler. The code you have shown makes use of a VLA (variable length array) which is part of the C99 standard but not part of any C++ standard. CUDA is primarily implemented based on C++, and makes use of the C++ host compiler to compile host code, which is what you have shown. On windows it is using the Microsoft compiler for that. So the Microsoft compiler is correct to disallow VLA, and there is no way to avoid this AFAIK. Your code works on linux, because on linux nvcc uses the g++ host compiler, and it allows (in a non-standard-compliant way) the use of a VLA in C++ host code.

I don't know of any method to address this that doesn't involve some change to your code, for cross-platform compatibility. But a small amount of (C or) C++ programming skill can provide a solution for you that should work either on linux or windows:

int n_devices = 0;
cudaGetDeviceCount(&n_devices);
cudaDeviceProp *props = new cudaDeviceProp[n_devices];

(if you wanted to use a C compliant method, you could use malloc in a similar fashion)

The second issue is a limitation of CUDA, it is documented here.

There is also no method to address this cross-platform that I know of that involves no changes to your code.

You already have identified one possible workaround that can work in a cross-platform way both on linux and windows:

#define PI 3.141592654f
#define EPS 1e-3f


Related Topics



Leave a reply



Submit