【问题标题】:TensorFlow only works with GPU 0TensorFlow 仅适用于 GPU 0
【发布时间】:2016-06-27 08:43:12
【问题描述】:

我很难尝试在 GPU 1 中运行 tensorflow 程序。无论我使用 CUDA_VISIBLE_DEVICES=1 python program.py 还是在程序内部使用 tf.device('/gpu:1') 都没有关系,我总是收到以下错误:

I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:900] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
I tensorflow/core/common_runtime/gpu/gpu_init.cc:102] Found device 0 with properties: 
name: Tesla K40c
major: 3 minor: 5 memoryClockRate (GHz) 0.745
pciBusID 0000:04:00.0
Total memory: 12.00GiB
Free memory: 11.90GiB
I tensorflow/core/common_runtime/gpu/gpu_init.cc:126] DMA: 0 
I tensorflow/core/common_runtime/gpu/gpu_init.cc:136] 0:   Y 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:717] Creating TensorFlow device (/gpu:0) -> (device: 0, name: Tesla K40c, pci bus id: 0000:04:00.0)
I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:51] Creating bin of max chunk size 1.0KiB
I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:51] Creating bin of max chunk size 2.0KiB
I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:51] Creating bin of max chunk size 4.0KiB
I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:51] Creating bin of max chunk size 8.0KiB
I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:51] Creating bin of max chunk size 16.0KiB
I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:51] Creating bin of max chunk size 32.0KiB
I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:51] Creating bin of max chunk size 64.0KiB
I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:51] Creating bin of max chunk size 128.0KiB
I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:51] Creating bin of max chunk size 256.0KiB
I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:51] Creating bin of max chunk size 512.0KiB
I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:51] Creating bin of max chunk size 1.00MiB
I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:51] Creating bin of max chunk size 2.00MiB
I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:51] Creating bin of max chunk size 4.00MiB
I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:51] Creating bin of max chunk size 8.00MiB
I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:51] Creating bin of max chunk size 16.00MiB
I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:51] Creating bin of max chunk size 32.00MiB
I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:51] Creating bin of max chunk size 64.00MiB
I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:51] Creating bin of max chunk size 128.00MiB
I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:51] Creating bin of max chunk size 256.00MiB
I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:51] Creating bin of max chunk size 512.00MiB
I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:51] Creating bin of max chunk size 1.00GiB
I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:51] Creating bin of max chunk size 2.00GiB
I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:51] Creating bin of max chunk size 4.00GiB
I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:51] Creating bin of max chunk size 8.00GiB
I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:51] Creating bin of max chunk size 16.00GiB
I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:73] Allocating 11.31GiB bytes.
I tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:83] GPU 0 memory begins at 0x9047a0000 extends to 0xbd8325334
F tensorflow/stream_executor/cuda/cuda_driver.cc:383] Check failed: CUDA_SUCCESS == dynload::cuCtxSetCurrent(context) (0 vs. 216)
F tensorflow/stream_executor/cuda/cuda_driver.cc:383] Check failed: CUDA_SUCCESS == dynload::cuCtxSetCurrent(context) (0 vs. 216)
F tensorflow/stream_executor/cuda/cuda_driver.cc:383] Check failed: CUDA_SUCCESS == dynload::cuCtxSetCurrent(context) (0 vs. 216)
Aborted

使用 GPU0 运行时不会发生这种情况,但问题是其他人正在使用该 GPU,而 GPU1 处于空闲状态

【问题讨论】:

  • 我猜在某处的张量流代码库中有一些对设备 0 的硬编码引用。
  • @talonmies 我在 tensorflow 中一直使用不同的 GPU(使用 CUDA_VISIBLE_DEVICES 来选择 GPU),所以我很确定这种方式一般都有效
  • @etarion:一般工作和针对这种特殊情况工作是两件不同的事情:显然内部上下文处理例程正在崩溃 - 错误 216 是“CUDA_ERROR_CONTEXT_ALREADY_IN_USE”跨度>

标签: python gpu gpgpu tensorflow


【解决方案1】:

如果您使用的是 CUDA_VISIBLE_DEVICES=1,请确保“其他人”正在使用 CUDA_VISIBLE_DEVICES=0 运行。

默认情况下,如果未指定 CUDA_VISIBLE_DEVICES,则 TensorFlow 进程会占用所有 GPU,即使它没有主动使用它们。它们可能看起来很空闲,但后续的 tensorflow 进程将无法访问它们。但是,您可以在每个进程上使用 CUDA_VISIBLE_DEVICES 为每个进程分配不同的 GPU。

请记住,在每个进程中,tensorflow 设备 /gpu:0、/gpu:1 等都是相对于进程而言的,而不是您机器的全局...所以,它们将引用任何可用的 cuda 可见设备到那个进程......换句话说,如果你希望每个进程使用 1 个 GPU,你可以在代码中为所有进程引用 /gpu:0,同时使用 CUDA_VISIBLE_DEVICES 为每个进程分配特定的 GPU。

使用命令nvidia-smi 查看哪些进程正在使用哪些 GPU。

【讨论】:

    猜你喜欢
    • 2020-08-07
    • 1970-01-01
    • 2019-01-04
    • 2019-01-20
    • 2020-09-18
    • 1970-01-01
    • 2021-07-19
    • 1970-01-01
    • 2018-05-07
    相关资源
    最近更新 更多