我有两个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)


两者都不起作用。

如何解决问题?

最佳答案

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

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

10-06 06:29