Multiple GPU slower than single GPU or even CPU

1 vue (au cours des 30 derniers jours)
Muhammad Abir
Muhammad Abir le 17 Nov 2020
Commenté : Muhammad Abir le 20 Nov 2020
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;

Réponses (1)

Shadaab Siddiqie
Shadaab Siddiqie le 20 Nov 2020
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 commentaires
Shadaab Siddiqie
Shadaab Siddiqie le 20 Nov 2020
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 le 20 Nov 2020
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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Image Data Workflows dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by