How to build TVM with OpenCL


#1

when i reproduce benchmark on Mobile-gpu:
python3 mobile_gpu_imagenet_bench.py --model rk3399 --rpc-key rk3399

i got the following error:

[10:43:05] /home/zzw/tvm/src/pass/vectorize_loop.cc:343: Detect vector condition in Vectorized Loop, scalarizing…
[10:43:05] /home/zzw/tvm/src/pass/vectorize_loop.cc:343: Detect vector condition in Vectorized Loop, scalarizing…
[10:43:05] /home/zzw/tvm/src/pass/vectorize_loop.cc:343: Detect vector condition in Vectorized Loop, scalarizing…
[10:43:05] /home/zzw/tvm/src/pass/vectorize_loop.cc:343: Detect vector condition in Vectorized Loop, scalarizing…
[10:43:05] /home/zzw/tvm/src/runtime/opencl/opencl_device_api.cc:244: No OpenCL platform matched given existing options …
Traceback (most recent call last):
File “mobile_gpu_imagenet_bench.py”, line 88, in
evaluate_network(network, target, target_host, args.dtype, args.repeat)
File “mobile_gpu_imagenet_bench.py”, line 44, in evaluate_network
rlib = remote.load_module(filename)
File “/home/zzw/tvm/python/tvm/rpc/client.py”, line 132, in load_module
return base._LoadRemoteModule(self._sess, path)
File “/home/zzw/tvm/python/tvm/_ffi/_ctypes/function.py”, line 190, in call
raise get_last_ffi_error()
tvm._ffi.base.TVMError: Traceback (most recent call last):
[bt] (8) /home/firefly/tvm/build/libtvm.so(+0xc1e68c) [0x7f96ecb68c]
[bt] (7) /home/firefly/tvm/build/libtvm.so(+0xc1e360) [0x7f96ecb360]
[bt] (6) /home/firefly/tvm/build/libtvm.so(+0xc23efc) [0x7f96ed0efc]
[bt] (5) /home/firefly/tvm/build/libtvm.so(+0xc23448) [0x7f96ed0448]
[bt] (4) /home/firefly/tvm/build/libtvm.so(+0xc22368) [0x7f96ecf368]
[bt] (3) /home/firefly/tvm/build/libtvm.so(+0xc1c8cc) [0x7f96ec98cc]
[bt] (2) /home/firefly/tvm/build/libtvm.so(+0xc21c2c) [0x7f96ecec2c]
[bt] (1) /home/firefly/tvm/build/libtvm.so(+0xc1d6e4) [0x7f96eca6e4]
[bt] (0) /home/firefly/tvm/build/libtvm.so(+0xbdc600) [0x7f96e89600]
File “/home/firefly/tvm/python/tvm/_ffi/_ctypes/function.py”, line 55, in cfun
rv = local_pyfunc(*pyargs)
File “/home/firefly/tvm/python/tvm/rpc/server.py”, line 50, in load_module
m = _load_module(path)
File “/home/firefly/tvm/python/tvm/module.py”, line 244, in load
return _LoadFromFile(path, fmt)
File “/home/firefly/tvm/python/tvm/_ffi/_ctypes/function.py”, line 190, in call
raise get_last_ffi_error()
[bt] (4) /home/firefly/tvm/build/libtvm.so(TVMFuncCall+0x70) [0x7f96e8c6e8]
[bt] (3) /home/firefly/tvm/build/libtvm.so(+0xbf1fb4) [0x7f96e9efb4]
[bt] (2) /home/firefly/tvm/build/libtvm.so(tvm::runtime::Module::LoadFromFile(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)+0x3c0) [0x7f96e9c618]
[bt] (1) /home/firefly/tvm/build/libtvm.so(+0xbe3934) [0x7f96e90934]
[bt] (0) /home/firefly/tvm/build/libtvm.so(+0xbf69b0) [0x7f96ea39b0]
File “/home/firefly/tvm/src/runtime/module_util.cc”, line 36
TVMError: Except caught from RPC call: TVMError: Check failed: f != nullptr: Loader of opencl(module.loadbinary_opencl) is not presented.

Before that, i have install OpenCL by:
sudo apt install ocl-icd-libopencl1
sudo apt install opencl-headers
sudo apt install clinfo
sudo apt install ocl-icd-opencl-dev

and then i build TVM with OpenCL by:
cmake..
make -j4
I am sure that it is successfully build.


Can't deploy the model remotely by RPC to RK3399
[SOLVED] Using OpenCL without LLVM
#2

Do you have an OpenCL installation that gives you a libOpenCL.so? This is essentially the driver.

e.g., check that your LD_LIBRARY_PATH has a libOpenCL.so


#3

I find libOpenCL.so at /usr/lib/x86_64-linux-gnu, and then i add the path to ./bashrc
export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu

but the same error occurred, when
python3 mobile_gpu_imagenet_bench.py --model rk3399 --rpc-key rk3399


#4

Then, i install the opencl-sdk, errors change a little, which occurs at:
[22:59:46] /home/zzw/tvm/src/runtime/opencl/opencl_device_api.cc:254: Using CPU OpenCL device

the other errors are same as above.


#5

Did you rebuild the runtime with OpenCL enabled after this step?


#6

yeah, I follow the step in the picture to rebuild the runtime with OpenCL successfully on the RK3399, but it doesn’t work.

and I also try to install the opencl-header according the following picture,


but, when i run ./clpeak, nothing presents.


#7

who can help me solve this error?


#8

yeah, I follow the step in the picture to rebuild the runtime with OpenCL successfully on the RK3399, but it doesn’t work.


#9

First, i have rebuild the TVM runtime with OpenCL:

firefly@firefly:~/tvm$ make runtime -j4
– Build with RPC support…
– Build with Graph runtime support…
– Build VTA runtime with target: sim
– Build with OpenCL support
– Build with contrib.sort
– Build with contrib.hybriddump
– Configuring done
– Generating done
– Build files have been written to: /home/firefly/tvm/build
make[1]: Entering directory ‘/home/firefly/tvm/build’
make[2]: Entering directory ‘/home/firefly/tvm/build’
make[3]: Entering directory ‘/home/firefly/tvm/build’
make[4]: Entering directory ‘/home/firefly/tvm/build’
make[4]: Leaving directory ‘/home/firefly/tvm/build’
[100%] Built target tvm_runtime
make[4]: Entering directory ‘/home/firefly/tvm/build’
make[4]: Leaving directory ‘/home/firefly/tvm/build’
[100%] Built target runtime
make[3]: Leaving directory ‘/home/firefly/tvm/build’
make[2]: Leaving directory ‘/home/firefly/tvm/build’
make[1]: Leaving directory ‘/home/firefly/tvm/build’

Is there something wroung?

and then I rerun the benchmark:


#10

Can you trying running a simple OpenCL example (not in TVM) on the board itself to verify that the runtime is working properly?

Note that the advice of having LD_LIBRARY_PATH include a path to libOpenCL.so is for the device running the TVM runtime, not on your host machine…
On my rk3399 board it is just in /usr/local/lib/


#11

Thank you for your reply.
The problems have been solved, the reseaon is that I flash the wroung Ubuntu to rk3399, so command ‘clinfo’ doesn’t work.