﻿# LiteRT GPU delegates: a serial executor can still change the execution thread

Moving local inference off the interface thread must preserve the delegate thread and EGL context contract. Serial scheduling alone does not establish that identity.

Author: Retrivium team
Updated: 2026-11-06
Canonical URL: https://retrivium.ai/journal/edge-litert-gpu-delegate-thread-egl-context/
Language: en

## The refactor removes concurrency but changes identity

A phone application creates its GPU interpreter during startup, then routes image classification through a background executor. Calls never overlap, yet a delegate error appears after the refactor. A serial work policy only determines which task may run next; it does not necessarily keep every task on the worker that initialized the delegate. Preserve the actual execution thread at initialization and invocation. Calling both operations from the same application component is not equivalent to the same thread.

## Use the documented Interpreter contract

The [Android GPU guide](https://developers.google.com/edge/litert/android/gpu) explicitly requires the delegate to be created on the same thread that runs it. That requirement belongs to the documented Interpreter path; it should not be generalized to every accelerator API by association. An initialization future completing successfully does not transfer the object into an arbitrary worker pool. Record the runtime distribution, delegate configuration and lifecycle owner so the supported contract is clear before investigating model operators or numerical accuracy.

## Native EGL handling is a more specific condition

The [native GPU guide](https://developers.google.com/edge/litert/android/gpu_native) describes a current EGLContext for graph modification and invocation, with invocation using the same context. If no context exists and the delegate creates it internally, invocation must stay on the graph-modification thread. Keep these conditions distinct instead of paraphrasing them as any background thread works. Do not invent manual context migration as a universal repair; the application must follow the contract of its actual native integration.

## Give the delegate a stable lifecycle owner

A proposed application design assigns delegate initialization and inference dispatch to a stable owner thread. Requests carry their inputs to that owner, and results return through the application callback path. Define what happens when the owner is stopped or replaced: an old object should not silently become an object initialized by its successor. Keep shutdown coordinated with outstanding work. This is an ownership design proposal, not a claim that a particular executor implementation automatically satisfies the requirement.

## Observe initialization and dispatch in the same fixture

Use a harmless supported model and retain actual worker identities around creation and invocation. Exercise normal dispatch, screen recreation and worker shutdown without changing the model artifact. Acceptance requires the recorded operations to obey the applicable thread/context condition and return a checked result. It does not require provoking a driver crash. No Android model or delegate was run for this article; the procedure identifies evidence needed to separate lifecycle misuse from model compatibility and device-specific failures.

## Keep affinity and acceleration evidence separate

[Linux thread affinity](/journal/guide-linux-taskset-thread/) concerns where a thread may execute, not which thread owns a graphics object. [LiteRT benchmark boundaries](/journal/google-ai-edge-portal-litert-board-measurement-boundaries/) concern what was measured and delegated. A correct lifecycle establishes neither complete GPU graph coverage nor a speedup. Report thread/context compliance, model result checks and any actual performance observations separately. That separation lets an application improve responsiveness without treating background scheduling as proof of GPU correctness or acceleration.
