Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 34 additions & 13 deletions docs/linked-operators.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Linked Operators

The linked backend calls operators provided by an installed third-party shared
library. It supports exact exported C++ symbols and registered PyTorch
Dispatcher operators when a platform package does not provide source code or a
stable C API.
library. It supports exact exported symbols, TVM FFI entry points, and
registered PyTorch Dispatcher operators when a platform package does not
provide source code or a stable C API.

## Source Layout

Expand All @@ -15,16 +15,25 @@ src/linked/<transport>/<device>/
ops/<operator>/
<implementation>.yaml
<implementation>.h
<implementation>.cc
<implementation>.{cc,cu}
```

CUDA providers may use `<implementation>.cu` instead of `.cc`.

The platform library file contains DSO discovery information:

```yaml
python_distribution_package: vllm
library_glob: vllm/_C*.so
```

A library may also provide `include_glob` when its transport needs installed
headers. Each glob must resolve to exactly one path in the Python distribution.
A library may set `python_distribution_version` to a PEP 440 specifier. The
resolver verifies the installed distribution version before looking up its DSO.
A DSO that depends on another declared platform library lists that dependency
under the implementation's optional `link_libraries` key.

Files for an operator implementation use the provider name as their common
stem. Multiple implementations for the same operator and device use distinct
file stems and implementation slots.
Expand Down Expand Up @@ -54,15 +63,19 @@ partial Dispatcher contract or a binding that mixes both forms.

## Adapter Boundary

Keep ABI behavior in `<implementation>.cc`, not in YAML. Shared operator
templates own reusable tensor conversion, stream guards, layout staging, and
copy-back behavior. Provider sources own exact typed function declarations,
Keep ABI behavior in `<implementation>.cc` or `.cu`, not in YAML. Shared
operator templates own reusable tensor conversion, stream guards, layout
staging, and copy-back behavior. Provider sources own exact typed declarations,
synthesized arguments, and provider-specific return handling.

For the `torch` transport, an implementation backend inherits its device `C10`
specialization for device identity and external-stream handling, then defines
its provider-specific `Call` ABI.

For the `tvm_ffi` transport, provider sources call exported TVM FFI entry
points directly. The resolver supplies installed TVM FFI headers and links the
provider DSO together with every library named in `link_libraries`.

## Configuration

At configure time, `scripts/resolve_linked_ops.py` locates the installed Python
Expand All @@ -73,8 +86,10 @@ loading the DSO, comparing the registered schema exactly, and checking the
requested dispatch key. The resolver writes a CMake manifest and diagnostic
JSON under `generated/linked/`. Generated files are not committed.

DSOs that provide Dispatcher registrations are force-loaded only for their own
link item so that the linker cannot discard their static registration code.
DSOs that provide Dispatcher registrations and DSOs named in
`link_libraries` are retained with `--no-as-needed` only for their own link
items. This prevents the linker from discarding registration code or an
explicit dependency while preserving its state for unrelated libraries.

Enable the backend independently of generated ATen implementations:

Expand All @@ -86,6 +101,11 @@ cmake -S . -B build \
-DINFINI_OPS_OPS=silu_and_mul
```

`WITH_TORCH=OFF` disables the generated ATen backend, but `WITH_LINKED=ON`
currently still requires an installed `torch` package. Linked configuration
shares its Python interpreter and C++ ABI setup with the existing `torch`
transport.

To resolve only selected linked implementation slots, pass an `ops.json` file
through `INFINI_OPS_OPS`. The resolver reads each linked provider's slot from
its sibling C++ header before locating external libraries, so an unselected
Expand All @@ -98,10 +118,11 @@ Provider and PyTorch C++ ABIs must match. Configuration fails before compilation
when the distribution, shared library, or an exact required symbol is missing.

InfiniOps does not bundle the provider library. Its resolved directory and the
PyTorch runtime directories are recorded in the installed binary's RPATH, so a
linked build is tied to that Python environment. Reconfigure and rebuild after
moving or replacing the provider environment. In-place changes to a resolved
provider DSO are tracked as CMake configure and link dependencies.
directories of its linked dependencies are recorded in the installed binary's
RPATH, so a linked build is tied to that Python environment. PyTorch runtime
directories are recorded for the `torch` transport as well. Reconfigure and
rebuild after moving or replacing the provider environment. In-place changes
to a resolved provider DSO are tracked as CMake configure and link dependencies.

## Implementation Slots

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["scikit-build-core", "pybind11", "libclang", "pyyaml"]
requires = ["scikit-build-core", "pybind11", "libclang", "packaging", "pyyaml"]
build-backend = "scikit_build_core.build"

[project]
Expand Down
Loading
Loading