Download and Integrate Prebuilt LiteRT C++ Binary

You can use prebuilt C++ libraries in your applications without building the entire LiteRT source tree. The integration can be done with CMake.

The following shows basic steps to use LiteRT CompiledModel API in your C++ code.

Download prebuilt LiteRT runtime shared library

Download the LiteRT runtime shared library by following the links:

Platform Version LiteRT runtime library
android_arm64 latest libLiteRt.so
linux_x86_64 latest libLiteRt.so
linux_arm64 latest libLiteRt.so
macos_arm64 latest libLiteRt.dylib
windows_x86_64 latest libLiteRt.dll

Download prebuilt GPU Accelerators

If you need GPU Acceleration, you need GPU Accelerator. Since it's not open sourced yet, you need to download prebuilts.

Here are available GPU Accelerators.

Platform Version GPU Accelerator Backend
android_arm64 latest libLiteRtGpuAccelerator.so OpenCL + OpenGL
linux_x86_64 latest libLiteRtWebGpuAccelerator.so WebGPU (Vulkan)
linux_arm64 latest libLiteRtWebGpuAccelerator.so WebGPU (Vulkan)
macos_arm64 latest libLiteRtMetalAccelerator.dylib Metal
windows_x86_64 latest libLiteRtWebGpuAccelerator.dll WebGPU (Direct3D)

Prepare prebuilt LiteRT C++ library

Choose a folder to host LiteRT C++ SDK. We'll refer to it as <litert_cc_sdk_location>.

  1. Download C++ SDK

    You need to prepare the necessary files (CMakeLists.txt, source and header files) from LiteRT C++ SDK zip file under <litert_cc_sdk_location>.

    wget https://github.com/google-ai-edge/LiteRT/releases/download/<litert_version>/litert_cc_sdk.zip
    unzip litert_cc_sdk.zip -d <litert_cc_sdk_location>
    
  2. Place the downloaded libLiteRt.so under <litert_cc_sdk_location>.

    cp <path_to_prebuilt_lib>/libLiteRt.so <litert_cc_sdk_location>/litert_cc_sdk/
    
  3. Build library and run_model_simple tool.

    LiteRT needs clang to build. Configure C++ SDK and build tools as the following:

    cd <litert_cc_sdk_location>
    cmake -S litert_cc_sdk -B litert_cc_sdk_build -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
    cmake --build litert_cc_sdk_build -j
    

Integrate prebuilt LiteRT C++ library

  1. Update your CMakeLists.txt to use LiteRT API.

    add_subdirectory("<litert_cc_sdk_location>" "<litert_cc_sdk_location>/build")
    include_directories("<litert_cc_sdk_location>")
    
    target_link_libraries(${CMAKE_PROJECT_NAME}
            # Use `litert_cc_api` for LiteRT C++ SDK
            litert_cc_api
            android
            log)