Skip to content

Commit 268a78d

Browse files
authored
opencv: support cross-compilation and add sample function (#44)
* opencv: support cross-compilation and add sample function * nits: clean-up * func: pass --cmdline * opencv: add example doing k-NN inference * gha: re-generate wasm if we add new function * gha: few nits * cpp: bump for latest s3 * gha: make cache depend on functions too
1 parent 5cdd796 commit 268a78d

File tree

16 files changed

+345
-5
lines changed

16 files changed

+345
-5
lines changed

.github/workflows/tests.yml

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ jobs:
2828

2929
# Work-out whether we need to re-build the examples. We need to re-build the
3030
# examples if either _any_ fo the examples has changed, or the WASM cache
31-
# has expired
31+
# has expired, or the ./funcs folder have changed
3232
needs-build:
3333
if: github.event.pull_request.draft == false
3434
runs-on: ubuntu-latest
3535
outputs:
36-
needs-wasm: ${{ steps.wasm-cache.outputs.cache-hit != 'true' }}
36+
needs-wasm: ${{ (steps.wasm-cache.outputs.cache-hit != 'true') || (steps.filter.outputs.funcs-changed == 'true') }}
3737
steps:
3838
- name: "Checkout code"
3939
uses: actions/checkout@v4
@@ -52,6 +52,14 @@ jobs:
5252
path: ./wasm
5353
key: wasm-${{ steps.submodule-commit.outputs.digest }}
5454
lookup-only: true
55+
# Check if any of the submodules have been modified
56+
- uses: dorny/paths-filter@v3
57+
id: filter
58+
with:
59+
filters: |
60+
funcs-changed:
61+
- 'func/**'
62+
5563
5664
build-examples:
5765
needs: needs-build
@@ -73,6 +81,8 @@ jobs:
7381
rustup default stable
7482
rustup target add wasm32-wasip1
7583
./bin/inv_wrapper.sh rabe jwt
84+
- name: "Build OpenCV"
85+
run: ./bin/inv_wrapper.sh opencv
7686
- name: "Build FFmpeg"
7787
run: ./bin/inv_wrapper.sh ffmpeg
7888
- name: "Build ImageMagick"
@@ -93,14 +103,22 @@ jobs:
93103
run: ./bin/inv_wrapper.sh tensorflow
94104
- name: "Build PolyBench/C"
95105
run: ./bin/inv_wrapper.sh polybench polybench --native
106+
- name: "Manually re-compile libz (the sysroot has a version with atomics)"
107+
run: |
108+
git submodule update --init
109+
./bin/inv_wrapper.sh zlib
110+
working-directory: ./cpp
96111
- name: "Build functions used in the tests"
97112
run: ./bin/inv_wrapper.sh func.tests
98113
- name: "Get CPP/Python commits"
99114
id: submodule-commit
100115
run: |
101116
apt install -y zstd
102117
git config --global --add safe.directory "$GITHUB_WORKSPACE"
103-
echo "digest=$(git submodule status | awk '{ print $1; }' | md5sum | cut -d' ' -f1)" >> $GITHUB_OUTPUT
118+
submodule_digest=$(git submodule status | awk '{ print $1; }' | md5sum | awk '{ print $1}')
119+
func_digest=$(find 'func' -type f -exec md5sum {} + | sort | md5sum | awk '{ print $1 }')
120+
echo "${submodule_digest}-${func_digest}"
121+
echo "digest=$(echo -n '${submodule_digest}-${func_digest}' | md5sum | awk '{ print $1 }')" >> $GITHUB_OUTPUT
104122
# Also move to a different path to restore from
105123
mv /usr/local/faasm/wasm ./wasm
106124
# If we are here we _always_ want to overwrite the cache
@@ -168,7 +186,11 @@ jobs:
168186
run: |
169187
sudo apt install -y zstd
170188
git config --global --add safe.directory "$GITHUB_WORKSPACE"
171-
echo "digest=$(git submodule status | awk '{ print $1; }' | md5sum | cut -d' ' -f1)" >> $GITHUB_OUTPUT
189+
submodule_digest=$(git submodule status | awk '{ print $1; }' | md5sum | awk '{ print $1}')
190+
func_digest=$(find 'func' -type f -exec md5sum {} + | sort | md5sum | awk '{ print $1 }')
191+
echo "${submodule_digest}-${func_digest}"
192+
echo "digest=$(echo -n '${submodule_digest}-${func_digest}' | md5sum | awk '{ print $1 }')" >> $GITHUB_OUTPUT
193+
# echo "digest=$(git submodule status | awk '{ print $1; }' | md5sum | cut -d' ' -f1)" >> $GITHUB_OUTPUT
172194
- name: "Get WASM cache"
173195
uses: actions/cache/restore@v4
174196
id: cpp-wasm-cache
@@ -182,6 +204,14 @@ jobs:
182204
- name: "Print logs if wasm-upload fails"
183205
if: failure() && (steps.wasm-upload.outcome == 'failure')
184206
run: faasmctl logs -s upload
207+
- name: "Run OpenCV check"
208+
if: "contains(env.FAASM_WASM_VM, 'wamr')"
209+
timeout-minutes: 2
210+
run: faasmctl invoke opencv pca --cmdline "faasm://opencv/composers"
211+
- name: "Run OpenCV k-NN Inference"
212+
if: "contains(env.FAASM_WASM_VM, 'wamr')"
213+
timeout-minutes: 2
214+
run: faasmctl invoke opencv check --cmdline "faasm://opencv/bus_photo.bmp faasm://opencv/out.bmp"
185215
- name: "Run MPI kernels"
186216
timeout-minutes: 2
187217
run: |

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,6 @@
5454
[submodule "examples/tless-jwt"]
5555
path = examples/tless-jwt
5656
url = https://github.com/faasm/tless-jwt.git
57+
[submodule "examples/opencv"]
58+
path = examples/opencv
59+
url = https://github.com/opencv/opencv.git

data/beethoven.bmp

5.13 MB
Binary file not shown.

data/bus_photo.bmp

732 KB
Binary file not shown.

data/tchaikovsky.bmp

230 KB
Binary file not shown.

data/wagner.bmp

2.86 MB
Binary file not shown.

examples/opencv

Submodule opencv added at 0f23420

func/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@ add_subdirectory(ffmpeg)
3535
add_subdirectory(jwt)
3636
add_subdirectory(lammps)
3737
add_subdirectory(mpi)
38+
add_subdirectory(opencv)
3839
add_subdirectory(rabe)
3940
add_subdirectory(tf)

func/opencv/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
set(FAASM_USER opencv)
2+
3+
faasm_example_func(check check.cpp)
4+
target_link_libraries(opencv_check opencv_core opencv_imgcodecs opencv_imgproc)
5+
6+
faasm_example_func(pca pca.cpp)
7+
target_link_libraries(opencv_pca opencv_core opencv_imgcodecs opencv_imgproc opencv_ml z)

0 commit comments

Comments
 (0)