shong9
November 18, 2007, 7:52pm
1
CUDA: How to run cuda kernel functions not in SDK directory?
I am currently trying to modify the program (already implemented in C++, and running properly on CPU). I am planning to create a separate CUDA kernel function as a different file to run that small portion of the program on GPU.
However, I would like to hear some recommendations from what .h files should I include ? and compilation issues that might arise.
Thank you
serge
November 19, 2007, 11:11am
2
I created a separate project in VS 2005 for all my cuda files and applied the following build rule to it:
<?xml version="1.0" encoding="utf-8"?>
<VisualStudioToolFile
Name="CUDA rules"
Version="8.00"
>
<Rules>
<CustomBuildRule
Name="CUDA compiler"
DisplayName="CUDA compiler"
CommandLine="$(CUDA_BIN_PATH)\nvcc.exe -ccbin "$(VCInstallDir)bin" [emulation] -c [definitions] -DWIN32 -D_CONSOLE -D_MBCS -Xcompiler /EHsc,/W3,/nologo,/Wp64,[Optimization],/Zi,[RTC],[MT] -I"$(CUDA_INC_PATH)" -I./ -I"$(NVSDKCUDA_ROOT)"/common/inc -o $(ConfigurationName)\$(InputName).obj $(InputName).cu"
Outputs="$(ConfigurationName)\$(InputName).obj"
FileExtensions="*.cu"
ExecutionDescription="$(InputFileName)"
>
<Properties>
<BooleanProperty
Name="emulation"
DisplayName="Enable Emulation Mode"
Category="Default"
Description="Compiles the code to run in emulation mode."
Switch="-deviceemu"
DefaultValue="false"
/>
<BooleanProperty
Name="fastmath"
DisplayName="Use Fast Math"
Category="Default"
Description="Make use of the fast math library."
Switch="-use_fast_math"
DefaultValue="false"
/>
<BooleanProperty
Name="RTC"
DisplayName="Enable RTC"
Category="Default"
Description="RTC"
Switch="/RTC1"
DefaultValue="false"
/>
<StringProperty
Name="optimization"
DisplayName="Optimization Level"
Description="Sets the optimization level, where level = /Od, /O1, /O2, or /O3."
Switch="[value]"
/>
<StringProperty
Name="MT"
DisplayName="MT usage"
Category="Default"
Description="/MT or /MTd for debug"
Switch="[value]"
/>
<StringProperty
Name="definitions"
DisplayName="Preprocessor Definitions"
Description="Defines a text macro with the given name. (-D[symbol])"
Switch="-D_[value]"
Delimited="true"
Inheritable="true"
/>
<StringProperty
Name="includes"
DisplayName="Include Paths"
Description="Sets path for include file. A maximum of 10 -I options is allowed. (-I [path])"
Switch="-I"[value]""
Delimited="true"
Inheritable="true"
DefaultValue="$(CUDA_INC_PATH), $(VCInstallDir)\include, $(VCInstallDir)\PlatformSDK\include"
/>
</Properties>
</CustomBuildRule>
</Rules>
</VisualStudioToolFile>
AFAIK each “.cu” file should include <cuda_runtime.h> and <cutil.h>.
Functions which are located in “.cu” - files and called from non-CUDA code should be declared as extern “C” .
wumpus
November 19, 2007, 11:59am
3
You don’t strictly need to include <cutil.h>, this includes some common functions used by the NVidia demos for loading textures, doing timings and so on. Useful, but not neccesary. Only cuda_runtime.h and maybe cuda.h you really need.
Isn’t that only the case if you want to use CU or C++ functions from C? From C++ you probably don’t need anything special apart from wrapping your kernel call in a function.
It MUST be
CommandLine=""$(CUDA_BIN_PATH)\nvcc.exe" ....
I hate “please path without spaces” folks.
serge
November 20, 2007, 10:25am
5
Isn’t that only the case if you want to use CU or C++ functions from C? From C++ you probably don’t need anything special apart from wrapping your kernel call in a function.
[snapback]281449[/snapback]
May be. I use kernel wrappers from another libs and it doesnt seems to work without “extern C”. Probably I am doing something wrong.
It MUST be
CommandLine=""$(CUDA_BIN_PATH)\nvcc.exe" ....
I hate “please path without spaces” folks.
[snapback]281925[/snapback]
:)
Thank you. I missed it.
CUDA 1.0 mangles names as C, so you NEED to declare function definitions as extern “C” in the header file so that C++ can call them. CUDA 1.1 now mangles names as c++ by default, even if you aren’t using the c++ compilation mode for .cu files.
serge
November 22, 2007, 2:24pm
7
MisterAnderson42
Thanks for the explanation.
CUDA: How to run cuda kernel functions not in SDK directory?
I am currently trying to modify the program (already implemented in C++, and running properly on CPU). I am planning to create a separate CUDA kernel function as a different file to run that small portion of the program on GPU.
However, I would like to hear some recommendations from what .h files should I include ? and compilation issues that might arise.
Thank you
If you just run on the windows , use the CUDA_VS_Wizard. It is developed by the OpenHeros.