In [1]:
import os
import tensorflow as tf
tensortflow_version = tf.__version__
# gpu_available = tf.test.is_gpu_available() 后续会丢弃
gpu_available = tf.config.list_physical_devices('GPU')
print(tensortflow_version, gpu_available)
2024-03-29 22:03:14.978569: I tensorflow/core/util/port.cc:110] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`. 2024-03-29 22:03:14.981247: I tensorflow/tsl/cuda/cudart_stub.cc:28] Could not find cuda drivers on your machine, GPU will not be used. 2024-03-29 22:03:15.045083: I tensorflow/tsl/cuda/cudart_stub.cc:28] Could not find cuda drivers on your machine, GPU will not be used. 2024-03-29 22:03:15.046007: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations. To enable the following instructions: AVX2 AVX512F AVX512_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
2024-03-29 22:03:15.967938: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT
2.13.1 []
In [2]:
a = tf.constant([1., 2.], name='a')
b = tf.constant([1., 2.], name='b')
result = tf.add(a, b, name='add')
print(result)
tf.Tensor([2. 4.], shape=(2,), dtype=float32)
In [ ]: