TensorFlow - GPU 专用内存 vs 共享内存

3
Tensorflow是否仅使用专用GPU内存,还是也可以使用共享内存?
此外,我运行了以下代码:
from tensorflow.python.client import device_lib

device_lib.list_local_devices()

[名称: "/device:CPU:0" 设备类型: "CPU" 内存限制: 268435456

名称: "/device:GPU:0" 设备类型: "GPU" 内存限制: 112128819

这些“内存限制”268,435,456和112,128,819是什么意思?

我说的是 - 当我在Win10上运行TF时,共享内存总是为零,但如果我的批次大小太大,我会遇到ResourceExhaustedError。似乎共享内存从未被使用。

TF not using shared memory


1
如果同时使用专用GPU内存和共享内存(https://github.com/tensorflow/tensorflow/blob/4be5afc8b656cf6b540b547a1faafd2a0a82f5f2/tensorflow/core/kernels/concat_lib_gpu_impl.cu.cc#L72)。这些值在此处描述:https://github.com/tensorflow/tensorflow/blob/5a5a25ea3ebef623e07fb9a46419a9df377a37a5/tensorflow/core/framework/device_attributes.proto#L22 - Patwie
我只能观察专用内存的使用情况(在nvidia-smi和Windows任务管理器中),但我无法看到它是否在使用共享内存。我该如何确认? - Mike
你是说这个共享内存吗?CUDA核函数会使用这个共享内存,就像c malloc在主机端申请内存一样。 - Patwie
1个回答

0
根据我的经验,Tensorflow只使用如下所述的专用GPU内存。此时,memory_limit = 最大专用内存 - 当前专用内存使用量(在Win10任务管理器中观察)。
from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())

输出:

physical_device_desc: "device: XLA_CPU device"
, name: "/device:GPU:0"
device_type: "GPU"
memory_limit: 2196032718

为了验证这一点,我尝试使用一个单一的任务(来自https://github.com/aime-team/tf2-benchmarks的Tensorflow 2基准测试),在装有Tensorflow 2.3.0的GTX1060 3GB上运行时出现了以下“资源耗尽”的错误。
2021-01-20 01:50:53.738987: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1716] Found device 0 with properties: 
pciBusID: 0000:01:00.0 name: GeForce GTX 1060 3GB computeCapability: 6.1
coreClock: 1.7085GHz coreCount: 9 deviceMemorySize: 3.00GiB deviceMemoryBandwidth: 178.99GiB/s

Limit:                      2196032718
InUse:                      1997814016
MaxInUse:                   2155556352
NumAllocs:                        1943
MaxAllocSize:                551863552
Reserved:                            0
PeakReserved:                        0
LargestFreeBlock:                    0

2021-01-20 01:51:21.393175: W tensorflow/core/framework/op_kernel.cc:1767] OP_REQUIRES failed at conv_ops.cc:539 : Resource exhausted: OOM when allocating tensor with shape[64,256,56,56] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc
Traceback (most recent call last):

我尝试通过多个小任务来实现同样的操作。它试图使用共享的GPU内存来运行不同的Juypter内核上的多个任务,但最终较新的任务失败。

例如,有两个相似的Xception模型:

任务1:没有错误地运行

任务2:出现以下错误而失败

UnknownError:  Failed to get convolution algorithm. This is probably because cuDNN failed to initialize, so try looking to see if a warning log message was printed above.
     [[node xception/block1_conv1/Conv2D (defined at <ipython-input-25-0c5fe80db9f1>:3) ]] [Op:__inference_predict_function_5303]

Function call stack:
predict_function

在失败时的GPU内存使用情况(请注意任务2开始时共享内存的使用)

GPU Memory usage at the failure


1
我不确定这是否是回答问题的尝试,无论如何,这个地方是用来回答问题的,而不是评论或无关的讨论。 - Dr. Snoopy

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接