Daya Shankar
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    <h1> How to Use Nsight Compute for Deep Learning Workload Analysis </h1> ![deep-learning](https://hackmd.io/_uploads/B1TAEDafZl.jpg) <p>Nsight Compute is NVIDIA&rsquo;s kernel profiler. If Nsight Systems tells you <em>where</em> time goes across CPU, GPU, and the runtime, Nsight Compute tells you <em>why a specific GPU kernel is slow</em> by showing occupancy, memory behavior, instruction mix, Tensor Core usage, and more. For deep learning, this is where you confirm whether your key kernels are compute bound, memory bound, or limited by something more subtle like poor launch configuration or low Tensor Core utilization.</p> <p>This blog walks through a practical workflow for using Nsight Compute to analyze deep learning workloads, with examples you can adapt for PyTorch, TensorFlow, and custom CUDA kernels.</p> <h2><strong>When to use Nsight Compute for deep learning</strong></h2> <p>Use Nsight Compute when you already know which kernels matter and you want deeper answers such as:</p> <ul> <li>Is my GEMM or convolution limited by memory bandwidth or math throughput?<br /><br /></li> <li>Are Tensor Cores being used effectively?<br /><br /></li> <li>Is occupancy low because of register pressure or shared memory usage?<br /><br /></li> <li>Are memory loads uncoalesced or thrashing cache?<br /><br /></li> <li>Why is this fused kernel slower than expected?<br /><br /></li> </ul> <p>If you do not yet know which kernels to inspect, start with Nsight Systems or PyTorch Profiler to identify hotspots, then zoom in with Nsight Compute.</p> <h2><strong>Key concept: you are profiling kernels, not &ldquo;the model&rdquo;</strong></h2> <p>Deep learning frameworks launch many GPU kernels per iteration. Nsight Compute profiles individual kernel launches. Your job is to identify the few kernels that dominate runtime, then analyze them deeply.</p> <p>In many models, the heavy hitters are:</p> <ul> <li>GEMMs from matmul and linear layers (often cuBLAS)<br /><br /></li> <li>Convolutions (often cuDNN)<br /><br /></li> <li>Attention primitives, including softmax, layernorm, and fused kernels<br /><br /></li> <li>Reductions and elementwise ops if fusion is poor<br /><br /></li> <li>Data movement kernels if the pipeline is inefficient<br /><br /></li> </ul> <h2><strong>Getting set up</strong></h2> <h3><strong>Install and verify access</strong></h3> <p>Nsight Compute comes with the <a href="https://acecloud.ai/blog/nvidia-cuda-cores-explained/">NVIDIA CUDA</a> toolkit or as a separate package depending on your platform. Confirm you can run the CLI:</p> <p>ncu --version</p> <p>For server environments, the CLI is usually enough. The GUI is great for interactive exploration and roofline charts, but it is optional.</p> <h3><strong>Profile in a stable environment</strong></h3> <p>Profiling changes timing and can perturb scheduling. For best results:</p> <ul> <li>Use a <a href="https://acecloud.ai/cloud/gpu/">dedicated GPU</a> if possible<br /><br /></li> <li>Fix input shapes and batch size<br /><br /></li> <li>Warm up the model before profiling<br /><br /></li> <li>Avoid profiling the first iteration if kernels are still caching or autotuning<br /><br /></li> </ul> <h2><strong>Step 1: Narrow to a small capture window</strong></h2> <p>Do not profile an entire training job. Instead, capture a short window around steady state.</p> <p>For PyTorch, a simple approach is to run a few warmup iterations, then a small number of profiled iterations.</p> <p>If you cannot easily &ldquo;pause&rdquo; the run, Nsight Compute supports capturing only specific kernels or only the first N launches, which is often good enough.</p> <h2><strong>Step 2: Collect a lightweight kernel list first</strong></h2> <p>Start with a minimal metric set to see which kernels dominate and to confirm you are targeting the right work. A typical pattern:</p> <p>ncu --target-processes all \</p> <p>--set default \</p> <p>--profile-from-start off \</p> <p>--launch-skip 100 \</p> <p>--launch-count 50 \</p> <p>-o ncu_report \</p> <p>python train_or_infer.py</p> <p>Notes:</p> <ul> <li>--launch-skip and --launch-count help you skip warmup launches and capture a stable window.<br /><br /></li> <li>--set default keeps overhead manageable.<br /><br /></li> <li>--target-processes all helps with multi process launchers, but use it carefully since it can generate a lot of data.<br /><br /></li> </ul> <p>Then open the report in the GUI or inspect from the CLI:</p> <p>ncu --import ncu_report.ncu-rep --page summary</p> <p>Look for the kernels with the highest total time. Often you will see cuBLAS GEMM kernels and cuDNN convolution kernels near the top.</p> <h2><strong>Step 3: Filter to the one kernel you care about</strong></h2> <p>Once you identify the kernel name, profile only that kernel with richer metrics. Filtering dramatically reduces overhead and noise.</p> <p>Example:</p> <p>ncu --target-processes all \</p> <p>--kernel-name "regex:.*gemm.*" \</p> <p>--launch-count 10 \</p> <p>--set full \</p> <p>-o gemm_deep \</p> <p>python train_or_infer.py</p> <p>If you are profiling attention, you might filter by patterns like fmha, flash, softmax, layernorm, or framework specific fused kernel names.</p> <h2><strong>Step 4: Use the &ldquo;Speed of Light&rdquo; view and roofline thinking</strong></h2> <p>Nsight Compute often organizes key findings in a &ldquo;Speed of Light&rdquo; style summary. The core question is: is the kernel limited by compute or by memory?</p> <p>A simple roofline mindset helps:</p> <ul> <li>If achieved FLOPs is far below peak, you might be memory bound or instruction limited.<br /><br /></li> <li>If memory bandwidth is near peak but math is low, you are likely memory bound.<br /><br /></li> <li>If both are low, you may have low occupancy, launch overhead, synchronization, or poor vectorization.<br /><br /></li> </ul> <p>For deep learning kernels, common scenarios include:</p> <ul> <li>GEMM is compute bound but not using Tensor Cores efficiently<br /><br /></li> <li>Softmax is memory bound with lots of reads and writes<br /><br /></li> <li>Layernorm is memory bound, and fusion matters more than micro tuning<br /><br /></li> <li>Small batch inference leads to underutilized compute due to small problem size<br /><br /></li> </ul> <h2><strong>Step 5: Check Tensor Core utilization</strong></h2> <p>If you expect Tensor Cores to be active, verify it. Things that often prevent Tensor Core use:</p> <ul> <li>Wrong dtype, such as FP32 path when you intended FP16 or BF16<br /><br /></li> <li>Shapes not aligned to preferred tile sizes<br /><br /></li> <li>Operations not hitting Tensor Core capable kernels<br /><br /></li> <li>Conversions or layout issues causing fallbacks<br /><br /></li> </ul> <p>Nsight Compute can reveal whether the kernel uses HMMA or Tensor Core instructions. If you see a GEMM that is not using Tensor Cores when it should, fix dtype, layout, and alignment first before any deeper tuning.</p> <h2><strong>Step 6: Diagnose occupancy and launch limits</strong></h2> <p>Low occupancy can be fine if the kernel is already saturating memory bandwidth or compute, but it can also be a red flag.</p> <p>Typical reasons occupancy is limited:</p> <ul> <li>High register usage per thread<br /><br /></li> <li>Large shared memory per block<br /><br /></li> <li>Block size that does not map well to SM resources<br /><br /></li> <li>Too few blocks overall because the problem size is small<br /><br /></li> </ul> <p>Nsight Compute shows achieved occupancy and the limiting factor. For deep learning inference at small batch sizes, the &ldquo;problem too small&rdquo; scenario is extremely common, and the fix is usually batching, fusion, or choosing kernels optimized for small shapes rather than chasing occupancy alone.</p> <h2><strong>Step 7: Investigate memory behavior</strong></h2> <p>If the kernel looks memory bound, focus on:</p> <ul> <li>Global memory load and store efficiency<br /><br /></li> <li>L2 cache hit rate<br /><br /></li> <li>Memory coalescing and transaction sizes<br /><br /></li> <li>Excessive reads and writes due to unfused ops<br /><br /></li> <li>Use of shared memory and whether it reduces global traffic<br /><br /></li> </ul> <p>In many deep learning graphs, the largest memory improvements come from fusion and avoiding intermediate tensors, not from micro optimizing a single kernel. Nsight Compute helps you prove this by showing how much bandwidth each kernel is consuming and whether the data movement is the true limiter.</p> <h2><strong>Step 8: Use NVTX to map kernels to model phases</strong></h2> <p>Deep learning runs can have hundreds of similar kernels. NVTX ranges make it easier to connect kernels to steps like forward, backward, optimizer, or specific layers.</p> <p>Many frameworks and libraries already emit NVTX ranges when enabled. If not, you can add NVTX ranges in your code and then use those ranges to guide what you capture and when.</p> <h2><strong>Practical tips and common pitfalls</strong></h2> <ul> <li>Profile fewer kernels with deeper metrics, not many kernels with everything.<br /><br /></li> <li>Re run profiling. Single runs can be noisy, especially with dynamic shapes or autotuning.<br /><br /></li> <li>Watch for profiler overhead. The &ldquo;full&rdquo; set can slow kernels significantly.<br /><br /></li> <li>Lock clocks only if you know what you are doing. Changing GPU clocks can improve repeatability but can also misrepresent production behavior.<br /><br /></li> <li>For multi GPU training, start with one GPU. Then profile a single rank and isolate communication kernels separately with Nsight Systems.<br /><br /></li> <li>In containers, ensure you have the right permissions and the host driver supports profiling. Some environments restrict access to performance counters.<br /><br /></li> </ul> <h2><strong>A simple end to end workflow</strong></h2> <ol> <li>Identify hotspot ops with PyTorch Profiler or Nsight Systems.<br /><br /></li> <li>Capture a short steady state window with Nsight Compute default set.<br /><br /></li> <li>Filter to the top kernel and switch to a richer set like full.<br /><br /></li> <li>Classify the kernel as compute bound or memory bound.<br /><br /></li> <li>Verify Tensor Core usage where expected.<br /><br /></li> <li>Use occupancy and memory metrics to decide the best fix, often dtype, layout, fusion, batching, or kernel choice.<br /><br /></li> <li>Re benchmark with the same inputs and compare throughput and latency.<br /><br /></li> </ol> <p>If you tell me whether you are profiling training or inference, your GPU model, and whether you are using FP16, BF16, or FP32, I can suggest a focused Nsight Compute command line and the highest value metric sections to collect for your specific workload.</p>

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully