【问题标题】:Tensorflow - GPU dedicated vs shared memoryTensorflow - GPU 专用与共享内存
【发布时间】:2018-07-07 14:33:31
【问题描述】:

Tensorflow 是只使用专用 GPU 内存还是也可以使用共享内存?

我也跑了这个:

从 tensorflow.python.client 导入 device_lib

device_lib.list_local_devices()

[名称:“/设备:CPU:0” 设备类型:“CPU” memory_limit: 268435456

名称:“/设备:GPU:0” 设备类型:“GPU” memory_limit: 112128819

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

这就是我所说的——当我在 Win10 上运行 TF 时,共享内存始终为零,但如果我的批处理大小太大,我会得到 ResourceExhaustedError。似乎从未使用过共享内存。

【问题讨论】:

标签: python memory tensorflow gpu


【解决方案1】:

根据我的经验,Tensorflow 仅使用如下所述的专用 GPU 内存。那时memory_limit = max dedicated memory - 当前的专用内存使用量(在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开始时共享内存的使用情况)

【讨论】:

  • 我不确定这是不是试图回答这个问题,无论如何这个地方是为了回答这个问题,而不是 cmets 或无关的讨论。
猜你喜欢
  • 2018-05-31
  • 1970-01-01
  • 2018-06-17
  • 2017-08-28
  • 2012-06-24
  • 1970-01-01
  • 2013-06-11
  • 1970-01-01
相关资源
最近更新 更多