Skip to content

How use NPU Backend in flutter_gemma (LiteRT-LM Android) #197

@nesror

Description

@nesror

According to the official LiteRT-LM Kotlin API documentation (https://github.com/google-ai-edge/LiteRT-LM/blob/main/docs/api/kotlin/getting_started.md#2-initialize-the-engine), to use the NPU backend on Android, developers must:

  1. Bundle NPU libraries: Manually compile/download the required NPU libraries and place them in the app's src/main/jniLibs directory (or another appropriate location).

  2. Configure the Engine: Specify the path to these libraries when initializing the Engine. The documentation provides the following code snippet:
    val engineConfig = EngineConfig(
    modelPath = modelPath,
    backend = Backend.NPU(nativeLibraryDir = context.applicationInfo.nativeLibraryDir)
    )

    Here, context.applicationInfo.nativeLibraryDir should point to the directory containing the bundled NPU native libraries.

Problem:
In flutter_gemmain, is it only necessary to place the NPU library for the SoC in the src/main/jniLibs directory, and is it unnecessary to set Backend.NPU(nativeLibraryDir = context.applicationInfo.nativeLibraryDir)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions