提交 3dee87b6 编写于 作者: A Alexander Alekhin

update CPU detection on ANDROID patch

上级 bb3a4163
if(NOT ANDROID)
message("cpufeatures is ANDROID project")
endif()
ocv_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
file(GLOB cpuf_s *.c)
file(GLOB cpuf_h *.h)
set(CPUFEATURES_ROOT "${CMAKE_CURRENT_SOURCE_DIR}" CACHE PATH "Android cpufeatures project sources (for example, <android-ndk>/sources/android/cpufeatures)")
set(lib_srcs ${cpuf_s})
set(lib_hdrs ${cpuf_h})
set(CPUFEATURES_INCLUDE_DIRS ${CPUFEATURES_ROOT} CACHE INTERNAL "")
set(CPUFEATURES_LIBRARIES cpufeatures CACHE INTERNAL "")
set(CPUFEATURES_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "")
set(CPUFEATURES_LIBRARIES cpufeatures CACHE INTERNAL "")
if(NOT DEFINED CPUFEATURES_SOURCES)
set(CPUFEATURES_SOURCES ${CPUFEATURES_ROOT}/cpu-features.c ${CPUFEATURES_ROOT}/cpu-features.h)
endif()
add_library(cpufeatures STATIC ${lib_srcs} ${lib_hdrs})
include_directories(${CPUFEATURES_INCLUDE_DIRS})
add_library(cpufeatures STATIC ${CPUFEATURES_SOURCES})
set_target_properties(cpufeatures
PROPERTIES OUTPUT_NAME cpufeatures
......@@ -17,8 +20,8 @@ set_target_properties(cpufeatures
COMPILE_PDB_NAME cpufeatures
COMPILE_PDB_NAME_DEBUG "cpufeatures${OPENCV_DEBUG_POSTFIX}"
ARCHIVE_OUTPUT_DIRECTORY ${3P_LIBRARY_OUTPUT_PATH}
)
)
if(ENABLE_SOLUTION_FOLDERS)
set_target_properties(cpufeatures PROPERTIES FOLDER "3rdparty")
endif()
......@@ -26,4 +29,3 @@ endif()
if(NOT BUILD_SHARED_LIBS)
ocv_install_target(cpufeatures EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev)
endif()
Copyright (C) 2016 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
The Android NDK provides a small library named cpufeatures that your app can use at runtime to detect the target device's CPU family and the optional features it supports.
It is designed to work as-is on all official Android platform versions.
https://developer.android.com/ndk/guides/cpu-features.html
......@@ -5,7 +5,7 @@
project(${WEBP_LIBRARY})
ocv_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
ocv_include_directories("${CPUFEATURES_INCLUDE_DIR}")
ocv_include_directories(${CPUFEATURES_INCLUDE_DIRS})
file(GLOB lib_srcs dec/*.c demux/*.c dsp/*.c enc/*.c mux/*.c utils/*.c webp/*.c)
file(GLOB lib_hdrs dec/*.h demux/*.h dsp/*.h enc/*.h mux/*.h utils/*.h webp/*.h)
......
......@@ -98,6 +98,10 @@ if(POLICY CMP0042)
cmake_policy(SET CMP0042 NEW)
endif()
if(POLICY CMP0046)
cmake_policy(SET CMP0046 OLD)
endif()
if(POLICY CMP0051)
cmake_policy(SET CMP0051 NEW)
endif()
......
......@@ -32,10 +32,10 @@ source_group("Src" FILES "${OPENCV_MODULE_opencv_core_BINARY_DIR}/version_string
ocv_glob_module_sources(SOURCES "${OPENCV_MODULE_opencv_core_BINARY_DIR}/version_string.inc"
HEADERS ${lib_cuda_hdrs} ${lib_cuda_hdrs_detail})
ocv_module_include_directories(${the_module} ${ZLIB_INCLUDE_DIRS} ${OPENCL_INCLUDE_DIRS} ${CPUFEATURES_INCLUDE_DIR})
ocv_module_include_directories(${the_module} ${ZLIB_INCLUDE_DIRS} ${OPENCL_INCLUDE_DIRS} ${CPUFEATURES_INCLUDE_DIRS})
ocv_create_module(${extra_libs})
ocv_target_link_libraries(${the_module} ${ZLIB_LIBRARIES} "${OPENCL_LIBRARIES}" "${VA_LIBRARIES}" "${LAPACK_LIBRARIES}" "${CPUFEATURES_LIBRARIES}")
ocv_target_link_libraries(${the_module} ${ZLIB_LIBRARIES} "${OPENCL_LIBRARIES}" "${VA_LIBRARIES}" "${LAPACK_LIBRARIES}" "${CPUFEATURES_LIBRARIES}")
ocv_add_accuracy_tests()
ocv_add_perf_tests()
......@@ -447,10 +447,16 @@ struct HWFeatures
CV_UNUSED(cpuid_data_ex);
#endif // OPENCV_HAVE_X86_CPUID
#if defined ANDROID || defined __linux__
#if defined __ANDROID__ || defined __linux__
#ifdef __aarch64__
have[CV_CPU_NEON] = true;
have[CV_CPU_FP16] = true;
#elif defined __arm__ && defined __ANDROID__
__android_log_print(ANDROID_LOG_INFO, "OpenCV", "calling android_getCpuFeatures() ...");
uint64_t features = android_getCpuFeatures();
__android_log_print(ANDROID_LOG_INFO, "OpenCV", "calling android_getCpuFeatures() ... Done (%llx)", features);
have[CV_CPU_NEON] = (features & ANDROID_CPU_ARM_FEATURE_NEON) != 0;
have[CV_CPU_FP16] = (features & ANDROID_CPU_ARM_FEATURE_VFP_FP16) != 0;
#elif defined __arm__
int cpufile = open("/proc/self/auxv", O_RDONLY);
......@@ -471,11 +477,6 @@ struct HWFeatures
close(cpufile);
}
#ifdef ANDROID
uint64_t features = android_getCpuFeatures();
have[CV_CPU_NEON] = (features & ANDROID_CPU_ARM_FEATURE_NEON) != 0;
have[CV_CPU_FP16] = (features & ANDROID_CPU_ARM_FEATURE_VFP_FP16) != 0;
#endif
#endif
#elif (defined __clang__ || defined __APPLE__)
#if (defined __ARM_NEON__ || (defined __ARM_NEON && defined __aarch64__))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册