Skip to content

feat(cambricon): add Embedding implementation - #926

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

feat(cambricon): add Embedding implementation#926
baominghelly wants to merge 1 commit into
masterfrom
feat/cambricon-embedding

Conversation

@baominghelly

Copy link
Copy Markdown
Contributor

Summary

  • Add a native Cambricon Embedding implementation with a CNNL fast path for contiguous tensors and a custom BANG C path for scalar and strided tensors.
  • Support max_norm renormalization and introduce reusable CNNL/CNRT resource helpers.
  • Extend embedding coverage to scalar index tensors.

Motivation

Enable native Embedding execution on Cambricon while preserving the existing InfiniOps interface for max_norm and layouts that CNNL does not accept directly.

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

The required affected-platform smoke build and tests -m smoke set have not been run after the latest commit. Focused Cambricon validation was run in container 0f34305d9bc9 on cambricon218_01:

/torch/venv3/pytorch/bin/python3.10 -m pytest tests/test_embedding.py -q --devices cambricon
............................................................             [100%]
60 passed in 0.33s

A clean Cambricon infiniops/ops build and installation also completed successfully during focused validation.

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 Focused clean build and installation passed; required smoke suite not run tests/test_embedding.py: 60 passed
Moore No N/A - not affected N/A - not affected
Ascend No N/A - not affected N/A - not affected
Focused validation output
clang-format version 21.1.2
clang-format --dry-run --Werror   src/native/cambricon/cnnl_utils.h   src/native/cambricon/cnrt_utils.h   src/native/cambricon/ops/embedding/kernel.h   src/native/cambricon/ops/embedding/kernel.mlu
# passed with no diagnostics

git diff --check upstream/master...HEAD
# passed with no diagnostics

/torch/venv3/pytorch/bin/python3.10 -m pytest tests/test_embedding.py -q --devices cambricon
............................................................             [100%]
60 passed in 0.33s

Benchmark / Performance Impact

N/A - this is a new backend implementation; no baseline benchmark was collected.

Notes for Reviewers

  • CNNL handles contiguous, non-scalar forward calls. The custom BANG C path handles scalar or strided forward calls and max_norm renormalization.
  • The custom forward path zero-fills output rows for out-of-range indices; reviewers should confirm this Cambricon behavior is acceptable because PyTorch raises IndexError.
  • cnnl_utils.h and cnrt_utils.h centralize reusable CNNL descriptor/handle ownership and CNRT device-buffer ownership for future Cambricon operators.
  • The launcher declaration is in kernel.h and its implementation is in kernel.mlu, matching existing Cambricon operator practice. This differs from the literal launcher-placement wording in CONTRIBUTING.md and should be confirmed by maintainers.
  • Before marking this PR ready, rebase onto current master and rerun the required affected-platform smoke build and smoke test set.

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