SummaryData

PURPOSE ^

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 classdef SummaryData
0002     %SUMMARYDATA  a class to store GPUBench summary data
0003     %
0004     %   s = gpubench.SummaryData(data) creates a summary data object from
0005     %   some previously stored GPUBench data.
0006     %
0007     %   See also: gpuBench
0008     
0009     %   Copyright 2011 The MathWorks, Inc.
0010     
0011     %% Private properties
0012     properties (SetAccess=private)
0013         DeviceName        % List of names for each device
0014         FunctionName      % List of names for each function
0015         Datatype          % List of datatype used
0016         LongName          % The long form of the function name to use in legends etc
0017         IsSelectedDevice  % True for the selected device, false for the others
0018         PeakFLOPS         % Array of peak results for each function run on each device
0019         Score             % Relative ranking for each device
0020         SortOrder         % The order of the summary data with respect to the original
0021     end
0022     
0023     %% Public methods
0024     methods
0025         function obj = SummaryData( data )
0026             % Construct a new summary data object
0027             
0028             N = numel( data );
0029             
0030             % First get the full list of function names across all results
0031             obj.DeviceName = cell(N,1);
0032             obj.IsSelectedDevice = [data.IsSelected];
0033             functionNames = cell(N,1);
0034             datatypes = cell(N,1);
0035             longNames = cell(N,1);
0036             peakFlops = cell(N,1);
0037             for jj=1:numel(data)
0038                 thisResults = data(jj).Results;
0039                 M = numel( thisResults );
0040                 obj.DeviceName{jj} = data(jj).getDeviceName();
0041                 functionNames{jj} = cell( 1, M );
0042                 datatypes{jj} = cell( 1, M );
0043                 longNames{jj} = cell( 1, M );
0044                 peakFlops{jj} = zeros( 1, M );
0045                 for ii=1:M
0046                     datatypes{jj}{ii} = thisResults(ii).DataType;
0047                     functionNames{jj}{ii} = thisResults(ii).FunctionName;
0048                     datatypes{jj}{ii} = thisResults(ii).DataType;
0049                     longNames{jj}{ii} = [functionNames{jj}{ii},' (',datatypes{jj}{ii},')'];
0050                     peakFlops{jj}(ii) = max( thisResults(ii).NumOps ./ thisResults(ii).Times );
0051                 end
0052             end
0053             datatypes = [datatypes{:}];
0054             functionNames = [functionNames{:}];
0055             
0056             % Work out the Union of the names and pad any missing ones with zero
0057             % results
0058             [obj.LongName,idx] = unique( [longNames{:}] );
0059             obj.Datatype = datatypes(idx);
0060             obj.FunctionName = functionNames(idx);
0061             
0062             % Now create the table of results
0063             M = numel( obj.LongName );
0064             obj.PeakFLOPS = nan( N, M );
0065             for row=1:N
0066                 [~,col] = ismember( longNames{row}, obj.LongName );
0067                 obj.PeakFLOPS(row, col) = peakFlops{row};
0068             end
0069             
0070             % Now create a score based on the performance in each category
0071             % relative to the best performance. Since MATLAB defaults to
0072             % using doubles we ignore singles in this score.
0073             normalizedFLOPS = bsxfun( @rdivide, obj.PeakFLOPS, max( obj.PeakFLOPS, [], 1 ) );
0074             normalizedFLOPS = normalizedFLOPS( :, strcmpi( obj.Datatype, 'double' ) );
0075             % NaN's indicate missing data, so we must ignore them
0076             obj.Score = zeros( N, 1 );
0077             for ii=1:N
0078                 valid = ~isnan( normalizedFLOPS(ii,:) );
0079                 obj.Score(ii) = mean( normalizedFLOPS(ii, valid) );
0080             end
0081             
0082             % Sort the scores and re-jig the summary data accordingly
0083             obj = sortResults( obj );
0084             
0085         end % constructor
0086         
0087         function t = getDatatypes( obj )
0088             t = unique( obj.Datatype );
0089         end % getDatatypes
0090 
0091         function cols = getColsForType( obj, typename )
0092             if iscell( typename )
0093                 cols = cell( size( typename ) );
0094                 for ii=1:numel(cols)
0095                     cols{ii} = obj.getColsForType( typename{ii} );
0096                 end
0097             else
0098                 cols = find( strcmp( obj.Datatype, typename ) );
0099             end
0100         end % getColsForType
0101     end
0102     
0103     %% Protected methods
0104     methods (Access=protected)
0105         function obj = sortResults(obj)
0106             % There are two different "sort"s we wish to apply. First we
0107             % want to order the devices according their "score". Next we
0108             % want to arrange the functions by data-type and then by peak
0109             % performance.
0110             
0111             % First put the devices into order
0112             [obj.Score,obj.SortOrder] = sort( obj.Score, 'descend' );
0113             obj.DeviceName = obj.DeviceName(obj.SortOrder);
0114             obj.PeakFLOPS = obj.PeakFLOPS(obj.SortOrder,:);
0115             obj.IsSelectedDevice = obj.IsSelectedDevice(obj.SortOrder);
0116             
0117             % Now sort by the peak performance for each function
0118             [~,idx] = sort( max( obj.PeakFLOPS ), 'descend' );
0119             obj = reorderFunctions( obj, idx );
0120             
0121             % Sort by data-type, preserving the performance order within
0122             % each type.
0123             [~,idx] = sort( obj.Datatype );
0124             obj = reorderFunctions( obj, idx );
0125         end
0126         
0127         function obj = reorderFunctions( obj, idx )
0128             assert( numel(idx) == numel(obj.LongName) );
0129             obj.PeakFLOPS = obj.PeakFLOPS(:,idx);
0130             obj.FunctionName = obj.FunctionName(idx);
0131             obj.LongName = obj.LongName(idx);
0132             obj.Datatype = obj.Datatype(idx);
0133         end % reorderFunctions
0134         
0135     end % Protected methods
0136     
0137 end
0138

Community support and wiki are available on Redmine. Last update: 18-Apr-2019.