Skip to content

FastCV-based HAL for OpenCV acceleration#26316

Closed
sssanjee-quic wants to merge 10 commits intoopencv:4.xfrom
CodeLinaro:FastcvHAL_1stPost
Closed

FastCV-based HAL for OpenCV acceleration#26316
sssanjee-quic wants to merge 10 commits intoopencv:4.xfrom
CodeLinaro:FastcvHAL_1stPost

Conversation

@sssanjee-quic
Copy link
Copy Markdown
Contributor

@sssanjee-quic sssanjee-quic commented Oct 16, 2024

Added Fastcv HAL changes in the 3rdparty folder.
Code Changes includes HAL code , Fastcv libs and Headers

Change-Id: I2f0ddb1f57515c82ae86ba8c2a82965b1a9626ec

Requires binaries from opencv/opencv_3rdparty#86.
Related patch to opencv_contrib: opencv/opencv_contrib#3811

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

Added Fastcv HAL changes in the 3rdparty folder.
Includes HAL code , Fastcv libs and Headers

Change-Id: I2f0ddb1f57515c82ae86ba8c2a82965b1a9626ec
@asmorkalov asmorkalov changed the title OpenCV Acceleration with FastCV HAL changes FastCV-based HAL for OpenCV acceleration Oct 16, 2024
@asmorkalov asmorkalov self-assigned this Oct 16, 2024
@asmorkalov asmorkalov added this to the 4.11.0 milestone Oct 16, 2024
@asmorkalov
Copy link
Copy Markdown
Contributor

@sssanjee-quic Please create dedicated PR with binaries in opencv_3rdparty repository as we discussed. Static libraries are preferable instead of the dynamic ones.

#include <opencv2/core/utils/logger.hpp>
#include <opencv2/imgproc.hpp>

extern bool isInitialized;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be moved to fastcv_hal_utils.hpp

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will update in next PR

Reorganized the files in the folder,
Added rules to download the fastcv bins
from the 3rdparty repo

Change-Id: Ia66f138894d3e8a06d0f32a6e7ce3359619189d7
@asmorkalov
Copy link
Copy Markdown
Contributor

There is some bug in CMake. FastCV is downloaded and reported in CMake status, but HAL is not built and linked:
CMake command for Android:

cmake -DCMAKE_TOOLCHAIN_FILE=/home/alexander/Android/Sdk/ndk/28.0.12433566/build/cmake/android.toolchain.cmake -DWITH_KLEIDICV=OFF -DANDROID_NATIVE_API_LEVEL=24 -DANDROID_NDK=/home/alexander/Android/Sdk/ndk/28.0.12433566/ -DANDROID_SDK=/home/alexander/Android/Sdk/ -DANDROID_ABI="arm64-v8a" ../opencv

CMake status output:

  Other third-party libraries:
    Custom HAL:                  YES (fastcv (ver 0.0.1) carotene (ver 0.0.1))
    Protobuf:                    build (3.19.1)
    Flatbuffers:                 builtin/3rdparty (23.5.9)

Actual binaries do not have FastCV dependency:

readelf -d ./bin/opencv_test_core 

Dynamic section at offset 0x929cb8 contains 27 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libdl.so]
 0x0000000000000001 (NEEDED)             Shared library: [libm.so]
 0x0000000000000001 (NEEDED)             Shared library: [liblog.so]
 0x0000000000000001 (NEEDED)             Shared library: [libz.so]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so]
 0x000000000000001e (FLAGS)              BIND_NOW
 0x000000006ffffffb (FLAGS_1)            Flags: NOW PIE
 0x0000000000000015 (DEBUG)              0x0
 0x0000000000000007 (RELA)               0x2110
 0x0000000000000008 (RELASZ)             576000 (bytes)
 0x0000000000000009 (RELAENT)            24 (bytes)
 0x000000006ffffff9 (RELACOUNT)          23983
 0x0000000000000017 (JMPREL)             0x8eb10
 0x0000000000000002 (PLTRELSZ)           4872 (bytes)
 0x0000000000000003 (PLTGOT)             0x92e658
 0x0000000000000014 (PLTREL)             RELA
 0x0000000000000006 (SYMTAB)             0x348
 0x000000000000000b (SYMENT)             24 (bytes)
 0x0000000000000005 (STRTAB)             0x18f4
 0x000000000000000a (STRSZ)              2073 (bytes)
 0x000000006ffffef5 (GNU_HASH)           0x18d8
 0x0000000000000019 (INIT_ARRAY)         0x92dad8
 0x000000000000001b (INIT_ARRAYSZ)       480 (bytes)
 0x000000006ffffff0 (VERSYM)             0x16c8
 0x000000006ffffffe (VERNEED)            0x1868
 0x000000006fffffff (VERNEEDNUM)         3
 0x0000000000000000 (NULL)               0x0

for java part:

readelf -d ./jni/arm64-v8a/libopencv_java4.so 

Dynamic section at offset 0x1552788 contains 33 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libdl.so]
 0x0000000000000001 (NEEDED)             Shared library: [libm.so]
 0x0000000000000001 (NEEDED)             Shared library: [liblog.so]
 0x0000000000000001 (NEEDED)             Shared library: [libjnigraphics.so]
 0x0000000000000001 (NEEDED)             Shared library: [libz.so]
 0x0000000000000001 (NEEDED)             Shared library: [libandroid.so]
 0x0000000000000001 (NEEDED)             Shared library: [libmediandk.so]
 0x0000000000000001 (NEEDED)             Shared library: [libcamera2ndk.so]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so]
 0x000000000000000e (SONAME)             Library soname: [libopencv_java4.so]
 0x000000000000001e (FLAGS)              BIND_NOW
 0x000000006ffffffb (FLAGS_1)            Flags: NOW
 0x0000000000000007 (RELA)               0xc6740
 0x0000000000000008 (RELASZ)             1240752 (bytes)
 0x0000000000000009 (RELAENT)            24 (bytes)
 0x000000006ffffff9 (RELACOUNT)          38680
 0x0000000000000017 (JMPREL)             0x1f55f0
 0x0000000000000002 (PLTRELSZ)           63336 (bytes)
 0x0000000000000003 (PLTGOT)             0x15581b0
 0x0000000000000014 (PLTREL)             RELA
 0x0000000000000006 (SYMTAB)             0x2f8
 0x000000000000000b (SYMENT)             24 (bytes)
 0x0000000000000005 (STRTAB)             0x4e9ec
 0x000000000000000a (STRSZ)              490833 (bytes)
 0x000000006ffffef5 (GNU_HASH)           0x3efe0
 0x0000000000000019 (INIT_ARRAY)         0x1556608
 0x000000000000001b (INIT_ARRAYSZ)       384 (bytes)
 0x000000000000001a (FINI_ARRAY)         0x15565f8
 0x000000000000001c (FINI_ARRAYSZ)       16 (bytes)
 0x000000006ffffff0 (VERSYM)             0x3a228
 0x000000006ffffffe (VERNEED)            0x3ef6c
 0x000000006fffffff (VERNEEDNUM)         3
 0x0000000000000000 (NULL)               0x0

@asmorkalov asmorkalov removed the RFC label Nov 13, 2024
@asmorkalov
Copy link
Copy Markdown
Contributor

There is conflict with last KleidiCV-related patch. Could you rebase on top of 4.x and fix the conflict?

@asmorkalov
Copy link
Copy Markdown
Contributor

asmorkalov commented Nov 18, 2024

Build warnings with fresh NDK:

[493/1895] Building CXX object 3rdparty/fastcv/CMakeFiles/fastcv_hal.dir/src/fastcv_hal_core.cpp.o
/mnt/Projects/Projects/opencv/3rdparty/fastcv/src/fastcv_hal_core.cpp:112:40: warning: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Wsign-compare]
  112 |     if (src1_step < width && src2_step < width)
      |                              ~~~~~~~~~ ^ ~~~~~
/mnt/Projects/Projects/opencv/3rdparty/fastcv/src/fastcv_hal_core.cpp:112:19: warning: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Wsign-compare]
  112 |     if (src1_step < width && src2_step < width)
      |         ~~~~~~~~~ ^ ~~~~~
/mnt/Projects/Projects/opencv/3rdparty/fastcv/src/fastcv_hal_core.cpp:139:40: warning: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Wsign-compare]
  139 |     if (src1_step < width && src2_step < width)
      |                              ~~~~~~~~~ ^ ~~~~~
/mnt/Projects/Projects/opencv/3rdparty/fastcv/src/fastcv_hal_core.cpp:139:19: warning: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Wsign-compare]
  139 |     if (src1_step < width && src2_step < width)
      |         ~~~~~~~~~ ^ ~~~~~
/mnt/Projects/Projects/opencv/3rdparty/fastcv/src/fastcv_hal_core.cpp:199:23: warning: unused parameter 'mask_step' [-Wunused-parameter]
  199 |     size_t            mask_step)

The last one looks like some bug. OpenCV allows noncontinuous matrices for mask too.

@quic-xuezha
Copy link
Copy Markdown
Contributor

There is conflict with last KleidiCV-related patch. Could you rebase on top of 4.x and fix the conflict?

done

@quic-xuezha
Copy link
Copy Markdown
Contributor

Hi @asmorkalov the warnings we will fix, but the error about the doc, how should we fix it? #7601

@asmorkalov
Copy link
Copy Markdown
Contributor

Please ignore patch size check. The result looks like false-alarm.

@asmorkalov
Copy link
Copy Markdown
Contributor

@sssanjee-quic Thanks a lot for the great job! The PR has been squashed and merged manually through #26556

@asmorkalov asmorkalov closed this Dec 2, 2024
asmorkalov pushed a commit to opencv/opencv_contrib that referenced this pull request Dec 2, 2024
Depends on opencv/opencv#26316

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [ ] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants