# openxla/xla architecture

> Architecture diagram of the GitHub repository openxla/xla, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/openxla/xla
- Repository: https://github.com/openxla/xla

## Overview

XLA is an ML compiler that accepts computations from framework integrations, represents them as HLO, optimizes them through compiler passes, lowers them for hardware backends, and executes compiled programs. Its runtime-facing clients and PJRT interfaces support device interaction, while CPU and GPU backends provide distinct code generation and execution paths. The README documents the product workflow and hardware scope; the source index supports several internal links. Other backend and client details are represented at subsystem level where source excerpts were not available.

Main entry points: [`xla/client/local_client.cc`](https://github.com/openxla/xla/blob/main/xla/client/local_client.cc) (Local client), [`xla/pjrt`](https://github.com/openxla/xla/tree/main/xla/pjrt) (PJRT clients), [`xla/hlo/ir`](https://github.com/openxla/xla/tree/main/xla/hlo/ir) (HLO module and IR), [`xla/backends/cpu/codegen`](https://github.com/openxla/xla/tree/main/xla/backends/cpu/codegen) (CPU code generation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_front["Frontend and clients"]
  node_local["Local client<br/>[local_client.cc]"]
  node_python["Python client<br/>[xla_client.py]"]
  node_pjrt["PJRT clients"]
  node_transfer["Host transfer"]
end

subgraph group_ir["Compiler IR and passes"]
  node_hlo["HLO module and IR"]
  node_shape["Shape and layout<br/>[shape.h]"]
  node_shapeutil["Shape utilities<br/>[shape_util.h]"]
  node_literal["Literal values<br/>[literal.h]"]
  node_passes["HLO pass pipeline"]
  node_collective["Collective pipelining"]
  node_gpu_spmd["GPU SPMD pipeline"]
end

subgraph group_backend["Hardware backends"]
  node_cpu_codegen["CPU code generation"]
  node_cpu_engine["CPU execution engine"]
  node_gpu_codegen["GPU code generation"]
  node_gpu_thunks["GPU thunk pipeline"]
  node_autotune["Autotuning"]
end

subgraph group_runtime["Execution and services"]
  node_cpu_runtime["CPU runtime"]
  node_gpu_runtime["GPU runtime"]
  node_stream["Stream Executor"]
  node_ifrt_proxy["IFRT proxy client"]
end

node_frameworks(("ML frameworks"))

node_frameworks -.->|"submit computations"| node_local
node_frameworks -.->|"submit computations"| node_python
node_local -->|"compile input"| node_hlo
node_hlo -.->|"optimize"| node_passes
node_passes -.->|"runs pass"| node_collective
node_gpu_spmd -->|"builds pipeline"| node_passes
node_hlo -->|"uses shapes"| node_shape
node_shapeutil -->|"operates on"| node_shape
node_local -->|"accepts values"| node_literal
node_local -.->|"selects backend"| node_cpu_codegen
node_local -.->|"selects backend"| node_gpu_codegen
node_cpu_codegen -->|"loads generated code"| node_cpu_engine
node_cpu_engine -.->|"executes kernels"| node_cpu_runtime
node_gpu_codegen -.->|"lowers for runtime"| node_gpu_thunks
node_gpu_thunks -->|"dispatches thunks"| node_gpu_runtime
node_cpu_codegen -.->|"tunes kernels"| node_autotune
node_gpu_codegen -.->|"tunes kernels"| node_autotune
node_pjrt -->|"transfers buffers"| node_transfer
node_pjrt -.->|"uses device services"| node_stream
node_python -.->|"connects runtime"| node_pjrt
node_ifrt_proxy -.->|"connects remotely"| node_pjrt
node_cpu_runtime -.->|"uses platform services"| node_stream
node_gpu_runtime -.->|"uses platform services"| node_stream

click node_local "https://github.com/openxla/xla/blob/main/xla/client/local_client.cc"
click node_python "https://github.com/openxla/xla/blob/main/xla/python/xla_client.py"
click node_pjrt "https://github.com/openxla/xla/tree/main/xla/pjrt"
click node_transfer "https://github.com/openxla/xla/blob/main/xla/pjrt/host_to_device_transfer_manager.cc"
click node_hlo "https://github.com/openxla/xla/tree/main/xla/hlo/ir"
click node_shape "https://github.com/openxla/xla/blob/main/xla/shape.h"
click node_shapeutil "https://github.com/openxla/xla/blob/main/xla/shape_util.h"
click node_literal "https://github.com/openxla/xla/blob/main/xla/literal.h"
click node_passes "https://github.com/openxla/xla/blob/main/xla/hlo/pass/hlo_pass_pipeline.cc"
click node_collective "https://github.com/openxla/xla/blob/main/xla/service/collective_pipeliner.cc"
click node_gpu_spmd "https://github.com/openxla/xla/blob/main/xla/service/gpu/gpu_spmd_pipeline.cc"
click node_cpu_codegen "https://github.com/openxla/xla/tree/main/xla/backends/cpu/codegen"
click node_cpu_engine "https://github.com/openxla/xla/blob/main/xla/backends/cpu/codegen/execution_engine.cc"
click node_gpu_codegen "https://github.com/openxla/xla/tree/main/xla/backends/gpu/codegen"
click node_gpu_thunks "https://github.com/openxla/xla/blob/main/xla/backends/gpu/runtime/thunk_pass_pipeline.h"
click node_autotune "https://github.com/openxla/xla/tree/main/xla/backends/autotuner"
click node_cpu_runtime "https://github.com/openxla/xla/tree/main/xla/backends/cpu/runtime"
click node_gpu_runtime "https://github.com/openxla/xla/tree/main/xla/backends/gpu/runtime"
click node_stream "https://github.com/openxla/xla/tree/main/xla/stream_executor"
click node_ifrt_proxy "https://github.com/openxla/xla/blob/main/xla/python/ifrt_proxy/client/grpc_client_session.cc"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_local,node_python,node_pjrt,node_transfer toneBlue
class node_hlo,node_shape,node_shapeutil,node_literal,node_passes,node_collective,node_gpu_spmd toneAmber
class node_cpu_codegen,node_cpu_engine,node_gpu_codegen,node_gpu_thunks,node_autotune toneMint
class node_cpu_runtime,node_gpu_runtime,node_stream,node_ifrt_proxy toneRose
class node_frameworks toneIndigo
```

## Components

### Frontend and clients

- [Local client](https://github.com/openxla/xla/blob/main/xla/client/local_client.cc): `xla/client/local_client.cc`
- [Python client](https://github.com/openxla/xla/blob/main/xla/python/xla_client.py): `xla/python/xla_client.py`
- [PJRT clients](https://github.com/openxla/xla/tree/main/xla/pjrt): `xla/pjrt`
- [Host transfer](https://github.com/openxla/xla/blob/main/xla/pjrt/host_to_device_transfer_manager.cc): `xla/pjrt/host_to_device_transfer_manager.cc`

### Compiler IR and passes

- [HLO module and IR](https://github.com/openxla/xla/tree/main/xla/hlo/ir): `xla/hlo/ir`
- [Shape and layout](https://github.com/openxla/xla/blob/main/xla/shape.h): `xla/shape.h`
- [Shape utilities](https://github.com/openxla/xla/blob/main/xla/shape_util.h): `xla/shape_util.h`
- [Literal values](https://github.com/openxla/xla/blob/main/xla/literal.h): `xla/literal.h`
- [HLO pass pipeline](https://github.com/openxla/xla/blob/main/xla/hlo/pass/hlo_pass_pipeline.cc): `xla/hlo/pass/hlo_pass_pipeline.cc`
- [Collective pipelining](https://github.com/openxla/xla/blob/main/xla/service/collective_pipeliner.cc): `xla/service/collective_pipeliner.cc`
- [GPU SPMD pipeline](https://github.com/openxla/xla/blob/main/xla/service/gpu/gpu_spmd_pipeline.cc): `xla/service/gpu/gpu_spmd_pipeline.cc`

### Hardware backends

- [CPU code generation](https://github.com/openxla/xla/tree/main/xla/backends/cpu/codegen): `xla/backends/cpu/codegen`
- [CPU execution engine](https://github.com/openxla/xla/blob/main/xla/backends/cpu/codegen/execution_engine.cc): `xla/backends/cpu/codegen/execution_engine.cc`
- [GPU code generation](https://github.com/openxla/xla/tree/main/xla/backends/gpu/codegen): `xla/backends/gpu/codegen`
- [GPU thunk pipeline](https://github.com/openxla/xla/blob/main/xla/backends/gpu/runtime/thunk_pass_pipeline.h): `xla/backends/gpu/runtime/thunk_pass_pipeline.h`
- [Autotuning](https://github.com/openxla/xla/tree/main/xla/backends/autotuner): `xla/backends/autotuner`

### Execution and services

- [CPU runtime](https://github.com/openxla/xla/tree/main/xla/backends/cpu/runtime): `xla/backends/cpu/runtime`
- [GPU runtime](https://github.com/openxla/xla/tree/main/xla/backends/gpu/runtime): `xla/backends/gpu/runtime`
- [Stream Executor](https://github.com/openxla/xla/tree/main/xla/stream_executor): `xla/stream_executor`
- [IFRT proxy client](https://github.com/openxla/xla/blob/main/xla/python/ifrt_proxy/client/grpc_client_session.cc): `xla/python/ifrt_proxy/client/grpc_client_session.cc`

### Other components

- **ML frameworks**

## Connections

- ML frameworks → Local client: submit computations
- ML frameworks → Python client: submit computations
- Local client → HLO module and IR: compile input (evidence: `xla/client/local_client.cc`)
- HLO module and IR → HLO pass pipeline: optimize
- HLO pass pipeline → Collective pipelining: runs pass
- GPU SPMD pipeline → HLO pass pipeline: builds pipeline (evidence: `xla/service/gpu/gpu_spmd_pipeline.cc`)
- HLO module and IR → Shape and layout: uses shapes (evidence: `xla/hlo/ir/hlo_module.h`)
- Shape utilities → Shape and layout: operates on (evidence: `xla/shape_util.h`)
- Local client → Literal values: accepts values (evidence: `xla/client/local_client.cc`)
- Local client → CPU code generation: selects backend
- Local client → GPU code generation: selects backend
- CPU code generation → CPU execution engine: loads generated code (evidence: `xla/backends/cpu/codegen/execution_engine.cc`)
- CPU execution engine → CPU runtime: executes kernels
- GPU code generation → GPU thunk pipeline: lowers for runtime
- GPU thunk pipeline → GPU runtime: dispatches thunks (evidence: `xla/backends/gpu/runtime/thunk_pass_pipeline.h`)
- CPU code generation → Autotuning: tunes kernels
- GPU code generation → Autotuning: tunes kernels
- PJRT clients → Host transfer: transfers buffers (evidence: `xla/pjrt/host_to_device_transfer_manager.cc`)
- PJRT clients → Stream Executor: uses device services
- Python client → PJRT clients: connects runtime
- IFRT proxy client → PJRT clients: connects remotely (evidence: `xla/python/ifrt_proxy/client/grpc_client_session.cc`)
- CPU runtime → Stream Executor: uses platform services
- GPU runtime → Stream Executor: uses platform services (evidence: `xla/backends/gpu/runtime/thunk_pass_pipeline.h`)
