Skip to content

[cuda.compute]: Fix windows race related to get nvrtc type name - #10049

Merged
NaderAlAwar merged 1 commit into
NVIDIA:mainfrom
NaderAlAwar:fix-windows-nvrtc-typename-race
Jul 21, 2026
Merged

[cuda.compute]: Fix windows race related to get nvrtc type name#10049
NaderAlAwar merged 1 commit into
NVIDIA:mainfrom
NaderAlAwar:fix-windows-nvrtc-typename-race

Conversation

@NaderAlAwar

Copy link
Copy Markdown
Contributor

This was discovered in CI in #9887

@NaderAlAwar
NaderAlAwar requested a review from a team as a code owner July 21, 2026 16:29
@NaderAlAwar
NaderAlAwar requested a review from rwgk July 21, 2026 16:29
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Jul 21, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Jul 21, 2026
@coderabbitai

coderabbitai Bot commented Jul 21, 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: bf1db24b-14f1-49ef-99de-88812148a2c9

📥 Commits

Reviewing files that changed from the base of the PR and between a05b3ac and 070e467.

📒 Files selected for processing (1)
  • c/parallel/src/util/types.h

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved Windows build stability when multiple operations request NVRTC type names concurrently.
    • Prevented returned type-name information from being corrupted or mixed during parallel processing.

Walkthrough

Changes

Windows builds now serialize cccl_type_name_from_nvrtc<T> calls with a process-wide inline mutex while non-Windows builds retain the existing path.

NVRTC synchronization

Layer / File(s) Summary
Guard Windows NVRTC queries
c/parallel/src/util/types.h
Conditionally includes <mutex> and protects nvrtcGetTypeName with a std::lock_guard on Windows.

Suggested reviewers: bernhardmgruber


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

// policy). Serialize every call through one process-wide mutex; the `inline`
// variable is a single instance shared across all `cccl_type_name_from_nvrtc<T>`
// instantiations and translation units.
inline std::mutex nvrtc_type_name_mutex;

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.

Any reason not to just make this a static inside the function? Putting it at bare global scope is also potentially dangerous because std::mutex can throw on construction and opens us up to the static initialization ordering fiasco

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

cccl_type_name_from_nvrtc is a template, so a static inside it would be instantiated once per T. This is a problem because e.g. device_reduce_policy and device_transform_policy would get separate mutexes and wouldn't serialize against each other. Since the race is cross-type (a transform build and a reduce build both calling nvrtcGetTypeName, which funnels into the process-global, single-threaded DbgHelp UnDecorateSymbolName), we need one shared instance.

std::mutex can throw on construction and opens us up to the static initialization ordering fiasco

std::mutex's default ctor is constexpr + noexcept, so a namespace-scope instance is constant-initialized rather than dynamically initialized, so it's not subject to the static-init-order fiasco and can't throw at construction (nothing references it during static init anyway).

Would you prefer something like

inline std::mutex& nvrtc_type_name_mutex()
{
  static std::mutex m;
  return m;
}

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.

I have no concerns here. A global mutex variable is fine I think.

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.

Ah yes missed the fact it was templated. And it is strange they made the constructor constexpr (I didn't know this), I don't believe any other member in mutex is constexpr so it is functionally useless for it to be constexpr...

@github-actions

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 1h 21m: Pass: 100%/20 | Total: 5h 43m | Max: 49m 12s | Hits: 82%/2043

See results here.

@NaderAlAwar
NaderAlAwar merged commit d7823c5 into NVIDIA:main Jul 21, 2026
43 of 45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants