casting float2 to float

Hi everyone

Being a newbie in CUDA, and in C/C++ for that matter, i would like to ask this question:

Let’s say i have a float2 array G of size N, and a procedure

setValuesToZero(float *tab, int size)

that set each component of a float array to zero. Is there a way to use my function on either the “.x” components or the “.y” components of G?

for example (simbolically):

N = 3;

G = [ (1,1) (2,2) (3,3) ];

setValuesToZero( '.x components of G' ,3);

//and now if we 'look at' G, it would be

G = [ (0,1) (0,2) (0,3) ];

I don’t know if this is really clear, i tried to do my best :)

Thanks in advance anyway

No. You would need a zeroing routing that takes element size and stride as additional parameters, because the .x or .y components are not contiguous in memory.

I don’t think you can do it with that function, can you not just write another one? you could just write the cuda kernel that accepts an array of float2, a size of the array and a parameter that says if you want to use x or y components. Then in the kernel you just make it check whether you want x or y then only update those components.


settozero(float2 data, int size, bool xory){


if (xory){

data[i].x = 0;


else {

data[i].y = 0;


Wow that was fast :)

Thanks for the reply. Yeah actually the parameter solution is i think the best way to do so. I was considering it but didn’t know whether or not there was another ‘more elegant’ way to do that.

Thanks again to both of you