Multiple GPU slower than single GPU or even CPU

1 次查看(过去 30 天)
I have an image processing code that uses multiple GPU, however, the multi-gpu process is slower than single GPU and even CPU. Moreover, the single GPU and the CPU processing time is about the same. Does anyone know what's wrong?
clc
clear all
close all
ImageFolder = uigetdir('D:\', 'Select Image Directory');
[parentFolder, thisFolder] = fileparts(ImageFolder);
fileListing = dir(parentFolder);
fileListing(ismember( {fileListing.name}, {'.', '..'})) = [];
areAFolder = [fileListing.isdir];
folderListing = fileListing(areAFolder);
RawImage = [dir([ImageFolder '/*.tif']);dir([ImageFolder '/*.tiff']);...
dir([ImageFolder '/*.png']); dir([ImageFolder '/*.jpg']);...
dir([ImageFolder '/*.dcm']); dir([ImageFolder '/*.fits']);...
dir([ImageFolder '/*.fts']); dir([ImageFolder '/*.img']);...
dir([ImageFolder '/*.raw']); dir([ImageFolder '/*.his']);...
dir([ImageFolder '/*.hdr']); dir([ImageFolder '/*.nitf'])];
RawFileNames= {RawImage(:,1).name}';
RawFilenames = fullfile(ImageFolder, RawFileNames);
RawImageData = cellfun(@ReadInputImage, RawFilenames , 'uniformoutput', 0);
for k = 1 : length(folderListing)
thisFolder = fullfile(folderListing(k).folder, folderListing(k).name);
[~, theFolder] = fileparts(thisFolder);
if matches(theFolder, ["Bright","bright","gain","Gain"])
BrightImage= [dir([thisFolder '/*.tif']);dir([thisFolder '/*.tiff']);...
dir([thisFolder '/*.png']); dir([thisFolder '/*.jpg']);...
dir([thisFolder '/*.dcm']); dir([thisFolder '/*.fits']);...
dir([thisFolder '/*.fts']); dir([thisFolder '/*.img']);...
dir([thisFolder '/*.raw']); dir([thisFolder '/*.his']);...
dir([thisFolder '/*.hdr']); dir([thisFolder '/*.nitf'])];
BrightFileNames= {BrightImage(:,1).name}';
BrightFilenames = fullfile(thisFolder, BrightFileNames);
BrightImageData = cellfun(@ReadInputImage, BrightFilenames , 'uniformoutput', 0);
elseif matches(theFolder, {'Dark', 'dark', 'Offset', 'offset'})
DarkImage= [dir([thisFolder '/*.tif']);dir([thisFolder '/*.tiff']);...
dir([thisFolder '/*.png']); dir([thisFolder '/*.jpg']);...
dir([thisFolder '/*.dcm']); dir([thisFolder '/*.fits']);...
dir([thisFolder '/*.fts']); dir([thisFolder '/*.img']);...
dir([thisFolder '/*.raw']); dir([thisFolder '/*.his']);...
dir([thisFolder '/*.hdr']); dir([thisFolder '/*.nitf'])];
DarkFileNames= {DarkImage(:,1).name}';
DarkFilenames = fullfile(thisFolder, DarkFileNames);
DarkImageData = cellfun(@ReadInputImage, DarkFilenames , 'uniformoutput', 0);
end
end
if ~exist('BrightImageData','var') || isempty(BrightImageData) || ~exist ('DarkImageData','var') || isempty(DarkImageData)
msgbox(sprintf('Either Bright or Dark Images Not Found','warn'));
end
tic;
parpool('local',gpuDeviceCount);
parfor ii = 1:numel(RawImageData)
G = gpuArray(RawImageData{ii});
FilterImage{ii}=medfilt2(G,[5,5]);
end
delete(gcp('nocreate'));
toc;

回答(1 个)

Shadaab Siddiqie
Shadaab Siddiqie 2020-11-20
When training with multiple GPUs, each image batch is distributed between the GPUs. This effectively increases the total GPU memory available, allowing larger batch sizes. Because it improves the significance of each batch, you can increase the learning rate. A good general guideline is to increase the learning rate proportionally to the increase in batch size. For more information refere this link.
  3 个评论
Shadaab Siddiqie
Shadaab Siddiqie 2020-11-20
From my understanding in this case reading the images is taking much more time than processing thus, you are not seeing any improvent by using multiple GPU.
Muhammad Abir
Muhammad Abir 2020-11-20
That;s okay. But I have many functions like medfilt2 that I want them to run in multiple GPU. I don't find any solution to that problem.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by