Skip to content
Snippets Groups Projects
Commit 18fd4f14 authored by Nicola Vigano's avatar Nicola Vigano
Browse files

Astra: updated benchmarks against new cell interface

parent 387b7b25
No related branches found
No related tags found
No related merge requests found
classdef GtAstraBenchmarks < GtBenchmarks
methods (Access = public, Static)
function benchmark3Dset(numIters, sirtDetectImages)
if (~exist('numIters', 'var'))
numIters = 20;
end
if (~exist('sirtDetectImages', 'var'))
sirtDetectImages = rand(1e2, 2e2, 3e2);
end
proj = [];
proj.stack = sirtDetectImages;
proj.num_cols = size(sirtDetectImages, 1);
proj.num_rows = size(sirtDetectImages, 3);
proj.geom = ones(size(sirtDetectImages, 2), 12);
proj_geom = astra_create_proj_geom('parallel3d_vec', proj.num_rows, proj.num_cols, proj.geom);
%%% SINO
function benchmark3Dcreate(numIters, sirtDetectImages)
[proj, proj_geom] = GtAstraBenchmarks.createProjAndGeom(sirtDetectImages);
bytes = GtBenchmarks.getSizeVariable(sirtDetectImages);
GtBenchmarks.printHeader('Set Mex Data 3D', bytes)
GtBenchmarks.printHeader('Create Mex Data 3D', bytes)
fprintf(' - Doing %d iterations: ', numIters)
tic();
......@@ -26,7 +16,28 @@ classdef GtAstraBenchmarks < GtBenchmarks
GtBenchmarks.printResult('astra_mex_data3d(''create'', ''-proj3d'')', toc()/numIters, bytes);
% Let's assume 'get' is correct!
proj_id = astra_mex_data3d('create', '-proj3d', proj_geom, proj.stack);
proj_id = astra_mex_data3d('create', '-proj3d', proj_geom, proj.stack);
copied = astra_mex_data3d('get', proj_id);
astra_mex_data3d('delete', proj_id);
GtBenchmarks.verifyError(sirtDetectImages, copied);
end
function benchmark3Dstore(numIters, sirtDetectImages)
[proj, proj_geom] = GtAstraBenchmarks.createProjAndGeom(sirtDetectImages);
bytes = GtBenchmarks.getSizeVariable(sirtDetectImages);
GtBenchmarks.printHeader('Store Mex Data 3D', bytes)
fprintf(' - Doing %d iterations: ', numIters)
proj_id = astra_mex_data3d('create', '-proj3d', proj_geom, proj.stack);
tic();
for ii = 1:numIters
astra_mex_data3d('store', proj_id, proj.stack);
end
GtBenchmarks.printResult('astra_mex_data3d(''store'', ''-proj3d'')', toc()/numIters, bytes);
% Let's assume 'get' is correct!
copied = astra_mex_data3d('get', proj_id);
astra_mex_data3d('delete', proj_id);
......@@ -34,23 +45,72 @@ classdef GtAstraBenchmarks < GtBenchmarks
end
function benchmark3Dget(numIters, sirtDetectImages)
if (~exist('numIters', 'var'))
numIters = 20;
[proj, proj_geom] = GtAstraBenchmarks.createProjAndGeom(sirtDetectImages);
bytes = GtBenchmarks.getSizeVariable(sirtDetectImages);
GtBenchmarks.printHeader('Get Mex Data 3D', bytes)
fprintf(' - Doing %d iterations: ', numIters)
proj_id = astra_mex_data3d('create', '-proj3d', proj_geom, proj.stack);
tic();
for ii = 1:numIters
proj = astra_mex_data3d('get', proj_id);
end
if (~exist('sirtDetectImages', 'var'))
sirtDetectImages = rand(1e2, 2e2, 3e2);
astra_mex_data3d('delete', proj_id);
GtBenchmarks.printResult('astra_mex_data3d(''get'', proj_id)', toc()/numIters, bytes);
end
%%% VOL
function benchmarkVolCreate(numIters, sirtDetectImages)
vol_geom = GtAstraBenchmarks.createVolAndGeom(sirtDetectImages);
bytes = GtBenchmarks.getSizeVariable(sirtDetectImages);
GtBenchmarks.printHeader('Create Mex Data 3D', bytes)
fprintf(' - Doing %d iterations: ', numIters)
tic();
for ii = 1:numIters
proj_id = astra_mex_data3d('create', '-vol', vol_geom, sirtDetectImages);
astra_mex_data3d('delete', proj_id);
end
proj = [];
proj.stack = sirtDetectImages;
proj.num_cols = size(sirtDetectImages, 1);
proj.num_rows = size(sirtDetectImages, 3);
proj.geom = ones(size(sirtDetectImages, 2), 12);
proj_geom = astra_create_proj_geom('parallel3d_vec', proj.num_rows, proj.num_cols, proj.geom);
GtBenchmarks.printResult('astra_mex_data3d(''create'', ''-vol'')', toc()/numIters, bytes);
% Let's assume 'get' is correct!
proj_id = astra_mex_data3d('create', '-vol', vol_geom, sirtDetectImages);
copied = astra_mex_data3d('get', proj_id);
astra_mex_data3d('delete', proj_id);
GtBenchmarks.verifyError(sirtDetectImages, copied);
end
function benchmarkVolStore(numIters, sirtDetectImages)
vol_geom = GtAstraBenchmarks.createVolAndGeom(sirtDetectImages);
bytes = GtBenchmarks.getSizeVariable(sirtDetectImages);
GtBenchmarks.printHeader('Store Mex Data 3D', bytes)
fprintf(' - Doing %d iterations: ', numIters)
proj_id = astra_mex_data3d('create', '-vol', vol_geom);
tic();
for ii = 1:numIters
astra_mex_data3d('store', proj_id, sirtDetectImages);
end
GtBenchmarks.printResult('astra_mex_data3d(''store'', ''-vol'')', toc()/numIters, bytes);
% Let's assume 'get' is correct!
copied = astra_mex_data3d('get', proj_id);
astra_mex_data3d('delete', proj_id);
GtBenchmarks.verifyError(sirtDetectImages, copied);
end
function benchmarkVolGet(numIters, sirtDetectImages)
vol_geom = GtAstraBenchmarks.createVolAndGeom(sirtDetectImages);
bytes = GtBenchmarks.getSizeVariable(sirtDetectImages);
GtBenchmarks.printHeader('Get Mex Data 3D', bytes)
fprintf(' - Doing %d iterations: ', numIters)
proj_id = astra_mex_data3d('create', '-proj3d', proj_geom, proj.stack);
proj_id = astra_mex_data3d('create', '-vol', vol_geom, sirtDetectImages);
tic();
for ii = 1:numIters
......@@ -60,11 +120,209 @@ classdef GtAstraBenchmarks < GtBenchmarks
GtBenchmarks.printResult('astra_mex_data3d(''get'', proj_id)', toc()/numIters, bytes);
end
%%% CELL SINO
function benchmarkCellCreate(numIters, detectImages, numCells)
proj = cell(1, numCells);
proj_geom = cell(1, numCells);
for n = 1:numCells
[proj{n}, proj_geom{n}] = GtAstraBenchmarks.createProjAndGeom(detectImages);
end
proj_stack = cell(1, numCells);
for n = 1:numCells
proj_stack{n} = proj{n}.stack;
end
bytes = numCells * GtBenchmarks.getSizeVariable(detectImages);
GtBenchmarks.printHeader('Create Mex Data Cell', bytes)
fprintf(' - Doing %d iterations: ', numIters)
tic();
for ii = 1:numIters
proj_id = astra_mex_data3d('create', '-proj3d', proj_geom, proj_stack);
astra_mex_data3d('delete', proj_id{:});
end
GtBenchmarks.printResult('astra_mex_data3d(''create'', ''-proj3d'')', toc()/numIters, bytes);
% Let's assume 'get' is correct!
proj_id = astra_mex_data3d('create', '-proj3d', proj_geom, proj_stack);
copied = astra_mex_data3d('get', proj_id);
astra_mex_data3d('delete', proj_id{:});
GtBenchmarks.verifyError(proj_stack, copied);
end
function benchmarkCellStore(numIters, detectImages, numCells)
proj = cell(1, numCells);
proj_geom = cell(1, numCells);
for n = 1:numCells
[proj{n}, proj_geom{n}] = GtAstraBenchmarks.createProjAndGeom(detectImages);
end
proj_stack = cell(1, numCells);
for n = 1:numCells
proj_stack{n} = proj{n}.stack;
end
bytes = numCells * GtBenchmarks.getSizeVariable(detectImages);
GtBenchmarks.printHeader('Store Mex Data Cell', bytes)
fprintf(' - Doing %d iterations: ', numIters)
proj_id = astra_mex_data3d('create', '-proj3d', proj_geom, proj_stack);
tic();
for ii = 1:numIters
astra_mex_data3d('store', proj_id, proj_stack);
end
GtBenchmarks.printResult('astra_mex_data3d(''store'', ''-proj3d'')', toc()/numIters, bytes);
% Let's assume 'get' is correct!
copied = astra_mex_data3d('get', proj_id);
astra_mex_data3d('delete', proj_id{:});
GtBenchmarks.verifyError(proj_stack, copied);
end
function benchmarkCellGet(numIters, detectImages, numCells)
proj = cell(1, numCells);
proj_geom = cell(1, numCells);
for n = 1:numCells
[proj{n}, proj_geom{n}] = GtAstraBenchmarks.createProjAndGeom(detectImages);
end
proj_stack = cell(1, numCells);
for n = 1:numCells
proj_stack{n} = proj{n}.stack;
end
bytes = numCells * GtBenchmarks.getSizeVariable(detectImages);
GtBenchmarks.printHeader('Get Mex Data Cell', bytes)
fprintf(' - Doing %d iterations: ', numIters)
proj_id = astra_mex_data3d('create', '-proj3d', proj_geom, proj_stack);
tic();
for ii = 1:numIters
proj = astra_mex_data3d('get', proj_id);
end
GtBenchmarks.printResult('astra_mex_data3d(''get'', proj_id)', toc()/numIters, bytes);
astra_mex_data3d('delete', proj_id{:});
end
%%% CELL VOL
function benchmarkCellVolCreate(numIters, detectImages, numCells)
vol_geom = cell(1, numCells);
for n = 1:numCells
vol_geom{n} = GtAstraBenchmarks.createVolAndGeom(detectImages);
end
vol_stack = cell(1, numCells);
for n = 1:numCells
vol_stack{n} = detectImages;
end
bytes = numCells * GtBenchmarks.getSizeVariable(detectImages);
GtBenchmarks.printHeader('Create Mex Data Cell', bytes)
fprintf(' - Doing %d iterations: ', numIters)
tic();
for ii = 1:numIters
proj_id = astra_mex_data3d('create', '-vol', vol_geom, vol_stack);
astra_mex_data3d('delete', proj_id{:});
end
GtBenchmarks.printResult('astra_mex_data3d(''create'', ''-vol'')', toc()/numIters, bytes);
% Let's assume 'get' is correct!
proj_id = astra_mex_data3d('create', '-vol', vol_geom, vol_stack);
copied = astra_mex_data3d('get', proj_id);
astra_mex_data3d('delete', proj_id{:});
GtBenchmarks.verifyError(vol_stack, copied);
end
function benchmarkCellVolStore(numIters, detectImages, numCells)
vol_geom = cell(1, numCells);
for n = 1:numCells
vol_geom{n} = GtAstraBenchmarks.createVolAndGeom(detectImages);
end
vol_stack = cell(1, numCells);
for n = 1:numCells
vol_stack{n} = detectImages;
end
bytes = numCells * GtBenchmarks.getSizeVariable(detectImages);
GtBenchmarks.printHeader('Store Mex Data Cell', bytes)
fprintf(' - Doing %d iterations: ', numIters)
proj_id = astra_mex_data3d('create', '-vol', vol_geom);
tic();
for ii = 1:numIters
astra_mex_data3d('store', proj_id, vol_stack);
end
GtBenchmarks.printResult('astra_mex_data3d(''store'', ''-vol'')', toc()/numIters, bytes);
% Let's assume 'get' is correct!
copied = astra_mex_data3d('get', proj_id);
astra_mex_data3d('delete', proj_id{:});
GtBenchmarks.verifyError(vol_stack, copied);
end
function benchmarkCellVolGet(numIters, detectImages, numCells)
vol_geom = cell(1, numCells);
for n = 1:numCells
vol_geom{n} = GtAstraBenchmarks.createVolAndGeom(detectImages);
end
vol_stack = cell(1, numCells);
for n = 1:numCells
vol_stack{n} = detectImages;
end
bytes = numCells * GtBenchmarks.getSizeVariable(detectImages);
GtBenchmarks.printHeader('Get Mex Data Cell', bytes)
fprintf(' - Doing %d iterations: ', numIters)
proj_id = astra_mex_data3d('create', '-vol', vol_geom, vol_stack);
tic();
for ii = 1:numIters
proj = astra_mex_data3d('get', proj_id);
end
GtBenchmarks.printResult('astra_mex_data3d(''get'', proj_id)', toc()/numIters, bytes);
astra_mex_data3d('delete', proj_id{:});
end
function allBenchmarks()
imgs = rand(5e2, 5e2, 5e2);
imgs = rand(1e3, 1e3, 1e2);
GtAstraBenchmarks.benchmark3Dset(5, imgs)
GtAstraBenchmarks.benchmark3Dcreate(5, imgs)
GtAstraBenchmarks.benchmark3Dstore(5, imgs)
GtAstraBenchmarks.benchmark3Dget(5, imgs)
GtAstraBenchmarks.benchmarkVolCreate(5, imgs)
GtAstraBenchmarks.benchmarkVolStore(5, imgs)
GtAstraBenchmarks.benchmarkVolGet(5, imgs)
imgs = rand(1e3, 1e3, 2e1);
GtAstraBenchmarks.benchmarkCellCreate(5, imgs, 5);
GtAstraBenchmarks.benchmarkCellStore(5, imgs, 5);
GtAstraBenchmarks.benchmarkCellGet(5, imgs, 5);
GtAstraBenchmarks.benchmarkCellVolCreate(5, imgs, 5);
GtAstraBenchmarks.benchmarkCellVolStore(5, imgs, 5);
GtAstraBenchmarks.benchmarkCellVolGet(5, imgs, 5);
% Just in case
astra_mex_data3d('clear');
end
end
methods (Access = protected, Static)
function [proj, proj_geom] = createProjAndGeom(detectImages)
proj = [];
proj.stack = detectImages;
proj.num_cols = size(detectImages, 1);
proj.num_rows = size(detectImages, 3);
proj.geom = ones(size(detectImages, 2), 12);
proj_geom = astra_create_proj_geom('parallel3d_vec', proj.num_rows, proj.num_cols, proj.geom);
end
function vol_geom = createVolAndGeom(detectImages)
vol_geom = astra_create_vol_geom(size(detectImages, 1), size(detectImages, 2), size(detectImages, 3));
end
end
end
......@@ -19,7 +19,8 @@ classdef GtBenchmarks
function verifyError(reference, computed)
fprintf('Checking errors in computation:\n')
if (iscell(reference))
fprintf('\t%g\n', max(cellfun(@(x, y)max(max(max(abs(x - y)))), reference, computed)));
fprintf('\t%g\n', max(cellfun(@(x, y)max(max(max(abs(x - y)))), ...
reshape(reference, [numel(reference), 1]), reshape(computed, [numel(computed), 1]) )) );
elseif (isscalar(reference))
fprintf('\t%g (%g relative)\n', abs(reference - computed), abs((reference - computed)/reference) );
else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment