Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples using tf-lite with gpu (face_detection_gpu) does not compile on jetson nano #305

Closed
ksachdeva opened this issue Dec 8, 2019 · 11 comments
Assignees

Comments

@ksachdeva
Copy link

The CPU example is working fine on jetson nano

 bazel build -c opt --define MEDIAPIPE_DISABLE_GPU=1 mediapipe/examples/desktop/face_detection:face_detection_cpu

However, when I try to compile the gpu version of above i.e

bazel build -c opt --copt -DMESA_EGL_NO_X11_HEADERS mediapipe/examples/desktop/face_detection:face_detection_gpu

I get lot of compilation errors related to EGL from tf-lite. Here is one trace of it.

In file included from external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/egl_context.h:21:0,
                 from external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/egl_context.cc:16:
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/egl_context.cc: In function 'int tflite::gpu::gl::{anonymous}::GetConfig(EGLDisplay, const EGLint*, void**)':
external/org_tensorflow/tensorflow/lite/delegates/gpu/common/status.h:68:18: error: request for member 'ok' in 'status2', which is of non-class type 'const int'
     if (!status2.ok()) return status2; \
                  ^
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/egl_context.cc:33:3: note: in expansion of macro 'RETURN_IF_ERROR'
   RETURN_IF_ERROR(GetOpenGlErrors());
   ^~~~~~~~~~~~~~~
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/egl_context.cc:35:69: error: cannot convert 'tflite::gpu::Status' to 'int' in return
     return InternalError("No EGL error, but eglChooseConfig failed.");
                                                                     ^
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/egl_context.cc:37:19: error: cannot convert 'tflite::gpu::Status' to 'int' in return
   return OkStatus();
                   ^
In file included from external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/egl_context.h:21:0,
                 from external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/egl_context.cc:16:
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/egl_context.cc: In function 'int tflite::gpu::gl::{anonymous}::CreateContext(EGLDisplay, EGLContext, EGLConfig, tflite::gpu::gl::EglContext*)':
external/org_tensorflow/tensorflow/lite/delegates/gpu/common/status.h:68:18: error: request for member 'ok' in 'status2', which is of non-class type 'const int'
     if (!status2.ok()) return status2; \
                  ^
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/egl_context.cc:50:3: note: in expansion of macro 'RETURN_IF_ERROR'
   RETURN_IF_ERROR(GetOpenGlErrors());
   ^~~~~~~~~~~~~~~
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/egl_context.cc:52:70: error: cannot convert 'tflite::gpu::Status' to 'int' in return
     return InternalError("No EGL error, but eglCreateContext failed.");
                                                                      ^
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/egl_context.cc:55:19: error: cannot convert 'tflite::gpu::Status' to 'int' in return
   return OkStatus();
                   ^
In file included from external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/egl_context.h:21:0,
                 from external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/egl_context.cc:16:
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/egl_context.cc: In member function 'int tflite::gpu::gl::EglContext::MakeCurrent(EGLSurface, EGLSurface)':
external/org_tensorflow/tensorflow/lite/delegates/gpu/common/status.h:68:18: error: request for member 'ok' in 'status2', which is of non-class type 'const int'
     if (!status2.ok()) return status2; \
                  ^
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/egl_context.cc:98:3: note: in expansion of macro 'RETURN_IF_ERROR'
   RETURN_IF_ERROR(GetOpenGlErrors());
   ^~~~~~~~~~~~~~~
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/egl_context.cc:100:68: error: cannot convert 'tflite::gpu::Status' to 'int' in return
     return InternalError("No EGL error, but eglMakeCurrent failed.");
                                                                    ^
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/egl_context.cc:102:19: error: cannot convert 'tflite::gpu::Status' to 'int' in return
   return OkStatus();
                   ^
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/egl_context.cc: In function 'int tflite::gpu::gl::CreateConfiglessContext(EGLDisplay, EGLContext, tflite::gpu::gl::EglContext*)':
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/egl_context.cc:112:70: error: cannot convert 'tflite::gpu::Status' to 'int' in return
     return UnavailableError("EGL_KHR_no_config_context not supported");
                                                                      ^
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/egl_context.cc: In function 'int tflite::gpu::gl::CreateSurfacelessContext(EGLDisplay, EGLContext, tflite::gpu::gl::EglContext*)':
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/egl_context.cc:120:67: error: cannot convert 'tflite::gpu::Status' to 'int' in return
     return UnavailableError("EGL_KHR_create_context not supported");
                                                                   ^
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/egl_context.cc:123:72: error: cannot convert 'tflite::gpu::Status' to 'int' in return
     return UnavailableError("EGL_KHR_surfaceless_context not supported");
                                                                        ^
In file included from external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/egl_context.h:21:0,
                 from external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/egl_context.cc:16:
external/org_tensorflow/tensorflow/lite/delegates/gpu/common/status.h:68:18: error: request for member 'ok' in 'status2', which is of non-class type 'const int'
     if (!status2.ok()) return status2; \
                  ^
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/egl_context.cc:128:3: note: in expansion of macro 'RETURN_IF_ERROR'
   RETURN_IF_ERROR(GetConfig(display, attributes, &config));
   ^~~~~~~~~~~~~~~
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/egl_context.cc: In function 'int tflite::gpu::gl::CreatePBufferContext(EGLDisplay, EGLContext, tflite::gpu::gl::EglContext*)':
external/org_tensorflow/tensorflow/lite/delegates/gpu/common/status.h:68:18: error: request for member 'ok' in 'status2', which is of non-class type 'const int'
     if (!status2.ok()) return status2; \
                  ^
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/egl_context.cc:146:3: note: in expansion of macro 'RETURN_IF_ERROR'
   RETURN_IF_ERROR(GetConfig(display, attributes, &config));
   ^~~~~~~~~~~~~~~
src/main/tools/linux-sandbox-pid1.cc:437: waitpid returned 2
src/main/tools/linux-sandbox-pid1.cc:457: child exited with code 1
src/main/tools/linux-sandbox.cc:204: child exited normally with exitcode 1
Target //mediapipe/examples/desktop/face_detection:face_detection_gpu failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 4.812s, Critical Path: 1.58s
INFO: 0 processes.
FAILED: Build did NOT complete successfully

@impjdi
Copy link
Contributor

impjdi commented Dec 9, 2019

Based on:

request for member 'ok' in 'status2', which is of non-class type 'const int'

I think you are still pulling in X11's Status. TFLite GPU's Status is a class, but that's not being recognized. Instead X11's Status (which is an int) is being handled. I don't know what Jetson Nano is, but Mesa is not officially supported from TFLite's point of view. Some plumbing will be required on your end. Can you make sure to block out X11 headers?

@mcclanahoochie
Copy link

Based on:

request for member 'ok' in 'status2', which is of non-class type 'const int'

I think you are still pulling in X11's Status. TFLite GPU's Status is a class, but that's not being recognized. Instead X11's Status (which is an int) is being handled. I don't know what Jetson Nano is, but Mesa is not officially supported from TFLite's point of view. Some plumbing will be required on your end. Can you make sure to block out X11 headers?

I agree with impjdi, ensuring X11 headers are disabled sounds like the first thing todo.

You can try compiling with EGL_NO_X11
bazel build -c opt --copt -DMESA_EGL_NO_X11_HEADERS --copt -DEGL_NO_X11 ...
and see if that helps (we have no jetson nano here to test with).

@ksachdeva
Copy link
Author

Thank @mcclanahoochie

Unfortunately adding EGL_NO_X11 did not help

@ksachdeva
Copy link
Author

ksachdeva commented Dec 11, 2019

@mcclanahoochie here is a thought -

bazel build -c opt --copt -DMESA_EGL_NO_X11_HEADERS mediapipe/examples/desktop/face_detection:face_detection_gpu

when executed on x86_64 Ubuntu 18.04 with nvidia 1080T at least compiles with out any issue

Jetson is arm64v8 machine that has Ubuntu 18.04 with nvidia embedded gpu. I have checked it has the same mesa egl etc (version wise) installed as on x86_64 machine.

Now I tried to trace the bazel build (I am a novice with bazel ... my first experience with bazel with this project itself) and it seems that usage of face_detection_gpu refers to mobile_calculators with then refers to gl etc.

Now since it arm64v8, by any chance bazel is thinking that it is android and hence including or not including some headers ?

Is there is a way to find out (any bazel command) which platform is detected ?

@jiuqiant jiuqiant removed their assignment Dec 11, 2019
@mcclanahoochie
Copy link

mcclanahoochie commented Dec 11, 2019

That is very strange...

I have an arm64 linux board (with non-nvidia gpu) running ubuntu 18.04 and can compile the gpu examples (after installing mesa libs)

I'm not sure what else would also be trying to define 'Status' ..

Also I don't think bazel is confusing ubuntu/android, but there are some extra bazel flags to make things verbose :
--show_progress --subcommands --verbose_failures

maybe those verbose logs can point to something

@ksachdeva
Copy link
Author

Thanks @mcclanahoochie Here is the log after adding the suggested options to cmd line

(cd /home/ml/.cache/bazel/_bazel_ml/f1cff6d9ddc54c5055773f45a79d1262/execroot/mediapipe && \
  exec env - \
    PATH=/home/ml/.nvm/versions/node/v8.16.2/bin:/home/ml/.pyenv/plugins/pyenv-virtualenv/shims:/home/ml/.pyenv/shims:/home/ml/.pyenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games \
    PWD=/proc/self/cwd \
  /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g0 -O2 '-D_FORTIFY_SOURCE=1' -DNDEBUG -ffunction-sections -fdata-sections '-std=c++0x' -MD -MF bazel-out/aarch64-opt/bin/external/flatbuffers/_objs/flatbuffers/code_generators.d '-frandom-seed=bazel-out/aarch64-opt/bin/external/flatbuffers/_objs/flatbuffers/code_generators.o' -iquote external/flatbuffers -iquote bazel-out/aarch64-opt/bin/external/flatbuffers -isystem external/flatbuffers/include -isystem bazel-out/aarch64-opt/bin/external/flatbuffers/include -Wno-sign-compare -Wno-unused-function -Wno-uninitialized -Wno-unused-result -Wno-comment -Wno-return-type -Wno-unused-local-typedefs -Wno-ignored-attributes -DMESA_EGL_NO_X11_HEADERS -DEGL_NO_X11 '-std=c++14' -Wno-implicit-fallthrough -fexceptions -fno-canonical-system-headers -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -c external/flatbuffers/src/code_generators.cpp -o bazel-out/aarch64-opt/bin/external/flatbuffers/_objs/flatbuffers/code_generators.o)
ERROR: /home/ml/.cache/bazel/_bazel_ml/f1cff6d9ddc54c5055773f45a79d1262/external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/BUILD:259:1: C++ compilation of rule '@org_tensorflow//tensorflow/lite/delegates/gpu/gl:gl_shader' failed (Exit 1) gcc failed: error executing command
  (cd /home/ml/.cache/bazel/_bazel_ml/f1cff6d9ddc54c5055773f45a79d1262/sandbox/linux-sandbox/737/execroot/mediapipe && \
  exec env - \
    PATH=/home/ml/.nvm/versions/node/v8.16.2/bin:/home/ml/.pyenv/plugins/pyenv-virtualenv/shims:/home/ml/.pyenv/shims:/home/ml/.pyenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games \
    PWD=/proc/self/cwd \
  /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g0 -O2 '-D_FORTIFY_SOURCE=1' -DNDEBUG -ffunction-sections -fdata-sections '-std=c++0x' -MD -MF bazel-out/aarch64-opt/bin/external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/_objs/gl_shader/gl_shader.d '-frandom-seed=bazel-out/aarch64-opt/bin/external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/_objs/gl_shader/gl_shader.o' -D__CLANG_SUPPORT_DYN_ANNOTATION__ -iquote external/org_tensorflow -iquote bazel-out/aarch64-opt/bin/external/org_tensorflow -iquote external/com_google_absl -iquote bazel-out/aarch64-opt/bin/external/com_google_absl -Wno-sign-compare -Wno-unused-function -Wno-uninitialized -Wno-unused-result -Wno-comment -Wno-return-type -Wno-unused-local-typedefs -Wno-ignored-attributes -DMESA_EGL_NO_X11_HEADERS -DEGL_NO_X11 '-std=c++14' -fno-canonical-system-headers -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -c external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/gl_shader.cc -o bazel-out/aarch64-opt/bin/external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/_objs/gl_shader/gl_shader.o)
Execution platform: @local_config_platform//:host

Use --sandbox_debug to see verbose messages from the sandbox
In file included from external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/gl_shader.h:22:0,
                 from external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/gl_shader.cc:16:
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/gl_shader.cc: In static member function 'static int tflite::gpu::gl::GlShader::CompileShader(GLenum, const string&, tflite::gpu::gl::GlShader*)':
external/org_tensorflow/tensorflow/lite/delegates/gpu/common/status.h:68:18: error: request for member 'ok' in 'status2', which is of non-class type 'const int'
     if (!status2.ok()) return status2; \
                  ^
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/gl_shader.cc:50:3: note: in expansion of macro 'RETURN_IF_ERROR'
   RETURN_IF_ERROR(TFLITE_GPU_CALL_GL(glCreateShader, &shader_id, shader_type));
   ^~~~~~~~~~~~~~~
external/org_tensorflow/tensorflow/lite/delegates/gpu/common/status.h:68:18: error: request for member 'ok' in 'status2', which is of non-class type 'const int'
     if (!status2.ok()) return status2; \
                  ^
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/gl_shader.cc:54:3: note: in expansion of macro 'RETURN_IF_ERROR'
   RETURN_IF_ERROR(
   ^~~~~~~~~~~~~~~
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/gl_shader.cc:68:66: error: cannot convert 'tflite::gpu::Status' to 'int' in return
                          "\nProblem shader is:\n" + shader_source);
                                                                  ^
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/gl_shader.cc:72:19: error: cannot convert 'tflite::gpu::Status' to 'int' in return
   return OkStatus();
                   ^
In file included from external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/gl_shader.cc:19:0:
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/gl_call.h: In instantiation of 'int tflite::gpu::gl::gl_call_internal::Caller<T>::operator()(const string&, F, ErrorF, T*, Params&& ...) [with F = unsigned int (*)(unsigned int); ErrorF = int (*)(); Params = {unsigned int&}; T = unsigned int; std::__cxx11::string = std::__cxx11::basic_string<char>]':
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/gl_call.h:81:27:   required from 'int tflite::gpu::gl::gl_call_internal::CallAndCheckError(const string&, F, ErrorF, ResultT*, ParamsT&& ...) [with F = unsigned int (*)(unsigned int); ErrorF = int (*)(); ResultT = unsigned int; ParamsT = {unsigned int&}; std::__cxx11::string = std::__cxx11::basic_string<char>]'
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/gl_shader.cc:50:3:   required from here
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/gl_call.h:60:16: error: request for member 'ok' in 'status', which is of non-class type 'const int'
     if (status.ok()) return OkStatus();
         ~~~~~~~^~
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/gl_call.h:60:38: error: cannot convert 'tflite::gpu::Status' to 'int' in return
     if (status.ok()) return OkStatus();
                                      ^
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/gl_call.h:61:26: error: request for member 'code' in 'status', which is of non-class type 'const int'
     return Status(status.code(), status.error_message() + ": " + context);
                   ~~~~~~~^~~~
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/gl_call.h:61:41: error: request for member 'error_message' in 'status', which is of non-class type 'const int'
     return Status(status.code(), status.error_message() + ": " + context);
                                  ~~~~~~~^~~~~~~~~~~~~
In file included from /usr/include/EGL/eglplatform.h:136:0,
                 from /usr/include/EGL/egl.h:39,
                 from external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/portable_gl31.h:21,
                 from external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/gl_shader.h:23,
                 from external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/gl_shader.cc:16:
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/gl_call.h:61:12: error: expression list treated as compound expression in functional cast [-fpermissive]
     return Status(status.code(), status.error_message() + ": " + context);
            ^
In file included from external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/gl_shader.cc:19:0:
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/gl_call.h: In instantiation of 'int tflite::gpu::gl::gl_call_internal::Caller<void>::operator()(const string&, F, ErrorF, Params&& ...) [with F = void (*)(unsigned int, int, const char* const*, const int*); ErrorF = int (*)(); Params = {unsigned int, int, const char**, std::nullptr_t}; std::__cxx11::string = std::__cxx11::basic_string<char>]':
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/gl_call.h:88:24:   required from 'int tflite::gpu::gl::gl_call_internal::CallAndCheckError(const string&, F, ErrorF, Params&& ...) [with F = void (*)(unsigned int, int, const char* const*, const int*); ErrorF = int (*)(); Params = {unsigned int, int, const char**, std::nullptr_t}; std::__cxx11::string = std::__cxx11::basic_string<char>]'
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/gl_shader.cc:54:3:   required from here
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/gl_call.h:73:16: error: request for member 'ok' in 'status', which is of non-class type 'const int'
     if (status.ok()) return OkStatus();
         ~~~~~~~^~
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/gl_call.h:73:38: error: cannot convert 'tflite::gpu::Status' to 'int' in return
     if (status.ok()) return OkStatus();
                                      ^
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/gl_call.h:74:26: error: request for member 'code' in 'status', which is of non-class type 'const int'
     return Status(status.code(), status.error_message() + ": " + context);
                   ~~~~~~~^~~~
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/gl_call.h:74:41: error: request for member 'error_message' in 'status', which is of non-class type 'const int'
     return Status(status.code(), status.error_message() + ": " + context);
                                  ~~~~~~~^~~~~~~~~~~~~
In file included from /usr/include/EGL/eglplatform.h:136:0,
                 from /usr/include/EGL/egl.h:39,
                 from external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/portable_gl31.h:21,
                 from external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/gl_shader.h:23,
                 from external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/gl_shader.cc:16:
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/gl_call.h:74:12: error: expression list treated as compound expression in functional cast [-fpermissive]
     return Status(status.code(), status.error_message() + ": " + context);
            ^
Target //mediapipe/examples/desktop/face_detection:face_detection_gpu failed to build
INFO: Elapsed time: 190.797s, Critical Path: 189.56s
INFO: 88 processes: 88 linux-sandbox.
FAILED: Build did NOT complete successfully

@mcclanahoochie
Copy link

Thanks for the log.
It looks like the problem could be with eglplatform.h
See https://www.khronos.org/registry/EGL/api/EGL/eglplatform.h
and search the page for X11, and this is what you see

#elif defined(__unix__) && defined(EGL_NO_X11)

typedef void             *EGLNativeDisplayType;
typedef khronos_uintptr_t EGLNativePixmapType;
typedef khronos_uintptr_t EGLNativeWindowType;

#elif defined(__unix__) || defined(USE_X11)

/* X11 (tentative)  */
#include <X11/Xlib.h>
#include <X11/Xutil.h>

typedef Display *EGLNativeDisplayType;
typedef Pixmap   EGLNativePixmapType;
typedef Window   EGLNativeWindowType;

We want to be in the EGL_NO_X11 case (hence the bazel defines).
The 'Status' problem will definitely happen if we include <X11/Xlib.h>, because inside Xlib.h we get
#define Status int
.. not what we want :/

As an experiment, try opening that file on your machine and making sure the EGL_NO_X11 case is chosen (either by using '#if 1' or write 'blah' inside that case to see if there are errors compiling). Either way the goal is to not use the X11 headers.
I know editing system files is not a solution, this is just to see if we're on the right track.

@ksachdeva
Copy link
Author

Thanks @mcclanahoochie

Your suggestion worked !!

Indeed there is a difference between the eglplatform.h on jetson vs the one that you provided the link to.

I inserted the above block resulting in the exclusion of X11 headers and I got the face_detection_gpu compiled.

I have yet to test it by running it.

Many thanks.

Here are some details that are bit strange -

A dell laptop running ubuntu 18.04 with Nvidia Quadro

# ml @ ml-dell in ~ [14:57:12]
$ sudo dpkg --status libegl1-mesa-dev
Package: libegl1-mesa-dev
Status: install ok installed
Priority: optional
Section: libdevel
Installed-Size: 172
Maintainer: Ubuntu X-SWAT <[email protected]>
Architecture: amd64
Multi-Arch: same
Source: mesa
Version: 19.0.8-0ubuntu0~18.04.3
Depends: mesa-common-dev (= 19.0.8-0ubuntu0~18.04.3), libglvnd-dev, libdrm-dev (>= 2.4.95), libx11-dev, libxext-dev, libxxf86vm-dev, libxdamage-dev, libxfixes-dev, libxcb-glx0-dev, libxcb-dri2-0-dev, libxcb-dri3-dev, libxcb-present-dev, libxcb-sync-dev, libxshmfence-dev, libx11-xcb-dev, libwayland-dev (>= 1.15.0), x11proto-dev
Description: free implementation of the EGL API -- development files
 This package contains the development environment required for compiling
 programs against EGL native platform graphics interface library.
 EGL provides a platform-agnostic mechanism for creating rendering surfaces
 for use with other graphics libraries, such as OpenGL|ES.
 .
 This package provides the development environment for compiling programs
 against the EGL library.
Homepage: https://mesa3d.org/
Original-Maintainer: Debian X Strike Force <[email protected]>

Content of eglplatform.h

#elif defined(__ANDROID__) || defined(ANDROID)

struct ANativeWindow;
struct egl_native_pixmap_t;

typedef struct ANativeWindow*           EGLNativeWindowType;
typedef struct egl_native_pixmap_t*     EGLNativePixmapType;
typedef void*                           EGLNativeDisplayType;

#elif defined(USE_OZONE)

typedef intptr_t EGLNativeDisplayType;
typedef intptr_t EGLNativeWindowType;
typedef intptr_t EGLNativePixmapType;

#elif defined(__unix__) || defined(__APPLE__)

#if defined(MESA_EGL_NO_X11_HEADERS)

typedef void            *EGLNativeDisplayType;
typedef khronos_uintptr_t EGLNativePixmapType;
typedef khronos_uintptr_t EGLNativeWindowType;

Important thing to note is that MESA_EGL_NO_X11_HEADERS is there in the header file

Jetson Nano

# ml @ ml-nano1 in ~/Desktop/Dev/third-party/mediapipe on git:master x [14:59:43]
$ sudo dpkg --status libegl1-mesa-dev
Package: libegl1-mesa-dev
Status: install ok installed
Priority: optional
Section: libdevel
Installed-Size: 172
Maintainer: Ubuntu X-SWAT <[email protected]>
Architecture: arm64
Multi-Arch: same
Source: mesa
Version: 19.0.8-0ubuntu0~18.04.3
Depends: mesa-common-dev (= 19.0.8-0ubuntu0~18.04.3), libglvnd-dev, libdrm-dev (>= 2.4.95), libx11-dev, libxext-dev, libxxf86vm-dev, libxdamage-dev, libxfixes-dev, libxcb-glx0-dev, libxcb-dri2-0-dev, libxcb-dri3-dev, libxcb-present-dev, libxcb-sync-dev, libxshmfence-dev, libx11-xcb-dev, libwayland-dev (>= 1.15.0), x11proto-dev
Description: free implementation of the EGL API -- development files
 This package contains the development environment required for compiling
 programs against EGL native platform graphics interface library.
 EGL provides a platform-agnostic mechanism for creating rendering surfaces
 for use with other graphics libraries, such as OpenGL|ES.
 .
 This package provides the development environment for compiling programs
 against the EGL library.
Homepage: https://mesa3d.org/
Original-Maintainer: Debian X Strike Force <[email protected]>

Content of eglplatform.h

#elif defined(USE_OZONE)

typedef intptr_t EGLNativeDisplayType;
typedef intptr_t EGLNativeWindowType;
typedef intptr_t EGLNativePixmapType;

#elif defined(WAYLAND)

#include <wayland-client.h>

typedef struct wl_display    *EGLNativeDisplayType;
typedef void                 *EGLNativePixmapType;
typedef struct wl_egl_window *EGLNativeWindowType;

#elif defined(__unix__) || defined(__APPLE__)

/* X11 (tentative)  */
#include <X11/Xlib.h>
#include <X11/Xutil.h>

typedef Display *EGLNativeDisplayType;
typedef Pixmap   EGLNativePixmapType;
typedef Window   EGLNativeWindowType;

#elif defined(__HAIKU__)

and the necessary define is missing !!

Now, the version of mesa on jetson and my dell laptop is identical but the eglplatform.h is different.

May be this file is autogenerated.

I am going to test if the gpu on jetson indeed gets used or not in next 1 hour or so and will inform the results.

Regards
Kapil

@ksachdeva
Copy link
Author

So I ran the stuff and got an error -

Command issued to run

# ml @ ml-nano1 in ~/Desktop/Dev/third-party/mediapipe on git:master x [16:27:44]
$ bazel-bin/mediapipe/examples/desktop/face_detection/face_detection_gpu --calculator_graph_config_file=mediapipe/graphs/face_detection/face_detection_mobile_gpu.pbtxt --input_video_path=/home/ml/Desktop/Dev/testdata/Run_combined.mp4

The response was -

I1212 16:27:44.495141 11397 demo_run_graph_main_gpu.cc:56] Initialize the calculator graph.
I1212 16:27:44.496888 11397 demo_run_graph_main_gpu.cc:60] Initialize the GPU.
I1212 16:27:44.518015 11397 gl_context_egl.cc:158] Successfully initialized EGL. Major : 1 Minor: 5
W1212 16:27:44.518121 11397 gl_context_egl.cc:163] Creating a context with OpenGL ES 3 failed: Unknown: ; eglChooseConfig() returned no matching EGL configuration for RGBA8888 D16 ES3 request.
W1212 16:27:44.518146 11397 gl_context_egl.cc:164] Fall back on OpenGL ES 2.
E1212 16:27:44.518735 11397 demo_run_graph_main_gpu.cc:186] Failed to run the graph: ; eglChooseConfig() returned no matching EGL configuration for RGBA8888 D16 ES2 request.

Now I do not anything about EGL etc as such. I looked at the line that is failing at gl_context_egl.cc and still nothing made sense. Then I googled and just with a shear luck at this point of time I found this thread that talks about EGL & X11.

https://devtalk.nvidia.com/default/topic/1030582/jetson-tx2/egl-without-x11/

Based on this thread I understood that EGL needs the notion of windowing. When I issued the above command, I was using ssh (from my osx).

I connected a monitor to jetson nano and issued the command there and it worked !!

However, this brings then another aspect as highlighted in the above thread at devtalk.nvidia.com. If one want to use non-X11 windowing system then the configuration would be different. At least this is what I understood.

Based on above, would it make sense for mediapipe to let the user (i.e. me in this case) pass the eglConfig or eglContext ? This is necessary because these edge devices will run headless and there will be no X11 windowing etc.

Please guide.

Regards
Kapil

@mcclanahoochie
Copy link

Nice progress!

Passing in an eglConfig would require some framework plumbing (you can try modifying gl_context_egl locally for testing directly at least).

For external GL contexts, please see this #313 (comment)

Maybe some combination of those options works for you

@m-decoster
Copy link

@ksachdeva I got this to work based on the link you shared. It's actually fairly easy, you simply have to only enable rendering to pixel buffers rather than also to windows. This comes down to removing | EGL_WINDOW_BIT in the context creation.

Using these configuration attributes I got hand tracking to run on GPU on a headless Ubuntu 18.04 machine.

For reference:

const EGLint config_attr[] = {
      // clang-format off
          EGL_RENDERABLE_TYPE, gl_version == 3 ? EGL_OPENGL_ES3_BIT_KHR
                                               : EGL_OPENGL_ES2_BIT,
          EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
          EGL_BLUE_SIZE, 8,
          EGL_GREEN_SIZE, 8,
          EGL_RED_SIZE, 8,
          EGL_ALPHA_SIZE, 8,
          EGL_DEPTH_SIZE, 16,
          EGL_NONE
      // clang-format on
  };

EGL_SURFACE_TYPE was modified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants