Skip to content

Skip redundant stream initialization guard check - #195190

Closed
lakshayg wants to merge 1 commit into
pytorch:mainfrom
lakshayg:skip-static-lookup
Closed

lakshayg wants to merge 1 commit into
pytorch:mainfrom
lakshayg:skip-static-lookup

Conversation

@lakshayg

Copy link
Copy Markdown
Collaborator

I saw from build/bolt_profiles/libc10_cuda.yaml that initCUDAStreamsOnce is a hot function. This function does a one-time process-wide initialization and a per-thread initialization. With the help of GPT 5.6 I was able to identify that the function enters the initialization paths very rarely but pays the cost of the static flag lookup in each invocation.

I have reordered this function to avoid the static flag lookup in the common case.

GPT 5.6 analyzed the binaries before and after the change and noted 3 fewer instructions (global flag lookup) and 1 fewer branch in the generated assembly. This was also confirmed using perf on a micro- benchmark that calls this function in a tight loop.

Assisted-by: gpt-5.6-sol medium

I saw from `build/bolt_profiles/libc10_cuda.yaml` that
`initCUDAStreamsOnce` is a hot function. This function does a one-time
process-wide initialization and a per-thread initialization. With the
help of GPT 5.6 I was able to identify that the function enters the
initialization paths very rarely but pays the cost of the static flag
lookup in each invocation.

I have reordered this function to avoid the static flag lookup in the
common case.

GPT 5.6 analyzed the binaries before and after the change and noted
3 fewer instructions (global flag lookup) and 1 fewer branch in the
generated assembly. This was also confirmed using perf on a micro-
benchmark that calls this function in a tight loop.

Assisted-by: gpt-5.6-sol medium
@pytorch-bot

pytorch-bot Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/195190

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 9a1cf5b with merge base 4380f31 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@lakshayg
lakshayg requested a review from Skylion007 August 28, 2026 18:42
@lakshayg lakshayg self-assigned this Aug 28, 2026
@lakshayg lakshayg added ciflow/trunk Trigger trunk jobs on your pull request topic: not user facing topic category labels Aug 28, 2026
@lakshayg

Copy link
Copy Markdown
Collaborator Author

@pytorchmergebot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@lakshayg
lakshayg deleted the skip-static-lookup branch August 29, 2026 16:51
orrangetabby17 pushed a commit to orrangetabby17/pytorch that referenced this pull request Sep 2, 2026
I saw from `build/bolt_profiles/libc10_cuda.yaml` that `initCUDAStreamsOnce` is a hot function. This function does a one-time process-wide initialization and a per-thread initialization. With the help of GPT 5.6 I was able to identify that the function enters the initialization paths very rarely but pays the cost of the static flag lookup in each invocation.

I have reordered this function to avoid the static flag lookup in the common case.

GPT 5.6 analyzed the binaries before and after the change and noted 3 fewer instructions (global flag lookup) and 1 fewer branch in the generated assembly. This was also confirmed using perf on a micro- benchmark that calls this function in a tight loop.

Assisted-by: gpt-5.6-sol medium
Pull Request resolved: pytorch#195190
Approved by: https://github.com/eqy
Sanskaaar1 pushed a commit to Sanskaaar1/pytorch that referenced this pull request Sep 8, 2026
I saw from `build/bolt_profiles/libc10_cuda.yaml` that `initCUDAStreamsOnce` is a hot function. This function does a one-time process-wide initialization and a per-thread initialization. With the help of GPT 5.6 I was able to identify that the function enters the initialization paths very rarely but pays the cost of the static flag lookup in each invocation.

I have reordered this function to avoid the static flag lookup in the common case.

GPT 5.6 analyzed the binaries before and after the change and noted 3 fewer instructions (global flag lookup) and 1 fewer branch in the generated assembly. This was also confirmed using perf on a micro- benchmark that calls this function in a tight loop.

Assisted-by: gpt-5.6-sol medium
Pull Request resolved: pytorch#195190
Approved by: https://github.com/eqy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged open source topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants