Skip to content

[litertlm] Update LiteRT-LM Kotlin Backend API to a sealed class#1546

Merged
copybara-service[bot] merged 1 commit intomainfrom
litert_lm_pr_878215193
Mar 6, 2026
Merged

[litertlm] Update LiteRT-LM Kotlin Backend API to a sealed class#1546
copybara-service[bot] merged 1 commit intomainfrom
litert_lm_pr_878215193

Conversation

@copybara-service
Copy link
Copy Markdown
Contributor

@copybara-service copybara-service Bot commented Mar 4, 2026

[litertlm] Update LiteRT-LM Kotlin Backend API to a sealed class

This change refactors the Backend API in Config.kt from an enum
to a sealed class to support backend-specific configurations directly
within the backend definition.

Key changes include:

  • Backend Sealed Class: Backend is now a sealed class with three
    variants: CPU(val numThreads: Int), NPU(),
    and GPU().
  • JNI Configuration: Updated LiteRtLmJni.nativeCreateEngine and
    litertlm.cc to accept and process the num_threads parameter, which
    is mapped to number_of_threads in the C++ CpuConfig.
  • Tests & Examples Migration: Updated all test cases (e.g.,
    SessionTest, DeviceTest, BaseDeviceTest) and example scripts
    (Main.kt, ToolMain.kt, BenchmarkMain.kt) to instantiate the new
    Backend.CPU() and Backend.NPU(...) data classes.

@copybara-service copybara-service Bot force-pushed the litert_lm_pr_878215193 branch 9 times, most recently from 8e89ddc to 5c3db42 Compare March 6, 2026 17:00
This change refactors the `Backend` API in `Config.kt` from an enum
to a sealed class to support backend-specific configurations directly
within the backend definition.

**Key changes include:**
*   **Backend Sealed Class:** `Backend` is now a sealed class with three
    variants: `CPU(val numThreads: Int)`, `NPU()`,
    and `GPU()`.
*   **JNI Configuration:** Updated `LiteRtLmJni.nativeCreateEngine` and
    `litertlm.cc` to accept and process the `num_threads` parameter, which
    is mapped to `number_of_threads` in the C++ `CpuConfig`.
*   **Tests & Examples Migration:** Updated all test cases (e.g.,
    `SessionTest`, `DeviceTest`, `BaseDeviceTest`) and example scripts
    (`Main.kt`, `ToolMain.kt`, `BenchmarkMain.kt`) to instantiate the new
    `Backend.CPU()` and `Backend.NPU(...)` data classes.

LiteRT-LM-PiperOrigin-RevId: 879674985
@copybara-service copybara-service Bot force-pushed the litert_lm_pr_878215193 branch from 5c3db42 to ff00423 Compare March 6, 2026 17:33
@copybara-service copybara-service Bot merged commit ff00423 into main Mar 6, 2026
@copybara-service copybara-service Bot deleted the litert_lm_pr_878215193 branch March 6, 2026 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant