MCPcopy
hub / github.com/apache/tvm / CachedCallStack

Class CachedCallStack

web/src/memory.ts:279–498  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

277 * - reset.
278 */
279export class CachedCallStack implements Disposable {
280 /** List of temporay arguments that can be disposed during reset. */
281 tempArgs: Array<Disposable> = [];
282
283 private memory: Memory;
284 private cAllocSpace: ctypes.FTVMWasmAllocSpace;
285 private cFreeSpace: ctypes.FTVMWasmFreeSpace;
286
287 private buffer: ArrayBuffer;
288 private viewU8: Uint8Array;
289 private viewI32: Int32Array;
290 private viewU32: Uint32Array;
291 private viewF64: Float64Array;
292
293 private stackTop: PtrOffset = 0;
294 private basePtr: Pointer = 0;
295
296 private addressToSetTargetValue: Array<[PtrOffset, PtrOffset]> = [];
297
298 constructor(
299 memory: Memory,
300 allocSpace: ctypes.FTVMWasmAllocSpace,
301 freeSpace: ctypes.FTVMWasmFreeSpace
302 ) {
303 const initCallStackSize = 128;
304 this.memory = memory;
305 this.cAllocSpace = allocSpace;
306 this.cFreeSpace = freeSpace;
307 this.buffer = new ArrayBuffer(initCallStackSize);
308 this.basePtr = this.cAllocSpace(initCallStackSize);
309 this.viewU8 = new Uint8Array(this.buffer);
310 this.viewI32 = new Int32Array(this.buffer);
311 this.viewU32 = new Uint32Array(this.buffer);
312 this.viewF64 = new Float64Array(this.buffer);
313 this.updateViews();
314 }
315
316 dispose(): void {
317 if (this.basePtr != 0) {
318 this.cFreeSpace(this.basePtr);
319 this.basePtr = 0;
320 }
321 }
322 /**
323 * Rest the call stack so that it can be reused again.
324 */
325 reset(): void {
326 this.stackTop = 0;
327 assert(this.addressToSetTargetValue.length === 0);
328 while (this.tempArgs.length != 0) {
329 (this.tempArgs.pop() as Disposable).dispose();
330 }
331 }
332
333 /**
334 * Commit all the cached data to WasmMemory.
335 * This function can only be called once.
336 * No further store function should be called.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…