cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

dinaharchery
Journeyman III

Vector Dot Product

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;

0 Likes
5 Replies
gaurav_garg
Adept I

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);

}

0 Likes

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;

0 Likes

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

0 Likes

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.)

0 Likes

Brook+ just does byte by byte copy in streamRead and Write, similar to C memcpy. That explains why you were getting wrong results with double datatype pointer on host side.

0 Likes