ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • docker --runtime=nvidia default로 바꾸기 (GPU 사용 default)
    개발 환경/Docker 2020. 2. 26. 13:24
    반응형

    docker container에서 GPU를 사용하기 위해 docker의 runtime을 nvidia로 설정해줘야한다. 하지만 Pycharm과 같은 IDE에서 docker를 사용할 때는 매우 번거롭다. 그러므로 docker 차원에서 runtime을 nvidia로 default 설정해주자.

     

    1. nvidia-smi test

    docker run --rm ubuntu nvidia-smi

    output:

    nvidia-smi: command not found
    • --runtime=nvidia
    docker run --rm --runtime=nvidia ubuntu nvidia-smi

    output:

    Wed Feb 26 04:19:07 2020
    +-----------------------------------------------------------------------------+
    | NVIDIA-SMI 430.50       Driver Version: 430.50       CUDA Version: 10.1     |
    |-------------------------------+----------------------+----------------------+
    | GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
    | Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
    |===============================+======================+======================|
    |   0  GeForce GTX 1070    Off  | 00000000:01:00.0 Off |                  N/A |
    |  0%   32C    P8     6W / 166W |     21MiB /  8117MiB |      1%      Default |
    +-------------------------------+----------------------+----------------------+
    
    +-----------------------------------------------------------------------------+
    | Processes:                                                       GPU Memory |
    |  GPU       PID   Type   Process name                             Usage      |
    |=============================================================================|
    +-----------------------------------------------------------------------------+

    2. docker daemon.json 파일 수정

    sudo vim /etc/docker/daemon.json

    before:

    {
        "runtimes": {
            "nvidia": {
                "path": "nvidia-container-runtime",
                "runtimeArgs": []
            }
        }
    }

    after:

    {
        "default-runtime": "nvidia",
        "runtimes": {
            "nvidia": {
                "path": "nvidia-container-runtime",
                "runtimeArgs": []
            }
        }
    }

     

     

    3. docker 재시작

    sudo service docker restart

     

    4. --runtime=nvidia 없이 nvidia-smi test

    docker run --rm ubuntu nvidia-smi

    output:

    Wed Feb 26 04:21:52 2020
    +-----------------------------------------------------------------------------+
    | NVIDIA-SMI 430.50       Driver Version: 430.50       CUDA Version: 10.1     |
    |-------------------------------+----------------------+----------------------+
    | GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
    | Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
    |===============================+======================+======================|
    |   0  GeForce GTX 1070    Off  | 00000000:01:00.0 Off |                  N/A |
    |  0%   32C    P8     6W / 166W |     21MiB /  8117MiB |      0%      Default |
    +-------------------------------+----------------------+----------------------+
    
    +-----------------------------------------------------------------------------+
    | Processes:                                                       GPU Memory |
    |  GPU       PID   Type   Process name                             Usage      |
    |=============================================================================|
    +-----------------------------------------------------------------------------+

     

    출처:

    http://drmola.com/bbs_free/318738

    반응형
Designed by Tistory.