cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

Peterp
Journeyman III

brook::Stream::domain how to use?

Hi,

how do i use the domain function correct? I want to call the kernel for every first element in the rows. This is my kernel:

kernel void callKernel(float a[][], out float b[][])

{

int2 index = instance().xy;

b[index.y][index.x] = b[index.y][index.x];

 

}

And this the c++ code, i'm using s1.domain(int2(0,0),int2(0,MAX) to set the domain but in the end the values are not correct.

float *zahlen = new float[MAX*MAX];
 float *ausgabe = new float[MAX*MAX];
 for(int i=0;i  for(int j=0;j   zahlen[(i*MAX)+j] = 1.0f;

 unsigned int dim[] = { MAX, MAX };
 ::brook::Streams1(2,dim);
 s1.read(zahlen);
 ::brook::Streamsout(2,dim);
 sout.read(ausgabe);
 callKernel(s1.domain(int2(0,0),int2(0,MAX)),sout);
 sout.write(ausgabe);





0 Likes
5 Replies
gaurav_garg
Adept I

I am not exactly sure what you are trying to do. If you want to use only first column of input s1, you need to use s1.domain(int2(0,0),int2(1,MAX))

If you want to set domain of execution (shape of kernel instances), you need to use domainOffset and domainSize methods on kernel call.

0 Likes

Hi,

i only want so use the first column of input s1, i changed it to s1.domain(int2(0,0),int2(1,MAX)) but i still get the wrong results. In the output stream all values are set to the input values.

0 Likes

Let me know if I understand your problem correctly. You want to copy first column of input matrix to first column of output matrix. You can do something like this-

//BR file

kernel void copy(float a<>, out float b<>

{

    b = a;

}

//CPP file

copy.domainOffset(uint4(0,0,0,0));

copy.domainSize(uint4(1,MAX,0,0));

0 Likes

Thank you, this is exactly what i want to do. When i set the domainOffset and the domainSize, can i still access any element in the gather/scatter-streams or only the elements for which i start the kernel? Because i only need to run the kernel for the first row but maybe i need some data from the second row. 

0 Likes

Yes, you can access other values using gather/scatter streams. Remember instance() will have values only for the domain that you have specified in kernel call.

Also, it is recommended to avoid use of scatter streams if possible as it is much slower than regular output stream.

0 Likes