Hi guys…i’m new with cuda and i found it awesome!!! I’m developping some functions that should be called from another big C program. This functions are composed by “floating point operations” so i would like to execute them with cuda but the main program is too big so i can’t rewrite in cuda so i would call the cuda program from the main C program…is that possible???
At first I’ve create standard DLL project in Visual Studio and added a *.cu file
(In properties for this file “Command line” property was specified according to the Sarnath’s advise as well: nvcc -I"$(CUDA_INC_PATH)" -c -o $(ConfigurationName)\cuda_kernel.obj cuda_kernel.cu)
#include <stdio.h>
__global__ void my_intcopy(int *src, int *dest, int n)
{
int i=threadIdx.x;
dest[i] = src[i]*2+1;
}
__declspec(dllexport)
void my_intcopy_caller(int *Source, int *Dest, int n)
{
printf("INITIALIZING \n");
dim3 grid(1), block(n);
int *d_S, *d_D;
cudaMalloc((void**) &d_S, n*sizeof(int));
cudaMalloc((void**) &d_D, n*sizeof(int));
cudaMemcpy(d_S, Source, n*sizeof(int), cudaMemcpyHostToDevice);
printf("RUNNING \n");
my_intcopy<<<grid,block>>>(d_S, d_D, n);
Dest[7]=777;
printf("DONE \n");
cudaMemcpy(Dest, d_D, n*sizeof(int), cudaMemcpyDeviceToHost);
cudaThreadSynchronize();
}
And then I’ve created a console application with following code
I have to embed a few functions to a large project too, and in such an aproach it seems that I can use CUDA functions without any use of CUDA API in main project External Media . Is it true or some problems (like simultaneous acces to GPU) could appear?