Skip to content

Commit

Permalink
Merge pull request #303 from Kashu7100/feat-docker
Browse files Browse the repository at this point in the history
Feat docker
  • Loading branch information
zhouxian authored Dec 25, 2024
2 parents c2c0a63 + 3d68483 commit 04b045c
Show file tree
Hide file tree
Showing 7 changed files with 215 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,26 @@ cd Genesis
pip install -e .
```

## Docker Support

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
```

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

docker run --gpus all --rm -it \
-e DISPLAY=$DISPLAY \
-v /tmp/.X11-unix/:/tmp/.X11-unix \
-v $PWD:/workspace \
genesis
```

## 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.
Expand Down
20 changes: 20 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,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)
Expand Down
6 changes: 6 additions & 0 deletions docker/10_nvidia.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"file_format_version" : "1.0.0",
"ICD" : {
"library_path" : "libEGL_nvidia.so.0"
}
}
118 changes: 118 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
ARG CUDA_VERSION=12.1

# ===============================================================
# Stage 1: Build LuisaRender
# ===============================================================
FROM pytorch/pytorch:2.5.1-cuda${CUDA_VERSION}-cudnn9-devel AS builder

ENV DEBIAN_FRONTEND=noninteractive
ARG PYTHON_VERSION=3.11

# Install necessary packages
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
manpages-dev \
libvulkan-dev \
zlib1g-dev \
xorg-dev libglu1-mesa-dev \
libsnappy-dev \
software-properties-common \
git \
curl \
wget
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 && \
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

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 \
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 \
&& 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"]
22 changes: 22 additions & 0 deletions docker/build_luisa.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

# Check if Python version is provided
if [ -z "$1" ]; then
echo "Usage: $0 <PYTHON_VERSION>"
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)
7 changes: 7 additions & 0 deletions docker/nvidia_icd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"file_format_version" : "1.0.0",
"ICD": {
"library_path": "libGLX_nvidia.so.0",
"api_version" : "1.2.155"
}
}
22 changes: 22 additions & 0 deletions docker/nvidia_layers.json
Original file line number Diff line number Diff line change
@@ -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": ""
}
}
}

0 comments on commit 04b045c

Please sign in to comment.