problem with pointer arithmetic on device

Hi,

debugging a kernel I recognized that [font=“Courier New”]max_data[/font] and [font=“Courier New”]max_data2[/font] from the following

snippet are different pointers.

[codebox] extern shared float sdata;

float * max_data = &sdata[N];

float * max_data2 = sdata + N * sizeof(float);[/codebox]

in this case [font=“Courier New”]max_data2[/font] is the same as [font=“Courier New”]&sdata[4*N][/font] which I do not understand.

I tried to use google to find some answers concerning “cuda pointer arithmetics”, but

found nothing usable.

Greetings, Uwe

You don’t need to do * sizeof(float) - this is actually equivalent to doing

float * max_data2 = &sdata[N * sizeof(float)];

if I’m not mistaken

The pointer type enforces proper arithmetic, incrementing only by meaningful amounts - if you really wanted to advance the pointer by one byte at a time (instead of one float at a time), you’d have to cast it to char*

Oh holy s**t, this is something I should have knowm myself. Debugging for some hours made my mind dump.

Thanks & Greetings,

Uwe