Skip to content

feat(cambricon): add ReLU provider - #960

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

feat(cambricon): add ReLU provider#960
baominghelly wants to merge 1 commit into
masterfrom
feat/cambricon-relu

Conversation

@baominghelly

Copy link
Copy Markdown
Contributor

Summary

  • Add a native Cambricon ReLU provider in src/native/cambricon/ops/relu/.
  • Support contiguous and strided tensors, in-place execution, partial-overlap staging, integer dtypes, and PyTorch-compatible special-value semantics.
  • Reuse the shared Cambricon task-range and logical-offset helpers from src/native/cambricon/kernel_utils.h.

Motivation

InfiniOps currently lacks a native Cambricon implementation for the canonical relu operator. This provider enables ReLU execution on Cambricon without relying on another backend.

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

cmake -S . -B /workspace/build/pr-relu-20260901 \
  -DAUTO_DETECT_DEVICES=OFF \
  -DWITH_CPU=ON \
  -DWITH_CAMBRICON=ON \
  -DWITH_TORCH=OFF \
  -DWITH_LINKED=OFF \
  -DGENERATE_PYTHON_BINDINGS=ON \
  -DINFINI_OPS_OPS=relu \
  -DINFINI_RT_ROOT=/workspace/install/infinirt-master-test \
  -DPython_EXECUTABLE=/torch/venv3/pytorch/bin/python3.10 \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_INSTALL_PREFIX=/workspace/build/pr-relu-20260901-site/infini
cmake --build /workspace/build/pr-relu-20260901 --parallel "$(nproc)"
cmake --install /workspace/build/pr-relu-20260901

Result: targeted Cambricon build and install passed.

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 Targeted build passed python -m pytest -q tests/test_relu.py --devices cambricon --maxfail=1 -rs: 38 passed, 9 skipped
Moore No N/A - not affected N/A - not affected
Ascend No N/A - not affected N/A - not affected
Full `pytest` output (optional)
sssssss................................ss......                          [100%]
SKIPPED [7] tests/test_relu.py:55: Cambricon device code does not support float64 comparisons
SKIPPED [2] tests/test_relu.py:136: Cambricon device code does not support float64 comparisons
38 passed, 9 skipped in 0.31s

Benchmark / Performance Impact

N/A - no benchmark was run.

Notes for Reviewers

  • Supported dtypes are float32, float16, bfloat16, int64, int32, int16, int8, and uint8.
  • Float16 and bfloat16 values are converted to float32 in NRAM for comparison so NaN and signed-zero behavior matches PyTorch.
  • Float64 is intentionally rejected because the Cambricon device compiler does not support the required float64 comparisons; the corresponding MLU cases are skipped explicitly.
  • The implementation stages input data when input/output partially overlap and supports both contiguous and strided layouts.
  • Repository-wide smoke tests were not run; this Draft PR records the targeted Cambricon build and complete tests/test_relu.py result.

@baominghelly
baominghelly marked this pull request as ready for review September 1, 2026 07:32
@baominghelly
baominghelly requested a review from a team September 1, 2026 07:32
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