Skip to content

Conversation

@yuerqiqi
Copy link
Contributor

@yuerqiqi yuerqiqi commented Jan 20, 2026

Description

This PR adds support for Subtraction and Multiplication element-wise operations on the Ascend backend.

Changes

  • Implemented AscendSubOp and AscendMulOp.
  • Added corresponding unit tests (SubFloat16 and MulFloat16) in AscendKernelTest.

Summary by CodeRabbit

Release Notes

  • New Features

    • Extended Ascend backend with support for subtraction and multiplication elementwise operations.
    • Enhanced build configuration with improved dependency resolution.
  • Tests

    • Added comprehensive test coverage for new subtraction and multiplication operations.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 20, 2026

📝 Walkthrough

Walkthrough

The changes add support for two new elementwise operations (subtraction and multiplication) to the Ascend backend, including operation implementations, factory registrations, CMake build configuration updates, and corresponding unit tests with FP16 validation.

Changes

Cohort / File(s) Summary
Operation Registration & Build Configuration
mllm/backends/ascend/AscendBackend.cpp, mllm/backends/ascend/CMakeLists.txt
Registers AscendSubOpFactory and AscendMulOpFactory; adds fallback ATB_HOME_PATH resolution to ${PROJECT_SOURCE_DIR}/../libs/atb
Operation Declarations
mllm/backends/ascend/ops/AscendElewiseOps.hpp
Declares AscendSubOp/AscendSubOpFactory and AscendMulOp/AscendMulOpFactory classes following AscendAddOp pattern
Operation Implementations
mllm/backends/ascend/ops/AscendElewiseOps.cpp
Implements Sub and Mul elementwise operations with constructors, setup, and forward methods; includes workspace management and ATB op execution
Tests
tests/ascend/AscendKernelTest.hpp, tests/ascend/KernelTest.cpp
Adds SubFloat16Test and MulFloat16Test utility methods; includes TEST_F test cases with FP16 validation and allClose tolerance checks

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Poem

🐰 Hop, skip, and multiply—or subtract with glee!
Two new operations join the Ascend symphony.
Sub and Mul now dance in tandem bright,
With tests aglow in FP16 light.
The backend grows, one kernel at a time! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: implementing element-wise operations for the Ascend backend.
Description check ✅ Passed The description provides a clear summary of changes with specific implementation details (AscendSubOp, AscendMulOp) and mentions the corresponding tests added.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@mllm/backends/ascend/CMakeLists.txt`:
- Around line 37-40: The fallback block that configures ATB when EXISTS
"${PROJECT_SOURCE_DIR}/../libs/atb" must guard against partial installs: before
calling target_include_directories and target_link_directories for target
MllmAscendBackend, check that both "${PROJECT_SOURCE_DIR}/../libs/atb/include"
and "${PROJECT_SOURCE_DIR}/../libs/atb/lib" exist (use if(EXISTS ...) or
if(IS_DIRECTORY ...)); only add the include and link directories when both are
present, otherwise emit a message(WARNING ...) and skip wiring the paths so
CMake doesn't get invalid search paths.
🧹 Nitpick comments (3)
mllm/backends/ascend/ops/AscendElewiseOps.hpp (1)

27-55: Add brief API comments for new public ops/factories.

These are public-facing classes in a header; consider short comments mirroring the existing Add op style so their purpose/usage is explicit. As per coding guidelines, public APIs should be documented.
As per coding guidelines, add brief API docs for these new public classes/factories.

mllm/backends/ascend/ops/AscendElewiseOps.cpp (1)

109-195: Consider extracting shared elementwise forward logic.

Sub and Mul closely mirror Add’s forward path; a small helper (e.g., taking the elewise type + trace name) would reduce duplication and future drift.

tests/ascend/AscendKernelTest.hpp (1)

52-120: Replace repeated FP16 tolerance literals with a named constant.

This keeps the new tests consistent and avoids spreading magic numbers. As per coding guidelines, use named constants instead of literals.
As per coding guidelines, use a named constant for the tolerance.

♻️ Suggested tweak
   bool SubFloat16Test(const std::vector<mllm::Tensor::shape_t>& shapes) {
     using namespace mllm;  // NOLINT
+    constexpr float kTol = 1e-2f;
     for (auto& shape : shapes) {
@@
-      auto result = mllm::test::allClose(z_cpu, ref_cpu, 1e-2f, 1e-2f);
+      auto result = mllm::test::allClose(z_cpu, ref_cpu, kTol, kTol);
@@
   bool MulFloat16Test(const std::vector<mllm::Tensor::shape_t>& shapes) {
     using namespace mllm;  // NOLINT
+    constexpr float kTol = 1e-2f;
     for (auto& shape : shapes) {
@@
-      auto result = mllm::test::allClose(z_cpu, ref_cpu, 1e-2f, 1e-2f);
+      auto result = mllm::test::allClose(z_cpu, ref_cpu, kTol, kTol);

Comment on lines +37 to +40
elseif(EXISTS "${PROJECT_SOURCE_DIR}/../libs/atb")
message(STATUS "Found ATB in ${PROJECT_SOURCE_DIR}/../libs/atb")
target_include_directories(MllmAscendBackend PUBLIC "${PROJECT_SOURCE_DIR}/../libs/atb/include")
target_link_directories(MllmAscendBackend PUBLIC "${PROJECT_SOURCE_DIR}/../libs/atb/lib")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# First, check if the file exists and examine its structure
find . -name "CMakeLists.txt" -path "*/backends/ascend/*" | head -20

Repository: UbiquitousLearning/mllm

Length of output: 104


🏁 Script executed:

# Get the full CMakeLists.txt file to verify lines 37-40 and understand context
if [ -f "mllm/backends/ascend/CMakeLists.txt" ]; then
  echo "=== File exists, showing content with line numbers ==="
  cat -n "mllm/backends/ascend/CMakeLists.txt" | head -50
else
  echo "File not found at mllm/backends/ascend/CMakeLists.txt"
fi

Repository: UbiquitousLearning/mllm

Length of output: 2355


🏁 Script executed:

# Check for similar ATB-related paths in the codebase
rg -n "libs/atb" --type cmake

Repository: UbiquitousLearning/mllm

Length of output: 531


Guard the ATB fallback path against partial installs.

If ../libs/atb exists but the include/ or lib/ subdirectories are missing, CMake will add invalid search paths that fail later during compilation. Check for required subdirectories before wiring the paths.

🔧 Suggested guard
-elseif(EXISTS "${PROJECT_SOURCE_DIR}/../libs/atb")
-  message(STATUS "Found ATB in ${PROJECT_SOURCE_DIR}/../libs/atb")
-  target_include_directories(MllmAscendBackend PUBLIC "${PROJECT_SOURCE_DIR}/../libs/atb/include")
-  target_link_directories(MllmAscendBackend PUBLIC "${PROJECT_SOURCE_DIR}/../libs/atb/lib")
+elseif(EXISTS "${PROJECT_SOURCE_DIR}/../libs/atb/include" AND EXISTS "${PROJECT_SOURCE_DIR}/../libs/atb/lib")
+  message(STATUS "Found ATB in ${PROJECT_SOURCE_DIR}/../libs/atb")
+  target_include_directories(MllmAscendBackend PUBLIC "${PROJECT_SOURCE_DIR}/../libs/atb/include")
+  target_link_directories(MllmAscendBackend PUBLIC "${PROJECT_SOURCE_DIR}/../libs/atb/lib")
+elseif(EXISTS "${PROJECT_SOURCE_DIR}/../libs/atb")
+  message(WARNING "ATB fallback path exists but include/lib are missing; skipping")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
elseif(EXISTS "${PROJECT_SOURCE_DIR}/../libs/atb")
message(STATUS "Found ATB in ${PROJECT_SOURCE_DIR}/../libs/atb")
target_include_directories(MllmAscendBackend PUBLIC "${PROJECT_SOURCE_DIR}/../libs/atb/include")
target_link_directories(MllmAscendBackend PUBLIC "${PROJECT_SOURCE_DIR}/../libs/atb/lib")
elseif(EXISTS "${PROJECT_SOURCE_DIR}/../libs/atb/include" AND EXISTS "${PROJECT_SOURCE_DIR}/../libs/atb/lib")
message(STATUS "Found ATB in ${PROJECT_SOURCE_DIR}/../libs/atb")
target_include_directories(MllmAscendBackend PUBLIC "${PROJECT_SOURCE_DIR}/../libs/atb/include")
target_link_directories(MllmAscendBackend PUBLIC "${PROJECT_SOURCE_DIR}/../libs/atb/lib")
elseif(EXISTS "${PROJECT_SOURCE_DIR}/../libs/atb")
message(WARNING "ATB fallback path exists but include/lib are missing; skipping")
🤖 Prompt for AI Agents
In `@mllm/backends/ascend/CMakeLists.txt` around lines 37 - 40, The fallback block
that configures ATB when EXISTS "${PROJECT_SOURCE_DIR}/../libs/atb" must guard
against partial installs: before calling target_include_directories and
target_link_directories for target MllmAscendBackend, check that both
"${PROJECT_SOURCE_DIR}/../libs/atb/include" and
"${PROJECT_SOURCE_DIR}/../libs/atb/lib" exist (use if(EXISTS ...) or
if(IS_DIRECTORY ...)); only add the include and link directories when both are
present, otherwise emit a message(WARNING ...) and skip wiring the paths so
CMake doesn't get invalid search paths.

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