cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

david_aiken
Journeyman III

pointer to float3 can't reference members

hi..

The following kernel code:

    __global float3 *pos = (__global float3*)(bufPnts + ndx * simData->stride);

    int gz = (pos->z - simData->min.z) * simData->delta.z ;

produces an error:
error: expression must have pointer-to-struct-or-union type
      int gz = (pos->z - simData->min.z) * simData->delta.z ;
It seems like this should be allowed.
It doesn't mind:
    __global float3 *pos2 = (__global float3*)(bufPnts);
    int q = (*pos2).x;


0 Likes
7 Replies

float3 is not a valid OpenCL data type and the vector types are not structures so the (->) operator cannot be used on them as they do not have fields to dereference. In section 6.1.7 it specifies the way to access the components of a vector.
0 Likes

Perhaps float3 would be a useful type 😆. Section 6.1.7 (i'm using doc rev 29) refers to indices "1...4" and the AMD compiler complains if you try to define a struct with that name so it seems like it might be. I'll work around it.. thanks.

 

0 Likes

Yes, but then it iterates over the values that are valid after that and the valid components for each type. Also, if you read 6.1.4, in the second sentence, it states that all vector lengths of the vector data types that aren't, 2, 4, 8 and 16 are reserved.
0 Likes

ok.. powers of two are certainly nice.

Out of curiosity, do you know when it makes sense to use a float4 vs, say, float[4]? Probably a FAQ isgust;.

0 Likes

Originally posted by: david_aiken ok.. powers of two are certainly nice.

 

Out of curiosity, do you know when it makes sense to use a float4 vs, say, float[4]? Probably a FAQ isgust;.

 

float4 et al are different from normal arrays because they use SSE instructions if present. If you have a cpu that supports these SSE instructions float4 will make the calculations faster. Not sure if it is of use (speed wise) on the gpu as well.

0 Likes

yes it is wise. i run two kernels. one have float parameters and other float4. first kernel have 200GPLOPS and second 800GPLOPS.

0 Likes

david_aiken,
If you want dynamic indexing, use float[4], otherwise float4.
0 Likes