Skip to content

Avoid warning about unused variables#1125

Merged
cliffburdick merged 2 commits intoNVIDIA:mainfrom
miscco:avoid_unused_variable_warning
Jan 29, 2026
Merged

Avoid warning about unused variables#1125
cliffburdick merged 2 commits intoNVIDIA:mainfrom
miscco:avoid_unused_variable_warning

Conversation

@miscco
Copy link
Contributor

@miscco miscco commented Jan 29, 2026

Commonly the NVTX annotations do not get a variable assigned

Picked up in CCCL CI

Commonly the NVTX annotations do not get a variable assigned
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 29, 2026

Greptile Overview

Greptile Summary

Added [[maybe_unused]] attribute to NVTX range variables in kernel fusion examples to suppress compiler warnings when NVTX is disabled.

Key Changes

  • unfused_range and fused_range variables now marked with [[maybe_unused]] attribute
  • Variables are still properly defined and used by MATX_NVTX_END_RANGE macro
  • When NVTX is disabled, these macros expand to no-ops, making the variables technically unused
  • The [[maybe_unused]] attribute correctly suppresses warnings in this configuration

Previous Review Thread Clarification

The previous comments claiming variables are "now undefined" are incorrect. The variables remain properly defined and assigned. The [[maybe_unused]] attribute only suppresses compiler warnings about unused variables in certain build configurations.

Confidence Score: 5/5

  • This PR is safe to merge with no risk
  • The changes are minimal and correct. The [[maybe_unused]] attribute is the appropriate solution for variables that are used in some configurations but not others. The previous review comments incorrectly stated the variables were undefined, but they remain properly defined and used when NVTX is enabled.
  • No files require special attention

Important Files Changed

Filename Overview
examples/kernel_fusion.cu Added [[maybe_unused]] to NVTX range variables to suppress warnings when NVTX is disabled
docs_input/notebooks/gtc_lab/samples/kernel_fusion.cu Added [[maybe_unused]] to NVTX range variables to suppress warnings when NVTX is disabled

Sequence Diagram

sequenceDiagram
    participant Code as kernel_fusion.cu
    participant NVTX as NVTX Macros
    participant Compiler as C++ Compiler
    
    Note over Code,Compiler: When NVTX is enabled
    Code->>NVTX: MATX_NVTX_START_RANGE("Unfused Kernels")
    NVTX->>NVTX: autoCreateNvtxEvent() returns int ID
    NVTX-->>Code: Returns range ID
    Code->>Code: Store in [[maybe_unused]] int unfused_range
    Code->>Code: Execute operations
    Code->>NVTX: MATX_NVTX_END_RANGE(unfused_range)
    NVTX->>NVTX: endEvent(id) uses the variable
    
    Note over Code,Compiler: When NVTX is disabled
    Code->>NVTX: MATX_NVTX_START_RANGE("Unfused Kernels")
    NVTX-->>Code: Macro expands to 0
    Code->>Code: Store in [[maybe_unused]] int unfused_range = 0
    Code->>Code: Execute operations
    Code->>NVTX: MATX_NVTX_END_RANGE(unfused_range)
    NVTX-->>Code: Macro expands to no-op
    Note over Code,Compiler: [[maybe_unused]] prevents warning
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, 5 comments

Edit Code Review Agent Settings | Greptile

Comment on lines 32 to 36
MATX_NVTX_START_RANGE("Unfused Kernels");
(result = cos(C)).run(exec);
(result = result / D).run(exec);
(result = result * B).run(exec);
MATX_NVTX_END_RANGE(unfused_range);
Copy link
Contributor

Choose a reason for hiding this comment

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

unfused_range is now undefined. MATX_NVTX_START_RANGE was changed to not assign to a variable, but line 36 still references unfused_range in MATX_NVTX_END_RANGE(unfused_range).

Suggested change
MATX_NVTX_START_RANGE("Unfused Kernels");
(result = cos(C)).run(exec);
(result = result / D).run(exec);
(result = result * B).run(exec);
MATX_NVTX_END_RANGE(unfused_range);
[[maybe_unused]] int unfused_range = MATX_NVTX_START_RANGE("Unfused Kernels");
(result = cos(C)).run(exec);
(result = result / D).run(exec);
(result = result * B).run(exec);
MATX_NVTX_END_RANGE(unfused_range);

Comment on lines 39 to 41
MATX_NVTX_START_RANGE("Fused Operation");
(A = B * cos(C)/D).run(exec);
MATX_NVTX_END_RANGE(fused_range);
Copy link
Contributor

Choose a reason for hiding this comment

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

fused_range is now undefined. MATX_NVTX_START_RANGE was changed to not assign to a variable, but line 41 still references fused_range in MATX_NVTX_END_RANGE(fused_range).

Suggested change
MATX_NVTX_START_RANGE("Fused Operation");
(A = B * cos(C)/D).run(exec);
MATX_NVTX_END_RANGE(fused_range);
[[maybe_unused]] int fused_range = MATX_NVTX_START_RANGE("Fused Operation");
(A = B * cos(C)/D).run(exec);
MATX_NVTX_END_RANGE(fused_range);

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 29, 2026

Additional Comments (1)

docs_input/notebooks/gtc_lab/samples/kernel_fusion.cu
Duplicate MATX_EXIT_HANDLER() call on line 53 (already called on line 52)

}

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@cliffburdick
Copy link
Collaborator

/build

@cliffburdick cliffburdick merged commit b221325 into NVIDIA:main Jan 29, 2026
1 check was pending
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