merrymercy / tvm-mali

Optimizing Mobile Deep Learning on ARM GPU with TVM
http://tvmlang.org/2018/01/16/opt-mali-gpu.html
MIT License
179 stars 28 forks source link

Encounter an error with different network model #1

Closed kaishijeng closed 6 years ago

kaishijeng commented 6 years ago

I import YOLOv2_tiny.onnx from the link below using mali on firefly3399 and got an error on nnvm.compiler.build. It looks like something wrong with conv2d which mail supports. Any idea?

https://github.com/tkat0/chainer-nnvm-example

Traceback (most recent call last): File "mali_imagenet_bench.py", line 102, in run_case('tinyYolo2', 'float32') File "mali_imagenet_bench.py", line 42, in run_case graph, lib, params = nnvm.compiler.build(net, tvm.target.mali(), shape={input_name: data_shape}, params=params, dtype=dtype, target_host=args.target_host) File "/usr/local/lib/python2.7/dist-packages/nnvm-0.8.0-py2.7.egg/nnvm/compiler/build_module.py", line 251, in build graph = graph.apply("GraphFusePartition").apply("GraphFuseCompile") File "/usr/local/lib/python2.7/dist-packages/nnvm-0.8.0-py2.7.egg/nnvm/graph.py", line 235, in apply check_call(_LIB.NNGraphApplyPasses(self.handle, npass, cpass, ctypes.byref(ghandle))) File "/usr/local/lib/python2.7/dist-packages/nnvm-0.8.0-py2.7.egg/nnvm/_base.py", line 72, in check_call raise NNVMError(py_str(_LIB.NNGetLastError())) nnvm._base.NNVMError: TVMCall CFunc Error: Traceback (most recent call last): File "tvm/_ffi/_cython/function.pxi", line 39, in core.tvm_callback (tvm/_ffi/_cython/core.cpp:3206) File "/usr/local/lib/python2.7/dist-packages/nnvm-0.8.0-py2.7.egg/nnvm/top/nn.py", line 123, in compute_conv2d out = topi.nn.conv2d(inputs[0], inputs[1], strides, padding) File "", line 2, in conv2d File "/usr/local/lib/python2.7/dist-packages/tvm-0.1.0-py2.7-linux-x86_64.egg/tvm/target.py", line 222, in dispatch_func return dispatch_dict[k](*args, **kwargs) File "build/bdist.linux-x86_64/egg/topi/mali/conv2d.py", line 100, in decl_conv2d return _decl_direct(data, kernel, stride, padding, layout, out_dtype) File "build/bdist.linux-x86_64/egg/topi/mali/conv2d.py", line 184, in _decl_direct assert OW % VW == 0, "OW: %d VW : %d" % (OW, VW) AssertionError: OW: 22 VW : 4

Thanks,

merrymercy commented 6 years ago

I did not tune the tile size for this workload. A possible quick fix can be adding these lines before this assertion.

if OW % VW != 0:
    while OW % VW != 0:
        VW //= 2
    if CO % (2 * VC) == 0:
        VC *= 2

OW is the output width of this conv layer, VW is the tile size on this dimension.

kaishijeng commented 6 years ago

Which file to change?

Thanks,

merrymercy commented 6 years ago

Add before this line

File "build/bdist.linux-x86_64/egg/topi/mali/conv2d.py", line 184, in _decl_direct
assert OW % VW == 0, "OW: %d VW : %d" % (OW, VW)
AssertionError: OW: 22 VW : 4
kaishijeng commented 6 years ago

It works with your change. However, the performance of this model on firefly is not very good (0.75sec/frame on average). I can reproduce your data of Mobilenet on my firefly3399. My main application is object detection and not able to find any object detection model which NNVM can support (missing operators in NNVM frontend). I am hoping that NNVM can support SSD-Mobilenet very soon.

Thanks,

merrymercy commented 6 years ago

Thanks for your report. The performance may not be very good for all workloads. Because currently I only tune for vgg, mobilenet, resnet on 224x224 imagenet images. For other workloads, you need re-tune parameters like tiling factor and unroll flag to get the best performance. I do not have plan to tune for your workloads manually in the near future. But an auto-tuner for tvm is on the plan. Once the auto-tuner is released, we can try it for your task.

kaishijeng commented 6 years ago

Thanks