traits

The problem about gather the double struct

Discussion created by traits on Sep 3, 2008
Latest reply on Nov 10, 2008 by traits

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.

Outcomes