This wiki explain how to run TVM Haxagon example on Hexagon simulator. Original paper is here
- OS: Ubuntu 18.04
- LLVM: llvm-10
- cmake: 3.10.2+
apt install -y python3 python3-dev python3-setuptools gcc libtinfo-dev zlib1g-dev \
build-essential cmake libedit-dev libxml2-dev llvm-10
Downoad and unzip Haxagon SDK 3.5.2 for Linux
https://developer.qualcomm.com/software/hexagon-dsp-sdk/tools
Run the installation
./qualcomm_hexagon_sdk_3_5_2_eval.bin
After the installation we need to setup environment variables
cd ~/Qualcomm/Hexagon_SDK/3.5.2
source setup_sdk_env.source
First we need to build a full version of TVM
cd ~
git clone --recursive https://github.com/apache/tvm.git
cd tvm
mkdir build
cd build
cmake .. \
-DUSE_LLVM=ON -DUSE_HEXAGON_DEVICE=sim -DUSE_HEXAGON_SDK=$HEXAGON_SDK_ROOT
make -j$(nproc)
# copy sim_dev to /usr/local/bin/
cp sim_dev-prefix/src/sim_dev-build/sim_dev /usr/local/bin/
cd ../python
python3 setup.py install
cd ~/tvm
mkdir build-hexagon
cd build-hexagon
CC=$DEFAULT_HEXAGON_TOOLS_ROOT/Tools/bin/hexagon-clang \
CXX=$DEFAULT_HEXAGON_TOOLS_ROOT/Tools/bin/hexagon-clang++ \
CXXFLAGS='-stdlib=libc++ -I${HEXAGON_SDK_ROOT}/libs/common/qurt/computev66/include/posix -I${HEXAGON_SDK_ROOT}/libs/common/qurt/computev66/include/qurt' \
cmake .. \
-DUSE_RPC=OFF -DUSE_LLVM=OFF \
-DUSE_HEXAGON_DEVICE=OFF -DUSE_HEXAGON_SDK=$HEXAGON_SDK_ROOT
make runtime -j$(nproc)
cd ~
mkdir tvm-hexagon
cd tvm-hexagon
create python file test-matmul.py
chmod +x test-matmul.py
cp ~/tvm/build-hexagon/libtvm_runtime.so .
cp $DEFAULT_HEXAGON_TOOLS_ROOT/Tools/target/hexagon/lib/v66/G0/pic/libgcc.so .
Run test-matmul.py
HEXAGON_TOOLCHAIN=$DEFAULT_HEXAGON_TOOLS_ROOT/Tools \
./test-matmul.py
[05:05:48] /root/tvm/src/runtime/hexagon/sim/hexagon_device_sim.cc:556: HexagonSimulator: Core version: v66
[00:05:49] /root/tvm/src/runtime/hexagon/sim/driver/sim_device.cc:520: TVM runtime path: libtvm_runtime.so
[05:05:49] /root/tvm/src/runtime/hexagon/sim/hexagon_device_sim.cc:608: HexagonSimulator::Alloc(size=2048, align=128)
[00:05:49] /root/tvm/src/runtime/hexagon/sim/driver/sim_device.cc:350: device: {kAlloc, 8, 102a10}
[00:05:49] /root/tvm/src/runtime/hexagon/sim/driver/sim_device.cc:183: device: allocated 2048 bytes aligned at 128: 1eea80
[05:05:49] /root/tvm/src/runtime/hexagon/sim/hexagon_device_sim.cc:514: host: execution took 48976 cycles
[05:05:49] /root/tvm/src/runtime/hexagon/sim/hexagon_device_sim.cc:617: HexagonSimulator::Alloc -> 1eea80
[[ 4 0 5 ... 15 9 4]
[10 9 5 ... 5 0 13]
[ 7 11 10 ... 11 2 4]
...
[ 7 12 12 ... 7 11 11]
[10 9 14 ... 1 13 14]
[ 7 5 15 ... 9 0 0]]
[[ 1 15 12 ... 11 15 1]
[ 5 11 2 ... 14 5 9]
[ 3 7 7 ... 12 3 13]
...
[12 4 11 ... 12 3 3]
[10 9 14 ... 12 13 2]
[14 6 15 ... 7 5 10]]
[05:05:49] /root/tvm/src/runtime/hexagon/sim/hexagon_device_sim.cc:608: HexagonSimulator::Alloc(size=2048, align=128)
[00:05:49] /root/tvm/src/runtime/hexagon/sim/driver/sim_device.cc:350: device: {kAlloc, 8, 102a10}
[00:05:49] /root/tvm/src/runtime/hexagon/sim/driver/sim_device.cc:183: device: allocated 2048 bytes aligned at 128: 1ef380
[05:05:49] /root/tvm/src/runtime/hexagon/sim/hexagon_device_sim.cc:514: host: execution took 49226 cycles
[05:05:49] /root/tvm/src/runtime/hexagon/sim/hexagon_device_sim.cc:617: HexagonSimulator::Alloc -> 1ef380
[05:05:49] /root/tvm/src/runtime/hexagon/sim/hexagon_device_sim.cc:670: HexagonSimulator::CopyHostToDevice(dst=0x1ef380, host_src=0x2da60e0, len=2048)
[05:05:49] /root/tvm/src/runtime/hexagon/sim/hexagon_device_sim.cc:608: HexagonSimulator::Alloc(size=2048, align=128)
[00:05:49] /root/tvm/src/runtime/hexagon/sim/driver/sim_device.cc:350: device: {kAlloc, 8, 102a10}
[00:05:49] /root/tvm/src/runtime/hexagon/sim/driver/sim_device.cc:183: device: allocated 2048 bytes aligned at 128: 1efc00
[05:05:49] /root/tvm/src/runtime/hexagon/sim/hexagon_device_sim.cc:514: host: execution took 48910 cycles
[05:05:49] /root/tvm/src/runtime/hexagon/sim/hexagon_device_sim.cc:617: HexagonSimulator::Alloc -> 1efc00
[05:05:49] /root/tvm/src/runtime/hexagon/sim/hexagon_device_sim.cc:670: HexagonSimulator::CopyHostToDevice(dst=0x1efc00, host_src=0x2dbeb00, len=2048)
[05:05:49] /root/tvm/src/runtime/hexagon/sim/hexagon_device_sim.cc:695: HexagonSimulator::Resolve(sym=mmult_kernel0)
[00:05:49] /root/tvm/src/runtime/hexagon/sim/driver/sim_device.cc:405: device: {kResolve, 14, 102a10}
[05:05:49] /root/tvm/src/runtime/hexagon/sim/hexagon_device_sim.cc:514: host: execution took 20656 cycles
[05:05:49] /root/tvm/src/runtime/hexagon/sim/hexagon_device_sim.cc:703: HexagonSimulator::Resolve -> 1f30f0
[05:05:49] /root/tvm/src/runtime/hexagon/sim/hexagon_device_sim.cc:709: HexagonSimulator::Call(func=0x1f30f0, scalar=0x33f27f0, sc_num=3, stack=0, st_num=0
[05:05:49] /root/tvm/src/runtime/hexagon/sim/hexagon_device_sim.cc:735: data: { 1f30f0 3 0 1eea80 1ef380 1efc00 }
[00:05:49] /root/tvm/src/runtime/hexagon/sim/driver/sim_device.cc:415: device: {kCall, 24, 102a10}
[05:05:49] /root/tvm/src/runtime/hexagon/sim/hexagon_device_sim.cc:514: host: execution took 19234 cycles
[05:05:49] /root/tvm/src/runtime/hexagon/sim/hexagon_device_sim.cc:755: HexagonSimulator::Call -> { 00 00 00 00 }
[05:05:49] /root/tvm/src/runtime/hexagon/sim/hexagon_device_sim.cc:623: HexagonSimulator::Free(ptr=0x1efc00)
[00:05:49] /root/tvm/src/runtime/hexagon/sim/driver/sim_device.cc:428: device: {kFlush}
[00:05:49] /root/tvm/src/runtime/hexagon/sim/driver/sim_device.cc:429: device: 1 tasks in the queue
[00:05:49] /root/tvm/src/runtime/hexagon/sim/driver/sim_device.cc:247: device: launching 1f30f0 sc:3 { 1eea80, 1ef380, 1efc00 }, st:0 { }
[00:05:49] /root/tvm/src/runtime/hexagon/sim/driver/sim_device.cc:440: device: execution took 76050 pcycles
[05:05:49] /root/tvm/src/runtime/hexagon/sim/hexagon_device_sim.cc:514: host: execution took 153460 cycles
[00:05:49] /root/tvm/src/runtime/hexagon/sim/driver/sim_device.cc:359: device: {kFree, 4, 102a10}
[00:05:49] /root/tvm/src/runtime/hexagon/sim/driver/sim_device.cc:216: device: freeing 1efc00
[05:05:49] /root/tvm/src/runtime/hexagon/sim/hexagon_device_sim.cc:514: host: execution took 35624 cycles
[05:05:49] /root/tvm/src/runtime/hexagon/sim/hexagon_device_sim.cc:623: HexagonSimulator::Free(ptr=0x1ef380)
[00:05:49] /root/tvm/src/runtime/hexagon/sim/driver/sim_device.cc:428: device: {kFlush}
[00:05:49] /root/tvm/src/runtime/hexagon/sim/driver/sim_device.cc:429: device: 0 tasks in the queue
[05:05:49] /root/tvm/src/runtime/hexagon/sim/hexagon_device_sim.cc:514: host: execution took 36328 cycles
[00:05:49] /root/tvm/src/runtime/hexagon/sim/driver/sim_device.cc:359: device: {kFree, 4, 102a10}
[00:05:49] /root/tvm/src/runtime/hexagon/sim/driver/sim_device.cc:216: device: freeing 1ef380
[05:05:49] /root/tvm/src/runtime/hexagon/sim/hexagon_device_sim.cc:514: host: execution took 35624 cycles
[05:05:49] /root/tvm/src/runtime/hexagon/sim/hexagon_device_sim.cc:660: HexagonSimulator::CopyDeviceToHost(host_dst=0x3004720, src=0x1eea80, len=2048)
[00:05:49] /root/tvm/src/runtime/hexagon/sim/driver/sim_device.cc:428: device: {kFlush}
[00:05:49] /root/tvm/src/runtime/hexagon/sim/driver/sim_device.cc:429: device: 0 tasks in the queue
[05:05:49] /root/tvm/src/runtime/hexagon/sim/hexagon_device_sim.cc:514: host: execution took 36328 cycles
tvm
[[1833 1867 1771 ... 2151 1903 1771]
[1288 1971 1810 ... 2143 1944 1857]
[1742 2019 1882 ... 2165 2017 1898]
...
[2203 2249 2028 ... 2050 2116 2131]
[1916 2030 1885 ... 1998 1871 2048]
[1295 1874 1796 ... 2029 1872 1721]]
numpy
[[1833 1867 1771 ... 2151 1903 1771]
[1288 1971 1810 ... 2143 1944 1857]
[1742 2019 1882 ... 2165 2017 1898]
...
[2203 2249 2028 ... 2050 2116 2131]
[1916 2030 1885 ... 1998 1871 2048]
[1295 1874 1796 ... 2029 1872 1721]]
[05:05:49] /root/tvm/src/runtime/hexagon/sim/hexagon_device_sim.cc:660: HexagonSimulator::CopyDeviceToHost(host_dst=0x3004720, src=0x1eea80, len=2048)
[00:05:49] /root/tvm/src/runtime/hexagon/sim/driver/sim_device.cc:428: device: {kFlush}
[00:05:49] /root/tvm/src/runtime/hexagon/sim/driver/sim_device.cc:429: device: 0 tasks in the queue
[05:05:49] /root/tvm/src/runtime/hexagon/sim/hexagon_device_sim.cc:514: host: execution took 36328 cycles
correct
[05:05:49] /root/tvm/src/runtime/hexagon/sim/hexagon_device_sim.cc:623: HexagonSimulator::Free(ptr=0x1eea80)
[00:05:49] /root/tvm/src/runtime/hexagon/sim/driver/sim_device.cc:428: device: {kFlush}
[00:05:49] /root/tvm/src/runtime/hexagon/sim/driver/sim_device.cc:429: device: 0 tasks in the queue
[05:05:49] /root/tvm/src/runtime/hexagon/sim/hexagon_device_sim.cc:514: host: execution took 36328 cycles
[00:05:49] /root/tvm/src/runtime/hexagon/sim/driver/sim_device.cc:359: device: {kFree, 4, 102a10}
[00:05:49] /root/tvm/src/runtime/hexagon/sim/driver/sim_device.cc:216: device: freeing 1eea80
[05:05:49] /root/tvm/src/runtime/hexagon/sim/hexagon_device_sim.cc:514: host: execution took 35614 cycles
- https://developer.qualcomm.com/blog/tvm-open-source-compiler-now-includes-initial-support-qualcomm-hexagon-dsp
- https://github.com/apache/tvm/tree/main/src/runtime/hexagon
- https://github.com/apache/tvm/tree/main/src/runtime/hexagon/sim/driver
- https://developer.qualcomm.com/software/hexagon-dsp-sdk/tools