Skip to content

Add CUDA BitwiseXor integer kernels - #33645

Open
Justin Chu (justinchuby) wants to merge 1 commit into
mainfrom
justinchuby-cuda-bitwise-xor
Open

Justin Chu (justinchuby) wants to merge 1 commit into
mainfrom
justinchuby-cuda-bitwise-xor

Conversation

@justinchuby

Copy link
Copy Markdown
Contributor

Description

Add CUDA execution for standard ONNX BitwiseXor (opset 18+) for int8, uint8, int16, uint16, int32, uint32, int64, and uint64. Reuse the existing binary elementwise implementation for multidirectional broadcasting and empty tensors. Boolean Xor is unchanged; this does not add other bitwise operators.

Add CUDA-only regressions with CPU fallback explicitly disabled, covering all eight integer types at opsets 18 and 24, signed/unsigned boundaries, scalar operands, multidirectional broadcasting in both operand orders, empty outputs, and the INT64 state XOR (state / 2048) RNG pattern. Update the CUDA operator support table.

Validation on Azure Linux 3 / NVIDIA H200 (physical GPU4), CUDA 13.3, cuDNN 9.10.2, Python 3.12, Release/sm90; source based on main 997d2d1b26 plus this patch:

  • python tools/ci_build/build.py --config Release --build_dir /tmp/ort-cuda-bitwise-xor-8d05709c/build --build --build_wheel --skip_tests --skip_submodule_sync --use_cuda --cuda_home /usr/local/cuda --cudnn_home /usr/lib/python3.12/site-packages/nvidia/cudnn --parallel 16 --disable_contrib_ops --disable_ml_ops --targets onnxruntime_provider_test onnxruntime_pybind11_state — passed, producing an ORT 1.32.0 GPU wheel. The build was configured with Ninja, CMAKE_CUDA_ARCHITECTURES=90, onnxruntime_QUICK_BUILD=ON, and Flash/MEA/TRT-fused-attention/XQA disabled.
  • From the build output directory: CUDA_VISIBLE_DEVICES=4 LD_LIBRARY_PATH=/usr/local/cuda/lib64:/usr/lib/python3.12/site-packages/nvidia/cudnn/lib ./onnxruntime_provider_test --gtest_filter=*Xor* — 45 tests passed, no skips, including existing boolean XOR tests.
  • Additional ad hoc wheel probe: 146/146 models produced bit-identical NumPy results, and 146/146 profiled BitwiseXor executions used CUDAExecutionProvider, with CPU fallback disabled. This covers all integer types, opsets 18/24, full-width random values (including upper 64-bit lanes), scalar/multidirectional/empty cases, and integrated Div → BitwiseXor graphs over 4,103 INT64 RNG states. Before installing the patched wheel, the same probes on ORT 1.28.0 (0368187f84) produced 146 CPU XOR executions; GPU-only initialization failed as expected.
  • clang-format --dry-run --Werror on all six changed C++/CUDA files — passed; git diff --check — passed.

The initial untargeted contrib-disabled build encountered a pre-existing -Werror=unused-function in onnxruntime/test/optimizer/nhwc_transformer_test.cc:71; the relevant provider-test and wheel targets above built successfully without changing unrelated code. Full-suite, non-sm90, full-model fidelity, and performance validation were not performed.

Motivation and Context

Current main has CPU and DirectML BitwiseXor kernels but no CUDA registration. Integer RNG hashing therefore falls back to CPU, even for INT32/UINT32, introducing repeated device transfers in GPU inference. This was observed while adding fishaudio/drama-3 support in onnxruntime/mobius#793 (2,862 CPU XOR executions in one sampled profile). Supporting the standard operator preserves the model's RNG algorithm and exact integer outputs without a custom operator or graph rewrite.

Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 27, 2026 17:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The scoped implementation, registrations, documentation, and fallback-disabled regression coverage are consistent, with no unresolved blocking issues.

No open issues 🎉

What changed in this PR

Adds CUDA support for standard ONNX BitwiseXor at opset 18+, allowing integer XOR workloads to stay on the GPU without changing boolean Xor.

Changes:

  • Registers kernels for all eight signed and unsigned integer types using existing binary elementwise infrastructure.
  • Adds CPU-fallback-disabled CUDA regressions for boundaries, broadcasting, scalars, empty outputs, and INT64 RNG-state XOR values at opsets 18 and 24.
  • Updates the CUDA operator support table.

No actionable findings remain.

File Description
onnxruntime/​test/​providers/​cpu/​math/​element_wise_ops_test.cc Adds CUDA-only integer XOR regression coverage.
onnxruntime/​core/​providers/​cuda/​math/​binary_elementwise_ops.h Declares the typed BitwiseXor kernel.
onnxruntime/​core/​providers/​cuda/​math/​binary_elementwise_ops.cc Defines registrations for eight integer types.
onnxruntime/​core/​providers/​cuda/​math/​binary_elementwise_ops_impl.h Adds the integer XOR expression.
onnxruntime/​core/​providers/​cuda/​math/​binary_elementwise_ops_impl.cu Instantiates typed CUDA implementations.
onnxruntime/​core/​providers/​cuda/​cuda_execution_provider.cc Includes the kernels in CUDA provider registration.
docs/​OperatorKernels.md Documents CUDA BitwiseXor support.

Review effort: Balanced

This branch has not been deployed

No deployments
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.

2 participants