From fca1f006d833d966803341296522de0506127622 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Mon, 18 Mar 2013 12:12:17 +0400 Subject: [PATCH] Tegra4 support added. --- .../jni/BinderComponent/HardwareDetector.cpp | 15 +++---------- .../jni/BinderComponent/HardwareDetector.h | 1 + .../jni/BinderComponent/TegraDetector.cpp | 8 +++++++ .../NativeService/CommonPackageManager.cpp | 5 +++-- .../engine/jni/NativeService/PackageInfo.cpp | 9 ++++++++ .../engine/jni/NativeService/PackageInfo.h | 3 +-- .../engine/jni/Tests/OpenCVEngineTest.cpp | 18 +++++++++++++++ .../engine/jni/Tests/PackageInfoTest.cpp | 22 +++++++++++++++++++ .../engine/jni/Tests/PackageManagmentTest.cpp | 16 ++++++++++++++ .../org/opencv/engine/HardwareDetector.java | 2 ++ .../engine/manager/ManagerActivity.java | 10 ++++++--- 11 files changed, 90 insertions(+), 19 deletions(-) diff --git a/android/service/engine/jni/BinderComponent/HardwareDetector.cpp b/android/service/engine/jni/BinderComponent/HardwareDetector.cpp index b5e0fa6001..eab49ac5f3 100644 --- a/android/service/engine/jni/BinderComponent/HardwareDetector.cpp +++ b/android/service/engine/jni/BinderComponent/HardwareDetector.cpp @@ -163,22 +163,13 @@ int DetectKnownPlatforms() { int tegra_status = DetectTegra(); - if (3 == tegra_status) + // All Tegra platforms since Tegra3 + if (2 < tegra_status) { - return PLATFORM_TEGRA3; + return PLATFORM_TEGRA + tegra_status - 1; } else { return PLATFORM_UNKNOWN; } - - // NOTE: Uncomment when all Tegras will be supported - /*if (tegra_status > 0) - * { - * return PLATFORM_TEGRA + tegra_status - 1; - } - else - { - return PLATFORM_UNKNOWN; - }*/ } \ No newline at end of file diff --git a/android/service/engine/jni/BinderComponent/HardwareDetector.h b/android/service/engine/jni/BinderComponent/HardwareDetector.h index e049db9c5f..135684418b 100644 --- a/android/service/engine/jni/BinderComponent/HardwareDetector.h +++ b/android/service/engine/jni/BinderComponent/HardwareDetector.h @@ -27,6 +27,7 @@ #define PLATFORM_TEGRA 1L #define PLATFORM_TEGRA2 2L #define PLATFORM_TEGRA3 3L +#define PLATFORM_TEGRA4 4L int DetectKnownPlatforms(); int GetProcessorCount(); diff --git a/android/service/engine/jni/BinderComponent/TegraDetector.cpp b/android/service/engine/jni/BinderComponent/TegraDetector.cpp index f7db1fa85d..3933efe499 100644 --- a/android/service/engine/jni/BinderComponent/TegraDetector.cpp +++ b/android/service/engine/jni/BinderComponent/TegraDetector.cpp @@ -7,6 +7,7 @@ #define KERNEL_CONFIG_TEGRA_MAGIC "CONFIG_ARCH_TEGRA=y" #define KERNEL_CONFIG_TEGRA2_MAGIC "CONFIG_ARCH_TEGRA_2x_SOC=y" #define KERNEL_CONFIG_TEGRA3_MAGIC "CONFIG_ARCH_TEGRA_3x_SOC=y" +#define KERNEL_CONFIG_TEGRA4_MAGIC "CONFIG_ARCH_TEGRA_11x_SOC=y" #define MAX_DATA_LEN 4096 int DetectTegra() @@ -19,9 +20,11 @@ int DetectTegra() const char *tegra_config = KERNEL_CONFIG_TEGRA_MAGIC; const char *tegra2_config = KERNEL_CONFIG_TEGRA2_MAGIC; const char *tegra3_config = KERNEL_CONFIG_TEGRA3_MAGIC; + const char *tegra4_config = KERNEL_CONFIG_TEGRA4_MAGIC; int len = strlen(tegra_config); int len2 = strlen(tegra2_config); int len3 = strlen(tegra3_config); + int len4 = strlen(tegra4_config); while (0 != gzgets(kernelConfig, tmpbuf, KERNEL_CONFIG_MAX_LINE_WIDTH)) { if (0 == strncmp(tmpbuf, tegra_config, len)) @@ -41,6 +44,11 @@ int DetectTegra() break; } + if (0 == strncmp(tmpbuf, tegra4_config, len4)) + { + result = 4; + break; + } } gzclose(kernelConfig); } diff --git a/android/service/engine/jni/NativeService/CommonPackageManager.cpp b/android/service/engine/jni/NativeService/CommonPackageManager.cpp index dbcd8ff689..eaa03d4d82 100644 --- a/android/service/engine/jni/NativeService/CommonPackageManager.cpp +++ b/android/service/engine/jni/NativeService/CommonPackageManager.cpp @@ -197,6 +197,7 @@ std::vector > CommonPackageManager::InitArmRating() result.push_back(std::pair(PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_VFPv3 | FEATURES_HAS_NEON)); result.push_back(std::pair(PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_VFPv3 | FEATURES_HAS_VFPv3d16 | FEATURES_HAS_NEON)); result.push_back(std::pair(PLATFORM_TEGRA3, ARCH_ARMv7 | FEATURES_HAS_VFPv3 | FEATURES_HAS_NEON)); + result.push_back(std::pair(PLATFORM_TEGRA4, ARCH_ARMv7 | FEATURES_HAS_VFPv3 | FEATURES_HAS_NEON)); return result; } @@ -218,8 +219,8 @@ std::vector > CommonPackageManager::InitMipsRating() } const std::vector > CommonPackageManager::ArchRatings[] = { - CommonPackageManager::InitArmRating(), - CommonPackageManager::InitIntelRating(), + CommonPackageManager::InitArmRating(), + CommonPackageManager::InitIntelRating(), CommonPackageManager::InitMipsRating() }; diff --git a/android/service/engine/jni/NativeService/PackageInfo.cpp b/android/service/engine/jni/NativeService/PackageInfo.cpp index 2eb8230739..2f8dde043a 100644 --- a/android/service/engine/jni/NativeService/PackageInfo.cpp +++ b/android/service/engine/jni/NativeService/PackageInfo.cpp @@ -18,6 +18,7 @@ map PackageInfo::InitPlatformNameMap() result[PLATFORM_TEGRA] = PLATFORM_TEGRA_NAME; result[PLATFORM_TEGRA2] = PLATFORM_TEGRA2_NAME; result[PLATFORM_TEGRA3] = PLATFORM_TEGRA3_NAME; + result[PLATFORM_TEGRA4] = PLATFORM_TEGRA4_NAME; return result; } @@ -186,6 +187,10 @@ inline int SplitPlatfrom(const vector& features) { result = PLATFORM_TEGRA3; } + else if (PLATFORM_TEGRA4_NAME == tmp) + { + result = PLATFORM_TEGRA4; + } } else { @@ -425,6 +430,10 @@ InstallPath(install_path) { CpuID = ARCH_ARMv7 | FEATURES_HAS_VFPv3 | FEATURES_HAS_NEON; } break; + case PLATFORM_TEGRA4: + { + CpuID = ARCH_ARMv7 | FEATURES_HAS_VFPv3 | FEATURES_HAS_NEON; + } break; } } else diff --git a/android/service/engine/jni/NativeService/PackageInfo.h b/android/service/engine/jni/NativeService/PackageInfo.h index b86ef7a92e..2ce561e2f3 100644 --- a/android/service/engine/jni/NativeService/PackageInfo.h +++ b/android/service/engine/jni/NativeService/PackageInfo.h @@ -12,7 +12,6 @@ #define ARCH_ARMv7_NAME "armv7a" #define ARCH_ARMv8_NAME "armv8" - #define FEATURES_HAS_VFPv3d16_NAME "vfpv3d16" #define FEATURES_HAS_VFPv3_NAME "vfpv3" #define FEATURES_HAS_NEON_NAME "neon" @@ -25,7 +24,7 @@ #define PLATFORM_TEGRA_NAME "tegra" #define PLATFORM_TEGRA2_NAME "tegra2" #define PLATFORM_TEGRA3_NAME "tegra3" - +#define PLATFORM_TEGRA4_NAME "tegra4" class PackageInfo { diff --git a/android/service/engine/jni/Tests/OpenCVEngineTest.cpp b/android/service/engine/jni/Tests/OpenCVEngineTest.cpp index 4e390386fe..ce5159f818 100644 --- a/android/service/engine/jni/Tests/OpenCVEngineTest.cpp +++ b/android/service/engine/jni/Tests/OpenCVEngineTest.cpp @@ -201,6 +201,24 @@ TEST(OpenCVEngineTest, GetPathForCompatiblePackage2) #endif } +TEST(OpenCVEngineTest, GetPathForCompatiblePackage3) +{ + sp Engine = InitConnect(); + Starter.PackageManager->InstalledPackages.clear(); + Starter.PackageManager->InstallVersion(2040400, PLATFORM_TEGRA4, ARCH_ARMv7 | FEATURES_HAS_VFPv3 | FEATURES_HAS_NEON); + EXPECT_FALSE(NULL == Engine.get()); + String16 result = Engine->GetLibPathByVersion(String16("2.4")); + #ifdef __SUPPORT_TEGRA3 + EXPECT_STREQ("/data/data/org.opencv.lib_v24_tegra4/lib", String8(result).string()); + #else + #ifdef __SUPPORT_ARMEABI_V7A_FEATURES + EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv7a_neon/lib", String8(result).string()); + #else + EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv7a/lib", String8(result).string()); + #endif + #endif +} + TEST(OpenCVEngineTest, InstallAndGetVersion) { sp Engine = InitConnect(); diff --git a/android/service/engine/jni/Tests/PackageInfoTest.cpp b/android/service/engine/jni/Tests/PackageInfoTest.cpp index 6bc84856ce..6cbb069431 100644 --- a/android/service/engine/jni/Tests/PackageInfoTest.cpp +++ b/android/service/engine/jni/Tests/PackageInfoTest.cpp @@ -85,6 +85,21 @@ TEST(PackageInfo, FullNameTegra3) #endif } +TEST(PackageInfo, FullNameTegra4) +{ + PackageInfo info(2040400, PLATFORM_TEGRA4, ARCH_ARMv7 | FEATURES_HAS_NEON); + string name = info.GetFullName(); + #ifdef __SUPPORT_TEGRA3 + EXPECT_STREQ("org.opencv.lib_v24_tegra4", name.c_str()); + #else + #ifdef __SUPPORT_ARMEABI_V7A_FEATURES + EXPECT_STREQ("org.opencv.lib_v24_armv7a_neon", name.c_str()); + #else + EXPECT_STREQ("org.opencv.lib_v24_armv7a", name.c_str()); + #endif + #endif +} + TEST(PackageInfo, FullNameX86SSE2) { PackageInfo info(2030000, PLATFORM_UNKNOWN, ARCH_X86 | FEATURES_HAS_SSE2); @@ -148,6 +163,13 @@ TEST(PackageInfo, Tegra3FromFullName) EXPECT_EQ(PLATFORM_TEGRA3, info.GetPlatform()); } +TEST(PackageInfo, Tegra4FromFullName) +{ + PackageInfo info("org.opencv.lib_v24_tegra4", "/data/data/org.opencv.lib_v24_tegra4"); + EXPECT_EQ(2040000, info.GetVersion()); + EXPECT_EQ(PLATFORM_TEGRA4, info.GetPlatform()); +} + #ifdef __SUPPORT_MIPS TEST(PackageInfo, MipsFromFullName) { diff --git a/android/service/engine/jni/Tests/PackageManagmentTest.cpp b/android/service/engine/jni/Tests/PackageManagmentTest.cpp index f9ccb74844..e21dcf7604 100644 --- a/android/service/engine/jni/Tests/PackageManagmentTest.cpp +++ b/android/service/engine/jni/Tests/PackageManagmentTest.cpp @@ -102,6 +102,22 @@ TEST(PackageManager, GetPackagePathForTegra3) #endif } +TEST(PackageManager, GetPackagePathForTegra4) +{ + PackageManagerStub pm; + EXPECT_TRUE(pm.InstallVersion(2040400, PLATFORM_TEGRA4, ARCH_ARMv7 | FEATURES_HAS_VFPv3 | FEATURES_HAS_NEON)); + string path = pm.GetPackagePathByVersion(2040400, PLATFORM_TEGRA4, ARCH_ARMv7 | FEATURES_HAS_VFPv3 | FEATURES_HAS_NEON); + #ifdef __SUPPORT_TEGRA3 + EXPECT_STREQ("/data/data/org.opencv.lib_v24_tegra4/lib", path.c_str()); + #else + #ifdef __SUPPORT_ARMEABI_V7A_FEATURES + EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv7a_neon/lib", path.c_str()); + #else + EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv7a/lib", path.c_str()); + #endif + #endif +} + #ifdef __SUPPORT_MIPS TEST(PackageManager, GetPackagePathForMips) { diff --git a/android/service/engine/src/org/opencv/engine/HardwareDetector.java b/android/service/engine/src/org/opencv/engine/HardwareDetector.java index 7e2a6135f9..67320865af 100644 --- a/android/service/engine/src/org/opencv/engine/HardwareDetector.java +++ b/android/service/engine/src/org/opencv/engine/HardwareDetector.java @@ -33,6 +33,8 @@ public class HardwareDetector public static final int PLATFORM_TEGRA = 1; public static final int PLATFORM_TEGRA2 = 2; public static final int PLATFORM_TEGRA3 = 3; + public static final int PLATFORM_TEGRA4 = 4; + public static final int PLATFORM_UNKNOWN = 0; diff --git a/android/service/engine/src/org/opencv/engine/manager/ManagerActivity.java b/android/service/engine/src/org/opencv/engine/manager/ManagerActivity.java index fad2797727..5213d91495 100644 --- a/android/service/engine/src/org/opencv/engine/manager/ManagerActivity.java +++ b/android/service/engine/src/org/opencv/engine/manager/ManagerActivity.java @@ -83,10 +83,14 @@ public class ManagerActivity extends Activity { HardwarePlatformView.setText("Tegra 2"); } - else + else if (HardwareDetector.PLATFORM_TEGRA3 == Platfrom) { HardwarePlatformView.setText("Tegra 3"); } + else + { + HardwarePlatformView.setText("Tegra 4"); + } } else { @@ -367,10 +371,10 @@ public class ManagerActivity extends Activity temp.put("Version", NormalizeVersion(OpenCVersion, VersionName)); // HACK: OpenCV Manager for Armv7-a Neon already has Tegra3 optimizations // that is enabled on proper hardware - if (HardwareDetector.DetectKnownPlatforms() == HardwareDetector.PLATFORM_TEGRA3 && + if (HardwareDetector.DetectKnownPlatforms() >= HardwareDetector.PLATFORM_TEGRA3 && HardwareName.equals("armv7a neon ") && Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { - temp.put("Hardware", "Tegra 3"); + temp.put("Hardware", "Tegra"); if (Tags == null) { Tags = "optimized";