Anaconda环境安装
输入conda,检查是否安装
输入activate,下一行输入python,检查python版本,然后exit退出。
Cuda安装
选择第二个,可以下载历史版cuda,我在里面选的cuda10.1
进行下载
安装cudnn
安装tensorflow
conda create -n tf21 python=3.7
pip install tensorflow_gpu==2.1.0 -i https://pypi.douban.com/simple --trusted-host pypi.douban.com
import tensorflow as tf
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' # 不显示等级2以下的提示信息
print('GPU', tf.test.is_gpu_available())
a = tf.constant(2.0)
b = tf.constant(4.0)
print(a + b)
引用https://blog.csdn.net/weixin_43786241/article/details/109203995
安装pytorch
conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cudatoolkit=10.1 -c pytorch
到pycharm下载
pytorch测试代码:
import torch
import time
from torch import autograd
#GPU加速
print(torch.__version__)
print(torch.cuda.is_available())
a=torch.randn(10000,1000)
b=torch.randn(1000,10000)
print(a)
print(b)
t0=time.time()
c=torch.matmul(a,b)
t1=time.time()
print(a.device,t1-t0,c.norm(2))
device=torch.device('cuda')
print(device)
a=a.to(device)
b=b.to(device)
t0=time.time()
c=torch.matmul(a,b)
t2=time.time()
print(a.device,t2-t0,c.norm(2))
t0=time.time()
c=torch.matmul(a,b)
t2=time.time()
print(a.device,t2-t0,c.norm(2))
引用https://blog.csdn.net/qq_36162036/article/details/107407928
注意有的显卡会操作不成功