cpu消耗 pytorch_pytorch中分析时间开销的方法

前天实验室老铁突然给我发来消息

原来是之前在服务器跑的一个程序cpu占比超过了1000%,明显就是有操作在cpu耗时太大,.并且肉眼检查了code之后,发现模型运算都是在gpu中运行的,于是上网搜索了一下,看到了下面了工具,mark一下:

查看你定义操作的时间花销,autograd 的 profiler 提供内视每个操作在GPU和CPU的花销,对于CPU通过profile,  基于nvprof通过使用emit_nvtx

from torch.autograd import Variable

import torch

x = Variable(torch.randn(1, 1), requires_grad=True)

with torch.autograd.profiler.profile() as prof:

y = x ** 2

y.backward()

# NOTE: some columns were removed for brevity

print(prof)

结果如下(没有使用gpu):

但是我用上述方法的时候,即使在gpu上运行,发现CUDA时间也是0.000us,在论坛上搜到了下面的回答:

于是我在with torch.autograd.profiler.profile(uascuda=True) as prof:加了use_cuda=True,结果如下:

希望大家可以用这个工具帮助分析。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值