Skip to content

feat: add minimal returning calls for Add and Gemm#761

Open
voltjia wants to merge 1 commit into
masterfrom
feat/add-minimal-returning-calls
Open

feat: add minimal returning calls for Add and Gemm#761
voltjia wants to merge 1 commit into
masterfrom
feat/add-minimal-returning-calls

Conversation

@voltjia

@voltjia voltjia commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add returning-style Call support for Add and Gemm only.
  • Route returning calls through the shared Operator<Key>::Call(...) entry in src/operator.h, so future hooks can stay centralized.
  • Let each base operator define only MakeReturnValue(...) for output construction; operator.h then reuses the existing in-place Call(..., out) path.
  • Keep existing in-place Call overloads available via using Operator<Op>::Call.
  • Add C++ API smoke coverage for returning Add::Call(...) and Gemm::Call(...), plus existing in-place API regression coverage in tests/test_cpp_api.py.

Motivation

Returning tensor APIs are easier for external users than explicitly allocating and passing output tensors. InfiniOps still does not own tensor storage: the returning path delegates allocation to the external tensor type through Empty(...), then calls the existing in-place operator implementation.

Closes N/A.

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

$ python -m pip install .[dev] --no-build-isolation \
    -C cmake.define.INFINI_RT_SOURCE_DIR=/workspace/InfiniRT \
    -C cmake.define.INFINI_OPS_SMOKE_BUILD=ON \
    -C cmake.define.AUTO_DETECT_BACKENDS=OFF \
    -C cmake.define.WITH_TORCH=OFF
Successfully built InfiniOps
Successfully installed InfiniOps-0.1.0

$ python -m pytest -v --tb=short --junitxml=/workspace/results/test-results.xml tests/test_cpp_api.py
collected 2 items

tests/test_cpp_api.py::test_cpp_operator_call_instantiation_smoke PASSED [ 50%]
tests/test_cpp_api.py::test_cpp_returning_call_smoke PASSED              [100%]

============================== 2 passed in 2.55s ===============================

Test Results on Supported Platforms

Platform Affected Build / Smoke Result Full Result / Notes
NVIDIA Yes smoke passed Full suite not run; scoped API/header change.
Iluvatar No N/A - not affected Not tested.
MetaX No N/A - not affected Not tested.
Cambricon No N/A - not affected Not tested.
Moore No N/A - not affected Not tested.
Ascend No N/A - not affected Not tested.
Full `pytest` output (optional)
See smoke output above.

Benchmark / Performance Impact

N/A. This adds a convenience API that allocates an output through the caller-provided tensor type and then reuses the existing in-place operator path.

Notes for Reviewers

  • Depends on feat: add tensor-like TensorView constructor InfiniRT#10 for TensorView construction from tensor-like objects.
  • tests/test_cpp_api.py compiles an external temporary C++ source against installed headers and links -linfiniops -linfinirt, so the new API is validated in the same form an external library would use it.
  • First version intentionally supports only Add::Call(x, y) and Gemm::Call(a, b); other operators and more complex Gemm attribute forms are left out of scope.

@voltjia voltjia force-pushed the feat/add-minimal-returning-calls branch 4 times, most recently from f557a7a to e1a1191 Compare June 26, 2026 09:18
@voltjia voltjia marked this pull request as ready for review June 26, 2026 09:22
@voltjia voltjia requested a review from a team June 26, 2026 09:22
@voltjia voltjia force-pushed the feat/add-minimal-returning-calls branch from e1a1191 to 5852b4d Compare June 26, 2026 09:26
Comment thread src/base/add.h
Comment on lines +12 to +13
using Operator<Add>::Call;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是哪里需要呢?

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