Image processing using gpu array

조회 수: 5 (최근 30일)
nahyun lee
nahyun lee 2020년 3월 16일
답변: Sai Bhargav Avula 2020년 3월 23일
Hi all,
I am now trying to process the image using gpu array.
I made the code so that the gpu can be used, but I confirmed that matlab is running using CPU instead of using GPU on the computer.
The code to use gpu is as follows.
O = gather(video_ycbcr(gpuArray(video)))
O_cpu = {};
O_cpu{1} = O(:,:,001:149); % Can be easily extend to multiple GPU
O_gpu{1} = gpuArray(O_cpu{1}); % Move array from CPU to GPU for acceleration
R_gpu{1}=RainDetect(O_gpu{1},paras);
R_cpu{1}=gather(cat(3,R_gpu{1}{:}));
R = R_cpu{1};
What parts of this code need to be modified to use GPU properly on a computer?
Thank you.
  댓글 수: 3
nahyun lee
nahyun lee 2020년 3월 16일
Oh Sorry. RainDetect function and video_ycbcr function code is as follows.
Are there any problems with using GPU for these functions?
function [R,iter]=RainDetect(O,paras)
[m,n,t] = size(O);
O = num2cell(O,[1 2]);
R{1} = gpuArray(zeros(m,n));
B{1} = O{1}-R{1};
iter{1} = 0;
[R{2},B{2},iter{2}]=RainDetect_i(O{2},B{1},paras);
for i = 3:t
disp(i);
[R{i},B{i},iter{i}]=RainDetect_i(O{i},B{i-1},paras);
end
%% ===============================================================
function [y] = video_ycbcr(video)
[m,n,~,num_frame] = size(video);
y = zeros(m,n,num_frame);
y = gpuArray(y);
for i = 1:num_frame
f_ycbcr = rgb2ycbcr(video(:,:,:,i));
y(:,:,i)=f_ycbcr(:,:,1);
end
end
Walter Roberson
Walter Roberson 2020년 3월 16일
O = num2cell(O,[1 2])
It is not obvious to me that produces a cell on the gpu or that the entries will be on the gpu. I do not understand why you convert to cell instead of just indexing the input?

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

답변 (1개)

Sai Bhargav Avula
Sai Bhargav Avula 2020년 3월 23일
Hi,
The link attached below gives a better insight on how to use GPU for better performance.
Hope this helps!

카테고리

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