google-ai-edge / mediapipe

Cross-platform, customizable ML solutions for live and streaming media.
https://ai.google.dev/edge/mediapipe
Apache License 2.0
27.79k stars 5.18k forks source link

How to select which GPU to run on? #2472

Closed HarryWindsor closed 3 years ago

HarryWindsor commented 3 years ago

I successfully compiled MediaPipe for CUDA. I use a multi GPU setup and want to run the MediaPipe model on a specific GPU, but MediaPipe always just picks the first GPU. The CUDA_VISIBLE_DEVICES=1 flag I normally use did not work.

How can I select the GPU MediaPipe should run on`

sgowroji commented 3 years ago

Hi @HarryWindsor, Did you get a chance to go through our GPU documentation. Could you please provide more details like which solution and what is the error you are seeing with the above. Can you point us to the exact links which your referring the above. Thanks!

HarryWindsor commented 3 years ago

I am using the face mesh solution and compiled the code with CUDA enabled and face_detection/face_detection_short_range_gpu, face_detection/face_detection_full_range_gpu, face_landmark/face_landmark_front_gpu.

When I run the example from MediaPipe Face Mesh Python Solution API (I don't think another solution behaves differently) I get this output and can validate that the code used the GPU and works, but it always uses GPU 0.

WARNING: Logging before InitGoogleLogging() is written to STDERR
I20210827 11:27:23.775424 347818 gl_context_egl.cc:163] Successfully initialized EGL. Major : 1 Minor: 5
I20210827 11:27:23.809967 347921 gl_context.cc:331] GL version: 3.2 (OpenGL ES 3.2 NVIDIA 470.57.02)
I20210827 11:27:23.810029 347818 gl_context_egl.cc:163] Successfully initialized EGL. Major : 1 Minor: 5
I20210827 11:27:23.833227 347922 gl_context.cc:331] GL version: 3.2 (OpenGL ES 3.2 NVIDIA 470.57.02)
INFO: Created TensorFlow Lite delegate for GPU.

I would prefer to use GPU 1 instead of GPU 0.

mcclanahoochie commented 3 years ago

Selecting a GPU involves choosing the correct 'EGLDisplay', currently in MediaPipe this is done here. Notice the eglGetDisplay(), which defaults to device 0.

You will need to replace eglGetDisplay with something like eglGetPlatformDisplayEXT, then have that select device 1.

An example using eglGetPlatformDisplayEXT can be found here in the #else part.

There are not currently any plans to integrate this into MediaPipe [yet], but it can be considered in the future.

google-ml-butler[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you.

google-ml-butler[bot] commented 3 years ago

Closing as stale. Please reopen if you'd like to work on this further.