cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

BarnacleJunior
Journeyman III

Undefined behavior when indexing vector components

Both the nvidia and ATI drivers compile this code without warning, but both exhibit apparently undefined behavior..

In D3D you can index a vector component with [].  eg:

uint4 foo; foo[2] = 3;  // now foo.z is 3.

The OpenCL compilers compile that, but they don't work!

eg


    // Load in a and b terms
    uint4 a, b;
   
    /*
    for(int i = 0; i < 4; ++i) {
        a = pass1_values[leftIndex + i];
        b
= pass1_values[rightIndex + i];
    }
    */
    a.x = pass1_values[leftIndex + 0];
    a.y = pass1_values[leftIndex + 1];
    a.z = pass1_values[leftIndex + 2];
    a.w = pass1_values[leftIndex + 3];
    b.x = pass1_values[rightIndex + 0];
    b.y = pass1_values[rightIndex + 1];
    b.z = pass1_values[rightIndex + 2];
    b.w = pass1_values[rightIndex + 3];

If I uncomment the commented part, the behavior is undefined.  Is this a legal kernel operation? If not, the compiler should error.

 

.sean

 

0 Likes
1 Reply

Indexing into a vector is not part of OpenCL. Section 6.1.7, Vector Components specifies how to access the components of the vector correctly. I'll report this so that the compiler emits a proper error message.
0 Likes