Bug in hardware ratings fixed.

This commit is contained in:
Alexander Smorkalov 2013-01-22 15:53:07 +04:00
parent 8c44e1ff81
commit 9f01074f4c
5 changed files with 54 additions and 31 deletions

View File

@ -5,5 +5,3 @@ mkdir -p build_service
cd build_service cd build_service
cmake -DCMAKE_TOOLCHAIN_FILE=../android.toolchain.cmake -DANDROID_TOOLCHAIN_NAME="arm-linux-androideabi-4.4.3" -DANDROID_STL=stlport_static -DANDROID_STL_FORCE_FEATURES=OFF -DBUILD_ANDROID_SERVICE=ON -DANDROID_SOURCE_TREE=~/Projects/AndroidSource/ServiceStub/ $@ ../.. cmake -DCMAKE_TOOLCHAIN_FILE=../android.toolchain.cmake -DANDROID_TOOLCHAIN_NAME="arm-linux-androideabi-4.4.3" -DANDROID_STL=stlport_static -DANDROID_STL_FORCE_FEATURES=OFF -DBUILD_ANDROID_SERVICE=ON -DANDROID_SOURCE_TREE=~/Projects/AndroidSource/ServiceStub/ $@ ../..
#-DANDROID_TOOLCHAIN_NAME="arm-linux-androideabi-4.4.3"

View File

@ -64,12 +64,12 @@ get_target_property(engine_lib_location ${engine}_jni LOCATION)
add_custom_command(TARGET ${engine}_jni POST_BUILD COMMAND ${CMAKE_STRIP} --strip-unneeded "${engine_lib_location}") add_custom_command(TARGET ${engine}_jni POST_BUILD COMMAND ${CMAKE_STRIP} --strip-unneeded "${engine_lib_location}")
# native tests # native tests
add_definitions(-DGTEST_HAS_CLONE=0 -DGTEST_OS_LINUX_ANDROID=1 -DGTEST_HAS_TR1_TUPLE=0) add_definitions(-DGTEST_HAS_CLONE=0 -DANDROID -DGTEST_HAS_TR1_TUPLE=0)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-allow-shlib-undefined") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-allow-shlib-undefined")
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/jni/Tests) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/jni/Tests)
file(GLOB engine_test_files "jni/Tests/*.cpp") file(GLOB engine_test_files "jni/Tests/*.cpp")
add_executable(opencv_engine_test ${engine_test_files} jni/Tests/gtest/gtest-all.cpp) add_executable(opencv_test_engine ${engine_test_files} jni/Tests/gtest/gtest-all.cpp)
target_link_libraries(opencv_engine_test z binder log utils android_runtime ${engine} ${engine}_jni) target_link_libraries(opencv_test_engine z binder log utils android_runtime ${engine} ${engine}_jni)

View File

@ -80,17 +80,21 @@ string CommonPackageManager::GetPackagePathByVersion(int version, int platform,
if (!packages.empty()) if (!packages.empty())
{ {
int OptRating = -1; int platform_group = 0;
int OptVersion = 0;
std::vector<std::pair<int, int> >& group = CommonPackageManager::ArmRating;
if ((cpu_id & ARCH_X86) || (cpu_id & ARCH_X64)) if ((cpu_id & ARCH_X86) || (cpu_id & ARCH_X64))
group = CommonPackageManager::IntelRating; platform_group = 1;
int HardwareRating = GetHardwareRating(platform, cpu_id, group); if (cpu_id & ARCH_MIPS)
LOGD("Current hardware platform rating %d for (%d,%d)", HardwareRating, platform, cpu_id); platform_group = 2;
if (-1 == HardwareRating) int opt_rating = -1;
int opt_version = 0;
const int hardware_rating = GetHardwareRating(platform, cpu_id, ArchRatings[platform_group]);
LOGD("Current hardware platform rating %d for (%d,%d)", hardware_rating, platform, cpu_id);
if (-1 == hardware_rating)
{ {
LOGE("Cannot calculate rating for current hardware platform!"); LOGE("Cannot calculate rating for current hardware platform!");
} }
@ -99,26 +103,38 @@ string CommonPackageManager::GetPackagePathByVersion(int version, int platform,
vector<PackageInfo>::iterator found = packages.end(); vector<PackageInfo>::iterator found = packages.end();
for (vector<PackageInfo>::iterator it = packages.begin(); it != packages.end(); ++it) for (vector<PackageInfo>::iterator it = packages.begin(); it != packages.end(); ++it)
{ {
int PackageRating = GetHardwareRating(it->GetPlatform(), it->GetCpuID(), group); int package_group = 0;
LOGD("Package \"%s\" rating %d for (%d,%d)", it->GetFullName().c_str(), PackageRating, it->GetPlatform(), it->GetCpuID());
if ((PackageRating >= 0) && (PackageRating <= HardwareRating)) if ((it->GetCpuID() & ARCH_X86) || (it->GetCpuID() & ARCH_X64))
package_group = 1;
if (it->GetCpuID() & ARCH_MIPS)
package_group = 2;
if (package_group != platform_group)
continue;
const int package_rating = GetHardwareRating(it->GetPlatform(), it->GetCpuID(), ArchRatings[package_group]);
LOGD("Package \"%s\" rating %d for (%d,%d)", it->GetFullName().c_str(), package_rating, it->GetPlatform(), it->GetCpuID());
if ((package_rating >= 0) && (package_rating <= hardware_rating))
{ {
if (((it->GetVersion() >= OptVersion) && (PackageRating >= OptRating)) || (it->GetVersion() > OptVersion)) if (((it->GetVersion() >= opt_version) && (package_rating >= opt_rating)) || (it->GetVersion() > opt_version))
{ {
OptRating = PackageRating; opt_rating = package_rating;
OptVersion = it->GetVersion(); opt_version = it->GetVersion();
found = it; found = it;
} }
} }
} }
if ((-1 != OptRating) && (packages.end() != found)) if ((-1 != opt_rating) && (packages.end() != found))
{ {
result = found->GetInstalationPath(); result = found->GetInstalationPath();
} }
else else
{ {
LOGI("Found package is incompatible with current hardware platform"); LOGI("No compatible packages found!");
} }
} }
} }
@ -146,10 +162,13 @@ int CommonPackageManager::GetHardwareRating(int platform, int cpu_id, const std:
else else
{ {
// Calculate rating for Arm // Calculate rating for Arm
LOGD("!!! Calculating rating for ARM\n");
for (size_t i = 0; i < group.size(); i++) for (size_t i = 0; i < group.size(); i++)
{ {
LOGD("Checking (%d, %d) against (%d,%d)\n", group[i].first, group[i].second, platform, cpu_id);
if (group[i] == std::pair<int, int>(platform, cpu_id)) if (group[i] == std::pair<int, int>(platform, cpu_id))
{ {
LOGD("Rating found: %d\n", i);
result = i; result = i;
break; break;
} }
@ -182,21 +201,27 @@ std::vector<std::pair<int, int> > CommonPackageManager::InitArmRating()
return result; return result;
} }
// Stub for Intel platforms rating initialization. Common package for all Intel based devices is used now
std::vector<std::pair<int, int> > CommonPackageManager::InitIntelRating() std::vector<std::pair<int, int> > CommonPackageManager::InitIntelRating()
{ {
std::vector<std::pair<int, int> > result; std::vector<std::pair<int, int> > result;
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_X64)); return result;
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_X86 | FEATURES_HAS_SSSE3)); }
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_X86 | FEATURES_HAS_SSE2));
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_X86 | FEATURES_HAS_SSE)); // Stub for MIPS platforms rating initialization. Common package for all MIPS based devices is used now
result.push_back(std::pair<int, int>(PLATFORM_UNKNOWN, ARCH_X86)); std::vector<std::pair<int, int> > CommonPackageManager::InitMipsRating()
{
std::vector<std::pair<int, int> > result;
return result; return result;
} }
std::vector<std::pair<int, int> > CommonPackageManager::IntelRating = CommonPackageManager::InitIntelRating(); const std::vector<std::pair<int, int> > CommonPackageManager::ArchRatings[] = {
std::vector<std::pair<int, int> > CommonPackageManager::ArmRating = InitArmRating(); CommonPackageManager::InitArmRating(),
CommonPackageManager::InitIntelRating(),
CommonPackageManager::InitMipsRating()
};
CommonPackageManager::~CommonPackageManager() CommonPackageManager::~CommonPackageManager()
{ {

View File

@ -16,11 +16,11 @@ public:
virtual ~CommonPackageManager(); virtual ~CommonPackageManager();
protected: protected:
static std::vector<std::pair<int, int> > ArmRating; static const std::vector<std::pair<int, int> > ArchRatings[];
static std::vector<std::pair<int, int> > IntelRating;
static std::vector<std::pair<int, int> > InitArmRating(); static std::vector<std::pair<int, int> > InitArmRating();
static std::vector<std::pair<int, int> > InitIntelRating(); static std::vector<std::pair<int, int> > InitIntelRating();
static std::vector<std::pair<int, int> > InitMipsRating();
bool IsVersionCompatible(int target_version, int package_version); bool IsVersionCompatible(int target_version, int package_version);
int GetHardwareRating(int platform, int cpu_id, const std::vector<std::pair<int, int> >& group); int GetHardwareRating(int platform, int cpu_id, const std::vector<std::pair<int, int> >& group);

View File

@ -126,7 +126,7 @@ TEST(CpuID, CheckNotEmpy)
EXPECT_NE(0, cpu_id); EXPECT_NE(0, cpu_id);
} }
#ifdef __i386__ #if defined(__i386__)
TEST(CpuID, CheckX86) TEST(CpuID, CheckX86)
{ {
int cpu_id = GetCpuID(); int cpu_id = GetCpuID();
@ -138,7 +138,7 @@ TEST(CpuID, CheckSSE2)
int cpu_id = GetCpuID(); int cpu_id = GetCpuID();
EXPECT_TRUE(cpu_id & FEATURES_HAS_SSE2); EXPECT_TRUE(cpu_id & FEATURES_HAS_SSE2);
} }
#elseif __mips #elif defined(__mips)
#ifdef __SUPPORT_MIPS #ifdef __SUPPORT_MIPS
TEST(CpuID, CheckMips) TEST(CpuID, CheckMips)
{ {