From 5dc64fe99227efece77eb7cd14abc47474a48fb8 Mon Sep 17 00:00:00 2001 From: Francis Murtagh Date: Mon, 25 Jan 2021 10:18:10 +0000 Subject: IVGCVSW-5525 Handle Neon optionality on 32 bit linux platforms * Add neon detection for linux using HWCAPs * Add test to check for backend throwing BackendUnavailable exception Signed-off-by: Francis Murtagh Change-Id: Ib74aeb06abe5f88f21ecdd1edb2a1cd20ee2019d --- src/armnn/Utils.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'src/armnn/Utils.cpp') diff --git a/src/armnn/Utils.cpp b/src/armnn/Utils.cpp index 13bf3025f2..62c8ae6262 100644 --- a/src/armnn/Utils.cpp +++ b/src/armnn/Utils.cpp @@ -5,6 +5,13 @@ #include "armnn/Logging.hpp" #include "armnn/Utils.hpp" +#if !defined(BARE_METAL) && (defined(__arm__) || defined(__aarch64__)) + +#include +#include + +#endif + namespace armnn { void ConfigureLogging(bool printToStandardOutput, bool printToDebugOutput, LogSeverity severity) @@ -25,4 +32,45 @@ struct DefaultLoggingConfiguration static DefaultLoggingConfiguration g_DefaultLoggingConfiguration; +// Detect the presence of Neon on Linux +bool NeonDetected() +{ +#if !defined(BARE_METAL) && (defined(__arm__) || defined(__aarch64__)) + auto hwcaps= getauxval(AT_HWCAP); +#endif + +#if !defined(BARE_METAL) && defined(__aarch64__) + + if (hwcaps & HWCAP_ASIMD) + { + // On an arm64 device with Neon. + return true; + } + else + { + // On an arm64 device without Neon. + return false; + } + +#endif +#if !defined(BARE_METAL) && defined(__arm__) + + if (hwcaps & HWCAP_NEON) + { + // On an armhf device with Neon. + return true; + } + else + { + // On an armhf device without Neon. + return false; + } + +#endif + + // This method of Neon detection is only supported on Linux so in order to prevent a false negative + // we will return true in cases where detection did not run. + return true; +} + } // namespace armnn \ No newline at end of file -- cgit v1.2.1