Skip to content

Plug-and-play wheels: vendored FKL headers + arch/CUDA auto-detection (pip install and go) - #5

Merged
morousg merged 2 commits into
Libraries-Openly-Fused:mainfrom
johnnynunez:feat/plug-and-play-wheels
Jun 11, 2026
Merged

Plug-and-play wheels: vendored FKL headers + arch/CUDA auto-detection (pip install and go)#5
morousg merged 2 commits into
Libraries-Openly-Fused:mainfrom
johnnynunez:feat/plug-and-play-wheels

Conversation

@johnnynunez

Copy link
Copy Markdown
Contributor

Summary

Makes pip install fkl-python truly plug and play: zero user steps after install — no FKL checkout, no FKL_INCLUDE/FKL_ROOT/FKL_ARCH environment variables.

pip install fkl-python
python -c "import fkl; pipe = fkl.compose(...); out = pipe(x)"   # just works

(Includes the PyPI Trusted Publishing commit from #4 — merging this supersedes that PR.)

How

  1. Vendored headers: FKL is header-only and Apache-2.0, so scripts/vendor_fkl.py copies include/ (67 files, ~700KB) into fkl/_vendor/FusedKernelLibrary/ with the upstream LICENSE and the exact commit recorded in VENDOR_INFO.txt. pyproject.toml packages them as package-data; the CI build job vendors from LTS-C++17 before building and the wheel smoke test asserts the headers are present inside the installed wheel.

  2. Resolution cascade (lazily, so import fkl never fails on CUDA-less machines): FKL_INCLUDE env var → vendored headers in the wheel → sibling dev checkout. Developers keep full control; users need nothing.

  3. GPU arch auto-detection: FKL_ARCH env → compute capability of GPU 0 queried via the CUDA driver API with pure ctypes (no nvidia-smi/nvcc needed) → sm_75 floor. On the dev box this resolves sm_120 correctly.

  4. CUDA toolkit auto-detection: CUDA_HOME/CUDA_PATH env → /usr/local/cudanvcc on PATH.

Verification (real end-to-end)

Installed the built wheel in a clean venv and ran under env -i with a fake HOME (so the dev checkout is unreachable) and zero FKL env vars:

arch auto-detected : sm_120
headers from wheel : True
compiler           : nvcc
TRUE PLUG AND PLAY OK (-1.0, 2.0, 5.0)     <- correct fused Mul(3)+Sub(1) results

Remaining machine requirements (unavoidable for a JIT design): an NVIDIA driver and a CUDA toolkit (nvcc) or clang++. The vendored-headers + JIT approach is what keeps ONE pure-python wheel serving every GPU arch and CUDA version — the alternative (precompiled binaries) would defeat FKL's whole compile-time fusion model.

New publish-pypi job: on v* tags (after build + codegen compile checks
pass) the sdist+wheel are uploaded to PyPI with pypa/gh-action-pypi-publish
using OIDC Trusted Publishing — no API tokens or secrets stored in GitHub.

One-time setup required on pypi.org (documented in the workflow):
add a pending publisher for project 'fkl-python' pointing at this
repository, workflow wheels.yml, environment 'pypi'. The 'fkl-python'
name is currently unclaimed on PyPI (verified via the simple index).

skip-existing=true makes tag re-runs idempotent; the GitHub Release job
is unchanged and runs in parallel.
…tion

'pip install fkl-python' now works with ZERO user steps: no FKL checkout,
no FKL_INCLUDE/FKL_ROOT/FKL_ARCH env vars.

- scripts/vendor_fkl.py copies the FKL headers (header-only, Apache-2.0,
  704KB/67 files) into fkl/_vendor/ with LICENSE + upstream commit
  recorded; pyproject packages them as package-data; the CI build job
  vendors from LTS-C++17 before building, and the wheel smoke test
  asserts the headers are present inside the installed wheel.
- backend.py resolution cascade: FKL_INCLUDE env > vendored > dev
  checkout. Resolved lazily so import never fails (CI builds without
  CUDA still pass the import test).
- FKL_ARCH now auto-detects: env > compute capability of GPU 0 via the
  CUDA driver API (pure ctypes, no nvidia-smi/nvcc needed) > sm_75 floor.
- CUDA_HOME auto-detects: env > /usr/local/cuda > nvcc on PATH.

Verified end-to-end: wheel installed in a clean venv with env -i (fake
HOME, zero FKL env vars) runs a real fused GPU pipeline: arch sm_120
auto-detected, headers resolved from inside the wheel, correct results.
Existing test matrix re-verified (vertical/circular/thread-fusion spot
checks green).
@morousg
morousg merged commit a94e8e4 into Libraries-Openly-Fused:main Jun 11, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants