添加nnrt getdevice

Signed-off-by: w30052974 <wangyifan94@huawei.com>
This commit is contained in:
w30052974 2024-08-15 16:34:41 +08:00
parent 9fd56d0e8b
commit 12a98d96de
4 changed files with 37 additions and 1 deletions

View File

@ -29,7 +29,8 @@
"hilog",
"hitrace",
"ipc",
"mindspore"
"mindspore",
"init"
],
"third_party": []
},

View File

@ -21,6 +21,7 @@ config("nnrt_config") {
"../neural_network_core",
"../../../interfaces/innerkits/c",
"../../../interfaces/kits/c",
"//base/startup/init/interfaces/innerkits/include",
]
}
@ -190,6 +191,7 @@ ohos_shared_library("libneural_network_runtime") {
"hitrace:libhitracechain",
"ipc:ipc_core",
"mindspore:mindir",
"init:libbegetutil",
]
deps = [ "../neural_network_core:libneural_network_core" ]

View File

@ -22,6 +22,7 @@
#include "common/log.h"
#include "quant_param.h"
#include "validation.h"
#include "syspara/parameter.h"
#include <fstream>
#include <sys/stat.h>
@ -38,6 +39,11 @@ 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 NULL_HARDWARE_NAME = "NULL";
const std::string HARDWARE_NAME = "const.ai.nnrt_device";
const std::string HARDWARE_VERSION = "v5_0";
constexpr size_t HARDWARE_NAME_MAX_LENGTH = 128;
NNRT_API NN_QuantParam *OH_NNQuantParam_Create()
{
auto* quantParamImpl = new (std::nothrow) QuantParams();
@ -688,3 +694,18 @@ NNRT_API OH_NN_ReturnCode OH_NNModel_GetAvailableOperations(OH_NNModel *model,
InnerModel *innerModel = reinterpret_cast<InnerModel*>(model);
return innerModel->GetSupportedOperations(deviceID, isAvailable, *opCount);
}
NNRT_API OH_NN_ReturnCode OH_NNModel_GetDevice(const char **nnrtDevice)
{
const cName[HARDWARE_NAME_MAX_LENGTH] = {0};
int ret = GetParameter(HARDWARE_NAME.c_str(), NULL_HARDWARE_NAME.c_str(), cName, HARDWARE_NAME_MAX_LENGTH);
// 如果成功获取返回值为硬件名称的字节数
if (ret <= 0) {
LOGE("GetNNRTDeviceName failed, failed to get parameter.");
return OH_NN_FAILED;
}
std::string deviceName = (std::string)cName + "_" + HARDWARE_VERSION;
*nnrtDevice = static_cast<const char*>(deviceName.c_str());
return OH_NN_SUCCESS;
}

View File

@ -141,6 +141,18 @@ OH_NN_ReturnCode OH_NNModel_BuildFromMetaGraph(OH_NNModel *model, const void *me
*/
bool OH_NNModel_HasCache(const char *cacheDir, const char *modelName, uint32_t version);
/**
* @brief NNRt device信息
*
* Neural Network Runtime接口对外开放\n
*
* @param nnrtDevice device参数
* @return OH_NN_SUCCESS{@link OH_NN_ReturnCode}
* @since 11
* @version 1.0
*/
OH_NN_ReturnCode OH_NNModel_GetDevice(const char **nnrtDevice);
#ifdef __cplusplus
}
#endif // __cpluscplus