MCPcopy Index your code
hub / github.com/apache/tvm / onInitServer

Method onInitServer

web/src/rpc_server.ts:266–396  ·  view source on GitHub ↗

Event handler during server initialization.

(
    args: Array<unknown>,
    header: Uint8Array,
    body: Uint8Array
  )

Source from the content-addressed store, hash-verified

264
265 /** Event handler during server initialization. */
266 private onInitServer(
267 args: Array<unknown>,
268 header: Uint8Array,
269 body: Uint8Array
270 ): void {
271 // start the server
272 assert(args[0] === "rpc.WasmSession");
273 assert(this.pendingBytes === 0);
274
275 const asyncInitServer = async (): Promise<void> => {
276 assert(args[1] instanceof Uint8Array);
277 const inst = await runtime.instantiate(
278 args[1].buffer as ArrayBuffer,
279 this.getImports(),
280 this.logger
281 );
282
283 try {
284 const output: GPUDeviceDetectOutput | undefined = await detectGPUDevice();
285 if (output !== undefined) {
286 const label = "WebGPU: "+ output.adapterInfo.description;
287 this.log("Initialize GPU device: " + label);
288 inst.initWebGPU(output.device);
289 } else {
290 this.log("Cannot find WebGPU device in the env");
291 }
292 } catch (err) {
293 this.log("Cannnot initialize WebGPU, " + err.toString());
294 }
295
296 this.inst = inst;
297 // begin scope to allow handling of objects
298 this.inst.beginScope();
299 if (this.initProgressCallback !== undefined) {
300 this.inst.registerInitProgressCallback(this.initProgressCallback);
301 }
302
303 if (this.tensorCacheUrl.length != 0) {
304 if (this.tensorCacheDevice === "cpu") {
305 await this.inst.fetchTensorCache(this.tensorCacheUrl, this.inst.cpu());
306 } else {
307 assert(this.tensorCacheDevice === "webgpu");
308 await this.inst.fetchTensorCache(this.tensorCacheUrl, this.inst.webgpu());
309 }
310 }
311
312 assert(this.inst !== undefined);
313 if (this.asyncOnServerLoad !== undefined) {
314 await this.asyncOnServerLoad(this.inst);
315 }
316 const fcreate = this.inst.getGlobalFunc("rpc.CreateEventDrivenServer");
317 const messageHandler = fcreate(
318 (cbytes: Uint8Array): runtime.Scalar => {
319 assert(this.inst !== undefined);
320 if (this.socket.readyState === 1) {
321 // WebSocket will automatically close the socket
322 // if we burst send data that exceeds its internal buffer
323 // wait a bit before we send next one.

Callers 1

onPacketReadyMethod · 0.95

Calls 1

assertFunction · 0.90

Tested by

no test coverage detected