Why "inv" or "\" functions give wrong result

[Old posts from the commercial version of ArrayFire] Discussion of ArrayFire using CUDA or OpenCL.

Moderator: pavanky

Why "inv" or "\" functions give wrong result

Postby Farzad » Tue Jul 05, 2011 9:40 am

Hi
it seems that there's something wrong with the inverse algorithm that is used to find inverse of a matrix in jacket. if you try following test

>> A=kron(eye(2),rand(N));
>> norm(double(inv(gdouble(A)))-inv(A))

where A is a block diagonal matrix, you'll see that for N<64 norm of difference of the result from gpu and the result from cpu are the same but for N>=65 the results do not match. Actually the result only matches for the first block only!
Does anybody know how to fix this problem please let me know.
Farzad
 
Posts: 2
Joined: Tue Jul 05, 2011 9:30 am

Re: Why "inv" or "\" functions give wrong result

Postby pavanky » Tue Jul 05, 2011 11:36 am

Hi,

Can you give us the output of ginfo ? This will give us information regarding the version of Jacket and the card you are using.

On our current version of Jacket, here are the results I am getting:
Code: Select all

>> for N = 60:70; a = kron(eye(2), rand(N)); A = gdouble(a); norm(double(inv(gdouble(a))) - inv(a)), end
ans =
   9.3968e-13
ans =
   5.8176e-13
ans =
   1.4223e-11
ans =
   1.4229e-11
ans =
   2.6200e-13
ans =
   1.3348e-11
ans =
   5.5847e-13
ans =
   1.1017e-12
ans =
   1.1765e-13
ans =
   1.5659e-10
ans =
   2.0977e-11
Pavan Yalamanchili,
ArrayFire
--
~ If it is not broken, you have not tried hard enough ~
User avatar
pavanky
Site Admin
 
Posts: 1123
Joined: Mon Mar 15, 2010 7:39 pm
Location: Atlanta, GA

Re: Why "inv" or "\" functions give wrong result

Postby Farzad » Tue Jul 05, 2011 12:29 pm

Hi
Thanks for the response.
I just checked the test again and it worked fine. However when I run another code that uses the gpu functions for matrix inversion and multiplication extensively (which gives wrong results) and then run the command again, I get following result

Code: Select all
 
clear all; for N = 60:70; a = kron(eye(2), rand(N)); A = gdouble(a); norm(double(inv(gdouble(a))) - inv(a)), end

ans =
   1.8583e-12
ans =
   4.6066e-13
ans =
   1.3154e-13
ans =
   1.9623e-13
ans =
   7.9725e-13
ans =
  227.9688
ans =
  200.1699
ans =
   8.5355e+04
ans =
   2.7756e+04
ans =
   1.7390e+06
ans =
   2.4477e+04


I'm not sure how this could happen! In my long code I'm not adding any path or additional external function (all the functions are defined inside a main function called "Main1.m"). I'm using matlabpool but that doesn't look like to cause the problem.
P.S. the ginfo gives me following infos

Code: Select all
>> ginfo
Jacket v1.7.1 (build 58de35b) by AccelerEyes
License Type: Designated Computer (on 64-bit Linux)
Licensed Addons: DLA, SLA
Multi-GPU: Not Available

Detected CUDA-capable GPUs:
CUDA driver 275.09.07, CUDA toolkit 3.2
GPU0 Tesla C2070, 1147 MHz, 5376 MB VRAM, Compute 2.0 (single,double)
Display Device: GPU0 Tesla C2070

GPU Memory Usage: 5097 MB free (5376 MB total)
Farzad
 
Posts: 2
Joined: Tue Jul 05, 2011 9:30 am

Re: Why "inv" or "\" functions give wrong result

Postby pavanky » Tue Jul 05, 2011 1:46 pm

Hi,

There are two things we can do here.

1) Provide us the code that produces this problem, so that we can debug this further. If you are not comfortable giving out the code in the forums, you can email us (support@accelereyes.com, pavan.yalamanchili@accelereyes.com)

Or

2) Download the latest version of Jacket release candidates (www.accelereyes.com/nightly) and see if that reproduces the problem or fixed. If the problem still persists, you may need to send us the smallest code that you are comfortable sharing with us..
Pavan Yalamanchili,
ArrayFire
--
~ If it is not broken, you have not tried hard enough ~
User avatar
pavanky
Site Admin
 
Posts: 1123
Joined: Mon Mar 15, 2010 7:39 pm
Location: Atlanta, GA

Why "\" functions give different result with CPU ?

Postby jackevin » Thu Aug 23, 2012 3:27 am

HI,
I have a about sparse mldivide question.

a = sparse(rand(5,5)) ;
b= rand(5,1) ;
c= a\b ;

A= gdouble(a) ;
B= gdouble(b) ;
C= A\B ;

ans for CPU :
-0.3621
0.8286
-0.7096
0.3641
0.7415

ans for GPU
0.7059
1.3489
-0.3695
-0.6137
5.3863

why the different ans with CPU and GPU ?

I use jacket 2.2
jackevin
 
Posts: 1
Joined: Thu Aug 23, 2012 3:15 am

Re: Why "inv" or "\" functions give wrong result

Postby pavanky » Thu Aug 23, 2012 7:16 pm

Hi,

The "\" operator is only supported for triangular matrices when the matrix is sparse. Ideally, your code should have thrown an error, but it looks like a bug at our end that it is failing silently.

We will fix it ASAP.
Pavan Yalamanchili,
ArrayFire
--
~ If it is not broken, you have not tried hard enough ~
User avatar
pavanky
Site Admin
 
Posts: 1123
Joined: Mon Mar 15, 2010 7:39 pm
Location: Atlanta, GA

Re: Why "inv" or "\" functions give wrong result

Postby donato84 » Tue Sep 18, 2012 5:56 am

hi all, i have this problem, i have written this code:
precision='single';
gfor q=1:fine
cova(:,:,q)=cova(:,:,q)\geye(Nb,Nb,precision);
end

where cova is a 3D matrix( 105,105,256) . I have written the same code with a for-loop:

for q=1:fine
cova(:,:,q)=cova(:,:,q)\eye(Nb,Nb,precision);
end

the CPU is really fast the GPU no. How can improve my code? thank a lot !!
donato84
 
Posts: 7
Joined: Thu Apr 19, 2012 3:50 pm

Re: Why "inv" or "\" functions give wrong result

Postby tudor00 » Wed Nov 14, 2012 11:28 pm

Hi.

I have a similar problem, namely I get different results when using the \ operator on the CPU and the GPU. Has the problem been fixed? (It's the middle of November now.)

Here's my problem. I have two large sparse matrices, A and B, and two vectors, c and d (all of type double). On the CPU I compute
r1=A*(B\c + d).

Then I define the GPU variables GA=gdouble(A); GB=gdouble(B); Gc=gdouble(c); Gd=gdouble(d) and compute
r2=double(GA*(GB\Gc + Gd)).

Unfortunately, r1 and r2 are not even close (the elements differ by several orders of magnitude) and I don't get any error messages. What is going on?

I would like to add that I got the Tesla C2075 precisely because I need to solve problems of the type A*(B\c + d), where A and B are sparse, and I understood that Jacket, as opposed to MATLAB, could handle this problem on the GPU. I am running MATLAB R2012a on a Windows 7 (Ultimate) workstation. I also use an nVidia Quadro 5000 in this workstation as the graphics card.

Thank you.
-TNB
tudor00
 
Posts: 2
Joined: Wed Nov 14, 2012 11:05 pm

Re: Why "inv" or "\" functions give wrong result

Postby tudor00 » Fri Nov 16, 2012 12:05 am

pavanky wrote:Hi,

The "\" operator is only supported for triangular matrices when the matrix is sparse. Ideally, your code should have thrown an error, but it looks like a bug at our end that it is failing silently.

We will fix it ASAP.


==============

I think you have tried and succeeded :) I have a large, symmetric, sparse matrix. How do I do a left division in this case? Am I missing something (it is possible I am...)?
tudor00
 
Posts: 2
Joined: Wed Nov 14, 2012 11:05 pm

Re: Why "inv" or "\" functions give wrong result

Postby pavanky » Fri Nov 16, 2012 3:21 pm

Hi turdor,

Unfortunately, the problem seems to come from upstream library. We have not found an easy way to fix this yet. If you can contact support@accelereyes.com we will try to see if a custom solution can be provided for your case.
Pavan Yalamanchili,
ArrayFire
--
~ If it is not broken, you have not tried hard enough ~
User avatar
pavanky
Site Admin
 
Posts: 1123
Joined: Mon Mar 15, 2010 7:39 pm
Location: Atlanta, GA

Re: Why "inv" or "\" functions give wrong result

Postby lourencohen » Thu Mar 06, 2014 7:26 am

I have tried to execute the code you were trying, but it gives me a false output here. So I guess you should try rewriting the code without trying to correct the same. I am unable to find where the error occurred. Hope you will share the correct results with us too.



Thanks
LoURENE
tech support windows
lourencohen
 
Posts: 1
Joined: Thu Mar 06, 2014 7:22 am


Return to [archive-commercial] Programming & Development with ArrayFire