python - Tensorflow - GPU 专用与共享内存

标签 python memory tensorflow gpu

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

我还运行了这个:

从 tensorflow.python.client 导入 device_lib

device_lib.list_local_devices()

[name: "/device:CPU:0" device_type: "CPU" memory_limit: 268435456

name: "/device:GPU:0" device_type: "GPU" memory_limit: 112128819

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

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

TF not using shared memory

最佳答案

根据我的经验,Tensorflow 仅使用如下所述的专用 GPU 内存。当时memory_limit = max dedicated memory - 当前dedicated memory usage(在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

关于python - Tensorflow - GPU 专用与共享内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48492079/

相关文章:

python - 在 2 个 Python 进程之间共享数据结构

c - 用 C 调整数组大小

python - apache上的python flask应用程序的随机问题

android - 如何将在 tensorflow 中制作的对象检测模型与 android 应用程序集成?

python - 在Tensorflow中,sampled_softmax_loss和softmax_cross_entropy_with_logits有什么区别

python - numpy Polynomial.fit 返回不切实际的值

python - 整数数组的基本转换

python - 我的pip正在安装Python3.4中的所有模块

c++ - 缺少析构函数声明

python - 训练好的 Keras 模型无法使用 load_model 加载