tensorflow和torch代码验证cuda是否安装成功

tensorflow代码验证cuda是否安装成功
tensorflow 测试 cuda 是否安装成功,测试代码环境

tensorflow

import tensorflow as tf

tf.test.is_gpu_available()

或者

sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))

torch

import torch
flag = torch.cuda.is_available()
print(flag)

gpunumber = 1

Decide which device we want to run on

device = torch.device("cuda:0" if (torch.cuda.is_available() and gpunumber > 0) else "cpu")
print(device)
print(torch.cuda.get_device_name(0))
print(torch.rand(3,3).cuda())

猜你喜欢

转载自blog.csdn.net/qq_15821487/article/details/125634549
今日推荐