Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions tfjs-core/src/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export type ProfileInfo = {
newBytes: number; newTensors: number; peakBytes: number;
kernels: KernelInfo[];
result: TensorContainer;
kernelNames: string[];
};

export interface TimingInfo extends BackendTimingInfo {
Expand Down Expand Up @@ -119,8 +120,16 @@ class EngineState {
}>();

profiling = false;
activeProfile: ProfileInfo =
{newBytes: 0, newTensors: 0, peakBytes: 0, kernels: [], result: null};
activeProfile: ProfileInfo = {
newBytes: 0,
newTensors: 0,
peakBytes: 0,
kernels: [],
result: null,
get kernelNames() {
return Array.from(new Set(this.kernels.map(k => k.name)));
}
};

dispose() {
for (const variableName in this.registeredVariables) {
Expand Down
13 changes: 13 additions & 0 deletions tfjs-core/src/engine_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,19 @@ describeWithFlags('profile', ALL_ENVS, () => {
'extraInfo': profile.kernels[0].extraInfo
});
});

it('reports correct kernelNames', async () => {
const profile = await tf.profile(() => {
const x = tf.tensor1d([1, 2, 3]);
const x2 = x.square();
const x3 = x2.abs();
return x3;
});

expect(profile.kernelNames).toEqual(jasmine.arrayWithExactContents([
'Square', 'Abs'
]));
});
});

describeWithFlags('disposeVariables', ALL_ENVS, () => {
Expand Down
2 changes: 2 additions & 0 deletions tfjs-core/src/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ export function memory(): MemoryInfo {
* - `kernels`: an array of objects for each kernel involved that reports
* their input and output shapes, number of bytes used, and number of new
* tensors created.
* - `kernelNames`: an array of unique strings with just the names of the
* kernels in the `kernels` array.
*
* ```js
* const profile = await tf.profile(() => {
Expand Down