5

我有两个 GPU。我的程序使用 TensorRT 和 Tensorflow。

当我只运行 TensorRT 部分时,这很好。当我与 Tensorflow 部分一起运行时,出现错误

[TensorRT] ERROR: engine.cpp (370) - Cuda Error in ~ExecutionContext: 77 (an illegal memory access was encountered)
terminate called after throwing an instance of 'nvinfer1::CudaError'
  what():  std::exception

问题是当 TensorFlow 会话开始时如下

self.graph = tf.get_default_graph()
self.persistent_sess = tf.Session(graph=self.graph, config=tf_config)

它将两个 GPU 加载为

2019-06-06 14:15:04.420265: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 6965 MB memory) -> physical GPU (device: 0, name: Quadro P4000, pci bus id: 0000:04:00.0, compute capability: 6.1)
2019-06-06 14:15:04.420713: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:1 with 7159 MB memory) -> physical GPU (device: 1, name: Quadro P4000, pci bus id: 0000:05:00.0, compute capability: 6.1)

我试图只加载一个 GPU

(1)放在python代码之上

import os
os.environ["CUDA_VISIBLE_DEVICES"]="0"

(2)

with tf.device('/device:GPU:0'):
    self.graph = tf.get_default_graph()
    self.persistent_sess = tf.Session(graph=self.graph, config=tf_config)

两者都不起作用。

如何解决问题?

4

1 回答 1

9

我可以设法只加载一个 GPU,将以下几行放在 python 代码的第一行。

import sys, os
os.environ["CUDA_VISIBLE_DEVICES"]="0"
于 2019-06-06T06:41:16.730 回答