Skip to content

Fix arena configuration handling and optimize CUDA GEMV and prefill - #33381

Open
Akshay Sonawane (apsonawane) wants to merge 4 commits into
mainfrom
asonawane/generic-cuda-memory-kernels-main
Open

Akshay Sonawane (apsonawane) wants to merge 4 commits into
mainfrom
asonawane/generic-cuda-memory-kernels-main

Conversation

@apsonawane

@apsonawane Akshay Sonawane (apsonawane) commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fix allocator edge cases and improve parallelism in existing CUDA GEMV and causal-convolution kernels. These changes are based directly on main and do not introduce model-specific operators or schema changes.

Allocator fixes

  • Avoid splitting an exact-size free chunk when max_dead_bytes_per_chunk is zero.
  • Support setting and querying default_memory_arena_cfg through the CUDA pointer-provider-option APIs.
  • Copy the arena configuration into provider-owned storage so it remains valid after the caller releases the original configuration.
  • Return an invalid-argument error for unsupported CUDA pointer-option names instead of silently ignoring them.

CUDA kernel improvements

  • Increase the small-N GEMV split-K limit and vectorized occupancy target.
  • Add regression coverage for workspace sizing, FP16/BF16 outputs, and repeated CUDA graph replay.
  • Add temporal tiling for eligible single-request VarlenCausalConvWithState prefill workloads.
  • Preserve initial/final-state aliasing through a separate final-state update kernel.
  • Retain the existing general fallback for unsupported shapes.
  • Keep the existing operator schema and state-update interface unchanged.

Validation

Built the runtime, CUDA provider, and native test runners with CUDA 13.3 for H200. The focused build disabled unrelated optional FP4 QMoE, FpA-IntB GEMM, and fused-attention kernel families.

Test coverage Result
BFC arena tests 15 passed
CUDA provider-option tests 2 passed
Variable-length causal-convolution tests 47 passed, 1 WebGPU-only test skipped
Small-N GEMV internal tests 7 passed

Total: 71 tests passed.

Convolution coverage includes dispatch boundaries, capture-count clamping, FP32/FP16/BF16, optional state updates, and aliased two-call continuation. GEMV coverage includes higher split counts and CUDA graph replay.

Port standalone allocator fixes from the original Qwen optimization branch without its operator or model dependencies. Expose the CUDA arena pointer option, copy its configuration into provider-owned storage, and avoid splitting exact-size free chunks when the dead-byte limit is zero. Add allocation and pointer-option regression coverage.
Raise the split limit and vectorized occupancy target for the existing generic GEMV implementation. Cover higher split counts, workspace sizing, FP16/BF16 outputs, and repeated CUDA graph replay.
Port the temporal prefill optimization onto main without changing the operator schema or adding the Qwen branch state-update-active input. Preserve state aliasing with a separate final-state launch and retain the general fallback. Test threshold boundaries, capture clamping, all floating-point types, optional outputs, and aliased two-call continuation.

@github-actions github-actions Bot 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.

You can commit the suggested changes from lintrunner.

#pragma unroll
for (int k = 0; k < 4; ++k) {
sum += weights[k] * to_float(ReadStateOrInput(
input, channel_state, 0, channels, c, pad, t - pad + k * dilation));

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.

Suggested change
input, channel_state, 0, channels, c, pad, t - pad + k * dilation));
input, channel_state, 0, channels, c, pad, t - pad + k * dilation));

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.

🔵 Needs a closer look

CUDA scheduling and alias-sensitive state updates warrant human review beyond the reported H200 validation.

0 open findings

What changed in this PR

Improves arena configuration handling and CUDA kernel parallelism without changing operator schemas.

Changes:

  • Fixes exact-size arena allocation and CUDA arena-configuration ownership.
  • Increases GEMV split-K parallelism and adds tiled causal-convolution prefill.
  • Adds regression coverage for configuration lifetime, graph replay, and state aliasing.
File Description
onnxruntime/​test/​shared_lib/​test_inference.cc Tests CUDA arena pointer options and configuration lifetime.
onnxruntime/​test/​providers/​cuda/​test_cases/​matmul_small_n_gemv_test.cc Tests higher split counts, workspace sizing, and graph replay.
onnxruntime/​test/​framework/​bfc_arena_test.cc Tests exact-size allocation with zero dead bytes.
onnxruntime/​test/​contrib_ops/​causal_conv_with_state_op_test.cc Tests tiled prefill boundaries and aliased continuation.
onnxruntime/​core/​session/​provider_bridge_ort.cc Supports arena pointer options and rejects unknown update keys.
onnxruntime/​core/​providers/​cuda/​math/​matmul_small_n_gemv.cu Raises split-K and occupancy targets.
onnxruntime/​core/​providers/​cuda/​cuda_provider_factory.cc Copies arena configuration into owned storage.
onnxruntime/​core/​providers/​cuda/​cuda_execution_provider_info.h Retains shared ownership of arena configuration.
onnxruntime/​core/​framework/​bfc_arena.cc Prevents splitting exact-size free chunks.
onnxruntime/​contrib_ops/​cuda/​bert/​varlen_causal_conv_with_state_impl.cu Adds tiled prefill with a separate final-state update.
include/​onnxruntime/​core/​session/​onnxruntime_c_api.h Documents arena pointer-option support and copy timing.

🧠 Review effort: Balanced


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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