gputest.py 675 Bytes
Newer Older
maming's avatar
maming committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import tensorflow as tf

# 检查 TensorFlow 版本
print("TensorFlow 版本:", tf.__version__)

# 检查是否有 GPU 可用
physical_devices = tf.config.list_physical_devices('GPU')
if len(physical_devices) > 0:
    print("GPU 可用! 检测到的 GPU 设备:")
    for device in physical_devices:
        print(device)
else:
    print("未检测到 GPU,TensorFlow 将使用 CPU。")

# 简单测试 GPU 是否工作
try:
    with tf.device('/GPU:0'):
        a = tf.random.normal([1000, 1000])
        b = tf.random.normal([1000, 1000])
        c = tf.matmul(a, b)
        print("GPU 上矩阵乘法成功!")
except RuntimeError as e:
    print("GPU 测试失败:", e)