필터 지우기
필터 지우기

Can I run custom Matlab function or gpuArray on another GPU?

조회 수: 4 (최근 30일)
Zhenhong Du
Zhenhong Du 2022년 4월 20일
댓글: Zhenhong Du 2022년 4월 21일
Hello, everyone
I work on image processing and handle large scale images. I designed an algorithm that could get the result I wanted by multiple iterations, and it ran successfully.
%% code example
input = zeros(500,500,50);
a = zeros(500,500,50);
b = zeros(500,500,50);
c = zeros(500,500,50);
d = zeros(500,500,50);
input = gpuArray(input);
a = gpuArray(a);
b = gpuArray(b);
c = gpuArray(c);
d = gpuArray(d);
for i=1:100
a = input + d;
b = a + input;
c = b + a;
d = func1(c);
end
I use the gpuArray provided by matlab to speed up operations.But the size of the image I'm processing is constrained by the size of the GPU's memory.
Can I load c,d arrays on another gpu? Or can I run func1 on another GPU2? I want to reduce the consumption of memory of my current GPU1. Do you have any suggestions?

채택된 답변

Joss Knight
Joss Knight 2022년 4월 20일
You can use parallel syntax to process other arrays on other GPUs at the same time, or to process some data on the CPU at the same time as processing others on the GPU. Try this documentation for some examples.
In your code example your initial arrays a, b and c are all immediately overwritten by other variables. Does that matter? Anyway, worth checking.
  댓글 수: 5
Joss Knight
Joss Knight 2022년 4월 21일
Hi Zhenhong. It does look as if your algorithm may be inherently serial so there may be no way to parallelize. However, it is often true that a serial algorithm can be computed in parallel chunks, for instance, a sum a+b+c+d can be computed by calculating (a+b) and (c+d) in parallel before summing the result. So perhaps rethinking your algorithm might be a way to start. Alternatively, if you call your entire algorithm multiple times with different inputs you could do each call in parallel.
As for device selection, you shouldn't be doing that. The point is to select a different device on each worker, but this is done for you automatically. If you select the device manually you will reset the device and clear all GPU variables. If you have two devices and you open a pool with two workers, for instance by going parpool('local',gpuDeviceCount), then any operations on those workers will take place on different devices.
There are various other odd issues with your code but of course I understand it's just a simplified example. You shouldn't need to gather the inputs to func1, because it supports gpuArray inputs. It seems you did it to switch device, but as I pointed out you should never do that within a worker. When results are returned from the worker back to the client MATLAB, they are automatically transferred from whatever GPU the worker is using to the client's GPU.
Zhenhong Du
Zhenhong Du 2022년 4월 21일
I understand. Despite some frustration, thank you very much for your patient response.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 GPU Computing에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by