From 887eb82f099ba48a59f894b8eaa50ce52fbbb7da Mon Sep 17 00:00:00 2001 From: pvl-bot Date: Sat, 5 Aug 2023 15:18:52 -0400 Subject: [PATCH] Docker overhaul (#65) Co-authored-by: datashaman Co-authored-by: David Yan --- Dockerfile | 40 ++++++++++++ Makefile | 103 +++++++++++++++++++++++++++++++ docs/Installation.md | 16 +++++ install.sh | 2 +- worldgen/tools/compile_opengl.sh | 12 ++++ 5 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 worldgen/tools/compile_opengl.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..462741744 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,40 @@ +ARG APP_IMAGE=continuumio/miniconda3 +FROM ${APP_IMAGE} +ARG APP_IMAGE +ENV PATH="/root/miniconda3/bin:${PATH}" +RUN if [ "$APP_IMAGE" = "nvidia/cuda:12.0.0-devel-ubuntu22.04" ]; then \ + echo "Using CUDA image" && \ + apt-get update && \ + apt-get install -y unzip sudo git g++ libglm-dev libglew-dev libglfw3-dev libgles2-mesa-dev zlib1g-dev wget cmake vim libxi6 libgconf-2-4 && \ + wget \ + https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \ + && mkdir /root/.conda \ + && bash Miniconda3-latest-Linux-x86_64.sh -b \ + && rm -f Miniconda3-latest-Linux-x86_64.sh; \ +else \ + echo "Using Conda image" && \ + apt-get update -yq \ + && apt-get install -yq \ + cmake \ + g++ \ + libgconf-2-4 \ + libgles2-mesa-dev \ + libglew-dev \ + libglfw3-dev \ + libglm-dev \ + libxi6 \ + sudo \ + unzip \ + vim \ + zlib1g-dev; \ +fi + +RUN mkdir /opt/infinigen +WORKDIR /opt/infinigen +COPY . . +RUN chmod +x worldgen/tools/compile_opengl.sh +RUN conda init bash \ + && . ~/.bashrc \ + && conda create --name infinigen python=3.10 \ + && conda activate infinigen \ + && ./install.sh \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..131c521a6 --- /dev/null +++ b/Makefile @@ -0,0 +1,103 @@ +DOCKER_BUILD_PROGRESS ?= auto +DOCKER_TAG ?= infinigen_docker_img + +PWD = $(shell pwd) + +XSOCK=/tmp/.X11-unix +XAUTH=/tmp/.docker.xauth + +default: + +docker-build: + git submodule init + git submodule update + docker build \ + --tag $(DOCKER_TAG) \ + --progress $(DOCKER_BUILD_PROGRESS) . + +docker-build-cuda: + git submodule init + git submodule update + docker build \ + --tag $(DOCKER_TAG) \ + --progress $(DOCKER_BUILD_PROGRESS) \ + --build-arg APP_IMAGE=nvidia/cuda:12.0.0-devel-ubuntu22.04 . + +docker-clean: + echo "Removing infinigen docker image if already exists..." + -docker rmi -f $(DOCKER_TAG) + +docker-setup: + sudo apt-get install x11-xserver-utils \ + && touch ~/.Xauthority \ + && xauth add $(HOST):0 . $(shell xxd -l 16 -p /dev/urandom) \ + && touch "$(XAUTH)" \ + && xauth nlist "$(DISPLAY)" | sed -e 's/^..../ffff/' | xauth -f "$(XAUTH)" nmerge - \ + && xhost +local:docker + +docker-run: + docker run -td --privileged --net=host --ipc=host \ + --name="infinigen" \ + --gpus=all \ + --env NVIDIA_DISABLE_REQUIRE=1 \ + -e "BLENDER=/opt/infinigen/blender/blender" \ + -e "DISPLAY=$(DISPLAY)" \ + -e "QT_X11_NO_MITSHM=1" \ + -v "/tmp/.X11-unix:/tmp/.X11-unix:rw" \ + -v $(PWD)/worldgen/outputs:/opt/infinigen/worldgen/outputs \ + -e "XAUTHORITY=$(XAUTH)" \ + -e ROS_IP=127.0.0.1 \ + --cap-add=SYS_PTRACE \ + -v /etc/group:/etc/group:ro \ + "$(DOCKER_TAG)" /bin/bash \ + || docker run -td --privileged --net=host --ipc=host \ + --name="infinigen" \ + --device /dev/dri \ + -e "BLENDER=/opt/infinigen/blender/blender" \ + -e "DISPLAY=$(DISPLAY)" \ + -e "QT_X11_NO_MITSHM=1" \ + -v "/tmp/.X11-unix:/tmp/.X11-unix:rw" \ + -v $(PWD)/worldgen/outputs:/opt/infinigen/worldgen/outputs \ + -e "XAUTHORITY=$(XAUTH)" \ + -e ROS_IP=127.0.0.1 \ + --cap-add=SYS_PTRACE \ + -v /etc/group:/etc/group:ro \ + "$(DOCKER_TAG)" bash + + docker exec infinigen /bin/bash -c worldgen/tools/compile_opengl.sh + +docker-run-no-opengl: + echo "Launching Docker image without OpenGL ground truth" + docker run -td --rm --privileged --net=host --ipc=host \ + --name="infinigen" \ + --gpus=all \ + --env NVIDIA_DISABLE_REQUIRE=1 \ + -e "BLENDER=/opt/infinigen/blender/blender" \ + -v $(PWD)/worldgen/outputs:/opt/infinigen/worldgen/outputs \ + "$(DOCKER_TAG)" /bin/bash + +docker-run-no-gpu: + echo "Launching Docker image without GPU passthrough" + docker run -td --privileged --net=host --ipc=host \ + --name="infinigen" \ + -e "BLENDER=/opt/infinigen/blender/blender" \ + -e "DISPLAY=$(DISPLAY)" \ + -e "QT_X11_NO_MITSHM=1" \ + -v "/tmp/.X11-unix:/tmp/.X11-unix:rw" \ + -v $(PWD)/worldgen/outputs:/opt/infinigen/worldgen/outputs \ + -e "XAUTHORITY=$(XAUTH)" \ + -e ROS_IP=127.0.0.1 \ + --cap-add=SYS_PTRACE \ + -v /etc/group:/etc/group:ro \ + "$(DOCKER_TAG)" /bin/bash \ + + docker exec infinigen /bin/bash -c worldgen/tools/compile_opengl.sh + +docker-run-no-gpu-opengl: + echo "Launching Docker image without GPU passthrough or OpenGL" + docker run -td --rm --privileged --net=host --ipc=host \ + --name="infinigen" \ + -e "BLENDER=/opt/infinigen/blender/blender" \ + -v $(PWD)/worldgen/outputs:/opt/infinigen/worldgen/outputs \ + "$(DOCKER_TAG)" /bin/bash + \ No newline at end of file diff --git a/docs/Installation.md b/docs/Installation.md index 79e350dbd..ddfa57ea5 100644 --- a/docs/Installation.md +++ b/docs/Installation.md @@ -42,6 +42,22 @@ export BLENDER="/PATH/TO/infinigen/Blender.app/Contents/MacOS/Blender" **Docker on Linux** +In `/infinigen/` +``` +make docker-build +make docker-setup +make docker-run +``` +To enable CUDA compilation, use `make docker-build-cuda` instead of `make docker-build` + +To run without GPU passthrough use `make docker-run-no-gpu` +To run without OpenGL ground truth use `docker-run-no-opengl` +To run without either, use `docker-run-no-gpu-opengl` + +Note: `make docker-setup` can be skipped if not using OpenGL. + +Use `exit` to exit the container and `docker exec -it infinigen bash` to re-enter the container as needed. Remember to `conda activate infinigen` before running scenes. + **Docker on Windows** Install [WSL2](https://infinigen.org/docs/installation/intro#setup-for-windows) and [Docker Desktop](https://www.docker.com/products/docker-desktop/), with "Use the WSL 2 based engine..." enabled in settings. Keep the Docker Desktop application open while running containers. Then follow instructions as above. diff --git a/install.sh b/install.sh index 7e52a560f..14c740e4c 100755 --- a/install.sh +++ b/install.sh @@ -116,5 +116,5 @@ rm -rf build cd - if [ "$1" = "opengl" ]; then - + bash ./worldgen/tools/compile_opengl.sh fi diff --git a/worldgen/tools/compile_opengl.sh b/worldgen/tools/compile_opengl.sh new file mode 100644 index 000000000..02d60f1c2 --- /dev/null +++ b/worldgen/tools/compile_opengl.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# Compile process_mesh (i.e. OpenGL-based ground truth) +cd ./process_mesh +cmake -S . -Bbuild -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_BUILD_TYPE=Release +cmake --build build --target all +./build/process_mesh -in x -out x --height 100 --width 10 --frame 0 +if [ $? -eq 174 ]; then + echo "OpenGL/EGL ground truth is working." +else + echo "WARNING: OpenGL/EGL is not supported on this machine. If you are running from a cluster head-node, this is likely not an issue." +fi +cd -