Skip to content

Reshape: guard the 9.22 reshape-mode attribute at runtime, not just at compile time - #466

Merged
Anerudhan merged 1 commit into
NVIDIA:developfrom
YangXu1990uiuc:yanxu/fe-reshape-runtime-guard-gh
Jul 31, 2026
Merged

Reshape: guard the 9.22 reshape-mode attribute at runtime, not just at compile time#466
Anerudhan merged 1 commit into
NVIDIA:developfrom
YangXu1990uiuc:yanxu/fe-reshape-runtime-guard-gh

Conversation

@YangXu1990uiuc

@YangXu1990uiuc YangXu1990uiuc commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

CUDNN_ATTR_OPERATION_RESHAPE_MODE is set under #if (CUDNN_VERSION >= 92200) alone
(node/reshape.h:109). The compile-time guard is necessary but not sufficient: a frontend built
against >= 9.22 headers and run against an older runtime sets an attribute that runtime does not
know, and the failure takes down every graph containing a Reshape node — in practice all of
sdpa_backward, on 9.18 / 9.19 / 9.20 / 9.21.

Fix: nest a runtime check inside the existing compile-time guard, the idiom already used at
node/reduction.h:96-97.

Two decisions that aren't obvious from the diff:

  • LOGICAL is rejected rather than silently skipped. Not setting the attribute reproduces an old
    runtime's behaviour exactly, because pre-9.22 reshape has one semantics and it is the view-only one
    (CUDNN_RESHAPE_VIEW_ONLY == 0, "no data movement") — also this frontend's default. But an
    explicit LOGICAL request cannot be honoured there, and downgrading it to view-only would change
    results, so it returns GRAPH_NOT_SUPPORTED.

  • The check is spelled out instead of using NV_CUDNN_FE_DYNAMIC_CHECK_CUDNN_BACKEND_VERSION.
    That macro expands to nothing unless NV_CUDNN_FRONTEND_USE_DYNAMIC_LOADING is defined
    (cudnn_frontend_shim.h:213-215), so it would be a no-op in an ordinary C++ build — the exact
    configuration this needs to protect. Same caveat applies to sites that do use the macro
    (e.g. node/transpose.h:99); not addressed here.

g++ -fsyntax-only -std=c++17 clean; clang-format clean (pre-commit passed).

Summary by CodeRabbit

  • Bug Fixes
    • Improved reshape operation compatibility across supported runtime versions.
    • View-only reshape operations now work correctly with older runtimes.
    • Logical reshape operations on runtimes that do not support them now report a clear “graph not supported” result instead of failing unexpectedly.

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 1765c333-2cfe-4a9b-a18f-1c6435b189f2

📥 Commits

Reviewing files that changed from the base of the PR and between 504e34e and 3ff9747.

📒 Files selected for processing (1)
  • include/cudnn_frontend/node/reshape.h
🚧 Files skipped from review as they are similar to previous changes (1)
  • include/cudnn_frontend/node/reshape.h

📝 Walkthrough

Walkthrough

Reshape operation creation gates mode attribute configuration on the cuDNN runtime version. Older runtimes support view-only reshapes without the attribute and reject logical reshapes. Runtimes 9.22 and newer retain explicit mode configuration.

Changes

Reshape runtime compatibility

Layer / File(s) Summary
Version-gated reshape mode handling
include/cudnn_frontend/node/reshape.h
Reshape creation checks the runtime version before setting CUDNN_ATTR_OPERATION_RESHAPE_MODE. Older runtimes omit the attribute for view-only reshapes and return GRAPH_NOT_SUPPORTED for logical reshapes.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: adding a runtime guard for the reshape-mode attribute.
Description check ✅ Passed The description clearly explains the problem, solution, compatibility behavior, rationale, and testing results.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

…t compile time

CUDNN_ATTR_OPERATION_RESHAPE_MODE is set under `#if (CUDNN_VERSION >= 92200)`
alone. The compile-time guard is necessary -- cudnnBackendReshapeMode_t and the
attribute only exist in >= 9.22 headers -- but not sufficient: a frontend built
against >= 9.22 headers and run against an older runtime sets an attribute that
runtime does not know, and the failure takes down every graph containing a
Reshape node. In practice that is all of sdpa_backward:

  RuntimeError: detail::set_attribute(reshape_operation.get_raw_desc(),
    CUDNN_ATTR_OPERATION_RESHAPE_MODE, CUDNN_TYPE_RESHAPE_MODE, 1,
    &cudnn_reshape_mode) failed

Observed on 9.18 / 9.19 / 9.20 / 9.21 runtimes with an FE built against 9.26
headers; forward is unaffected. Rebuilding the identical FE source against 9.18
headers turns 20/44 SDPA cases into 40/44, and that 9.18-header FE then runs
against the 9.26 runtime with identical numerics -- i.e. the attribute is the
only thing at issue.

Fix: nest a runtime check inside the existing compile-time guard, matching the
idiom already at reduction.h:96-97. plan_helpers.h:80 and Heuristics.h:236 have
the same unconditional shape, but only at the 9.08 floor, where a runtime that
old paired with modern headers is already outside support; 9.22 vs 9.18-9.21 is
inside the range consumers run (PyTorch's varlen floor is 91800).

Skipping the attribute on an older runtime reproduces that runtime's behaviour
exactly: pre-9.22 reshape has a single semantics and it is the view-only one
(CUDNN_RESHAPE_VIEW_ONLY == 0, "no data movement"), which is also this
frontend's default. An explicit LOGICAL request cannot be honoured there and
silently downgrading it would change results, so that returns
GRAPH_NOT_SUPPORTED.

NV_CUDNN_FE_DYNAMIC_CHECK_CUDNN_BACKEND_VERSION is deliberately not reused: it
expands to nothing unless NV_CUDNN_FRONTEND_USE_DYNAMIC_LOADING is defined
(cudnn_frontend_shim.h:213-215), so it would be a no-op in an ordinary C++
build -- exactly the configuration this protects. The same caveat applies to
sites that do use the macro, e.g. transpose.h:99; not addressed here.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@YangXu1990uiuc
YangXu1990uiuc force-pushed the yanxu/fe-reshape-runtime-guard-gh branch from 504e34e to 3ff9747 Compare July 31, 2026 20:38
@Anerudhan
Anerudhan self-requested a review July 31, 2026 23:20
@Anerudhan Anerudhan added cat-bug Reports of incorrect behavior, crashes, regressions, or unexpected results. mod-frontend cuDNN frontend APIs, operation graph construction, plans, and user-facing wrappers. orig-nv-eng Reported or requested by NVIDIA engineering. labels Jul 31, 2026
@Anerudhan Anerudhan added this to the Frontend 1.27.0 milestone Jul 31, 2026
@Anerudhan
Anerudhan merged commit 0e0faaf into NVIDIA:develop Jul 31, 2026
1 check passed
@Anerudhan Anerudhan mentioned this pull request Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cat-bug Reports of incorrect behavior, crashes, regressions, or unexpected results. mod-frontend cuDNN frontend APIs, operation graph construction, plans, and user-facing wrappers. orig-nv-eng Reported or requested by NVIDIA engineering.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants