I was hoping it's the model failed to segment the image, but sadly it was not the case.
(litert-samples) jacfger@engine-05 ~/n/litert-samples (main) [SIGSEGV]> ./compiled_model_api/image_segmentation/c++_segmentation/build_from_source/deploy_and_run_on_android.sh --accelerator=gpu --phone=s25 --use_gl_buffers bazel-bin/
Selected Accelerator: gpu
Selected GPU Backend: opencl
Use GL Buffers: true
Defaulting to QNN libraries path.
Defaulting to internal dispatch library path.
Starting deployment to Android device...
Using output path: bazel-bin//compiled_model_api/image_segmentation/c++_segmentation/build_from_source/cpp_segmentation_gpu
Target device directory: /data/local/tmp/cpp_segmentation_android
Created directories on device.
bazel-bin//compiled_model_api/image_segmentation/c++_segmentation/build_from_source/cpp_segmentation_gpu: 0 files pushed, 1 skipped.
Pushed executable.
compiled_model_api/image_segmentation/c++_segmentation/build_from_source/shaders/passthrough_shader.vert: 0 files pushed, 1 skipped.
compiled_model_api/image_segmentation/c++_segmentation/build_from_source/shaders/mask_blend_compute.glsl: 0 files pushed, 1 skipped.
compiled_model_api/image_segmentation/c++_segmentation/build_from_source/shaders/resize_compute.glsl: 0 files pushed, 1 skipped.
compiled_model_api/image_segmentation/c++_segmentation/build_from_source/shaders/preprocess_compute.glsl: 0 files pushed, 1 skipped.
compiled_model_api/image_segmentation/c++_segmentation/build_from_source/shaders/deinterleave_masks.glsl: 0 files pushed, 1 skipped.
Pushed shaders.
compiled_model_api/image_segmentation/c++_segmentation/build_from_source/test_images/image.jpeg: 0 files pushed, 1 skipped.
Pushed test images.
compiled_model_api/image_segmentation/c++_segmentation/build_from_source/models/selfie_multiclass_256x256.tflite: 0 files pushed, 1 skipped.
Pushed segmentation models.
bazel-bin//external/litert_archive/litert/c/libLiteRt.so: 1 file pushed, 0 skipped. 23.2 MB/s (5764896 bytes in 0.237s)
Pushed c api shared library.
bazel-bin//compiled_model_api/image_segmentation/c++_segmentation/build_from_source/cpp_segmentation_gpu.runfiles/litert_prebuilts/android_arm64//libLiteRtClGlAccelerator.so: 1 file pushed, 0 skipped. 14.2 MB/s (2845416 bytes in 0.191s)
Pushed gpu accelerator shared library.
Set execute permissions on device.
Cleaning up previous run results
Deployment complete.
To run the async segmentation on the device, use a command like this:
adb shell "cd /data/local/tmp/cpp_segmentation_android && LD_LIBRARY_PATH="/data/local/tmp/cpp_segmentation_android/npu/:/data/local/tmp/cpp_segmentation_android/:/data/local/tmp/cpp_segmentation_android/" ./cpp_segmentation_executable ./models/selfie_multiclass_256x256.t
flite ./test_images/image.jpeg ./output_segmented.png opencl true"
LiteRT GPU backend: opencl, use_gl_buffers=true
ImageProcessor: EGL Initialized. Version: 1.4
ImageProcessor: OpenGL ES Version: OpenGL ES 3.2 v1.r32p1-01bet2-mbs2v39_0.40f4de7be2ee6c932b838a20f6245c4e
ImageProcessor::SetupComputeShader: shaders/mask_blend_compute.glsl
ImageProcessor::SetupComputeShader: shaders/resize_compute.glsl
ImageProcessor::SetupComputeShader: shaders/preprocess_compute.glsl
ImageProcessor::SetupComputeShader: shaders/deinterleave_masks.glsl
INFO: [environment.cc:30] Creating LiteRT environment with options
WARNING: [auto_registration.cc:78] NPU accelerator could not be loaded and registered: kLiteRtStatusErrorInvalidArgument.
INFO: [gpu_registry.cc:162] Loading GPU accelerator(libLiteRtGpuAccelerator.so).
INFO: [gpu_registry.cc:162] Loading GPU accelerator(libLiteRtClGlAccelerator.so).
INFO: [accelerator_registry.cc:54] RegisterAccelerator: ptr=0x72a01e5900, name=LiteRT GPU
INFO: [gpu_registry.cc:170] Dynamically loaded GPU accelerator(libLiteRtClGlAccelerator.so) registered.
INFO: [accelerator_registry.cc:54] RegisterAccelerator: ptr=0x72a01e7d60, name=CpuAccelerator
INFO: [cpu_registry.cc:40] CPU accelerator registered.
INFO: [compiled_model.cc:719] Flatbuffer model initialized directly from incoming litert model.
INFO: Initialized TensorFlow Lite runtime.
Segmentation fault
CPU runs fine. But GPU fails, whether opengl backend is declared or not.
Also, during compiling, I had to enable --nocheck_visibility (which was said to be needed for NPU only, but apparently it's needed for both CPU and GPU when I ran it).
I've read both the README.md in the built from source folder and also https://developers.google.com/codelabs/litert-image-segmentation-cpp#4 So hopefully I didn't miss anything and is reproducible.
(litert-samples) jacfger@engine-05 ~/n/litert-samples (main) [SIGSEGV]> ./configure
You have bazel 7.6.1 installed.
Please specify the location of python. [Default is /home/jacfger/litert-samples/.venv/bin/python3]:
Found possible Python library paths:
/home/jacfger/litert-samples/.venv/lib/python3.11/site-packages
Please input the desired Python library path to use. Default is [/home/jacfger/litert-samples/.venv/lib/python3.11/site-packages]
Do you wish to build TensorFlow with ROCm support? [y/N]: N
No ROCm support will be enabled for TensorFlow.
Do you wish to build TensorFlow with CUDA support? [y/N]: N
No CUDA support will be enabled for TensorFlow.
Do you want to use Clang to build TensorFlow? [Y/n]: Y
Clang will be used to compile TensorFlow.
Please specify the path to clang executable. [Default is /usr/lib/llvm-18/bin/clang]:
You have Clang 18.1.3 installed.
Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -Wno-sign-compare]:
Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: y
Searching for NDK and SDK installations.
Please specify the home path of the Android NDK to use. [Default is /home/jacfger/Android/Sdk/ndk-bundle]: /home/jacfger/.local/share/Android/sdk/ndk
The path /home/jacfger/.local/share/Android/sdk/ndk or its child file "source.properties" does not exist.
Please specify the home path of the Android NDK to use. [Default is /home/jacfger/Android/Sdk/ndk-bundle]: /home/jacfger/.local/share/Android/sdk/ndk/26.3.11579264/
WARNING: The NDK version in /home/jacfger/.local/share/Android/sdk/ndk/26.3.11579264/ is 26, which is not supported by Bazel (officially supported versions: [19, 20, 21, 25]). Please use another version. Compiling Android targets may result in confusing errors.
Please specify the (min) Android NDK API level to use. [Available levels: [16, 17, 18, 19, 21, 22, 23, 24, 26, 27, 28, 29, 30, 31, 32, 33, 34]] [Default is 26]:
Please specify the home path of the Android SDK to use. [Default is /home/jacfger/Android/Sdk]: /home/jacfger/.local/share/Android/sdk/
Please specify the Android SDK API level to use. [Available levels: ['36']] [Default is 36]:
Please specify an Android build tools version to use. [Available versions: ['34.0.0', '37.0.0']] [Default is 37.0.0]: 34.0.0
I was hoping it's the model failed to segment the image, but sadly it was not the case.
CPU runs fine. But GPU fails, whether opengl backend is declared or not.
Also, during compiling, I had to enable
--nocheck_visibility(which was said to be needed for NPU only, but apparently it's needed for both CPU and GPU when I ran it).I've read both the
README.mdin the built from source folder and also https://developers.google.com/codelabs/litert-image-segmentation-cpp#4 So hopefully I didn't miss anything and is reproducible.