7 Replies Latest reply on Aug 21, 2009 12:34 PM by riza.guntur

    Conditional reduction on vector, How to?[SOLVED]

    riza.guntur
      The cause is wrong stream size than expected

      I want to do conditional reduction on vector like the following but I get incorrect result, is there any other way to do it?

      reduce void cond_vec_red(float4 a, reduce float4 b){

      if(a.x < b.x)

      b.x = a.x

      if(a.y< b.y)

      b.y = a.y

      if(a.y< b.y)

      b.y = a.y

      if(a.y< b.y)

      b.y = a.y

      if(a.y < b.y)

      b.y = a.y

      }

        • Conditional reduction on vector, How to?
          gaurav.garg

          The kernel looks correct. Can you post your runtime code as well?

            • Conditional reduction on vector, How to?
              riza.guntur

              I'm sorry, the kernel should have declaration like this

              reduce void cond_vec_red(float4 a<>, reduce float4 b<>)

              The runtime code is reduction from sizes {xdim,ydim} to {xdim,1}

                • Conditional reduction on vector, How to?
                  riza.guntur

                  After running the code again after 2 months, it runs well.

                  Maybe before this I use wrong stream size.

                    • Conditional reduction on vector, How to?
                      Raistmer
                      Do I understand right that this kernel should find min element for each of xdim*4 float 1D arrays?
                      If yes, what initial value will be in b.x (and so on) for comparison?
                        • Conditional reduction on vector, How to?[SOLVED]
                          gaurav.garg

                          An element from the array is chosen for the initial value of b. Reduction is a multi-pass and different array elements are chosen for initialization in each pass.

                            • Conditional reduction on vector, How to?[SOLVED]
                              riza.guntur

                               

                              Originally posted by: gaurav.garg An element from the array is chosen for the initial value of b. Reduction is a multi-pass and different array elements are chosen for initialization in each pass.

                              Thanks for your information. This is crucial. I always wonder why I don't need to reinitialize b when using reduction kernel, yet it still produce the correct result.

                            • Conditional reduction on vector, How to?
                              riza.guntur

                               

                              Originally posted by: Raistmer Do I understand right that this kernel should find min element for each of xdim*4 float 1D arrays? If yes, what initial value will be in b.x (and so on) for comparison?


                              Yes. They will be height of crossing line between two triangle where the top has height 1.

                              Oh... I remember why I am not using this reduction kernel and stay with my current approach (those help I posted before). Reduction can't take more than one input and one output 

                              Help...........................

                              I need

                              reduce void cond_vec_red(float4 a<>, float y<>, float z<>, reduce float4 b<>, reduce float4 yn<>, reduce float4 zn<>{

                              if(a.x < b.x){

                              b.x = a.x;

                              yn.x = y.x;

                              zn.x = z.x;

                              }

                              if(a.y< b.y){

                              b.y = a.y;

                              yn.y= y.y;

                              zn.y = z.y;

                              }

                              if(a.z< b.z){

                              b.z = a.z;

                              yn.z = y.z;

                              zn.z = z.z;

                              }

                              if(a.w< b.w){

                              b.w = a.w;

                              yn.w = y.w;

                              zn.w= z.w;

                              }

                              }

                              with my current approach, input with float4.x is height, float4.y is target, float4.z is another target (hard to explain it here), float4.z don't need to be filled (but I fill it with 0.0f)

                              I want to separate those into three separate streams, BUT if I do reduction like: reduce void cond_vec_red(float4 a<>, reduce float4 b<> then the target information will be loss since a filled with height values, no target information and struct can't be used inside reduction..................

                              So how to?