Opencl run fails: CL_INVALID_WORK_GROUP_SIZE

When I try to run a workload from the relay testing module on OpenCL I get the following error:

One or more operators have not been tuned. Please tune your model for better performance. Use DEBUG logging level to see more details.
Traceback (most recent call last):
  File "/Users/nkaminsky/Library/Application Support/JetBrains/PyCharmCE2021.1/scratches/scratch.py", line 41, in <module>
    module.run()
  File "/Users/nkaminsky/.local/lib/python3.7/site-packages/tvm-0.8.dev1845+g6a32ac57a-py3.7-macosx-10.9-x86_64.egg/tvm/contrib/graph_executor.py", line 207, in run
    self._run()
  File "tvm/_ffi/_cython/./packed_func.pxi", line 323, in tvm._ffi._cy3.core.PackedFuncBase.__call__
  File "tvm/_ffi/_cython/./packed_func.pxi", line 257, in tvm._ffi._cy3.core.FuncCall
  File "tvm/_ffi/_cython/./packed_func.pxi", line 246, in tvm._ffi._cy3.core.FuncCall3
  File "tvm/_ffi/_cython/./base.pxi", line 163, in tvm._ffi._cy3.core.CALL
tvm.error.RPCError: Traceback (most recent call last):
  [bt] (8) 9   libtvm.dylib                        0x000000011616fa16 tvm::runtime::RPCWrappedFunc::operator()(tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*) const + 1158
  [bt] (7) 8   libtvm.dylib                        0x000000011616851c tvm::runtime::RPCClientSession::CallFunc(void*, TVMValue const*, int const*, int, std::__1::function<void (tvm::runtime::TVMArgs)> const&) + 124
  [bt] (6) 7   libtvm.dylib                        0x000000011616059d tvm::runtime::RPCEndpoint::CallFunc(void*, TVMValue const*, int const*, int, std::__1::function<void (tvm::runtime::TVMArgs)>) + 333
  [bt] (5) 6   libtvm.dylib                        0x000000011615edbe tvm::runtime::RPCEndpoint::HandleUntilReturnEvent(bool, std::__1::function<void (tvm::runtime::TVMArgs)>) + 622
  [bt] (4) 5   libtvm.dylib                        0x000000011615f05e tvm::runtime::RPCEndpoint::EventHandler::HandleNextEvent(bool, bool, std::__1::function<void (tvm::runtime::TVMArgs)>) + 494
  [bt] (3) 4   libtvm.dylib                        0x0000000116163169 tvm::runtime::RPCEndpoint::EventHandler::HandleProcessPacket(std::__1::function<void (tvm::runtime::TVMArgs)>) + 393
  [bt] (2) 3   libtvm.dylib                        0x0000000116165105 tvm::runtime::RPCEndpoint::EventHandler::HandleReturn(tvm::runtime::RPCCode, std::__1::function<void (tvm::runtime::TVMArgs)>) + 213
  [bt] (1) 2   libtvm.dylib                        0x0000000114cab2a9 tvm::runtime::detail::LogFatal::Entry::Finalize() + 89
  [bt] (0) 1   libtvm.dylib                        0x00000001160fed08 tvm::runtime::Backtrace() + 24
  File "/Users/nkaminsky/code/my-tvm-android/apps/android_rpc/app/src/main/jni/../../../../../../include/../src/runtime/opencl/opencl_module.cc", line 83
  File "/Users/nkaminsky/code/my-tvm-android/src/runtime/rpc/rpc_endpoint.cc", line 376
RPCError: Error caught from RPC call:
[11:35:10] /Users/nkaminsky/code/my-tvm-android/apps/android_rpc/app/src/main/jni/../../../../../../include/../src/runtime/library_module.cc:78: 
---------------------------------------------------------------
An error occurred during the execution of TVM.
For more information, please see: https://tvm.apache.org/docs/errors.html
---------------------------------------------------------------

  Check failed: ret == 0 (-1 vs. 0) : TVMError: 
---------------------------------------------------------------
An error occurred during the execution of TVM.
For more information, please see: https://tvm.apache.org/docs/errors.html
---------------------------------------------------------------
  Check failed: (e == CL_SUCCESS) is false: OpenCL Error, code=-54: CL_INVALID_WORK_GROUP_SIZE


Process finished with exit code 1

The script that reproduces this error:

import os
import tvm
from tvm.contrib import utils, ndk, graph_executor
import numpy as np
from tvm import relay, rpc
import tvm.relay.testing


if __name__ == "__main__":
    target = tvm.target.Target("opencl", 'llvm -mtriple=arm64-linux-android')

    tracker_host = "0.0.0.0"
    tracker_port = 9111
    key = 'android'
    os.environ["TVM_NDK_CC"] = '/users/nkaminsky/library/android/android-toolchain-arm64/bin/aarch64-linux-android-g++'

    mod, params = relay.testing.mobilenet.get_workload(
        batch_size=1, layout="NCHW", dtype="float32", image_shape=(3, 224, 224)
    )

    with tvm.transform.PassContext(opt_level=3):
        lib = relay.build(mod, target=target, params=params)

    tracker = rpc.connect_tracker(tracker_host, tracker_port)
    remote = tracker.request(key, priority=0, session_timeout=0)

    device = remote.cl(0)

    tmp = utils.tempdir()
    lib_fname = tmp.relpath(f"net.so")
    fcompile = ndk.create_shared
    lib.export_library(lib_fname, fcompile)
    remote.upload(lib_fname)
    exported_lib = remote.load_module(f"net.so")
    module = graph_executor.GraphModule(exported_lib["default"](device))

    rng = np.random.default_rng(seed=0)
    dummy_input = {'input': rng.random([1, 3, 224, 224]).astype("float32")}
    tvm_dummy = {key: tvm.nd.array(input) for key, input in dummy_input.items()}
    module.set_input(**tvm_dummy)
    module.run()
    module_output = module.get_output(0).numpy()

I’m using Redmi Note 8 with an Adreno 610 GPU as my remote device. I ran this script on mac with macOS Big Sur 11.6. Thanks for the help.

Anyone knows how to fix this?

Please try running auto tuning. You got this error the default schedule we picked is not good for your device.

1 Like

This works! thank you for your help!

how can we achieve this while using llm model on an android device please suggest…