cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

traits
Journeyman III

A bug about cosine function?

cosine bug

Hi All,

I found that the result of cos(1611.625) is incorrect. It's 1.0 on GPU, whereas it's -0.9893 on CPU.

My box is HD4870, AMD Stream SDK 1.3 and Ubuntu amd64.

Is it a bug?

Thanks

Traits

Tags (1)
0 Likes
6 Replies
gaurav_garg
Adept I

A bug about cosine function?

Try sending 1611.625 as a constant parameter to kernel so that its value is not determined at compile time. It will help us know if its an issue with compiler or hadware floating point accuracy.

0 Likes
traits
Journeyman III

A bug about cosine function?

The test code:

 

kernel void cosin_testcase(float x<>, out float y<>)
{   
    y=cos(x);
}


int main()
{
   
    int length=4;
          
    float * x, *y;
   
    int i=0;
   
    x=(float*) malloc(sizeof(float) *length);
   
    y=(float*) malloc(sizeof(float) *length);
   

    for(i=0;i<length;i++){
       
        x [ i ]=1611.625f;
       
        y [ i ]=0.0f;
       
    }
   

    {
       
        float x_stream<length>;
       
        float y_stream<length>;
       

        x_stream.read(x);
       
        cosin_testcase(x_stream, y_stream);
       
        y_stream.write(y);
       
    }
   
    for(i=0;i<length;i++){
       
        printf("%lf\n",y [ i ] );
       
    }
   
    free(x);
   
    free(y);
   
    return 0;
   
}

0 Likes
gaurav_garg
Adept I

A bug about cosine function?

hmmm.....seems an issue with floating point accuracy.

Try 1611.625 - 256 * 2 *PI = 2.482f and see if it works.

0 Likes
traits
Journeyman III

A bug about cosine function?

Originally posted by: gaurav.garg hmmm.....seems an issue with floating point accuracy.

 

Try 1611.625 - 256 * 2 *PI = 2.482f and see if it works.

 

I try 1611.625 - 256 * 2 *PI =3.12956f. The result is correct (-0.999928).

0 Likes
gaurav_garg
Adept I

A bug about cosine function?

Hardware implementation of sin/cos requires input value to be within -100*PI to 100*PI.

nberger
Adept I

A bug about cosine function?

Is this documented somewhere? What about the other transcendentals?