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

Class TVMObject

web/src/runtime.ts:436–489  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

434 * Generic object base
435 */
436export class TVMObject implements Disposable {
437 protected handle: Pointer;
438 protected lib: FFILibrary;
439 protected ctx: RuntimeContext;
440
441 constructor(
442 handle: Pointer,
443 lib: FFILibrary,
444 ctx: RuntimeContext
445 ) {
446 this.handle = handle;
447 this.lib = lib;
448 this.ctx = ctx;
449 }
450
451 dispose(): void {
452 if (this.handle != 0) {
453 this.lib.checkCall(
454 (this.lib.exports.TVMFFIObjectDecRef as ctypes.FTVMFFIObjectDecRef)(this.handle)
455 );
456 this.handle = 0;
457 }
458 }
459
460 /**
461 * Get handle of module, check it is not null.
462 *
463 * @param requireNotNull require handle is not null.
464 * @returns The handle.
465 */
466 getHandle(requireNotNull = true): Pointer {
467 if (requireNotNull && this.handle === 0) {
468 throw Error("Object has already been disposed");
469 }
470 return this.handle;
471 }
472
473 /** get the type index of the object */
474 typeIndex(): number {
475 if (this.handle === 0) {
476 throw Error("The current Object has already been disposed");
477 }
478 return this.lib.memory.loadObjectTypeIndex(this.handle);
479 }
480
481 /** get the type key of the object */
482 typeKey(): string {
483 const type_index = this.typeIndex();
484 const typeInfoPtr = (this.lib.exports.TVMFFIGetTypeInfo as ctypes.FTVMFFIGetTypeInfo)(
485 type_index
486 );
487 return this.lib.memory.loadTypeInfoTypeKey(typeInfoPtr);
488 }
489}
490
491/**
492 * Cell holds the PackedFunc object.

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…