pyrender
                                
                                 pyrender copied to clipboard
                                
                                    pyrender copied to clipboard
                            
                            
                            
                        Can't select GPU for EGL headless rendering
TL;DR - how can I select the GPU that the EGL headless rendering runs on? I want to use /dev/nvidia2 but it seems only /dev/nvidia0 is supported.
===
I have two machines in the cloud that are Docker containers of the same image (Ubuntu). When I run the code from the EGL offscreen rendering colab notebook as a Python script, one renders the bottle well, while the other gives me the error below. The working machine has its GPU mounted on /dev/nvidia0 while on the faulty machine it is on /dev/nvidia2.
It seems that egl_display = egl.eglGetDisplay(egl.EGL_DEFAULT_DISPLAY) tries picking on /dev/nvidia0 and fails if it is not available. Since I can't control where will the GPU get mounted on my machine, is there a way to make OpenGL/EGL pick the other device? I tried multiple solutions found around the web, from different environment variables to creating a symlink, but to no avail.
The error:
Traceback (most recent call last):
  File "colab", line 30, in <module>
    r = pyrender.OffscreenRenderer(640, 480)
  File "/miniconda/envs/foo/lib/python3.6/site-packages/pyrender/offscreen.py", line 31, in __init__
    self._create()
  File "/miniconda/envs/foo/lib/python3.6/site-packages/pyrender/offscreen.py", line 134, in _create
    self._platform.init_context()
  File "/miniconda/envs/foo/lib/python3.6/site-packages/pyrender/platforms/egl.py", line 177, in init_context
    assert eglInitialize(self._egl_display, major, minor)
  File "/miniconda/envs/foo/lib/python3.6/site-packages/OpenGL/platform/baseplatform.py", line 402, in __call__
    return self( *args, **named )
  File "/miniconda/envs/foo/lib/python3.6/site-packages/OpenGL/error.py", line 232, in glCheckError
    baseOperation = baseOperation,
OpenGL.error.GLError: GLError(
	err = 12290,
	baseOperation = eglInitialize,
	cArguments = (
		<OpenGL._opaque.EGLDisplay_pointer object at 0x7f7c9f107400>,
		c_long(0),
		c_long(0),
	),
	result = 0
)
Does it make sense that if my nvidia device is /dev/nvidia1 or /dev/nvidia2 then it doesn't get picked up as the egl.EGL_DEFAULT_DISPLAY? Is there an environment variable I should set for this case? (Like I'm setting PYOPENGL_PLATFORM=egl before import pyrender?)
@guy4261 Hi, I'm meeting the same issue. Have you resolve it? On my machine I indeed have /dev/nvidia0 but still get that error. Are you sure your two machines have the only difference in that /dev/nvidia id?
@Guptajakala sorry - 1. I didn't solve this, 2. I do believe that on my machine it's the /dev/nvidiaN issue, perhaps you are experiencing something else I can't help with :(
I submitted a PR (https://github.com/mmatl/pyrender/pull/60) a couple months ago that does this.
Just set the environment variable EGL_DEVICE_ID e.g.
export EGL_DEVICE_ID=1
python run.py
Great @keunhong !!! Thanks!!!
Does this mean I should for now build from master rather then install with pip?
@guy4261 I dont think you need. Just run export EGL_DEVICE_ID=1 before you run your python file. However, it still doesn't work in my case, maybe my server has some wierd things. Please let me know if it works for you.
Great @keunhong !!! Thanks!!! Does this mean I should for now build from
masterrather then install withpip?
Looks like the commit should be in 0.1.33 so shouldn't be necessary.
I also had the following issue:
OpenGL.error.GLError: GLError(	err = 12290,
It was related to incompatible versions of pyrender and PyOpenGL.
However, is not working for me using headless rendering with EGL. I now have the following error
@oarriaga What was the incompatibility issue and what was eventually the compatible versions that you used?
I submitted a PR (#60) a couple months ago that does this.
Just set the environment variable
EGL_DEVICE_IDe.g.export EGL_DEVICE_ID=1 python run.py
How do I do this on Windows 11?