From: Ilya Lavrenov Date: Tue, 30 Dec 2014 13:53:19 +0000 (+0300) Subject: NEON detection in runtime X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~2716^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=81f786393a586e9d2a98180d869759fbdac00d53;p=platform%2Fupstream%2Fopencv.git NEON detection in runtime --- diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp index d9a2087..b4484f9 100644 --- a/modules/core/src/system.cpp +++ b/modules/core/src/system.cpp @@ -48,6 +48,13 @@ # endif #endif +#if defined ANDROID || defined __linux__ +# include +# include +# include +# include +#endif + #if defined WIN32 || defined _WIN32 || defined WINCE #ifndef _WIN32_WINNT // This is needed for the declaration of TryEnterCriticalSection in winbase.h with Visual Studio 2005 (and older?) #define _WIN32_WINNT 0x0400 // http://msdn.microsoft.com/en-us/library/ms686857(VS.85).aspx @@ -253,6 +260,29 @@ struct HWFeatures f.have[CV_CPU_AVX] = (((cpuid_data[2] & (1<<28)) != 0)&&((cpuid_data[2] & (1<<27)) != 0));//OS uses XSAVE_XRSTORE and CPU support AVX } + #if defined ANDROID || defined __linux__ + int cpufile = open("/proc/self/auxv", O_RDONLY); + + if (cpufile >= 0) + { + Elf32_auxv_t auxv; + const size_t size_auxv_t = sizeof(Elf32_auxv_t); + + while (read(cpufile, &auxv, sizeof(Elf32_auxv_t)) == size_auxv_t) + { + if (auxv.a_type == AT_HWCAP) + { + f.have[CV_CPU_NEON] = (auxv.a_un.a_val & 4096) != 0; + break; + } + } + + close(cpufile); + } + #elif (defined __clang__ || defined __APPLE__) && defined __ARM_NEON__ + f.have[CV_CPU_NEON] = true; + #endif + return f; } diff --git a/modules/imgproc/src/filter.cpp b/modules/imgproc/src/filter.cpp index f376507..63a1005 100644 --- a/modules/imgproc/src/filter.cpp +++ b/modules/imgproc/src/filter.cpp @@ -2231,9 +2231,8 @@ struct SymmRowSmallVec_8u32s int operator()(const uchar* src, uchar* _dst, int width, int cn) const { - //Uncomment the two following lines when runtime support for neon is implemented. - // if( !checkHardwareSupport(CV_CPU_NEON) ) - // return 0; + if( !checkHardwareSupport(CV_CPU_NEON) ) + return 0; int i = 0, _ksize = kernel.rows + kernel.cols - 1; int* dst = (int*)_dst; @@ -2459,9 +2458,8 @@ struct SymmColumnVec_32s8u int operator()(const uchar** _src, uchar* dst, int width) const { - //Uncomment the two following lines when runtime support for neon is implemented. - // if( !checkHardwareSupport(CV_CPU_NEON) ) - // return 0; + if( !checkHardwareSupport(CV_CPU_NEON) ) + return 0; int _ksize = kernel.rows + kernel.cols - 1; int ksize2 = _ksize / 2; @@ -2612,9 +2610,8 @@ struct SymmColumnSmallVec_32s16s int operator()(const uchar** _src, uchar* _dst, int width) const { - //Uncomment the two following lines when runtime support for neon is implemented. - // if( !checkHardwareSupport(CV_CPU_NEON) ) - // return 0; + if( !checkHardwareSupport(CV_CPU_NEON) ) + return 0; int ksize2 = (kernel.rows + kernel.cols - 1)/2; const float* ky = kernel.ptr() + ksize2; @@ -2788,15 +2785,13 @@ struct SymmColumnVec_32f16s kernel = _kernel; delta = (float)_delta; CV_Assert( (symmetryType & (KERNEL_SYMMETRICAL | KERNEL_ASYMMETRICAL)) != 0 ); - //Uncomment the following line when runtime support for neon is implemented. - // neon_supported = checkHardwareSupport(CV_CPU_NEON); + neon_supported = checkHardwareSupport(CV_CPU_NEON); } int operator()(const uchar** _src, uchar* _dst, int width) const { - //Uncomment the two following lines when runtime support for neon is implemented. - // if( !neon_supported ) - // return 0; + if( !neon_supported ) + return 0; int _ksize = kernel.rows + kernel.cols - 1; int ksize2 = _ksize / 2; @@ -2943,9 +2938,8 @@ struct SymmRowSmallVec_32f int operator()(const uchar* _src, uchar* _dst, int width, int cn) const { - //Uncomment the two following lines when runtime support for neon is implemented. - // if( !checkHardwareSupport(CV_CPU_NEON) ) - // return 0; + if( !checkHardwareSupport(CV_CPU_NEON) ) + return 0; int i = 0, _ksize = kernel.rows + kernel.cols - 1; float* dst = (float*)_dst; diff --git a/modules/ts/src/ts_func.cpp b/modules/ts/src/ts_func.cpp index 7745c86..03877c0 100644 --- a/modules/ts/src/ts_func.cpp +++ b/modules/ts/src/ts_func.cpp @@ -3020,7 +3020,7 @@ void printVersionInfo(bool useStdOut) if (checkHardwareSupport(CV_CPU_AVX)) cpu_features += " avx"; #endif #if CV_NEON - cpu_features += " neon"; // NEON is currently not checked at runtime + if (checkHardwareSupport(CV_CPU_NEON)) cpu_features += " neon"; #endif cpu_features.erase(0, 1); // erase initial space