GPUArray ANDs and ORs

3 次查看(过去 30 天)
First off, I am very satisfied with matlab's ability to leverage the GPU for parellel computing. It makes so many functions and calculations faster (usually about 3-5x faster). With the pre-release and release of MATLAB 2011a, they have added even more functionality for use with GPUArrays. One troubling thing is there seems to be no support for the "and" and "or" operators on GPUArrays.
To get around this, one could gather their GPUArray each time they would like to run a logical AND or OR. This represents a slow down in performance over using non-distrubuted arrays, and requires a re-write (albeit small) of many the existing functions that I have to handle GPUArrays. There is also a clever way to perform the "AND" and "OR" operators using concatanation and the "all" or "any" functions. I have written two short functions to do so
function obj = and(A,B)
nD = ndims(A)+1;
obj = all(cat(nD,A,B),nD);
return
function obj = or2(A,B)
nD = ndims(A)+1;
obj = any(cat(nD,A,B),nD);
return
Is there away to define the method "AND" and "OR" for an existing class type of parallel.gpu.GPUArray?
Any help or insight would me much appreciated.

采纳的回答

Sarah Wait Zaranek
Sarah Wait Zaranek 2011-4-15
Have you tried the option of creating your own kernal from a MATLAB function?
I wrote a brief code tidbit below. Note: I haven't tried it out since I don't have access to my GPU machine at the moment.
function C = testAnd(A, B)
C = A & B;
end
To call it then as a GPU kernel.
C = arrayfun(@testAnd, A, B);
A and B must already be gpuArrays.
Hope this helps.
More info here:
  2 个评论
Jonathan Sullivan
Jonathan Sullivan 2011-4-15
Sarah. Something of note. I am running the prerelease of 2011a. It looks like (from following that link) that this functionality has been added in the release version. I guess I ought to have my sys admin upgrade me to the full version.
Sarah Wait Zaranek
Sarah Wait Zaranek 2011-4-15
Hi Jonathan -
Looks like & and | were added in 11a. However, I thought they were supported in the pre-release for arrayfun - but I haven't checked. Once you get your upgrade, let me know if it works for you.
I did also want to make sure that I was clear that this is actually different then what you have been doing before with the built-in MATLAB functions. This actually takes your MATLAB function which could be a series of element-wise operations and make them into their own kernel run by arrayfun. Just as an FYI.
Cheers,
Sarah

请先登录,再进行评论。

更多回答(1 个)

Jill Reese
Jill Reese 2011-7-29
Hi Jonathan, if your MATLAB license is up to date you might like to have a look at the pre-release of R2011b which is now available. This includes a number of updates to the GPU features. It can be downloaded by logging in to the main www.mathworks.com page.

类别

Help CenterFile Exchange 中查找有关 GPU Computing 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by