Is there any option in ‘nvcc’ to specify our own C compiler.
For eg.: by default, in windows, ‘cl.exe’ is considered to be the C compiler. Can I change this to, let us say, ‘gcc’ compiler for windows or a turbo C compiler?
I was just curious whether or not its possible! :)
I’ve gotten these error message before and they usually meant there were bogus command line options. Try removing the space between your -D and -I switches and the strings next to them.
e.g. -D_CRT_NONSTDC_NO_DEPRECATE and -I"/cygdrive/c/CUDA/include"
If I include ‘gcc’ then the previous error message is getting repeated again.
Also, ‘–foreign’ option is a ‘boolean switch’
i.e. default c compilers are ‘gcc/g++’ for linux and ‘cl’ for windows.
and presence of ‘–foreign’ will just reverse this default values (i.e. ‘gcc/g++’ for windows)
Besides, which version of CUDA are you using that you’re running it under cygwin? I don’t think anything is supported under cygwin, you’d need a totally win32 gcc.
I bet you could hack it if you really tried… what does MSVC have that gcc don’t? GCC can interface to win32 dlls, in mingw, cygwin, and subsystem for unix applications (MS’s cygwin).
Surely if you used the Driver API none of this would even be a problem.
The driver api is the one that doesn’t use “nvcc.” It just uses a standard C compiler, you’ve got to include the header files yourself, and all the function calls get more complicated because the syntactic sugar goes away. But it should work 100% with gcc since gcc can work 100% with ordinary windows dlls. It’s nvcc’s “magic” that’s the problem. Look at the programming guide re driver api.
A last (idiotic) question :)
So, if I use driver API (with appropriate header files) can I use ‘gcc’ (or any other C compiler) to compile my code for GPU?
Afaik in 2.3 where the kernel should be in .ptx or .cubin format, you cannot compile the kernel in gcc, as gcc knows nothing about these (Nvidia?) formats.
I got mine test working on win64 with mingw-w64 by using the driver api and 64bit linux nvcc to compile the kernel to .cubin (and .ptx). What is kind of annoying is that i cannot compile 64b and 32b versions on same nvcc, as it seems to support only native compiling. Also the message if you try to load 32b .cubin to 64bit cuda program you just get ‘cannot find function’-error.
Steps to compile program using driver-api:
create .def files for the nvcuda.dll that can be found from system32 directory (with for example mingw-w64 gendef tool)
create .a gcc library files (dlltool)
compile your program with gcc and link with libraries
compile your kernel on some OS that has same bitcount (linux compiled 64bit kernel worked on w64 .exe and 32b on w32 .exe)
I have not tested would it be possible (well in chroot at least it should be) to install both 32b and 64b nvcc to 64b os.
I would love to use the runtime api.
Some post say that one could use “–foreign” option to select compiler but in nvcc 2.3 it is not documented.
I also think that i saw (i cannot find it anymore!) a post about suggestion writing a wrapper for gcc that converts the input parameters from cl.exe to gcc but i have my doubts on that since the output of these two compilers are (??) not the same?
So, has anyone got runtime working in windows without using CL.exe?
I think that NVCC first runs the native compiler’s preprocessor to separate kernel code from CPU code; it must use the native compiler for that because (at least last time I looked) that’s the only way to assign the code to the proper sections inside object files. My own hobby projects use gcc and I primarily develop on windows, so I compromise by installing the free MSVC Express edition, let NVCC compile only device code, and use gcc for everything else. Note that if you use the driver API you can write C code to launch GPU kernels, that can compile with any compiler that can link with cuda.lib on windows. But the moment you start using keywords like global or device then you must have cl.exe or it won’t compile, even if it’s only device code that NVCC ends up compiling on its own and even if the output is just PTX.