From 9807b0cd4f81dddc3e7224615082ff8661aa56a0 Mon Sep 17 00:00:00 2001 From: Kashu7100 Date: Tue, 24 Dec 2024 23:57:17 -0500 Subject: [PATCH 1/3] init docker --- docker/10_nvidia.json | 6 ++ docker/Dockerfile | 120 ++++++++++++++++++++++++++++++++++++++ docker/build_luisa.sh | 22 +++++++ docker/nvidia_icd.json | 7 +++ docker/nvidia_layers.json | 22 +++++++ 5 files changed, 177 insertions(+) create mode 100644 docker/10_nvidia.json create mode 100644 docker/Dockerfile create mode 100644 docker/build_luisa.sh create mode 100644 docker/nvidia_icd.json create mode 100644 docker/nvidia_layers.json diff --git a/docker/10_nvidia.json b/docker/10_nvidia.json new file mode 100644 index 00000000..2bfcca05 --- /dev/null +++ b/docker/10_nvidia.json @@ -0,0 +1,6 @@ +{ + "file_format_version" : "1.0.0", + "ICD" : { + "library_path" : "libEGL_nvidia.so.0" + } +} diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 00000000..585332e1 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,120 @@ +ARG CUDA_VERSION=12.1 +ARG PYTHON_VERSION=3.11 + +# =============================================================== +# Stage 1: Build LuisaRender +# =============================================================== +FROM pytorch/pytorch:2.5.1-cuda${CUDA_VERSION}-cudnn9-devel AS builder + +ENV DEBIAN_FRONTEND=noninteractive +ENV NVIDIA_DRIVER_CAPABILITIES all + +# Install necessary packages +RUN apt-get update && apt-get install -y --no-install-recommends \ + sudo \ + build-essential \ + manpages-dev \ + libvulkan-dev \ + zlib1g-dev \ + xorg-dev libglu1-mesa-dev \ + libsnappy-dev \ + software-properties-common \ + git \ + curl \ + wget +RUN sudo add-apt-repository ppa:ubuntu-toolchain-r/test && \ + sudo apt update && \ + sudo apt install -y --no-install-recommends \ + gcc-11 \ + g++-11 \ + gcc-11 g++-11 patchelf && \ + rm -rf /var/lib/apt/lists/* + +# Set GCC-11 and G++-11 as the default +RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 110 && \ + update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 110 + +# Install Rust for build requirements +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y + +RUN pip install "pybind11[global]" + +# Install CMake +RUN wget https://github.com/Kitware/CMake/releases/download/v3.31.0-rc2/cmake-3.31.0-rc2-linux-x86_64.sh && \ + chmod +x cmake-3.31.0-rc2-linux-x86_64.sh && \ + ./cmake-3.31.0-rc2-linux-x86_64.sh --skip-license --prefix=/usr/local && \ + rm cmake-3.31.0-rc2-linux-x86_64.sh + +# Build LuisaRender +WORKDIR /workspace +RUN git clone https://github.com/Genesis-Embodied-AI/Genesis.git && \ + cd Genesis && \ + git submodule update --init --recursive +COPY build_luisa.sh /workspace/build_luisa.sh +RUN chmod +x ./build_luisa.sh && ./build_luisa.sh ${PYTHON_VERSION} + +# =============================================================== +# Stage 2: Runtime Environment +# =============================================================== +FROM pytorch/pytorch:2.5.1-cuda${CUDA_VERSION}-cudnn9-devel + +ENV DEBIAN_FRONTEND=noninteractive + +# Install runtime dependencies +RUN apt-get update && apt-get install -y --no-install-recommends \ + sudo \ + tmux \ + git \ + curl \ + wget \ + bash-completion \ + libgl1 \ + libgl1-mesa-glx \ + libegl-dev \ + libegl1 \ + libxrender1 \ + libglib2.0-0 \ + ffmpeg \ + libgtk2.0-dev \ + pkg-config \ + libvulkan-dev \ + libgles2 \ + libglvnd0 \ + libglx0 \ + nvidia-utils-535 \ + && apt clean \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /workspace + +# --------------------------- Genesis ---------------------------- +RUN pip install --no-cache-dir open3d +RUN git clone https://github.com/Genesis-Embodied-AI/Genesis.git && \ + cd Genesis && \ + pip install . && \ + pip install --no-cache-dir PyOpenGL==3.1.5 + +# ------------------------ Motion planning ----------------------- +RUN PYTHON_MAJOR_MINOR=$(echo ${PYTHON_VERSION} | tr -d '.') && \ + wget https://github.com/ompl/ompl/releases/download/prerelease/ompl-1.6.0-cp${PYTHON_MAJOR_MINOR}-cp${PYTHON_MAJOR_MINOR}-manylinux_2_28_x86_64.whl && \ + pip install ompl-1.6.0-cp${PYTHON_MAJOR_MINOR}-cp${PYTHON_MAJOR_MINOR}-manylinux_2_28_x86_64.whl && \ + rm ompl-1.6.0-cp${PYTHON_MAJOR_MINOR}-cp${PYTHON_MAJOR_MINOR}-manylinux_2_28_x86_64.whl + +# -------------------- Surface Reconstruction -------------------- +# Set the LD_LIBRARY_PATH directly in the environment +COPY --from=builder /workspace/Genesis/genesis/ext/ParticleMesher/ParticleMesherPy /opt/conda/lib/python3.1/site-packages/genesis/ext/ParticleMesher/ParticleMesherPy +ENV LD_LIBRARY_PATH=/opt/conda/lib/python3.1/site-packages/genesis/ext/ParticleMesher/ParticleMesherPy:$LD_LIBRARY_PATH + +# --------------------- Ray Tracing Renderer --------------------- +# Copy LuisaRender build artifacts from the builder stage +COPY --from=builder /workspace/Genesis/genesis/ext/LuisaRender/build/bin /opt/conda/lib/python3.1/site-packages/genesis/ext/LuisaRender/build/bin +# fix GLIBCXX_3.4.30 not found +RUN cd /opt/conda/lib && \ + mv libstdc++.so.6 libstdc++.so.6.old && \ + ln -s /usr/lib/x86_64-linux-gnu/libstdc++.so.6 libstdc++.so.6 + +COPY 10_nvidia.json /usr/share/glvnd/egl_vendor.d/10_nvidia.json +COPY nvidia_icd.json /usr/share/vulkan/icd.d/nvidia_icd.json +COPY nvidia_layers.json /etc/vulkan/implicit_layer.d/nvidia_layers.json + +ENTRYPOINT ["/bin/bash"] diff --git a/docker/build_luisa.sh b/docker/build_luisa.sh new file mode 100644 index 00000000..95d861c5 --- /dev/null +++ b/docker/build_luisa.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Check if Python version is provided +if [ -z "$1" ]; then + echo "Usage: $0 " + exit 1 +fi + +PYTHON_VERSION=$1 + +cd Genesis/genesis/ext/LuisaRender && \ +git submodule update --init --recursive && \ +mkdir -p build && \ +cmake -S . -B build \ + -D CMAKE_BUILD_TYPE=Release \ + -D PYTHON_VERSIONS=$PYTHON_VERSION \ + -D LUISA_COMPUTE_DOWNLOAD_NVCOMP=ON \ + -D LUISA_COMPUTE_DOWNLOAD_OIDN=ON \ + -D LUISA_COMPUTE_ENABLE_GUI=OFF \ + -D LUISA_COMPUTE_ENABLE_CUDA=ON \ + -Dpybind11_DIR=$(python3 -c "import pybind11; print(pybind11.get_cmake_dir())") && \ +cmake --build build -j $(nproc) \ No newline at end of file diff --git a/docker/nvidia_icd.json b/docker/nvidia_icd.json new file mode 100644 index 00000000..69600b17 --- /dev/null +++ b/docker/nvidia_icd.json @@ -0,0 +1,7 @@ +{ + "file_format_version" : "1.0.0", + "ICD": { + "library_path": "libGLX_nvidia.so.0", + "api_version" : "1.2.155" + } +} diff --git a/docker/nvidia_layers.json b/docker/nvidia_layers.json new file mode 100644 index 00000000..a8e098eb --- /dev/null +++ b/docker/nvidia_layers.json @@ -0,0 +1,22 @@ + +{ + "file_format_version" : "1.0.0", + "layer": { + "name": "VK_LAYER_NV_optimus", + "type": "INSTANCE", + "library_path": "libGLX_nvidia.so.0", + "api_version" : "1.2.155", + "implementation_version" : "1", + "description" : "NVIDIA Optimus layer", + "functions": { + "vkGetInstanceProcAddr": "vk_optimusGetInstanceProcAddr", + "vkGetDeviceProcAddr": "vk_optimusGetDeviceProcAddr" + }, + "enable_environment": { + "__NV_PRIME_RENDER_OFFLOAD": "1" + }, + "disable_environment": { + "DISABLE_LAYER_NV_OPTIMUS_1": "" + } + } +} From 4fc8eaf13974c6f71b0908f548c6f09fec27d75b Mon Sep 17 00:00:00 2001 From: Kashu7100 Date: Wed, 25 Dec 2024 04:02:24 -0500 Subject: [PATCH 2/3] dockker update --- README.md | 20 ++++++++++++++++++++ docker/Dockerfile | 16 +++++++--------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 95c1d23b..7ea3a5ae 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,26 @@ cd Genesis pip install -e . ``` +## Docker Installation + +First build the Docker image: + +```bash +docker build -t genesis -f docker/Dockerfile docker +``` + +And then run the examples inside the docker image (mounted to `/workspace/examples`): + +```bash +xhost +local:root # Allow the container to access the display + +docker run --gpus all --rm -it \ +-e DISPLAY=$DISPLAY \ +-v /tmp/.X11-unix/:/tmp/.X11-unix \ +-v $PWD:/workspace \ +genesis bash +``` + ## Documentation Comprehensive documentation is available in [English](https://genesis-world.readthedocs.io/en/latest/user_guide/index.html) and [Chinese](https://genesis-world.readthedocs.io/zh-cn/latest/user_guide/index.html). This includes detailed installation steps, tutorials, and API references. diff --git a/docker/Dockerfile b/docker/Dockerfile index 585332e1..e2ef6707 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,5 +1,4 @@ ARG CUDA_VERSION=12.1 -ARG PYTHON_VERSION=3.11 # =============================================================== # Stage 1: Build LuisaRender @@ -7,11 +6,10 @@ ARG PYTHON_VERSION=3.11 FROM pytorch/pytorch:2.5.1-cuda${CUDA_VERSION}-cudnn9-devel AS builder ENV DEBIAN_FRONTEND=noninteractive -ENV NVIDIA_DRIVER_CAPABILITIES all +ARG PYTHON_VERSION=3.11 # Install necessary packages RUN apt-get update && apt-get install -y --no-install-recommends \ - sudo \ build-essential \ manpages-dev \ libvulkan-dev \ @@ -22,9 +20,9 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ git \ curl \ wget -RUN sudo add-apt-repository ppa:ubuntu-toolchain-r/test && \ - sudo apt update && \ - sudo apt install -y --no-install-recommends \ +RUN add-apt-repository ppa:ubuntu-toolchain-r/test && \ + apt update && \ + apt install -y --no-install-recommends \ gcc-11 \ g++-11 \ gcc-11 g++-11 patchelf && \ @@ -58,11 +56,12 @@ RUN chmod +x ./build_luisa.sh && ./build_luisa.sh ${PYTHON_VERSION} # =============================================================== FROM pytorch/pytorch:2.5.1-cuda${CUDA_VERSION}-cudnn9-devel +ARG PYTHON_VERSION=3.11 ENV DEBIAN_FRONTEND=noninteractive +ENV NVIDIA_DRIVER_CAPABILITIES=all # Install runtime dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ - sudo \ tmux \ git \ curl \ @@ -80,8 +79,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ libvulkan-dev \ libgles2 \ libglvnd0 \ - libglx0 \ - nvidia-utils-535 \ + libglx0 \ && apt clean \ && rm -rf /var/lib/apt/lists/* From 3d684834bdffdda3b0d1e27089a1e7f3a7ac99ab Mon Sep 17 00:00:00 2001 From: Kashu7100 Date: Wed, 25 Dec 2024 04:53:25 -0500 Subject: [PATCH 3/3] update readme --- README.md | 8 ++++---- README_CN.md | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7ea3a5ae..3fd756d3 100644 --- a/README.md +++ b/README.md @@ -72,15 +72,15 @@ cd Genesis pip install -e . ``` -## Docker Installation +## Docker Support -First build the Docker image: +If you want to use Genesis from Docker, you can first build the Docker image as: ```bash docker build -t genesis -f docker/Dockerfile docker ``` -And then run the examples inside the docker image (mounted to `/workspace/examples`): +Then you can run the examples inside the docker image (mounted to `/workspace/examples`): ```bash xhost +local:root # Allow the container to access the display @@ -89,7 +89,7 @@ docker run --gpus all --rm -it \ -e DISPLAY=$DISPLAY \ -v /tmp/.X11-unix/:/tmp/.X11-unix \ -v $PWD:/workspace \ -genesis bash +genesis ``` ## Documentation diff --git a/README_CN.md b/README_CN.md index 41e8c424..ef84b230 100644 --- a/README_CN.md +++ b/README_CN.md @@ -55,6 +55,26 @@ pip install genesis-world # 需要 Python >=3.9; 您还需要按照 [官方说明](https://pytorch.org/get-started/locally/) 安装 **PyTorch**。 +### Docker 支持 + +如果您想通过 Docker 使用 Genesis,您可以首先构建 Docker 镜像,命令如下: + +```bash +docker build -t genesis -f docker/Dockerfile docker +``` + +然后,您可以在 Docker 镜像内运行示例代码(挂载到 `/workspace/examples`): + +```bash +xhost +local:root # 允许容器访问显示器 + +docker run --gpus all --rm -it \ +-e DISPLAY=$DISPLAY \ +-v /tmp/.X11-unix/:/tmp/.X11-unix \ +-v $PWD:/workspace \ +genesis +``` + ### 文档 请参阅我们的 [文档网站(英文)](https://genesis-world.readthedocs.io/en/latest/user_guide/index.html)/[(中文)](https://genesis-world.readthedocs.io/zh-cn/latest/user_guide/index.html)以获取详细的安装步骤、教程和 API 参考。