MCPcopy Create free account
hub / github.com/tensorflow/tfjs / time

Method time

tfjs-backend-webgpu/src/backend_webgpu.ts:649–702  ·  view source on GitHub ↗
(f: () => void)

Source from the content-addressed store, hash-verified

647 }
648
649 override async time(f: () => void): Promise<WebGPUTimingInfo> {
650 if (!this.supportTimestampQuery && !this.hasTimestampQueryWarned) {
651 console.warn(
652 `This device doesn't support timestamp-query extension. ` +
653 `Start Chrome browser with flag ` +
654 `--enable-dawn-features=allow_unsafe_apis to try it again. ` +
655 `Otherwise, zero will be shown for the kernel time when profiling ` +
656 `mode is enabled.`);
657 this.hasTimestampQueryWarned = true;
658 }
659
660 const oldActiveTimers = this.activeTimers;
661 const newActiveTimers: TimerNode[] = [];
662
663 let outerMostTime = false;
664 if (this.programTimersStack == null) {
665 this.programTimersStack = newActiveTimers;
666 outerMostTime = true;
667 } else {
668 this.activeTimers.push(newActiveTimers);
669 }
670 this.activeTimers = newActiveTimers;
671
672 f();
673
674 const flattenedActiveTimerQueries =
675 util.flatten(this.activeTimers.map((d: WebGPUKernelInfo) => d.query))
676 .filter(d => d != null);
677 const flattenedActiveTimerNames =
678 util.flatten(this.activeTimers.map((d: WebGPUKernelInfo) => d.name))
679 .filter(d => d != null);
680
681 this.activeTimers = oldActiveTimers;
682
683 if (outerMostTime) {
684 this.programTimersStack = null;
685 }
686 const res: WebGPUTimingInfo = {
687 uploadWaitMs: this.uploadWaitMs,
688 downloadWaitMs: this.downloadWaitMs,
689 kernelMs: null,
690 wallMs: null
691 };
692
693 const kernelMs = await Promise.all(flattenedActiveTimerQueries);
694 res['kernelMs'] = util.sum(kernelMs);
695 res['getExtraProfileInfo'] = () =>
696 kernelMs.map((d, i) => ({name: flattenedActiveTimerNames[i], ms: d}))
697 .map(d => `${d.name}: ${d.ms}`)
698 .join(', ');
699 this.uploadWaitMs = 0;
700 this.downloadWaitMs = 0;
701 return res;
702 }
703
704 makeTensorInfo(
705 shape: number[], dtype: DataType,

Callers

nothing calls this directly

Calls 6

flattenMethod · 0.80
allMethod · 0.80
sumMethod · 0.80
joinMethod · 0.80
fFunction · 0.50
pushMethod · 0.45

Tested by

no test coverage detected