【问题标题】:Force python script on GPU在 GPU 上强制执行 python 脚本
【发布时间】:2020-04-19 14:22:53
【问题描述】:

有没有办法在 GPU 上强制 Python 脚本?在我的代码中,我使用了 tensorflow 和 keras,并且我已经有了 tensorflow-gpu 版本,但是我的代码无论如何都在 CPU 上运行。我想知道是否有办法在 Tensorflow、Numpy 或其他人上独立地强制在 GPU 上运行。

【问题讨论】:

  • 有pyopencl和pycuda;这是你要找的东西吗?

标签: python tensorflow


【解决方案1】:

您的 tensorflow-gpu 安装可能存在问题。尝试创建一个单独的环境并仅重新安装 tensorflow-gpu。

Similar post

【讨论】:

    【解决方案2】:

    对于 TensorFlow(但不是一般的 python),这里有一个很好的描述:https://www.tensorflow.org/guide/gpu

    要强制在特定处理器(CPU 或 GPU)上执行功能,请使用 TensorFlow 调用 tf.device(),如下所示:

    import tensorflow as tf
    with tf.device('/GPU:0'):
      a = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
      b = tf.constant([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])
      c = tf.matmul(a, b)
    

    在这种情况下,a 和 b 的数据将存储在 GPU0 上,“matmul”操作也会在 GPU0 上执行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-01
      • 2015-06-03
      • 1970-01-01
      • 2012-07-01
      • 2012-03-28
      • 2011-05-13
      相关资源
      最近更新 更多