cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

jean-claude
Journeyman III

Stream domains implementation in Brook+ ??

How to access/refer to substreams

Hi ,

I'm looking for a way to access to a stream's sub-streams (1D and 2D) in order to

consider them as independant streams for further processing.

simple example:

float a<100,100>;

// then having  b as the sub-stream of 10 elements a<20,30>  for further processing.

Googling on the net, I found that Brook domain stream operator should be highly relevant for this purpose as described here :

" The domain operator is meant to be applied to streams as they are being passed to a kernel function, as in:

kernel void copy( float input<>, out float output<> ) { output = input; }
...
float a<100>;
float b<20>;
copy( b.domain( 5, 15 ), a.domain( 20, 30 ) ); // a[i+20] = b[i+5] for 0 <= i < 10

Domains of streams can be passed to kernel functions as input stream arguments, output stream arguments and gather stream arguments. The operator can be applied to 1, 2, 3, and 4 dimensional streams, using int, int2, int3, and int4 input arguments.

While domains were originally intended to only work at a kernel call site, they can actually be copied to other stream references (often using the brook C++ runtime API) to create persistent 'views' of a stream:

brook::stream a = brook::stream::create<float>( 100 );
brook::stream b = a.domain( 20, 30 );
...
copy( data, b ); // writes to both b and a
"


The issue is that in ATI Brook+ this feature seems to be left unimplemented.
The compiler is not dealing with it...


Anyway digging into Brook runtime interface (brt.hpp) , it does appear that "domain" is part of Brook stream class.

Is there a practical way get access to it and use it ????


Thanks

Jean-Claude
0 Likes
4 Replies
the729
Journeyman III

You can try putting only the kernel in .br files and all the other codes in .cpp file.

Also, with "using namespace brook;", working with brook stream objects can be very easy in .cpp file.

0 Likes

Hi the729,

I'm not sure I get your point. What do you mean exactly?

Could you provide a short example?

Thanks

0 Likes

for my simple increase-number example:

#include <stdio.h>

kernel void increase(float a<>, out float c<>
{
    c = a+1;
}

int main(int argc, char** argv)
{
  int i, j;
  float input_a[4] = {1, 2, 3, 4};
  float c<4>;
  float a<4>;

  streamRead(a, input_a);
  increase(a, c);
  streamWrite(c, input_a);

  return 0;
}

Instead of writing all the codes in one .br file, you can write them in 2 seperate files.

A .br file for the kernel only:

kernel void increase(float a<>, out float c<>
{
    c = a+1;
}

And a main cpp file:

#include "brook/brook.hpp"
#include <stdio.h>
using namespace brook;

void  increase (stream a, stream c);

int main(int argc, char** argv)
{
  int i, j;
  float input_a[4] = {1, 2, 3, 4};
  stream c(getStreamType((float *)0), 4 ,-1);
  stream a(getStreamType((float *)0), 4 ,-1);

//here you can do things like stream b=c.domain(...);

  streamRead(a, input_a);
  increase(a, c);
  streamWrite(c, input_a);

  return 0;
}

This file is not processed by brcc.

Remember to include brook/brook.hpp and to declare the kernel function in the main cpp file.

0 Likes
udeepta
Staff

Not sure what you mean. It used to work the last time I tried it:

copy( b.domain( 5, 15 ), a.domain( 20, 30 ) ); // a[i+20] = b[i+5] for 0 <= i < 10

0 Likes