Home | History | Annotate | Download | only in optimized
      1 /* Copyright 2017 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 #ifndef TENSORFLOW_CONTRIB_LITE_KERNELS_INTERNAL_OPTIMIZED_CPU_CHECK_
     16 #define TENSORFLOW_CONTRIB_LITE_KERNELS_INTERNAL_OPTIMIZED_CPU_CHECK_
     17 
     18 namespace tflite {
     19 
     20 #ifdef __ANDROID__
     21 
     22 // Runtime check for Neon support on Android.
     23 inline bool TestCPUFeatureNeon() {
     24 #if defined(__aarch64__) || defined(__ARM_NEON__)
     25   // ARM-64 always has NEON support.
     26   return true;
     27 #else
     28   return false;
     29 #endif
     30 }
     31 
     32 #elif defined USE_NEON || defined __ARM_NEON
     33 
     34 inline bool TestCPUFeatureNeon() { return true; }
     35 
     36 #else
     37 
     38 inline bool TestCPUFeatureNeon() { return false; }
     39 
     40 #endif
     41 
     42 }  // namespace tflite
     43 
     44 // NEON_OR_PORTABLE(SomeFunc, arcs) calls NeonSomeFunc(args) if Neon is both
     45 // enabled at build time and detected at runtime, or PortableSomeFunc(args)
     46 // otherwise.
     47 #ifdef __ARM_ARCH_5TE__
     48 // Neon isn't available at all on ARMv5.
     49 #define NEON_OR_PORTABLE(funcname, ...) Portable##funcname(__VA_ARGS__)
     50 #else
     51 #define NEON_OR_PORTABLE(funcname, ...)              \
     52   TestCPUFeatureNeon() ? Neon##funcname(__VA_ARGS__) \
     53                        : Portable##funcname(__VA_ARGS__)
     54 #endif
     55 
     56 #endif  // TENSORFLOW_CONTRIB_LITE_KERNELS_INTERNAL_OPTIMIZED_CPU_CHECK_
     57