Declare gpuArray while executing on gpu

조회 수: 1 (최근 30일)
cedric W
cedric W 2019년 1월 4일
댓글: Marios 2019년 11월 15일
I'm trying to modify my code working well for a CPU setup to a GPU setup. It appears to be more complicated than what I had expected.
I'm using arrayfun to send the computation to GPU for my monte carlo simulations:
MC_Paths = arrayfun(@Heston_One_Simulation, Param1, Param2, and so on)
with the beginning of the function Heston_One_Simulation defined as
function [S] = Heston_One_Simulation(Param1,Params2, so on...)
HistoCorrelatedPaths1=zeros(N,NbAssets,BatchSize,'gpuArray');
...
end
And I get the following error message:
Function passed as first input argument contains unsupported or unknown function 'zeros'. For more information see Tips and Restrictions.
Is it impossible to declare new variables while running on a GPU ?
I'm sure I'll have more problems once this one is solved but let's start with that one.

답변 (1개)

Joss Knight
Joss Knight 2019년 1월 5일
GPU arrayfun functions can only do scalar operations. You can declare new scalar variables but you can't create new arrays.
  댓글 수: 5
Joss Knight
Joss Knight 2019년 1월 7일
Most problems are solved using a combination of arrayfun, pagefun, and standard vectorisation. You need to look for opportunity to batch up all your work as much as possible. Arrayfun can be used wherever you have a sequence of element-wise maths, but isn't usually necessary because MATLAB is clever enough to group all those operations into a single kernel for you where possible.
Essentially you are looking to remove all the loops in your code and replace them with masks, vector algebra and arrayfun/pagefun calls.
This is a good blog post to get you on the right track:
Marios
Marios 2019년 11월 15일
Is this way the example paralleldemo_gpu_arrayfun does not show any improvement between the standard "tgpuObject" and GPU arrayfun() "tgpuArrayfun"? I have tried different GPUs (1080, 1650) on 2019b and both cases return the same speed. I assume it's because horner() has been optimized in 2019b to "bunch" all the kernels in one anyway eliminating the need for GPU arrayfun()?

댓글을 달려면 로그인하십시오.

카테고리

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