1 /* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #include "tensorflow/lite/kernels/internal/optimized/cpu_check.h"
17 
18 #if defined __linux__ && defined __aarch64__
19 #include <sys/auxv.h>
20 #endif
21 
22 namespace tflite {
23 
24 namespace {
25 
26 // The implementation of dotprod detection is copied from ruy's internal
27 // function DetectDotprod().
28 // At the moment it's only implemented on Linux ARM64. Consider syncing again
29 // with ruy in the future to share improvements.
30 #if defined __linux__ && defined __aarch64__
DetectDotprodByLinuxAuxvMethod()31 bool DetectDotprodByLinuxAuxvMethod() {
32   // This is the value of HWCAP_ASIMDDP in sufficiently recent Linux headers,
33   // however we need to support building against older headers for the time
34   // being.
35   const int kLocalHwcapAsimddp = 1 << 20;
36   return getauxval(AT_HWCAP) & kLocalHwcapAsimddp;
37 }
38 #endif
39 
40 }  // namespace
41 
DetectArmNeonDotprod()42 bool DetectArmNeonDotprod() {
43 #if defined __linux__ && defined __aarch64__
44   return DetectDotprodByLinuxAuxvMethod();
45 #endif
46 
47   return false;
48 }
49 
50 }  // namespace tflite
51