mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 07:43:03 +04:00
Merge pull request #8900 from alalek:update_android_build
This commit is contained in:
@@ -32,7 +32,11 @@ source_group("Src" FILES "${OPENCV_MODULE_opencv_core_BINARY_DIR}/version_string
|
||||
ocv_glob_module_sources(SOURCES "${OPENCV_MODULE_opencv_core_BINARY_DIR}/version_string.inc"
|
||||
HEADERS ${lib_cuda_hdrs} ${lib_cuda_hdrs_detail})
|
||||
|
||||
ocv_module_include_directories(${the_module} ${ZLIB_INCLUDE_DIRS} ${OPENCL_INCLUDE_DIRS} ${CPUFEATURES_INCLUDE_DIRS})
|
||||
ocv_module_include_directories(${the_module} ${ZLIB_INCLUDE_DIRS} ${OPENCL_INCLUDE_DIRS})
|
||||
if(ANDROID AND HAVE_CPUFEATURES)
|
||||
ocv_append_sourge_file_compile_definitions(${CMAKE_CURRENT_SOURCE_DIR}/src/system.cpp "HAVE_CPUFEATURES=1")
|
||||
ocv_module_include_directories(${CPUFEATURES_INCLUDE_DIRS})
|
||||
endif()
|
||||
ocv_create_module(${extra_libs})
|
||||
|
||||
ocv_target_link_libraries(${the_module} ${ZLIB_LIBRARIES} "${OPENCL_LIBRARIES}" "${VA_LIBRARIES}" "${LAPACK_LIBRARIES}" "${CPUFEATURES_LIBRARIES}" "${HALIDE_LIBRARIES}")
|
||||
|
||||
@@ -71,7 +71,11 @@
|
||||
# define CV_AVX 1
|
||||
#endif
|
||||
#ifdef CV_CPU_COMPILE_FP16
|
||||
# include <immintrin.h>
|
||||
# if defined(__arm__) || defined(__aarch64__) || defined(_M_ARM)
|
||||
# include <arm_neon.h>
|
||||
# else
|
||||
# include <immintrin.h>
|
||||
# endif
|
||||
# define CV_FP16 1
|
||||
#endif
|
||||
#ifdef CV_CPU_COMPILE_AVX2
|
||||
|
||||
@@ -279,15 +279,27 @@ struct v_float64x2
|
||||
#endif
|
||||
|
||||
#if CV_FP16
|
||||
// Workaround for old comiplers
|
||||
// Workaround for old compilers
|
||||
template <typename T> static inline int16x4_t vreinterpret_s16_f16(T a)
|
||||
{ return (int16x4_t)a; }
|
||||
template <typename T> static inline float16x4_t vreinterpret_f16_s16(T a)
|
||||
{ return (float16x4_t)a; }
|
||||
template <typename T> static inline float16x4_t vld1_f16(const T* ptr)
|
||||
{ return vreinterpret_f16_s16(vld1_s16((const short*)ptr)); }
|
||||
template <typename T> static inline void vst1_f16(T* ptr, float16x4_t a)
|
||||
{ vst1_s16((short*)ptr, vreinterpret_s16_f16(a)); }
|
||||
template <typename T> static inline float16x4_t cv_vld1_f16(const T* ptr)
|
||||
{
|
||||
#ifndef vld1_f16 // APPLE compiler defines vld1_f16 as macro
|
||||
return vreinterpret_f16_s16(vld1_s16((const short*)ptr));
|
||||
#else
|
||||
return vld1_f16((const __fp16*)ptr);
|
||||
#endif
|
||||
}
|
||||
template <typename T> static inline void cv_vst1_f16(T* ptr, float16x4_t a)
|
||||
{
|
||||
#ifndef vst1_f16 // APPLE compiler defines vst1_f16 as macro
|
||||
vst1_s16((short*)ptr, vreinterpret_s16_f16(a));
|
||||
#else
|
||||
vst1_f16((__fp16*)ptr, a);
|
||||
#endif
|
||||
}
|
||||
|
||||
struct v_float16x4
|
||||
{
|
||||
@@ -299,7 +311,7 @@ struct v_float16x4
|
||||
v_float16x4(short v0, short v1, short v2, short v3)
|
||||
{
|
||||
short v[] = {v0, v1, v2, v3};
|
||||
val = vld1_f16(v);
|
||||
val = cv_vld1_f16(v);
|
||||
}
|
||||
short get0() const
|
||||
{
|
||||
@@ -778,9 +790,9 @@ OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_float64x2, double, f64)
|
||||
#if CV_FP16
|
||||
// Workaround for old comiplers
|
||||
inline v_float16x4 v_load_f16(const short* ptr)
|
||||
{ return v_float16x4(vld1_f16(ptr)); }
|
||||
{ return v_float16x4(cv_vld1_f16(ptr)); }
|
||||
inline void v_store_f16(short* ptr, v_float16x4& a)
|
||||
{ vst1_f16(ptr, a.val); }
|
||||
{ cv_vst1_f16(ptr, a.val); }
|
||||
#endif
|
||||
|
||||
#define OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(_Tpvec, _Tpnvec, scalartype, func, vectorfunc, suffix) \
|
||||
|
||||
@@ -108,11 +108,6 @@ void cvtScaleHalf_SIMD16f32f( const short* src, size_t sstep, float* dst, size_t
|
||||
#elif CV_NEON
|
||||
const static int cVectorWidth = 4;
|
||||
|
||||
template <typename T> static inline float16x4_t vld1_f16(const T* ptr)
|
||||
{ return (float16x4_t)vld1_s16((const short*)ptr); }
|
||||
template <typename T> static inline void vst1_f16(T* ptr, float16x4_t a)
|
||||
{ vst1_s16((short*)ptr, a); }
|
||||
|
||||
void cvtScaleHalf_SIMD32f16f( const float* src, size_t sstep, short* dst, size_t dstep, cv::Size size )
|
||||
{
|
||||
CV_INSTRUMENT_REGION()
|
||||
@@ -129,7 +124,7 @@ void cvtScaleHalf_SIMD32f16f( const float* src, size_t sstep, short* dst, size_t
|
||||
|
||||
float16x4_t v_dst = vcvt_f16_f32(v_src);
|
||||
|
||||
vst1_f16((__fp16*)dst + x, v_dst);
|
||||
cv_vst1_f16((__fp16*)dst + x, v_dst);
|
||||
}
|
||||
|
||||
for ( ; x < size.width; x++ )
|
||||
@@ -151,7 +146,7 @@ void cvtScaleHalf_SIMD16f32f( const short* src, size_t sstep, float* dst, size_t
|
||||
int x = 0;
|
||||
for ( ; x <= size.width - cVectorWidth ; x += cVectorWidth )
|
||||
{
|
||||
float16x4_t v_src = vld1_f16((__fp16*)src + x);
|
||||
float16x4_t v_src = cv_vld1_f16((__fp16*)src + x);
|
||||
|
||||
float32x4_t v_dst = vcvt_f32_f16(v_src);
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ const unsigned int kBiasFp32Exponent = 127;
|
||||
#endif
|
||||
|
||||
#if CV_FP16_TYPE
|
||||
float convertFp16SW(short fp16)
|
||||
inline float convertFp16SW(short fp16)
|
||||
{
|
||||
// Fp16 -> Fp32
|
||||
Cv16suf a;
|
||||
@@ -21,7 +21,7 @@ float convertFp16SW(short fp16)
|
||||
return (float)a.h;
|
||||
}
|
||||
#else
|
||||
float convertFp16SW(short fp16)
|
||||
inline float convertFp16SW(short fp16)
|
||||
{
|
||||
// Fp16 -> Fp32
|
||||
Cv16suf b;
|
||||
@@ -75,7 +75,7 @@ float convertFp16SW(short fp16)
|
||||
#endif
|
||||
|
||||
#if CV_FP16_TYPE
|
||||
short convertFp16SW(float fp32)
|
||||
inline short convertFp16SW(float fp32)
|
||||
{
|
||||
// Fp32 -> Fp16
|
||||
Cv16suf a;
|
||||
@@ -83,7 +83,7 @@ short convertFp16SW(float fp32)
|
||||
return a.i;
|
||||
}
|
||||
#else
|
||||
short convertFp16SW(float fp32)
|
||||
inline short convertFp16SW(float fp32)
|
||||
{
|
||||
// Fp32 -> Fp16
|
||||
Cv32suf a;
|
||||
|
||||
@@ -73,7 +73,7 @@ Mutex* __initialization_mutex_initializer = &getInitializationMutex();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined ANDROID
|
||||
#if defined ANDROID && defined HAVE_CPUFEATURES
|
||||
# include <cpu-features.h>
|
||||
#endif
|
||||
|
||||
@@ -450,11 +450,27 @@ struct HWFeatures
|
||||
have[CV_CPU_NEON] = true;
|
||||
have[CV_CPU_FP16] = true;
|
||||
#elif defined __arm__ && defined __ANDROID__
|
||||
#if defined HAVE_CPUFEATURES
|
||||
__android_log_print(ANDROID_LOG_INFO, "OpenCV", "calling android_getCpuFeatures() ...");
|
||||
uint64_t features = android_getCpuFeatures();
|
||||
__android_log_print(ANDROID_LOG_INFO, "OpenCV", "calling android_getCpuFeatures() ... Done (%llx)", features);
|
||||
have[CV_CPU_NEON] = (features & ANDROID_CPU_ARM_FEATURE_NEON) != 0;
|
||||
have[CV_CPU_FP16] = (features & ANDROID_CPU_ARM_FEATURE_VFP_FP16) != 0;
|
||||
#else
|
||||
__android_log_print(ANDROID_LOG_INFO, "OpenCV", "cpufeatures library is not avaialble for CPU detection");
|
||||
#if CV_NEON
|
||||
__android_log_print(ANDROID_LOG_INFO, "OpenCV", "- NEON instructions is enabled via build flags");
|
||||
have[CV_CPU_NEON] = true;
|
||||
#else
|
||||
__android_log_print(ANDROID_LOG_INFO, "OpenCV", "- NEON instructions is NOT enabled via build flags");
|
||||
#endif
|
||||
#if CV_FP16
|
||||
__android_log_print(ANDROID_LOG_INFO, "OpenCV", "- FP16 instructions is enabled via build flags");
|
||||
have[CV_CPU_FP16] = true;
|
||||
#else
|
||||
__android_log_print(ANDROID_LOG_INFO, "OpenCV", "- FP16 instructions is NOT enabled via build flags");
|
||||
#endif
|
||||
#endif
|
||||
#elif defined __arm__
|
||||
int cpufile = open("/proc/self/auxv", O_RDONLY);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user