Multiple GPU slower than single GPU or even CPU

조회 수: 4 (최근 30일)
Muhammad Abir
Muhammad Abir 2020년 11월 17일
댓글: Muhammad Abir 2020년 11월 20일
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