Multiple GPU slower than single GPU or even CPU
조회 수: 4 (최근 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;
댓글 수: 0
답변 (1개)
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
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Data Workflows에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!