Skip to content

Commit ae31f47

Browse files
authored
[WASM] Update support for latest emcc, add ffi test. (#6751)
1 parent 2d8ac1d commit ae31f47

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

python/tvm/contrib/emcc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def create_tvmjs_wasm(output, objects, options=None, cc="emcc"):
4242
cmd += ["-O3"]
4343

4444
cmd += ["-std=c++14"]
45+
cmd += ["--no-entry"]
4546
cmd += ["-s", "ERROR_ON_UNDEFINED_SYMBOLS=0"]
4647
cmd += ["-s", "STANDALONE_WASM=1"]
4748
cmd += ["-s", "ALLOW_MEMORY_GROWTH=1"]

web/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ all: dist/wasm/tvmjs_runtime.wasm dist/wasm/tvmjs_runtime.wasi.js
2626

2727
EMCC = emcc
2828

29-
EMCC_CFLAGS = $(INCLUDE_FLAGS) -O3 -std=c++14 -Wno-ignored-attributes \
30-
-s ALLOW_MEMORY_GROWTH=1 -s STANDALONE_WASM=1 -s ERROR_ON_UNDEFINED_SYMBOLS=0
29+
EMCC_CFLAGS = $(INCLUDE_FLAGS) -O3 -std=c++14 -Wno-ignored-attributes --no-entry \
30+
-s ALLOW_MEMORY_GROWTH=1 -s STANDALONE_WASM=1 -s ERROR_ON_UNDEFINED_SYMBOLS=0
3131

3232
EMCC_LDFLAGS = --pre-js emcc/preload.js
3333

web/emcc/wasm_runtime.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,13 @@ TVM_REGISTER_GLOBAL("testing.wrap_callback").set_body([](TVMArgs args, TVMRetVal
7575
PackedFunc pf = args[0];
7676
*ret = runtime::TypedPackedFunc<void()>([pf]() { pf(); });
7777
});
78+
79+
// internal function used for debug and testing purposes
80+
TVM_REGISTER_GLOBAL("testing.object_use_count").set_body([](TVMArgs args, TVMRetValue* ret) {
81+
runtime::ObjectRef obj = args[0];
82+
// substract the current one because we always copy
83+
// and get another value.
84+
*ret = (obj.use_count() - 1);
85+
});
7886
} // namespace runtime
7987
} // namespace tvm

web/tests/node/test_packed_func.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,16 @@ test("RegisterGlobal", () => {
109109
let syslib = tvm.systemLib();
110110
syslib.dispose();
111111
});
112+
113+
test("NDArrayCbArg", () => {
114+
let use_count = tvm.getGlobalFunc("testing.object_use_count");
115+
116+
let fcheck = tvm.toPackedFunc(function (x) {
117+
assert(use_count(x) == 2);
118+
x.dispose();
119+
});
120+
let x = tvm.empty([2], "float32").copyFrom([1, 2]);
121+
assert(use_count(x) == 1);
122+
fcheck(x);
123+
assert(use_count(x) == 1);
124+
});

0 commit comments

Comments
 (0)