Skip to content

feat(cambricon): link Apex silu_and_mul - #876

Merged
voltjia merged 3 commits into
fix/linked-readelf-demanglingfrom
feat/linked-cambricon-silu-and-mul
Aug 7, 2026
Merged

feat(cambricon): link Apex silu_and_mul#876
voltjia merged 3 commits into
fix/linked-readelf-demanglingfrom
feat/linked-cambricon-silu-and-mul

Conversation

@voltjia

@voltjiavoltjia commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add Cambricon Apex silu_and_mul as implementation slot 16.
  • Reuse TorchSiluAndMul<Backend> for tensor wrapping, contiguous staging, and output copy-back.
  • Use C10<Device::Type::kCambricon> to bind the caller's CNRT queue to a C10 stream guard.
  • Keep the Apex-specific zero-bias and returned-Tensor mapping in ApexSiluAndMul::Call.

Motivation

The Cambricon Apex package exports packed SiLU-and-multiply semantics through:

bias_swiglu_fwd(at::Tensor const&, at::Tensor const&)

Linking that exported ABI avoids copying the vendor kernel into InfiniOps while preserving the existing silu_and_mul(input, out) public interface.

Depends on #875. N/A - 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

Platforms Affected

  • CPU (WITH_CPU)
  • NVIDIA (WITH_NVIDIA)
  • Iluvatar (WITH_ILUVATAR)
  • MetaX (WITH_METAX)
  • Cambricon (WITH_CAMBRICON)
  • Moore (WITH_MOORE)
  • Ascend (WITH_ASCEND)
  • Hygon (WITH_HYGON)
  • PyTorch C++ bindings (WITH_TORCH)
  • Build system / CMake / CI
  • Python bindings / user-facing API

Smoke Test Result

Vendor environment:

  • host: ssh cambricon
  • image: cambricon/pytorch:v1.25.3-torch2.1-anolisos8.8-py310
  • image ID: sha256:d3544201bc7039f328abf137d154b24a89a17fdd48a487dc0ae0bdd6d14a5cf6
  • linked package: apex==0.1+mlu0.8.0

Runtime evidence collected at 2e781a5b:

INFINI_OPS_OPS=silu_and_mul, WITH_CAMBRICON=ON, WITH_LINKED=ON, WITH_TORCH=OFF
python3 -m pytest tests/test_silu_and_mul.py -m smoke --devices cambricon -q
2 passed, 23 deselected in 0.90s
python3 -m pytest tests/test_silu_and_mul.py --devices cambricon -q
25 passed

At b9ca02c6, both Cambricon main CI and Cambricon shadow CI passed. Current head d0eac65d only renames the logical mapping from apex to apex_glu_activation and updates its binding. Build, formatting, Ruff, and the main Cambricon/Ascend/Moore/MetaX jobs pass; the remaining self-hosted jobs are pending.

Test Results on Supported Platforms

Focused host-independent validation at c2bbc2df:

python -m pytest --noconftest tests/test_resolve_linked_ops.py tests/test_generate_wrappers.py -q
39 passed
ruff format --check tests/test_silu_and_mul.py
1 file already formatted
ruff check tests/test_silu_and_mul.py
All checks passed!
clang-format --dry-run --Werror <Cambricon linked C++ files>
exit 0

Benchmark / Performance Impact

N/A - this PR validates correctness and linkage; it makes no performance claim.

Notes for Reviewers

  • ApexSiluAndMul inherits C10<Device::Type::kCambricon> and supplies only the external ABI call.
  • The logical library name apex_glu_activation identifies the concrete glu_activation*.so DSO; other Apex DSOs use separate mappings, such as apex_fused_layer_norm.
  • C10<Device::Type::kCambricon> uses torch_mlu::getStreamFromExternal and c10::StreamGuard, so execution stays on the caller-provided stream.
  • Apex represents no bias with a zero-length integer Tensor and returns a Tensor; ApexSiluAndMul::Call maps those details to the shared output-oriented adapter.
  • WITH_TORCH=OFF disables the generated ATen backend. The linked implementation still uses the installed Torch/torch-mlu C++ ABI required by the external library.
  • The Cambricon environment requires fix(linked): support readelf without demangling #875 because its GNU readelf does not provide --demangle.

@voltjia
voltjiaforce-pushed the feat/linked-cambricon-silu-and-mul branch from 8bc996f to dd31ddbCompareAugust 4, 2026 04:16
@voltjia
voltjiaforce-pushed the feat/linked-cambricon-silu-and-mul branch from dd31ddb to 2e781a5CompareAugust 6, 2026 01:30
@voltjia
voltjiaforce-pushed the feat/linked-cambricon-silu-and-mul branch from 2e781a5 to 518e385CompareAugust 6, 2026 08:44
@voltjia
voltjiaforce-pushed the feat/linked-cambricon-silu-and-mul branch from 518e385 to b9ca02cCompareAugust 6, 2026 08:49
@voltjiavoltjia changed the title feat(cambricon): link Apex silu_and_mulfeat(cambricon): link Apex silu_and_mulAug 6, 2026
@voltjia
voltjiaforce-pushed the feat/linked-cambricon-silu-and-mul branch from b9ca02c to c2bbc2dCompareAugust 6, 2026 09:18
@voltjia
voltjia marked this pull request as ready for review August 6, 2026 09:20
@voltjia
voltjia requested a review from a teamAugust 6, 2026 09:20
@voltjiavoltjia mentioned this pull request Aug 6, 2026
19 tasks
@voltjiavoltjia mentioned this pull request Aug 6, 2026
19 tasks
@voltjia
voltjia merged commit f0332f8 into masterAug 7, 2026
18 of 20 checks passed
@voltjia
voltjia deleted the feat/linked-cambricon-silu-and-mul branch August 7, 2026 10:59
Sign up for freeto 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.

3 participants

@voltjia@whjthu@Ziminli