Dockerfile.vx-delegate 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. # Copyright (C) 2019 Intel Corporation. All rights reserved.
  2. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  3. FROM ubuntu:20.04 AS base
  4. ENV DEBIAN_FRONTEND=noninteractive
  5. # hadolint ignore=DL3008
  6. RUN apt-get update && apt-get install -y \
  7. cmake build-essential git curl libssl-dev python3 --no-install-recommends \
  8. && apt-get clean -y \
  9. && rm -rf /var/lib/apt/lists/*
  10. # hadolint ignore=DL3008
  11. RUN apt-get update && apt-get install -y wget ca-certificates --no-install-recommends \
  12. && apt-get clean -y \
  13. && rm -rf /var/lib/apt/lists/* \
  14. && mkdir /usr/local/share/ca-certificates/cacert.org \
  15. && wget -qP /usr/local/share/ca-certificates/cacert.org http://www.cacert.org/certs/root.crt http://www.cacert.org/certs/class3.crt \
  16. && update-ca-certificates \
  17. && git config --global http.sslCAinfo /etc/ssl/certs/ca-certificates.crt
  18. # need a newer cmake
  19. RUN apt-get purge -y cmake
  20. ARG CMAKE_VER=3.27.0
  21. RUN wget https://github.com/Kitware/CMake/releases/download/v${CMAKE_VER}/cmake-${CMAKE_VER}-Linux-x86_64.sh \
  22. -q -O /tmp/cmake-install.sh \
  23. && chmod u+x /tmp/cmake-install.sh \
  24. && mkdir /opt/cmake-${CMAKE_VER} \
  25. && /tmp/cmake-install.sh --skip-license --prefix=/opt/cmake-${CMAKE_VER} \
  26. && rm /tmp/cmake-install.sh \
  27. && ln -s /opt/cmake-${CMAKE_VER}/bin/* /usr/local/bin
  28. # Build TensorFlow Lite VX delegate default built for x86-64 simulator
  29. WORKDIR /tmp
  30. RUN git clone https://github.com/VeriSilicon/TIM-VX.git tim-vx \
  31. && git clone https://github.com/VeriSilicon/tflite-vx-delegate.git \
  32. && git clone https://github.com/tensorflow/tensorflow.git --branch v2.12.0
  33. WORKDIR /tmp/tensorflow
  34. RUN git cherry-pick -n 5115fa96d7c5b41451674892317be43e30b7c389
  35. # Build TIM-VX
  36. WORKDIR /tmp/tim-vx/host_build
  37. RUN cmake -DCMAKE_INSTALL_PREFIX=/usr/local ../ \
  38. && make -j "$(grep -c ^processor /proc/cpuinfo)" \
  39. && make install
  40. WORKDIR /tmp/tim-vx
  41. #RUN mkdir -p prebuilt-sdk/x86_64_linux/lib/include
  42. #RUN cp prebuilt-sdk/x86_64_linux/include/CL prebuilt-sdk/x86_64_linux/lib/include -fr
  43. # Build TensorFlow Lite
  44. WORKDIR /tmp/tensorflow/build
  45. RUN cmake \
  46. -DBUILD_SHARED_LIBS=ON=on \
  47. -DTFLITE_ENABLE_RUY=on \
  48. -DTFLITE_ENABLE_NNAPI=off \
  49. -DTFLITE_ENABLE_XNNPACK=on \
  50. -DTFLITE_ENABLE_EXTERNAL_DELEGATE=on \
  51. ../tensorflow/lite/
  52. RUN make -j "$(grep -c ^processor /proc/cpuinfo)" \
  53. && make install \
  54. && cp --no-preserve=ownership -d lib*.so* /usr/local/lib \
  55. && cp -r --no-preserve=ownership -d flatbuffers/include/flatbuffers /usr/local/include
  56. # install header files
  57. RUN install -d /usr/local/include/tensorflow/lite
  58. WORKDIR /tmp/tensorflow/tensorflow/lite
  59. # hadolint ignore=SC2046
  60. RUN cp --parents \
  61. $(find . -name "*.h*") \
  62. /usr/local/include/tensorflow/lite
  63. # install version.h from core
  64. RUN install -d /usr/local/include/tensorflow/core/public && \
  65. cp /tmp/tensorflow/tensorflow/core/public/version.h /usr/local/include/tensorflow/core/public
  66. # Build Vx Delegate default built for x86-64 simulator
  67. WORKDIR /tmp/tflite-vx-delegate/build
  68. RUN cmake \
  69. -DBUILD_SHARED_LIBS=ON \
  70. -DFETCHCONTENT_SOURCE_DIR_TENSORFLOW=/tmp/tensorflow \
  71. -DTFLITE_LIB_LOC=/usr/local/lib/libtensorflow-lite.so \
  72. -DTIM_VX_INSTALL=/usr/local \
  73. -DCMAKE_INSTALL_PREFIX=/usr/ \
  74. ../
  75. RUN make vx_delegate -j "$(grep -c ^processor /proc/cpuinfo)" \
  76. && make install \
  77. && cp --no-preserve=ownership -d lib*.so* /usr/lib
  78. # install header files
  79. RUN install -d /usr/local/include/tensorflow-lite-vx-delegate
  80. WORKDIR /tmp/tflite-vx-delegate/
  81. # hadolint ignore=SC2046
  82. RUN cp --parents \
  83. $(find . -name "*.h*") \
  84. /usr/local/include/tensorflow-lite-vx-delegate
  85. ENV VIVANTE_SDK_DIR=/tmp/tim-vx/prebuilt-sdk/x86_64_linux/
  86. ENV VSIMULATOR_CONFIG=czl
  87. # Build WASI-NN
  88. WORKDIR /home/wamr
  89. COPY . .
  90. WORKDIR /home/wamr/product-mini/platforms/linux
  91. RUN rm -rf build \
  92. && cmake -S . -B build\
  93. -DCMAKE_LIBRARY_PATH="/usr/local/lib/" \
  94. -DCMAKE_INCLUDE_PATH="/usr/local/include/" \
  95. -DWAMR_BUILD_WASI_NN=1 \
  96. -DWAMR_BUILD_WASI_NN_TFLITE=1\
  97. -DWAMR_BUILD_WASI_NN_ENABLE_EXT=1 \
  98. -DWASI_NN_EXT_DELEGATE_PATH="/usr/lib/libvx_delegate.so" \
  99. && cmake --build build -j "$(grep -c ^processor /proc/cpuinfo)"
  100. RUN cp /home/wamr/product-mini/platforms/linux/build/iwasm /run/iwasm \
  101. && cp /home/wamr/product-mini/platforms/linux/build/lib*.so /usr/lib
  102. ENTRYPOINT [ "/run/iwasm" ]