Skip to content

fix(cambricon): prevent duplicate half definitions - #982

Merged
voltjia merged 1 commit into
masterfrom
fix/cambricon-dispatch-batching
Sep 9, 2026
Merged

fix(cambricon): prevent duplicate half definitions#982
voltjia merged 1 commit into
masterfrom
fix/cambricon-dispatch-batching

Conversation

@baominghelly

Copy link
Copy Markdown
Contributor

Summary

  • Pre-include a Cambricon host compatibility header that gives Neuware FP16/BF16 helper definitions standard C++ inline linkage when they are parsed by GNU/Clang host compilers.
  • Apply the compatibility include to both the infiniops library and generated Python ops extension, with a regression test covering the CMake configuration.

Motivation

Neuware 6.0 leaves the BANG host annotation empty in its FP16/BF16 headers when they are parsed by a host C++ compiler. When generated dispatch or binding sources are split across multiple translation units, each object emits strong definitions for the same __half/BF16 helpers and the final shared-library link fails with multiple definition errors.

This fixes the linkage at the vendor-header boundary without changing dispatch batching or forcing all generated operators into one translation unit.

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

PYTHONNOUSERSITE=1 python -m pip install . --target /workspace/build/pr-c412dbb-site \
  --no-build-isolation --no-deps --no-cache-dir \
  -C cmake.define.INFINI_RT_ROOT=/workspace/install/infinirt-master-test \
  -C cmake.define.AUTO_DETECT_DEVICES=OFF \
  -C cmake.define.AUTO_DETECT_BACKENDS=OFF \
  -C cmake.define.WITH_CPU=ON \
  -C cmake.define.WITH_CAMBRICON=ON \
  -C cmake.define.WITH_NVIDIA=OFF \
  -C cmake.define.INFINI_OPS_SMOKE_BUILD=ON

Successfully built InfiniOps
Successfully installed InfiniOps-0.1.0

PYTHONNOUSERSITE=1 PYTHONPATH=/workspace/build/pr-c412dbb-site \
  python -m pytest tests -m smoke -q --devices cambricon

1 failed, 77 passed, 38 skipped, 4635 deselected in 5.91s

The single failure is the existing Cambricon CNNL FP16 GEMM numerical-tolerance case in tests/test_gemm.py (rtol=0.001, atol=0.001). It is outside the files and linkage path changed by this PR.

Test Results on Supported Platforms

Platform Affected Build / Smoke Result Full Result / Notes
NVIDIA No N/A - not affected N/A - not affected
Iluvatar No N/A - not affected N/A - not affected
MetaX No N/A - not affected N/A - not affected
Cambricon Yes Wheel build passed; smoke: 77 passed, 38 skipped, 1 existing GEMM tolerance failure Full suite not run; wrapper regression tests: 40 passed
Moore No N/A - not affected N/A - not affected
Ascend No N/A - not affected N/A - not affected
Additional validation
clang-format version 21.1.2
clang-format --dry-run --Werror src/native/cambricon/host_bang_compat.h
# passed

git diff --check origin/master...HEAD
# passed

python -m pytest -q tests/test_generate_wrappers.py
40 passed in 5.76s

Benchmark / Performance Impact

N/A. This changes host-side linkage semantics during compilation and does not change operator kernels or runtime dispatch behavior.

Notes for Reviewers

  • The forced include is gated by WITH_CAMBRICON, GNU/Clang, and host C++ compilation. It does not apply to .mlu device compilation or other backends.
  • Both infiniops and the generated Python ops target need the compatibility include because each can contain multiple generated dispatch translation units.
  • This intentionally keeps the normal dispatch batch size and does not add INFINI_OPS_DISPATCH_BATCH_SIZE.
  • The known Cambricon FP16 GEMM tolerance failure is intentionally not mixed into this focused linkage fix.

@baominghelly
baominghelly marked this pull request as ready for review September 9, 2026 07:04
@baominghelly
baominghelly requested review from a team and voltjia September 9, 2026 07:04
@voltjia
voltjia merged commit a00dbac into master Sep 9, 2026
12 of 20 checks passed
@voltjia
voltjia deleted the fix/cambricon-dispatch-batching branch September 9, 2026 07:35
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