* Register function to be global function in tvm runtime. * @param name The name of the function. * @param func Function to be registered. * @param override Whether overwrite function in existing registry.
(
name: string,
func: PackedFunc | Function,
override = false
)
| 1085 | * @param override Whether overwrite function in existing registry. |
| 1086 | */ |
| 1087 | registerFunc( |
| 1088 | name: string, |
| 1089 | func: PackedFunc | Function, |
| 1090 | override = false |
| 1091 | ): void { |
| 1092 | this.withNewScope(() => { |
| 1093 | const autoAttachToScope = true; |
| 1094 | // packed func can be released once it is registered |
| 1095 | const packedFunc = this.toPackedFuncInternal(func, autoAttachToScope); |
| 1096 | const ioverride = override ? 1 : 0; |
| 1097 | |
| 1098 | const stack = this.lib.getOrAllocCallStack(); |
| 1099 | const nameOffset = stack.allocByteArrayForString(name); |
| 1100 | stack.commitToWasmMemory(); |
| 1101 | this.lib.checkCall( |
| 1102 | (this.lib.exports.TVMFFIFunctionSetGlobal as ctypes.FTVMFFIFunctionSetGlobal)( |
| 1103 | stack.ptrFromOffset(nameOffset), |
| 1104 | packedFunc._tvmPackedCell.getHandle(), |
| 1105 | ioverride |
| 1106 | ) |
| 1107 | ); |
| 1108 | this.lib.recycleCallStack(stack); |
| 1109 | }); |
| 1110 | } |
| 1111 | |
| 1112 | /** |
| 1113 | * Get global PackedFunc from the runtime. |
no test coverage detected