From 5e220d43fed7397d66c40c04e7c2e43a0d439d8a Mon Sep 17 00:00:00 2001 From: Saran Tunyasuvunakool Date: Mon, 19 Jun 2023 05:36:25 -0700 Subject: [PATCH] Add missing Nvidia ICD file for glvnd to enable GPU rendering on Colab. PiperOrigin-RevId: 541615331 Change-Id: Iff85772bffb245330898e9c2a511d77896bac0cf --- python/LQR.ipynb | 21 ++++++++++++++++++--- python/tutorial.ipynb | 18 +++++++++++++++++- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/python/LQR.ipynb b/python/LQR.ipynb index 497dbb0b..75a93cc3 100644 --- a/python/LQR.ipynb +++ b/python/LQR.ipynb @@ -69,12 +69,28 @@ "from google.colab import files\n", "\n", "import distutils.util\n", + "import os\n", "import subprocess\n", "if subprocess.run('nvidia-smi').returncode:\n", " raise RuntimeError(\n", " 'Cannot communicate with GPU. '\n", " 'Make sure you are using a GPU Colab runtime. '\n", - " 'Go to the Runtime menu and select Choose runtime type.')", + " 'Go to the Runtime menu and select Choose runtime type.')\n", + "\n", + "# Add an ICD config so that glvnd can pick up the Nvidia EGL driver.\n", + "# This is usually installed as part of an Nvidia driver package, but the Colab\n", + "# kernel doesn't install its driver via APT, and as a result the ICD is missing.\n", + "# (https://github.com/NVIDIA/libglvnd/blob/master/src/EGL/icd_enumeration.md)\n", + "NVIDIA_ICD_CONFIG_PATH = '/usr/share/glvnd/egl_vendor.d/10_nvidia.json'\n", + "if not os.path.exists(NVIDIA_ICD_CONFIG_PATH):\n", + " with open(NVIDIA_ICD_CONFIG_PATH, 'w') as f:\n", + " f.write(\"\"\"{\n", + " \"file_format_version\" : \"1.0.0\",\n", + " \"ICD\" : {\n", + " \"library_path\" : \"libEGL_nvidia.so.0\"\n", + " }\n", + "}\n", + "\"\"\")\n", "\n", "# Configure MuJoCo to use the EGL rendering backend (requires GPU)\n", "print('Setting environment variable to use GPU rendering:')\n", @@ -931,8 +947,7 @@ "accelerator": "GPU", "colab": { "collapsed_sections": [ - "LBAvTJ0xHKy7", - "zcXO67XM5-Kc" + "LBAvTJ0xHKy7" ], "last_runtime": { "build_target": "", diff --git a/python/tutorial.ipynb b/python/tutorial.ipynb index ba301d2c..bc72ec6c 100644 --- a/python/tutorial.ipynb +++ b/python/tutorial.ipynb @@ -77,12 +77,28 @@ "from google.colab import files\n", "\n", "import distutils.util\n", + "import os\n", "import subprocess\n", "if subprocess.run('nvidia-smi').returncode:\n", " raise RuntimeError(\n", " 'Cannot communicate with GPU. '\n", " 'Make sure you are using a GPU Colab runtime. '\n", - " 'Go to the Runtime menu and select Choose runtime type.')", + " 'Go to the Runtime menu and select Choose runtime type.')\n", + "\n", + "# Add an ICD config so that glvnd can pick up the Nvidia EGL driver.\n", + "# This is usually installed as part of an Nvidia driver package, but the Colab\n", + "# kernel doesn't install its driver via APT, and as a result the ICD is missing.\n", + "# (https://github.com/NVIDIA/libglvnd/blob/master/src/EGL/icd_enumeration.md)\n", + "NVIDIA_ICD_CONFIG_PATH = '/usr/share/glvnd/egl_vendor.d/10_nvidia.json'\n", + "if not os.path.exists(NVIDIA_ICD_CONFIG_PATH):\n", + " with open(NVIDIA_ICD_CONFIG_PATH, 'w') as f:\n", + " f.write(\"\"\"{\n", + " \"file_format_version\" : \"1.0.0\",\n", + " \"ICD\" : {\n", + " \"library_path\" : \"libEGL_nvidia.so.0\"\n", + " }\n", + "}\n", + "\"\"\")\n", "\n", "# Configure MuJoCo to use the EGL rendering backend (requires GPU)\n", "print('Setting environment variable to use GPU rendering:')\n",