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

2024-09-28 17:15:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试为WebGL后端编译用TVM(python)优化的神经网络,遵循[TVM文档中给出的示例]。(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

(一切都是在sane会话中完成的,否则我将源代码脚本来初始化环境)

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

# 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示例,它已经过时了,只需要很少的修改就可以使用新版本的工具链。你知道吗

由于我从未使用过这些工具,所以我对所有这些工具的协同工作感到有些不知所措,不知道应该在哪里查找错误,您的帮助将不胜感激。你知道吗

谢谢。你知道吗


Tags: inpybuildtargethomesolibline