Skip to content

Commit

Permalink
[WASM] Update support for latest emcc, add ffi test. (apache#6751)
Browse files Browse the repository at this point in the history
  • Loading branch information
tqchen authored and Trevor Morris committed Dec 2, 2020
1 parent 6a5ba05 commit ac37485
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions python/tvm/contrib/emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def create_tvmjs_wasm(output, objects, options=None, cc="emcc"):
cmd += ["-O3"]

cmd += ["-std=c++14"]
cmd += ["--no-entry"]
cmd += ["-s", "ERROR_ON_UNDEFINED_SYMBOLS=0"]
cmd += ["-s", "STANDALONE_WASM=1"]
cmd += ["-s", "ALLOW_MEMORY_GROWTH=1"]
Expand Down
4 changes: 2 additions & 2 deletions web/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ all: dist/wasm/tvmjs_runtime.wasm dist/wasm/tvmjs_runtime.wasi.js

EMCC = emcc

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

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

Expand Down
8 changes: 8 additions & 0 deletions web/emcc/wasm_runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,13 @@ TVM_REGISTER_GLOBAL("testing.wrap_callback").set_body([](TVMArgs args, TVMRetVal
PackedFunc pf = args[0];
*ret = runtime::TypedPackedFunc<void()>([pf]() { pf(); });
});

// internal function used for debug and testing purposes
TVM_REGISTER_GLOBAL("testing.object_use_count").set_body([](TVMArgs args, TVMRetValue* ret) {
runtime::ObjectRef obj = args[0];
// substract the current one because we always copy
// and get another value.
*ret = (obj.use_count() - 1);
});
} // namespace runtime
} // namespace tvm
13 changes: 13 additions & 0 deletions web/tests/node/test_packed_func.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,16 @@ test("RegisterGlobal", () => {
let syslib = tvm.systemLib();
syslib.dispose();
});

test("NDArrayCbArg", () => {
let use_count = tvm.getGlobalFunc("testing.object_use_count");

let fcheck = tvm.toPackedFunc(function (x) {
assert(use_count(x) == 2);
x.dispose();
});
let x = tvm.empty([2], "float32").copyFrom([1, 2]);
assert(use_count(x) == 1);
fcheck(x);
assert(use_count(x) == 1);
});

0 comments on commit ac37485

Please sign in to comment.