0

Assume:

  • Windows 7 OS
  • Visual Studio Express 2010 SP1 just installed (and not modified with any *.rules or whatever)
  • CUDA SDK installed
  • GPU computing SDK installed
  • clean/empty environment variable set (so, we need to run vcvars and whatever..)

Correct answer provides then:

  • batch file contents
  • source (and project, if needed) file contents (including at least one .cu file to be acually utilized)

(Answering the inevitable "Why are not you.." comment)

The default setup does work not for me already, and my choice is to try the way this question is about.

(Extra ranty question)

Or is this not possible at all and we are doomed to explore GUI checkboxes brute-force-style?

Anyone? :)

mlvljr
  • 4,066
  • 8
  • 44
  • 61
  • 1
    I am not sure what it is you want. If you have VS 2010 installed and the CUDA *toolkit* installed (I presume that is what you mean by "CUDA SDK"), then you don't need anything else. You should be able to open the `Visual Studio Command Prompt` and compile with `nvcc` directly from the command prompt without requiring anything else – talonmies Mar 01 '12 at 15:55
  • @talonmies Ok, and VS command prompt will be effectively what I get after running `vsvars`, right? What about CUDA paths, includes, libs and dlls then? And where do I find a minimalistic set of `.cpp` and `.cu` files to compile into a working app? – mlvljr Mar 01 '12 at 16:18
  • nvcc already knows where to find all the CUDA headers and libraries required to compile a runnable application. As for where to find something to compile - use the search engine of your choice/one of the SDK examples/one of the hundreds of Stackoverflow questions/answers containing code. – talonmies Mar 01 '12 at 17:12
  • @talonmies ..for example->? (i.e. which ones contain both C++ and .cu code while being at the same time small and complete?) – mlvljr Mar 01 '12 at 17:52
  • 1
    All CUDA code is compiled with a C++ compiler, so even the ones that look like C will do. At random, how about the code in [this answer](http://stackoverflow.com/a/9250115/681865)? – talonmies Mar 01 '12 at 18:04
  • @talonmies So, I built the "template" project (see below). Now, the question is, how do I build a larger one (like "particles")? ;) – mlvljr Mar 02 '12 at 01:03

1 Answers1

2

Be my initial question requirements exotic or not, there turns out to be a rather simple way to suffice them, providing for:

  • no dependency on VS .*proj file and its intricacies
  • binary compatibility with cutil and shrutils utility librarires built with default GPU computing SDK setup (building them "by hand" (i.e. without a .*proj file), I think, will also impose no problems)
  • no implicit dependency on envirinment setup (only a few explicitly specified PATH components are needed (i.e. CUDA_PATH (or whatever it is -- CUDA_PATH_4_1?) and friends can go away from your global environment), see below)
  • no restriction on where the build catalog must reside (relative to CUDA toolkit or GPU SDK distribution catalogs or whatever)
  • no need to appropriately deploy (or even patch) VS project rules or MSBuild extensions and no dependency on installation order of VC10, NVIDA GPU SDK and CUDA toolkit (I believe, one of the latter actuallly deploys CUDA project rules to VC10 with rules and CUDA build extensions to MSBUILD)
  • (with all above) ability to correctly (I believe) build GPU computing SDK examples

To begin with, suppose we have NVIDIA "template" project's set of source files compiled completely from scratch without any VS .*proj files under:

  • Win7 x86
  • VS2010 SP1
  • CUDA toolkit 4.1
  • NVIDIA GPU SDK 4.1

The source files are under "C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.1\C\src\template" by default (there're others but they will not be needed):

  • template_gold.cpp
  • template.cu
  • template_kernel.cu

The batch commands to prepare the environment are (fix the first three to accomodate your setup, if does not match the default one):

set "vc10=C:\Program Files\Microsoft Visual Studio 10.0\vc"
set "cudatoolkit=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.1"
set "gpusdk=C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.1"

call "%vc10%\bin\vcvars32.bat"

set "path=%cudatoolkit%\bin\;%path%"
set "path=%gpusdk%\C\common\lib\win32;%path%"

The batch file (I called mine cuda_build.bat) to build is (assuming you will need both cutil and shrutil which are heavily used by SDK samples):

nvcc --verbose --keep --cl-version 2010 --use-local-env ^
 -Xcompiler "/EHsc /nologo /Od /Zi /MT" ^
 -DWIN32 -D_MBCS ^
 -L"%cudatoolkit%\lib\win32" ^
 -L"%gpusdk%\C\common\lib\win32" ^
 -L"%gpusdk%\shared\lib\Win32" ^
 -I"%cudatoolkit%\include" ^
 -I"%gpusdk%\C\common\inc" -I"%gpusdk%\shared\inc" ^
 -I. ^
 -lcuda  -lcudart -lcufft ^
 -lcutil32 -lshrutils32 ^
 -lopengl32 -lfreeglut -lglew32 ^
 -lkernel32 -luser32 -lgdi32 ^
 %*

To build, pass the list of .cpp and .cu files to the batch file above:

cuda_build.bat template_gold.cpp template.cu

To build more or less silently and not retain any intermediate files, remove --verbose --keep keys from cuda_build.bat.

The resulting a.exe can be run as long as the paths are set with the first portions of commands in this post (i.e., any necessary .dll will be already on path).

Note (if you are interested), that the minimum environment to start with is merely (in shell commands, change apporpriately according to your setup), or even smaller (I have not tried, but linker fails at least in absence of temp dirs):

set Path=C:\Windows\System32

set SystemDrive=C:
set SystemRoot=C:\Windows
set TEMP=C:\Users\A90B~1\AppData\Local\Temp
set TMP=C:\Users\A90B~1\AppData\Local\Temp

P.S. To build a larger example, one should follow similair steps, but adding (or copying) source files like rendercheck_gl.cpp if referenced in project to the list of source files to build. I've tested it with nbody, fluidsGL, simpleGL and oceanFFT example projects, and it works. (particle example breaks on thrust library header inclusion -- but compiling via .*proj file fails the same way -- looks (to me) like some template magic is incompatible with VC10).

Hope, anyone interested in the topic and disliking MS IDE configuration mess as much as I do, will like this. :)

mlvljr
  • 4,066
  • 8
  • 44
  • 61
  • 1
    Don't use cutil in your own programs. – Eric Mar 02 '12 at 09:57
  • @Eric Thanks, I've already got that hint. The thing is, cutil (and shrutils) are used in NVIDIA examples, so if one starts with them, he has no choice but to use them to build something working. – mlvljr Mar 02 '12 at 10:17