Skip to content

Build riscv with c++ intrinsics#17922

Merged
opencv-pushbot merged 1 commit intoopencv:masterfrom
joy2myself:build_riscv_with_c++_intrin
Aug 4, 2020
Merged

Build riscv with c++ intrinsics#17922
opencv-pushbot merged 1 commit intoopencv:masterfrom
joy2myself:build_riscv_with_c++_intrin

Conversation

@joy2myself
Copy link
Copy Markdown
Contributor

@joy2myself joy2myself commented Jul 23, 2020

This PR From GSoC Project "Optimize OpenCV for RISC-V"

This PR added cross compiling environment for RISC-V and use C++ version universal intrinsics for building.

PR contains:
Added toolchain file for target riscv64-clang.
Extended CMake for RISC-V and add instruction checks (cmake/checks/cpu_riscv.cpp).
Created intrin_riscv.hpp with C++ version universal intrinsics.

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 OpenCV (BSD) License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to 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
force_builders_only=docs,linux


ocv_optimization_process_obsolete_option(ENABLE_VSX VSX ON)

ocv_optimization_process_obsolete_option(ENABLE_RISCV RISCV OFF)
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.

ENABLE_RISCV is bad choise as it's general architecture name. I propose to use something ENABLE_RVV or enable ENABLE_RISCV_VEXT.

return (int)vfmv_f_s_f32m1_f32(val);
}
#else
#error "RISCV is not supported"
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.

"RISC-V vector extension"

@asmorkalov
Copy link
Copy Markdown
Contributor

General recommendation: replace RISCV by RISCV_RVV or something associated with V-extension to not mix general features and vectorized code.

@asmorkalov
Copy link
Copy Markdown
Contributor

There is build failure with clang:

/home/alexander/Projects/riscv/opencv/modules/core/src/system.cpp:607:37: error: use of undeclared identifier 'CV_CPU_RISCV'
        int baseline_features[] = { CV_CPU_BASELINE_FEATURES };
                                    ^
/home/alexander/Projects/riscv/opencv-build/cv_cpu_config.h:7:7: note: expanded from macro 'CV_CPU_BASELINE_FEATURES'
    , CV_CPU_RISCV \
      ^
/home/alexander/Projects/riscv/opencv/modules/core/src/system.cpp:608:53: error: invalid application of 'sizeof' to an incomplete type 'int []'
        if (!checkFeatures(baseline_features, sizeof(baseline_features) / sizeof(baseline_features[0]))
                                                    ^~~~~~~~~~~~~~~~~~~
/home/alexander/Projects/riscv/opencv/modules/core/src/system.cpp:619:52: error: invalid application of 'sizeof' to an incomplete type 'int []'
            checkFeatures(baseline_features, sizeof(baseline_features) / sizeof(baseline_features[0]), true);
                                                   ^~~~~~~~~~~~~~~~~~~
/home/alexander/Projects/riscv/opencv/modules/core/src/system.cpp:623:47: error: invalid application of 'sizeof' to an incomplete type 'int []'
        readSettings(baseline_features, sizeof(baseline_features) / sizeof(baseline_features[0]));
                                              ^~~~~~~~~~~~~~~~~~~
/home/alexander/Projects/riscv/opencv/modules/core/src/system.cpp:747:30: error: use of undeclared identifier 'CV_CPU_RISCV'
    const int features[] = { CV_CPU_BASELINE_FEATURES, CV_CPU_DISPATCH_FEATURES };
                             ^
/home/alexander/Projects/riscv/opencv-build/cv_cpu_config.h:7:7: note: expanded from macro 'CV_CPU_BASELINE_FEATURES'
    , CV_CPU_RISCV \
      ^
/home/alexander/Projects/riscv/opencv/modules/core/src/system.cpp:748:26: error: invalid application of 'sizeof' to an incomplete type 'const int []'
    const int sz = sizeof(features) / sizeof(features[0]);

@joy2myself joy2myself force-pushed the build_riscv_with_c++_intrin branch from 753f6f4 to 3e85280 Compare July 23, 2020 15:09
@joy2myself
Copy link
Copy Markdown
Contributor Author

I have updated the code for naming issue. Use RVV instead of RISCV now.

@asmorkalov
Copy link
Copy Markdown
Contributor

There is build issue still:

[  6%] Building C object 3rdparty/libtiff/CMakeFiles/libtiff.dir/tif_aux.c.o
cd /home/alexander/Projects/riscv/opencv-build/3rdparty/libtiff && /home/alexander/Projects/riscv/rvv-llvm/build/bin/clang --target=riscv64-unknown-linux-gnu --sysroot=/home/alexander/Projects/riscv/riscv-gnu-toolchain-install/sysroot -DNEED_LIBPORT -D_FILE_OFFSET_BITS=64 -I/home/alexander/Projects/riscv/opencv-build/3rdparty/zlib -I/home/alexander/Projects/riscv/opencv/3rdparty/zlib -I/home/alexander/Projects/riscv/opencv-build/3rdparty/libtiff -I/home/alexander/Projects/riscv/opencv/3rdparty/libtiff -I/home/alexander/Projects/riscv/opencv-build/3rdparty/libjpeg-turbo -I/home/alexander/Projects/riscv/opencv/3rdparty/libjpeg-turbo/src -isystem /home/alexander/Projects/riscv/opencv-build  -march=rv64gcv --gcc-toolchain=/home/alexander/Projects/riscv/riscv-gnu-toolchain-install -w -march=rv64gcv --gcc-toolchain=/home/alexander/Projects/riscv/riscv-gnu-toolchain-install -w   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wstrict-prototypes -Winit-self -Wpointer-arith -Wsign-promo -Wuninitialized -Winit-self -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -Wno-deprecated-enum-enum-conversion -Wno-deprecated-anon-enum-enum-conversion -fdiagnostics-show-option -pthread -Qunused-arguments -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -Wno-unused-but-set-variable -Wno-missing-prototypes -Wno-missing-declarations -Wno-undef -Wno-unused -Wno-sign-compare -Wno-cast-align -Wno-shadow -Wno-maybe-uninitialized -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast -Wno-misleading-indentation -Wno-implicit-fallthrough -Wno-unused-parameter -O3 -DNDEBUG  -DNDEBUG -fPIC   -o CMakeFiles/libtiff.dir/tif_aux.c.o   -c /home/alexander/Projects/riscv/opencv/3rdparty/libtiff/tif_aux.c
In file included from /home/alexander/Projects/riscv/opencv/3rdparty/libtiff/tif_aux.c:30:
/home/alexander/Projects/riscv/opencv/3rdparty/libtiff/tiffiop.h:54:48: error: unknown type name 'size_t'
extern void *lfind(const void *, const void *, size_t *, size_t,
                                               ^
/home/alexander/Projects/riscv/opencv/3rdparty/libtiff/tiffiop.h:61:32: error: unknown type name 'size_t'
extern int snprintf(char* str, size_t size, const char* format, ...);
                               ^
2 errors generated.

@joy2myself joy2myself force-pushed the build_riscv_with_c++_intrin branch from 3e85280 to b79ecef Compare July 24, 2020 08:47
@joy2myself
Copy link
Copy Markdown
Contributor Author

I have updated the code. Fixed clang build issues.

@asmorkalov asmorkalov self-requested a review July 27, 2020 11:00
Copy link
Copy Markdown
Contributor

@asmorkalov asmorkalov left a comment

Choose a reason for hiding this comment

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

I fixed CMake toolchain file to build the library. Please squash commits to have one commit in PR.

@asmorkalov
Copy link
Copy Markdown
Contributor

@joy2myself joy2myself force-pushed the build_riscv_with_c++_intrin branch 2 times, most recently from e80d3a7 to 98f47fa Compare July 28, 2020 02:04
@joy2myself
Copy link
Copy Markdown
Contributor Author

Hi Alex, I squashed commits to one and fixed the whitespace issue.

@asmorkalov
Copy link
Copy Markdown
Contributor


#if (CV_SSE2 || CV_NEON || CV_VSX || CV_MSA || CV_WASM_SIMD) && !defined(CV_FORCE_SIMD128_CPP)

#if (CV_SSE2 || CV_NEON || CV_VSX || CV_MSA || CV_WASM_SIMD/* || CV_RVV*/) && !defined(CV_FORCE_SIMD128_CPP)
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.

Please revert the change here till we do not have specific optimizations.

@joy2myself joy2myself force-pushed the build_riscv_with_c++_intrin branch 2 times, most recently from 48db9b5 to 8c6130c Compare July 28, 2020 13:55
@asmorkalov asmorkalov self-requested a review July 29, 2020 05:57
Copy link
Copy Markdown
Contributor

@asmorkalov asmorkalov left a comment

Choose a reason for hiding this comment

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

👍

@joy2myself
Copy link
Copy Markdown
Contributor Author

@mshabunin Hi, Maksim. Thanks a lot for your review. Firstly, I'd like to explain that this patch just added the toolchain file for cross compiling and extended some files for target RISC-V. The code in file intrin_rvv.hpp is all from the c++ version universal intrinsics. I'm not sure that part of the changes you requested about the file intrin_rvv.hpp were due to a misunderstanding of this or not.

@joy2myself joy2myself force-pushed the build_riscv_with_c++_intrin branch from 8c6130c to e418f43 Compare July 30, 2020 02:26
@joy2myself
Copy link
Copy Markdown
Contributor Author

I have resolved changes except these in intrin_rvv.cpp and runtime check.

@joy2myself joy2myself force-pushed the build_riscv_with_c++_intrin branch from e418f43 to 033687b Compare July 31, 2020 02:58
@joy2myself
Copy link
Copy Markdown
Contributor Author

@mshabunin Hi, Maksim. I have finished all the changes you requested. Please review it again. Thank you!

#define CV_CPU_AVX512_CLX 261
#define CV_CPU_AVX512_ICL 262

#define CV_CPU_RVV 300
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please use 210 here and below.

256+ is used for "groups".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Thanks a lot for your review!

- Added cross compile cmake file for target riscv64-clang
- Extended cmake for RISC-V and added instruction checks
- Created intrin_rvv.hpp with C++ version universal intrinsics
@joy2myself joy2myself force-pushed the build_riscv_with_c++_intrin branch from 033687b to ff4c387 Compare August 3, 2020 12:19
@asmorkalov
Copy link
Copy Markdown
Contributor

@alalek Can we merge the PR?

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.

5 participants