xref: /aosp_15_r20/external/armnn/src/armnn/Utils.cpp (revision 89c4ff92f2867872bb9e2354d150bf0c8c502810)
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #include "armnn/Logging.hpp"
6 #include "armnn/Utils.hpp"
7 #include "armnn/Version.hpp"
8 
9 #if !defined(ARMNN_BUILD_BARE_METAL) && (defined(__arm__) || defined(__aarch64__))
10 
11 #include <sys/auxv.h>
12 #include <asm/hwcap.h>
13 
14 #endif
15 
16 namespace armnn
17 {
ConfigureLogging(bool printToStandardOutput,bool printToDebugOutput,LogSeverity severity)18 void ConfigureLogging(bool printToStandardOutput, bool printToDebugOutput, LogSeverity severity)
19 {
20     SetAllLoggingSinks(printToStandardOutput, printToDebugOutput, false);
21     SetLogFilter(severity);
22 }
23 
24 // Defaults to logging completely disabled.
25 // The user of the library must enable it if they want by calling armnn::ConfigureLogging().
26 struct DefaultLoggingConfiguration
27 {
DefaultLoggingConfigurationarmnn::DefaultLoggingConfiguration28     DefaultLoggingConfiguration()
29     {
30         ConfigureLogging(false, false, LogSeverity::Trace);
31     }
32 };
33 
34 static DefaultLoggingConfiguration g_DefaultLoggingConfiguration;
35 
36 // Detect the presence of Neon on Linux
NeonDetected()37 bool NeonDetected()
38 {
39 #if !defined(ARMNN_BUILD_BARE_METAL) && (defined(__arm__) || defined(__aarch64__))
40     auto hwcaps= getauxval(AT_HWCAP);
41 #endif
42 
43 #if !defined(ARMNN_BUILD_BARE_METAL) && defined(__aarch64__)
44 
45     if (hwcaps & HWCAP_ASIMD)
46     {
47         // On an arm64 device with Neon.
48         return true;
49     }
50     else
51     {
52         // On an arm64 device without Neon.
53         return false;
54     }
55 
56 #endif
57 #if !defined(ARMNN_BUILD_BARE_METAL) && defined(__arm__)
58 
59     if (hwcaps & HWCAP_NEON)
60     {
61         // On an armhf device with Neon.
62         return true;
63     }
64     else
65     {
66         // On an armhf device without Neon.
67         return false;
68     }
69 
70 #endif
71 
72     // This method of Neon detection is only supported on Linux so in order to prevent a false negative
73     // we will return true in cases where detection did not run.
74     return true;
75 }
76 
GetVersion()77 const std::string GetVersion()
78 {
79     return ARMNN_VERSION;
80 }
81 
82 } // namespace armnn
83