Skip to content

fix(mul): handle broadcasted operand indexing - #935

Draft
voltjia wants to merge 1 commit into
masterfrom
fix/mul-broadcasting-indexing
Draft

fix(mul): handle broadcasted operand indexing#935
voltjia wants to merge 1 commit into
masterfrom
fix/mul-broadcasting-indexing

Conversation

@voltjia

@voltjia voltjia commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Expand Mul operand metadata to the output rank and use zero strides for broadcast dimensions.
  • Disable the contiguous fast path when an operand shape differs from the output shape, preventing out-of-bounds reads.
  • Cover scalar operands, reversed operand order, rank expansion, non-contiguous tensors, and empty outputs.

Motivation

Mul previously treated every contiguous operand as flat over the output. For an output such as [1, 151936], a contiguous [1, 1] operand was indexed beyond element zero instead of being broadcast. This could read out of bounds and surface later as non-finite results or an asynchronous device error.

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)
  • PyTorch C++ bindings (WITH_TORCH)
  • Build system / CMake / CI
  • Python bindings / user-facing API

Smoke Test Result

Validated exact public head b170ae2c1d85b6f51de332c916448729fa379fe5 on 8x A100 80 GB with accelerator-dev/nvidia:latest and InfiniRT 0cdbb16967e15f2e055dea1ec9641617bf3b6cf6:

Release smoke wheel: built and installed
NVIDIA smoke: 86 passed, 28 skipped, 6138 deselected in 17.58s
tests/test_mul.py --devices nvidia: 159 passed in 0.78s
BF16 [1, 151936] * [1, 1] direct Fill+Mul: 500/500 finite and exact allclose
Maximum absolute error: 0.0
Ruff 0.15.22: check passed; 160 files already formatted

All validation checkouts remained on the exact head with no tracked changes.

Test Results on Supported Platforms

Platform Affected Build / Smoke Result Full Result / Notes
CPU Yes Release smoke wheel built CPU runtime was not exercised separately.
NVIDIA Yes Smoke passed Full tests/test_mul.py 159/159; direct BF16 stress 500/500.
Iluvatar Yes Hosted regular and shadow CI passed Uses the shared CUDA Mul implementation.
MetaX Yes Hosted regular and shadow CI passed Uses the shared CUDA Mul implementation.
Cambricon No N/A - not affected No native Mul implementation consumes this metadata.
Moore Yes Hosted CI queued Uses the shared CUDA Mul implementation.
Ascend No N/A - not affected aclnnMul consumes the original tensor descriptors rather than the base indexing metadata.

Benchmark / Performance Impact

N/A. This is a correctness fix; kernel arithmetic and launch configuration are unchanged.

Notes for Reviewers

The key invariant is that a broadcasted operand must not take the contiguous fast path. Its logical shape is expanded to the output rank, and zero strides select the same source element along broadcast dimensions.

The first Ascend and Cambricon CI attempts were cancelled by self-hosted runner network failures (127.0.0.1:7897 proxy connection refused / artifact upload ECONNRESET) before compilation or tests. They are infrastructure failures, not failures in this patch; rerun is pending workflow availability.

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