From 7a0db809f3c1c4f385102bc63f276ca43420b312 Mon Sep 17 00:00:00 2001 From: Yongjoo Ahn Date: Wed, 10 Dec 2025 14:26:39 +0900 Subject: [PATCH] [snpe] Add performance profile configuration support usage:`... custom=Runtime:DSP,...,PerfProfile:"burst" ...`" - Add support for configuring SNPE performance profiles through custom properties. - The default performance profile is set to 'BALANCED' REF: ``` typedef enum { SNPE_PERFORMANCE_PROFILE_DEFAULT = 0, SNPE_PERFORMANCE_PROFILE_BALANCED = 0, SNPE_PERFORMANCE_PROFILE_HIGH_PERFORMANCE = 1, SNPE_PERFORMANCE_PROFILE_POWER_SAVER = 2, SNPE_PERFORMANCE_PROFILE_SYSTEM_SETTINGS = 3, SNPE_PERFORMANCE_PROFILE_SUSTAINED_HIGH_PERFORMANCE = 4, SNPE_PERFORMANCE_PROFILE_BURST = 5, SNPE_PERFORMANCE_PROFILE_LOW_POWER_SAVER = 6, SNPE_PERFORMANCE_PROFILE_HIGH_POWER_SAVER = 7, SNPE_PERFORMANCE_PROFILE_LOW_BALANCED = 8, SNPE_PERFORMANCE_PROFILE_EXTREME_POWER_SAVER = 9, } Snpe_PerformanceProfile_t; ``` Signed-off-by: Yongjoo Ahn --- src/hal-backend-ml-snpe.cc | 39 +++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/hal-backend-ml-snpe.cc b/src/hal-backend-ml-snpe.cc index 238c7c1..f7683ec 100644 --- a/src/hal-backend-ml-snpe.cc +++ b/src/hal-backend-ml-snpe.cc @@ -196,6 +196,9 @@ ml_snpe_configure_instance (void *backend_private, const void *prop_) /* default runtime is CPU */ Snpe_Runtime_t runtime = SNPE_RUNTIME_CPU; + /* default performance profile is 'BALANCED' */ + Snpe_PerformanceProfile_t perfProfile = SNPE_PERFORMANCE_PROFILE_BALANCED; + /* lambda function to handle tensor */ auto handleTensor = [&] (const char *tensorName, GstTensorInfo *info, Snpe_UserBufferMap_Handle_t bufferMapHandle, @@ -283,7 +286,7 @@ ml_snpe_configure_instance (void *backend_private, const void *prop_) }; auto parse_custom_prop = [&runtime, &outputstrListHandle, &inputTypeVec, - &outputTypeVec] (const char *custom_prop) { + &outputTypeVec, &perfProfile] (const char *custom_prop) { if (!custom_prop) return; @@ -355,6 +358,36 @@ ml_snpe_configure_instance (void *backend_private, const void *prop_) } } g_strfreev (types); + } else if (g_ascii_strcasecmp (option[0], "PerfProfile") == 0) { + bool _valid = true; + if (g_ascii_strcasecmp (option[1], "BALANCED") == 0) { + perfProfile = SNPE_PERFORMANCE_PROFILE_BALANCED; + } else if (g_ascii_strcasecmp (option[1], "HIGH_PERFORMANCE") == 0) { + perfProfile = SNPE_PERFORMANCE_PROFILE_HIGH_PERFORMANCE; + } else if (g_ascii_strcasecmp (option[1], "POWER_SAVER") == 0) { + perfProfile = SNPE_PERFORMANCE_PROFILE_POWER_SAVER; + } else if (g_ascii_strcasecmp (option[1], "SYSTEM_SETTINGS") == 0) { + perfProfile = SNPE_PERFORMANCE_PROFILE_SYSTEM_SETTINGS; + } else if (g_ascii_strcasecmp (option[1], "SUSTAINED_HIGH_PERFORMANCE") == 0) { + perfProfile = SNPE_PERFORMANCE_PROFILE_SUSTAINED_HIGH_PERFORMANCE; + } else if (g_ascii_strcasecmp (option[1], "BURST") == 0) { + perfProfile = SNPE_PERFORMANCE_PROFILE_BURST; + } else if (g_ascii_strcasecmp (option[1], "LOW_POWER_SAVER") == 0) { + perfProfile = SNPE_PERFORMANCE_PROFILE_LOW_POWER_SAVER; + } else if (g_ascii_strcasecmp (option[1], "HIGH_POWER_SAVER") == 0) { + perfProfile = SNPE_PERFORMANCE_PROFILE_HIGH_POWER_SAVER; + } else if (g_ascii_strcasecmp (option[1], "LOW_BALANCED") == 0) { + perfProfile = SNPE_PERFORMANCE_PROFILE_LOW_BALANCED; + } else if (g_ascii_strcasecmp (option[1], "EXTREME_POWER_SAVER") == 0) { + perfProfile = SNPE_PERFORMANCE_PROFILE_EXTREME_POWER_SAVER; + } else { + _valid = false; + g_warning ("Unknown performance profile (%s), set BALANCED as default.", + options[op]); + } + + if (_valid) + g_info ("Set performance profile to %s", option[1]); } else { g_warning ("Unknown option (%s).", options[op]); } @@ -428,6 +461,10 @@ ml_snpe_configure_instance (void *backend_private, const void *prop_) } } + /* Set Perfornamce Profile */ + if (Snpe_SNPEBuilder_SetPerformanceProfile (snpebuilder_h, perfProfile) != SNPE_SUCCESS) + throw std::runtime_error ("Failed to set performance profile"); + snpe->snpe_h = Snpe_SNPEBuilder_Build (snpebuilder_h); if (!snpe->snpe_h) throw std::runtime_error ("Failed to build SNPE handle");