!212 模型共享内存

Merge pull request !212 from wangyifan/master
This commit is contained in:
openharmony_ci 2024-08-29 03:51:08 +00:00 committed by Gitee
commit 04fe5d30a8
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 27 additions and 4 deletions

View File

@ -55,6 +55,7 @@ struct ExtensionConfig {
// inputDims and dynamicDims are used in hiai adapter
std::vector<std::vector<int32_t>> inputDims;
std::vector<std::vector<int32_t>> dynamicDims;
bool isNpuFmShared = false;
};
struct ModelConfig {

View File

@ -40,6 +40,7 @@ const std::string EXTENSION_KEY_IS_PROFILING = "isProfiling";
const std::string EXTENSION_KEY_OP_LAYOUT = "opLayout";
const std::string EXTENSION_KEY_INPUT_DIMS = "InputDims";
const std::string EXTENSION_KEY_DYNAMIC_DIMS = "DynamicDims";
const std::string EXTENSION_KEY_FM_SHARED = "NPU_FM_SHARED";
const std::string NULL_HARDWARE_NAME = "NULL";
const std::string HARDWARE_NAME = "const.ai.nnrt_device";
@ -417,11 +418,10 @@ OH_NN_ReturnCode ParseDynamicDimsFromExtensions(
return OH_NN_SUCCESS;
}
OH_NN_ReturnCode ParseExtensionConfigs(
OH_NN_ReturnCode CheckExtensionConfigs(
const std::unordered_map<std::string, std::vector<std::pair<char*, size_t>>>& extensionMap,
const mindspore::lite::LiteGraph* pLiteGraph, ExtensionConfig& extensionConfig)
ExtensionConfig& extensionConfig)
{
extensionConfig.tuningStrategy = TuningStrategy::ON_DEVICE_PREPROCESS_TUNING;
if (extensionMap.find(EXTENSION_KEY_QUANT_BUFFER) != extensionMap.end()) {
const std::vector<std::pair<char*, size_t>>& value = extensionMap.at(EXTENSION_KEY_QUANT_BUFFER);
if (value.empty()) {
@ -460,6 +460,19 @@ OH_NN_ReturnCode ParseExtensionConfigs(
LOGI("ParseExtensionConfigs opLayout:%{public}s.", ops.c_str());
}
}
return OH_NN_SUCCESS;
}
OH_NN_ReturnCode ParseExtensionConfigs(
const std::unordered_map<std::string, std::vector<std::pair<char*, size_t>>>& extensionMap,
const mindspore::lite::LiteGraph* pLiteGraph, ExtensionConfig& extensionConfig)
{
extensionConfig.tuningStrategy = TuningStrategy::ON_DEVICE_PREPROCESS_TUNING;
OH_NN_ReturnCode ret = CheckExtensionConfigs(extensionMap, extensionConfig);
if (ret != OH_NN_SUCCESS) {
LOGE("CheckExtensionConfigs failed.");
return ret;
}
if (extensionMap.find(EXTENSION_KEY_INPUT_DIMS) != extensionMap.end() &&
extensionMap.find(EXTENSION_KEY_DYNAMIC_DIMS) != extensionMap.end()) {
auto returnCode = ParseDynamicDimsFromExtensions(extensionMap, pLiteGraph, extensionConfig);
@ -469,7 +482,10 @@ OH_NN_ReturnCode ParseExtensionConfigs(
}
extensionConfig.tuningStrategy = TuningStrategy::OFF; // 分档shape不支持fftl
}
if (extensionMap.find(EXTENSION_KEY_FM_SHARED) != extensionMap.end()) {
extensionConfig.isNpuFmShared = true;
LOGI("NNRT enable fm shared success.");
}
return OH_NN_SUCCESS;
}

View File

@ -31,6 +31,7 @@ const int CACHE_INPUT_TENSORDESC_OFFSET = 2;
const int CACHE_OUTPUT_TENSORDESC_OFFSET = 1;
constexpr int32_t NUMBER_CACHE_INFO_MEMBERS = 3;
const std::string EXTENSION_KEY_MODEL_NAME = "ModelName";
const std::string EXTENSION_KEY_FM_SHARED = "NPU_FM_SHARED";
const int OPVERSION_SUBSTR_NUM = 2;
const std::string CURRENT_VERSION = "0x00000000";
const std::string HIAI_VERSION_PATH = "/data/data/hiai/version";
@ -623,6 +624,7 @@ OH_NN_ReturnCode NNCompiler::RestoreFromCacheFile()
config.enableFloat16 = m_enableFp16;
config.mode = m_performance;
config.priority = m_priority;
config.extensionConfig.isNpuFmShared = m_extensionConfig.isNpuFmShared;
std::vector<Buffer> modelOnlyCaches(caches.begin(), caches.end() - CACHE_INPUT_TENSORDESC_OFFSET);
bool isUpdatable = false;
ret = m_device->PrepareModelFromModelCache(modelOnlyCaches, config, m_preparedModel, isUpdatable);
@ -719,6 +721,10 @@ OH_NN_ReturnCode NNCompiler::SetExtensionConfig(const std::unordered_map<std::st
m_extensionConfig.modelName.assign(value.data(), value.data() + value.size());
LOGI("[NNCompiler] SetExtensionConfig get model name:%{public}s.", m_extensionConfig.modelName.c_str());
}
if (configs.find(EXTENSION_KEY_FM_SHARED) != configs.end()) {
m_extensionConfig.isNpuFmShared = true;
LOGI("[NNCompiler] SetExtensionConfig NpuFmShared enabled.");
}
return OH_NN_SUCCESS;
}