EN 中文
Back to Overview

LiteRtLm_CreateEngine

Engine constructor. Loads weights, allocates VRAM, and initializes the computation pipeline. This is the most time-consuming operation in the entire system.

01. Physical Behavior during Construction

graph TD Config[LiteRtLm_Config] --> Call[CreateEngine] subgraph Runtime_Init [Internal Engine Initialization Logic] Load[Model File Loading: RAM] --> Alloc[Memory Allocation: VRAM] Alloc --> Shader[Shader Compilation/Pre-optimization] Shader --> Pipeline[Build Inference Computation Graph] end Call --> Runtime_Init Runtime_Init -->|Success| Ptr["Return void* Engine Handle"] Runtime_Init -->|Fail| Null[NULL]
Latency Warning: Initialization can take 2~10 seconds (depending on model size and hardware performance). In Unreal Engine, it is strictly forbidden to call this function on the GameThread (Main Thread), as it will cause the screen to freeze completely.

02. Parameter and Return Value

void* LiteRtLm_CreateEngine(LiteRtLm_Config config);
Parameter / Return ValueDetailed Description
config Initialization configuration structure. See details in LiteRtLm_Config.
Return Value (void*) Engine instance handle.
This is an Opaque Pointer used for all subsequent API calls. Returns NULL if it fails; please check the console error logs.

03. Asynchronous Creation Code Paradigm

// Execute initialization in a background thread
AsyncTask(ENamedThreads::AnyBackgroundHiPriTask, [this]() {
    LiteRtLm_Config MyConfig = GetDefaultConfig();
    void* NewEngine = LiteRtLm_CreateEngine(MyConfig);
    
    if (NewEngine) {
        this->EngineHandle = NewEngine;
    }
});