Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ option(CUDNN_FRONTEND_SKIP_JSON_LIB "Defines whether FE should not include nlohm
option(CUDNN_FRONTEND_BUILD_SAMPLES "Defines if samples are built or not." ON)
option(CUDNN_FRONTEND_BUILD_TESTS "Defines if unittests are built or not." ON)
option(CUDNN_FRONTEND_BUILD_PYTHON_BINDINGS "Defines if python bindings are built or not." OFF)
option(CUDNN_FRONTEND_ENABLE_RTTI "Build in-tree targets with RTTI. Off by default so the headers stay compilable for consumers that disable it." OFF)

if(MSVC OR MSYS OR MINGW)
add_compile_options(/W4 /WX)
if(NOT CUDNN_FRONTEND_ENABLE_RTTI)
add_compile_options(/GR-)
endif()
Comment on lines +13 to +15

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

else()
add_compile_options(-Wall -Wextra -Wpedantic -Werror -Wno-error=attributes -Wno-attributes -Wno-error=unused-function -Wno-unused-function)
if(NOT CUDNN_FRONTEND_ENABLE_RTTI)
add_compile_options(-fno-rtti)
endif()
endif()

add_library(cudnn_frontend INTERFACE)
Expand Down
25 changes: 13 additions & 12 deletions include/cudnn_frontend/graph_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -419,15 +419,13 @@ class Graph : public ICudnn, public INode {
// Register an OSS NVRTC engine for SDPA by extracting tensor metadata from the SDPA node's attributes
error_t
register_oss_engine_() {
// Find the SDPA node in the graph's sub_nodes via dynamic_cast
// Find the SDPA node in the graph's sub_nodes. Uses the virtual get_sdpa_attributes()
// accessor rather than dynamic_cast so this header compiles under -fno-rtti / /GR-.
// Covers both CompositeSDPANode and UnifiedSDPANode, which share SDPANodeBase.
SDPA_attributes const *sdpa_attrs = nullptr;
for (auto const &sub_node : sub_nodes) {
if (auto *composite = dynamic_cast<CompositeSDPANode *>(sub_node.get())) {
sdpa_attrs = &composite->attributes;
break;
}
if (auto *unified = dynamic_cast<UnifiedSDPANode *>(sub_node.get())) {
sdpa_attrs = &unified->attributes;
if (auto const *attrs = sub_node->get_sdpa_attributes()) {
sdpa_attrs = attrs;
break;
}
}
Expand Down Expand Up @@ -539,11 +537,14 @@ class Graph : public ICudnn, public INode {
std::shared_ptr<Tensor_attributes> swish_output;

for (size_t i = 0; i + 1 < sub_nodes.size(); ++i) {
auto *rmsnorm_node = dynamic_cast<RMSNormNode *>(sub_nodes[i].get());
if (!rmsnorm_node) continue;

auto *pointwise_node = dynamic_cast<PointwiseNode *>(sub_nodes[i + 1].get());
if (!pointwise_node) continue;
// getType() + static_cast rather than dynamic_cast so this header compiles under
// -fno-rtti / /GR-. RMSNORM and POINTWISE are distinct Type values, so this is an
// exact substitute for the type-check the dynamic_casts performed.
if (sub_nodes[i]->getType() != Type::RMSNORM) continue;
auto *rmsnorm_node = static_cast<RMSNormNode *>(sub_nodes[i].get());

if (sub_nodes[i + 1]->getType() != Type::POINTWISE) continue;
auto *pointwise_node = static_cast<PointwiseNode *>(sub_nodes[i + 1].get());

if (pointwise_node->attributes.get_mode() != PointwiseMode_t::SWISH_FWD) continue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ class SDPANodeBase : public NodeCRTP<DerivedT> {
SDPANodeBase(SDPA_attributes&& attributes_, detail::Context const& context)
: NodeCRTP<DerivedT>(context), attributes(std::move(attributes_)) {}

SDPA_attributes const*
get_sdpa_attributes() const override {
return &attributes;
}

bool
is_paged_v() const {
auto page_table_v_it = attributes.inputs.find(input_names::Page_table_V);
Expand Down
8 changes: 8 additions & 0 deletions include/cudnn_frontend/node_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,14 @@ class INode {
virtual Type
getType() = 0;

// Returns this node's SDPA attributes if it is an SDPA node, nullptr otherwise.
// Provides an RTTI-free alternative to dynamic_cast for SDPA node discovery so that
// these headers compile under -fno-rtti (GCC/Clang) and /GR- (MSVC).
virtual SDPA_attributes const*
get_sdpa_attributes() const {
return nullptr;
}

virtual std::pair<int64_t, std::unordered_map<KnobType_t, int64_t>>
override_heuristics_query() const {
return {-1, {}};
Expand Down
8 changes: 8 additions & 0 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ target_link_libraries(_compiled_module PRIVATE pybind11::headers)

target_compile_features(_compiled_module PRIVATE cxx_std_20)

# pybind11's type registry is typeid-based, so this module requires RTTI even when
# CUDNN_FRONTEND_ENABLE_RTTI is off for the rest of the build.
if(MSVC)
target_compile_options(_compiled_module PRIVATE /GR)
else()
target_compile_options(_compiled_module PRIVATE -frtti)
endif()

target_include_directories(
_compiled_module
PRIVATE $<TARGET_PROPERTY:cudnn_frontend,INTERFACE_INCLUDE_DIRECTORIES>
Expand Down