通过nvtx和Nsight Compute分析pytorch算子的耗时

通过nvtx和Nsight Compute分析pytorch算子的耗时

本文演示了如何借助nvtx和Nsight Compute分析pytorch算子的耗时

一.效果

  • 第一次执行,耗时很长
    在这里插入图片描述
  • 小规模的matmul,调度耗时远大于算子本身
    在这里插入图片描述
  • 大规模的matmul,对资源的利用率高在这里插入图片描述
  • 小规模matmul,各层调用的耗时
    在这里插入图片描述

二.代码

import torch
import nvtx

# 二种不同规模矩阵乘的耗时,通过小算子可以看到调度的耗时
A=torch.ones((3,4),dtype=torch.float32).to('cuda:0')
B=torch.ones((4,5),dtype=torch.float32).to('cuda:0')

C=torch.ones((1024,8196),dtype=torch.float32).to('cuda:0')
D=torch.ones((8196,1024),dtype=torch.float32).to('cuda:0')

#torch.cuda.cudart().cudaProfilerStart()
for i in range(10):
    #torch.cuda.nvtx.range_push(f"iteration{i}")
    with nvtx.annotate(f"iteration{i}", color="red"):
        with nvtx.annotate(f"sub0", color="green"):
            OUT0=torch.matmul(A,B)
            torch.cuda.synchronize()
        with nvtx.annotate(f"sub1", color="green"):
            OUT1=torch.matmul(C,D)
            torch.cuda.synchronize()
    #torch.cuda.nvtx.range_pop()
#torch.cuda.cudart().cudaProfilerStop()

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-03 18:06:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-03 18:06:01       101 阅读
  3. 在Django里面运行非项目文件

    2024-04-03 18:06:01       82 阅读
  4. Python语言-面向对象

    2024-04-03 18:06:01       91 阅读

热门阅读

  1. 在stable diffusion中如何分辨lora、大模型、controlnet

    2024-04-03 18:06:01       37 阅读
  2. 第1章 开始

    2024-04-03 18:06:01       45 阅读
  3. 浅谈无文件攻击

    2024-04-03 18:06:01       38 阅读
  4. P1352 没有上司的舞会 【深搜树型DP】

    2024-04-03 18:06:01       40 阅读
  5. Solidity Uniswap V2 Router swapExactTokensForTokens

    2024-04-03 18:06:01       38 阅读
  6. free函数的用法和注意事项

    2024-04-03 18:06:01       34 阅读
  7. 基于Spring Boot的高校科研信息管理系统

    2024-04-03 18:06:01       37 阅读
  8. C 函数指针与回调函数

    2024-04-03 18:06:01       32 阅读
  9. 深度学习该如何入门?

    2024-04-03 18:06:01       35 阅读