Assign 4 GPUs - 1 to each worker in parfor loop
1 次查看(过去 30 天)
显示 更早的评论
Hi. I have written a function that uses the GPU to speed up the progress. It seems to be working well, because the GPU version is already 7.5 times as fast as the CPU version using 12 workers in a parfor loop. But the server that runs the batch jobs has 4 GPUs. I assume that in my gpu function, only one of them is used. I was wondering if I could write a script that uses a parfor loop with 4 workers (dividing the matrices into 4 segments) and assigns one GPU to each of the workers. Ideally, this should give the script another 4x boost, bringing the total speed boost to 30.
Here is my idea:
fr1 = 4; %Number of GPUs to work
width = size(input1,2);
fr2 = round(width./fr1); %index to divide data by to spread it equally over 4 workers
output1 = zeros(size(input1),'single');
output2 = output1;
output3 = output1;
out1 = cell(1,fr1); out2 = out1; out3 = out1; %store data in cells to avoid indexing errors
parfor fr = 1:fr1 %divide between 4 workers
[out1{fr}, out2{fr}, out3{fr}] = ...
GPU_function(input1(: , fr*fr2-fr2+1:min(fr.*fr2+fr2,width)),...
input2(:,fr*fr2-fr2+1:min(fr.*fr2+fr2,width)),...
input3 (:,fr*fr2-fr2+1:min(fr.*fr2+fr2,width)));
end
%sort data from cells into outputs
for fr = 1:fr1
output1(:,fr*fr2-fr2+1:min(fr.*fr2+fr2,width)) = out1{fr};
output2(:,fr*fr2-fr2+1:min(fr.*fr2+fr2,width)) = out2{fr};
output3(:,fr*fr2-fr2+1:min(fr.*fr2+fr2,width)) = out3{fr};
end
I am pretty sure this is not enough to assign a GPU to each worker. Running the script on the server results in the error message "Out of memory on device." Running GPU_function() on the entire data set on one worker without splitting it into 4 does not return this error. Does anyone have an idea how I could make this work?
Thanks in advance!
Marc
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 GPU Computing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!