Skip to content

Remove the shared state and the mutex from NVTX internals - #2310

Merged
rapids-bot[bot] merged 2 commits into
NVIDIA:branch-24.06from
achirkin:enh-nvtx-without-mutex
May 15, 2024
Merged

Remove the shared state and the mutex from NVTX internals#2310
rapids-bot[bot] merged 2 commits into
NVIDIA:branch-24.06from
achirkin:enh-nvtx-without-mutex

Conversation

@achirkin

Copy link
Copy Markdown
Contributor

Until now, raft has stored a map of NVTX colors (annotation -> color) to avoid using the same color for different annotations and keep using the same color for the same annotations. This map is a shared state.
During an extensive ANN_BENCH throughput testing it has turned out that the mutex guarding the map can sometimes become a bottleneck when the number of concurrent threads is really large (>~ 256). This PR replaces the unordered map and the mutex guarding it with a deterministic hash value of the annotation instead (which is stateless).

Pros:

  • No shared state, no mutexes.
  • Assigns the same colors to the same annotations across program runs.

Cons:

  • Sometimes different annotations can have the same color (hash collisions).

@achirkin achirkin added 3 - Ready for Review improvement Improvement / enhancement to an existing function non-breaking Non-breaking change labels May 14, 2024
@achirkin
achirkin requested a review from a team as a code owner May 14, 2024 09:41
@github-actions github-actions Bot added the cpp label May 14, 2024

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

Thanks Artem for the PR, looks good, just a small update in docstring is missing!

Comment thread cpp/include/raft/core/detail/nvtx.hpp
@achirkin
achirkin requested a review from tfeher May 14, 2024 15:32

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

Thanks for the update, LGTM!

@achirkin

Copy link
Copy Markdown
Contributor Author

/merge

@rapids-bot
rapids-bot Bot merged commit f3806f1 into NVIDIA:branch-24.06 May 15, 2024
loulankxh pushed a commit to loulankxh/raft that referenced this pull request Oct 14, 2025
Until now, raft has stored a map of NVTX colors (annotation -> color) to avoid using the same color for different annotations and keep using the same color for the same annotations. This map is a shared state.
During an extensive ANN_BENCH throughput testing it has turned out that the mutex guarding the map can sometimes become a bottleneck when the number of concurrent threads is really large (>~ 256). This PR replaces the unordered map and the mutex guarding it with a deterministic hash value of the annotation instead (which is stateless).

**Pros:**
  - No shared state, no mutexes.
  - Assigns the same colors to the same annotations across program runs.
 
**Cons:**
  - Sometimes different annotations can have the same color (hash collisions).

Authors:
  - Artem M. Chirkin (https://github.com/achirkin)

Approvers:
  - Tamas Bela Feher (https://github.com/tfeher)
  - Corey J. Nolet (https://github.com/cjnolet)

URL: NVIDIA#2310
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3 - Ready for Review cpp improvement Improvement / enhancement to an existing function non-breaking Non-breaking change

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants