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. :)