Skip to content

[NVRTC] Enable compiling templated kernels#162875

Closed
gau-nernst wants to merge 5 commits intopytorch:mainfrom
gau-nernst:nvrtc_template
Closed

[NVRTC] Enable compiling templated kernels#162875
gau-nernst wants to merge 5 commits intopytorch:mainfrom
gau-nernst:nvrtc_template

Conversation

@gau-nernst
Copy link
Contributor

@gau-nernst gau-nernst commented Sep 13, 2025

Per NVRTC doc - https://docs.nvidia.com/cuda/nvrtc/index.html#accessing-lowered-names, we can compile a templated kernel (e.g. kernel<float>) with the following steps

NVRTC side

  • (new) nvrtcAddNameExpression -> C++ template e.g. f<float>
  • nvrtcCompileProgram
  • (new) nvrtcGetLoweredName -> get mangled name. need to do a copy since later this string is freed after NVRTC program is destroyed
  • nvrtcDestroyProgram

CUDA side

  • use mangled name instead of normal name -> profit
  • extern "C" is not even needed

cc @msaroufim

@pytorch-bot
Copy link

pytorch-bot bot commented Sep 13, 2025

🔗 Helpful Links

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

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

❌ 1 Cancelled Job

As of commit ebec2a9 with merge base aa41d3e (image):

CANCELLED JOB - The following job was cancelled. Please retry:

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

@gau-nernst
Copy link
Contributor Author

@pytorchbot label "topic: not user facing"

@msaroufim
Copy link
Member

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Sep 14, 2025
@pytorchmergebot
Copy link
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

@tohskai
Copy link

tohskai commented Sep 16, 2025

thanks a lot for this!

markc-614 pushed a commit to markc-614/pytorch that referenced this pull request Sep 17, 2025
Per NVRTC doc - https://docs.nvidia.com/cuda/nvrtc/index.html#accessing-lowered-names, we can compile a templated kernel (e.g. `kernel<float>`) with the following steps

NVRTC side
- (new) `nvrtcAddNameExpression` -> C++ template e.g. `f<float>`
- `nvrtcCompileProgram`
- (new) `nvrtcGetLoweredName` -> get mangled name. need to do a copy since later this string is freed after NVRTC program is destroyed
- `nvrtcDestroyProgram`

CUDA side
- use mangled name instead of normal name -> profit
- `extern "C"` is not even needed

Pull Request resolved: pytorch#162875
Approved by: https://github.com/msaroufim
mansiag05 pushed a commit to mansiag05/pytorch that referenced this pull request Sep 22, 2025
Per NVRTC doc - https://docs.nvidia.com/cuda/nvrtc/index.html#accessing-lowered-names, we can compile a templated kernel (e.g. `kernel<float>`) with the following steps

NVRTC side
- (new) `nvrtcAddNameExpression` -> C++ template e.g. `f<float>`
- `nvrtcCompileProgram`
- (new) `nvrtcGetLoweredName` -> get mangled name. need to do a copy since later this string is freed after NVRTC program is destroyed
- `nvrtcDestroyProgram`

CUDA side
- use mangled name instead of normal name -> profit
- `extern "C"` is not even needed

Pull Request resolved: pytorch#162875
Approved by: https://github.com/msaroufim
cleonard530 pushed a commit to cleonard530/pytorch that referenced this pull request Sep 22, 2025
Per NVRTC doc - https://docs.nvidia.com/cuda/nvrtc/index.html#accessing-lowered-names, we can compile a templated kernel (e.g. `kernel<float>`) with the following steps

NVRTC side
- (new) `nvrtcAddNameExpression` -> C++ template e.g. `f<float>`
- `nvrtcCompileProgram`
- (new) `nvrtcGetLoweredName` -> get mangled name. need to do a copy since later this string is freed after NVRTC program is destroyed
- `nvrtcDestroyProgram`

CUDA side
- use mangled name instead of normal name -> profit
- `extern "C"` is not even needed

Pull Request resolved: pytorch#162875
Approved by: https://github.com/msaroufim
dsashidh pushed a commit to dsashidh/pytorch that referenced this pull request Sep 26, 2025
Per NVRTC doc - https://docs.nvidia.com/cuda/nvrtc/index.html#accessing-lowered-names, we can compile a templated kernel (e.g. `kernel<float>`) with the following steps

NVRTC side
- (new) `nvrtcAddNameExpression` -> C++ template e.g. `f<float>`
- `nvrtcCompileProgram`
- (new) `nvrtcGetLoweredName` -> get mangled name. need to do a copy since later this string is freed after NVRTC program is destroyed
- `nvrtcDestroyProgram`

CUDA side
- use mangled name instead of normal name -> profit
- `extern "C"` is not even needed

Pull Request resolved: pytorch#162875
Approved by: https://github.com/msaroufim
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 release notes: cuda release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants