forked from DaLaw2/Performance-Monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGPU.py
More file actions
27 lines (22 loc) · 639 Bytes
/
Copy pathGPU.py
File metadata and controls
27 lines (22 loc) · 639 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import time
import torch
import sys
import os
os.environ['CUDA_LAUNCH_BLOCKING'] = '1'
# 测试gpu计算耗时
A = torch.ones(5000, 5000).to('cuda')
B = torch.ones(5000, 5000).to('cuda')
startTime2 = time.time()
for i in range(100):
C = torch.matmul(A, B)
endTime2 = time.time()
print('gpu:', round((endTime2 - startTime2) * 1000, 2), 'ms')
sys.exit(1)
# # 测试cpu计算耗时
# A = torch.ones(5000, 5000)
# B = torch.ones(5000, 5000)
# startTime1 = time.time()
# for i in range(100):
# C = torch.matmul(A, B)
# endTime1 = time.time()
# print('cpu:', round((endTime1 - startTime1) * 1000, 2), 'ms')