CUDA: How to run cuda kernel functions not in SDK? Compilation issues

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

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”.

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.

May be. I use kernel wrappers from another libs and it doesnt seems to work without “extern C”. Probably I am doing something wrong.

:)

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.

MisterAnderson42
Thanks for the explanation.

If you just run on the windows , use the CUDA_VS_Wizard. It is developed by the OpenHeros.