5 Replies Latest reply on Nov 17, 2009 11:57 AM by gaurav.garg

    Vector Dot Product

    dinaharchery

      I have been trying to create a vector dot product using the GPU with Brook+ and have been getting strange results (should be 4 but I get 7.012).  This dot-product is being performed on a vector with itself. Can anyone tell me why this is?

      The y[] consists of {1.0f, 1.0f, 1.0f, 1.0f}

      kernel void multiply(float a<>, float b<>, out float c<>) { c = a*b; } reduce void constSum(float x<>, reduce float result){ result += x; } unsigned int m = 4; float dp = 0.0f; Stream<float> yStrm(1, &m); Stream<float> tmpStrm(1, &m); yStrm.read(y); // Kernel Calls: multiply(r0Strm, r0Strm, tmpStrm); constSum(tmpStrm, dp); std::cout << "GPU Residual = " << dp << std::endl;

        • Vector Dot Product
          gaurav.garg

          Did you check errorLog on your tmpStream? Does CPU backend gives correct result.

          As a side note, you can directly use intrinsic function dot(x, y) to calculate vector dot product.

          kernel void test(float4 a<>, float4 b<>, out float c<>

          {

              c = dot(a, b);

          }

            • Vector Dot Product
              dinaharchery

              Thank you for replying.

              I checked the errorLog of 'tmpStrm' and 'yStrm' there were no errors in either of the two kernels.

              I also just noticed some mis-typing on my original code and am reposting the corrected code.

              kernel void multiply(float a<>, float b<>, out float c<>) { c = a*b; } reduce void constSum(float x<>, reduce float result){ result += x; } unsigned int m = 4; float dp = 0.0f; Stream<float> yStrm(1, &m); Stream<float> tmpStrm(1, &m); yStrm.read(y); // Kernel Calls: multiply(yStrm, yStrm, tmpStrm); constSum(tmpStrm, dp); std::cout << "GPU Residual = " << dp << std::endl;

                • Vector Dot Product
                  gaurav.garg

                  Which OS, catalyst and GPU model are you using? It works perfectly fine on my XP32, Catalyst 9.10, RV770 system.

                  • Vector Dot Product
                    dinaharchery

                    Found the problem

                    I was using the double data type from the host-side to the GPU which was using floating-point.  When I changed to a consistent floating-point data type everything worked perfectly. I probably should update my Catalyst driver, I am using 9.2

                    Can anyone explain how Brook+ translates a double to float and vice-versa? I am assuming some sort of data 'wrap-around' that caused my problem.

                    Once again, thank you. gaurav.garg you deserve much credit for the amount of help you have given me in this forum (not just this thread, but many others I have posted in the past.)