Skip to content

Commit 30539bf

Browse files
authored
Fix compilation error found in tflite test (#3820)
ps. #3817
1 parent 6b4d8aa commit 30539bf

File tree

12 files changed

+139
-51
lines changed

12 files changed

+139
-51
lines changed

core/iwasm/libraries/wasi-nn/README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ docker run \
103103
wasi-nn-cpu \
104104
--dir=/ \
105105
--env="TARGET=cpu" \
106-
--native-lib=/lib/libwasi-nn-tflite.so \
107106
/assets/test_tensorflow.wasm
108107
```
109108

@@ -119,7 +118,6 @@ docker run \
119118
wasi-nn-nvidia-gpu \
120119
--dir=/ \
121120
--env="TARGET=gpu" \
122-
--native-lib=/lib/libwasi-nn-tflite.so \
123121
/assets/test_tensorflow.wasm
124122
```
125123

@@ -131,7 +129,6 @@ docker run \
131129
wasi-nn-vx-delegate \
132130
--dir=/ \
133131
--env="TARGET=gpu" \
134-
--native-lib=/lib/libwasi-nn-tflite.so \
135132
/assets/test_tensorflow_quantized.wasm
136133
```
137134

@@ -147,16 +144,15 @@ docker run \
147144
wasi-nn-tpu \
148145
--dir=/ \
149146
--env="TARGET=tpu" \
150-
--native-lib=/lib/libwasi-nn-tflite.so \
151147
/assets/test_tensorflow_quantized.wasm
152148
```
153149

154150
## What is missing
155151

156152
Supported:
157153

158-
- Graph encoding: `tensorflowlite`.
159-
- Execution target: `cpu`, `gpu` and `tpu`.
154+
- Graph encoding: `tensorflowlite`, `openvino` and `ggml`
155+
- Execution target: `cpu` for all. `gpu` and `tpu` for `tensorflowlite`.
160156
- Tensor type: `fp32`.
161157

162158
## Smoke test

core/iwasm/libraries/wasi-nn/cmake/Findcjson.cmake

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,21 @@
44
include(FetchContent)
55

66
set(CJSON_SOURCE_DIR "${WAMR_ROOT_DIR}/core/deps/cjson")
7-
8-
FetchContent_Declare(
9-
cjson
10-
GIT_REPOSITORY https://github.com/DaveGamble/cJSON.git
11-
GIT_TAG v1.7.18
12-
SOURCE_DIR ${CJSON_SOURCE_DIR}
13-
)
7+
if(EXISTS ${CJSON_SOURCE_DIR})
8+
message("Use existed source code under ${CJSON_SOURCE_DIR}")
9+
FetchContent_Declare(
10+
cjson
11+
SOURCE_DIR ${CJSON_SOURCE_DIR}
12+
)
13+
else()
14+
message("download source code and store it at ${CJSON_SOURCE_DIR}")
15+
FetchContent_Declare(
16+
cjson
17+
GIT_REPOSITORY https://github.com/DaveGamble/cJSON.git
18+
GIT_TAG v1.7.18
19+
SOURCE_DIR ${CJSON_SOURCE_DIR}
20+
)
21+
endif()
1422

1523
set(ENABLE_CJSON_TEST OFF CACHE INTERNAL "Turn off tests")
1624
set(ENABLE_CJSON_UNINSTALL OFF CACHE INTERNAL "Turn off uninstall to avoid targets conflict")

core/iwasm/libraries/wasi-nn/cmake/Findllamacpp.cmake

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,21 @@
44
include(FetchContent)
55

66
set(LLAMA_SOURCE_DIR "${WAMR_ROOT_DIR}/core/deps/llama.cpp")
7-
8-
FetchContent_Declare(
9-
llamacpp
10-
GIT_REPOSITORY https://github.com/ggerganov/llama.cpp.git
11-
GIT_TAG b3573
12-
SOURCE_DIR ${LLAMA_SOURCE_DIR}
13-
)
7+
if(EXISTS ${LLAMA_SOURCE_DIR})
8+
message("Use existed source code under ${LLAMA_SOURCE_DIR}")
9+
FetchContent_Declare(
10+
llamacpp
11+
SOURCE_DIR ${LLAMA_SOURCE_DIR}
12+
)
13+
else()
14+
message("download source code and store it at ${LLAMA_SOURCE_DIR}")
15+
FetchContent_Declare(
16+
llamacpp
17+
GIT_REPOSITORY https://github.com/ggerganov/llama.cpp.git
18+
GIT_TAG b3573
19+
SOURCE_DIR ${LLAMA_SOURCE_DIR}
20+
)
21+
endif()
1422

1523
set(LLAMA_BUILD_TESTS OFF)
1624
set(LLAMA_BUILD_EXAMPLES OFF)

core/iwasm/libraries/wasi-nn/cmake/Findtensorflow_lite.cmake

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,32 @@
44
include(FetchContent)
55

66
set(TFLITE_SOURCE_DIR "${WAMR_ROOT_DIR}/core/deps/tensorflow-src")
7+
if(EXISTS ${TFLITE_SOURCE_DIR})
8+
message("Use existed source code under ${TFLITE_SOURCE_DIR}")
9+
FetchContent_Declare(
10+
tensorflow_lite
11+
SOURCE_DIR ${TFLITE_SOURCE_DIR}
12+
SOURCE_SUBDIR tensorflow/lite
13+
)
14+
else()
15+
message("download source code and store it at ${TFLITE_SOURCE_DIR}")
16+
FetchContent_Declare(
17+
tensorflow_lite
18+
GIT_REPOSITORY https://github.com/tensorflow/tensorflow.git
19+
GIT_TAG v2.12.0
20+
GIT_SHALLOW ON
21+
GIT_PROGRESS ON
22+
SOURCE_DIR ${TFLITE_SOURCE_DIR}
23+
SOURCE_SUBDIR tensorflow/lite
24+
PATCH_COMMAND git apply ${CMAKE_CURRENT_LIST_DIR}/add_telemetry.patch
25+
)
26+
endif()
727

8-
FetchContent_Declare(
9-
tensorflow_lite
10-
GIT_REPOSITORY https://github.com/tensorflow/tensorflow.git
11-
GIT_TAG v2.12.0
12-
GIT_SHALLOW ON
13-
GIT_PROGRESS ON
14-
SOURCE_DIR ${TFLITE_SOURCE_DIR}
15-
SOURCE_SUBDIR tensorflow/lite
16-
)
1728

1829
if(WAMR_BUILD_WASI_NN_ENABLE_GPU EQUAL 1)
1930
set(TFLITE_ENABLE_GPU ON)
2031
endif()
32+
2133
if (CMAKE_SIZEOF_VOID_P EQUAL 4)
2234
set(TFLITE_ENABLE_XNNPACK OFF)
2335
endif()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
diff --git a/tensorflow/lite/CMakeLists.txt b/tensorflow/lite/CMakeLists.txt
2+
index c71a3925ac..39591a3bd7 100644
3+
--- a/tensorflow/lite/CMakeLists.txt
4+
+++ b/tensorflow/lite/CMakeLists.txt
5+
@@ -493,6 +493,7 @@ set(TFLITE_PROFILER_SRCS
6+
${TFLITE_SOURCE_DIR}/profiling/root_profiler.h
7+
${TFLITE_SOURCE_DIR}/profiling/root_profiler.cc
8+
${TFLITE_SOURCE_DIR}/profiling/telemetry/profiler.cc
9+
+ ${TFLITE_SOURCE_DIR}/profiling/telemetry/telemetry.cc
10+
)
11+
if(CMAKE_SYSTEM_NAME MATCHES "Android")
12+
list(APPEND TFLITE_PROFILER_SRCS

core/iwasm/libraries/wasi-nn/test/Dockerfile.cpu

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,32 @@ WORKDIR /usr/local/share/ca-certificates/cacert.org
1414
RUN wget -qP /usr/local/share/ca-certificates/cacert.org http://www.cacert.org/certs/root.crt http://www.cacert.org/certs/class3.crt \
1515
&& update-ca-certificates
1616

17+
# need a newer cmake
18+
RUN apt-get purge -y cmake
19+
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+
1729
WORKDIR /home/wamr
1830
COPY . .
1931
RUN git config --global http.sslCAinfo /etc/ssl/certs/ca-certificates.crt
2032

2133
WORKDIR /home/wamr/product-mini/platforms/linux
2234
RUN rm -rf build \
23-
&& cmake -S . -B build -DWAMR_BUILD_WASI_NN=1 \
35+
&& cmake -S . -B build\
36+
-DWAMR_BUILD_WASI_NN=1 -DWAMR_BUILD_WASI_NN_TFLITE=1\
2437
&& cmake --build build -j "$(grep -c ^processor /proc/cpuinfo)"
2538

2639
FROM ubuntu:22.04
2740

28-
COPY --from=base /home/wamr/product-mini/platforms/linux/build/iwasm /usr/bin/iwasm
29-
COPY --from=base /home/wamr/product-mini/platforms/linux/build/libiwasm.so /lib/libiwasm.so
30-
COPY --from=base /home/wamr/product-mini/platforms/linux/build/libwasi-nn-*.so /lib/
41+
COPY --from=base /home/wamr/product-mini/platforms/linux/build/iwasm /usr/bin
42+
COPY --from=base /home/wamr/product-mini/platforms/linux/build/lib*.so /usr/lib
43+
ENV LD_LIBRARY_PATH=/usr/lib
3144

3245
ENTRYPOINT [ "iwasm" ]

core/iwasm/libraries/wasi-nn/test/Dockerfile.nvidia-gpu

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,26 @@ WORKDIR /usr/local/share/ca-certificates/cacert.org
1414
RUN wget -qP /usr/local/share/ca-certificates/cacert.org http://www.cacert.org/certs/root.crt http://www.cacert.org/certs/class3.crt \
1515
&& update-ca-certificates
1616

17+
# need a newer cmake
18+
RUN apt-get purge -y cmake
19+
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+
1729
WORKDIR /home/wamr
1830
COPY . .
1931
RUN git config --global http.sslCAinfo /etc/ssl/certs/ca-certificates.crt
2032

21-
WORKDIR /home/wamr/product-mini/platforms/linux/build
33+
WORKDIR /home/wamr/product-mini/platforms/linux
2234
RUN rm -rf build \
2335
&& cmake -S . -B build \
24-
-DWAMR_BUILD_WASI_NN=1 \
36+
-DWAMR_BUILD_WASI_NN=1 -DWAMR_BUILD_WASI_NN_TFLITE=1\
2537
-DWAMR_BUILD_WASI_NN_ENABLE_GPU=1 \
2638
&& cmake --build build -j "$(grep -c ^processor /proc/cpuinfo)"
2739

@@ -40,8 +52,8 @@ RUN mkdir -p /etc/OpenCL/vendors && \
4052
ENV NVIDIA_VISIBLE_DEVICES=all
4153
ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility
4254

43-
COPY --from=base /home/wamr/product-mini/platforms/linux/build/iwasm /usr/bin/iwasm
44-
COPY --from=base /home/wamr/product-mini/platforms/linux/build/libiwasm.so /lib/libiwasm.so
45-
COPY --from=base /home/wamr/product-mini/platforms/linux/build/libwasi-nn-*.so /lib/
55+
COPY --from=base /home/wamr/product-mini/platforms/linux/build/iwasm /usr/bin
56+
COPY --from=base /home/wamr/product-mini/platforms/linux/build/lib*.so /usr/lib
57+
ENV LD_LIBRARY_PATH=/usr/lib
4658

4759
ENTRYPOINT [ "iwasm" ]

core/iwasm/libraries/wasi-nn/test/Dockerfile.tpu

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,35 @@ WORKDIR /usr/local/share/ca-certificates/cacert.org
1414
RUN wget -qP /usr/local/share/ca-certificates/cacert.org http://www.cacert.org/certs/root.crt http://www.cacert.org/certs/class3.crt \
1515
&& update-ca-certificates
1616

17+
# need a newer cmake
18+
RUN apt-get purge -y cmake
19+
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+
1729
WORKDIR /home/wamr
1830
COPY . .
1931
RUN git config --global http.sslCAinfo /etc/ssl/certs/ca-certificates.crt
2032

2133
WORKDIR /home/wamr/product-mini/platforms/linux
2234
RUN rm -rf build \
23-
&& cmake -S . -B build -DWAMR_BUILD_WASI_NN=1 \
24-
-DWAMR_BUILD_WASI_NN=1 \
35+
&& cmake -S . -B build\
36+
-DWAMR_BUILD_WASI_NN=1\
37+
-DWAMR_BUILD_WASI_NN_TFLITE=1\
2538
-DWAMR_BUILD_WASI_NN_ENABLE_EXTERNAL_DELEGATE=1 \
2639
-DWAMR_BUILD_WASI_NN_EXTERNAL_DELEGATE_PATH="libedgetpu.so.1.0" \
2740
-DWAMR_BUILD_WASI_NN_ENABLE_GPU=1 \
2841
&& cmake --build build -j "$(grep -c ^processor /proc/cpuinfo)"
2942

30-
RUN cp /home/wamr/product-mini/platforms/linux/build/iwasm /usr/bin/iwasm \
31-
&& cp /home/wamr/product-mini/platforms/linux/build/libiwasm.so /lib/libiwasm.so \
32-
&& cp /home/wamr/product-mini/platforms/linux/build/libwasi-nn-*.so /lib/
43+
RUN cp /home/wamr/core/iwasm/libraries/wasi-nn/test/build/iwasm /run/iwasm \
44+
&& cp /home/wamr/product-mini/platforms/linux/build/lib*.so /usr/lib
45+
ENV LD_LIBRARY_PATH=/usr/lib
3346

3447
WORKDIR /assets
3548
ENTRYPOINT [ "iwasm" ]

core/iwasm/libraries/wasi-nn/test/Dockerfile.vx-delegate

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ RUN apt-get update && apt-get install -y wget ca-certificates --no-install-recom
2121
&& update-ca-certificates \
2222
&& git config --global http.sslCAinfo /etc/ssl/certs/ca-certificates.crt
2323

24+
# need a newer cmake
25+
RUN apt-get purge -y cmake
26+
27+
ARG CMAKE_VER=3.27.0
28+
RUN wget https://github.com/Kitware/CMake/releases/download/v${CMAKE_VER}/cmake-${CMAKE_VER}-Linux-x86_64.sh \
29+
-q -O /tmp/cmake-install.sh \
30+
&& chmod u+x /tmp/cmake-install.sh \
31+
&& mkdir /opt/cmake-${CMAKE_VER} \
32+
&& /tmp/cmake-install.sh --skip-license --prefix=/opt/cmake-${CMAKE_VER} \
33+
&& rm /tmp/cmake-install.sh \
34+
&& ln -s /opt/cmake-${CMAKE_VER}/bin/* /usr/local/bin
35+
2436
# Build TensorFlow Lite VX delegate default built for x86-64 simulator
2537
WORKDIR /tmp
2638
RUN git clone https://github.com/VeriSilicon/TIM-VX.git tim-vx \
@@ -89,7 +101,6 @@ ENV VSIMULATOR_CONFIG=czl
89101

90102
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
91103

92-
93104
# Build WASI-NN
94105
WORKDIR /home/wamr
95106

@@ -102,12 +113,14 @@ RUN cmake \
102113
-DCMAKE_LIBRARY_PATH=${CMAKE_LIBRARY_PATH}:/usr/local/lib/ \
103114
-DCMAKE_INCLUDE_PATH=${CMAKE_INCLUDE_PATH}:/usr/local/include/ \
104115
-DWAMR_BUILD_WASI_NN=1 \
116+
-DWAMR_BUILD_WASI_NN_TFLITE=1\
105117
-DWAMR_BUILD_WASI_NN_ENABLE_EXT=1 \
106118
-DWASI_NN_EXT_DELEGATE_PATH="/usr/lib/libvx_delegate.so" \
107119
..
108120

109121
RUN make -j "$(grep -c ^processor /proc/cpuinfo)"
110122

111-
RUN cp /home/wamr/core/iwasm/libraries/wasi-nn/test/build/iwasm /run/iwasm
123+
RUN cp /home/wamr/core/iwasm/libraries/wasi-nn/test/build/iwasm /run/iwasm \
124+
&& cp /home/wamr/product-mini/platforms/linux/build/lib*.so /usr/lib
112125

113126
ENTRYPOINT [ "/run/iwasm" ]

core/iwasm/libraries/wasi-nn/test/build.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ CURR_PATH=$(cd $(dirname $0) && pwd -P)
88
# WASM application that uses WASI-NN
99

1010
/opt/wasi-sdk/bin/clang \
11+
--target=wasm32-wasi \
12+
-DNN_LOG_LEVEL=1 \
1113
-Wl,--allow-undefined \
12-
-Wl,--strip-all,--no-entry \
13-
--sysroot=/opt/wasi-sdk/share/wasi-sysroot \
1414
-I../include -I../src/utils \
1515
-o test_tensorflow.wasm \
1616
test_tensorflow.c utils.c
@@ -28,9 +28,9 @@ python3 sum.py
2828

2929
cd ${CURR_PATH}
3030
/opt/wasi-sdk/bin/clang \
31+
--target=wasm32-wasi \
32+
-DNN_LOG_LEVEL=1 \
3133
-Wl,--allow-undefined \
32-
-Wl,--strip-all,--no-entry \
33-
--sysroot=/opt/wasi-sdk/share/wasi-sysroot \
3434
-I../include -I../src/utils \
3535
-o test_tensorflow_quantized.wasm \
3636
test_tensorflow_quantized.c utils.c

0 commit comments

Comments
 (0)