Doesn't the GPU Coder support singleton expansion of ARRAYFUN?
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a question about SINGLETON EXPANSION for ARRAYFUN on GPU.
For gpuArrays, @times with ARRAYFUN and direct calculation on M-file both work fine.
However, MEX generated by GPU Coder from a code using ARRAYFUN does not seem to perform SINGLETON EXPANSION well.
Doesn't the GPU Coder support SINGLETON EXPANSION of ARRAYFUN?
Shogo MURAMATSU
Sample code
function Y = arrayfuntest(m,X) %#codegen
Y = arrayfun(@times,m,X);
%Y = m.*X;
end
Code generation for ARRAYFUN
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/749309/image.png)
Code generation for a direct operation
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/749314/image.png)
Preparation of arrays
m = gpuArray(single([1;-1;1]))
X = gpuArray(rand(3,'single'))
Execution with M-file
Y = arrayfuntest(m,X)
MEX Generation
cfg = coder.gpuConfig('mex');
nChs = 64;
datatype = 'single';
aM = coder.typeof(gpuArray(cast(0,datatype)),[nChs 1],[1 0]);
aX = coder.typeof(gpuArray(cast(0,datatype)),[nChs nChs],[1 1]);
cfg.DynamicMemoryAllocation = 'Off';
cfg.GenerateReport = true;
codegen -config cfg -o arrayfuntest_mex arrayfuntest.m -args { aM, aX }
Execution with MEX-file
Y = arrayfuntest_mex(m,X)
댓글 수: 0
채택된 답변
Joss Knight
2021년 10월 2일
Support for dimension expansion is actually restricted to the GPU version of arrayfun, and GPU Coder supports the CPU version's syntax. So the answer is no, it doesn't support dimension expansion.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Kernel Creation from MATLAB Code에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!