4 Replies Latest reply on Oct 10, 2008 11:43 PM by udeepta@amd

    Stream domains implementation in Brook+ ??

    jean-claude
      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
        • Stream domains implementation in Brook+ ??
          the729

          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.

            • Stream domains implementation in Brook+ ??
              jean-claude

              Hi the729,

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

              Could you provide a short example?

              Thanks

                • Stream domains implementation in Brook+ ??
                  the729

                  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.

              • Stream domains implementation in Brook+ ??
                udeepta@amd

                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