Open3

VSCode の DevContainer でGPUを使用しつつMMxxxをデバッグする

PINTOPINTO
.devcontainer/devcontainer.json
{
    "name": "Python 3",
    "build": {
        "dockerfile": "Dockerfile",
        "context": ".."
    },

    // Configure tool-specific properties.
    "customizations": {
        // Configure properties specific to VS Code.
        "vscode": {
            // Set *default* container specific settings.json values on container create.
            "settings": {
                "python.defaultInterpreterPath": "/usr/local/bin/python",
                "python.linting.enabled": true,
                "python.linting.pylintEnabled": true,
                "python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
                "python.formatting.blackPath": "/usr/local/py-utils/bin/black",
                "python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
                "python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
                "python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
                "python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
                "python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
                "python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
                "python.linting.pylintPath": "/usr/local/py-utils/bin/pylint"
            },

            // Add the IDs of extensions you want installed when the container is created.
            "extensions": [
                "ms-python.python",
                "ms-python.vscode-pylance"
            ]
        }
    },

    "remoteUser": "vscode",
    "features": {
        "github-cli": "latest"
    },

    // USB Camera mount
    "runArgs": [
        "--gpus", "all",
        "--device", "/dev/video0:/dev/video0:mwr",
        "--privileged"
    ]
}
PINTOPINTO
.devcontainer/Dockerfile
FROM nvidia/cuda:11.3.1-cudnn8-devel-ubuntu20.04

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update \
    && apt-get install -y \
        automake autoconf libpng-dev nano python3-pip \
        curl zip unzip libtool swig zlib1g-dev pkg-config \
        python3-mock libpython3-dev libpython3-all-dev \
        g++ gcc make pciutils cpio gosu wget libmkldnn-dev \
        libgtk-3-dev libxtst-dev sudo apt-transport-https \
        build-essential gnupg git xz-utils vim libyaml-cpp-dev \
        libva-drm2 libva-x11-2 vainfo libva-wayland2 libva-glx2 \
        libva-dev libdrm-dev xorg xorg-dev protobuf-compiler \
        openbox libx11-dev libgl1-mesa-glx libgl1-mesa-dev \
        libtbb2 libtbb-dev libopenblas-dev libopenmpi-dev \
        python-is-python3 software-properties-common \
        libxcb-xinerama0 patchelf libusb-1.0-0-dev \
    && sed -i 's/# set linenumbers/set linenumbers/g' /etc/nanorc \
    && apt clean \
    && rm -rf /var/lib/apt/lists/*

RUN pip3 install \
torch torchvision torchaudio \
--extra-index-url https://download.pytorch.org/whl/cu113

RUN pip3 install --upgrade pip \
    && pip install mmcv-full==1.6.1 \
    && pip install mmdet==2.25.0 \
    && pip install mmsegmentation==0.14.1

RUN pip install onnx \
    && pip install onnxruntime-extensions \
    && pip install onnxsim \
    && pip install scikit-image==0.18.3 \
    && pip install lyft_dataset_sdk \
    && pip install networkx==2.2 \
    && pip install numba==0.48.0 \
    && pip install numpy==1.19.5 \
    && pip install nuscenes-devkit \
    && pip install plyfile \
    && pip install tensorboard \
    && pip install trimesh==2.35.39 \
    && pip install torchmetrics \
    && pip install fvcore \
    && pip install kwarray \
    && pip install isort==4.3.21 \
    && pip install ubelt \
    && pip install yapf \
    && pip install interrogate

ENV USERNAME=vscode
RUN echo "root:root" | chpasswd \
    && adduser --disabled-password --gecos "" "${USERNAME}" \
    && echo "${USERNAME}:${USERNAME}" | chpasswd \
    && echo "%${USERNAME}    ALL=(ALL)   NOPASSWD:    ALL" >> /etc/sudoers.d/${USERNAME} \
    && chmod 0440 /etc/sudoers.d/${USERNAME}
USER ${USERNAME}
ARG WKDIR=/home/${USERNAME}/workdir
WORKDIR ${WKDIR}
RUN sudo chown ${USERNAME}:${USERNAME} ${WKDIR}
RUN echo 'export QT_X11_NO_MITSHM=1' >> ${HOME}/.bashrc
RUN echo 'sudo chmod 776 /dev/video*' >> ${HOME}/.bashrc
PINTOPINTO
$ sudo apt update
$ sudo apt-get install libgl1-mesa-dev -y
$ pip install pip --upgrade
$ pip install torch torchvision torchaudio \
--extra-index-url https://download.pytorch.org/whl/cu113
$ pip install opencv-python
$ pip install -U simple-onnx-processing-tools \
&& pip install -U onnx onnxruntime-gpu onnxsim \
&& python3 -m pip install -U onnx_graphsurgeon \
--index-url https://pypi.ngc.nvidia.com

$ python -c "import torch;print(torch.cuda.is_available())"
True

$ nvidia-smi
Sun Jul 24 06:22:38 2022       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 510.47.03    Driver Version: 510.47.03    CUDA Version: 11.6     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA GeForce ...  On   | 00000000:01:00.0  On |                  N/A |
|  0%   57C    P8    23W / 220W |    579MiB /  8192MiB |      6%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      2184      G                                      53MiB |
|    0   N/A  N/A      2690      G                                     214MiB |
|    0   N/A  N/A      2832      G                                      57MiB |
|    0   N/A  N/A      3246      G                                      36MiB |
|    0   N/A  N/A     33338      G                                      93MiB |
|    0   N/A  N/A     98983      G                                     110MiB |
+-----------------------------------------------------------------------------+