DLR-RM / AugmentedAutoencoder

Official Code: Implicit 3D Orientation Learning for 6D Object Detection from RGB Images
MIT License
338 stars 97 forks source link

enable EGL backend #42

Closed wangg12 closed 5 years ago

wangg12 commented 5 years ago

reference: https://github.com/mmatl/pyrender/blob/master/pyrender/platforms.py

MartinSmeyer commented 5 years ago

glInitBindlessTextureNV() returns False when running test_egl_meshrenderer_phong.py, i.e. the egl context in my environment. Also I get a memory leak that quickly kills the ae_train script at line 126 queue.start(sess) even when using glfw. I'm not sure why, yet.

wangg12 commented 5 years ago

Could you check this. This is the only problem for me to get egl work.

MartinSmeyer commented 5 years ago

thanks! After changing egl.py, the egl rendering was working with a connected display. However, headless rendering still gave eglinitialize errors . Then, I changed to a newer OpenSuse Version (42.3->15.1) and hardware accelerated headless rendering just worked, independent of linking against libGL.so or libOpenGL.so. :-) I checked with pyrender and our meshrenderer, both works in display and headless mode, so I will make egl the default. Could you please check whether you also get a memory leak when running ae_train with your added code? It does not depend on the context.. After pinning it down, I will merge it.

wangg12 commented 5 years ago

@MartinSmeyer Now I can train with the egl backend. What do you mean by memory leak? GPU memory leak or RAM memory leak?

MartinSmeyer commented 5 years ago

The RAM was filling up. The problem was the python2 -> python3 port. I was running the code in python2 in debug mode, i.e.

ae_train test/me -d

You changed all xrange to range which in python2 does an explicit memory allocation.

for i in range(ae.global_step.eval(), num_iter):

In debug mode only, num_iter was set to

np.iinfo(np.int32).max 
Out[2]: 2147483647

Setting num_iter in debug mode to a lower number solved the problem.

MartinSmeyer commented 5 years ago

Concerning the PyOpenGL hacks, I had to do this to make headless rendering work in osl42 but not in osl15. Thanks again for the pointer.

wangg12 commented 5 years ago

Sorry, I didn't test python2. Glad that you have catched the problem. BTW, what are "osl42" and "osl15"?

MartinSmeyer commented 5 years ago

OpenSuse42 and the successor OpenSuse15 are both linux distributions. There might have been some updates in the libraries.

wangg12 commented 5 years ago

So the hack of egl.py is not needed in OpenSuse15? I had to hack it for both Ubuntu 14.04 and 16.04.

MartinSmeyer commented 5 years ago

Yes, it seems like. Looking at the referenced

/usr/lib/python2.7/site-packages/OpenGL/platform/egl.py
def GL(self):
    try:
        return ctypesloader.loadLibrary(
            ctypes.cdll,
            'GL', 
            mode=ctypes.RTLD_GLOBAL 
        )

It still references GL. Might be that OpenGL.so is loaded elsewhere?

MartinSmeyer commented 5 years ago

hmm, if this is an issue for both Ubuntu 14.04 and 16.04. I will make EGL a prominent option but not default. We can not assume every user to be allowed / know how to change PyOpenGL. Hope you are fine with that. A simple

export PYOPENGL_PLATFORM='egl'

will switch to egl mode.