Commit d214770d authored by Maksim Shabunin's avatar Maksim Shabunin

HAL samples: renamed and added readme

parent 84f37d35
Custom HAL samples
==================
Samples in this folder are intended to demonstrate functionality replacement mechanism in the OpenCV library.
The __c_hal__ is the example of pure C replacement library with all functions returning error. It can be used to verify error handling in the function switching code.
The __slow_hal__ contains naive C++ implementations of the element-wise logical array operations (and, or, xor, not) making them twice slower than the default.
Build custom HAL replacement library
------------------------------------
1. Create folder for build (for example `<home-dir>/my-hal-build`)
2. Go to created folder and run cmake: `cmake <opencv-src>/samples/hal/slow_hal`
3. Run make
After build you will find static library in the build folder: `libslow_hal.a`
Build OpenCV with HAL replacement
---------------------------------
1. Create folder for build (for example `<home-dir>/my-opencv-build`)
2. Go to created folder and run cmake:
```
cmake \
-DOPENCV_HAL_HEADERS="<opencv-src>/samples/hal/slow_hal/impl.hpp" \
-DOPENCV_HAL_LIBS="<home-dir>/my-hal-build/libslow_hal.a" \
<opencv-src>
```
3. Run make (or `make opencv_perf_core` to build the demonstration test executable only)
4. After build you can run the tests and verify that some functions are slower now:
```
./bin/opencv_perf_core --gtest_filter=*bitwise_and*
```
This diff is collapsed.
This diff is collapsed.
...@@ -6,6 +6,6 @@ if(UNIX) ...@@ -6,6 +6,6 @@ if(UNIX)
endif() endif()
endif() endif()
add_library(broken_hal broken.c) add_library(c_hal impl.c)
set(OPENCV_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../..") set(OPENCV_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../..")
target_include_directories(broken_hal PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${OPENCV_SRC_DIR}/modules/core/include) target_include_directories(c_hal PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${OPENCV_SRC_DIR}/modules/core/include)
This diff is collapsed.
This diff is collapsed.
...@@ -6,6 +6,6 @@ if(UNIX) ...@@ -6,6 +6,6 @@ if(UNIX)
endif() endif()
endif() endif()
add_library(simple_hal simple.cpp) add_library(slow_hal impl.cpp)
set(OPENCV_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../..") set(OPENCV_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../..")
target_include_directories(simple_hal PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${OPENCV_SRC_DIR}/modules/core/include) target_include_directories(slow_hal PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${OPENCV_SRC_DIR}/modules/core/include)
#include "simple.hpp" #include "impl.hpp"
int slow_and8u(const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height) int slow_and8u(const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height)
{ {
...@@ -24,9 +24,9 @@ int slow_xor8u(const uchar* src1, size_t step1, const uchar* src2, size_t step2, ...@@ -24,9 +24,9 @@ int slow_xor8u(const uchar* src1, size_t step1, const uchar* src2, size_t step2,
return CV_HAL_ERROR_OK; return CV_HAL_ERROR_OK;
} }
int slow_not8u(const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height) int slow_not8u(const uchar* src1, size_t step1, uchar* dst, size_t step, int width, int height)
{ {
for(; height--; src1 = src1 + step1, src2 = src2 + step2, dst = dst + step) for(; height--; src1 = src1 + step1, dst = dst + step)
for(int x = 0 ; x < width; x++ ) for(int x = 0 ; x < width; x++ )
dst[x] = ~src1[x]; dst[x] = ~src1[x];
return CV_HAL_ERROR_OK; return CV_HAL_ERROR_OK;
......
...@@ -6,15 +6,15 @@ ...@@ -6,15 +6,15 @@
int slow_and8u(const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height); int slow_and8u(const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height);
int slow_or8u(const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height); int slow_or8u(const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height);
int slow_xor8u(const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height); int slow_xor8u(const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height);
int slow_not8u(const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height); int slow_not8u(const uchar* src1, size_t step1, uchar* dst, size_t step, int width, int height);
#undef hal_and8u #undef cv_hal_and8u
#define hal_and8u slow_and8u #define cv_hal_and8u slow_and8u
#undef hal_or8u #undef cv_hal_or8u
#define hal_or8u slow_or8u #define cv_hal_or8u slow_or8u
#undef hal_xor8u #undef cv_hal_xor8u
#define hal_xor8u slow_xor8u #define cv_hal_xor8u slow_xor8u
#undef hal_not8u #undef cv_hal_not8u
#define hal_not8u slow_not8u #define cv_hal_not8u slow_not8u
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment