使用TVM和WebGL后端编译优化的神经网络

时间:2019-05-07 11:01:24

标签: python python-3.x llvm cross-compiling asm.js

我正在按照[tvm文档中给出的示例]尝试针对WebGL后端编译使用TVM(python)优化的神经网络。 (https://github.com/dmlc/nnvm/blob/master/tutorials/from_mxnet_to_webgl.py)。 我只更改了代码中的变量run_deploy_web,并将其设置为True的顶部,以运行所需的示例。

问题是我得到了错误:

Loading pretrained resnet model from MXNet...
- Model loaded!
Compiling the neural network...
[11:23:05] /home/SERILOCAL/n.perto/Documents/tvm/src/runtime/opengl/opengl_device_api.cc:227: OpenGL initialized, version = 4.3 (Core Profile) Mesa 17.2.8
Traceback (most recent call last):
  File "from_mxnet_to_webgl.py", line 515, in <module>
    deploy_web()
  File "from_mxnet_to_webgl.py", line 462, in deploy_web
    params=params)
  File "from_mxnet_to_webgl.py", line 243, in compile_net
    params=params)
  File "/home/SERILOCAL/n.perto/Documents/tvm/nnvm/python/nnvm/compiler/build_module.py", line 321, in build
    graph = graph.apply("GraphCompile")
  File "/home/SERILOCAL/n.perto/Documents/tvm/nnvm/python/nnvm/graph.py", line 250, in apply
    check_call(_LIB.NNGraphApplyPasses(self.handle, npass, cpass, ctypes.byref(ghandle)))
  File "/home/SERILOCAL/n.perto/Documents/tvm/nnvm/python/nnvm/_base.py", line 91, in check_call
    raise NNVMError(py_str(_LIB.NNGetLastError()))
nnvm._base.NNVMError: TVMError: Check failed: allow_null: No available targets are compatible with this triple. target_triple=asmjs-unknown-emscripten
Stack trace:
  File "/home/SERILOCAL/n.perto/Documents/tvm/src/codegen/llvm/llvm_common.cc", line 162
  [bt] (0) /home/SERILOCAL/n.perto/Documents/tvm/build/libtvm.so(+0x8eff6d) [0x7f7200ff7f6d]
  [bt] (1) /home/SERILOCAL/n.perto/Documents/tvm/build/libtvm.so(+0x8e6ad5) [0x7f7200feead5]
  [bt] (2) /home/SERILOCAL/n.perto/Documents/tvm/build/libtvm.so(+0x8e529b) [0x7f7200fed29b]
  [bt] (3) /home/SERILOCAL/n.perto/Documents/tvm/build/libtvm.so(+0x274f6e) [0x7f720097cf6e]
  [bt] (4) /home/SERILOCAL/n.perto/Documents/tvm/build/libtvm.so(+0x195158) [0x7f720089d158]
  [bt] (5) /home/SERILOCAL/n.perto/Documents/tvm/build/libtvm.so(TVMFuncCall+0x61) [0x7f720101f001]
    raise get_last_ffi_error()
  File "/home/SERILOCAL/n.perto/Documents/tvm/python/tvm/_ffi/_ctypes/function.py", line 206, in __call__
    return _Build(lowered_func, target)
  File "/home/SERILOCAL/n.perto/Documents/tvm/python/tvm/codegen.py", line 36, in build_module
    mhost = codegen.build_module(fhost_all, str(target_host))
  File "/home/SERILOCAL/n.perto/Documents/tvm/python/tvm/build_module.py", line 623, in build
    return tvm.build(funcs, target=target, target_host=target_host)
  File "/home/SERILOCAL/n.perto/Documents/tvm/nnvm/python/nnvm/compiler/build_module.py", line 140, in _build
    rv = local_pyfunc(*pyargs)
  File "/home/SERILOCAL/n.perto/Documents/tvm/python/tvm/_ffi/_ctypes/function.py", line 71, in cfun
Stack trace:
  [bt] (0) /home/SERILOCAL/n.perto/Documents/tvm/build/libtvm.so(+0x913b7b) [0x7f720101bb7b]
  [bt] (1) /home/SERILOCAL/n.perto/Documents/tvm/nnvm/python/nnvm/../../lib/libnnvm_compiler.so(nnvm::compiler::GraphCompile(nnvm::Graph const&)+0x28bd) [0x7f71fa47e08d]
  [bt] (2) /home/SERILOCAL/n.perto/Documents/tvm/nnvm/python/nnvm/../../lib/libnnvm_compiler.so(std::_Function_handler<nnvm::Graph (nnvm::Graph), nnvm::Graph (*)(nnvm::Graph const&)>::_M_invoke(std::_Any_data const&, nnvm::Graph&&)+0x20) [0x7f71fa4788b0]
  [bt] (3) /home/SERILOCAL/n.perto/Documents/tvm/nnvm/python/nnvm/../../lib/libnnvm_compiler.so(nnvm::ApplyPasses(nnvm::Graph, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&)+0x32b) [0x7f71fa4ab95b]
  [bt] (4) /home/SERILOCAL/n.perto/Documents/tvm/nnvm/python/nnvm/../../lib/libnnvm_compiler.so(NNGraphApplyPasses+0x348) [0x7f71fa4a1ef8]
  [bt] (5) /home/SERILOCAL/n.perto/.anaconda3/envs/tf/lib/python3.6/lib-dynload/../../libffi.so.6(ffi_call_unix64+0x4c) [0x7f72030abec0]
  [bt] (6) /home/SERILOCAL/n.perto/.anaconda3/envs/tf/lib/python3.6/lib-dynload/../../libffi.so.6(ffi_call+0x22d) [0x7f72030ab87d]
  [bt] (7) /home/SERILOCAL/n.perto/.anaconda3/envs/tf/lib/python3.6/lib-dynload/_ctypes.cpython-36m-x86_64-linux-gnu.so(_ctypes_callproc+0x2ce) [0x7f7205c12ede]
  [bt] (8) /home/SERILOCAL/n.perto/.anaconda3/envs/tf/lib/python3.6/lib-dynload/_ctypes.cpython-36m-x86_64-linux-gnu.so(+0x13915) [0x7f7205c13915]

这行应该是问题所在:

nnvm._base.NNVMError: TVMError: Check failed: allow_null: No available targets are compatible with this triple. target_triple=asmjs-unknown-emscripten

Emscripten先前已通过sdk工具安装:

emsdk install latest
emsdk activate latest

source emsdk_env.sh

(在理智的会话中所做的一切,否则我会提供脚本来初始化环境)

脚本中尝试构建一些代码的部分如下:

# As usual, compile the model.
graph, lib, params = compile_net(
    net,
    target_host="llvm -target=asmjs-unknown-emscripten -system-lib",
    target="opengl",
    data_shape=data_shape,
    params=params)

我还没有配置有关emscripten sdk的其他任何东西。 在fastcomp的文档中,据说它与llvm紧密集成,因此我认为从sdk工具运行安装后它应该可以无缝运行,但是也许我需要更多配置。

这也可能是tvm文档中的pyhton示例,该示例已经过时,只需进行少量修改即可使用新版本的工具链。

由于我从未使用过这些工具,因此所有这些工具一起使用使我有点不知所措,并且不知道该在哪里寻找错误,您的帮助将不胜感激。

谢谢。

0 个答案:

没有答案