Skip to content

feat(cpu): add SiLU implementation - #859

Merged
voltjia merged 1 commit into
masterfrom
feat/cpu-silu
Aug 3, 2026
Merged

feat(cpu): add SiLU implementation#859
voltjia merged 1 commit into
masterfrom
feat/cpu-silu

Conversation

@voltjia

@voltjia voltjia commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • This PR adds Operator<Silu, Device::Type::kCpu> for contiguous and strided CPU tensors.
  • This PR supports float16, bfloat16, float32, and float64 while promoting float16 and bfloat16 computation to float32.

Motivation

The torch-infini PrivateUse1 plugin needs InfiniOps to expose Silu in CPU-only builds before it can register standard aten::silu while retaining its no-accelerator fallback. Without a CPU specialization, the generated public operator header omits Silu because no active CPU implementation exists. Adding the native CPU path makes the generated call surface available and keeps CPU fallback behavior consistent with accelerator builds.

No issue is linked to this prerequisite change.

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 operator is intentionally excluded from the minimal smoke allowlist because it reuses the existing elementwise execution path. Therefore, INFINI_OPS_SMOKE_BUILD=ON would not compile or exercise this implementation. The affected CPU path was instead validated with a full CPU-only wheel build, followed by the unchanged smoke suite and the complete SiLU test module.

The exact commit 023f7fc15736464947281f0c638e6a319c7bdaa9 was built in accelerator-dev/nvidia:latest against a CPU-only install of InfiniRT 95c70080f9551e61241110497d163dfcdf9dc7e7.

python -m pip wheel --no-build-isolation --no-deps . -w /out/wheel \
  -C cmake.define.INFINI_RT_ROOT=/opt/infinirt \
  -C cmake.define.WITH_CPU=ON \
  -C cmake.define.AUTO_DETECT_DEVICES=OFF \
  -C cmake.define.AUTO_DETECT_BACKENDS=OFF
Successfully built InfiniOps

python -m pytest tests -m smoke --devices cpu -q
62 passed, 13 skipped, 4212 deselected in 3.46s

The smoke collection contained no tests/test_silu.py cases. The modified C++ file also passed clang-format.

Test Results on Supported Platforms

Platform Affected Build / Smoke Result Full Result / Notes
CPU Yes full build passed; smoke passed The complete SiLU module passed all 24 cases. The repository full suite was not run.
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 No N/A - not affected N/A - not affected
Moore No N/A - not affected N/A - not affected
Ascend No N/A - not affected N/A - not affected
Full `pytest` output (optional)
python -m pytest tests/test_silu.py --devices cpu -q
24 passed in 1.17s

Benchmark / Performance Impact

N/A. This correctness-only PR does not claim a performance change.

Notes for Reviewers

Please focus on the strided indexing and the promoted float32 computation used for float16 and bfloat16 inputs. This PR intentionally does not change the smoke allowlist. It is a prerequisite for registering standard aten::silu in torch-infini without breaking CPU-only builds or CPU fallback execution.

@voltjia
voltjia requested a review from a team July 30, 2026 03:12
@voltjia
voltjia merged commit 2cfb526 into master Aug 3, 2026
16 of 20 checks passed
@voltjia
voltjia deleted the feat/cpu-silu branch August 3, 2026 03:17
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