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

Method asyncInitServer

web/src/rpc_server.ts:275–392  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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.
324 const sendDataWithCongestionControl = async (): Promise<void> => {
325 const packetSize = 4 << 10;
326 const maxBufferAmount = 4 * packetSize;
327 const waitTimeMs = 20;
328 for (
329 let offset = 0;
330 offset < cbytes.length;
331 offset += packetSize
332 ) {

Callers

nothing calls this directly

Calls 15

logMethod · 0.95
requestBytesMethod · 0.95
processEventsMethod · 0.95
assertFunction · 0.90
detectGPUDeviceFunction · 0.90
initWebGPUMethod · 0.80
fetchTensorCacheMethod · 0.80
scalarMethod · 0.80
registerFuncMethod · 0.80
closeMethod · 0.65
toStringMethod · 0.45

Tested by

no test coverage detected