Skip to content

No rtti headers - #477

Merged
Anerudhan merged 2 commits into
NVIDIA:developfrom
bmanthos:no-rtti-headers
Aug 5, 2026
Merged

No rtti headers#477
Anerudhan merged 2 commits into
NVIDIA:developfrom
bmanthos:no-rtti-headers

Conversation

@bmanthos

@bmanthos bmanthos commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Before submitting

  • I agree to license this contribution under the terms of LICENSE.txt.
  • I ran pre-commit run and committed any formatting changes.

Affected area

  • C++ frontend API or graph construction

Summary

Replace dynamic_cast usage in the public headers.

Why

Support for consuming applications that use no-rtti.

Related issues

API and compatibility impact

Testing

Summary by CodeRabbit

  • New Features

    • Added a build option to enable or disable runtime type information (RTTI), with RTTI disabled by default.
    • Python bindings continue to support required type registration regardless of the global RTTI setting.
  • Compatibility

    • Improved support for builds without RTTI while preserving existing compiler warning behavior.
    • Graph processing and attention-pattern detection remain functional in RTTI-disabled builds.

Graph::register_oss_engine_() and Graph::register_oss_rms_norm_silu_engine_()
use dynamic_cast to locate nodes in sub_nodes. Both are inline members of
Graph, so every translation unit that includes cudnn_frontend.h compiles
them, and GCC/Clang reject the header outright when RTTI is disabled:

  graph_interface.h:425:35: error: 'dynamic_cast' not permitted with '-fno-rtti'

This makes the headers unusable for any consumer building with -fno-rtti or
/GR-, a common configuration for libraries that ship binaries. It has been
the case since these engines were introduced in v1.19.0.

MSVC does not error, so the problem is invisible on Windows: it emits C4541
("unpredictable behavior may result") and compiles. RTTI-disabled Windows
builds therefore reach these casts with no guarantee they behave correctly.

Replace both cast sites with RTTI-free equivalents:

- SDPA lookup: add a virtual INode::get_sdpa_attributes() returning nullptr
  by default, overridden once in SDPANodeBase. CompositeSDPANode and
  UnifiedSDPANode both inherit `attributes` from that base, so a single
  override covers both and the two cast branches collapse into one.

- RMSNorm+SiLU pattern match: gate on getType() and static_cast. RMSNORM and
  POINTWISE are distinct Type values, so this is an exact substitute for the
  check the dynamic_casts performed.

Both replacements are cheaper than the casts they replace: a virtual
dispatch and an enum comparison rather than an RTTI walk.

The static_cast downcasts are sound. NodeCRTP derives from INode via public
non-virtual single inheritance, and NodeCRTP already relies on the same
property internally via static_cast<DerivedT*>(this).

No functional change for RTTI-enabled builds.
Adds CUDNN_FRONTEND_ENABLE_RTTI (default OFF), which passes -fno-rtti
(GCC/Clang) or /GR- (MSVC) to samples and tests, so a dynamic_cast added
to the headers fails the build instead of only breaking downstream
consumers that disable RTTI.

The python bindings opt back in: pybind11's type registry is typeid-based
and requires RTTI.
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The build adds configurable RTTI support. General builds can disable RTTI, while the Python module enables it for pybind11. Graph inspection uses virtual SDPA attributes and explicit node type checks instead of RTTI casts.

Changes

RTTI graph support

Layer / File(s) Summary
RTTI compiler configuration
CMakeLists.txt, python/CMakeLists.txt
The main build adds CUDNN_FRONTEND_ENABLE_RTTI, which can disable RTTI. The Python _compiled_module target explicitly enables RTTI.
RTTI-free node discovery
include/cudnn_frontend/node_interface.h, include/cudnn_frontend/node/scaled_dot_product_flash_attention.h, include/cudnn_frontend/graph_interface.h
INode adds a virtual SDPA attribute accessor. SDPANodeBase implements it. Graph registration and RMSNorm+SiLU detection use the accessor and checked type tags instead of RTTI casts.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: yeliu-oss

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main no-RTTI header changes and is concise.
Description check ✅ Passed The description covers the required sections and explains the no-RTTI goal, but testing and API compatibility details are incomplete.
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.

@Anerudhan
Anerudhan self-requested a review August 4, 2026 19:16
@Anerudhan Anerudhan added mod-frontend cuDNN frontend APIs, operation graph construction, plans, and user-facing wrappers. orig-nv-eng Reported or requested by NVIDIA engineering. cat-enhancements labels Aug 4, 2026
@Anerudhan Anerudhan added this to the Frontend 1.27.0 milestone Aug 4, 2026

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@CMakeLists.txt`:
- Around line 13-15: Remove the inherited /GR- from the Python _compiled_module
configuration: update CMakeLists.txt lines 13-15 and python/CMakeLists.txt lines
75-81 so /GR- is scoped to non-Python targets or removed before _compiled_module
is created, while preserving RTTI-disabled behavior for other MSVC targets.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: cf66e3ae-e879-413f-89b0-49386e01b2cf

📥 Commits

Reviewing files that changed from the base of the PR and between b5a068d and 597a3d8.

📒 Files selected for processing (5)
  • CMakeLists.txt
  • include/cudnn_frontend/graph_interface.h
  • include/cudnn_frontend/node/scaled_dot_product_flash_attention.h
  • include/cudnn_frontend/node_interface.h
  • python/CMakeLists.txt

Comment thread CMakeLists.txt
Comment on lines +13 to +15
if(NOT CUDNN_FRONTEND_ENABLE_RTTI)
add_compile_options(/GR-)
endif()

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.

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- CMakeLists.txt ---'
sed -n '1,90p' CMakeLists.txt

printf '%s\n' '--- python/CMakeLists.txt ---'
sed -n '1,125p' python/CMakeLists.txt

printf '%s\n' '--- RTTI and warning-as-error settings ---'
rg -n --glob 'CMakeLists.txt' --glob '*.cmake' --glob '*.cmake.in' \
  'CUDNN_FRONTEND_ENABLE_RTTI|/GR-|/GR\b|-fno-rtti|-frtti|/WX|COMPILE_WARNING_AS_ERROR|target_compile_options|add_compile_options' .

printf '%s\n' '--- relevant targets and directory structure ---'
rg -n --glob 'CMakeLists.txt' 'add_(executable|library)|pybind|_compiled_module|add_subdirectory\(python|enable_testing|CUDNN_FRONTEND_BUILD' .

Repository: NVIDIA/cudnn-frontend

Length of output: 11437


🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- CMakeLists.txt ---'
sed -n '1,90p' CMakeLists.txt

printf '%s\n' '--- python/CMakeLists.txt ---'
sed -n '1,125p' python/CMakeLists.txt

printf '%s\n' '--- RTTI and warning-as-error settings ---'
rg -n --glob 'CMakeLists.txt' --glob '*.cmake' --glob '*.cmake.in' \
  'CUDNN_FRONTEND_ENABLE_RTTI|/GR-|(\/GR)([^-]|$)|-fno-rtti|-frtti|/WX|COMPILE_WARNING_AS_ERROR|target_compile_options|add_compile_options' .

printf '%s\n' '--- relevant targets and directory structure ---'
rg -n --glob 'CMakeLists.txt' \
  'add_(executable|library)|pybind|_compiled_module|add_subdirectory\(python|enable_testing|CUDNN_FRONTEND_BUILD' .

Repository: NVIDIA/cudnn-frontend

Length of output: 11437


🌐 Web query:

site:cmake.org/cmake/help/latest add_compile_options target_compile_options directory COMPILE_OPTIONS initialized target

💡 Result:

In CMake, compile options can be managed at different scopes, ranging from directory-wide to target-specific, using the following mechanisms: add_compile_options The add_compile_options command operates at the directory scope [1][2]. It adds options to the COMPILE_OPTIONS directory property [1]. These options are automatically applied to all targets created within that directory and any subdirectories processed afterward [1]. target_compile_options The target_compile_options command operates at the target scope [3][2]. It adds options to the COMPILE_OPTIONS and/or INTERFACE_COMPILE_OPTIONS target properties of a specific target [3][4]. This command requires a scope keyword (PRIVATE, PUBLIC, or INTERFACE) to determine whether the options should only apply to the target itself (PRIVATE), be propagated to consumers (INTERFACE), or both (PUBLIC) [3][4]. Initialization and Property Relationships The COMPILE_OPTIONS target property is initialized using the current value of the COMPILE_OPTIONS directory property at the time the target is created [5][6]. Once a target is created, the directory-level options and the target-level options are distinct; subsequent changes to the directory property will not affect existing targets [5]. When building a target, the final set of compile options consists of the target's own COMPILE_OPTIONS property (which includes its initial directory-based options plus any added via target_compile_options(PRIVATE/PUBLIC)) and the INTERFACE_COMPILE_OPTIONS properties propagated from its dependencies [5][7][4].

Citations:


🌐 Web query:

site:learn.microsoft.com MSVC D9025 overriding /GR- /GR /WX warning

💡 Result:

The MSVC compiler warning D9025 (overriding 'option1' with 'option2') occurs when conflicting command-line options are provided [1][2]. In the case of /GR and /GR-, these options are mutually exclusive: /GR enables Run-Time Type Information (RTTI), while /GR- disables it [3][4]. The compiler resolves this conflict by using the option that appears farthest to the right on the command line [1]. If both are specified, the one encountered last overrides the previous one [1]. Common causes for this warning include: 1. Conflicting Project Settings: The options may be defined in different places, such as the project's global C/C++ property pages and a specific source file's individual properties [1]. 2. Command Line Arguments: Build systems or manual command lines might inadvertently include both flags [1]. 3. Preprocessor or Build Tools: Generated build files (e.g., from CMake) may include conflicting configurations [5]. To resolve this: - Examine the compiler's Command Line property pages to see the full list of options applied [1]. - Check for redundant or contradictory settings in the C/C++ Language property page of your project [1][3]. - If you are using a build system like CMake, verify the configuration to ensure the desired RTTI setting is applied consistently across the project [5]. - If you need to override a project-wide setting, check the Additional Options field in the Command Line property page; adding the desired flag there will place it later on the command line, effectively overriding previous settings [1][6]. Note that /WX (Treat Warnings as Errors) is a separate flag that causes the compiler to treat all warnings as errors, which may cause your build to fail if a D9025 warning is generated [2]. You must resolve the underlying option conflict to prevent the D9025 warning, which in turn will resolve the /WX failure [1][2].

Citations:


🏁 Script executed:

#!/bin/bash
set -eu

python3 - <<'PY'
from pathlib import Path
import re

root = Path(".")
top = (root / "CMakeLists.txt").read_text()
py = (root / "python" / "CMakeLists.txt").read_text()

checks = {
    "MSVC global no-RTTI option": bool(re.search(
        r'if\(NOT CUDNN_FRONTEND_ENABLE_RTTI\).*?add_compile_options\(/GR-\)',
        top, re.S)),
    "Python target is created in the Python subdirectory": "python_add_library(" in py
        and "_compiled_module" in py,
    "Python MSVC RTTI option": bool(re.search(
        r'if\(MSVC\).*?target_compile_options\(_compiled_module PRIVATE /GR\)',
        py, re.S)),
    "global options are applied before Python subdirectory": top.index(
        "add_compile_options(/GR-)") < top.index("add_subdirectory(python)"),
}

for name, value in checks.items():
    print(f"{name}: {'yes' if value else 'no'}")

assert all(checks.values())

# CMake's directory-property initialization means the target receives /GR-
# before target_compile_options(PRIVATE /GR) adds /GR.
expected_msvc_options = ["/GR-", "/GR"]
print("Expected MSVC RTTI option sequence for _compiled_module: "
      + " ".join(expected_msvc_options))
print("D9025 condition: yes (mutually exclusive RTTI options)")
print("CUDNN_FRONTEND_ENABLE_RTTI=ON conflict: no (/GR- is not added)")
PY

Repository: NVIDIA/cudnn-frontend

Length of output: 520


Remove the inherited /GR- from _compiled_module.

When CUDNN_FRONTEND_ENABLE_RTTI=OFF on MSVC, the target receives both /GR- and /GR. MSVC emits D9025, and /WX can fail the build. Scope /GR- to non-Python targets or remove it from the Python directory before creating _compiled_module.

📍 Affects 2 files
  • CMakeLists.txt#L13-L15 (this comment)
  • python/CMakeLists.txt#L75-L81
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@CMakeLists.txt` around lines 13 - 15, Remove the inherited /GR- from the
Python _compiled_module configuration: update CMakeLists.txt lines 13-15 and
python/CMakeLists.txt lines 75-81 so /GR- is scoped to non-Python targets or
removed before _compiled_module is created, while preserving RTTI-disabled
behavior for other MSVC targets.

Source: MCP tools

@Anerudhan

Copy link
Copy Markdown
Collaborator

@cudnn-ci-bot run

@cudnn-ci-bot

Copy link
Copy Markdown

🚀 Running mirror pipeline

Branch: cudnn-gh/pr-477-597a3d8
Pipeline: 61254012

@Anerudhan
Anerudhan merged commit 4863e65 into NVIDIA:develop Aug 5, 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-enhancements 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.

3 participants