microsoft / wslg

Enabling the Windows Subsystem for Linux to include support for Wayland and X server related scenarios
MIT License
9.9k stars 296 forks source link

Docker not recognizing vulkan GPU #1215

Open selmiskr opened 3 months ago

selmiskr commented 3 months ago

Windows build number:

Microsoft Windows [Version 10.0.22631.3296]

Your Distribution version:

Ubuntu 22.04

Your WSL versions:

2.0.14.0

Steps to reproduce:

GIVEN following Dockerfile

FROM nvidia/cuda:12.3.2-base-ubuntu22.04
ENV NVIDIA_VISIBLE_DEVICES all
ENV NVIDIA_DRIVER_CAPABILITIES all

# DEPENDENCIES
RUN apt update && apt install -y software-properties-common
RUN add-apt-repository ppa:kisak/kisak-mesa && apt update
RUN apt update && apt install -y \                       
        libatomic1 \
        libxi6 \
        libxrandr2 \
        libxt6 \
        libegl1 \
        libglu1-mesa \
        libgomp1 \
        libsm6 \
        libvulkan1 \
        mesa-vulkan-drivers \
        vulkan-tools \
        sudo && rm -rf /var/lib/apt/lists/*

WORKDIR /etc/vulkan/icd.d
RUN ls -l
RUN sudo touch nvidia_icd.json
RUN printf "{ \"file_format_version\" : \"1.0.0\", \"ICD\": { \"library_path\": \"libGLX_nvidia.so.0\", \"api_version\" : \"$(dpkg -s libvulkan1 | grep -oP 'Version: [0-9|\.]+' | grep -oP '[0-9|\.]+')\" } }" | sudo tee nvidia_icd.json

BUILD Dockerfile

docker build `
    --no-cache `
    --progress=plain `
    -t vulkan `
    -f DOCKERFILE

RUN with

docker run `
    --rm `
    --privileged `
    --gpus all `
    -it `
    vulkan `
    vulkaninfo --summary

WSL logs:

No response

WSL dumps:

No response

Expected behavior:

Summary giving me the physical GPU. If I run within WSL2 I get the following:

image

I expect this also inside docker.

Actual behavior:

I only get the CPU for vulkan. See screenshot.

image

Running nvidia-smi inside the docker container gives. image

So the GPU is recognized within docker but vulkan is not selecting it. It seems that the icd.d json is also missing inside WSL and therefore vulkan within the docker container cannot map to it and does not recognize the GPU