cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

traits
Journeyman III

The problem about gather the double struct

When I gather the double struct in kernel, I encountered the problem. Here is the code:

#include <brook/brt.hpp>
typedef struct test
{
    double a;
    double b;
}doubletest;


kernel void gather_double_struct(doubletest x[], out double y<>)
 {
    doubletest test=x[1];
    y=test.a;
 }

int main()
{
    int length=4;
    int size=length/2;
    double * x, *y;
    int i=0;
    x=(double*) malloc(sizeof(double) *length);
    y=(double*) malloc(sizeof(double) *length);

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

    {
        doubletest x_stream<size>;
        double y_stream<length>;

        streamRead(x_stream,x);
        gather_double_struct(x_stream, y_stream);
        streamWrite(y_stream, y);
    }
    for(i=0;i<length;i++){
        printf("%lf\n",y [ i ] );
    }
    free(x);
    free(y);
    return 0;
}

The expected output:

2.000000
2.000000
2.000000
2.000000

But, I got this:

0.000000
0.000000
0.000000
0.000000

After setting BRT_RUNTIME=cpu,  I got the right output. If I set BRT_RUNTIME=cal, it will be wrong.

0 Likes
10 Replies
ryta1203
Journeyman III

x = double
x_stream = doubletest

streamRead(x_stream, x)?? Is this allowed? I would think that if this was the problem then you wouldn't get correct results with emu mode either, but there's no telling with this thing.

Also, I always have a problem when trying to declare and initiliaze a variable in the same line in a kernel with Brook+.

I agree that it seems emulation mode needs to be fixed so that code that runs in emulation mode will run on the GPU, otherwise, what is the point of emulation mode to begin with, especially since even in emulation mode you cannot put "printf() and such" in the kernel. Emulation mode is almost pointless at this point in the SDK.
0 Likes

Originally posted by: ryta1203 x = double x_stream = doubletest streamRead(x_stream, x)?? Is this allowed? I would think that if this was the problem then you wouldn't get correct results with emu mode either, but there's no telling with this thing. Also, I always have a problem when trying to declare and initiliaze a variable in the same line in a kernel with Brook+. I agree that it seems emulation mode needs to be fixed so that code that runs in emulation mode will run on the GPU, otherwise, what is the point of emulation mode to begin with, especially since even in emulation mode you cannot put "printf() and such" in the kernel. Emulation mode is almost pointless at this point in the SDK.


 

It's right in emulation mode. You can try the code and verify it.

I just tested using the same type in streamRead. It outputs the same wrong result in CAL.

0 Likes

I believe that it works in emu mode, I'm just saying the emu mode needs to be redone or made better.

I don't see what you did in the sample "tests/struct". There the streamRead is from a Pairs type to a Pairs type. It looks like you are reading from a double type to a doubletest type.
0 Likes

Originally posted by: ryta1203 I believe that it works in emu mode, I'm just saying the emu mode needs to be redone or made better. I don't see what you did in the sample "tests/struct". There the streamRead is from a Pairs type to a Pairs type. It looks like you are reading from a double type to a doubletest type.


Yes, I see. 

I just tested using the same type in streamRead. It outputs the same wrong result in CAL.

0 Likes

If I change double to float like this:

typedef struct testfloat
{
    float a;
    float b;
}floattest;

The result is correct in both.

0 Likes

Yes, I just tested this myself on a 4850. It appears that you are correct. AMD needs to look into this, maybe you should email this to streamdeveloper@amd.com and mention this might be a bug.

I also test float and double and got correct results with float and bad results for double.

EDIT: It seems to work fine if you do a 1 to 1 mapping (NON-GATHER) for doubles. Just an FYI, I know that doesn't help you though.
0 Likes

Originally posted by: ryta1203 Yes, I just tested this myself on a 4850. It appears that you are correct. AMD needs to look into this, maybe you should email this to streamdeveloper@amd.com and mention this might be a bug. I also test float and double and got correct results with float and bad results for double.


Yes, I got the same result.

0 Likes
traits
Journeyman III

I have test it on AMD Stream Computing SDK v1.2-beta and HD 4870, and it's failure too.

0 Likes

traits, please send a simple test case to streamdeveloper@amd.com so that we can have this tested and fixed for our next release.
0 Likes

I have sent the test case.

0 Likes