@@ -28,7 +28,7 @@ if [[ "$1" == "-h" || "$1" == "--help" ]]; then
2828fi
2929
3030if [[ $# -eq 0 ]]; then
31- TEST_SUITES=(run_ootb_tests_ethos_u run_ootb_tests_tosa run_ootb_tests_vgf run_deit_e2e_ethos_u run_swin2sr_e2e_vgf)
31+ TEST_SUITES=(run_ootb_tests_ethos_u run_ootb_tests_tosa run_ootb_tests_vgf run_deit_e2e_ethos_u run_mobilesam_e2e_ethos_u run_swin2sr_e2e_vgf)
3232else
3333 TEST_SUITES=(" $1 " )
3434fi
@@ -164,6 +164,143 @@ run_deit_e2e_ethos_u() {
164164 echo " ${FUNCNAME} : PASS"
165165}
166166
167+ run_mobilesam_e2e_ethos_u () {
168+ echo " $FUNCNAME : Export, build, and run the MobileSAM e2e test"
169+
170+ local example_dir=" ${et_root_dir} /examples/arm/mobilesam_prompt_segmentation_example_ethos_u"
171+ local work_root=" ${et_root_dir} /arm_test/mobilesam_ootb_smoke"
172+ local export_dir=" ${work_root} /export"
173+ local artifact_dir=" ${work_root} /artifacts"
174+ local debug_dir=" ${work_root} /debug"
175+ local et_build_dir=" ${work_root} /cmake-out-arm"
176+ local quantized_aot_build_dir=" ${work_root} /quantized_ops_aot"
177+ local build_dir=" ${work_root} /runtime"
178+ local mobile_sam_source=" ${work_root} /mobile_sam/source"
179+ local image_path=" ${et_root_dir} /examples/models/dinov2/dog.jpg"
180+ local pte_path=" ${export_dir} /mobilesam_prompt_smoke.pte"
181+ local metadata_path=" ${export_dir} /mobilesam_prompt_smoke.json"
182+ local fvp_log=" ${work_root} /fvp.log"
183+ local toolchain_file=" ${et_root_dir} /examples/arm/ethos-u-setup/arm-none-eabi-gcc.cmake"
184+ local input_size=448
185+ local fvp_timelimit=" ${FVP_TIMELIMIT:- 300} "
186+ echo " ${FUNCNAME} : Work directory: ${work_root} ; existing artifacts will be reused if present"
187+
188+ mkdir -p " ${export_dir} " " ${artifact_dir} " " ${debug_dir} " " ${build_dir} "
189+
190+ setup_path_script=${et_root_dir} /examples/arm/arm-scratch/setup_path.sh
191+ source ${setup_path_script}
192+
193+ source ${et_root_dir} /backends/arm/scripts/utils.sh
194+ local n_proc=" $( get_parallel_jobs) "
195+
196+ echo " ${FUNCNAME} : Building ExecuTorch (if needed)"
197+ cmake --preset arm-baremetal -B " ${et_build_dir} "
198+ cmake --build " ${et_build_dir} " --target install -j" $n_proc "
199+
200+ echo " ${FUNCNAME} : Building host quantized AOT library"
201+ local python_executable
202+ python_executable=" $( python3 -c ' import sys; print(sys.executable)' ) "
203+ cmake \
204+ -S " ${et_root_dir} " \
205+ -B " ${quantized_aot_build_dir} " \
206+ -DCMAKE_BUILD_TYPE=Release \
207+ -DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
208+ -DEXECUTORCH_BUILD_KERNELS_QUANTIZED_AOT=ON \
209+ -DEXECUTORCH_BUILD_XNNPACK=OFF \
210+ -DPYTHON_EXECUTABLE=" ${python_executable} "
211+ cmake --build " ${quantized_aot_build_dir} " --target quantized_ops_aot_lib -j" $n_proc "
212+
213+ local quantized_ops_library
214+ quantized_ops_library=" $(
215+ find " ${quantized_aot_build_dir} /kernels/quantized" \
216+ -name ' libquantized_ops_aot_lib.*' \
217+ -type f \
218+ -print \
219+ -quit
220+ ) "
221+ [[ -n " ${quantized_ops_library} " ]] || {
222+ echo " ${FUNCNAME} : Missing quantized AOT library under ${quantized_aot_build_dir} "
223+ return 1
224+ }
225+
226+ echo " ${FUNCNAME} : Installing example requirements"
227+ pip install -r " ${example_dir} /requirements.txt"
228+
229+ echo " ${FUNCNAME} : Preparing pinned MobileSAM source"
230+ python3 " ${example_dir} /model_export/prepare_mobilesam.py" \
231+ --source-dir " ${mobile_sam_source} "
232+
233+ echo " ${FUNCNAME} : Exporting quantized MobileSAM PTE"
234+ env EXECUTORCH_QUANTIZED_OPS_AOT_LIBRARY=" ${quantized_ops_library} " \
235+ python3 " ${example_dir} /model_export/export_mobilesam.py" \
236+ --output-path " ${pte_path} " \
237+ --calibration-image " ${image_path} " \
238+ --eval-image " ${image_path} " \
239+ --mobile-sam-source " ${mobile_sam_source} " \
240+ --input-size " ${input_size} " \
241+ --point 219 193 \
242+ --num-calibration-samples 1 \
243+ --num-eval-samples 1 \
244+ --num-debug-samples 1 \
245+ --minimum-fp32-quantized-iou 0.9 \
246+ --artifact-dir " ${artifact_dir} " \
247+ --debug-output-dir " ${debug_dir} "
248+
249+ for artifact in \
250+ " ${pte_path} " \
251+ " ${metadata_path} " \
252+ " ${export_dir} /mobilesam_prompt_smoke_delegation.txt" \
253+ " ${export_dir} /mobilesam_prompt_smoke_metrics.json" ; do
254+ [[ -f " ${artifact} " ]] || {
255+ echo " ${FUNCNAME} : Missing export artifact ${artifact} "
256+ return 1
257+ }
258+ done
259+
260+ echo " ${FUNCNAME} : Configuring the MobileSAM application"
261+ cmake \
262+ -U " LIB_*" \
263+ -U executorch_DIR \
264+ -S " ${example_dir} /runtime" \
265+ -B " ${build_dir} " \
266+ -DCMAKE_TOOLCHAIN_FILE=" ${toolchain_file} " \
267+ -DET_PTE_FILE_PATH=" ${pte_path} " \
268+ -DMODEL_METADATA_PATH=" ${metadata_path} " \
269+ -DIMAGE_PATH=" ${image_path} " \
270+ -DMASK_THRESHOLD=0.0 \
271+ -DET_SEGMENTATION_DUMP_MASK=ON \
272+ -DPYTHON_EXECUTABLE=" ${python_executable} " \
273+ -DET_BUILD_DIR_PATH=" ${et_build_dir} "
274+
275+ echo " ${FUNCNAME} : Building mobilesam_prompt_segmentation_example"
276+ cmake --build " ${build_dir} " -j" $n_proc " --target mobilesam_prompt_segmentation_example
277+
278+ local elf=" ${build_dir} /mobilesam_prompt_segmentation_example"
279+
280+ echo " ${FUNCNAME} : Running on FVP"
281+ backends/arm/scripts/run_fvp.sh \
282+ --elf=" ${elf} " \
283+ --target=ethos-u85-256 \
284+ --timeout=" ${fvp_timelimit} " \
285+ --semihosting-cwd=" ${build_dir} " \
286+ --fast | tee " ${fvp_log} "
287+
288+ grep -q " Model executed successfully." " ${fvp_log} " || {
289+ echo " ${FUNCNAME} : FVP run did not report successful execution"
290+ return 1
291+ }
292+
293+ python3 " ${example_dir} /runtime/visualize_fvp_output.py" \
294+ --fvp-log " ${fvp_log} " \
295+ --input-image " ${image_path} " \
296+ --metadata " ${metadata_path} " \
297+ --reference-mask " ${debug_dir} /dog/quantized_mask.png" \
298+ --minimum-iou 0.9 \
299+ --output-dir " ${work_root} /fvp_visual"
300+
301+ echo " ${FUNCNAME} : PASS"
302+ }
303+
167304run_swin2sr_e2e_vgf () {
168305 echo " $FUNCNAME : Prepare demo assets, export FP/INT8, build, and run the Swin2SR VGF e2e test"
169306
0 commit comments