Merge pull request #3568 from ilya-lavrenov:neon_runtime

This commit is contained in:
Vadim Pisarevsky 2015-01-20 12:47:51 +00:00
commit 21a9a17478
3 changed files with 42 additions and 18 deletions

View File

@ -48,6 +48,13 @@
# endif
#endif
#if defined ANDROID || defined __linux__
# include <unistd.h>
# include <fcntl.h>
# include <elf.h>
# include <linux/auxvec.h>
#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
@ -251,6 +258,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;
}

View File

@ -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<float>() + 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;

View File

@ -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