Can we do any simple calculation without memory allocation?

Can i send a call to kernel from my c code to do some normal mathematical operation without memory allocation.Means i want to just send a normal function call to kernel as we do in c/c++.
here is an example…

c code:

float xmax=100;
float xmin=200;
float ymax=300;
float ymin=400;
double dx,dy,dmax;
float xmid,ymid;

kernel_test<<<1,1>>>(a,b,c,d,e);

Cuda code

global void
kernel_add(double dx,double dy,double dmax,float xmid,float ymid,float xmax,float xmin,float ymax,float ymin)
{
dx = xmax - xmin;
dy = ymax - ymin;
dmax = (dx > dy) ? dx : dy;
xmid = (xmax + xmin) / 2.0;
ymid = (ymax + ymin) / 2.0;
}

But i m not getting the required result when i make this kernel call.Can anyone please help me with this?

Thanks in advance!!!

Kernels do NOT return any values. (its always a VOID function)

How do u read the results back from the kernel?

Arguments to kernel dont get updated.

thanks for the reply but to allocate memory for such a small mathematical operation it takes lots of time
Is it possible to do it if i make the variable whose values i want as pointer…
Can i get the answer then?I just want to bypass the memory allocation step…Can u please tell the CUDA part of the code for the above code only!!!

The first memory allocation or CUDA Library call will always take a LOTT of time – because of initialization.

You may want to consider “zero-copy” method. but that would need pinned memory allocation anyway…

You cant escape the initial overhead of some 20 ms or so…

No point in using GPUs for tasks that will take only a few milliseconds on CPU.