chore: import upstream snapshot with attribution
Lint / lint (push) Has been cancelled
CI / MacOS (push) Has been cancelled
CI / Windows (push) Has been cancelled

This commit is contained in:
wehub-resource-sync
2026-07-13 13:36:25 +08:00
commit 26446540fa
3151 changed files with 974126 additions and 0 deletions
+69
View File
@@ -0,0 +1,69 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// Load Emscripten Module, need to change path to root/lib
const path = require("path");
const fs = require("fs");
const assert = require("assert");
const tvmjs = require("../../dist");
const wasmPath = tvmjs.wasmPath();
const wasmSource = fs.readFileSync(path.join(wasmPath, "test_addone.wasm"));
const tvm = new tvmjs.Instance(
new WebAssembly.Module(wasmSource),
tvmjs.createPolyfillWASI()
);
function randomArray(length, max) {
return Array.apply(null, Array(length)).map(function () {
return Math.random() * max;
});
}
test("add one", () => {
tvm.beginScope();
// Load system library
const sysLib = tvm.systemLib();
// grab pre-loaded function
const faddOne = sysLib.getFunction("add_one");
tvm.detachFromCurrentScope(faddOne);
assert(tvm.isPackedFunc(faddOne));
const n = 124;
const A = tvm.empty(n).copyFrom(randomArray(n, 1));
const B = tvm.empty(n);
// call the function.
faddOne(A, B);
const AA = A.toArray(); // retrieve values in js array
const BB = B.toArray(); // retrieve values in js array
// verify
for (var i = 0; i < BB.length; ++i) {
assert(Math.abs(BB[i] - (AA[i] + 1)) < 1e-5);
}
tvm.endScope();
// assert auto release scope behavior
assert(sysLib.getHandle(false) == 0);
// fadd is not released because it is detached
assert(faddOne._tvmPackedCell.handle != 0);
faddOne.dispose();
assert(A.getHandle(false) == 0);
assert(B.getHandle(false) == 0);
});
+45
View File
@@ -0,0 +1,45 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
const path = require("path");
const fs = require("fs");
const assert = require("assert");
const tvmjs = require("../../dist/tvmjs.bundle")
const wasmPath = tvmjs.wasmPath();
const wasmSource = fs.readFileSync(path.join(wasmPath, "tvmjs_runtime.wasm"));
let tvm = new tvmjs.Instance(
new WebAssembly.Module(wasmSource),
tvmjs.createPolyfillWASI());
test("object", () => {
tvm.withNewScope(() => {
let data = [1, 2, 3, 4, 5, 6];
let a = tvm.empty([2, 3], "float32").copyFrom(data);
let t = tvm.makeTVMArray([]);
let b = tvm.makeTVMArray([a, t]);
// assert b instanceof tvmjs.TVMArray
assert(b instanceof tvmjs.TVMArray);
assert(b.size() == 2);
let t1 = b.get(1);
assert(t1.getHandle() == t.getHandle());
});
});
+221
View File
@@ -0,0 +1,221 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
const path = require("path");
const fs = require("fs");
const assert = require("assert");
const tvmjs = require("../../dist/tvmjs.bundle")
// for now skip exception testing
// as it may not be compatible with asyncify
const exceptionEnabled = false;
const wasmPath = tvmjs.wasmPath();
const wasmSource = fs.readFileSync(path.join(wasmPath, "tvmjs_runtime.wasm"));
let tvm = new tvmjs.Instance(
new WebAssembly.Module(wasmSource),
tvmjs.createPolyfillWASI()
);
test("GetGlobal", () => {
tvm.beginScope();
let flist = tvm.listGlobalFuncNames();
let faddOne = tvm.getGlobalFunc("tvmjs.testing.add_one");
let fecho = tvm.getGlobalFunc("testing.echo");
assert(faddOne(tvm.scalar(1, "int")) == 2);
assert(faddOne(tvm.scalar(-1, "int")) == 0);
// check function argument with different types.
assert(fecho(1123) == 1123);
assert(fecho("xyz") == "xyz");
// test long string as the abi can be different from small str
const long_str = "1234567890123456789abcdefghijklmnopqrstuvwxyz";
assert(fecho(long_str) == long_str);
let bytes = new Uint8Array([1, 2, 3]);
let rbytes = fecho(bytes);
assert(rbytes.length == bytes.length);
for (let i = 0; i < bytes.length; ++i) {
assert(rbytes[i] == bytes[i]);
}
const long_bytes = new Uint8Array(1024);
for (let i = 0; i < long_bytes.length; ++i) {
long_bytes[i] = i;
}
let rlong_bytes = fecho(long_bytes);
assert(rlong_bytes.length == long_bytes.length);
for (let i = 0; i < long_bytes.length; ++i) {
assert(rlong_bytes[i] == long_bytes[i]);
}
assert(fecho(undefined) == undefined);
tvm.beginScope();
let arr = tvm.empty([2, 2]).copyFrom([1, 2, 3, 4]);
let arr2 = fecho(arr);
assert(arr.getHandle() == arr2.getHandle());
assert(arr2.toArray().toString() == arr.toArray().toString());
tvm.moveToParentScope(arr2);
tvm.endScope();
// test move to parent scope and tracking
assert(arr.getHandle(false) == 0);
assert(arr2.handle != 0);
let mod = tvm.systemLib();
let ret = fecho(mod);
assert(ret.getHandle() == mod.getHandle());
assert(flist.length != 0);
tvm.endScope();
// assert auto release scope behavior
assert(mod.getHandle(false) == 0);
assert(ret.getHandle(false) == 0);
assert(arr2.getHandle(false) == 0);
assert(fecho._tvmPackedCell.getHandle(false) == 0);
assert(faddOne._tvmPackedCell.getHandle(false) == 0);
});
test("ReturnFunc", () => {
tvm.beginScope();
function addy(y) {
function add(x, z) {
return x + y + z;
}
return add;
}
let fecho = tvm.getGlobalFunc("testing.echo");
let myf = tvm.toPackedFunc(addy);
assert(tvm.isPackedFunc(myf));
let myf2 = tvm.toPackedFunc(myf);
assert(myf2._tvmPackedCell.handle === myf._tvmPackedCell.handle);
let f = myf(10);
assert(tvm.isPackedFunc(f));
assert(f(11, 0) == 21);
assert(f("x", 1) == "x101");
assert(f("x", "yz") == "x10yz");
fecho.dispose();
myf.dispose();
myf2.dispose();
// test multiple dispose.
f.dispose();
f.dispose();
tvm.endScope();
});
test("RegisterGlobal", () => {
tvm.beginScope();
tvm.registerFunc("xyz", function (x, y) {
return x + y;
});
let f = tvm.getGlobalFunc("xyz");
assert(f(1, 2) == 3);
f.dispose();
let syslib = tvm.systemLib();
syslib.dispose();
tvm.endScope();
});
test("ExceptionPassing", () => {
if (!exceptionEnabled) return;
tvm.beginScope();
tvm.registerFunc("throw_error", function (msg) {
throw Error(msg);
});
let f = tvm.getGlobalFunc("throw_error");
try {
f("error-xyz");
throw Error("error not caught");
} catch (error) {
assert(error.message.indexOf("error-xyz") != -1);
}
tvm.endScope();
});
test("TensorCbArg", () => {
tvm.beginScope();
let use_count = tvm.getGlobalFunc("testing.object_use_count");
let record = [];
let fcheck = tvm.toPackedFunc(function (x, retain) {
assert(use_count(x) == 2);
assert(x.handle != 0);
record.push(x);
if (retain) {
tvm.detachFromCurrentScope(x);
}
});
let x = tvm.empty([2], "float32").copyFrom([1, 2]);
assert(use_count(x) == 1);
fcheck(x, 0);
// auto-released when it is out of scope.
assert(record[0].getHandle(false) == 0);
assert(use_count(x) == 1);
fcheck(x, 1);
assert(use_count(x) == 2);
assert(record[1].handle != 0);
tvm.attachToCurrentScope(record[1]);
tvm.endScope();
assert(record[1].getHandle(false) == 0);
});
test("Logging", () => {
tvm.beginScope();
const log_info = tvm.getGlobalFunc("tvmjs.testing.log_info_str");
log_info("helow world")
log_info.dispose();
tvm.endScope();
});
test("AsyncifyFunc", async () => {
if (!tvm.asyncifyEnabled()) {
console.log("Skip asyncify tests as it is not enabled..");
return;
}
tvm.beginScope();
tvm.registerAsyncifyFunc("async_sleep_echo", async function (x) {
await new Promise(resolve => setTimeout(resolve, 10));
return x;
});
let fecho = tvm.wrapAsyncifyPackedFunc(
tvm.getGlobalFunc("async_sleep_echo")
);
let fcall = tvm.wrapAsyncifyPackedFunc(
tvm.getGlobalFunc("tvmjs.testing.call")
);
assert((await fecho(1)) == 1);
assert((await fecho(2)) == 2);
assert((await fcall(fecho, 2) == 2));
tvm.endScope();
assert(fecho._tvmPackedCell.getHandle(false) == 0);
assert(fcall._tvmPackedCell.getHandle(false) == 0);
});
+69
View File
@@ -0,0 +1,69 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
const tvmjs = require("../../dist");
test("Test coverage of [0,100] inclusive", () => {
const covered = Array(100);
const rng = new tvmjs.LinearCongruentialGenerator();
for (let i = 0; i < 100000; i++) {
covered[rng.nextInt() % 100] = true;
}
const notCovered = [];
for (let i = 0; i < 100; i++) {
if (!covered[i]) {
notCovered.push(i);
}
}
expect(notCovered).toEqual([]);
});
test("Test whether the same seed make two RNGs generate same results", () => {
const rng1 = new tvmjs.LinearCongruentialGenerator();
const rng2 = new tvmjs.LinearCongruentialGenerator();
rng1.setSeed(42);
rng2.setSeed(42);
for (let i = 0; i < 100; i++) {
expect(rng1.randomFloat()).toBeCloseTo(rng2.randomFloat());
}
});
test("Test two RNGs with different seeds generate different results", () => {
const rng1 = new tvmjs.LinearCongruentialGenerator();
const rng2 = new tvmjs.LinearCongruentialGenerator();
rng1.setSeed(41);
rng2.setSeed(42);
let numSame = 0;
const numTest = 100;
// Generate `numTest` random numbers, make sure not all are the same.
for (let i = 0; i < numTest; i++) {
if (rng1.nextInt() === rng2.nextInt()) {
numSame += 1;
}
}
expect(numSame < numTest).toBe(true);
});
test('Illegal argument to `setSeed()`', () => {
expect(() => {
const rng1 = new tvmjs.LinearCongruentialGenerator();
rng1.setSeed(42.5);
}).toThrow("Seed should be an integer.");
});
+56
View File
@@ -0,0 +1,56 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
const path = require("path");
const fs = require("fs");
const assert = require("assert");
const tvmjs = require("../../dist/tvmjs.bundle")
const wasmPath = tvmjs.wasmPath();
const wasmSource = fs.readFileSync(path.join(wasmPath, "tvmjs_runtime.wasm"));
let tvm = new tvmjs.Instance(
new WebAssembly.Module(wasmSource),
tvmjs.createPolyfillWASI()
);
// Basic fields.
assert(tvm.listGlobalFuncNames() !== undefined);
// Test ndarray
function testArrayCopy(dtype, arrayType) {
let data = [1, 2, 3, 4, 5, 6];
let a = tvm.empty([2, 3], dtype).copyFrom(data);
assert(a.device.toString() == "cpu:0");
assert(a.shape[0] == 2 && a.shape[1] == 3);
let ret = a.toArray();
assert(ret instanceof arrayType);
assert(ret.toString() == arrayType.from(data).toString());
}
test("array copy", () => {
tvm.withNewScope(() => {
testArrayCopy("float32", Float32Array);
testArrayCopy("int", Int32Array);
testArrayCopy("int8", Int8Array);
testArrayCopy("uint8", Uint8Array);
testArrayCopy("float64", Float64Array);
});
});
+64
View File
@@ -0,0 +1,64 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// Load Emscripten Module, need to change path to root/lib
const path = require("path");
const fs = require("fs");
const assert = require("assert");
const tvmjs = require("../../dist");
const wasmPath = tvmjs.wasmPath();
const wasmSource = fs.readFileSync(path.join(wasmPath, "test_relax.wasm"));
const tvm = new tvmjs.Instance(
new WebAssembly.Module(wasmSource),
tvmjs.createPolyfillWASI()
);
function randomArray(length, max) {
return Array.apply(null, Array(length)).map(function () {
return Math.random() * max;
});
}
test("add one", () => {
tvm.beginScope();
// Load system library
const vm = tvm.createVirtualMachine(tvm.cpu());
// grab pre-loaded function
const fadd = vm.getFunction("main");
assert(tvm.isPackedFunc(fadd));
const n = 124;
const A = tvm.empty(n).copyFrom(randomArray(n, 1));
const B = tvm.empty(n).copyFrom(randomArray(n, 1));
// call the function.
const C = fadd(A, B);
const AA = A.toArray(); // retrieve values in js array
const BB = B.toArray(); // retrieve values in js array
const CC = C.toArray(); // retrieve values in js array
// verify
for (var i = 0; i < BB.length; ++i) {
assert(Math.abs(CC[i] - (AA[i] + BB[i])) < 1e-5);
}
tvm.endScope();
// assert auto release scope behavior
assert(vm.mod.getHandle(false) == 0);
assert(fadd._tvmPackedCell.getHandle(false) == 0);
});
+65
View File
@@ -0,0 +1,65 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# Prepare test library for standalone wasm runtime test.
import os
import tvm
from tvm import relax, te
from tvm.contrib import tvmjs
from tvm.script import relax as R
def prepare_relax_lib(base_path):
pipeline = relax.get_pipeline()
@tvm.script.ir_module
class Mod:
@R.function
def main(x: R.Tensor(["n"], "float32"), y: R.Tensor(["n"], "float32")):
lv0 = R.add(x, y)
return lv0
target = tvm.target.Target({"kind": "llvm", "mtriple": "wasm32-unknown-unknown-wasm"})
mod = pipeline(Mod)
ex = relax.build(mod, target)
wasm_path = os.path.join(base_path, "test_relax.wasm")
ex.export_library(wasm_path, fcompile=tvmjs.create_tvmjs_wasm)
def prepare_tir_lib(base_path):
target = {"kind": "llvm", "mtriple": "wasm32-unknown-unknown-wasm"}
if not tvm.runtime.enabled("llvm"):
raise RuntimeError(f"Target {target} is not enbaled")
n = te.var("n")
A = te.placeholder((n,), name="A")
B = te.compute(A.shape, lambda *i: A(*i) + 1.0, name="B")
mod = tvm.IRModule.from_expr(
te.create_prim_func([A, B]).with_attr("global_symbol", "add_one")
).with_attr("system_lib_prefix", "")
fadd = tvm.build(mod, target)
wasm_path = os.path.join(base_path, "test_addone.wasm")
fadd.export_library(wasm_path, fcompile=tvmjs.create_tvmjs_wasm)
if __name__ == "__main__":
curr_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))
base_path = os.path.join(curr_path, "../../dist/wasm")
prepare_tir_lib(base_path)
prepare_relax_lib(base_path)
+91
View File
@@ -0,0 +1,91 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
"""Test relax vm through rpc."""
import numpy as np
import tvm
from tvm import relax, rpc
from tvm.contrib import tvmjs
from tvm.script import relax as R
from tvm.support import utils
proxy_host = "127.0.0.1"
proxy_port = 9090
def get_model():
pipeline = relax.get_pipeline()
@tvm.script.ir_module
class Mod:
@R.function
def main(x: R.Tensor([1024], "float32"), y: R.Tensor([1024], "float32")):
lv0 = R.add(x, y)
return lv0
mod = pipeline(Mod)
sch = tvm.s_tir.Schedule(mod)
# manually transform loop
sch.work_on("add")
(i,) = sch.get_loops(block=sch.get_sblock("T_add"))
i0, i1 = sch.split(i, [None, 128])
sch.bind(i0, "blockIdx.x")
sch.bind(i1, "threadIdx.x")
return sch.mod
def test_rpc():
if not tvm.runtime.enabled("rpc"):
return
n = 1024
dtype = "float32"
temp = utils.tempdir()
wasm_path = temp.relpath("relax.wasm")
target = tvm.target.Target(
"webgpu", host={"kind": "llvm", "mtriple": "wasm32-unknown-unknown-wasm"}
)
mod = get_model()
ex = relax.build(mod, target)
ex.export_library(wasm_path, fcompile=tvmjs.create_tvmjs_wasm)
wasm_binary = open(wasm_path, "rb").read()
remote = rpc.connect(
proxy_host,
proxy_port,
key="wasm",
session_constructor_args=["rpc.WasmSession", wasm_binary],
)
def check(remote):
dev = remote.webgpu(0)
# invoke the function
vm = relax.VirtualMachine(remote.system_lib(), device=dev)
adata = np.random.uniform(size=n).astype(dtype)
bdata = np.random.uniform(size=n).astype(dtype)
a = tvm.runtime.tensor(adata, dev)
b = tvm.runtime.tensor(bdata, dev)
vm.set_input("main", a, b)
vm.invoke_stateful("main")
c = vm.get_outputs("main")
np.testing.assert_equal(c.numpy(), a.numpy() + b.numpy())
check(remote)
test_rpc()
+83
View File
@@ -0,0 +1,83 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
"""Simple testcode to test Javascript RPC
To use it, start a rpc proxy with "python -m tvm.exec.rpc_proxy".
Connect javascript end to the websocket port and connect to the RPC.
"""
import numpy as np
import tvm
from tvm import rpc, te
from tvm.contrib import tvmjs
from tvm.support import utils
proxy_host = "127.0.0.1"
proxy_port = 9090
def test_rpc():
if not tvm.runtime.enabled("rpc"):
return
# generate the wasm library
target = tvm.target.Target(
"webgpu", host={"kind": "llvm", "mtriple": "wasm32-unknown-unknown-wasm"}
)
n = te.var("n")
A = te.placeholder((n,), name="A")
B = te.compute(A.shape, lambda *i: te.log(te.abs(A(*i) + 1)), name="B")
mod = tvm.IRModule.from_expr(te.create_prim_func([A, B]))
sch = tvm.s_tir.Schedule(mod)
(i,) = sch.get_loops(block=sch.get_sblock("B"))
i0, i1 = sch.split(i, [None, 32])
sch.bind(i0, "blockIdx.x")
sch.bind(i1, "threadIdx.x")
fadd = tvm.build(sch.mod.with_attr("system_lib_prefix", ""), target=target)
temp = utils.tempdir()
wasm_path = temp.relpath("addone_gpu.wasm")
fadd.export_library(wasm_path, fcompile=tvmjs.create_tvmjs_wasm)
wasm_binary = open(wasm_path, "rb").read()
remote = rpc.connect(
proxy_host,
proxy_port,
key="wasm",
session_constructor_args=["rpc.WasmSession", wasm_binary],
)
def check(remote, size):
# basic function checks.
dev = remote.webgpu(0)
adata = np.random.uniform(size=size).astype(A.dtype)
a = tvm.runtime.tensor(adata, dev)
b = tvm.runtime.tensor(np.zeros(size, dtype=A.dtype), dev)
np.testing.assert_equal(a.numpy(), adata)
f1 = remote.system_lib()
addone = f1.get_function("main")
addone(a, b)
tvm.testing.assert_allclose(b.numpy(), np.log(np.abs(a.numpy()) + 1), atol=1e-5, rtol=1e-5)
print("Test pass..")
check(remote, 71821 * 32)
test_rpc()