pixtreme.infer
This repository owns the distribution pixtreme-infer and its import package
pixtreme.infer. It provides the architecture-independent Frame boundary, shared inference
contracts, shared verification, recipe identity, and static dispatch used by architecture
distributions.
The wheel owns only the pixtreme/infer/ subtree. The namespace root
pixtreme/__init__.py remains owned by
pixtreme. Architecture implementations are
maintained and distributed separately as architecture distributions.
Capabilities
The base dependency is pixtreme>=2.35.0. Optional capabilities are separated by extra:
verify: device telemetry for the shared verification tools.
The core does not depend on TensorRT or torch. Architecture distributions build and run
TensorRT engines through tensoracle and declare TensorRT and tensoracle as their own
dependencies.
Core-only installation exposes the shared contracts and gives an actionable error when a
known architecture distribution is absent. The core does not eagerly import architecture
implementations.
Development
The standalone C++ SDK is in cpp/; the Python project and its environment are in
python/ and python/.venv. Run Python development commands from python/:
cd python
uv sync --all-extras --no-install-project
uv pip install --no-deps --reinstall-package pixtreme-infer .
uv lock --check
CUDA_VISIBLE_DEVICES='' uv run --no-sync python -m pytest -q
uv run --no-sync mypy
uv run --no-sync ruff check src tests tools
uv run --no-sync ruff format --check src tests tools
uv build --wheel
The environment holds pixtreme-infer as an installed wheel, not an editable install,
because the pixtreme package itself comes from the pixtreme wheel. uv sync removes
that wheel, so run the first two commands again after uv sync and after changing the
Python or C++ source, and pass --no-sync to uv run.
The C++ build takes its C and C++ dependencies from Conan with the recipe and lock in cpp/,
including pixtreme's prebuilt C and C++ SDK and shared library and the CUDA runtime.
The preparation script fetches missing recipes from the private
sync-dev-org/conan-recipes Release using the host's gh login, verifies the archive
and locked revisions, and obtains pixtreme's SDK from its public Release. It also
obtains CMake and Ninja binaries from ConanCenter; their versions are declared once
in cpp/conan/profiles/tools. The host needs Python 3.12 or newer, the compiler and
the Conan CLI version pinned in python/pyproject.toml.
Build and test the standalone SDK from the repository root:
uv tool install conan==2.34.0
python3 cpp/conan/prepare-tests.py --output build/conan-tests
python3 cpp/conan/prepare.py --output build/cpp --tests --offline
. ./build/cpp/conanbuild.sh
cd cpp
cmake --preset conan-release
cmake --build --preset conan-release
ctest --preset conan-release --output-on-failure
cd ..
Dependency preparation runs before CMake and stops on failure. Test builds use only
prepared recipes and binaries. To select another compiler, pass --host-profile and
--build-profile; the defaults are linux-gcc-toolset-13 on Linux and
windows-msvc194 on Windows (Windows builds remain unverified). On Windows use cmd
and call build\cpp\conanbuild.bat instead of sourcing the shell script.
Use CONAN_HOME to choose the Conan home, or --cache <absolute path> to choose only
the package storage; use the same values when preparing and building tests.
Python build hooks use this same preparation, apply its complete build environment,
and pass a private toolchain and build directory to scikit-build-core. They do not
write C++ user presets. An sdist carries the locked shared recipe copies so its build
needs no gh login. For a manylinux release wheel set
PIXTREME_INFER_CONAN_RELEASE=1, which selects linux-gcc-toolset-14 and builds the
library dependencies in the image while requiring CMake and Ninja binaries.
PIXTREME_INFER_CONAN_PROFILE and PIXTREME_INFER_CONAN_BUILD_PROFILE override the
profiles, and PIXTREME_INFER_CONAN_CACHE selects an absolute package storage path.
Use a writable CONAN_HOME and package storage under the container's build directory.
No step compiles pixtreme: its Conan package unpacks the prebuilt SDK of the Release. The
wheel never contains pixtreme: its library needs libpixtreme.so.2 and finds it in the
installed pixtreme distribution, which must be at least the version whose SDK the build used.
The wheel includes the nanobind extension, C interface, header-only C++ wrapper and
nanobind adapter, CMake package and shared
library under pixtreme/infer/. Module builds find the CMake package with
pixtreme.infer.get_cmake_dir() and link pixtreme_infer::pixtreme_infer. The SDK
uses the shared library supplied by the installed pixtreme distribution. The wheel
contains one shared library, libpixtreme_infer.so.3. Importing
pixtreme.infer loads its extension and shared library without initializing CUDA.
A native consumer declares the SDK dependency in its CMakeLists.txt:
find_package(pixtreme_infer CONFIG REQUIRED)
target_link_libraries(my_module PRIVATE pixtreme_infer::pixtreme_infer)
Configure the consumer from the Python environment containing the installed wheels:
cmake -S . -B build -Dpixtreme_infer_DIR="$(python -c 'import pixtreme.infer; print(pixtreme.infer.get_cmake_dir())')"
cmake --build build
The wheel's config finds pixtreme in the same environment. An explicit
-Dpixtreme_DIR=... takes priority when selecting a different pixtreme SDK.
The normal test suite does not require a GPU. Tests that require unavailable optional
dependencies skip with a reason.
Version and release
Versions come from tags named vX.Y.Z. Each version is published to PyPI as a
pixtreme-infer wheel; there is no source distribution. Install it from PyPI. The GitHub
Release of each version tag holds the same wheel, the C and C++ SDK archive, and a
SHA256SUMS file covering both.
C and C++ SDK through Conan
C and C++ consumers take the core SDK as a Conan 2 shared-library package. The public
pixtreme-infer-sdk-X.Y.Z-manylinux_2_28_x86_64.tar.gz archive contains
libpixtreme_infer.so.3, the C interface, the header-only C++ wrapper and nanobind adapter,
the CMake package, license files and sdk.json. Library, header and CMake bytes match the wheel.
Take both shared recipes from
sync-dev-org/conan-recipes,
following its authenticated GitHub API asset download instructions and checksum verification.
Their from_source options default to False, selecting the public prebuilt SDKs.
<shared-recipes> below is the extracted organization archive. Choose a pixtreme SDK version
that satisfies the shared core recipe's lower bound:
conan export <shared-recipes>/recipes/pixtreme --version <pixtreme-version>
conan export <shared-recipes>/recipes/pixtreme-infer --version X.Y.Z
Require the core from the consumer's conanfile.txt. CMakeDeps generates the dependency
configuration files, and CMakeToolchain adds their directory to CMAKE_PREFIX_PATH:
[requires]
pixtreme-infer/X.Y.Z
[generators]
CMakeToolchain
CMakeDeps
conan install . --output-folder build --build=missing
cmake -S . -B build -G Ninja -DCMAKE_TOOLCHAIN_FILE="$PWD/build/conan_toolchain.cmake" -DCMAKE_BUILD_TYPE=Release
cmake --build build
source build/conanrun.sh
./build/my_consumer
conan install uses your Conan profile; conan profile detect creates one in a new Conan
home. --build=missing only unpacks the two prebuilt SDK archives; neither recipe compiles
anything. Run the consumer in Conan's run environment (build/conanrun.sh, or the
VirtualRunEnv generator), which puts both packages' library directories on the loader path.
The core library is the same file as in the wheel and searches for libpixtreme.so.2 only in
the wheel layout, so a consumer that calls only the core API does not find pixtreme without
that environment.
The consumer's CMakeLists.txt reads the configuration generated by CMakeDeps:
find_package(pixtreme_infer CONFIG REQUIRED) and link pixtreme_infer::pixtreme_infer,
which also links pixtreme::pixtreme. One process loads only one pixtreme library: do not
load the wheel's libpixtreme.so.2 and the Conan package's in the same process.
To embed the core in a native library or application, build it from source with
BUILD_SHARED_LIBS=OFF. The default is ON; each build and installation contains one
form of the core, and both forms use pixtreme_infer::pixtreme_infer:
python3 cpp/conan/prepare-tests.py --output build/conan-tests
python3 cpp/conan/prepare.py --output build/static --tests --offline --no-presets
. ./build/static/conanbuild.sh
cmake -S cpp -B build/static -G Ninja -DCMAKE_TOOLCHAIN_FILE="$PWD/build/static/conan_toolchain.cmake" -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF
cmake --build build/static
ctest --test-dir build/static --output-on-failure
cmake --install build/static --prefix "$PWD/static-sdk"
The installed static archive contains only the core's objects. The consumer's toolchain
provides pixtreme's CMake package and the CUDAToolkit module finder. With Conan, the
cuda-toolkit package supplies cmake/FindCUDAToolkit.cmake through CMAKE_MODULE_PATH.
Outside Conan, pass -DCMAKE_MODULE_PATH=<cuda-package>/cmake and
-DCUDAToolkit_ROOT=<cuda-package>. Add the installed SDK to CMAKE_PREFIX_PATH;
linking the public target also supplies pixtreme, CUDA::cudart_static and the required
system libraries. The installed package records no absolute dependency paths from the
core's build machine.
One process uses one core. A statically embedded core resolves only the module entries
supplied with pixtreme_infer_module_entries_set; an unlisted name returns
PIXTREME_INFER_MODULE_NOT_FOUND without opening a shared module. The wheel and Release
SDK archives contain the shared core, and wheel builds explicitly select it. The shared
Conan recipe builds the static core only from source (from_source=True with
shared=False) and rejects a static request for the prebuilt SDK.
Native inference lifecycle
Architecture implementations derive from pixtreme::infer::StatelessInference or
TemporalInference in <pixtreme/infer/core.hpp>. A constructor inspects the artifact
and publishes its contract without initializing CUDA or allocating GPU memory.
prepare(device=0, stream=0) rechecks that contract and acquires backend resources.
Inference accepts one pixtreme.core.Frame, named pixtreme.NDArray parameters, an optional
reset for temporal inference, and an explicit stream handle. Omitting the stream
uses the legacy default stream. Calls before preparation, after a failed preparation,
and after close() fail before backend work. close() is idempotent.
A Python context manager prepares a newly constructed model with default arguments
and closes it on exit. For an explicit stream, prepare before entering the context:
import pixtreme as px
stream = px.core.Stream(device=0, non_blocking=True)
stream_handle = stream.ptr
model = ModuleModel(artifact, precision="fp16", input_hw=(height, width), use_cuda_graph=True)
model.prepare(device=0, stream=stream_handle)
with model:
result = model(frame, stream=stream_handle, **gpu_parameters)
stream.synchronize()
ModuleModel is the class supplied by an architecture distribution. Its constructor
owns its artifact settings; core has no query/open factory. model.contract is an
immutable copy of the C instance contract, including precision, fixed input shape,
scale, CUDA Graph selection, and temporal state bytes where applicable.
Auxiliary values use the names declared by the family. Pass pixtreme.NDArray
objects as keyword arguments; other values, including CuPy arrays, are rejected.
Wrap a DLPack producer explicitly with pixtreme.NDArray.from_dlpack(array).
The C interface accepts name/pixtreme_ndarray_t pairs. C++ consumers can call
model.run(frame, {{"motion", motion_array}}, stream) with a pixtreme::ndarray.
Core and modules exchange CUDA pixels and arrays only as pixtreme_frame_t and
pixtreme_ndarray_t, and the public headers declare no DLPack types. The input
staging helper writes name/NDArray destinations, the output helper reads a
three-dimensional HWC NDArray, and a graph declaration lists its routes only. A module
chooses how its backend reads that storage; pixtreme_ndarray_borrow describes
module-allocated memory without copying it.
The C ABI is 3.2; modules built against ABI 2 or earlier must be rebuilt for SONAME 3.
Preparation, inference, close() and destruction run on the prepared device: core makes
it current for the call and returns with the calling thread's current CUDA device and
context unchanged, on success and on failure. A thread whose current device differs can
therefore run and release the model. Module callbacks for preparation, inference and
release must use the model context made current by core and must not call cudaSetDevice:
a module linked into the executable shares the caller's CUDA runtime device state.
model.family_contract exposes the same native family's Frame and parameter declarations.
Python contract construction uses the native C validation as well.
When both channel declarations are exact and neither contains A, core also accepts
the declared input sequence followed by one A: RGB accepts RGBA, and BGR accepts BGRA.
The module receives only its declared channels. Core appends the input alpha to the
module result, using bilinear resize when dimensions change and converting alpha to
the result's dtype, range and bit depth. The module's other pixels and color metadata
stay unchanged. Core applies no extra clamp, color/gamma conversion or premultiplication
to alpha. Integer representation conversion includes pixtreme's rounding and saturation;
float results retain values outside [0,1].
This rule is shared by normal and CUDA Graph inference; alpha does not enter auxiliary
inputs or temporal state. Family queries and model contracts retain the module's
declarations. All other input checks still apply, and other channel sequences and
families retain their declared behavior.
The native class interface requires architecture modules built for core 0.18 or later.
Older modules exposing query/open factories are incompatible. Build modules against the
pixtreme headers of the installed pixtreme: pixtreme 2.14 rejects code built with headers
older than its C ABI 2.54. The core's
architecture table includes spanv2 and cda_vsr; it does not recommend the older
span distribution.
Creating a module by name from C and C++
C and C++ consumers can create a module's model from the module name and name/value
string options, without linking the module. The result is an ordinary model handle:
prepare, run, close and destroy it as above. Python keeps the module classes.
pixtreme_infer_option_t weights = PIXTREME_INFER_OPTION_INIT, precision = PIXTREME_INFER_OPTION_INIT;
weights.name = "weights"; weights.value = "/models/spanv2.safetensors";
precision.name = "precision"; precision.value = "fp16";
/* ... input_height, input_width, and optionally use_cuda_graph ... */
const pixtreme_infer_option_t *options[] = {&weights, &precision /* , ... */};
pixtreme_infer_model_t *model = NULL;
pixtreme_infer_error_t *error = NULL;
pixtreme_infer_status_t status = pixtreme_infer_model_create_by_name(
"spanv2", options, sizeof options / sizeof options[0], &model, &error);
auto model = pixtreme::infer::Model::create_by_name("spanv2", {
{"weights", "/models/spanv2.safetensors"}, {"precision", "fp16"},
{"input_height", "720"}, {"input_width", "1280"}, {"use_cuda_graph", "true"}});