How do I use @mldivide together with pagefun on the GPU?
2 次查看(过去 30 天)
显示 更早的评论
I need to solve a lot of batches of xA = B problems and I'm experimenting with different solutions to see which type is fastest. And since pagefun supports mldivide I suspect it could be the perfect function for what I want to do. However, I have never fully understood the concept behind how it works and the documentation only gives examples of multiplication problems that I can't completely relate to what I want to do.
So could someone please just provide a small example or tell me how to use pagefun with mldivide to solve several xA = B at the same time so I can see how it should be set up?
Say for example I have an A of size = [100 10 15] and a B of size = [100 1 15] and I want to solve the problem for the 15 different versions along the third dimension. So in a loop it would be:
for i = 1 : 15
A(:,:,i)\B(:,1,i)
end
But how do I use pagefun to do this in parallel without the loop? If I write it as:
A = gpuArray.rand(100, 10,15);
B = gpuArray.rand(100, 1, 15);
x = pagefun(@mldivide, A, B);
I get:
Error using gpuArray/pagefun
The number of rows and columns of each page of the divisor must be equal when
using MLDIVIDE or MRDIVIDE with PAGEFUN.
This is probably very trivial to everyone else, but I just don’t get it. Could someone clarify how this is done? Thanks!
0 个评论
采纳的回答
Joss Knight
2016-4-15
Your systems are rectangular. You can only solve square systems with pagefun, sorry.
2 个评论
Joss Knight
2016-4-19
You just want a pseudo inverse like inv(A'*A)*A'. So why not try
At = pagefun(@ctranspose, A);
AtA = pagefun(@mtimes, At, A);
pseudoInv = pagefun(@mldivide, AtA, At);
X = pagefun(@mtimes, pseudoInv, B);
Not as robust as a proper QR-based solve but could be good enough for you.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Detection 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!