GPU 通过并行化提供优秀的性能,可在一次调用中启动数百万个线程。尽管与 CPU 相比,GPU 的 clock speed 较低,且缺少多核管理功能,但 GPU 的表现通常比 CPU 好。...在 GPU 上执行张量乘法:
try:
with tf.device('/device:GPU:1'):
tensor1 = tf.constant([[1.0, 2.0..., 3.0], [4.0, 5.0, 6.0]])
tensor2 = tf.constant([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])...result = tf.matmul(tensor1, tensor2)
print(result)
except RuntimeError as exception:...选择 TPU 硬件加速器
确认在 TPU 硬件加速器上运行
这需要 TensorFlow 包。