import time
import tensorflow as tf
g = tf.Graph()
# 指定计算运行的设备
a=0
import os
os.environ["CUDA_VISIBLE_DEVICES"]="1"
print(tf.test.is_gpu_available())
with g.device('/gpu:1'):
while True:
a=a**2
2021-05-21 17:29:49.049019: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2021-05-21 17:29:49.053795: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcuda.so.1
2021-05-21 17:29:49.130671: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-05-21 17:29:49.131090: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x55eae82019b0 executing computations on platform CUDA. Devices:
2021-05-21 17:29:49.131115: I tensorflow/compiler/xla/service/service.cc:175] StreamExecutor device (0): GeForce GTX 1080, Compute Capability 6.1
2021-05-21 17:29:49.132963: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 4200000000 Hz
2021-05-21 17:29:49.133603: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x55eae8331e10 executing computations on platform Host. Devices:
2021-05-21 17:29:49.133631: I tensorflow/compiler/xla/service/service.cc:175] StreamExecutor device (0): ,
2021-05-21 17:29:49.133768: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-05-21 17:29:49.134122: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1640] Found device 0 with properties:
name: GeForce GTX 1080 major: 6 minor: 1 memoryClockRate(GHz): 1.873
pciBusID: 0000:02:00.0
2021-05-21 17:29:49.144082: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudart.so.10.0
2021-05-21 17:29:49.158649: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcublas.so.10.0
2021-05-21 17:29:49.166466: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcufft.so.10.0
2021-05-21 17:29:49.168784: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcurand.so.10.0
2021-05-21 17:29:49.187098: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcusolver.so.10.0
2021-05-21 17:29:49.200520: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcusparse.so.10.0
2021-05-21 17:29:49.253722: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudnn.so.7
2021-05-21 17:29:49.254121: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-05-21 17:29:49.255747: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-05-21 17:29:49.257176: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1763] Adding visible gpu devices: 0
2021-05-21 17:29:49.257310: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudart.so.10.0
2021-05-21 17:29:49.262782: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1181] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-05-21 17:29:49.262801: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1187] 0
2021-05-21 17:29:49.262812: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1200] 0: N
2021-05-21 17:29:49.262893: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-05-21 17:29:49.263225: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-05-21 17:29:49.263546: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1326] Created TensorFlow device (/device:GPU:0 with 7605 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1080, pci bus id: 0000:02:00.0, compute capability: 6.1)
True