cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

griffin2000
Journeyman III

Assigning FLT_MAX to a float4 has no affect...

Assigning FLT_MAX or MAXFLOAT to a float4 variable has no effect.

e.g.:

   myBuffer->a=(float4)(1,2,3,4);

   myBuffer->a=(float4)(FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX);

Will result in no errors, but the value of "a" in the buffer will (1,2,3,4).

Is this another optional feature that needs to be supported (and can be tested for with the appropriate call to clGetDeviceInfo), or is this a problem with the implementation ?

 

EDIT: Changed my typo, those were meant to be float4s

 

 

 

0 Likes
7 Replies
omkaranathan
Adept I

The code works fine for me. There is something else wrong at your end.

I am assuming 'a' is a float4 variable. Try using float4 instead of float, while assigning values to a float4 variable.

0 Likes

 

 

Sorry that was typo.  I meant to use float4:

   myBuffer->a=(float4)(1,2,3,4);

   myBuffer->a=(float4)(FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX);

 

Where type definitions are something like this:

struct MyStruct

{

  float4 a;

  float4 b;

  float4 c;


}

__global MyStruct *myBuffer;

When I map myBuffer back to the CPU and inspect the value they are the original ones, not MAX_FLT.

 

 

0 Likes

Assigning FLT_MAX is giving correct results for me. Could you post your source code(host & kernel code) so that I can try and reproduce your problem?

0 Likes

Hmmm I can't repro in a simple test case either.  But in our main codebase we definitely have an example where this will work:

myBuffer->a=(float4)(10000000.0f, 10000000.0f, 10000000.0f, 10000000.0f);

But this will have no effect:

myBuffer->a=(float4)(FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX);


I have tested multiple times, and the first case always works, and second one always fails.  I can't imagine anything we could be doing wrong that could manifest in this way (we don't do anything on that buffer after that line of code).

 

 

0 Likes

Originally posted by: griffin2000 Hmmm I can't repro in a simple test case either.  But in our main codebase we definitely have an example where this will work:

 

Does it work for you in a simple test case?

 

 

0 Likes

Does it work for you in a simple test case?

Yeah, I tried to replicate what was happening as closely as possible, but it works fine in my testcase.  If I can narrow down exactly whats happening.in our actual code I will post more details.

0 Likes

griffin2000,
Most likely you have a race condition on the write to myBuffer between two threads writing out FLT_MAX and 1.0f. Does it work when you only launch 1 thread?
0 Likes