PerformanceData

PURPOSE ^

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 classdef PerformanceData
0002     %PERFORMANCEDATA  a class to store GPUBench performance data
0003     %
0004     %   p = gpuBench measures some performance data for your currently
0005     %   selected GPU. Do not use this class directly - always use gpuBench
0006     %   to create the data.
0007     %
0008     %   See also: gpuBench
0009     
0010     %   Copyright 2011 The MathWorks, Inc.
0011     
0012     properties
0013         IsSelected
0014         IsHostData
0015     end
0016     
0017     properties (SetAccess=private)
0018         MATLABRelease
0019         CPUInfo
0020         GPUInfo
0021         Results
0022         Timestamp
0023     end
0024     
0025     methods
0026         function obj = PerformanceData( release, cpuinfo, gpuinfo, timestamp )
0027             % Construct a new performance data object
0028             obj.MATLABRelease = release;
0029             obj.CPUInfo = cpuinfo;
0030             obj.GPUInfo = gpuinfo;
0031             obj.Results = struct( ...
0032                 'FunctionName', {}, ...
0033                 'DataType', {}, ...
0034                 'Sizes', {}, ...
0035                 'NumOps', {}, ...
0036                 'Times', {} );
0037             obj.IsSelected = false;
0038             obj.IsHostData = false;
0039             obj.Timestamp = timestamp;
0040         end % constructor
0041         
0042         function obj = addResult( obj, fcnName, datatype, sizes, numops, times )
0043             N = numel( obj.Results );
0044             obj.Results(N+1,1).FunctionName = fcnName;
0045             obj.Results(N+1,1).DataType = datatype;
0046             obj.Results(N+1,1).Sizes = sizes;
0047             obj.Results(N+1,1).NumOps = numops;
0048             obj.Results(N+1,1).Times = times;
0049         end % addResult
0050         
0051         function out = hasResult( obj, fcnname, datatype )
0052             if nargin<3
0053                 % Name may be 'fcn (type)'
0054                 [fcnname,datatype] = iSplitName( fcnname );
0055             end
0056             nameMatches = ismember( {obj.Results.FunctionName}, fcnname );
0057             typeMatches = ismember( {obj.Results.DataType}, datatype );
0058             out = any( nameMatches & typeMatches );
0059         end % hasResult
0060         
0061         function out = getResult( obj, fcnname, datatype )
0062             if nargin<3
0063                 % Name may be 'fcn (type)'
0064                 [fcnname,datatype] = iSplitName( fcnname );
0065             end
0066             nameMatches = ismember( {obj.Results.FunctionName}, fcnname );
0067             typeMatches = ismember( {obj.Results.DataType}, datatype );
0068             idx = find( nameMatches & typeMatches, 1, 'first' );
0069             if isempty( idx )
0070                 error( 'GPUBench:PerformanceData:NoSuchData', 'No results were found for %s (%s).', ...
0071                     fcnname, datatype );
0072             end
0073             out = obj.Results(idx);
0074         end % getResult
0075         
0076         function name = getDeviceName( obj )
0077             if obj.IsHostData
0078                 name = 'Host PC';
0079             else
0080                 name = obj.GPUInfo.Name;
0081             end
0082         end
0083         
0084     end
0085     
0086 end
0087 
0088 function [fcnname,datatype] = iSplitName( longname )
0089 % Split a long name 'fcn (datatype)' into its component name and type
0090 out = regexp( longname, '(?<fcn>\w+)\s+\((?<type>\w+)\)', 'names' );
0091 fcnname = out.fcn;
0092 datatype = out.type;
0093 end

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