Skip to content

feat: build C API on functional operator API#617

Draft
voltjia wants to merge 2 commits into
feat/cpp-operator-apifrom
feat/operator-c-api
Draft

feat: build C API on functional operator API#617
voltjia wants to merge 2 commits into
feat/cpp-operator-apifrom
feat/operator-c-api

Conversation

@voltjia
Copy link
Copy Markdown
Collaborator

@voltjia voltjia commented May 20, 2026

Summary

  • Keep the stable C ABI declarations in the unified public header include/infini/ops.h.
  • Remove public InfiniOpsTensorDescriptor and descriptor create/destroy APIs.
  • Make InfiniOpsTensor a direct C value struct that describes caller-owned memory: data pointer, byte size, dtype, device, rank, shape, and stride.
  • Keep InfiniOpsHandle and InfiniOpsConfig because they correspond to existing C++ Handle and Config.
  • Implement C wrappers as thin adapters over infini::ops::functional::Add.
  • Ensure src/infini/ops.cc builds as normal C++ and no longer includes backend kernel headers.

Motivation

This is the second PR in the public operator API split. After the public C++ functional API exists, the stable C ABI can be implemented on top of that layer instead of depending on private dispatch or backend kernel headers.

Target base branch: feat/cpp-operator-api.

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_c_api.py tests/test_cpp_api.py: 4 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-pr2 python -m pytest tests/test_c_api.py tests/test_cpp_api.py -q
Running 4 items in this shard
....                                                                     [100%]
4 passed in 1.73s

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

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

Verified build/link details:

src/infini/ops.cc compiled as CXX object.
SONAME: libinfiniops.so.1
Defined C ABI symbols: infiniOpsAdd, infiniOpsCreateConfig, infiniOpsCreateHandle, infiniOpsDestroyConfig, infiniOpsDestroyHandle, infiniOpsGetLastError.
Defined C++ functional symbol includes: infini::ops::functional::Add(...)

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

Benchmark / Performance Impact

N/A. This PR changes API wrapping and validation. It does not change operator kernels or dispatch selection.

Notes for Reviewers

  • This PR should target feat/cpp-operator-api, not master, so the diff only shows the stable C ABI layer on top of the C++ functional API.
  • The C ABI remains the stable ABI boundary. The C++ functional API remains a source/link convenience layer.
  • InfiniOpsTensor does not own caller buffers and is not destroyed by the library.
  • InfiniOpsHandle and InfiniOpsConfig remain opaque handles because they map to existing C++ Handle and Config.
  • The C wrapper intentionally calls infini::ops::functional::Add and no longer includes backend kernel headers.

Checklist

Title, Branch, and Commits

  • PR title follows Conventional Commits: feat: build C API on functional operator API.
  • Branch name follows the expected <type>/... form: feat/operator-c-api.
  • Commit message follows Conventional Commits: feat: build C API on functional operator API.
  • Branch currently contains the PR1 dependency merge; retarget this PR to feat/cpp-operator-api so reviewers see only the C ABI diff.
  • No fixup! / squash! / wip commits remain.

Scope and Design

  • Changes are scoped to the C ABI, tests, and required build/export integration.
  • 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 reflected in 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-facing parameter order is preserved: handle/config first for API control, then inputs, then outputs.
  • No explicit exceptions are thrown; the C ABI catches C++ allocation/runtime failures and returns InfiniOpsStatus.
  • Error paths return InfiniOpsStatus and expose details through infiniOpsGetLastError.
  • N/A - no kernel files or launchers were added.
  • N/A - no new operator implementation classes were added.
  • The C ABI currently uses opaque handle ownership internally; reviewer attention requested for allocation/lifetime style.

Python Specific

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

Testing

  • Relevant remote NVIDIA build and pytest results are recorded above.
  • Untested platforms are explicitly noted in the table.
  • New C ABI smoke coverage exists in tests/test_c_api.py.
  • Existing external C++ smoke coverage remains in 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.
  • src/infini/ops.cc builds as CXX, not CUDA.
  • SONAME was verified as libinfiniops.so.1.
  • C ABI exported symbols were verified to use the infiniOps* prefix.
  • No new runtime dependency was added.

Documentation

  • README-level public C ABI documentation was not added in this PR.
  • Public API surface is represented in include/infini/ops.h and covered by smoke tests.
  • Public ABI ownership semantics are represented by InfiniOpsTensor being a value struct for caller-owned buffers.

Security and Safety

  • No secrets, access tokens, internal URLs, customer data, or personal hardware identifiers were committed.
  • No third-party code was added.
  • Tensor validation checks null pointers, rank, shape, stride, byte size, and overflow-sensitive size calculations before calling the C++ API.

@voltjia voltjia changed the title feat: add operator C API feat: build C API on functional operator API May 20, 2026
@voltjia voltjia changed the base branch from master to feat/cpp-operator-api May 20, 2026 08:34
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