Skip to content

feat(cambricon): add Add operator - #921

Open
baominghelly wants to merge 1 commit into
masterfrom
feat/cambricon-add
Open

feat(cambricon): add Add operator#921
baominghelly wants to merge 1 commit into
masterfrom
feat/cambricon-add

Conversation

@baominghelly

@baominghelly baominghelly commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add a Cambricon backend for Add in src/native/cambricon/ops/add/, including alpha, broadcasting, non-contiguous layouts, and contiguous fast-path execution.
  • Support float16, bfloat16, float32, int32, and int64, and skip dtype combinations that torch.mlu cannot clone before backend execution.

Motivation

Extend canonical Add coverage to Cambricon while matching the current input + alpha * other interface and preserving the default alpha=1 overload. The implementation handles both contiguous tensors and broadcast/strided layouts used by the existing cross-platform Add test matrix.

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

Focused Cambricon Add build and full operator test in infinicore-cambricon-dev-libaoming on cambricon218_01:

cmake --build /workspace/build/infiniops-refresh-add --target ops -j8
[7/7] Linking CXX shared module src/ops.cpython-310-x86_64-linux-gnu.so

/torch/venv3/pytorch/bin/python3.10 -m pytest -q tests/test_add.py --devices cambricon
84 passed, 48 skipped in 0.80s

The repository-wide default Cambricon smoke set was not run; validation was scoped to the affected operator.

Test Results on Supported Platforms

Platform Affected Build / Smoke Result Full Result / Notes
NVIDIA No N/A - not affected N/A
Iluvatar No N/A - not affected N/A
MetaX No N/A - not affected N/A
Cambricon Yes Focused Add-only build passed tests/test_add.py: 84 passed, 48 skipped
Moore No N/A - not affected N/A
Ascend No N/A - not affected N/A
Full `pytest` output
...s..sss...s..sss...s..sss...s..sss...s..sss...s..sss...s..sss...s..sss [ 54%]
...s..sss...s..sss...s..sss...s..sss........................             [100%]
84 passed, 48 skipped in 0.80s

Benchmark / Performance Impact

N/A. This PR adds backend coverage and makes no performance claim.

Notes for Reviewers

  • The fast path handles contiguous tensors with identical shapes; the general path handles broadcasting and arbitrary input/output strides.
  • Device-aware DispatchFunc maps the runtime dtype to Cambricon native types.
  • Floating-point alpha is converted to float for device execution; integral tensors use an integral alpha, as validated by the base operator.
  • The added MLU skips cover torch.mlu cloning limitations for int16 and unsigned integer dtypes before the InfiniOps kernel is invoked.
  • clang-format 21.1.2 was installed in the Cambricon container; clang-format --dry-run --Werror passed for the two added native files.

@baominghelly
baominghelly marked this pull request as ready for review August 12, 2026 02:03
@baominghelly
baominghelly requested review from a team and voltjia August 12, 2026 02:03
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