mirror of
https://gitee.com/openharmony/ai_neural_network_runtime
synced 2024-12-04 05:50:44 +00:00
commit
04fe5d30a8
@ -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 {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user