I’m exploring what TVM can do for wasm and webgpu, however I am having some issues running it. I’ve made as much progress as I can, with one or two ugly hacks.
According to the web README, building is straightforward, just ensure that
Emscripten is set up properly, and run
However, for me (on TVM v0.10.0),
make fails with:
/tvm/include/tvm/runtime/ndarray.h:51:45: error: integer value -1 is outside the valid range of values [0, 15] for this enumeration type [-Wenum-constexpr-conversion] constexpr DLDeviceType kInvalidDeviceType = static_cast<DLDeviceType>(-1); ^ 1 error generated. emcc: error: '/root/emsdk/upstream/bin/clang++ -target wasm32-unknown-emscripten -fignore-exceptions -fvisibility=default -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -DEMSCRIPTEN --sysroot=/root/emsdk/upstream/emscripten/cache/sysroot -Xclang -iwithsysroot/include/fakesdl -Xclang -iwithsysroot/include/compat -I/tvm -I/tvm/include -I/tvm/3rdparty/dlpack/include -I/tvm/3rdparty/dmlc-core/include -I/tvm/3rdparty/compiler-rt -O3 -std=c++17 -Wno-ignored-attributes -c emcc/wasm_runtime.cc -o dist/wasm/wasm_runtime.bc' failed (returned 1)
Looking at the line that causes the error, it was committed around 2 years ago, which makes me think that it’s not the responsible party. I am able to build regular TVM with this line intact.
There is a TVM web CI test here, so I can feel somewhat confident that the feature has not fallen to bitrot. Not sure what is causing it, perhaps my environment, but I am in a freshly pulled Ubuntu 20.04 docker container.
I can fix the web build by changing the invalid device type to some other valid value, e.g. 10. And I can then run
npm install without an issue.
Now, trying to get an example running, I am following the
webgpu-example from @tqchen. It is is a few years old, so I’ve had to make a few changes, as you can see in this git diff. Most importantly, it does not seem like the file
tvmjs.bundle.js is generated any more, so I am assuming that
tvmjs_runtime.js does the same thing.
However, now the part I am stuck on is I fail with the error:
ValueError: Error when parsing target["target"]: Cannot recognize 'target'. Candidates are: cl-opt, opt-level, fast-math-contract, fast-math-nsz, fast-math-nnan, fast-math-arcp, fast-math, keys, device, tag, model, host, mcpu, num-cores, mattr, fast-math-ninf, mtriple, libs, mfloat-abi, fast-math-reassoc, from_device, mabi. Target creation from string failed: llvm -target=wasm32-unknown-unknown-wasm -system-lib
Basically it doesn’t seem like my target is valid. It is possible that the target definition for wasm has changed, but I haven’t found a more up-to-date tutorial.