kernel write to ram question

if I use the same pointer for input and output of the kernel does data corruption occur(sometime I see weird data result)?
for example

pt1 are for global ram

for(int n=0;n<4;n++{
kernel <<<…>>>(pt1,pt1)// input pt1, then result output to pt1
kerne2 <<<…>>>(pt1,pt1)
}

As long as these are in the same stream the first will finish before the second starts, and your data should be correct. Make sure that you don’t have an issue within your kernels where multiple threads are writing to the same location, since the results of that are undefined.

By the way, I’m assuming you wrote these kernels, so unless you intend on the input and output to be different, you should only need one parameter. If you did something like used the restrict keyword in your function definitions then the compiler will assume aliasing won’t happen, when in reality, it could based on how you’re using it.

ok thx, by restrict you mean something like constant ram or read only cache.

restrict tells the compiler that the pointers will not be aliased – that they won’t be pointing to overlapping memory. If you give it that keyword, and you end up aliasing, then it may produce incorrect results.