Skip to content

feat: add public C++ operator API#618

Draft
voltjia wants to merge 1 commit into
masterfrom
feat/cpp-operator-api
Draft

feat: add public C++ operator API#618
voltjia wants to merge 1 commit into
masterfrom
feat/cpp-operator-api

Conversation

@voltjia
Copy link
Copy Markdown
Collaborator

@voltjia voltjia commented May 20, 2026

Summary

  • Add the unified public entry header include/infini/ops.h for C++ consumers.
  • Generate public one-shot operator declarations under infini::ops::functional in generated/include/infini/functional_ops.h.
  • Compile generated functional operator definitions into libinfiniops.
  • Route pybind one-shot operator calls through infini::ops::functional::<OpName>.
  • Install public headers, libinfiniops, pkg-config metadata, and CMake package metadata.

Motivation

This is the first PR in the public operator API split. It adds the C++ source/link convenience layer first so the later stable C ABI can be implemented as a thin adapter over public C++ operator entrypoints instead of including backend kernel headers directly.

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

Test Results on Supported Platforms

Platform Built pytest Result Notes / Hardware
NVIDIA Yes tests/test_cpp_api.py: 1 passed Remote ssh nvidia, container accelerator-dev/nvidia:latest; build configured with WITH_CPU=ON, WITH_NVIDIA=ON.
Iluvatar No Not run No Iluvatar hardware/toolchain available in this session.
MetaX No Not run No MetaX hardware/toolchain available in this session.
Cambricon No Not run No Cambricon hardware/toolchain available in this session.
Moore No Not run No Moore hardware/toolchain available in this session.
Ascend No Not run No Ascend hardware/toolchain available in this session.
Full `pytest` output (optional)
INFINIOPS_INSTALL_PREFIX=/workspace/project/.remote-install-pr1 python -m pytest tests/test_cpp_api.py -q
Running 1 items in this shard
.                                                                        [100%]
1 passed in 1.40s

Additional build checks on ssh nvidia with accelerator-dev/nvidia:latest:

cmake -S . -B .remote-build-pr1 -DWITH_CPU=ON -DWITH_NVIDIA=ON -DGENERATE_PYTHON_BINDINGS=OFF -DCMAKE_BUILD_TYPE=Release
cmake --build .remote-build-pr1 --target infiniops -j2
cmake --install .remote-build-pr1 --prefix .remote-install-pr1
cmake -S . -B .remote-build-pr1-pybind -DWITH_CPU=ON -DWITH_NVIDIA=ON -DGENERATE_PYTHON_BINDINGS=ON -DCMAKE_BUILD_TYPE=Release
cmake --build .remote-build-pr1-pybind --target ops -j2

Build emitted existing CUDA warnings around meaningless const return qualifiers and partially overridden overloads.

Benchmark / Performance Impact

N/A. This PR adds public API wrappers and build/install plumbing. It does not change operator kernels or dispatch selection.

Notes for Reviewers

  • The C++ API is intentionally a source/link convenience layer, not a stable C++ ABI commitment.
  • Public one-shot calls live in infini::ops::functional to avoid colliding with existing operator classes such as infini::ops::Add.
  • Backend implementation headers remain in generated source files; the public header does not include backend kernel headers.
  • The wrapper generator now has a constrained fallback parser for the current base operator headers when Python clang.cindex is unavailable in direct CMake builds.
  • This PR should land before the C ABI PR. The follow-up C ABI PR should target this branch.

Checklist

Title, Branch, and Commits

  • PR title follows Conventional Commits: feat: add public C++ operator API.
  • Branch name follows the expected <type>/... form: feat/cpp-operator-api.
  • Commit message follows Conventional Commits: feat: add public C++ operator API.
  • Small PR is a single squashable commit.
  • No stray merge commits from master.
  • No fixup! / squash! / wip commits remain.

Scope and Design

  • Changes are minimal for the stated motivation.
  • No dead code, commented-out blocks, debug prints, or ownerless TODOs were added.
  • No unrelated formatting churn was added.
  • Public API changes are intentional and covered by smoke tests.

General Code Hygiene

  • Comments were added only where they explain non-obvious behavior.
  • Modified and added files end with a single trailing newline.
  • git diff --check passed.
  • Comments and error messages are in English.
  • Comments and error messages are complete sentences where applicable.

C++ Specific

  • Code follows the repository's Google C++ style conventions to the extent verified manually.
  • clang-format version 21 was not run in this session; remote build and git diff --check passed.
  • clang-tidy was not run in this session.
  • Operator parameter order is preserved from the generated base operator signatures.
  • No explicit exceptions are thrown by the added code.
  • N/A - no kernel files or launchers were added.
  • N/A - no new operator implementation classes were added.
  • No raw new/delete was added by this PR.

Python Specific

  • Python changes are limited to tests and generator code.
  • ruff check / ruff format --check were not run in this session.
  • Python smoke test passed remotely.

Testing

  • Relevant remote NVIDIA build and pytest results are recorded above.
  • Untested platforms are explicitly noted in the table.
  • New public C++ API has a smoke test under tests/test_cpp_api.py.
  • N/A - no new operator numerical tests were added.
  • N/A - no bug-fix regression test is required.

Build, CI, and Tooling

  • pip install .[dev] was not run.
  • CMake configure/build/install paths were verified remotely.
  • GENERATE_PYTHON_BINDINGS=ON pybind target still builds remotely.
  • No new runtime dependency was added.

Documentation

  • README-level public API documentation was not added in this PR.
  • Public API surface is exposed through installed headers and covered by smoke tests.
  • N/A - no user-visible breaking change is introduced.

Security and Safety

  • No secrets, access tokens, internal URLs, customer data, or personal hardware identifiers were committed.
  • No third-party code was added.
  • No unsafe pointer arithmetic, uninitialized reads, or missing bounds checks were introduced.

@voltjia
Copy link
Copy Markdown
Collaborator Author

voltjia commented May 21, 2026

请列出几组通过这样暴露出的 API 的函数签名。

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