human/src/profile.ts

33 lines
1.1 KiB
TypeScript
Raw Normal View History

2021-03-21 12:49:55 +01:00
import { log } from './helpers';
2020-12-08 15:00:44 +01:00
2021-02-08 17:39:09 +01:00
export const data = {};
2020-11-01 19:07:53 +01:00
2021-03-27 15:25:31 +01:00
export function run(modelName: string, profileData: any): void {
if (!profileData || !profileData.kernels) return;
2020-11-01 19:07:53 +01:00
const maxResults = 5;
2021-03-27 15:25:31 +01:00
const time = profileData.kernels
2020-11-01 19:07:53 +01:00
.filter((a) => a.kernelTimeMs > 0)
.reduce((a, b) => a += b.kernelTimeMs, 0);
2021-03-27 15:25:31 +01:00
const slowest = profileData.kernels
2020-11-01 19:07:53 +01:00
.map((a, i) => { a.id = i; return a; })
.filter((a) => a.kernelTimeMs > 0)
.sort((a, b) => b.kernelTimeMs - a.kernelTimeMs);
2021-03-27 15:25:31 +01:00
const largest = profileData.kernels
2020-11-01 19:07:53 +01:00
.map((a, i) => { a.id = i; return a; })
.filter((a) => a.totalBytesSnapshot > 0)
.sort((a, b) => b.totalBytesSnapshot - a.totalBytesSnapshot);
if (slowest.length > maxResults) slowest.length = maxResults;
if (largest.length > maxResults) largest.length = maxResults;
2021-03-27 15:25:31 +01:00
data[modelName] = {
model: modelName,
newBytes: profileData.newBytes,
newTensors: profileData.newTensors,
peakBytes: profileData.peakBytes,
numKernelOps: profileData.kernels.length,
timeKernelOps: time,
slowestKernelOps: slowest,
largestKernelOps: largest,
};
log('profiler', modelName, data[modelName]);
2020-11-01 19:07:53 +01:00
}