Inverse of a square matrix using Gauss-Jordan elimination

Hello there,
I am trying to calculate inverse of a 3x3 matrix on the GPU using Gaussian elimination, as required by another kernel already running on the GPU. However, seems I am not getting the right answer:

My original matrix is:
-204.00000001_____________ 204.00000401____________________-2e-06
-2e-06____________________-2e-06____________________ 4e-06

If I try my algorithm on the CPU using a simple C-code or in Matlab, it gives me the right answer as follows:


however if I try this on the GPU, I get the following:

I am aware that this issue is probably related to the IEEE 754 standard of floating point operations on the GPU. Is there any way to work around this issue? I am pretty sure someone in this forum is having this similar issue. It would be highly appreciated if someone could share their few point here. thanks in advance.

I doubt this has anything to do with IEEE 754 standard. More likely a bug in your code. Here is a rudimentary GJE example:

Thank you for the comment. I am thinking about IEEE 754 because the matrix is only 3x3 and I tried with a different 3x3 matrix. As shown below:

Matrix before inversion:

Matrix after inversion:

These answers are from GPU version of the code and is in perfect match with CPU-based algorithms. I tried my code for other bigger matrices as well, results matches perfectly. So the issue of Bug is probably not here.

which is your kernel using float or double? (matlab uses double)

Thank you Txbob. I am using float type both on the CPU and GPU.Sorry for the delay in replying.

Try using double. GJE involves division, and some of your divisors for the badly performing matrix are quite small relatively speaking. The exact details probably matter here, i.e. the exact code probably matters. I don’t think this is actually specific to the GPU, because, in my experience, properly constrained float behavior on the CPU is basically identical to float behavior on the GPU. It is pretty much a misconception floating around that there are differences.

Thank you Txbob for your effort. For me no Luck yet!
However, I found some interesting thought from the following post, where it says:

"For single precision…

If you want an accuracy of +/-0.5 (or 2^-1), the maximum size that the number can be is 2^23. Any larger than this and the distance between floating point numbers is greater than 0.5.

If you want an accuracy of +/-0.0005 (about 2^-11), the maximum size that the number can be is 2^13. Any larger than this and the distance between floating point numbers is greater than 0.0005. " – during calculations, some of my numbers are going beyond 10^6 (i.e. 2^23) and I am getting wrong values? What do you think? thanks in advance.