foofel

reusing variables

Discussion created by foofel on Jun 25, 2010
Latest reply on Jul 2, 2010 by foofel

Hi, i am currently starting to experiment with opencl and found a (for me) strange behavior.  If i try to jump through a 1D Buffer, and reuse variables, i get wrong values.

An Example:

__global uint *root = octree;
uint nodeSize = GetNodeSize(root);
uint nodeNumber = 0;

/* get L1 child node */
uint childOffset = root[0];
__global uint *node = root + (childOffset * nodeSize) + (nodeNumber * nodeSize);

/* get L2 child node */
childOffset = node[0];
*node = root + (childOffset * nodeSize) + (nodeNumber * nodeSize);

 

If i try to read the value from childOffset after the last line (*node = root + ...), its 255. if i comment the last line out, it is 9 as expected (in my memory layout). But how is the last line changing a value in childOffset? (Btw. why do i get a build error for // comments in kernels? :/)

 

If I use different variable names  names for each "step" i also get the right result (just continued for the next levels)

uint childOffset3 = node2[0];
  __global uint *node3 = root + (childOffset3 * nodeSize) + (nodeNumber * nodeSize);

  /* get L4 child node */ 
uint childOffset4 = node3[0];
__global uint *node4 = root + (childOffset4 * nodeSize) + (nodeNumber * nodeSize);

 If i now access childOffset1 - childOffset4 i have the right values. Any idead of what kind of stupid error i did?

 

Thanks

 

 

Outcomes