Why is it not possible to pass matrix parameters as argument to GPU arrayfun and what to do?
조회 수: 10 (최근 30일)
이전 댓글 표시
Background
- The problem can be separated into a large number of independent sub-problems.
- All sub-problems share the same matrix parameters of significant sizes.
- Each sub-problem performs an operation involving the matrix parameters that is hard to express with linear algebra.
- The goal is to process the sub-problems in paralell on the GPU.
댓글 수: 0
채택된 답변
Edric Ellis
2024년 2월 27일
It would be great to see a simplified example of what you're trying to do. What you can do with gpuArray/arrayfun is write a nested function to access constant data from a parent workspace, a bit like this:
function [r,c] = example
% up-level variables that we will access inside the nested
% function "iFindLocation"
mat = gpuArray(magic(4));
[m,n] = size(mat);
[r,c] = arrayfun(@iFindLocation, gpuArray(1:100));
function [r,c] = iFindLocation(in)
r = NaN; c = NaN;
for i = 1:m
for j = 1:n
% Access the matrix "mat" from the parent
% workspace
if mat(i,j) == in
r = i;
c = j;
end
end
end
end
end
댓글 수: 2
Edric Ellis
2024년 3월 4일
I believe the constant data used inside the nested function here does not need to be duplicated.
추가 답변 (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!