How flagos-ai/torch-fl works
torch-fl is a PyTorch device plugin that presents accelerators through one logical flagos device. The principal workflow starts with standard PyTorch tensor operations, enters the plugin’s device and ATen dispatch layers, then selects an implementation such as portable FlagGems kernels, vendor-native kernels, compatibility boxing, or CPU fallback. Separate branches provide torch.compile, distributed collectives, and profiler integration. The README documents these capabilities; sampled excerpts are partial, so edges show only documented or source-supported relationships, not every platform-specific dispatch detail.
Main entry points: register.cc ATen dispatcher · torch_fl/__init__.py Plugin integration · flagos/__init__.py FlagOS device · functions.cc Device runtime
Components 21
Device interface
- Plugin integration
torch_fl/__init__.py - FlagOS device
torch_fl/flagos/__init__.py - Device runtime
csrc/runtime/functions.cc - Vendor runtimes
csrc/runtime/accelerator
Operator execution
- ATen dispatcher
csrc/aten/register.cc - Compatibility boxing
csrc/aten/device_boxing.h - FlagGems kernels
csrc/aten/flaggems_cpp_kernels.cc - Vendor kernels
csrc/aten/backends/ascend - CPU fallback
csrc/aten/fallback.cc
Compilation
- Compile API
torch_fl/compile/__init__.py - Inductor backend
torch_fl/compile/inductor_backend.py - Compile device interface
torch_fl/compile/device_interface.py - TileOps runtime
torch_fl/tileops/runtime.py
Distributed execution
- Distributed API
torch_fl/distributed.py - FlagOS process group
torch_fl/comm/process_group.py - Native collectives
torch_fl/csrc/dataparallel_comm.cc
Profiling
- Profiler integration
csrc/profiler/flagos_kineto_profiler.cc - Device tracing
csrc/profiler/device_tracer.h
Other components
- PyTorch user
- PyTorch APIs
- Tensor result
Connections 22
- PyTorch user → PyTorch APIs: invokes
- PyTorch APIs → Plugin integration: loads integration
- Plugin integration → FlagOS device: exposes
- FlagOS device → Device runtime: uses runtime
- Device runtime → Vendor runtimes: calls
- PyTorch APIs → ATen dispatcher: dispatches operations
- ATen dispatcher → FlagGems kernels: routes kernels
- ATen dispatcher → Vendor kernels: routes kernels
- ATen dispatcher → Compatibility boxing: routes operations
- ATen dispatcher → CPU fallback: falls back
- FlagGems kernels → Tensor result: produces
- Vendor kernels → Tensor result: produces
- Compatibility boxing → Tensor result: produces
- CPU fallback → Tensor result: produces
- PyTorch user → Compile API: requests compilation
- Compile API → Inductor backend: invokes
- Inductor backend → Compile device interface: registers device
- PyTorch user → Distributed API: requests collectives
- Distributed API → FlagOS process group: uses
- FlagOS process group → Native collectives: dispatches collectives
- PyTorch user → Profiler integration: starts profiling
- Profiler integration → Device tracing: controls tracing