How google-ai-edge/ml-drift works
ML Drift is a cross-platform on-device GPU inference engine. The principal workflow is to represent a model as a graph, build a backend-neutral GpuModel of GPU operations, then execute it through a selected GPU backend using device-specific kernels and managed tensor storage. The README documents graph optimization, runtime shader generation, memory reuse, and four backends; the source index confirms key model, operation, and backend modules. Some backend internals and wiring were not excerpted, so those links are shown only where documented at a high level.
Main entry points: gpu_model.h GPU model · gpu_model_builder.h GPU model builder · gpu_operation.h GPU operations · inference_context.cc OpenCL inference
Components 21
Model and graph
- Public API
ml_drift/include/ml_drift.h - Model graph
ml_drift/common/model.h - Graph transforms
ml_drift/common/transformations - GPU model builder
ml_drift/common/gpu_model_builder.h - GPU model
ml_drift/common/gpu_model.h
GPU compute
- GPU operations
ml_drift/common/task/gpu_operation.h - Operator kernels
ml_drift/common/kernels - Tensor descriptors
ml_drift/common/task/tensor_desc.h - Unified compute language
OpenCL backend
- OpenCL inference
ml_drift/cl/inference_context.cc - OpenCL environment
ml_drift/cl/environment.h - OpenCL memory
ml_drift/cl/memory_manager.cc
OpenGL backend
- OpenGL inference
ml_drift/gl/gl_inference_context.cc - OpenGL memory
ml_drift/gl/memory_manager.cc
WebGPU backend
- WebGPU inference
ml_drift/webgpu/inference_context.h - WebGPU environment
ml_drift/webgpu/environment.h - WebGPU memory
ml_drift/webgpu/memory_manager.cc
Metal backend
- Metal inference
ml_drift/metal/inference_context.h - Metal memory
ml_drift/metal/memory_manager.h
Other components
- Application developer
- GPU device
Connections 23
- Application developer → Public API: uses
ml_drift/include/ml_drift.h - Public API → Model graph: defines models
ml_drift/include/ml_drift.h - Model graph → Graph transforms: optimizes graph
README.md - GPU model builder → Model graph: builds from
ml_drift/common/gpu_model_builder.h - GPU model builder → GPU model: creates
ml_drift/common/gpu_model_builder.h - GPU model → GPU operations: contains operations
ml_drift/common/gpu_model.h - GPU model builder → Operator kernels: selects implementations
ml_drift/common/gpu_model_builder.h - GPU operations → Unified compute language: uses shader language
README.md - GPU operations → Tensor descriptors: describes tensors
ml_drift/common/task/gpu_operation.h - GPU device → OpenCL environment: provides GPU
- GPU device → OpenGL inference: provides GPU
- GPU device → WebGPU environment: provides GPU
- GPU device → Metal inference: provides GPU
- GPU model → OpenCL inference: executes on
README.md - GPU model → OpenGL inference: executes on
README.md - GPU model → WebGPU inference: executes on
README.md - GPU model → Metal inference: executes on
README.md - OpenCL inference → OpenCL environment: uses environment
ml_drift/cl/inference_context.cc - OpenCL inference → OpenCL memory: allocates tensors
ml_drift/cl/inference_context.cc - OpenGL inference → OpenGL memory: allocates tensors
- WebGPU inference → WebGPU environment: uses environment
- WebGPU inference → WebGPU memory: allocates tensors
- Metal inference → Metal memory: allocates tensors
ml_drift/metal/inference_context.h