First you need a .cu file with your kernel (the function must be executed on the GPU). Let there be a file mykernel.cu:
extern "C" __global__ void fooFunction(float4* data) {
This needs to be compiled into a .cubin file using the nvcc compiler. So that the compiler knows about the Visual C ++ compiler, you need to call it from the Visual Studio command line:
nvcc mykernel.cu --cubin
This creates the mykernel.cubin file in the same directory.
Then in C # code you can load this binary module and execute the kernel. In the higher-level GASS.CUDA API, it might look like this:
using GASS.CUDA; // ... CUDA cuda = new CUDA(true); // select first available device (GPU) cuda.CreateContext(0); // load binary kernel module (eg. relative to from bin/Debug/) CUmodule module = cuda.LoadModule("../../mykernel.cubin"); // select function from the module CUfunction function = cuda.GetModuleFunction(module, "fooFunction"); // execute the function fooFunction() on a GPU cuda.Launch(function);
What is it!
The nvcc compiler should be called as an assembly action better than calling it manually. If anyone knows how to do this, let us know.
Bohumir zamecnik
source share