10 Replies Latest reply on Aug 19, 2008 3:41 AM by jski

    max function

    berathebrain

      I was wondering how could I find a maximum of an array(stream) using AMD StreamSDK.

      Thanks.

        • max function
          ryta1203
          There is a bitonic sort example that comes with the SDK.
          • max function
            Ceq
            Well, if he only needs the maximum value I think it's better to use a 'max reduction' than sorting the array.
            You have an example in the documentation folder "brook/docs", section 5.2.

            reduce void max_reduce(double a<>, reduce double b<> ) {
            if (a > b) return a;
            else return b;
            }
              • max function
                ryta1203
                Have you tried this out yet?

                1. I wouldn't recommend going by anything in any of the documentation that you haven't directly coded and seen work. There are too many instances of poor documentation in the current SDK release. There are too many things they say "work" and then don't work.

                2. Just looking at this kernel it has a return type of "void" but then "return"s a value. How does that work? For me, I get compiler errors when trying the kernel unmodified. The primary kernel must have a return type of "void" for the SDK but are reduction functions allowed a return type even though the kernel has a return type of "void"?

                3. If you can get this working I would love for you to post the code. Right now, I can't find a sampe that came with the SDK that works AS IS that would do what he/she wants except Bitonic Sort.

                Thanks. I know for sure the Bitonic Sort works though.

                Maybe the AMD gods can shed some light on this.
              • max function
                Ceq
                Thanks Ryta, indeed its a mistake, I copied it from the documentation without checking.
                However you can get it working easily this way:

                reduce void red(double a<>, reduce double b<>) {
                if(b < a) b = a;
                }

                I've tested this on my Radeon 4850 and seems to work properly.
                • max function
                  Ceq
                    • max function
                      ryta1203
                      Thanks, I coded my own example to test it using 4850, but it's nice for everyone to see the "whole" code in simple format, in case they have questions as to the size of the streams, passing what to the kernel and how, etc.
                    • max function
                      MicahVillmow
                      I've notified the owner of the doc and will attempt to get it fixed in the release.
                      • max function
                        jski

                        reduce void red( float value<>, reduce float result<> )
                        {
                           result = max( value, value );
                        }

                        This seems to work just fine.  ---jski