当前位置: 首页 > 后端技术 > Python

tensor.to向cuda发送数据太慢?张量到速度测试

时间:2023-03-26 13:27:48 Python

测试代码:importtimeimporttorchfromloguruimportloggerdevice='cuda'batch_size=1000image_channel=3image_size=224count=int(100000/batch_size)logger.debug(f'readytoinputdata')input_data=torch.randn(batch_size,image_channelsize,image_image_size)total_bytes=input_data.numel()*input_data.element_size()print('total_MB',total_bytes/1024/1024)logger.debug(f'开始计数')started_at=time.time()foriinrange(count):input_data_with_cuda=input_data.to(device)ended_at=time.time()print('paytime',ended_at-started_at)测试不同平台下的运行速度,因为这个肯定和内存速度,显存带宽,显存速度等等等等都是相关的测试平台1:intelXeonE5-2690CPU+tesla-m60GPUCPU:IntelXeonE5-2690RAM:DDR42400MHzGPU:NVIDIATeslaM60运行结果2023-03-1507:18:28.542|调试|__main__::15-准备输入数据total_MB574.218752023-03-1507:18:29.688|调试|__main__::23-开始计算支付时间12.158783435821533测试平台二:Intel(R)Xeon(R)Gold5218CPU@2.30GHz+tesla-T4GPUCPU:Intel(R)Xeon(R)Gold5218CPU@2.30GHzRAM:DDR43200MHzGPU:NVIDIATeslaT4运行结果2023-03-1515:38:21.722|调试|__main__::15-准备输入数据total_MB574.218752023-03-1515:38:22.766|调试|__main__::23-开始计算支付时间13.845425367355347测试平台三:Macbookpro13AppleSiliconM18coreCPU8coreGPU运行结果2023-03-1515:39:53.084|调试|__main__::15-准备输入数据total_MB574.218752023-03-1515:39:54.708|调试|__main__::23-开始计算支付时间4.494465112686157