Fix compilation error found in tflite test (#3820)

ps. https://github.com/bytecodealliance/wasm-micro-runtime/pull/3817
This commit is contained in:
liang.he 2024-10-08 09:54:39 +08:00 committed by GitHub
parent 6b4d8aae2a
commit 30539bf50c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 139 additions and 51 deletions

View File

@ -103,7 +103,6 @@ docker run \
wasi-nn-cpu \ wasi-nn-cpu \
--dir=/ \ --dir=/ \
--env="TARGET=cpu" \ --env="TARGET=cpu" \
--native-lib=/lib/libwasi-nn-tflite.so \
/assets/test_tensorflow.wasm /assets/test_tensorflow.wasm
``` ```
@ -119,7 +118,6 @@ docker run \
wasi-nn-nvidia-gpu \ wasi-nn-nvidia-gpu \
--dir=/ \ --dir=/ \
--env="TARGET=gpu" \ --env="TARGET=gpu" \
--native-lib=/lib/libwasi-nn-tflite.so \
/assets/test_tensorflow.wasm /assets/test_tensorflow.wasm
``` ```
@ -131,7 +129,6 @@ docker run \
wasi-nn-vx-delegate \ wasi-nn-vx-delegate \
--dir=/ \ --dir=/ \
--env="TARGET=gpu" \ --env="TARGET=gpu" \
--native-lib=/lib/libwasi-nn-tflite.so \
/assets/test_tensorflow_quantized.wasm /assets/test_tensorflow_quantized.wasm
``` ```
@ -147,7 +144,6 @@ docker run \
wasi-nn-tpu \ wasi-nn-tpu \
--dir=/ \ --dir=/ \
--env="TARGET=tpu" \ --env="TARGET=tpu" \
--native-lib=/lib/libwasi-nn-tflite.so \
/assets/test_tensorflow_quantized.wasm /assets/test_tensorflow_quantized.wasm
``` ```
@ -155,8 +151,8 @@ docker run \
Supported: Supported:
- Graph encoding: `tensorflowlite`. - Graph encoding: `tensorflowlite`, `openvino` and `ggml`
- Execution target: `cpu`, `gpu` and `tpu`. - Execution target: `cpu` for all. `gpu` and `tpu` for `tensorflowlite`.
- Tensor type: `fp32`. - Tensor type: `fp32`.
## Smoke test ## Smoke test

View File

@ -4,13 +4,21 @@
include(FetchContent) include(FetchContent)
set(CJSON_SOURCE_DIR "${WAMR_ROOT_DIR}/core/deps/cjson") set(CJSON_SOURCE_DIR "${WAMR_ROOT_DIR}/core/deps/cjson")
if(EXISTS ${CJSON_SOURCE_DIR})
FetchContent_Declare( message("Use existed source code under ${CJSON_SOURCE_DIR}")
cjson FetchContent_Declare(
GIT_REPOSITORY https://github.com/DaveGamble/cJSON.git cjson
GIT_TAG v1.7.18 SOURCE_DIR ${CJSON_SOURCE_DIR}
SOURCE_DIR ${CJSON_SOURCE_DIR} )
) else()
message("download source code and store it at ${CJSON_SOURCE_DIR}")
FetchContent_Declare(
cjson
GIT_REPOSITORY https://github.com/DaveGamble/cJSON.git
GIT_TAG v1.7.18
SOURCE_DIR ${CJSON_SOURCE_DIR}
)
endif()
set(ENABLE_CJSON_TEST OFF CACHE INTERNAL "Turn off tests") set(ENABLE_CJSON_TEST OFF CACHE INTERNAL "Turn off tests")
set(ENABLE_CJSON_UNINSTALL OFF CACHE INTERNAL "Turn off uninstall to avoid targets conflict") set(ENABLE_CJSON_UNINSTALL OFF CACHE INTERNAL "Turn off uninstall to avoid targets conflict")

View File

@ -4,13 +4,21 @@
include(FetchContent) include(FetchContent)
set(LLAMA_SOURCE_DIR "${WAMR_ROOT_DIR}/core/deps/llama.cpp") set(LLAMA_SOURCE_DIR "${WAMR_ROOT_DIR}/core/deps/llama.cpp")
if(EXISTS ${LLAMA_SOURCE_DIR})
FetchContent_Declare( message("Use existed source code under ${LLAMA_SOURCE_DIR}")
llamacpp FetchContent_Declare(
GIT_REPOSITORY https://github.com/ggerganov/llama.cpp.git llamacpp
GIT_TAG b3573 SOURCE_DIR ${LLAMA_SOURCE_DIR}
SOURCE_DIR ${LLAMA_SOURCE_DIR} )
) else()
message("download source code and store it at ${LLAMA_SOURCE_DIR}")
FetchContent_Declare(
llamacpp
GIT_REPOSITORY https://github.com/ggerganov/llama.cpp.git
GIT_TAG b3573
SOURCE_DIR ${LLAMA_SOURCE_DIR}
)
endif()
set(LLAMA_BUILD_TESTS OFF) set(LLAMA_BUILD_TESTS OFF)
set(LLAMA_BUILD_EXAMPLES OFF) set(LLAMA_BUILD_EXAMPLES OFF)

View File

@ -4,20 +4,32 @@
include(FetchContent) include(FetchContent)
set(TFLITE_SOURCE_DIR "${WAMR_ROOT_DIR}/core/deps/tensorflow-src") set(TFLITE_SOURCE_DIR "${WAMR_ROOT_DIR}/core/deps/tensorflow-src")
if(EXISTS ${TFLITE_SOURCE_DIR})
message("Use existed source code under ${TFLITE_SOURCE_DIR}")
FetchContent_Declare(
tensorflow_lite
SOURCE_DIR ${TFLITE_SOURCE_DIR}
SOURCE_SUBDIR tensorflow/lite
)
else()
message("download source code and store it at ${TFLITE_SOURCE_DIR}")
FetchContent_Declare(
tensorflow_lite
GIT_REPOSITORY https://github.com/tensorflow/tensorflow.git
GIT_TAG v2.12.0
GIT_SHALLOW ON
GIT_PROGRESS ON
SOURCE_DIR ${TFLITE_SOURCE_DIR}
SOURCE_SUBDIR tensorflow/lite
PATCH_COMMAND git apply ${CMAKE_CURRENT_LIST_DIR}/add_telemetry.patch
)
endif()
FetchContent_Declare(
tensorflow_lite
GIT_REPOSITORY https://github.com/tensorflow/tensorflow.git
GIT_TAG v2.12.0
GIT_SHALLOW ON
GIT_PROGRESS ON
SOURCE_DIR ${TFLITE_SOURCE_DIR}
SOURCE_SUBDIR tensorflow/lite
)
if(WAMR_BUILD_WASI_NN_ENABLE_GPU EQUAL 1) if(WAMR_BUILD_WASI_NN_ENABLE_GPU EQUAL 1)
set(TFLITE_ENABLE_GPU ON) set(TFLITE_ENABLE_GPU ON)
endif() endif()
if (CMAKE_SIZEOF_VOID_P EQUAL 4) if (CMAKE_SIZEOF_VOID_P EQUAL 4)
set(TFLITE_ENABLE_XNNPACK OFF) set(TFLITE_ENABLE_XNNPACK OFF)
endif() endif()

View File

@ -0,0 +1,12 @@
diff --git a/tensorflow/lite/CMakeLists.txt b/tensorflow/lite/CMakeLists.txt
index c71a3925ac..39591a3bd7 100644
--- a/tensorflow/lite/CMakeLists.txt
+++ b/tensorflow/lite/CMakeLists.txt
@@ -493,6 +493,7 @@ set(TFLITE_PROFILER_SRCS
${TFLITE_SOURCE_DIR}/profiling/root_profiler.h
${TFLITE_SOURCE_DIR}/profiling/root_profiler.cc
${TFLITE_SOURCE_DIR}/profiling/telemetry/profiler.cc
+ ${TFLITE_SOURCE_DIR}/profiling/telemetry/telemetry.cc
)
if(CMAKE_SYSTEM_NAME MATCHES "Android")
list(APPEND TFLITE_PROFILER_SRCS

View File

@ -14,19 +14,32 @@ WORKDIR /usr/local/share/ca-certificates/cacert.org
RUN wget -qP /usr/local/share/ca-certificates/cacert.org http://www.cacert.org/certs/root.crt http://www.cacert.org/certs/class3.crt \ RUN wget -qP /usr/local/share/ca-certificates/cacert.org http://www.cacert.org/certs/root.crt http://www.cacert.org/certs/class3.crt \
&& update-ca-certificates && update-ca-certificates
# need a newer cmake
RUN apt-get purge -y cmake
ARG CMAKE_VER=3.27.0
RUN wget https://github.com/Kitware/CMake/releases/download/v${CMAKE_VER}/cmake-${CMAKE_VER}-Linux-x86_64.sh \
-q -O /tmp/cmake-install.sh \
&& chmod u+x /tmp/cmake-install.sh \
&& mkdir /opt/cmake-${CMAKE_VER} \
&& /tmp/cmake-install.sh --skip-license --prefix=/opt/cmake-${CMAKE_VER} \
&& rm /tmp/cmake-install.sh \
&& ln -s /opt/cmake-${CMAKE_VER}/bin/* /usr/local/bin
WORKDIR /home/wamr WORKDIR /home/wamr
COPY . . COPY . .
RUN git config --global http.sslCAinfo /etc/ssl/certs/ca-certificates.crt RUN git config --global http.sslCAinfo /etc/ssl/certs/ca-certificates.crt
WORKDIR /home/wamr/product-mini/platforms/linux WORKDIR /home/wamr/product-mini/platforms/linux
RUN rm -rf build \ RUN rm -rf build \
&& cmake -S . -B build -DWAMR_BUILD_WASI_NN=1 \ && cmake -S . -B build\
-DWAMR_BUILD_WASI_NN=1 -DWAMR_BUILD_WASI_NN_TFLITE=1\
&& cmake --build build -j "$(grep -c ^processor /proc/cpuinfo)" && cmake --build build -j "$(grep -c ^processor /proc/cpuinfo)"
FROM ubuntu:22.04 FROM ubuntu:22.04
COPY --from=base /home/wamr/product-mini/platforms/linux/build/iwasm /usr/bin/iwasm COPY --from=base /home/wamr/product-mini/platforms/linux/build/iwasm /usr/bin
COPY --from=base /home/wamr/product-mini/platforms/linux/build/libiwasm.so /lib/libiwasm.so COPY --from=base /home/wamr/product-mini/platforms/linux/build/lib*.so /usr/lib
COPY --from=base /home/wamr/product-mini/platforms/linux/build/libwasi-nn-*.so /lib/ ENV LD_LIBRARY_PATH=/usr/lib
ENTRYPOINT [ "iwasm" ] ENTRYPOINT [ "iwasm" ]

View File

@ -14,14 +14,26 @@ WORKDIR /usr/local/share/ca-certificates/cacert.org
RUN wget -qP /usr/local/share/ca-certificates/cacert.org http://www.cacert.org/certs/root.crt http://www.cacert.org/certs/class3.crt \ RUN wget -qP /usr/local/share/ca-certificates/cacert.org http://www.cacert.org/certs/root.crt http://www.cacert.org/certs/class3.crt \
&& update-ca-certificates && update-ca-certificates
# need a newer cmake
RUN apt-get purge -y cmake
ARG CMAKE_VER=3.27.0
RUN wget https://github.com/Kitware/CMake/releases/download/v${CMAKE_VER}/cmake-${CMAKE_VER}-Linux-x86_64.sh \
-q -O /tmp/cmake-install.sh \
&& chmod u+x /tmp/cmake-install.sh \
&& mkdir /opt/cmake-${CMAKE_VER} \
&& /tmp/cmake-install.sh --skip-license --prefix=/opt/cmake-${CMAKE_VER} \
&& rm /tmp/cmake-install.sh \
&& ln -s /opt/cmake-${CMAKE_VER}/bin/* /usr/local/bin
WORKDIR /home/wamr WORKDIR /home/wamr
COPY . . COPY . .
RUN git config --global http.sslCAinfo /etc/ssl/certs/ca-certificates.crt RUN git config --global http.sslCAinfo /etc/ssl/certs/ca-certificates.crt
WORKDIR /home/wamr/product-mini/platforms/linux/build WORKDIR /home/wamr/product-mini/platforms/linux
RUN rm -rf build \ RUN rm -rf build \
&& cmake -S . -B build \ && cmake -S . -B build \
-DWAMR_BUILD_WASI_NN=1 \ -DWAMR_BUILD_WASI_NN=1 -DWAMR_BUILD_WASI_NN_TFLITE=1\
-DWAMR_BUILD_WASI_NN_ENABLE_GPU=1 \ -DWAMR_BUILD_WASI_NN_ENABLE_GPU=1 \
&& cmake --build build -j "$(grep -c ^processor /proc/cpuinfo)" && cmake --build build -j "$(grep -c ^processor /proc/cpuinfo)"
@ -40,8 +52,8 @@ RUN mkdir -p /etc/OpenCL/vendors && \
ENV NVIDIA_VISIBLE_DEVICES=all ENV NVIDIA_VISIBLE_DEVICES=all
ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility
COPY --from=base /home/wamr/product-mini/platforms/linux/build/iwasm /usr/bin/iwasm COPY --from=base /home/wamr/product-mini/platforms/linux/build/iwasm /usr/bin
COPY --from=base /home/wamr/product-mini/platforms/linux/build/libiwasm.so /lib/libiwasm.so COPY --from=base /home/wamr/product-mini/platforms/linux/build/lib*.so /usr/lib
COPY --from=base /home/wamr/product-mini/platforms/linux/build/libwasi-nn-*.so /lib/ ENV LD_LIBRARY_PATH=/usr/lib
ENTRYPOINT [ "iwasm" ] ENTRYPOINT [ "iwasm" ]

View File

@ -14,22 +14,35 @@ WORKDIR /usr/local/share/ca-certificates/cacert.org
RUN wget -qP /usr/local/share/ca-certificates/cacert.org http://www.cacert.org/certs/root.crt http://www.cacert.org/certs/class3.crt \ RUN wget -qP /usr/local/share/ca-certificates/cacert.org http://www.cacert.org/certs/root.crt http://www.cacert.org/certs/class3.crt \
&& update-ca-certificates && update-ca-certificates
# need a newer cmake
RUN apt-get purge -y cmake
ARG CMAKE_VER=3.27.0
RUN wget https://github.com/Kitware/CMake/releases/download/v${CMAKE_VER}/cmake-${CMAKE_VER}-Linux-x86_64.sh \
-q -O /tmp/cmake-install.sh \
&& chmod u+x /tmp/cmake-install.sh \
&& mkdir /opt/cmake-${CMAKE_VER} \
&& /tmp/cmake-install.sh --skip-license --prefix=/opt/cmake-${CMAKE_VER} \
&& rm /tmp/cmake-install.sh \
&& ln -s /opt/cmake-${CMAKE_VER}/bin/* /usr/local/bin
WORKDIR /home/wamr WORKDIR /home/wamr
COPY . . COPY . .
RUN git config --global http.sslCAinfo /etc/ssl/certs/ca-certificates.crt RUN git config --global http.sslCAinfo /etc/ssl/certs/ca-certificates.crt
WORKDIR /home/wamr/product-mini/platforms/linux WORKDIR /home/wamr/product-mini/platforms/linux
RUN rm -rf build \ RUN rm -rf build \
&& cmake -S . -B build -DWAMR_BUILD_WASI_NN=1 \ && cmake -S . -B build\
-DWAMR_BUILD_WASI_NN=1 \ -DWAMR_BUILD_WASI_NN=1\
-DWAMR_BUILD_WASI_NN_TFLITE=1\
-DWAMR_BUILD_WASI_NN_ENABLE_EXTERNAL_DELEGATE=1 \ -DWAMR_BUILD_WASI_NN_ENABLE_EXTERNAL_DELEGATE=1 \
-DWAMR_BUILD_WASI_NN_EXTERNAL_DELEGATE_PATH="libedgetpu.so.1.0" \ -DWAMR_BUILD_WASI_NN_EXTERNAL_DELEGATE_PATH="libedgetpu.so.1.0" \
-DWAMR_BUILD_WASI_NN_ENABLE_GPU=1 \ -DWAMR_BUILD_WASI_NN_ENABLE_GPU=1 \
&& cmake --build build -j "$(grep -c ^processor /proc/cpuinfo)" && cmake --build build -j "$(grep -c ^processor /proc/cpuinfo)"
RUN cp /home/wamr/product-mini/platforms/linux/build/iwasm /usr/bin/iwasm \ RUN cp /home/wamr/core/iwasm/libraries/wasi-nn/test/build/iwasm /run/iwasm \
&& cp /home/wamr/product-mini/platforms/linux/build/libiwasm.so /lib/libiwasm.so \ && cp /home/wamr/product-mini/platforms/linux/build/lib*.so /usr/lib
&& cp /home/wamr/product-mini/platforms/linux/build/libwasi-nn-*.so /lib/ ENV LD_LIBRARY_PATH=/usr/lib
WORKDIR /assets WORKDIR /assets
ENTRYPOINT [ "iwasm" ] ENTRYPOINT [ "iwasm" ]

View File

@ -21,6 +21,18 @@ RUN apt-get update && apt-get install -y wget ca-certificates --no-install-recom
&& update-ca-certificates \ && update-ca-certificates \
&& git config --global http.sslCAinfo /etc/ssl/certs/ca-certificates.crt && git config --global http.sslCAinfo /etc/ssl/certs/ca-certificates.crt
# need a newer cmake
RUN apt-get purge -y cmake
ARG CMAKE_VER=3.27.0
RUN wget https://github.com/Kitware/CMake/releases/download/v${CMAKE_VER}/cmake-${CMAKE_VER}-Linux-x86_64.sh \
-q -O /tmp/cmake-install.sh \
&& chmod u+x /tmp/cmake-install.sh \
&& mkdir /opt/cmake-${CMAKE_VER} \
&& /tmp/cmake-install.sh --skip-license --prefix=/opt/cmake-${CMAKE_VER} \
&& rm /tmp/cmake-install.sh \
&& ln -s /opt/cmake-${CMAKE_VER}/bin/* /usr/local/bin
# Build TensorFlow Lite VX delegate default built for x86-64 simulator # Build TensorFlow Lite VX delegate default built for x86-64 simulator
WORKDIR /tmp WORKDIR /tmp
RUN git clone https://github.com/VeriSilicon/TIM-VX.git tim-vx \ RUN git clone https://github.com/VeriSilicon/TIM-VX.git tim-vx \
@ -89,7 +101,6 @@ ENV VSIMULATOR_CONFIG=czl
ENV LD_LIBRARY_PATH=/tmp/tim-vx/prebuilt-sdk/x86_64_linux/lib:/usr/local/lib:/lib/x86_64-linux-gnu/:/lib64/:/usr/lib:$LD_LIBRARY_PATH ENV LD_LIBRARY_PATH=/tmp/tim-vx/prebuilt-sdk/x86_64_linux/lib:/usr/local/lib:/lib/x86_64-linux-gnu/:/lib64/:/usr/lib:$LD_LIBRARY_PATH
# Build WASI-NN # Build WASI-NN
WORKDIR /home/wamr WORKDIR /home/wamr
@ -102,12 +113,14 @@ RUN cmake \
-DCMAKE_LIBRARY_PATH=${CMAKE_LIBRARY_PATH}:/usr/local/lib/ \ -DCMAKE_LIBRARY_PATH=${CMAKE_LIBRARY_PATH}:/usr/local/lib/ \
-DCMAKE_INCLUDE_PATH=${CMAKE_INCLUDE_PATH}:/usr/local/include/ \ -DCMAKE_INCLUDE_PATH=${CMAKE_INCLUDE_PATH}:/usr/local/include/ \
-DWAMR_BUILD_WASI_NN=1 \ -DWAMR_BUILD_WASI_NN=1 \
-DWAMR_BUILD_WASI_NN_TFLITE=1\
-DWAMR_BUILD_WASI_NN_ENABLE_EXT=1 \ -DWAMR_BUILD_WASI_NN_ENABLE_EXT=1 \
-DWASI_NN_EXT_DELEGATE_PATH="/usr/lib/libvx_delegate.so" \ -DWASI_NN_EXT_DELEGATE_PATH="/usr/lib/libvx_delegate.so" \
.. ..
RUN make -j "$(grep -c ^processor /proc/cpuinfo)" RUN make -j "$(grep -c ^processor /proc/cpuinfo)"
RUN cp /home/wamr/core/iwasm/libraries/wasi-nn/test/build/iwasm /run/iwasm RUN cp /home/wamr/core/iwasm/libraries/wasi-nn/test/build/iwasm /run/iwasm \
&& cp /home/wamr/product-mini/platforms/linux/build/lib*.so /usr/lib
ENTRYPOINT [ "/run/iwasm" ] ENTRYPOINT [ "/run/iwasm" ]

View File

@ -8,9 +8,9 @@ CURR_PATH=$(cd $(dirname $0) && pwd -P)
# WASM application that uses WASI-NN # WASM application that uses WASI-NN
/opt/wasi-sdk/bin/clang \ /opt/wasi-sdk/bin/clang \
--target=wasm32-wasi \
-DNN_LOG_LEVEL=1 \
-Wl,--allow-undefined \ -Wl,--allow-undefined \
-Wl,--strip-all,--no-entry \
--sysroot=/opt/wasi-sdk/share/wasi-sysroot \
-I../include -I../src/utils \ -I../include -I../src/utils \
-o test_tensorflow.wasm \ -o test_tensorflow.wasm \
test_tensorflow.c utils.c test_tensorflow.c utils.c
@ -28,9 +28,9 @@ python3 sum.py
cd ${CURR_PATH} cd ${CURR_PATH}
/opt/wasi-sdk/bin/clang \ /opt/wasi-sdk/bin/clang \
--target=wasm32-wasi \
-DNN_LOG_LEVEL=1 \
-Wl,--allow-undefined \ -Wl,--allow-undefined \
-Wl,--strip-all,--no-entry \
--sysroot=/opt/wasi-sdk/share/wasi-sysroot \
-I../include -I../src/utils \ -I../include -I../src/utils \
-o test_tensorflow_quantized.wasm \ -o test_tensorflow_quantized.wasm \
test_tensorflow_quantized.c utils.c test_tensorflow_quantized.c utils.c

View File

@ -1,2 +1,2 @@
tensorflow==2.12.1 tensorflow==2.12.1
numpy==1.26.4 numpy==1.24.4

View File

@ -5,6 +5,7 @@
#include "utils.h" #include "utils.h"
#include "logger.h" #include "logger.h"
#include "wasi_nn.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -57,7 +58,7 @@ wasm_load(char *model_name, graph *g, execution_target target)
wasi_nn_error wasi_nn_error
wasm_load_by_name(const char *model_name, graph *g) wasm_load_by_name(const char *model_name, graph *g)
{ {
wasm_nn_error res = load_by_name(model_name, g); wasi_nn_error res = load_by_name(model_name, g);
return res; return res;
} }