フィルターのクリア

Why is it not possible to pass matrix parameters as argument to GPU arrayfun and what to do?

4 ビュー (過去 30 日間)
Background
  1. The problem can be separated into a large number of independent sub-problems.
  2. All sub-problems share the same matrix parameters of significant sizes.
  3. Each sub-problem performs an operation involving the matrix parameters that is hard to express with linear algebra.
  4. The goal is to process the sub-problems in paralell on the GPU.

採用された回答

Edric Ellis
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 件のコメント
Anders
Anders 2024 年 2 月 27 日
編集済み: Anders 2024 年 2 月 27 日
99% of the code used for this project can be regarded as a black box function analogous to the function iFindLocation.
Your example code represents this problem nicely.
Follow-up question
For arrayfun to work in paralell, does it need to store copies of the matrix mat in GPU memory or is it enougth with just the one?
Edric Ellis
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 ExchangeGPU Computing についてさらに検索

タグ

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by