GPUArray ANDs and ORs
조회 수: 1 (최근 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.
댓글 수: 0
채택된 답변
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
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
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 GPU Computing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!