Skip to content

Commit

Permalink
Fix Web Build after CMake transition. (apache#2407)
Browse files Browse the repository at this point in the history
  • Loading branch information
tqchen authored Jan 9, 2019
1 parent 64e5681 commit 794bf7f
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ cpptest:
EMCC_FLAGS= -std=c++11 -DDMLC_LOG_STACK_TRACE=0\
-Oz -s RESERVED_FUNCTION_POINTERS=2 -s MAIN_MODULE=1 -s NO_EXIT_RUNTIME=1\
-s TOTAL_MEMORY=1073741824\
-s EXTRA_EXPORTED_RUNTIME_METHODS="['cwrap','getValue','setValue','addFunction']"\
-s EXTRA_EXPORTED_RUNTIME_METHODS="['addFunction','cwrap','getValue','setValue']"\
-s USE_GLFW=3 -s USE_WEBGL2=1 -lglfw\
$(INCLUDE_FLAGS)

Expand Down
4 changes: 2 additions & 2 deletions python/tvm/exec/rpc_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def find_example_resource():
index_page = os.path.join(base_path, "web/example_rpc.html")
js_files = [
os.path.join(base_path, "web/tvm_runtime.js"),
os.path.join(base_path, "lib/libtvm_web_runtime.js"),
os.path.join(base_path, "lib/libtvm_web_runtime.js.mem")
os.path.join(base_path, "build/libtvm_web_runtime.js"),
os.path.join(base_path, "build/libtvm_web_runtime.js.mem")
]
for fname in [index_page] + js_files:
if not os.path.exists(fname):
Expand Down
2 changes: 1 addition & 1 deletion tests/web/prepare_test_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ def prepare_test_libs(base_path):

if __name__ == "__main__":
curr_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))
prepare_test_libs(os.path.join(curr_path, "../../lib"))
prepare_test_libs(os.path.join(curr_path, "../../build"))
6 changes: 3 additions & 3 deletions tests/web/test_basic.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Load Emscripten Module, need to change path to root/lib
// Load Emscripten Module, need to change path to root/build
const path = require("path");
process.chdir(path.join(__dirname, "../../lib"));
var Module = require("../../lib/libtvm_web_runtime.js");
process.chdir(path.join(__dirname, "../../build"));
var Module = require("../../build/libtvm_web_runtime.js");
// Bootstrap TVMruntime with emscripten module.
const tvm_runtime = require("../../web/tvm_runtime.js");
const tvm = tvm_runtime.create(Module);
Expand Down
4 changes: 2 additions & 2 deletions tests/web/test_module_load.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Load Emscripten Module, need to change path to root/lib
const path = require("path");
process.chdir(path.join(__dirname, "../../lib"));
var Module = require("../../lib/test_module.js");
process.chdir(path.join(__dirname, "../../build"));
var Module = require("../../build/test_module.js");
// Bootstrap TVMruntime with emscripten module.
const tvm_runtime = require("../../web/tvm_runtime.js");
const tvm = tvm_runtime.create(Module);
Expand Down
6 changes: 3 additions & 3 deletions tests/web/test_packed_func.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Load Emscripten Module, need to change path to root/lib
// Load Emscripten Module, need to change path to root/build
const path = require("path");
process.chdir(path.join(__dirname, "../../lib"));
var Module = require("../../lib/libtvm_web_runtime.js");
process.chdir(path.join(__dirname, "../../build"));
var Module = require("../../build/libtvm_web_runtime.js");
// Bootstrap TVMruntime with emscripten module.
const tvm_runtime = require("../../web/tvm_runtime.js");
const tvm = tvm_runtime.create(Module);
Expand Down
12 changes: 6 additions & 6 deletions web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ to do so, make sure we set the environment correctly as in previous section and
make web
```

This will create ```lib/libtvm_web_runtime.bc``` and ```lib/libtvm_web_runtime.js```.
This will create ```build/libtvm_web_runtime.bc``` and ```build/libtvm_web_runtime.js```.

## Use TVM to Generate Javascript Library

Expand Down Expand Up @@ -87,11 +87,11 @@ def prepare_test_libs(base_path):

if __name__ == "__main__":
curr_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))
prepare_test_libs(os.path.join(curr_path, "../../lib"))
prepare_test_libs(os.path.join(curr_path, "../../build"))
```

In this workflow, we use TVM to generate a ```.bc``` file and statically link
that with the ```lib/libtvm_web_runtime.bc```(emscripten.create_js will help you do that).
that with the ```build/libtvm_web_runtime.bc```(emscripten.create_js will help you do that).
The result js library is a library that contains both TVM runtime and the compiled function.


Expand All @@ -101,10 +101,10 @@ The following code snippet from [tests/web/test_module_load.js](https://github.c
how to run the compiled library.

```js
// Load Emscripten Module, need to change path to root/lib
// Load Emscripten Module, need to change path to root/build
const path = require("path");
process.chdir(path.join(__dirname, "../../lib"));
var Module = require("../../lib/test_module.js");
process.chdir(path.join(__dirname, "../../buld"));
var Module = require("../../build/test_module.js");
// Bootstrap TVMruntime with emscripten module.
const tvm_runtime = require("../../web/tvm_runtime.js");
const tvm = tvm_runtime.create(Module);
Expand Down
1 change: 1 addition & 0 deletions web/web_runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "../src/runtime/module_util.cc"
#include "../src/runtime/system_lib_module.cc"
#include "../src/runtime/module.cc"
#include "../src/runtime/ndarray.cc"
#include "../src/runtime/registry.cc"
#include "../src/runtime/file_util.cc"
#include "../src/runtime/dso_module.cc"
Expand Down

0 comments on commit 794bf7f

Please sign in to comment.