Skip to content

feat: expose returning add python call#774

Open
voltjia wants to merge 3 commits into
masterfrom
feat/python-returning-calls
Open

feat: expose returning add python call#774
voltjia wants to merge 3 commits into
masterfrom
feat/python-returning-calls

Conversation

@voltjia

@voltjia voltjia commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add opt-in Python returning overload generation for operators with MakeReturnValue, enabled only for add in this PR.
  • Add Pybind11Tensor helpers for constructing returned PyTorch tensors through the external tensor protocol.
  • Reuse the existing tests/test_add.py::test_add coverage: contiguous output cases call the returning overload, while existing in-place cases remain covered.

Motivation

Returning-style Python calls are more ergonomic for Python users, but InfiniOps still should not own tensor storage. This PR exposes that behavior through the existing external tensor construction protocol and keeps the rollout narrow to add.

Closes N/A - no linked issue.

Type of Change

  • feat — new feature / new operator / new platform
  • fix — bug fix
  • perf — performance improvement (no behavioral change)
  • refactor — code restructuring without behavior change
  • test — adding or fixing tests only
  • docs — documentation only
  • build / ci — build system or CI configuration
  • chore — tooling, formatting, or other non-code changes
  • Breaking change (requires a ! in the Conventional Commits prefix or a BREAKING CHANGE: footer)

Platforms Affected

  • CPU (WITH_CPU)
  • NVIDIA (WITH_NVIDIA)
  • Iluvatar (WITH_ILUVATAR)
  • MetaX (WITH_METAX)
  • Cambricon (WITH_CAMBRICON)
  • Moore (WITH_MOORE)
  • Ascend (WITH_ASCEND)
  • PyTorch C++ bindings (WITH_TORCH)
  • Build system / CMake / CI
  • Python bindings / user-facing API

Smoke Test Result

$ INFINI_RT_ROOT=/infinirt-prefix scripts/dev/build.sh nvidia --smoke --jobs 16 --torch-jobs 2 --binding-jobs 2
[build] platform  : nvidia
-- Wrapper op allowlist: add;mul;cast;cat;gemm;matmul;linear;rms_norm;swiglu;causal_softmax;abs;clamp;exp
warning: operator(s) not available for active devices: matmul
[build] done
$ CUDA_VISIBLE_DEVICES=1 PYTHONPATH=/workspace/build-nvidia/install:${PYTHONPATH:-} python3 -m pytest -q tests/test_generate_wrappers.py tests/test_add.py --devices nvidia
191 passed, 36 skipped in 7.00s

Test Results on Supported Platforms

Platform Affected Build / Smoke Result Full Result / Notes
NVIDIA Yes smoke build passed Targeted tests/test_generate_wrappers.py tests/test_add.py --devices nvidia: 191 passed, 36 skipped
Iluvatar No N/A - not affected N/A
MetaX No N/A - not affected N/A
Cambricon No N/A - not affected N/A
Moore No N/A - not affected N/A
Ascend No N/A - not affected N/A
Additional checks
ruff format --check scripts/generate_wrappers.py tests/test_add.py tests/test_generate_wrappers.py
3 files already formatted

ruff check scripts/generate_wrappers.py tests/test_add.py tests/test_generate_wrappers.py
All checks passed!

git diff --check origin/master
# passed

Benchmark / Performance Impact

N/A - API binding change only.

Notes for Reviewers

  • matmul returning Python exposure is intentionally out of scope for this PR.
  • Python returning overloads remain explicitly allowlisted through _PY_RETURNING_OPS; currently only add is enabled.
  • The matmul smoke-build warning is expected on NVIDIA because this PR does not add a NVIDIA or PyTorch fallback implementation for matmul.

@voltjia voltjia force-pushed the feat/python-returning-calls branch from d424f0e to 3fcad40 Compare June 30, 2026 03:41
@voltjia voltjia marked this pull request as ready for review June 30, 2026 03:42
@voltjia voltjia requested a review from a team June 30, 2026 03:42
@voltjia voltjia marked this pull request as draft June 30, 2026 05:31
@voltjia voltjia force-pushed the feat/python-returning-calls branch from 3fcad40 to 330468c Compare June 30, 2026 05:38
@voltjia voltjia marked this pull request as ready for review June 30, 2026 05:39
@voltjia voltjia force-pushed the feat/python-returning-calls branch from 330468c to 766e3d6 Compare June 30, 2026 05:57
@voltjia voltjia changed the title feat: expose returning calls to python feat: expose returning add python call Jun 30, 2026
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.

1 participant