elucideye / acf

Aggregated Channel Feature object detection in C++ and OpenGL ES 2.0 based on https://github.com/pdollar/toolbox
BSD 3-Clause "New" or "Revised" License
49 stars 20 forks source link

Execute issues in cross platform board #102

Closed FFFFFUNKYMUZIK closed 5 years ago

FFFFFUNKYMUZIK commented 6 years ago

I compile this project with linux-gcc-armhf-neon (bin name : arm-linux-gnueabihf-c++ 5.4.0) and success compile. When I execute this in target board(SoC including cortex-a9 quad-core with fpu support), It fails at glfwInit() of aglet hunter package. Are there any dependent library for aglet&acf to load or do I have to install other packages(mesa-glx, etc ) with cross-compiling?

Thank you in advance for your support.

FFFFFUNKYMUZIK commented 6 years ago

In detail, I enter the following command in ${Project_folder}/_install/linux-gcc-armhf-neon/bin/ : ./acf-pipeline "--input=lena512color.png" "--repeat=256" "--model=drishti_face_gray_64x64.cpb" "--minimum=128" "--calibration=0.01" "--global"

then the following exception is caught: Exception caught: glfwInit(): Unreachable code assertion failed in file '/home/cjh/.hunter/_Base/e7fe3f0/f7274a8/Build/aglet/Source/lib/aglet/GLFWContext.cpp' line 38

headupinclouds commented 6 years ago

I'm not quite sure. As you've probably seen, the aglet package is just a small convenience wrapper library that provides a single interface for portable OpenGL contexts on iOS, Android and "desktop" (via glfw). I don't know if glfw supports your board or not? Do you know if it is expected to work? Have you tried glfw on the board outside of Hunter? Unfortunately, I don't have a board for testing. Have you configured an OpenGL context on the board in other projects?

FFFFFUNKYMUZIK commented 6 years ago

I found it in "aglet.h" the following:

elif defined(__ANDROID__) || defined(ANDROID)
  if defined(AGLET_OPENGL_ES3)
    include <GLES3/gl3.h>
    include <GLES3/gl3ext.h>
  else
    include <GLES2/gl2.h>
    include <GLES2/gl2ext.h>
  endif
  define AGLET_ANDROID 1
elif defined(__linux__) || defined(__unix__) || defined(__posix__)
  define GL_GLEXT_PROTOTYPES 1
  include <GL/gl.h>
  include <GL/glext.h>
  define AGLET_LINUX 1
else

I think the problem is the target board cannot use OpenGL(but ES), but It links OpenGL. Any methods to import edited aglet(change the define macro by mannually) package?? Thanks.

headupinclouds commented 6 years ago

UPDATE: Actually the OpenGL vs OpenGL ES distinction is a little more complicated than what I outlined below, since the ogles_gpgu module is also impacted. In practice I think the OpenGL ES libs you need might be very close to the ANDROID configuration. It mostly boils down to header paths and the linked OpenGL library. I will think about it more. BTW, for now, you should be able to build just the CPU/SIMD version of the lib without the all shader ACF processing.

I see. Unfortunately, I don't have a matching platform, but I think you could import aglet sources directly using add_subdirectory() and hack/experiment until you get it working. If you find a fix I can help update the aglet module.

The aglet package is introduced here:

https://github.com/elucideye/acf/blob/fe2738dc5d086092c9a708d15cce06369300c7a2/src/CMakeLists.txt#L62-L63

You can try adding sources temporarily for hacking using something like this:

[UNTESTED -- I will post a tested solution later today]

message("AGLET_PATH env var is $ENV{AGLET_PATH}")
if(DEFINED ENV{AGLET_PATH})
  message("Using aglet sources directly")
  add_subdirectory("$ENV{AGLET_PATH}" "${CMAKE_CURRENT_BINARY_DIR}/aglet")
  add_library(aglet::aglet ALIAS aglet) # CONFIG package compatibility
else()
  hunter_add_package(aglet) # if(TARGET aglet::aglet) will bed used in test/exe targets
  find_package(aglet CONFIG REQUIRED)
endif()

Just checkout aglet somewhere locally on your machine:

cd ${SOME_DIR}
git clone --recursive https://github.com/elucideye/aglet
export AGLET_PATH=${PWD}/aglet

Apply the patch shown above, and run the top level acf build command with --reconfig.

I think the above solution can be made to work. In general it will only work reliably for "leaf node" packages. Since aglet is really only used for application level tests, this should be the case.

FFFFFUNKYMUZIK commented 5 years ago

Hi. I solved the problem from hacking the aglet sources and include it in my project. (forces use EGL instead of glfw)

Now I moved my platform into android(and supports GLES3.1+AEP) and bump into some problem:

I used following command :

polly.py --toolchain android-ndk-r16b-api-24-arm64-v8a-clang-libcxx14 --fwd ACF_BUILD_TESTS=ON HUNTER_CONFIGURATION_TYPES=Release ACF_SHARED_SDK=ON ACF_OPENGL_ES3=ON --config Release --install --verbose --reconfig (--clear)

I found OGLES_GPGPU_OPENGL_ES3 & AGLET_OPENGL_ES3 is forced set to equal ACF_OPENGL_ES3 like this in src/app/cmake/Hunter/config.cmake :

set(aglet_cmake_args AGLET_OPENGL_ES3=${ACF_OPENGL_ES3}
hunter_config(....)

but log said that AGLET/OGLES_GPGPU doesn't receive the ES3 cmake arguments and I confused whether it uses PBO(GLES3.0 feature) or not.

-- [hunter *** DEBUG *** 2018-10-23T09:31:33] Package 'ogles_gpgpu' default arguments: 'OGLES_GPGPU_INSTALL=ON'
-- [hunter *** DEBUG *** 2018-10-23T09:31:33] Package 'ogles_gpgpu' user arguments: **'OGLES_GPGPU_VERBOSE=OFF;OGLES_GPGPU_OPENGL_ES3=OFF'**
-- [hunter *** DEBUG *** 2018-10-23T09:31:33] Add extra CMake args: 'OGLES_GPGPU_INSTALL' = 'ON'
-- [hunter *** DEBUG *** 2018-10-23T09:31:33] Add extra CMake args: 'OGLES_GPGPU_VERBOSE' = 'OFF'
**-- [hunter *** DEBUG *** 2018-10-23T09:31:33] Add extra CMake args: 'OGLES_GPGPU_OPENGL_ES3' = 'OFF'**

I tried it several times after remove ~/.hunter directory and clean option, but the log said the same.

Any suggestion? Thanks.

headupinclouds commented 5 years ago

I was traveling last week. Sorry for the delayed response.

I solved the problem from hacking the aglet sources and include it in my project. (forces use EGL instead of glfw)

If you have a fix for your platform, feel free to send a PR to aglet.

Although it sounds like you have moved to an Android?

log said that AGLET/OGLES_GPGPU doesn't receive the ES3 cmake arguments and I confused whether it uses PBO(GLES3.0 feature) or not.

If you build from the top directory, it will use a shared local configuration with the drishti project for consistent CI friendly hunter caching.

See: https://github.com/elucideye/acf/blob/fe2738dc5d086092c9a708d15cce06369300c7a2/CMakeLists.txt#L46

In that case you need to use DRISHTI_OPENGL_ES3 as ACF is sharing the package definitions with that project.

https://github.com/elucideye/drishti-upload/blob/b10026caa49ee8c3e3855fffcb1cbca777486fbc/config.cmake#L208-L212

Please try that and let me know if you have any problems.

The src/app tree is intended to be relocatable and can build against the ACF package. You can also build directly from that tree, in which case it will use the ACF_OPENGL_ES3 variable.

Sorry for the confusion.

BourneYin commented 5 years ago

I compile this project with linux-gcc-armhf-neon (bin name : arm-linux-gnueabihf-c++ 5.4.0) and success compile. When I execute this in target board(SoC including cortex-a9 quad-core with fpu support), It fails at glfwInit() of aglet hunter package. Are there any dependent library for aglet&acf to load or do I have to install other packages(mesa-glx, etc ) with cross-compiling?

Thank you in advance for your support.

Could you share how to compile the libacf.so for arm linux? Thanks!

FFFFFUNKYMUZIK commented 5 years ago

I struggled about this issue long time ago, I am quite vague to give exact answer. Maybe in directory polly-master of this project, there are lots of *.cmake files to configure cmake. Isn't it?

for example in linux-gcc-armhf-neon.cmake, there is corresponding compiler name and other cmake files listed to refer for checking exact cmake configuration. bless the author of this project, it suggests how to install the corresponding compiler. like this:

# install cross compiler on Ubuntu
# - sudo apt get install g++-arm-linux-gnueabihf
...
include("${CMAKE_CURRENT_LIST_DIR}/utilities/polly_common.cmake")
...
set(CROSS_COMPILE_TOOLCHAIN_PREFIX "arm-linux-gnueabihf")

Corresponding compiler you have to pick strongly depends on whether you compiles your project for host which you are compiling on or device(cross-compile).

If you figured out the correct compiler, The only thing you have to do is giving correct compiler option for polly.py scripts like following:

polly.py --toolchain g++-arm-linux-gnueabihf --install --verbose

The compiler must be installed(maybe in your /usr/lib/ or /usr/lib64/ directory) beforehand.

Hope this help.

BourneYin commented 5 years ago

Corresponding compiler you have to pick strongly depends on whether you compiles your project for host which you are compiling on or device(cross-compile).

If you figured out the correct compiler, The only thing you have to do is giving correct compiler option for polly.py scripts like following:

polly.py --toolchain g++-arm-linux-gnueabihf --install --verbose

The compiler must be installed(maybe in your /usr/lib/ or /usr/lib64/ directory) beforehand.

Hope this help.

Thank you for your reply! Actually, I'm trying to build the libacf.so for arm linux on Ubuntu x86 platform. But when I execute this command according to your suggestion: polly.py --toolchain linux-gcc-armhf-neon --install --verbose A compilation error occurred. Some segments as follows:

Android: iOS : Linux : 1 Xcode : CMake Error at /home/bourne/workbase/app_tools/acf/_ci/cmake/share/cmake-3.14/Modules/FindPackageHandleStandardArgs.cmake:137 (message): Could NOT find OpenGL (missing: OPENGL_opengl_LIBRARY OPENGL_glx_LIBRARY) Call Stack (most recent call first): /home/bourne/workbase/app_tools/acf/_ci/cmake/share/cmake-3.14/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE) /home/bourne/workbase/app_tools/acf/_ci/cmake/share/cmake-3.14/Modules/FindOpenGL.cmake:397 (FIND_PACKAGE_HANDLE_STANDARD_ARGS) ogles_gpgpu/CMakeLists.txt:96 (find_package) -- Configuring incomplete, errors occurred!

It meas I should get the arm OpenGL libs? Have you ever met, or could you give me some advice? Thanks very much!

headupinclouds commented 5 years ago

It means I should get the arm OpenGL libs?

The OpenGL configuration is only required for the low level shader based GPGPU ACF acceleration. If you don't need this, you can build with --fwd ACF_BUILD_OGLES_GPGPU=OFF to simplify the configuration, and it will still use the toolbox SIMD acceleration, which is updated to work for NEON in this repo. Note that using the GPGPU effectively in an application requires introducing some application level latency to mask the cost of the gpu->cpu transfers, but it does offload almost all of the processing from the CPU. There are also some tradeoffs in precision due to 4x8-bit limitations, but it is fast. There is a application POC of this here https://github.com/elucideye/acf/blob/master/src/app/pipeline/GPUDetectionPipeline.cpp.

I haven't tried cross compiling for g++-arm-linux-gnueabihf, but can take a look. If you do want to use GPGPU, then the ogles_gpgpu back end and the aglet test context will look for some OpenGL lib. You can configure what it uses now through CMake. Those packages previously assumed if(IOS OR ANDROID) == OpenGL ES 2.0 (or 3.0) and all other "desktop" platforms used a compatible OpenGL subset. This has since been relaxed and you can request OpenGL ES 2.0 on any systems that have it. In order to use this we just need to update the package entries in the local config. I can queue that up. I can try the build if you can point to the toolchain you are using.

BourneYin commented 5 years ago

It means I should get the arm OpenGL libs?

The OpenGL configuration is only required for the low level shader based GPGPU ACF acceleration. If you don't need this, you can build with --fwd ACF_BUILD_OGLES_GPGPU=OFF to simplify the configuration, and it will still use the toolbox SIMD acceleration, which is updated to work for NEON in this repo. Note that using the GPGPU effectively in an application requires introducing some application level latency to mask the cost of the gpu->cpu transfers, but it does offload almost all of the processing from the CPU. There are also some tradeoffs in precision due to 4x8-bit limitations, but it is fast. There is a application POC of this here https://github.com/elucideye/acf/blob/master/src/app/pipeline/GPUDetectionPipeline.cpp.

I haven't tried cross compiling for g++-arm-linux-gnueabihf, but can take a look. If you do want to use GPGPU, then the ogles_gpgpu back end and the aglet test context will look for some OpenGL lib. You can configure what it uses now through CMake. Those packages previously assumed if(IOS OR ANDROID) == OpenGL ES 2.0 (or 3.0) and all other "desktop" platforms used a compatible OpenGL subset. This has since been relaxed and you can request OpenGL ES 2.0 on any systems that have it. In order to use this we just need to update the package entries in the local config. I can queue that up. I can try the build if you can point to the toolchain you are using.

Thanks very much! CPU->GPU , it involves the image transmission of system memory to video memory,and so you are.

Actually, these days, I have met with a lot of doubts.

  1. Few days ago, I have tried to build with toolchain gcc-5-pic-hid-sections-lto on X86 Ubuntu 18.04, and run the acf-detect demo with some args as follos: ./acf-detect --input=./000007.jpg --output=./ --model=./cfInria-bourneDetector.cpb --nms --annotate --calibration=0.00001 --gpu An error occurred:

    Exception: glfwCreateWindow(): Assertion 'm_context' failed in file '/home/bourne/.hunter/_Base/6421d63/1247837/7868414/Build/aglet/Source/lib/aglet/GLFWContext.cpp' line 94

    I have traced into the glfw souce code, the root cause is chooseFBconfig failure. but why?

  2. As mentioned in the previous discussion, I also have tried to build with toolchain linux-gcc-armhf-neon on X86 Ubuntu 18.04。 Case 1: enable GPGPU, there was an build error as mentioned previous. Case 2: disable GPGPU wirh '--fwd ACF_BUILD_OGLES_GPGPU=OFF', there is a fresh build error as follows:

    [ 3%] Building CXX object src/lib/CMakeFiles/acf.dir/acf/acf/transfer.cpp.o cd /home/bourne/workbase/app_tools/acf/_builds/linux-gcc-armhf-neon/src/lib && /usr/bin/arm-linux-gnueabihf-g++ -DACF_DO_HALF=1 -DACF_SERIALIZE_WITH_CVMATIO=1 -DHALF_ENABLE_CPP11_CMATH=1 -I/home/bourne/workbase/app_tools/acf/_builds/linux-gcc-armhf-neon -I/home/bourne/workbase/app_tools/acf/src/lib/acf -isystem /home/bourne/.hunter/_Base/6421d63/d018056/8948932/Install/include/opencv4 -isystem /home/bourne/.hunter/_Base/6421d63/d018056/8948932/Install/include -isystem /home/bourne/.hunter/_Base/6421d63/d018056/8948932/Install/include/cvmatio -mfpu=neon -mfloat-abi=hard -std=c++11 -std=c++11 -o CMakeFiles/acf.dir/acf/acf/transfer.cpp.o -c /home/bourne/workbase/app_tools/acf/src/lib/acf/acf/transfer.cpp In file included from /home/bourne/workbase/app_tools/acf/src/lib/acf/acf/transfer.cpp:11:0: /home/bourne/workbase/app_tools/acf/src/lib/acf/acf/transfer.h:15:10: fatal error: ogles_gpgpu/common/proc/base/procinterface.h: No such file or directory

    include <ogles_gpgpu/common/proc/base/procinterface.h>

      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    compilation terminated.

    Can you help me?

  3. Besides, what I want to know is, On X86 Ubutu 18.04, to product the GPGPU support version libs/apps for arm Linux platform with OGL ES. should I need to cross compile the OGL/ES souce code for arm?

Could you please clarify it for me? Thanks very much!

headupinclouds commented 5 years ago

I've moved (1) to #107 and (2) to #108 .

Besides, what I want to know is, On X86 Ubutu 18.04, to product the GPGPU support version libs/apps for arm Linux platform with OGL ES. should I need to cross compile the OGL/ES souce code for arm?

I haven't tested this, but yes, you will need to link against OpenGL ES 2.0 libs compiled for ARM.

headupinclouds commented 5 years ago

I will close this older discussion in favor of the more focused follow up issues.