openai / mujoco-py

MuJoCo is a physics engine for detailed, efficient rigid body simulations with contacts. mujoco-py allows using MuJoCo from Python 3.
Other
2.87k stars 814 forks source link

GPU compilation broken: conflicting types for ‘PFNGLFRAGMENTLIGHTFVSGIXPROC’ #383

Open hartikainen opened 5 years ago

hartikainen commented 5 years ago

Describe the bug I'm trying to install and run mujoco-py with GPU. The compilation fails with the following error:

Compiling /mujoco_py/mujoco_py/cymj.pyx because it changed.
[1/1] Cythonizing /mujoco_py/mujoco_py/cymj.pyx
running build_ext
building 'mujoco_py.cymj' extension
creating /mujoco_py/mujoco_py/generated/_pyxbld_2.0.2.0_36_linuxgpuextensionbuilder
creating /mujoco_py/mujoco_py/generated/_pyxbld_2.0.2.0_36_linuxgpuextensionbuilder/temp.linux-x86_64-3.6
creating /mujoco_py/mujoco_py/generated/_pyxbld_2.0.2.0_36_linuxgpuextensionbuilder/temp.linux-x86_64-3.6/mujoco_py
creating /mujoco_py/mujoco_py/generated/_pyxbld_2.0.2.0_36_linuxgpuextensionbuilder/temp.linux-x86_64-3.6/mujoco_py/mujoco_py
creating /mujoco_py/mujoco_py/generated/_pyxbld_2.0.2.0_36_linuxgpuextensionbuilder/temp.linux-x86_64-3.6/mujoco_py/mujoco_py/gl
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -Imujoco_py -I/mujoco_py/mujoco_py -I/root/.mujoco/mujoco200/include -I/env/lib/python3.6/site-packages/numpy/core/include -I/mujoco_py/mujoco_py/vendor/egl -I/usr/include/python3.6m -I/env/include/python3.6m -c /mujoco_py/mujoco_py/cymj.c -o /mujoco_py/mujoco_py/generated/_pyxbld_2.0.2.0_36_linuxgpuextensionbuilder/temp.linux-x86_64-3.6/mujoco_py/mujoco_py/cymj.o -fopenmp -w
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -Imujoco_py -I/mujoco_py/mujoco_py -I/root/.mujoco/mujoco200/include -I/env/lib/python3.6/site-packages/numpy/core/include -I/mujoco_py/mujoco_py/vendor/egl -I/usr/include/python3.6m -I/env/include/python3.6m -c /mujoco_py/mujoco_py/gl/eglshim.c -o /mujoco_py/mujoco_py/generated/_pyxbld_2.0.2.0_36_linuxgpuextensionbuilder/temp.linux-x86_64-3.6/mujoco_py/mujoco_py/gl/eglshim.o -fopenmp -w
In file included from /mujoco_py/mujoco_py/gl/eglshim.c:7:0:
/usr/include/GL/glext.h:12066:25: error: conflicting types for ‘PFNGLFRAGMENTLIGHTFVSGIXPROC’
 typedef void (APIENTRYP PFNGLFRAGMENTLIGHTFVSGIXPROC) (GLenum light, GLenum pname, const GLfloat *params);
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /mujoco_py/mujoco_py/gl/eglshim.c:4:0:
/usr/include/GL/glew.h:16092:28: note: previous declaration of ‘PFNGLFRAGMENTLIGHTFVSGIXPROC’ was here
 typedef void (GLAPIENTRY * PFNGLFRAGMENTLIGHTFVSGIXPROC) (GLenum light, GLenum pname, GLfloat* params);
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /mujoco_py/mujoco_py/gl/eglshim.c:7:0:
/usr/include/GL/glext.h:12068:25: error: conflicting types for ‘PFNGLFRAGMENTLIGHTIVSGIXPROC’
 typedef void (APIENTRYP PFNGLFRAGMENTLIGHTIVSGIXPROC) (GLenum light, GLenum pname, const GLint *params);
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /mujoco_py/mujoco_py/gl/eglshim.c:4:0:
/usr/include/GL/glew.h:16094:28: note: previous declaration of ‘PFNGLFRAGMENTLIGHTIVSGIXPROC’ was here
 typedef void (GLAPIENTRY * PFNGLFRAGMENTLIGHTIVSGIXPROC) (GLenum light, GLenum pname, GLint* params);
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /mujoco_py/mujoco_py/gl/eglshim.c:7:0:
/usr/include/GL/glext.h:12070:25: error: conflicting types for ‘PFNGLFRAGMENTLIGHTMODELFVSGIXPROC’
 typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELFVSGIXPROC) (GLenum pname, const GLfloat *params);
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /mujoco_py/mujoco_py/gl/eglshim.c:4:0:
/usr/include/GL/glew.h:16088:28: note: previous declaration of ‘PFNGLFRAGMENTLIGHTMODELFVSGIXPROC’ was here
 typedef void (GLAPIENTRY * PFNGLFRAGMENTLIGHTMODELFVSGIXPROC) (GLenum pname, GLfloat* params);
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /mujoco_py/mujoco_py/gl/eglshim.c:7:0:
/usr/include/GL/glext.h:12072:25: error: conflicting types for ‘PFNGLFRAGMENTLIGHTMODELIVSGIXPROC’
 typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELIVSGIXPROC) (GLenum pname, const GLint *params);
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /mujoco_py/mujoco_py/gl/eglshim.c:4:0:
/usr/include/GL/glew.h:16090:28: note: previous declaration of ‘PFNGLFRAGMENTLIGHTMODELIVSGIXPROC’ was here
 typedef void (GLAPIENTRY * PFNGLFRAGMENTLIGHTMODELIVSGIXPROC) (GLenum pname, GLint* params);
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /mujoco_py/mujoco_py/gl/eglshim.c:7:0:
/usr/include/GL/glext.h:12079:25: error: conflicting types for ‘PFNGLGETFRAGMENTMATERIALFVSGIXPROC’
 typedef void (APIENTRYP PFNGLGETFRAGMENTMATERIALFVSGIXPROC) (GLenum face, GLenum pname, GLfloat *params);
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /mujoco_py/mujoco_py/gl/eglshim.c:4:0:
/usr/include/GL/glew.h:16101:28: note: previous declaration of ‘PFNGLGETFRAGMENTMATERIALFVSGIXPROC’ was here
 typedef void (GLAPIENTRY * PFNGLGETFRAGMENTMATERIALFVSGIXPROC) (GLenum face, GLenum pname, const GLfloat* data);
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /mujoco_py/mujoco_py/gl/eglshim.c:7:0:
/usr/include/GL/glext.h:12080:25: error: conflicting types for ‘PFNGLGETFRAGMENTMATERIALIVSGIXPROC’
 typedef void (APIENTRYP PFNGLGETFRAGMENTMATERIALIVSGIXPROC) (GLenum face, GLenum pname, GLint *params);
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /mujoco_py/mujoco_py/gl/eglshim.c:4:0:
/usr/include/GL/glew.h:16102:28: note: previous declaration of ‘PFNGLGETFRAGMENTMATERIALIVSGIXPROC’ was here
 typedef void (GLAPIENTRY * PFNGLGETFRAGMENTMATERIALIVSGIXPROC) (GLenum face, GLenum pname, const GLint* data);
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Traceback (most recent call last):
  File "/usr/lib/python3.6/distutils/unixccompiler.py", line 118, in _compile
    extra_postargs)
  File "/usr/lib/python3.6/distutils/ccompiler.py", line 909, in spawn
    spawn(cmd, dry_run=self.dry_run)
  File "/usr/lib/python3.6/distutils/spawn.py", line 36, in spawn
    _spawn_posix(cmd, search_path, dry_run=dry_run)
  File "/usr/lib/python3.6/distutils/spawn.py", line 159, in _spawn_posix
    % (cmd, exit_status))
distutils.errors.DistutilsExecError: command 'x86_64-linux-gnu-gcc' failed with exit status 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/mujoco_py/mujoco_py/__init__.py", line 3, in <module>
    from mujoco_py.builder import cymj, ignore_mujoco_warnings, functions, MujocoException
  File "/mujoco_py/mujoco_py/builder.py", line 503, in <module>
    cymj = load_cython_ext(mujoco_path)
  File "/mujoco_py/mujoco_py/builder.py", line 105, in load_cython_ext
    cext_so_path = builder.build()
  File "/mujoco_py/mujoco_py/builder.py", line 220, in build
    built_so_file_path = self._build_impl()
  File "/mujoco_py/mujoco_py/builder.py", line 290, in _build_impl
    so_file_path = super()._build_impl()
  File "/mujoco_py/mujoco_py/builder.py", line 243, in _build_impl
    dist.run_commands()
  File "/usr/lib/python3.6/distutils/dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/env/lib/python3.6/site-packages/Cython/Distutils/old_build_ext.py", line 186, in run
    _build_ext.build_ext.run(self)
  File "/usr/lib/python3.6/distutils/command/build_ext.py", line 339, in run
    self.build_extensions()
  File "/mujoco_py/mujoco_py/builder.py", line 143, in build_extensions
    build_ext.build_extensions(self)
  File "/env/lib/python3.6/site-packages/Cython/Distutils/old_build_ext.py", line 194, in build_extensions
    self.build_extension(ext)
  File "/usr/lib/python3.6/distutils/command/build_ext.py", line 533, in build_extension
    depends=ext.depends)
  File "/usr/lib/python3.6/distutils/ccompiler.py", line 574, in compile
    self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
  File "/usr/lib/python3.6/distutils/unixccompiler.py", line 120, in _compile
    raise CompileError(msg)
distutils.errors.CompileError: command 'x86_64-linux-gnu-gcc' failed with exit status 1

To Reproduce Create a new Dockerfile.broken with the following diff from the existing Dockerfile. This is required since the current Dockerfile doesn't actually compile with GPU (see #237). (Unrelated note: the build fails earlier with different error if we don't change the base image).

diff -u /mujoco-py/Dockerfile /mujoco-py/Dockerfile.broken
--- /mujoco-py/Dockerfile       2019-04-08 13:32:35.556265332 -0700
+++ /mujoco-py/Dockerfile.broken    2019-04-08 14:06:24.412613077 -0700
@@ -2,7 +2,7 @@
 # on hosts with GPUs.
 # The image below is a pinned version of nvidia/cuda:9.1-cudnn7-devel-ubuntu16.04 (from Jan 2018)
 # If updating the base image, be sure to test on GPU since it has broken in the past.
-FROM nvidia/cuda@sha256:4df157f2afde1cb6077a191104ab134ed4b2fd62927f27b69d788e8e79a45fa1
+FROM nvidia/cuda:10.0-base-ubuntu18.04

 RUN apt-get update -q \
     && DEBIAN_FRONTEND=noninteractive apt-get install -y \
@@ -52,6 +52,10 @@
 # Workaround for https://bugs.launchpad.net/ubuntu/+source/nvidia-graphics-drivers-375/+bug/1674677
 COPY ./vendor/10_nvidia.json /usr/share/glvnd/egl_vendor.d/10_nvidia.json

+# This is a hack required to make mujoco-py compile in gpu mode
+RUN mkdir -p /usr/lib/nvidia-000
+ENV LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:/usr/lib/nvidia-000
+
 WORKDIR /mujoco_py
 # Copy over just requirements.txt at first. That way, the Docker cache doesn't
 # expire until we actually change the requirements.

Diff finished.  Mon Apr  8 14:11:10 2019

Then build the image, run the container and import mujoco py to start the compilation:

$ docker build -t mujoco-py-broken -f ./Dockerfile.broken .
$ nvidia-docker run --rm -it mujoco-py-broken python -c "import mujoco_py"

Expected behavior Build succeeds.

Error Messages See above.

Desktop (please complete the following information):

Environment

Additional context n/a

hartikainen commented 5 years ago

I've narrowed down the issue to be the libegl1-mesa-dev apt package (or possibly some of its dependency). I have a working docker image which breaks if I do apt-get install libglew-dev. I still don't know how to downgrade it back to the working version though.

Here's the diff of apt list --installed for the working (18.2.2) vs. broken (18.2.8) installation:

-libegl1-mesa-dev/bionic-updates,now 18.2.8-0ubuntu0~18.04.2 amd64 [installed]
+libegl1-mesa-dev/bionic-updates,now 18.2.2-0ubuntu1~18.04.2 amd64 [installed]
hou-yz commented 5 years ago

same problem here

hou-yz commented 5 years ago

check this issue for fixes: https://github.com/mupen64plus/mupen64plus-video-z64/pull/16

qxcv commented 5 years ago

+1 for fix. In mujoco-py, I found it sufficient to simply remove #include <GL/glext.h> from mujoco_py/gl/eglshim.c.

Kelly510 commented 3 years ago

+1 for fix. In mujoco-py, I found it sufficient to simply remove #include <GL/glext.h> from mujoco_py/gl/eglshim.c.

The eglshim.c file doesn't include <GL/glext.h> but I still have the problem. Does anyone know what headers else should be removed?

fokx commented 3 years ago

The error info indicates conflicting types are defined both in /usr/include/GL/glew.h and /usr/include/GL/glext.h. So instead of

remove #include <GL/glext.h> from mujoco_py/gl/eglshim.c

, which could introduce unknown type name errors, it's preferred to comment out some lines in /usr/include/GL/glext.h. So L12306 to L12320 should be like:

//typedef void (APIENTRYP PFNGLFRAGMENTLIGHTFVSGIXPROC) (GLenum light, GLenum pname, const GLfloat *params);
typedef void (APIENTRYP PFNGLFRAGMENTLIGHTISGIXPROC) (GLenum light, GLenum pname, GLint param);
//typedef void (APIENTRYP PFNGLFRAGMENTLIGHTIVSGIXPROC) (GLenum light, GLenum pname, const GLint *params);
typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELFSGIXPROC) (GLenum pname, GLfloat param);
//typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELFVSGIXPROC) (GLenum pname, const GLfloat *params);
typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELISGIXPROC) (GLenum pname, GLint param);
//typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELIVSGIXPROC) (GLenum pname, const GLint *params);
typedef void (APIENTRYP PFNGLFRAGMENTMATERIALFSGIXPROC) (GLenum face, GLenum pname, GLfloat param);
typedef void (APIENTRYP PFNGLFRAGMENTMATERIALFVSGIXPROC) (GLenum face, GLenum pname, const GLfloat *params);
typedef void (APIENTRYP PFNGLFRAGMENTMATERIALISGIXPROC) (GLenum face, GLenum pname, GLint param);
typedef void (APIENTRYP PFNGLFRAGMENTMATERIALIVSGIXPROC) (GLenum face, GLenum pname, const GLint *params);
typedef void (APIENTRYP PFNGLGETFRAGMENTLIGHTFVSGIXPROC) (GLenum light, GLenum pname, GLfloat *params);
typedef void (APIENTRYP PFNGLGETFRAGMENTLIGHTIVSGIXPROC) (GLenum light, GLenum pname, GLint *params);
//typedef void (APIENTRYP PFNGLGETFRAGMENTMATERIALFVSGIXPROC) (GLenum face, GLenum pname, GLfloat *params);
//typedef void (APIENTRYP PFNGLGETFRAGMENTMATERIALIVSGIXPROC) (GLenum face, GLenum pname, GLint *params);