1. 代码
import os
from tensorflow.python.client import device_lib
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "99"
if __name__ == "__main__":
print(device_lib.list_local_devices())
import torch
import torch.nn as nn
from torch.utils.data import Dataset, DataLoader
print(torch.cuda.is_available())
import torch.nn as nn
import torch.optim as optim
input_size = 5
output_size = 2
batch_size = 30
data_size = 100
device = torch.device("cuda: 0" if torch.cuda.is_available() else "cpu")
class RandomDataset(Dataset):
def __init__(self, size, length):
self.len = length
self.data = torch.randn(length, size)
def __getitem__(self, index):
return self.data[index]
def __len__(self):
return self.len
rand_loader = DataLoader(dataset=RandomDataset(input_size, data_size),
batch_size=batch_size, shuffle=True)
class Model(nn.Module):
def __init__(self, input_size, output_size):
super(Model, self).__init__()
self.fc = nn.Linear(input_size, output_size)
def forward(self, input):
output = self.fc(input)
print("\tIn Model: input size", input.size(),
"output size", output.size())
return output
model = Model(input_size, output_size)
if torch.cuda.device_count() >= 1:
print("Let's use", torch.cuda.device_count(), "GPUs!")
model = nn.DataParallel(model)
model.to(device)
for data in rand_loader:
input = data.to(device)
output = model(input)
print("Outside: input size", input.size(),
"output_size", output.size())
2. 显卡计算能力对照表
GPU | Compute Capability |
---|
Tesla K80 | 3.7 |
Tesla K40 | 3.5 |
Tesla K20 | 3.5 |
Tesla C2075 | 2.0 |
Tesla C2050/C2070 | 2.0 |
Tesla P100 | 6.0 |
Tesla P40 | 6.1 |
Tesla P4 | 6.1 |
Tesla M40 | 5.2 |
Tesla K80 | 3.7 |
Tesla K40 | 3.5 |
Tesla K20 | 3.5 |
Tesla K10 | 3.0 |
Quadro P6000 | 6.1 |
Quadro P5000 | 6.1 |
Quadro M6000 24GB | 5.2 |
Quadro M6000 | 5.2 |
Quadro K6000 | 3.5 |
Quadro M5000 | 5.2 |
Quadro K5200 | 3.5 |
Quadro K5000 | 3.0 |
Quadro M4000 | 5.2 |
Quadro K4200 | 3.0 |
Quadro K4000 | 3.0 |
Quadro M2000 | 5.2 |
Quadro K2200 | 5.0 |
Quadro K2000 | 3.0 |
Quadro K2000D | 3.0 |
Quadro K1200 | 5.0 |
Quadro K620 | 5.0 |
Quadro K600 | 3.0 |
Quadro K420 | 3.0 |
Quadro 410 | 3.0 |
Quadro Plex 7000 | 2.0 |
Quadro K6000M | 3.0 |
Quadro M5500M | 5.0 |
Quadro K5200M | 3.0 |
Quadro K5100M | 3.0 |
Quadro M5000M | 5.0 |
Quadro K500M | 3.0 |
Quadro K4200M | 3.0 |
Quadro K4100M | 3.0 |
Quadro M4000M | 5.0 |
Quadro K3100M | 3.0 |
Quadro M3000M | 5.0 |
Quadro K2200M | 5.0 |
Quadro K2100M | 3.0 |
Quadro M2000M | 5.0 |
Quadro K1100M | 3.0 |
Quadro M1000M | 5.0 |
Quadro K620M | 5.0 |
Quadro K610M | 3.5 |
Quadro M600M | 5.0 |
Quadro K510M | 3.5 |
Quadro M500M | 5.0 |
…
更全的显卡链接
参考博客