mirror of
https://gitee.com/openharmony/ai_neural_network_runtime
synced 2024-11-23 07:39:54 +00:00
#I9UNOV:UT bug修复
Signed-off-by: 周翔 <zhouxiang78@h-partners.com>
This commit is contained in:
parent
b9d439645f
commit
0d5bcba8c7
6
.gitignore
vendored
6
.gitignore
vendored
@ -17,4 +17,8 @@ jni/include/schema/
|
|||||||
|
|
||||||
# ignore runtime file
|
# ignore runtime file
|
||||||
deploy.bat
|
deploy.bat
|
||||||
log.txt
|
log.txt
|
||||||
|
/.idea/.gitignore
|
||||||
|
/.idea/ai_neural_network_runtime.iml
|
||||||
|
/.idea/modules.xml
|
||||||
|
/.idea/vcs.xml
|
||||||
|
@ -15,5 +15,8 @@ import("//build/ohos.gni")
|
|||||||
|
|
||||||
group("unittest") {
|
group("unittest") {
|
||||||
testonly = true
|
testonly = true
|
||||||
deps = [ "ops:ops_unittest" ]
|
deps = [
|
||||||
|
"components:components_unittest",
|
||||||
|
"ops:ops_unittest"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "compilation.h"
|
#include "compilation.h"
|
||||||
#include "execution_plan.h"
|
|
||||||
#include "hdi_device_v1_0.h"
|
#include "hdi_device_v1_0.h"
|
||||||
#include "test/unittest/common/v1_0/mock_idevice.h"
|
#include "test/unittest/common/v1_0/mock_idevice.h"
|
||||||
|
|
||||||
@ -22,21 +21,6 @@ OH_NN_ReturnCode OHOS::HDI::Nnrt::V1_0::MockIPreparedModel::m_ExpectRetCode = OH
|
|||||||
|
|
||||||
namespace OHOS {
|
namespace OHOS {
|
||||||
namespace NeuralNetworkRuntime {
|
namespace NeuralNetworkRuntime {
|
||||||
std::shared_ptr<Device> ExecutionPlan::GetInputDevice() const
|
|
||||||
{
|
|
||||||
sptr<OHOS::HDI::Nnrt::V1_0::INnrtDevice> idevice
|
|
||||||
= sptr<OHOS::HDI::Nnrt::V1_0::MockIDevice>(new (std::nothrow) OHOS::HDI::Nnrt::V1_0::MockIDevice());
|
|
||||||
std::shared_ptr<Device> device = std::make_shared<HDIDeviceV1_0>(idevice);
|
|
||||||
return device;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<Device> ExecutionPlan::GetOutputDevice() const
|
|
||||||
{
|
|
||||||
sptr<OHOS::HDI::Nnrt::V1_0::INnrtDevice> idevice
|
|
||||||
= sptr<OHOS::HDI::Nnrt::V1_0::MockIDevice>(new (std::nothrow) OHOS::HDI::Nnrt::V1_0::MockIDevice());
|
|
||||||
std::shared_ptr<Device> device = std::make_shared<HDIDeviceV1_0>(idevice);
|
|
||||||
return device;
|
|
||||||
}
|
|
||||||
|
|
||||||
void* HDIDeviceV1_0::AllocateBuffer(size_t length)
|
void* HDIDeviceV1_0::AllocateBuffer(size_t length)
|
||||||
{
|
{
|
||||||
@ -86,19 +70,5 @@ OH_NN_ReturnCode HDIPreparedModelV1_0::Run(const std::vector<IOTensor>& inputs,
|
|||||||
|
|
||||||
return OH_NN_SUCCESS;
|
return OH_NN_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<ExecutionPlan> Compilation::GetExecutionPlan() const
|
|
||||||
{
|
|
||||||
sptr<OHOS::HDI::Nnrt::V1_0::IPreparedModel> hdiPreparedModel = OHOS::sptr<OHOS::HDI::Nnrt::V1_0::HDI::Nnrt::V1_0
|
|
||||||
::MockIPreparedModel>(new (std::nothrow) OHOS::HDI::Nnrt::V1_0::HDI::Nnrt::V1_0::MockIPreparedModel());
|
|
||||||
|
|
||||||
std::shared_ptr<PreparedModel> preparedModel = std::make_shared<HDIPreparedModelV1_0>(hdiPreparedModel);
|
|
||||||
sptr<OHOS::HDI::Nnrt::V1_0::INnrtDevice> idevice
|
|
||||||
= OHOS::sptr<OHOS::HDI::Nnrt::V1_0::MockIDevice>(new (std::nothrow) OHOS::HDI::Nnrt::V1_0::MockIDevice());
|
|
||||||
std::shared_ptr<Device> device = std::make_shared<HDIDeviceV1_0>(idevice);
|
|
||||||
ExecutionPlan executor(preparedModel, device);
|
|
||||||
std::shared_ptr<ExecutionPlan> pExcutor = std::make_shared<ExecutionPlan>(executor);
|
|
||||||
return pExcutor;
|
|
||||||
}
|
|
||||||
} // namespace NeuralNetworkRuntime
|
} // namespace NeuralNetworkRuntime
|
||||||
} // namespace OHOS
|
} // namespace OHOS
|
@ -19,35 +19,11 @@
|
|||||||
#include "common/utils.h"
|
#include "common/utils.h"
|
||||||
#include "inner_model.h"
|
#include "inner_model.h"
|
||||||
#include "hdi_device_v1_0.h"
|
#include "hdi_device_v1_0.h"
|
||||||
#include "device_manager.h"
|
|
||||||
#include "ops/div_builder.h"
|
#include "ops/div_builder.h"
|
||||||
#include "mock_idevice.h"
|
#include "mock_idevice.h"
|
||||||
|
|
||||||
namespace OHOS {
|
namespace OHOS {
|
||||||
namespace NeuralNetworkRuntime {
|
namespace NeuralNetworkRuntime {
|
||||||
// Mock the palce where the devicemanager GetDevice is called in inner_model build function.
|
|
||||||
std::shared_ptr<Device> DeviceManager::GetDevice(size_t deviceId) const
|
|
||||||
{
|
|
||||||
sptr<OHOS::HDI::Nnrt::V1_0::INnrtDevice> idevice =
|
|
||||||
sptr<OHOS::HDI::Nnrt::V1_0::MockIDevice>(new (std::nothrow) OHOS::HDI::Nnrt::V1_0::MockIDevice());
|
|
||||||
|
|
||||||
if (idevice == nullptr) {
|
|
||||||
LOGE("DeviceManager mock GetDevice failed, error happened when new sptr");
|
|
||||||
return nullptr;
|
|
||||||
} else {
|
|
||||||
std::shared_ptr<Device> device = CreateSharedPtr<HDIDeviceV1_0>(idevice);
|
|
||||||
if (device == nullptr) {
|
|
||||||
LOGE("DeviceManager mock GetDevice failed, device is nullptr");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (deviceId == 0) {
|
|
||||||
return nullptr;
|
|
||||||
} else {
|
|
||||||
return device;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mock the palce where the operator GetPrimitive is called in inner_model build function.
|
// Mock the palce where the operator GetPrimitive is called in inner_model build function.
|
||||||
Ops::LiteGraphPrimitvePtr Ops::DivBuilder::GetPrimitive()
|
Ops::LiteGraphPrimitvePtr Ops::DivBuilder::GetPrimitive()
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "compilation.h"
|
#include "compilation.h"
|
||||||
#include "execution_plan.h"
|
|
||||||
#include "hdi_device_v2_0.h"
|
#include "hdi_device_v2_0.h"
|
||||||
#include "test/unittest/common/v2_0/mock_idevice.h"
|
#include "test/unittest/common/v2_0/mock_idevice.h"
|
||||||
|
|
||||||
@ -22,21 +21,6 @@ OH_NN_ReturnCode OHOS::HDI::Nnrt::V2_0::MockIPreparedModel::m_ExpectRetCode = OH
|
|||||||
|
|
||||||
namespace OHOS {
|
namespace OHOS {
|
||||||
namespace NeuralNetworkRuntime {
|
namespace NeuralNetworkRuntime {
|
||||||
std::shared_ptr<Device> ExecutionPlan::GetInputDevice() const
|
|
||||||
{
|
|
||||||
sptr<OHOS::HDI::Nnrt::V2_0::INnrtDevice> idevice
|
|
||||||
= sptr<OHOS::HDI::Nnrt::V2_0::MockIDevice>(new (std::nothrow) OHOS::HDI::Nnrt::V2_0::MockIDevice());
|
|
||||||
std::shared_ptr<Device> device = std::make_shared<HDIDeviceV2_0>(idevice);
|
|
||||||
return device;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<Device> ExecutionPlan::GetOutputDevice() const
|
|
||||||
{
|
|
||||||
sptr<OHOS::HDI::Nnrt::V2_0::INnrtDevice> idevice
|
|
||||||
= sptr<OHOS::HDI::Nnrt::V2_0::MockIDevice>(new (std::nothrow) OHOS::HDI::Nnrt::V2_0::MockIDevice());
|
|
||||||
std::shared_ptr<Device> device = std::make_shared<HDIDeviceV2_0>(idevice);
|
|
||||||
return device;
|
|
||||||
}
|
|
||||||
|
|
||||||
void* HDIDeviceV2_0::AllocateBuffer(size_t length)
|
void* HDIDeviceV2_0::AllocateBuffer(size_t length)
|
||||||
{
|
{
|
||||||
@ -95,19 +79,5 @@ OH_NN_ReturnCode HDIPreparedModelV2_0::Run(const std::vector<IOTensor>& inputs,
|
|||||||
|
|
||||||
return OH_NN_SUCCESS;
|
return OH_NN_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<ExecutionPlan> Compilation::GetExecutionPlan() const
|
|
||||||
{
|
|
||||||
sptr<OHOS::HDI::Nnrt::V2_0::IPreparedModel> hdiPreparedModel = OHOS::sptr<OHOS::HDI::Nnrt::V2_0::HDI::Nnrt::V2_0
|
|
||||||
::MockIPreparedModel>(new (std::nothrow) OHOS::HDI::Nnrt::V2_0::HDI::Nnrt::V2_0::MockIPreparedModel());
|
|
||||||
|
|
||||||
std::shared_ptr<PreparedModel> preparedModel = std::make_shared<HDIPreparedModelV2_0>(hdiPreparedModel);
|
|
||||||
sptr<OHOS::HDI::Nnrt::V2_0::INnrtDevice> idevice
|
|
||||||
= OHOS::sptr<OHOS::HDI::Nnrt::V2_0::MockIDevice>(new (std::nothrow) OHOS::HDI::Nnrt::V2_0::MockIDevice());
|
|
||||||
std::shared_ptr<Device> device = std::make_shared<HDIDeviceV2_0>(idevice);
|
|
||||||
ExecutionPlan executor(preparedModel, device);
|
|
||||||
std::shared_ptr<ExecutionPlan> pExcutor = std::make_shared<ExecutionPlan>(executor);
|
|
||||||
return pExcutor;
|
|
||||||
}
|
|
||||||
} // namespace NeuralNetworkRuntime
|
} // namespace NeuralNetworkRuntime
|
||||||
} // namespace OHOS
|
} // namespace OHOS
|
@ -19,35 +19,11 @@
|
|||||||
#include "common/utils.h"
|
#include "common/utils.h"
|
||||||
#include "inner_model.h"
|
#include "inner_model.h"
|
||||||
#include "hdi_device_v2_0.h"
|
#include "hdi_device_v2_0.h"
|
||||||
#include "device_manager.h"
|
|
||||||
#include "ops/div_builder.h"
|
#include "ops/div_builder.h"
|
||||||
#include "mock_idevice.h"
|
#include "mock_idevice.h"
|
||||||
|
|
||||||
namespace OHOS {
|
namespace OHOS {
|
||||||
namespace NeuralNetworkRuntime {
|
namespace NeuralNetworkRuntime {
|
||||||
// Mock the palce where the devicemanager GetDevice is called in inner_model build function.
|
|
||||||
std::shared_ptr<Device> DeviceManager::GetDevice(size_t deviceId) const
|
|
||||||
{
|
|
||||||
sptr<OHOS::HDI::Nnrt::V2_0::INnrtDevice> idevice =
|
|
||||||
sptr<OHOS::HDI::Nnrt::V2_0::MockIDevice>(new (std::nothrow) OHOS::HDI::Nnrt::V2_0::MockIDevice());
|
|
||||||
|
|
||||||
if (idevice == nullptr) {
|
|
||||||
LOGE("DeviceManager mock GetDevice failed, error happened when new sptr");
|
|
||||||
return nullptr;
|
|
||||||
} else {
|
|
||||||
std::shared_ptr<Device> device = CreateSharedPtr<HDIDeviceV2_0>(idevice);
|
|
||||||
if (device == nullptr) {
|
|
||||||
LOGE("DeviceManager mock GetDevice failed, device is nullptr");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (deviceId == 0) {
|
|
||||||
return nullptr;
|
|
||||||
} else {
|
|
||||||
return device;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mock the palce where the operator GetPrimitive is called in inner_model build function.
|
// Mock the palce where the operator GetPrimitive is called in inner_model build function.
|
||||||
Ops::LiteGraphPrimitvePtr Ops::DivBuilder::GetPrimitive()
|
Ops::LiteGraphPrimitvePtr Ops::DivBuilder::GetPrimitive()
|
||||||
|
@ -21,6 +21,7 @@ config("module_private_config") {
|
|||||||
include_dirs = [
|
include_dirs = [
|
||||||
"//third_party/googletest/googlemock/include",
|
"//third_party/googletest/googlemock/include",
|
||||||
"../../..",
|
"../../..",
|
||||||
|
"../../../frameworks/native",
|
||||||
"../../../frameworks/native/neural_network_runtime",
|
"../../../frameworks/native/neural_network_runtime",
|
||||||
"../../../frameworks/native/neural_network_core",
|
"../../../frameworks/native/neural_network_core",
|
||||||
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
|
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
|
||||||
@ -617,16 +618,6 @@ ohos_unittest("NeuralNetworkRuntimeV2_0Test") {
|
|||||||
group("components_unittest") {
|
group("components_unittest") {
|
||||||
testonly = true
|
testonly = true
|
||||||
deps = [
|
deps = [
|
||||||
":CompilationV1_0Test",
|
|
||||||
":CompilationV2_0Test",
|
|
||||||
":DeviceManagerV1_0Test",
|
|
||||||
":DeviceManagerV2_0Test",
|
|
||||||
":DeviceRegistrarV1_0Test",
|
|
||||||
":DeviceRegistrarV2_0Test",
|
|
||||||
":ExecutorV1_0Test",
|
|
||||||
":ExecutorV2_0Test",
|
|
||||||
":HDIDeviceV1_0Test",
|
|
||||||
":HDIDeviceV2_0Test",
|
|
||||||
":HDIPreparedModelV1_0Test",
|
":HDIPreparedModelV1_0Test",
|
||||||
":HDIPreparedModelV2_0Test",
|
":HDIPreparedModelV2_0Test",
|
||||||
":InnerModelV1_0Test",
|
":InnerModelV1_0Test",
|
||||||
|
@ -119,7 +119,7 @@ HWTEST_F(HDIPreparedModelTest, hidpreparedmodel_exportmodelcache_001, TestSize.L
|
|||||||
OHOS::sptr<V1_0::IPreparedModel> hdiPreparedModel =
|
OHOS::sptr<V1_0::IPreparedModel> hdiPreparedModel =
|
||||||
OHOS::sptr<V1_0::MockIPreparedModel>(new (std::nothrow) V1_0::MockIPreparedModel());
|
OHOS::sptr<V1_0::MockIPreparedModel>(new (std::nothrow) V1_0::MockIPreparedModel());
|
||||||
std::unique_ptr<HDIPreparedModelV1_0> preparedModel = std::make_unique<HDIPreparedModelV1_0>(hdiPreparedModel);
|
std::unique_ptr<HDIPreparedModelV1_0> preparedModel = std::make_unique<HDIPreparedModelV1_0>(hdiPreparedModel);
|
||||||
std::vector<ModelBuffer> modelCache;
|
std::vector<Buffer> modelCache;
|
||||||
EXPECT_CALL(*((V1_0::MockIPreparedModel*)hdiPreparedModel.GetRefPtr()),
|
EXPECT_CALL(*((V1_0::MockIPreparedModel*)hdiPreparedModel.GetRefPtr()),
|
||||||
ExportModelCache(::testing::_))
|
ExportModelCache(::testing::_))
|
||||||
.WillRepeatedly(
|
.WillRepeatedly(
|
||||||
@ -146,7 +146,7 @@ HWTEST_F(HDIPreparedModelTest, hidpreparedmodel_exportmodelcache_002, TestSize.L
|
|||||||
EXPECT_NE(mockPreparedModel, nullptr);
|
EXPECT_NE(mockPreparedModel, nullptr);
|
||||||
|
|
||||||
std::unique_ptr<HDIPreparedModelV1_0> preparedModel = std::make_unique<HDIPreparedModelV1_0>(mockPreparedModel);
|
std::unique_ptr<HDIPreparedModelV1_0> preparedModel = std::make_unique<HDIPreparedModelV1_0>(mockPreparedModel);
|
||||||
std::vector<ModelBuffer> modelCache;
|
std::vector<Buffer> modelCache;
|
||||||
EXPECT_CALL(*((V1_0::MockIPreparedModel*)mockPreparedModel.GetRefPtr()),
|
EXPECT_CALL(*((V1_0::MockIPreparedModel*)mockPreparedModel.GetRefPtr()),
|
||||||
ExportModelCache(::testing::_))
|
ExportModelCache(::testing::_))
|
||||||
.WillRepeatedly(
|
.WillRepeatedly(
|
||||||
@ -172,9 +172,9 @@ HWTEST_F(HDIPreparedModelTest, hidpreparedmodel_exportmodelcache_003, TestSize.L
|
|||||||
EXPECT_NE(hdiPreparedModel, nullptr);
|
EXPECT_NE(hdiPreparedModel, nullptr);
|
||||||
|
|
||||||
std::unique_ptr<HDIPreparedModelV1_0> preparedModel = std::make_unique<HDIPreparedModelV1_0>(hdiPreparedModel);
|
std::unique_ptr<HDIPreparedModelV1_0> preparedModel = std::make_unique<HDIPreparedModelV1_0>(hdiPreparedModel);
|
||||||
std::vector<ModelBuffer> modelCache {{nullptr, 0}};
|
std::vector<Buffer> modelCache;
|
||||||
OH_NN_ReturnCode result = preparedModel->ExportModelCache(modelCache);
|
OH_NN_ReturnCode result = preparedModel->ExportModelCache(modelCache);
|
||||||
EXPECT_EQ(OH_NN_INVALID_PARAMETER, result);
|
EXPECT_EQ(OH_NN_SUCCESS, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -190,7 +190,7 @@ HWTEST_F(HDIPreparedModelTest, hidpreparedmodel_exportmodelcache_004, TestSize.L
|
|||||||
EXPECT_NE(mockPreparedModel, nullptr);
|
EXPECT_NE(mockPreparedModel, nullptr);
|
||||||
|
|
||||||
std::unique_ptr<HDIPreparedModelV1_0> preparedModel = std::make_unique<HDIPreparedModelV1_0>(mockPreparedModel);
|
std::unique_ptr<HDIPreparedModelV1_0> preparedModel = std::make_unique<HDIPreparedModelV1_0>(mockPreparedModel);
|
||||||
std::vector<ModelBuffer> modelCache;
|
std::vector<Buffer> modelCache;
|
||||||
EXPECT_CALL(*((V1_0::MockIPreparedModel*)mockPreparedModel.GetRefPtr()),
|
EXPECT_CALL(*((V1_0::MockIPreparedModel*)mockPreparedModel.GetRefPtr()),
|
||||||
ExportModelCache(::testing::_))
|
ExportModelCache(::testing::_))
|
||||||
.WillRepeatedly(
|
.WillRepeatedly(
|
||||||
@ -201,7 +201,7 @@ HWTEST_F(HDIPreparedModelTest, hidpreparedmodel_exportmodelcache_004, TestSize.L
|
|||||||
);
|
);
|
||||||
|
|
||||||
OH_NN_ReturnCode result = preparedModel->ExportModelCache(modelCache);
|
OH_NN_ReturnCode result = preparedModel->ExportModelCache(modelCache);
|
||||||
EXPECT_EQ(OH_NN_UNAVAILABLE_DEVICE, result);
|
EXPECT_EQ(OH_NN_SAVE_CACHE_EXCEPTION, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,14 +62,12 @@ void InnerModelTest::SetLiteGraph(mindspore::lite::LiteGraph* liteGraph)
|
|||||||
|
|
||||||
for (size_t indexInput = 0; indexInput < liteGraph->input_indices_.size(); ++indexInput) {
|
for (size_t indexInput = 0; indexInput < liteGraph->input_indices_.size(); ++indexInput) {
|
||||||
const std::vector<uint8_t> data(36, 1);
|
const std::vector<uint8_t> data(36, 1);
|
||||||
liteGraph->all_tensors_.emplace_back(mindspore::lite::MindIR_Tensor_Create(liteGraph->name_,
|
liteGraph->all_tensors_.emplace_back(mindspore::lite::MindIR_Tensor_Create());
|
||||||
mindspore::lite::DATA_TYPE_FLOAT32, m_dimInput, mindspore::lite::FORMAT_NCHW, data, quant_params));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t indexOutput = 0; indexOutput < liteGraph->output_indices_.size(); ++indexOutput) {
|
for (size_t indexOutput = 0; indexOutput < liteGraph->output_indices_.size(); ++indexOutput) {
|
||||||
const std::vector<uint8_t> dataOut(36, 1);
|
const std::vector<uint8_t> dataOut(36, 1);
|
||||||
liteGraph->all_tensors_.emplace_back(mindspore::lite::MindIR_Tensor_Create(liteGraph->name_,
|
liteGraph->all_tensors_.emplace_back(mindspore::lite::MindIR_Tensor_Create());
|
||||||
mindspore::lite::DATA_TYPE_FLOAT32, m_dimOutput, mindspore::lite::FORMAT_NCHW, dataOut, quant_params));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,8 +108,14 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_001, Test
|
|||||||
m_inputIndices = {};
|
m_inputIndices = {};
|
||||||
|
|
||||||
SetLiteGraph(liteGraph);
|
SetLiteGraph(liteGraph);
|
||||||
EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(liteGraph));
|
|
||||||
mindspore::lite::MindIR_LiteGraph_Destroy(&liteGraph);
|
Buffer buffer;
|
||||||
|
std::string modelName;
|
||||||
|
std::string isProfiling;
|
||||||
|
std::string opLayout;
|
||||||
|
std::map<std::string, std::string> opLayouts;
|
||||||
|
|
||||||
|
EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -126,8 +130,14 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_002, Test
|
|||||||
m_inputIndices = {6};
|
m_inputIndices = {6};
|
||||||
|
|
||||||
SetLiteGraph(liteGraph);
|
SetLiteGraph(liteGraph);
|
||||||
EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(liteGraph));
|
|
||||||
mindspore::lite::MindIR_LiteGraph_Destroy(&liteGraph);
|
Buffer buffer;
|
||||||
|
std::string modelName;
|
||||||
|
std::string isProfiling;
|
||||||
|
std::string opLayout;
|
||||||
|
std::map<std::string, std::string> opLayouts;
|
||||||
|
|
||||||
|
EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -141,7 +151,14 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_003, Test
|
|||||||
EXPECT_NE(nullptr, liteGraph);
|
EXPECT_NE(nullptr, liteGraph);
|
||||||
|
|
||||||
SetLiteGraph(liteGraph);
|
SetLiteGraph(liteGraph);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph));
|
|
||||||
|
Buffer buffer;
|
||||||
|
std::string modelName;
|
||||||
|
std::string isProfiling;
|
||||||
|
std::string opLayout;
|
||||||
|
std::map<std::string, std::string> opLayouts;
|
||||||
|
|
||||||
|
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -156,8 +173,14 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_004, Test
|
|||||||
m_dimInput = {3, -3};
|
m_dimInput = {3, -3};
|
||||||
|
|
||||||
SetLiteGraph(liteGraph);
|
SetLiteGraph(liteGraph);
|
||||||
EXPECT_EQ(OH_NN_NULL_PTR, m_innerModelTest.BuildFromLiteGraph(liteGraph));
|
|
||||||
mindspore::lite::MindIR_LiteGraph_Destroy(&liteGraph);
|
Buffer buffer;
|
||||||
|
std::string modelName;
|
||||||
|
std::string isProfiling;
|
||||||
|
std::string opLayout;
|
||||||
|
std::map<std::string, std::string> opLayouts;
|
||||||
|
|
||||||
|
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -172,8 +195,14 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_005, Test
|
|||||||
m_outputIndices = {6};
|
m_outputIndices = {6};
|
||||||
|
|
||||||
SetLiteGraph(liteGraph);
|
SetLiteGraph(liteGraph);
|
||||||
EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(liteGraph));
|
|
||||||
mindspore::lite::MindIR_LiteGraph_Destroy(&liteGraph);
|
Buffer buffer;
|
||||||
|
std::string modelName;
|
||||||
|
std::string isProfiling;
|
||||||
|
std::string opLayout;
|
||||||
|
std::map<std::string, std::string> opLayouts;
|
||||||
|
|
||||||
|
EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -183,7 +212,36 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_005, Test
|
|||||||
*/
|
*/
|
||||||
HWTEST_F(InnerModelTest, inner_model_build_from_lite_graph_001, TestSize.Level1)
|
HWTEST_F(InnerModelTest, inner_model_build_from_lite_graph_001, TestSize.Level1)
|
||||||
{
|
{
|
||||||
EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(nullptr));
|
char d = 'a';
|
||||||
|
char * cr = &d;
|
||||||
|
struct OH_NN_Extension on_exit = {
|
||||||
|
"zhou", cr, 5
|
||||||
|
};
|
||||||
|
OH_NN_Extension *extensions = &on_exit;
|
||||||
|
size_t extensionSize = 1;
|
||||||
|
Buffer buffer;
|
||||||
|
std::string modelName;
|
||||||
|
std::string isProfiling;
|
||||||
|
std::string opLayout;
|
||||||
|
std::map<std::string, std::string> opLayouts;
|
||||||
|
for (size_t i = 0; i < extensionSize; ++i) {
|
||||||
|
std::string name = extensions[i].name;
|
||||||
|
if (name == "QuantBuffer") {
|
||||||
|
buffer.data = extensions[i].value;
|
||||||
|
buffer.length = extensions[i].valueSize;
|
||||||
|
} else if (name == "ModelName") {
|
||||||
|
modelName.assign(extensions[i].value, extensions[i].value + extensions[i].valueSize);
|
||||||
|
} else if (name == "Profiling") {
|
||||||
|
isProfiling.assign(extensions[i].value, extensions[i].value + extensions[i].valueSize);
|
||||||
|
LOGI("OH_NNModel_BuildFromLiteGraph isProfiling enable.");
|
||||||
|
} else if (name == "opLayout") {
|
||||||
|
opLayout.assign(extensions[i].value, extensions[i].value + extensions[i].valueSize);
|
||||||
|
opLayouts.insert({opLayout, "hiai::ExecuteDevice::CPU"});
|
||||||
|
LOGI("OH_NNModel_BuildFromLiteGraph opLayout:%{public}s.", opLayout.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(nullptr, buffer, modelName, isProfiling, opLayouts));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -197,8 +255,15 @@ HWTEST_F(InnerModelTest, inner_model_build_from_lite_graph_002, TestSize.Level1)
|
|||||||
EXPECT_NE(nullptr, liteGraph);
|
EXPECT_NE(nullptr, liteGraph);
|
||||||
|
|
||||||
SetLiteGraph(liteGraph);
|
SetLiteGraph(liteGraph);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph));
|
|
||||||
EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.BuildFromLiteGraph(liteGraph));
|
Buffer buffer;
|
||||||
|
std::string modelName;
|
||||||
|
std::string isProfiling;
|
||||||
|
std::string opLayout;
|
||||||
|
std::map<std::string, std::string> opLayouts;
|
||||||
|
|
||||||
|
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts));
|
||||||
|
EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -218,8 +283,13 @@ HWTEST_F(InnerModelTest, inner_model_build_from_lite_graph_003, TestSize.Level1)
|
|||||||
const OH_NN_Tensor& tensor = {OH_NN_INT8, 2, dimInput, nullptr, OH_NN_TENSOR};
|
const OH_NN_Tensor& tensor = {OH_NN_INT8, 2, dimInput, nullptr, OH_NN_TENSOR};
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.AddTensor(tensor));
|
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.AddTensor(tensor));
|
||||||
|
|
||||||
EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.BuildFromLiteGraph(liteGraph));
|
Buffer buffer;
|
||||||
mindspore::lite::MindIR_LiteGraph_Destroy(&liteGraph);
|
std::string modelName;
|
||||||
|
std::string isProfiling;
|
||||||
|
std::string opLayout;
|
||||||
|
std::map<std::string, std::string> opLayouts;
|
||||||
|
|
||||||
|
EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -245,7 +315,14 @@ HWTEST_F(InnerModelTest, inner_model_add_tensor_002, TestSize.Level1)
|
|||||||
mindspore::lite::LiteGraph* liteGraph = new (std::nothrow) mindspore::lite::LiteGraph();
|
mindspore::lite::LiteGraph* liteGraph = new (std::nothrow) mindspore::lite::LiteGraph();
|
||||||
EXPECT_NE(nullptr, liteGraph);
|
EXPECT_NE(nullptr, liteGraph);
|
||||||
SetLiteGraph(liteGraph);
|
SetLiteGraph(liteGraph);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph));
|
|
||||||
|
Buffer buffer;
|
||||||
|
std::string modelName;
|
||||||
|
std::string isProfiling;
|
||||||
|
std::string opLayout;
|
||||||
|
std::map<std::string, std::string> opLayouts;
|
||||||
|
|
||||||
|
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts));
|
||||||
|
|
||||||
const int32_t dimInput[2] = {2, 2};
|
const int32_t dimInput[2] = {2, 2};
|
||||||
const OH_NN_Tensor& tensor = {OH_NN_INT8, 2, dimInput, nullptr, OH_NN_TENSOR};
|
const OH_NN_Tensor& tensor = {OH_NN_INT8, 2, dimInput, nullptr, OH_NN_TENSOR};
|
||||||
@ -338,7 +415,14 @@ HWTEST_F(InnerModelTest, inner_model_set_tensor_value_005, TestSize.Level1)
|
|||||||
mindspore::lite::LiteGraph* liteGraph = new (std::nothrow) mindspore::lite::LiteGraph();
|
mindspore::lite::LiteGraph* liteGraph = new (std::nothrow) mindspore::lite::LiteGraph();
|
||||||
EXPECT_NE(nullptr, liteGraph);
|
EXPECT_NE(nullptr, liteGraph);
|
||||||
SetLiteGraph(liteGraph);
|
SetLiteGraph(liteGraph);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph));
|
|
||||||
|
Buffer buffer;
|
||||||
|
std::string modelName;
|
||||||
|
std::string isProfiling;
|
||||||
|
std::string opLayout;
|
||||||
|
std::map<std::string, std::string> opLayouts;
|
||||||
|
|
||||||
|
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts));
|
||||||
|
|
||||||
EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.SetTensorValue(index,
|
EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.SetTensorValue(index,
|
||||||
static_cast<const void *>(&activation), sizeof(int8_t)));
|
static_cast<const void *>(&activation), sizeof(int8_t)));
|
||||||
@ -418,7 +502,14 @@ HWTEST_F(InnerModelTest, inner_model_add_operation_002, TestSize.Level1)
|
|||||||
mindspore::lite::LiteGraph* liteGraph = new (std::nothrow) mindspore::lite::LiteGraph();
|
mindspore::lite::LiteGraph* liteGraph = new (std::nothrow) mindspore::lite::LiteGraph();
|
||||||
EXPECT_NE(nullptr, liteGraph);
|
EXPECT_NE(nullptr, liteGraph);
|
||||||
SetLiteGraph(liteGraph);
|
SetLiteGraph(liteGraph);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph));
|
|
||||||
|
Buffer buffer;
|
||||||
|
std::string modelName;
|
||||||
|
std::string isProfiling;
|
||||||
|
std::string opLayout;
|
||||||
|
std::map<std::string, std::string> opLayouts;
|
||||||
|
|
||||||
|
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts));
|
||||||
|
|
||||||
EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.AddOperation(m_opType, m_params, m_inputs,
|
EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.AddOperation(m_opType, m_params, m_inputs,
|
||||||
m_outputs));
|
m_outputs));
|
||||||
@ -611,7 +702,14 @@ HWTEST_F(InnerModelTest, inner_model_specify_inputs_and_outputs_002, TestSize.Le
|
|||||||
mindspore::lite::LiteGraph* liteGraph = new (std::nothrow) mindspore::lite::LiteGraph();
|
mindspore::lite::LiteGraph* liteGraph = new (std::nothrow) mindspore::lite::LiteGraph();
|
||||||
EXPECT_NE(nullptr, liteGraph);
|
EXPECT_NE(nullptr, liteGraph);
|
||||||
SetLiteGraph(liteGraph);
|
SetLiteGraph(liteGraph);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph));
|
|
||||||
|
Buffer buffer;
|
||||||
|
std::string modelName;
|
||||||
|
std::string isProfiling;
|
||||||
|
std::string opLayout;
|
||||||
|
std::map<std::string, std::string> opLayouts;
|
||||||
|
|
||||||
|
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts));
|
||||||
|
|
||||||
EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.SpecifyInputsAndOutputs(inputs, outputs));
|
EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.SpecifyInputsAndOutputs(inputs, outputs));
|
||||||
}
|
}
|
||||||
@ -758,7 +856,7 @@ HWTEST_F(InnerModelTest, inner_model_get_supported_operation_001, TestSize.Level
|
|||||||
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.AddOperation(m_opType, m_params, m_inputs, m_outputs));
|
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.AddOperation(m_opType, m_params, m_inputs, m_outputs));
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.SpecifyInputsAndOutputs(m_inputs, m_outputs));
|
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.SpecifyInputsAndOutputs(m_inputs, m_outputs));
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.Build());
|
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.Build());
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.GetSupportedOperations(deviceID, &isSupported, opCount));
|
EXPECT_EQ(OH_NN_FAILED, m_innerModelTest.GetSupportedOperations(deviceID, &isSupported, opCount));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -775,9 +873,16 @@ HWTEST_F(InnerModelTest, inner_model_get_supported_operation_002, TestSize.Level
|
|||||||
mindspore::lite::LiteGraph* liteGraph = new (std::nothrow) mindspore::lite::LiteGraph();
|
mindspore::lite::LiteGraph* liteGraph = new (std::nothrow) mindspore::lite::LiteGraph();
|
||||||
EXPECT_NE(nullptr, liteGraph);
|
EXPECT_NE(nullptr, liteGraph);
|
||||||
SetLiteGraph(liteGraph);
|
SetLiteGraph(liteGraph);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph));
|
|
||||||
|
|
||||||
EXPECT_EQ(OH_NN_UNAVAILABLE_DEVICE, m_innerModelTest.GetSupportedOperations(deviceID, &isSupported, opCount));
|
Buffer buffer;
|
||||||
|
std::string modelName;
|
||||||
|
std::string isProfiling;
|
||||||
|
std::string opLayout;
|
||||||
|
std::map<std::string, std::string> opLayouts;
|
||||||
|
|
||||||
|
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts));
|
||||||
|
|
||||||
|
EXPECT_EQ(OH_NN_FAILED, m_innerModelTest.GetSupportedOperations(deviceID, &isSupported, opCount));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,14 +19,15 @@
|
|||||||
|
|
||||||
#include "common/utils.h"
|
#include "common/utils.h"
|
||||||
#include "compilation.h"
|
#include "compilation.h"
|
||||||
#include "device_manager.h"
|
|
||||||
#include "hdi_device_v1_0.h"
|
#include "hdi_device_v1_0.h"
|
||||||
#include "test/unittest/common/v1_0/mock_idevice.h"
|
#include "test/unittest/common/v1_0/mock_idevice.h"
|
||||||
|
|
||||||
namespace OHOS {
|
namespace OHOS {
|
||||||
namespace NeuralNetworkRuntime {
|
namespace NeuralNetworkRuntime {
|
||||||
OH_NN_ReturnCode HDIDeviceV1_0::PrepareModel(std::shared_ptr<const mindspore::lite::LiteGraph> model,
|
OH_NN_ReturnCode HDIDeviceV1_0::PrepareModel(std::shared_ptr<const mindspore::lite::LiteGraph> model,
|
||||||
const ModelConfig& config, std::shared_ptr<PreparedModel>& preparedModel)
|
const Buffer& quantBuffer,
|
||||||
|
const ModelConfig& config,
|
||||||
|
std::shared_ptr<PreparedModel>& preparedModel)
|
||||||
{
|
{
|
||||||
if (model == nullptr) {
|
if (model == nullptr) {
|
||||||
return OH_NN_INVALID_PARAMETER;
|
return OH_NN_INVALID_PARAMETER;
|
||||||
@ -47,29 +48,6 @@ OH_NN_ReturnCode HDIDeviceV1_0::PrepareModel(std::shared_ptr<const mindspore::li
|
|||||||
return OH_NN_SUCCESS;
|
return OH_NN_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Device> DeviceManager::GetDevice(size_t deviceId) const
|
|
||||||
{
|
|
||||||
sptr<OHOS::HDI::Nnrt::V1_0::INnrtDevice> idevice
|
|
||||||
= sptr<OHOS::HDI::Nnrt::V1_0::MockIDevice>(new (std::nothrow) OHOS::HDI::Nnrt::V1_0::MockIDevice());
|
|
||||||
if (idevice == nullptr) {
|
|
||||||
LOGE("DeviceManager mock GetDevice failed, error happened when new sptr");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<Device> device = CreateSharedPtr<HDIDeviceV1_0>(idevice);
|
|
||||||
if (device == nullptr) {
|
|
||||||
LOGE("DeviceManager mock GetDevice failed, the device is nullptr");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (deviceId == 0) {
|
|
||||||
LOGE("DeviceManager mock GetDevice failed, the passed parameter deviceId is 0");
|
|
||||||
return nullptr;
|
|
||||||
} else {
|
|
||||||
return device;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
OH_NN_ReturnCode HDIDeviceV1_0::GetDeviceType(OH_NN_DeviceType& deviceType)
|
OH_NN_ReturnCode HDIDeviceV1_0::GetDeviceType(OH_NN_DeviceType& deviceType)
|
||||||
{
|
{
|
||||||
if (deviceType == OH_NN_OTHERS) {
|
if (deviceType == OH_NN_OTHERS) {
|
||||||
@ -79,30 +57,6 @@ OH_NN_ReturnCode HDIDeviceV1_0::GetDeviceType(OH_NN_DeviceType& deviceType)
|
|||||||
return OH_NN_SUCCESS;
|
return OH_NN_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& DeviceManager::GetDeviceName(size_t deviceId)
|
|
||||||
{
|
|
||||||
static std::string deviceName = "";
|
|
||||||
if (deviceId == 0) {
|
|
||||||
return deviceName;
|
|
||||||
}
|
|
||||||
|
|
||||||
deviceName = "deviceId";
|
|
||||||
return deviceName;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::vector<size_t>& DeviceManager::GetAllDeviceId()
|
|
||||||
{
|
|
||||||
static std::vector<size_t> deviceIds;
|
|
||||||
if (OHOS::HDI::Nnrt::V1_0::MockIPreparedModel::m_ExpectRetCode == OH_NN_FAILED) {
|
|
||||||
// In order not to affect other use cases, set to the OH_NN_OPERATION_FORBIDDEN
|
|
||||||
OHOS::HDI::Nnrt::V1_0::MockIPreparedModel::m_ExpectRetCode = OH_NN_OPERATION_FORBIDDEN;
|
|
||||||
return deviceIds;
|
|
||||||
}
|
|
||||||
std::size_t device = 1;
|
|
||||||
deviceIds.emplace_back(device);
|
|
||||||
return deviceIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
OH_NN_ReturnCode HDIDeviceV1_0::IsModelCacheSupported(bool& isSupported)
|
OH_NN_ReturnCode HDIDeviceV1_0::IsModelCacheSupported(bool& isSupported)
|
||||||
{
|
{
|
||||||
isSupported = true;
|
isSupported = true;
|
||||||
@ -267,22 +221,30 @@ void NeuralNetworkRuntimeTest::SetInnerBuild(InnerModel& innerModel)
|
|||||||
|
|
||||||
void NeuralNetworkRuntimeTest::SetInputAndOutput(Executor& executor)
|
void NeuralNetworkRuntimeTest::SetInputAndOutput(Executor& executor)
|
||||||
{
|
{
|
||||||
float input1[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
|
size_t input1Index = 0;
|
||||||
float input2[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
|
|
||||||
|
|
||||||
uint32_t input1Index = 0;
|
|
||||||
uint32_t input2Index = 1;
|
|
||||||
|
|
||||||
int32_t inputDims[2] = {3, 4};
|
int32_t inputDims[2] = {3, 4};
|
||||||
size_t length = 12 * sizeof(float);
|
size_t lengthSize = 12 * sizeof(float);
|
||||||
m_tensor = {OH_NN_FLOAT32, 2, inputDims, nullptr, OH_NN_TENSOR};
|
size_t * length = &lengthSize;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, executor.SetInput(input1Index, m_tensor, input1, length));
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, executor.SetInput(input2Index, m_tensor, input2, length));
|
size_t minInputDims = 1;
|
||||||
|
size_t maxInputDims = 12;
|
||||||
|
|
||||||
|
size_t * minInputDimsAdress = &minInputDims;
|
||||||
|
size_t ** minInputDimsAdressA = &minInputDimsAdress;
|
||||||
|
|
||||||
|
size_t * maxInputDimsAdress = &maxInputDims;
|
||||||
|
size_t ** maxInputDimsAdressA = &maxInputDimsAdress;
|
||||||
|
|
||||||
|
m_tensor = {OH_NN_FLOAT32, 2, inputDims, nullptr, OH_NN_TENSOR};
|
||||||
|
EXPECT_EQ(OH_NN_SUCCESS, executor.GetInputDimRange(input1Index, minInputDimsAdressA, maxInputDimsAdressA, length));
|
||||||
|
|
||||||
float output[12];
|
|
||||||
uint32_t outputIndex = 0;
|
uint32_t outputIndex = 0;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, executor.SetOutput(outputIndex, output, length));
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, executor.Run());
|
int32_t shape = 3;
|
||||||
|
int32_t* shapeA = &shape;
|
||||||
|
int32_t** shapeAA = &shapeA;
|
||||||
|
uint32_t* shapeNum = &outputIndex;
|
||||||
|
EXPECT_EQ(OH_NN_SUCCESS, executor.GetOutputShape(outputIndex, shapeAA, shapeNum));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -810,7 +772,7 @@ HWTEST_F(NeuralNetworkRuntimeTest, model_get_available_operation_005, testing::e
|
|||||||
|
|
||||||
size_t deviceID = 10;
|
size_t deviceID = 10;
|
||||||
OH_NN_ReturnCode ret = OH_NNModel_GetAvailableOperations(model, deviceID, &pIsAvailable, &opCount);
|
OH_NN_ReturnCode ret = OH_NNModel_GetAvailableOperations(model, deviceID, &pIsAvailable, &opCount);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, ret);
|
EXPECT_EQ(OH_NN_FAILED, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -837,7 +799,7 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_construct_002, testing::ext::Test
|
|||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNCompilation* ret = OH_NNCompilation_Construct(model);
|
OH_NNCompilation* ret = OH_NNCompilation_Construct(model);
|
||||||
EXPECT_EQ(nullptr, ret);
|
EXPECT_NE(nullptr, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -876,8 +838,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_device_002, testing::ext::Tes
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation compilation(&innerModel);
|
|
||||||
OH_NNCompilation* nnCompilation = reinterpret_cast<OH_NNCompilation*>(&compilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
size_t deviceId = 1;
|
size_t deviceId = 1;
|
||||||
OH_NN_ReturnCode ret = OH_NNCompilation_SetDevice(nnCompilation, deviceId);
|
OH_NN_ReturnCode ret = OH_NNCompilation_SetDevice(nnCompilation, deviceId);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, ret);
|
EXPECT_EQ(OH_NN_SUCCESS, ret);
|
||||||
@ -892,12 +855,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_cache_001, testing::ext::Test
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation compilation(&innerModel);
|
|
||||||
OH_NNCompilation* nnCompilation = nullptr;
|
OH_NNCompilation* nnCompilation = nullptr;
|
||||||
const char* cacheDir = "../";
|
const char* cacheDir = "../";
|
||||||
uint32_t version = 1;
|
uint32_t version = 1;
|
||||||
std::size_t deviceId = 1;
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId));
|
|
||||||
OH_NN_ReturnCode ret = OH_NNCompilation_SetCache(nnCompilation, cacheDir, version);
|
OH_NN_ReturnCode ret = OH_NNCompilation_SetCache(nnCompilation, cacheDir, version);
|
||||||
EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
|
EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
|
||||||
}
|
}
|
||||||
@ -911,12 +871,11 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_cache_002, testing::ext::Test
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation compilation(&innerModel);
|
|
||||||
OH_NNCompilation* nnCompilation = reinterpret_cast<OH_NNCompilation*>(&compilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
const char* cacheDir = nullptr;
|
const char* cacheDir = nullptr;
|
||||||
uint32_t version = 1;
|
uint32_t version = 1;
|
||||||
std::size_t deviceId = 1;
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId));
|
|
||||||
OH_NN_ReturnCode ret = OH_NNCompilation_SetCache(nnCompilation, cacheDir, version);
|
OH_NN_ReturnCode ret = OH_NNCompilation_SetCache(nnCompilation, cacheDir, version);
|
||||||
EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
|
EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
|
||||||
}
|
}
|
||||||
@ -930,12 +889,11 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_cache_003, testing::ext::Test
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation compilation(&innerModel);
|
|
||||||
OH_NNCompilation* nnCompilation = reinterpret_cast<OH_NNCompilation*>(&compilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
const char* cacheDir = "../";
|
const char* cacheDir = "../";
|
||||||
uint32_t version = 1;
|
uint32_t version = 1;
|
||||||
std::size_t deviceId = 1;
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId));
|
|
||||||
OH_NN_ReturnCode ret = OH_NNCompilation_SetCache(nnCompilation, cacheDir, version);
|
OH_NN_ReturnCode ret = OH_NNCompilation_SetCache(nnCompilation, cacheDir, version);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, ret);
|
EXPECT_EQ(OH_NN_SUCCESS, ret);
|
||||||
}
|
}
|
||||||
@ -949,12 +907,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_performance_mode_001, testing
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation compilation(&innerModel);
|
|
||||||
OH_NNCompilation* nnCompilation = nullptr;
|
OH_NNCompilation* nnCompilation = nullptr;
|
||||||
OH_NN_PerformanceMode performanceMode = OH_NN_PERFORMANCE_NONE;
|
OH_NN_PerformanceMode performanceMode = OH_NN_PERFORMANCE_NONE;
|
||||||
|
|
||||||
std::size_t deviceId = 1;
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId));
|
|
||||||
OH_NN_ReturnCode ret = OH_NNCompilation_SetPerformanceMode(nnCompilation, performanceMode);
|
OH_NN_ReturnCode ret = OH_NNCompilation_SetPerformanceMode(nnCompilation, performanceMode);
|
||||||
EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
|
EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
|
||||||
}
|
}
|
||||||
@ -968,12 +923,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_performance_mode_002, testing
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation compilation(&innerModel);
|
|
||||||
OH_NNCompilation* nnCompilation = reinterpret_cast<OH_NNCompilation*>(&compilation);
|
|
||||||
OH_NN_PerformanceMode performanceMode = OH_NN_PERFORMANCE_NONE;
|
|
||||||
|
|
||||||
std::size_t deviceId = 1;
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId));
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NN_PerformanceMode performanceMode = OH_NN_PERFORMANCE_NONE;
|
||||||
|
|
||||||
OH_NN_ReturnCode ret = OH_NNCompilation_SetPerformanceMode(nnCompilation, performanceMode);
|
OH_NN_ReturnCode ret = OH_NNCompilation_SetPerformanceMode(nnCompilation, performanceMode);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, ret);
|
EXPECT_EQ(OH_NN_SUCCESS, ret);
|
||||||
@ -988,13 +941,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_priority_001, testing::ext::T
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation compilation(&innerModel);
|
|
||||||
OH_NNCompilation* nnCompilation = nullptr;
|
OH_NNCompilation* nnCompilation = nullptr;
|
||||||
OH_NN_Priority priority = OH_NN_PRIORITY_LOW;
|
OH_NN_Priority priority = OH_NN_PRIORITY_LOW;
|
||||||
|
|
||||||
std::size_t deviceId = 1;
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId));
|
|
||||||
|
|
||||||
OH_NN_ReturnCode ret = OH_NNCompilation_SetPriority(nnCompilation, priority);
|
OH_NN_ReturnCode ret = OH_NNCompilation_SetPriority(nnCompilation, priority);
|
||||||
EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
|
EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
|
||||||
}
|
}
|
||||||
@ -1008,12 +957,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_priority_002, testing::ext::T
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation compilation(&innerModel);
|
|
||||||
OH_NNCompilation* nnCompilation = reinterpret_cast<OH_NNCompilation*>(&compilation);
|
|
||||||
OH_NN_Priority priority = OH_NN_PRIORITY_LOW;
|
|
||||||
|
|
||||||
std::size_t deviceId = 1;
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId));
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NN_Priority priority = OH_NN_PRIORITY_LOW;
|
||||||
|
|
||||||
OH_NN_ReturnCode ret = OH_NNCompilation_SetPriority(nnCompilation, priority);
|
OH_NN_ReturnCode ret = OH_NNCompilation_SetPriority(nnCompilation, priority);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, ret);
|
EXPECT_EQ(OH_NN_SUCCESS, ret);
|
||||||
@ -1028,13 +975,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_enable_float16_001, testing::
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation compilation(&innerModel);
|
|
||||||
OH_NNCompilation* nnCompilation = nullptr;
|
OH_NNCompilation* nnCompilation = nullptr;
|
||||||
bool enableFloat16 = true;
|
bool enableFloat16 = true;
|
||||||
|
|
||||||
std::size_t deviceId = 1;
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId));
|
|
||||||
|
|
||||||
OH_NN_ReturnCode ret = OH_NNCompilation_EnableFloat16(nnCompilation, enableFloat16);
|
OH_NN_ReturnCode ret = OH_NNCompilation_EnableFloat16(nnCompilation, enableFloat16);
|
||||||
EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
|
EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
|
||||||
}
|
}
|
||||||
@ -1048,12 +991,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_enable_float16_002, testing::
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation compilation(&innerModel);
|
|
||||||
OH_NNCompilation* nnCompilation = reinterpret_cast<OH_NNCompilation*>(&compilation);
|
|
||||||
bool enableFloat16 = true;
|
|
||||||
|
|
||||||
std::size_t deviceId = 1;
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId));
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
bool enableFloat16 = true;
|
||||||
|
|
||||||
OH_NN_ReturnCode ret = OH_NNCompilation_EnableFloat16(nnCompilation, enableFloat16);
|
OH_NN_ReturnCode ret = OH_NNCompilation_EnableFloat16(nnCompilation, enableFloat16);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, ret);
|
EXPECT_EQ(OH_NN_SUCCESS, ret);
|
||||||
@ -1068,15 +1009,8 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_build_001, testing::ext::TestSize
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation compilation(&innerModel);
|
|
||||||
OH_NNCompilation* nnCompilation = nullptr;
|
OH_NNCompilation* nnCompilation = nullptr;
|
||||||
|
|
||||||
std::size_t deviceId = 1;
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId));
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetPerformance(OH_NN_PERFORMANCE_EXTREME));
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetPriority(OH_NN_PRIORITY_HIGH));
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetEnableFp16(true));
|
|
||||||
|
|
||||||
OH_NN_ReturnCode ret = OH_NNCompilation_Build(nnCompilation);
|
OH_NN_ReturnCode ret = OH_NNCompilation_Build(nnCompilation);
|
||||||
EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
|
EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
|
||||||
}
|
}
|
||||||
@ -1090,17 +1024,12 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_build_002, testing::ext::TestSize
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation compilation(&innerModel);
|
|
||||||
OH_NNCompilation* nnCompilation = reinterpret_cast<OH_NNCompilation*>(&compilation);
|
|
||||||
|
|
||||||
std::size_t deviceId = 1;
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId));
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetPerformance(OH_NN_PERFORMANCE_EXTREME));
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetPriority(OH_NN_PRIORITY_HIGH));
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetEnableFp16(true));
|
|
||||||
|
|
||||||
OH_NN_ReturnCode ret = OH_NNCompilation_Build(nnCompilation);
|
OH_NN_ReturnCode ret = OH_NNCompilation_Build(nnCompilation);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, ret);
|
EXPECT_EQ(OH_NN_FAILED, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1137,9 +1066,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_destroy_003, testing::ext::TestSi
|
|||||||
{
|
{
|
||||||
InnerModel* innerModel = new InnerModel();
|
InnerModel* innerModel = new InnerModel();
|
||||||
EXPECT_NE(nullptr, innerModel);
|
EXPECT_NE(nullptr, innerModel);
|
||||||
Compilation* compilation = new(std::nothrow) Compilation(innerModel);
|
|
||||||
EXPECT_NE(nullptr, compilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNCompilation* nnCompilation = reinterpret_cast<OH_NNCompilation*>(compilation);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
OH_NNCompilation_Destroy(&nnCompilation);
|
OH_NNCompilation_Destroy(&nnCompilation);
|
||||||
EXPECT_EQ(nullptr, nnCompilation);
|
EXPECT_EQ(nullptr, nnCompilation);
|
||||||
}
|
}
|
||||||
@ -1153,14 +1082,6 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_construct_001, testing::ext::TestSize
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation compilation(&innerModel);
|
|
||||||
|
|
||||||
std::size_t deviceId = 1;
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId));
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetEnableFp16(true));
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetPerformance(OH_NN_PERFORMANCE_EXTREME));
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetPriority(OH_NN_PRIORITY_HIGH));
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.Build());
|
|
||||||
|
|
||||||
OH_NNCompilation* nnCompilation = nullptr;
|
OH_NNCompilation* nnCompilation = nullptr;
|
||||||
OH_NNExecutor* executor = OH_NNExecutor_Construct(nnCompilation);
|
OH_NNExecutor* executor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
@ -1176,8 +1097,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_construct_002, testing::ext::TestSize
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation compilation(&innerModel);
|
|
||||||
OH_NNCompilation* nnCompilation = reinterpret_cast<OH_NNCompilation*>(&compilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
OH_NNExecutor * executor = OH_NNExecutor_Construct(nnCompilation);
|
OH_NNExecutor * executor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
EXPECT_EQ(nullptr, executor);
|
EXPECT_EQ(nullptr, executor);
|
||||||
}
|
}
|
||||||
@ -1191,18 +1113,11 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_construct_003, testing::ext::TestSize
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation compilation(&innerModel);
|
|
||||||
|
|
||||||
std::size_t deviceId = 1;
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId));
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetPerformance(OH_NN_PERFORMANCE_EXTREME));
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetPriority(OH_NN_PRIORITY_HIGH));
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetEnableFp16(true));
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.Build());
|
|
||||||
|
|
||||||
OH_NNCompilation* nnCompilation = reinterpret_cast<OH_NNCompilation*>(&compilation);
|
|
||||||
OH_NNExecutor * executor = OH_NNExecutor_Construct(nnCompilation);
|
OH_NNExecutor * executor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
EXPECT_NE(nullptr, executor);
|
EXPECT_EQ(nullptr, executor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1230,9 +1145,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setinput_002, testing::ext::TestSize.
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t inputIndex = 0;
|
uint32_t inputIndex = 0;
|
||||||
float input[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
|
float input[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
|
||||||
@ -1250,9 +1166,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setinput_003, testing::ext::TestSize.
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
SetTensor();
|
SetTensor();
|
||||||
|
|
||||||
@ -1271,9 +1188,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setinput_004, testing::ext::TestSize.
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t inputIndex = 0;
|
uint32_t inputIndex = 0;
|
||||||
SetTensor();
|
SetTensor();
|
||||||
@ -1293,9 +1211,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setinput_005, testing::ext::TestSize.
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t inputIndex = 0;
|
uint32_t inputIndex = 0;
|
||||||
int32_t dims[2] = {3, 4};
|
int32_t dims[2] = {3, 4};
|
||||||
@ -1305,7 +1224,7 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setinput_005, testing::ext::TestSize.
|
|||||||
const void *buffer = input;
|
const void *buffer = input;
|
||||||
size_t length = 12 * sizeof(float);
|
size_t length = 12 * sizeof(float);
|
||||||
OH_NN_ReturnCode ret = OH_NNExecutor_SetInput(nnExecutor, inputIndex, &m_tensor, buffer, length);
|
OH_NN_ReturnCode ret = OH_NNExecutor_SetInput(nnExecutor, inputIndex, &m_tensor, buffer, length);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, ret);
|
EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1331,9 +1250,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setoutput_002, testing::ext::TestSize
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t outputIndex = 0;
|
uint32_t outputIndex = 0;
|
||||||
void *buffer = nullptr;
|
void *buffer = nullptr;
|
||||||
@ -1350,9 +1270,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setoutput_003, testing::ext::TestSize
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t outputIndex = 0;
|
uint32_t outputIndex = 0;
|
||||||
float input[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
|
float input[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
|
||||||
@ -1370,14 +1291,15 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setoutput_004, testing::ext::TestSize
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t outputIndex = 0;
|
uint32_t outputIndex = 0;
|
||||||
float output[12];
|
float output[12];
|
||||||
size_t length = 12 * sizeof(float);
|
size_t length = 12 * sizeof(float);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, OH_NNExecutor_SetOutput(nnExecutor, outputIndex, output, length));
|
EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNExecutor_SetOutput(nnExecutor, outputIndex, output, length));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1389,12 +1311,8 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_getoutputshape_001, testing::ext::Tes
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
|
||||||
OH_NNExecutor* nnExecutor = nullptr;
|
OH_NNExecutor* nnExecutor = nullptr;
|
||||||
|
|
||||||
SetInputAndOutput(executor);
|
|
||||||
|
|
||||||
int32_t* ptr = nullptr;
|
int32_t* ptr = nullptr;
|
||||||
int32_t** shape = &ptr;
|
int32_t** shape = &ptr;
|
||||||
uint32_t length = 2;
|
uint32_t length = 2;
|
||||||
@ -1412,11 +1330,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_getoutputshape_002, testing::ext::Tes
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
|
||||||
|
|
||||||
SetInputAndOutput(executor);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t outputIndex = 0;
|
uint32_t outputIndex = 0;
|
||||||
int32_t** shape = nullptr;
|
int32_t** shape = nullptr;
|
||||||
@ -1434,11 +1351,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_getoutputshape_003, testing::ext::Tes
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
|
||||||
|
|
||||||
SetInputAndOutput(executor);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
int32_t expectDim[2] = {3, 3};
|
int32_t expectDim[2] = {3, 3};
|
||||||
int32_t* ptr = expectDim;
|
int32_t* ptr = expectDim;
|
||||||
@ -1458,11 +1374,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_getoutputshape_004, testing::ext::Tes
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
|
||||||
|
|
||||||
SetInputAndOutput(executor);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
int32_t* ptr = nullptr;
|
int32_t* ptr = nullptr;
|
||||||
int32_t** shape = &ptr;
|
int32_t** shape = &ptr;
|
||||||
@ -1479,17 +1394,16 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_getoutputshape_005, testing::ext::Tes
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
|
||||||
|
|
||||||
SetInputAndOutput(executor);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
int32_t* ptr = nullptr;
|
int32_t* ptr = nullptr;
|
||||||
int32_t** shape = &ptr;
|
int32_t** shape = &ptr;
|
||||||
uint32_t length = 2;
|
uint32_t length = 2;
|
||||||
uint32_t outputIndex = 0;
|
uint32_t outputIndex = 0;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, OH_NNExecutor_GetOutputShape(nnExecutor, outputIndex, shape, &length));
|
EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNExecutor_GetOutputShape(nnExecutor, outputIndex, shape, &length));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1512,25 +1426,14 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_run_002, testing::ext::TestSize.Level
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
|
||||||
|
|
||||||
float input1[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
float input2[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
uint32_t input1Index = 0;
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
uint32_t input2Index = 1;
|
|
||||||
|
|
||||||
int32_t inputDims[2] = {3, 4};
|
int32_t inputDims[2] = {3, 4};
|
||||||
size_t length = 12 * sizeof(float);
|
|
||||||
m_tensor = {OH_NN_FLOAT32, 2, inputDims, nullptr, OH_NN_TENSOR};
|
m_tensor = {OH_NN_FLOAT32, 2, inputDims, nullptr, OH_NN_TENSOR};
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, executor.SetInput(input1Index, m_tensor, input1, length));
|
EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNExecutor_Run(nnExecutor));
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, executor.SetInput(input2Index, m_tensor, input2, length));
|
|
||||||
|
|
||||||
float output[12];
|
|
||||||
uint32_t outputIndex = 0;
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, executor.SetOutput(outputIndex, output, length));
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, OH_NNExecutor_Run(nnExecutor));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1557,9 +1460,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_allocate_input_memory_002, testing::
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t outputIndex = 0;
|
uint32_t outputIndex = 0;
|
||||||
size_t length = 0;
|
size_t length = 0;
|
||||||
@ -1577,9 +1481,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_allocate_input_memory_003, testing::
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t outputIndex = 6;
|
uint32_t outputIndex = 6;
|
||||||
size_t length = 9 * sizeof(float);
|
size_t length = 9 * sizeof(float);
|
||||||
@ -1597,15 +1502,16 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_allocate_input_memory_004, testing::
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t outputIndex = 0;
|
uint32_t outputIndex = 0;
|
||||||
size_t length = 9 * sizeof(float);
|
size_t length = 9 * sizeof(float);
|
||||||
|
|
||||||
OH_NN_Memory* ret = OH_NNExecutor_AllocateInputMemory(nnExecutor, outputIndex, length);
|
OH_NN_Memory* ret = OH_NNExecutor_AllocateInputMemory(nnExecutor, outputIndex, length);
|
||||||
EXPECT_NE(nullptr, ret);
|
EXPECT_EQ(nullptr, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1632,9 +1538,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_allocate_output_memory_002, testing:
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t outputIndex = 0;
|
uint32_t outputIndex = 0;
|
||||||
size_t length = 0;
|
size_t length = 0;
|
||||||
@ -1652,9 +1559,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_allocate_output_memory_003, testing:
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t outputIndex = 6;
|
uint32_t outputIndex = 6;
|
||||||
size_t length = 9 * sizeof(float);
|
size_t length = 9 * sizeof(float);
|
||||||
@ -1672,15 +1580,16 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_allocate_output_memory_004, testing:
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t outputIndex = 0;
|
uint32_t outputIndex = 0;
|
||||||
size_t length = 9 * sizeof(float);
|
size_t length = 9 * sizeof(float);
|
||||||
|
|
||||||
OH_NN_Memory* ret = OH_NNExecutor_AllocateOutputMemory(nnExecutor, outputIndex, length);
|
OH_NN_Memory* ret = OH_NNExecutor_AllocateOutputMemory(nnExecutor, outputIndex, length);
|
||||||
EXPECT_NE(nullptr, ret);
|
EXPECT_EQ(nullptr, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1693,8 +1602,6 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_input_memory_001, testing::e
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
BuildModel(innerModel);
|
BuildModel(innerModel);
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
|
||||||
OH_NNExecutor* nnExecutor = nullptr;
|
OH_NNExecutor* nnExecutor = nullptr;
|
||||||
|
|
||||||
uint32_t inputIndex = 0;
|
uint32_t inputIndex = 0;
|
||||||
@ -1702,8 +1609,6 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_input_memory_001, testing::e
|
|||||||
void* const data = dataArry;
|
void* const data = dataArry;
|
||||||
OH_NN_Memory memory = {data, 9 * sizeof(float)};
|
OH_NN_Memory memory = {data, 9 * sizeof(float)};
|
||||||
OH_NN_Memory* pMemory = &memory;
|
OH_NN_Memory* pMemory = &memory;
|
||||||
size_t length = 9 * sizeof(float);
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, executor.CreateInputMemory(inputIndex, length, &pMemory));
|
|
||||||
OH_NNExecutor_DestroyInputMemory(nnExecutor, inputIndex, &pMemory);
|
OH_NNExecutor_DestroyInputMemory(nnExecutor, inputIndex, &pMemory);
|
||||||
EXPECT_EQ(nullptr, nnExecutor);
|
EXPECT_EQ(nullptr, nnExecutor);
|
||||||
}
|
}
|
||||||
@ -1717,9 +1622,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_input_memory_002, testing::e
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
BuildModel(innerModel);
|
BuildModel(innerModel);
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t inputIndex = 0;
|
uint32_t inputIndex = 0;
|
||||||
OH_NN_Memory** memory = nullptr;
|
OH_NN_Memory** memory = nullptr;
|
||||||
@ -1736,9 +1642,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_input_memory_003, testing::e
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
BuildModel(innerModel);
|
BuildModel(innerModel);
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t inputIndex = 0;
|
uint32_t inputIndex = 0;
|
||||||
OH_NN_Memory* memory = nullptr;
|
OH_NN_Memory* memory = nullptr;
|
||||||
@ -1756,9 +1663,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_input_memory_004, testing::e
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
BuildModel(innerModel);
|
BuildModel(innerModel);
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t inputIndex = 6;
|
uint32_t inputIndex = 6;
|
||||||
float dataArry[9] {0, 1, 2, 3, 4, 5, 6, 7, 8};
|
float dataArry[9] {0, 1, 2, 3, 4, 5, 6, 7, 8};
|
||||||
@ -1778,19 +1686,18 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_input_memory_005, testing::e
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
BuildModel(innerModel);
|
BuildModel(innerModel);
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t inputIndex = 0;
|
uint32_t inputIndex = 0;
|
||||||
float dataArry[9] {0, 1, 2, 3, 4, 5, 6, 7, 8};
|
float dataArry[9] {0, 1, 2, 3, 4, 5, 6, 7, 8};
|
||||||
void* const data = dataArry;
|
void* const data = dataArry;
|
||||||
OH_NN_Memory memory = {data, 9 * sizeof(float)};
|
OH_NN_Memory memory = {data, 9 * sizeof(float)};
|
||||||
OH_NN_Memory* pMemory = &memory;
|
OH_NN_Memory* pMemory = &memory;
|
||||||
size_t length = 9 * sizeof(float);
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, executor.CreateInputMemory(inputIndex, length, &pMemory));
|
|
||||||
OH_NNExecutor_DestroyInputMemory(nnExecutor, inputIndex, &pMemory);
|
OH_NNExecutor_DestroyInputMemory(nnExecutor, inputIndex, &pMemory);
|
||||||
EXPECT_EQ(nullptr, pMemory);
|
EXPECT_NE(nullptr, pMemory);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1819,9 +1726,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_output_memory_002, testing::
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t outputIndex = 0;
|
uint32_t outputIndex = 0;
|
||||||
OH_NN_Memory** memory = nullptr;
|
OH_NN_Memory** memory = nullptr;
|
||||||
@ -1838,9 +1746,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_output_memory_003, testing::
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t outputIndex = 0;
|
uint32_t outputIndex = 0;
|
||||||
OH_NN_Memory* memory = nullptr;
|
OH_NN_Memory* memory = nullptr;
|
||||||
@ -1858,9 +1767,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_output_memory_004, testing::
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t outputIndex = 6;
|
uint32_t outputIndex = 6;
|
||||||
float dataArry[9] {0, 1, 2, 3, 4, 5, 6, 7, 8};
|
float dataArry[9] {0, 1, 2, 3, 4, 5, 6, 7, 8};
|
||||||
@ -1880,19 +1790,18 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_output_memory_005, testing::
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
float dataArry[9] {0, 1, 2, 3, 4, 5, 6, 7, 8};
|
float dataArry[9] {0, 1, 2, 3, 4, 5, 6, 7, 8};
|
||||||
void* const data = dataArry;
|
void* const data = dataArry;
|
||||||
OH_NN_Memory memory = {data, 9 * sizeof(float)};
|
OH_NN_Memory memory = {data, 9 * sizeof(float)};
|
||||||
OH_NN_Memory* pMemory = &memory;
|
OH_NN_Memory* pMemory = &memory;
|
||||||
size_t length = 9 * sizeof(float);
|
|
||||||
uint32_t outputIndex = 0;
|
uint32_t outputIndex = 0;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, executor.CreateOutputMemory(outputIndex, length, &pMemory));
|
|
||||||
OH_NNExecutor_DestroyOutputMemory(nnExecutor, outputIndex, &pMemory);
|
OH_NNExecutor_DestroyOutputMemory(nnExecutor, outputIndex, &pMemory);
|
||||||
EXPECT_EQ(nullptr, pMemory);
|
EXPECT_NE(nullptr, pMemory);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1924,9 +1833,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_set_input_with_memory_002, testing::
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
OH_NN_Tensor* operand = nullptr;
|
OH_NN_Tensor* operand = nullptr;
|
||||||
|
|
||||||
@ -1948,9 +1858,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_set_input_with_memory_003, testing::
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
SetTensor();
|
SetTensor();
|
||||||
|
|
||||||
@ -1969,9 +1880,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_set_input_with_memory_004, testing::
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t inputIndex = 0;
|
uint32_t inputIndex = 0;
|
||||||
int32_t dims[2] = {3, 4};
|
int32_t dims[2] = {3, 4};
|
||||||
@ -1982,7 +1894,7 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_set_input_with_memory_004, testing::
|
|||||||
OH_NN_Memory memory = {data, 12 * sizeof(float)};
|
OH_NN_Memory memory = {data, 12 * sizeof(float)};
|
||||||
|
|
||||||
OH_NN_ReturnCode ret = OH_NNExecutor_SetInputWithMemory(nnExecutor, inputIndex, &m_tensor, &memory);
|
OH_NN_ReturnCode ret = OH_NNExecutor_SetInputWithMemory(nnExecutor, inputIndex, &m_tensor, &memory);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, ret);
|
EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2011,9 +1923,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_set_output_with_memory_002, testing:
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t outputIndex = 0;
|
uint32_t outputIndex = 0;
|
||||||
OH_NN_Memory* memory = nullptr;
|
OH_NN_Memory* memory = nullptr;
|
||||||
@ -2030,16 +1943,17 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_set_output_with_memory_003, testing:
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t outputIndex = 0;
|
uint32_t outputIndex = 0;
|
||||||
float dataArry[12] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
|
float dataArry[12] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
|
||||||
void* const data = dataArry;
|
void* const data = dataArry;
|
||||||
OH_NN_Memory memory = {data, 12 * sizeof(float)};
|
OH_NN_Memory memory = {data, 12 * sizeof(float)};
|
||||||
OH_NN_ReturnCode ret = OH_NNExecutor_SetOutputWithMemory(nnExecutor, outputIndex, &memory);
|
OH_NN_ReturnCode ret = OH_NNExecutor_SetOutputWithMemory(nnExecutor, outputIndex, &memory);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, ret);
|
EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2067,25 +1981,6 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_002, testing::ext::TestSize.
|
|||||||
EXPECT_EQ(nullptr, nnExecutor);
|
EXPECT_EQ(nullptr, nnExecutor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* @tc.name: executor_destroy_003
|
|
||||||
* @tc.desc: Verify the normal model of the OH_NNExecutor_Destroy function.
|
|
||||||
* @tc.type: FUNC
|
|
||||||
*/
|
|
||||||
HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_003, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
InnerModel* innerModel = new InnerModel();
|
|
||||||
EXPECT_NE(nullptr, innerModel);
|
|
||||||
Compilation* innerCompilation = new(std::nothrow) Compilation(innerModel);
|
|
||||||
EXPECT_NE(nullptr, innerCompilation);
|
|
||||||
Executor* executor = new(std::nothrow) Executor(innerCompilation);
|
|
||||||
EXPECT_NE(nullptr, executor);
|
|
||||||
|
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(executor);
|
|
||||||
OH_NNExecutor_Destroy(&nnExecutor);
|
|
||||||
EXPECT_EQ(nullptr, nnExecutor);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @tc.name: device_get_all_devices_id_001
|
* @tc.name: device_get_all_devices_id_001
|
||||||
* @tc.desc: Verify the allDevicesID is nullptr of the OH_NNDevice_GetAllDevicesID function.
|
* @tc.desc: Verify the allDevicesID is nullptr of the OH_NNDevice_GetAllDevicesID function.
|
||||||
@ -2213,7 +2108,7 @@ HWTEST_F(NeuralNetworkRuntimeTest, device_get_name_004, testing::ext::TestSize.L
|
|||||||
const char* name = nullptr;
|
const char* name = nullptr;
|
||||||
const char** pName = &name;
|
const char** pName = &name;
|
||||||
OH_NN_ReturnCode ret = OH_NNDevice_GetName(deviceID, pName);
|
OH_NN_ReturnCode ret = OH_NNDevice_GetName(deviceID, pName);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, ret);
|
EXPECT_EQ(OH_NN_FAILED, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2254,7 +2149,7 @@ HWTEST_F(NeuralNetworkRuntimeTest, device_get_type_003, testing::ext::TestSize.L
|
|||||||
OH_NN_DeviceType deviceType = OH_NN_OTHERS;
|
OH_NN_DeviceType deviceType = OH_NN_OTHERS;
|
||||||
OH_NN_DeviceType* pDeviceType = &deviceType;
|
OH_NN_DeviceType* pDeviceType = &deviceType;
|
||||||
OH_NN_ReturnCode ret = OH_NNDevice_GetType(deviceID, pDeviceType);
|
OH_NN_ReturnCode ret = OH_NNDevice_GetType(deviceID, pDeviceType);
|
||||||
EXPECT_EQ(OH_NN_UNAVAILABLE_DEVICE, ret);
|
EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2268,7 +2163,7 @@ HWTEST_F(NeuralNetworkRuntimeTest, device_get_type_004, testing::ext::TestSize.L
|
|||||||
OH_NN_DeviceType deviceType = OH_NN_CPU;
|
OH_NN_DeviceType deviceType = OH_NN_CPU;
|
||||||
OH_NN_DeviceType* pDeviceType = &deviceType;
|
OH_NN_DeviceType* pDeviceType = &deviceType;
|
||||||
OH_NN_ReturnCode ret = OH_NNDevice_GetType(deviceID, pDeviceType);
|
OH_NN_ReturnCode ret = OH_NNDevice_GetType(deviceID, pDeviceType);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, ret);
|
EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
|
||||||
}
|
}
|
||||||
} // namespace Unittest
|
} // namespace Unittest
|
||||||
} // namespace NeuralNetworkRuntime
|
} // namespace NeuralNetworkRuntime
|
||||||
|
@ -117,7 +117,7 @@ HWTEST_F(HDIPreparedModelTest, hidpreparedmodel_exportmodelcache_001, TestSize.L
|
|||||||
OHOS::sptr<V2_0::IPreparedModel> hdiPreparedModel =
|
OHOS::sptr<V2_0::IPreparedModel> hdiPreparedModel =
|
||||||
OHOS::sptr<V2_0::MockIPreparedModel>(new (std::nothrow) V2_0::MockIPreparedModel());
|
OHOS::sptr<V2_0::MockIPreparedModel>(new (std::nothrow) V2_0::MockIPreparedModel());
|
||||||
std::unique_ptr<HDIPreparedModelV2_0> preparedModel = std::make_unique<HDIPreparedModelV2_0>(hdiPreparedModel);
|
std::unique_ptr<HDIPreparedModelV2_0> preparedModel = std::make_unique<HDIPreparedModelV2_0>(hdiPreparedModel);
|
||||||
std::vector<ModelBuffer> modelCache;
|
std::vector<Buffer> modelCache;
|
||||||
EXPECT_CALL(*((V2_0::MockIPreparedModel*)hdiPreparedModel.GetRefPtr()),
|
EXPECT_CALL(*((V2_0::MockIPreparedModel*)hdiPreparedModel.GetRefPtr()),
|
||||||
ExportModelCache(::testing::_))
|
ExportModelCache(::testing::_))
|
||||||
.WillRepeatedly(
|
.WillRepeatedly(
|
||||||
@ -144,7 +144,7 @@ HWTEST_F(HDIPreparedModelTest, hidpreparedmodel_exportmodelcache_002, TestSize.L
|
|||||||
EXPECT_NE(mockPreparedModel, nullptr);
|
EXPECT_NE(mockPreparedModel, nullptr);
|
||||||
|
|
||||||
std::unique_ptr<HDIPreparedModelV2_0> preparedModel = std::make_unique<HDIPreparedModelV2_0>(mockPreparedModel);
|
std::unique_ptr<HDIPreparedModelV2_0> preparedModel = std::make_unique<HDIPreparedModelV2_0>(mockPreparedModel);
|
||||||
std::vector<ModelBuffer> modelCache;
|
std::vector<Buffer> modelCache;
|
||||||
EXPECT_CALL(*((V2_0::MockIPreparedModel*)mockPreparedModel.GetRefPtr()),
|
EXPECT_CALL(*((V2_0::MockIPreparedModel*)mockPreparedModel.GetRefPtr()),
|
||||||
ExportModelCache(::testing::_))
|
ExportModelCache(::testing::_))
|
||||||
.WillRepeatedly(
|
.WillRepeatedly(
|
||||||
@ -170,9 +170,9 @@ HWTEST_F(HDIPreparedModelTest, hidpreparedmodel_exportmodelcache_003, TestSize.L
|
|||||||
EXPECT_NE(hdiPreparedModel, nullptr);
|
EXPECT_NE(hdiPreparedModel, nullptr);
|
||||||
|
|
||||||
std::unique_ptr<HDIPreparedModelV2_0> preparedModel = std::make_unique<HDIPreparedModelV2_0>(hdiPreparedModel);
|
std::unique_ptr<HDIPreparedModelV2_0> preparedModel = std::make_unique<HDIPreparedModelV2_0>(hdiPreparedModel);
|
||||||
std::vector<ModelBuffer> modelCache {{nullptr, 0}};
|
std::vector<Buffer> modelCache;
|
||||||
OH_NN_ReturnCode result = preparedModel->ExportModelCache(modelCache);
|
OH_NN_ReturnCode result = preparedModel->ExportModelCache(modelCache);
|
||||||
EXPECT_EQ(OH_NN_INVALID_PARAMETER, result);
|
EXPECT_EQ(OH_NN_SUCCESS, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -188,7 +188,7 @@ HWTEST_F(HDIPreparedModelTest, hidpreparedmodel_exportmodelcache_004, TestSize.L
|
|||||||
EXPECT_NE(mockPreparedModel, nullptr);
|
EXPECT_NE(mockPreparedModel, nullptr);
|
||||||
|
|
||||||
std::unique_ptr<HDIPreparedModelV2_0> preparedModel = std::make_unique<HDIPreparedModelV2_0>(mockPreparedModel);
|
std::unique_ptr<HDIPreparedModelV2_0> preparedModel = std::make_unique<HDIPreparedModelV2_0>(mockPreparedModel);
|
||||||
std::vector<ModelBuffer> modelCache;
|
std::vector<Buffer> modelCache;
|
||||||
EXPECT_CALL(*((V2_0::MockIPreparedModel*)mockPreparedModel.GetRefPtr()),
|
EXPECT_CALL(*((V2_0::MockIPreparedModel*)mockPreparedModel.GetRefPtr()),
|
||||||
ExportModelCache(::testing::_))
|
ExportModelCache(::testing::_))
|
||||||
.WillRepeatedly(
|
.WillRepeatedly(
|
||||||
@ -199,7 +199,7 @@ HWTEST_F(HDIPreparedModelTest, hidpreparedmodel_exportmodelcache_004, TestSize.L
|
|||||||
);
|
);
|
||||||
|
|
||||||
OH_NN_ReturnCode result = preparedModel->ExportModelCache(modelCache);
|
OH_NN_ReturnCode result = preparedModel->ExportModelCache(modelCache);
|
||||||
EXPECT_EQ(OH_NN_UNAVAILABLE_DEVICE, result);
|
EXPECT_EQ(OH_NN_SAVE_CACHE_EXCEPTION, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,14 +62,12 @@ void InnerModelTest::SetLiteGraph(mindspore::lite::LiteGraph* liteGraph)
|
|||||||
|
|
||||||
for (size_t indexInput = 0; indexInput < liteGraph->input_indices_.size(); ++indexInput) {
|
for (size_t indexInput = 0; indexInput < liteGraph->input_indices_.size(); ++indexInput) {
|
||||||
const std::vector<uint8_t> data(36, 1);
|
const std::vector<uint8_t> data(36, 1);
|
||||||
liteGraph->all_tensors_.emplace_back(mindspore::lite::MindIR_Tensor_Create(liteGraph->name_,
|
liteGraph->all_tensors_.emplace_back(mindspore::lite::MindIR_Tensor_Create());
|
||||||
mindspore::lite::DATA_TYPE_FLOAT32, m_dimInput, mindspore::lite::FORMAT_NCHW, data, quant_params));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t indexOutput = 0; indexOutput < liteGraph->output_indices_.size(); ++indexOutput) {
|
for (size_t indexOutput = 0; indexOutput < liteGraph->output_indices_.size(); ++indexOutput) {
|
||||||
const std::vector<uint8_t> dataOut(36, 1);
|
const std::vector<uint8_t> dataOut(36, 1);
|
||||||
liteGraph->all_tensors_.emplace_back(mindspore::lite::MindIR_Tensor_Create(liteGraph->name_,
|
liteGraph->all_tensors_.emplace_back(mindspore::lite::MindIR_Tensor_Create());
|
||||||
mindspore::lite::DATA_TYPE_FLOAT32, m_dimOutput, mindspore::lite::FORMAT_NCHW, dataOut, quant_params));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,8 +108,14 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_001, Test
|
|||||||
m_inputIndices = {};
|
m_inputIndices = {};
|
||||||
|
|
||||||
SetLiteGraph(liteGraph);
|
SetLiteGraph(liteGraph);
|
||||||
EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(liteGraph));
|
|
||||||
mindspore::lite::MindIR_LiteGraph_Destroy(&liteGraph);
|
Buffer buffer;
|
||||||
|
std::string modelName;
|
||||||
|
std::string isProfiling;
|
||||||
|
std::string opLayout;
|
||||||
|
std::map<std::string, std::string> opLayouts;
|
||||||
|
|
||||||
|
EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -126,8 +130,14 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_002, Test
|
|||||||
m_inputIndices = {6};
|
m_inputIndices = {6};
|
||||||
|
|
||||||
SetLiteGraph(liteGraph);
|
SetLiteGraph(liteGraph);
|
||||||
EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(liteGraph));
|
|
||||||
mindspore::lite::MindIR_LiteGraph_Destroy(&liteGraph);
|
Buffer buffer;
|
||||||
|
std::string modelName;
|
||||||
|
std::string isProfiling;
|
||||||
|
std::string opLayout;
|
||||||
|
std::map<std::string, std::string> opLayouts;
|
||||||
|
|
||||||
|
EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -141,7 +151,14 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_003, Test
|
|||||||
EXPECT_NE(nullptr, liteGraph);
|
EXPECT_NE(nullptr, liteGraph);
|
||||||
|
|
||||||
SetLiteGraph(liteGraph);
|
SetLiteGraph(liteGraph);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph));
|
|
||||||
|
Buffer buffer;
|
||||||
|
std::string modelName;
|
||||||
|
std::string isProfiling;
|
||||||
|
std::string opLayout;
|
||||||
|
std::map<std::string, std::string> opLayouts;
|
||||||
|
|
||||||
|
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -156,8 +173,13 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_004, Test
|
|||||||
m_dimInput = {3, -3};
|
m_dimInput = {3, -3};
|
||||||
|
|
||||||
SetLiteGraph(liteGraph);
|
SetLiteGraph(liteGraph);
|
||||||
EXPECT_EQ(OH_NN_NULL_PTR, m_innerModelTest.BuildFromLiteGraph(liteGraph));
|
Buffer buffer;
|
||||||
mindspore::lite::MindIR_LiteGraph_Destroy(&liteGraph);
|
std::string modelName;
|
||||||
|
std::string isProfiling;
|
||||||
|
std::string opLayout;
|
||||||
|
std::map<std::string, std::string> opLayouts;
|
||||||
|
|
||||||
|
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -172,8 +194,13 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_005, Test
|
|||||||
m_outputIndices = {6};
|
m_outputIndices = {6};
|
||||||
|
|
||||||
SetLiteGraph(liteGraph);
|
SetLiteGraph(liteGraph);
|
||||||
EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(liteGraph));
|
Buffer buffer;
|
||||||
mindspore::lite::MindIR_LiteGraph_Destroy(&liteGraph);
|
std::string modelName;
|
||||||
|
std::string isProfiling;
|
||||||
|
std::string opLayout;
|
||||||
|
std::map<std::string, std::string> opLayouts;
|
||||||
|
|
||||||
|
EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -183,7 +210,36 @@ HWTEST_F(InnerModelTest, inner_model_construct_nntensor_from_litegraph_005, Test
|
|||||||
*/
|
*/
|
||||||
HWTEST_F(InnerModelTest, inner_model_build_from_lite_graph_001, TestSize.Level1)
|
HWTEST_F(InnerModelTest, inner_model_build_from_lite_graph_001, TestSize.Level1)
|
||||||
{
|
{
|
||||||
EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(nullptr));
|
char d = 'a';
|
||||||
|
char * cr = &d;
|
||||||
|
struct OH_NN_Extension on_exit = {
|
||||||
|
"zhou", cr, 5
|
||||||
|
};
|
||||||
|
OH_NN_Extension *extensions = &on_exit;
|
||||||
|
size_t extensionSize = 1;
|
||||||
|
Buffer buffer;
|
||||||
|
std::string modelName;
|
||||||
|
std::string isProfiling;
|
||||||
|
std::string opLayout;
|
||||||
|
std::map<std::string, std::string> opLayouts;
|
||||||
|
for (size_t i = 0; i < extensionSize; ++i) {
|
||||||
|
std::string name = extensions[i].name;
|
||||||
|
if (name == "QuantBuffer") {
|
||||||
|
buffer.data = extensions[i].value;
|
||||||
|
buffer.length = extensions[i].valueSize;
|
||||||
|
} else if (name == "ModelName") {
|
||||||
|
modelName.assign(extensions[i].value, extensions[i].value + extensions[i].valueSize);
|
||||||
|
} else if (name == "Profiling") {
|
||||||
|
isProfiling.assign(extensions[i].value, extensions[i].value + extensions[i].valueSize);
|
||||||
|
LOGI("OH_NNModel_BuildFromLiteGraph isProfiling enable.");
|
||||||
|
} else if (name == "opLayout") {
|
||||||
|
opLayout.assign(extensions[i].value, extensions[i].value + extensions[i].valueSize);
|
||||||
|
opLayouts.insert({opLayout, "hiai::ExecuteDevice::CPU"});
|
||||||
|
LOGI("OH_NNModel_BuildFromLiteGraph opLayout:%{public}s.", opLayout.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPECT_EQ(OH_NN_INVALID_PARAMETER, m_innerModelTest.BuildFromLiteGraph(nullptr, buffer, modelName, isProfiling, opLayouts));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -197,8 +253,14 @@ HWTEST_F(InnerModelTest, inner_model_build_from_lite_graph_002, TestSize.Level1)
|
|||||||
EXPECT_NE(nullptr, liteGraph);
|
EXPECT_NE(nullptr, liteGraph);
|
||||||
|
|
||||||
SetLiteGraph(liteGraph);
|
SetLiteGraph(liteGraph);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph));
|
Buffer buffer;
|
||||||
EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.BuildFromLiteGraph(liteGraph));
|
std::string modelName;
|
||||||
|
std::string isProfiling;
|
||||||
|
std::string opLayout;
|
||||||
|
std::map<std::string, std::string> opLayouts;
|
||||||
|
|
||||||
|
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts));
|
||||||
|
EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -217,9 +279,13 @@ HWTEST_F(InnerModelTest, inner_model_build_from_lite_graph_003, TestSize.Level1)
|
|||||||
const int32_t dimInput[2] = {2, 2};
|
const int32_t dimInput[2] = {2, 2};
|
||||||
const OH_NN_Tensor& tensor = {OH_NN_INT8, 2, dimInput, nullptr, OH_NN_TENSOR};
|
const OH_NN_Tensor& tensor = {OH_NN_INT8, 2, dimInput, nullptr, OH_NN_TENSOR};
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.AddTensor(tensor));
|
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.AddTensor(tensor));
|
||||||
|
Buffer buffer;
|
||||||
|
std::string modelName;
|
||||||
|
std::string isProfiling;
|
||||||
|
std::string opLayout;
|
||||||
|
std::map<std::string, std::string> opLayouts;
|
||||||
|
|
||||||
EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.BuildFromLiteGraph(liteGraph));
|
EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts));
|
||||||
mindspore::lite::MindIR_LiteGraph_Destroy(&liteGraph);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -245,7 +311,14 @@ HWTEST_F(InnerModelTest, inner_model_add_tensor_002, TestSize.Level1)
|
|||||||
mindspore::lite::LiteGraph* liteGraph = new (std::nothrow) mindspore::lite::LiteGraph();
|
mindspore::lite::LiteGraph* liteGraph = new (std::nothrow) mindspore::lite::LiteGraph();
|
||||||
EXPECT_NE(nullptr, liteGraph);
|
EXPECT_NE(nullptr, liteGraph);
|
||||||
SetLiteGraph(liteGraph);
|
SetLiteGraph(liteGraph);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph));
|
|
||||||
|
Buffer buffer;
|
||||||
|
std::string modelName;
|
||||||
|
std::string isProfiling;
|
||||||
|
std::string opLayout;
|
||||||
|
std::map<std::string, std::string> opLayouts;
|
||||||
|
|
||||||
|
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts));
|
||||||
|
|
||||||
const int32_t dimInput[2] = {2, 2};
|
const int32_t dimInput[2] = {2, 2};
|
||||||
const OH_NN_Tensor& tensor = {OH_NN_INT8, 2, dimInput, nullptr, OH_NN_TENSOR};
|
const OH_NN_Tensor& tensor = {OH_NN_INT8, 2, dimInput, nullptr, OH_NN_TENSOR};
|
||||||
@ -338,7 +411,14 @@ HWTEST_F(InnerModelTest, inner_model_set_tensor_value_005, TestSize.Level1)
|
|||||||
mindspore::lite::LiteGraph* liteGraph = new (std::nothrow) mindspore::lite::LiteGraph();
|
mindspore::lite::LiteGraph* liteGraph = new (std::nothrow) mindspore::lite::LiteGraph();
|
||||||
EXPECT_NE(nullptr, liteGraph);
|
EXPECT_NE(nullptr, liteGraph);
|
||||||
SetLiteGraph(liteGraph);
|
SetLiteGraph(liteGraph);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph));
|
|
||||||
|
Buffer buffer;
|
||||||
|
std::string modelName;
|
||||||
|
std::string isProfiling;
|
||||||
|
std::string opLayout;
|
||||||
|
std::map<std::string, std::string> opLayouts;
|
||||||
|
|
||||||
|
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts));
|
||||||
|
|
||||||
EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.SetTensorValue(index,
|
EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.SetTensorValue(index,
|
||||||
static_cast<const void *>(&activation), sizeof(int8_t)));
|
static_cast<const void *>(&activation), sizeof(int8_t)));
|
||||||
@ -418,7 +498,14 @@ HWTEST_F(InnerModelTest, inner_model_add_operation_002, TestSize.Level1)
|
|||||||
mindspore::lite::LiteGraph* liteGraph = new (std::nothrow) mindspore::lite::LiteGraph();
|
mindspore::lite::LiteGraph* liteGraph = new (std::nothrow) mindspore::lite::LiteGraph();
|
||||||
EXPECT_NE(nullptr, liteGraph);
|
EXPECT_NE(nullptr, liteGraph);
|
||||||
SetLiteGraph(liteGraph);
|
SetLiteGraph(liteGraph);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph));
|
|
||||||
|
Buffer buffer;
|
||||||
|
std::string modelName;
|
||||||
|
std::string isProfiling;
|
||||||
|
std::string opLayout;
|
||||||
|
std::map<std::string, std::string> opLayouts;
|
||||||
|
|
||||||
|
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts));
|
||||||
|
|
||||||
EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.AddOperation(m_opType, m_params, m_inputs,
|
EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.AddOperation(m_opType, m_params, m_inputs,
|
||||||
m_outputs));
|
m_outputs));
|
||||||
@ -611,7 +698,14 @@ HWTEST_F(InnerModelTest, inner_model_specify_inputs_and_outputs_002, TestSize.Le
|
|||||||
mindspore::lite::LiteGraph* liteGraph = new (std::nothrow) mindspore::lite::LiteGraph();
|
mindspore::lite::LiteGraph* liteGraph = new (std::nothrow) mindspore::lite::LiteGraph();
|
||||||
EXPECT_NE(nullptr, liteGraph);
|
EXPECT_NE(nullptr, liteGraph);
|
||||||
SetLiteGraph(liteGraph);
|
SetLiteGraph(liteGraph);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph));
|
|
||||||
|
Buffer buffer;
|
||||||
|
std::string modelName;
|
||||||
|
std::string isProfiling;
|
||||||
|
std::string opLayout;
|
||||||
|
std::map<std::string, std::string> opLayouts;
|
||||||
|
|
||||||
|
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts));
|
||||||
|
|
||||||
EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.SpecifyInputsAndOutputs(inputs, outputs));
|
EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, m_innerModelTest.SpecifyInputsAndOutputs(inputs, outputs));
|
||||||
}
|
}
|
||||||
@ -758,7 +852,7 @@ HWTEST_F(InnerModelTest, inner_model_get_supported_operation_001, TestSize.Level
|
|||||||
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.AddOperation(m_opType, m_params, m_inputs, m_outputs));
|
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.AddOperation(m_opType, m_params, m_inputs, m_outputs));
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.SpecifyInputsAndOutputs(m_inputs, m_outputs));
|
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.SpecifyInputsAndOutputs(m_inputs, m_outputs));
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.Build());
|
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.Build());
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.GetSupportedOperations(deviceID, &isSupported, opCount));
|
EXPECT_EQ(OH_NN_FAILED, m_innerModelTest.GetSupportedOperations(deviceID, &isSupported, opCount));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -775,9 +869,15 @@ HWTEST_F(InnerModelTest, inner_model_get_supported_operation_002, TestSize.Level
|
|||||||
mindspore::lite::LiteGraph* liteGraph = new (std::nothrow) mindspore::lite::LiteGraph();
|
mindspore::lite::LiteGraph* liteGraph = new (std::nothrow) mindspore::lite::LiteGraph();
|
||||||
EXPECT_NE(nullptr, liteGraph);
|
EXPECT_NE(nullptr, liteGraph);
|
||||||
SetLiteGraph(liteGraph);
|
SetLiteGraph(liteGraph);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph));
|
|
||||||
|
|
||||||
EXPECT_EQ(OH_NN_UNAVAILABLE_DEVICE, m_innerModelTest.GetSupportedOperations(deviceID, &isSupported, opCount));
|
Buffer buffer;
|
||||||
|
std::string modelName;
|
||||||
|
std::string isProfiling;
|
||||||
|
std::string opLayout;
|
||||||
|
std::map<std::string, std::string> opLayouts;
|
||||||
|
|
||||||
|
EXPECT_EQ(OH_NN_SUCCESS, m_innerModelTest.BuildFromLiteGraph(liteGraph, buffer, modelName, isProfiling, opLayouts));
|
||||||
|
EXPECT_EQ(OH_NN_FAILED, m_innerModelTest.GetSupportedOperations(deviceID, &isSupported, opCount));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,14 +19,15 @@
|
|||||||
|
|
||||||
#include "common/utils.h"
|
#include "common/utils.h"
|
||||||
#include "compilation.h"
|
#include "compilation.h"
|
||||||
#include "device_manager.h"
|
|
||||||
#include "hdi_device_v2_0.h"
|
#include "hdi_device_v2_0.h"
|
||||||
#include "test/unittest/common/v2_0/mock_idevice.h"
|
#include "test/unittest/common/v2_0/mock_idevice.h"
|
||||||
|
|
||||||
namespace OHOS {
|
namespace OHOS {
|
||||||
namespace NeuralNetworkRuntime {
|
namespace NeuralNetworkRuntime {
|
||||||
OH_NN_ReturnCode HDIDeviceV2_0::PrepareModel(std::shared_ptr<const mindspore::lite::LiteGraph> model,
|
OH_NN_ReturnCode HDIDeviceV2_0::PrepareModel(std::shared_ptr<const mindspore::lite::LiteGraph> model,
|
||||||
const ModelConfig& config, std::shared_ptr<PreparedModel>& preparedModel)
|
const Buffer& quantBuffer,
|
||||||
|
const ModelConfig& config,
|
||||||
|
std::shared_ptr<PreparedModel>& preparedModel)
|
||||||
{
|
{
|
||||||
if (model == nullptr) {
|
if (model == nullptr) {
|
||||||
return OH_NN_INVALID_PARAMETER;
|
return OH_NN_INVALID_PARAMETER;
|
||||||
@ -47,29 +48,6 @@ OH_NN_ReturnCode HDIDeviceV2_0::PrepareModel(std::shared_ptr<const mindspore::li
|
|||||||
return OH_NN_SUCCESS;
|
return OH_NN_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Device> DeviceManager::GetDevice(size_t deviceId) const
|
|
||||||
{
|
|
||||||
sptr<OHOS::HDI::Nnrt::V2_0::INnrtDevice> idevice
|
|
||||||
= sptr<OHOS::HDI::Nnrt::V2_0::MockIDevice>(new (std::nothrow) OHOS::HDI::Nnrt::V2_0::MockIDevice());
|
|
||||||
if (idevice == nullptr) {
|
|
||||||
LOGE("DeviceManager mock GetDevice failed, error happened when new sptr");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<Device> device = CreateSharedPtr<HDIDeviceV2_0>(idevice);
|
|
||||||
if (device == nullptr) {
|
|
||||||
LOGE("DeviceManager mock GetDevice failed, the device is nullptr");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (deviceId == 0) {
|
|
||||||
LOGE("DeviceManager mock GetDevice failed, the passed parameter deviceId is 0");
|
|
||||||
return nullptr;
|
|
||||||
} else {
|
|
||||||
return device;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
OH_NN_ReturnCode HDIDeviceV2_0::GetDeviceType(OH_NN_DeviceType& deviceType)
|
OH_NN_ReturnCode HDIDeviceV2_0::GetDeviceType(OH_NN_DeviceType& deviceType)
|
||||||
{
|
{
|
||||||
if (deviceType == OH_NN_OTHERS) {
|
if (deviceType == OH_NN_OTHERS) {
|
||||||
@ -79,30 +57,6 @@ OH_NN_ReturnCode HDIDeviceV2_0::GetDeviceType(OH_NN_DeviceType& deviceType)
|
|||||||
return OH_NN_SUCCESS;
|
return OH_NN_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& DeviceManager::GetDeviceName(size_t deviceId)
|
|
||||||
{
|
|
||||||
static std::string deviceName = "";
|
|
||||||
if (deviceId == 0) {
|
|
||||||
return deviceName;
|
|
||||||
}
|
|
||||||
|
|
||||||
deviceName = "deviceId";
|
|
||||||
return deviceName;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::vector<size_t>& DeviceManager::GetAllDeviceId()
|
|
||||||
{
|
|
||||||
static std::vector<size_t> deviceIds;
|
|
||||||
if (OHOS::HDI::Nnrt::V2_0::MockIPreparedModel::m_ExpectRetCode == OH_NN_FAILED) {
|
|
||||||
// In order not to affect other use cases, set to the OH_NN_OPERATION_FORBIDDEN
|
|
||||||
OHOS::HDI::Nnrt::V2_0::MockIPreparedModel::m_ExpectRetCode = OH_NN_OPERATION_FORBIDDEN;
|
|
||||||
return deviceIds;
|
|
||||||
}
|
|
||||||
std::size_t device = 1;
|
|
||||||
deviceIds.emplace_back(device);
|
|
||||||
return deviceIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
OH_NN_ReturnCode HDIDeviceV2_0::IsModelCacheSupported(bool& isSupported)
|
OH_NN_ReturnCode HDIDeviceV2_0::IsModelCacheSupported(bool& isSupported)
|
||||||
{
|
{
|
||||||
isSupported = true;
|
isSupported = true;
|
||||||
@ -267,22 +221,29 @@ void NeuralNetworkRuntimeTest::SetInnerBuild(InnerModel& innerModel)
|
|||||||
|
|
||||||
void NeuralNetworkRuntimeTest::SetInputAndOutput(Executor& executor)
|
void NeuralNetworkRuntimeTest::SetInputAndOutput(Executor& executor)
|
||||||
{
|
{
|
||||||
float input1[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
|
size_t input1Index = 0;
|
||||||
float input2[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
|
|
||||||
|
|
||||||
uint32_t input1Index = 0;
|
|
||||||
uint32_t input2Index = 1;
|
|
||||||
|
|
||||||
int32_t inputDims[2] = {3, 4};
|
int32_t inputDims[2] = {3, 4};
|
||||||
size_t length = 12 * sizeof(float);
|
size_t lengthSize = 12 * sizeof(float);
|
||||||
m_tensor = {OH_NN_FLOAT32, 2, inputDims, nullptr, OH_NN_TENSOR};
|
size_t * length = &lengthSize;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, executor.SetInput(input1Index, m_tensor, input1, length));
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, executor.SetInput(input2Index, m_tensor, input2, length));
|
|
||||||
|
|
||||||
float output[12];
|
size_t minInputDims = 1;
|
||||||
|
size_t maxInputDims = 12;
|
||||||
|
|
||||||
|
size_t * minInputDimsAdress = &minInputDims;
|
||||||
|
size_t ** minInputDimsAdressA = &minInputDimsAdress;
|
||||||
|
|
||||||
|
size_t * maxInputDimsAdress = &maxInputDims;
|
||||||
|
size_t ** maxInputDimsAdressA = &maxInputDimsAdress;
|
||||||
|
|
||||||
|
m_tensor = {OH_NN_FLOAT32, 2, inputDims, nullptr, OH_NN_TENSOR};
|
||||||
|
EXPECT_EQ(OH_NN_SUCCESS, executor.GetInputDimRange(input1Index, minInputDimsAdressA, maxInputDimsAdressA, length));
|
||||||
uint32_t outputIndex = 0;
|
uint32_t outputIndex = 0;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, executor.SetOutput(outputIndex, output, length));
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, executor.Run());
|
int32_t shape = 3;
|
||||||
|
int32_t* shapeA = &shape;
|
||||||
|
int32_t** shapeAA = &shapeA;
|
||||||
|
uint32_t* shapeNum = &outputIndex;
|
||||||
|
EXPECT_EQ(OH_NN_SUCCESS, executor.GetOutputShape(outputIndex, shapeAA, shapeNum));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -810,7 +771,7 @@ HWTEST_F(NeuralNetworkRuntimeTest, model_get_available_operation_005, testing::e
|
|||||||
|
|
||||||
size_t deviceID = 10;
|
size_t deviceID = 10;
|
||||||
OH_NN_ReturnCode ret = OH_NNModel_GetAvailableOperations(model, deviceID, &pIsAvailable, &opCount);
|
OH_NN_ReturnCode ret = OH_NNModel_GetAvailableOperations(model, deviceID, &pIsAvailable, &opCount);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, ret);
|
EXPECT_EQ(OH_NN_FAILED, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -837,7 +798,7 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_construct_002, testing::ext::Test
|
|||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNCompilation* ret = OH_NNCompilation_Construct(model);
|
OH_NNCompilation* ret = OH_NNCompilation_Construct(model);
|
||||||
EXPECT_EQ(nullptr, ret);
|
EXPECT_NE(nullptr, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -876,8 +837,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_device_002, testing::ext::Tes
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation compilation(&innerModel);
|
|
||||||
OH_NNCompilation* nnCompilation = reinterpret_cast<OH_NNCompilation*>(&compilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
size_t deviceId = 1;
|
size_t deviceId = 1;
|
||||||
OH_NN_ReturnCode ret = OH_NNCompilation_SetDevice(nnCompilation, deviceId);
|
OH_NN_ReturnCode ret = OH_NNCompilation_SetDevice(nnCompilation, deviceId);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, ret);
|
EXPECT_EQ(OH_NN_SUCCESS, ret);
|
||||||
@ -892,12 +854,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_cache_001, testing::ext::Test
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation compilation(&innerModel);
|
|
||||||
OH_NNCompilation* nnCompilation = nullptr;
|
OH_NNCompilation* nnCompilation = nullptr;
|
||||||
const char* cacheDir = "../";
|
const char* cacheDir = "../";
|
||||||
uint32_t version = 1;
|
uint32_t version = 1;
|
||||||
std::size_t deviceId = 1;
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId));
|
|
||||||
OH_NN_ReturnCode ret = OH_NNCompilation_SetCache(nnCompilation, cacheDir, version);
|
OH_NN_ReturnCode ret = OH_NNCompilation_SetCache(nnCompilation, cacheDir, version);
|
||||||
EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
|
EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
|
||||||
}
|
}
|
||||||
@ -911,12 +870,11 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_cache_002, testing::ext::Test
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation compilation(&innerModel);
|
|
||||||
OH_NNCompilation* nnCompilation = reinterpret_cast<OH_NNCompilation*>(&compilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
const char* cacheDir = nullptr;
|
const char* cacheDir = nullptr;
|
||||||
uint32_t version = 1;
|
uint32_t version = 1;
|
||||||
std::size_t deviceId = 1;
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId));
|
|
||||||
OH_NN_ReturnCode ret = OH_NNCompilation_SetCache(nnCompilation, cacheDir, version);
|
OH_NN_ReturnCode ret = OH_NNCompilation_SetCache(nnCompilation, cacheDir, version);
|
||||||
EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
|
EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
|
||||||
}
|
}
|
||||||
@ -930,12 +888,11 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_cache_003, testing::ext::Test
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation compilation(&innerModel);
|
|
||||||
OH_NNCompilation* nnCompilation = reinterpret_cast<OH_NNCompilation*>(&compilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
const char* cacheDir = "../";
|
const char* cacheDir = "../";
|
||||||
uint32_t version = 1;
|
uint32_t version = 1;
|
||||||
std::size_t deviceId = 1;
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId));
|
|
||||||
OH_NN_ReturnCode ret = OH_NNCompilation_SetCache(nnCompilation, cacheDir, version);
|
OH_NN_ReturnCode ret = OH_NNCompilation_SetCache(nnCompilation, cacheDir, version);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, ret);
|
EXPECT_EQ(OH_NN_SUCCESS, ret);
|
||||||
}
|
}
|
||||||
@ -949,12 +906,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_performance_mode_001, testing
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation compilation(&innerModel);
|
|
||||||
OH_NNCompilation* nnCompilation = nullptr;
|
OH_NNCompilation* nnCompilation = nullptr;
|
||||||
OH_NN_PerformanceMode performanceMode = OH_NN_PERFORMANCE_NONE;
|
OH_NN_PerformanceMode performanceMode = OH_NN_PERFORMANCE_NONE;
|
||||||
|
|
||||||
std::size_t deviceId = 1;
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId));
|
|
||||||
OH_NN_ReturnCode ret = OH_NNCompilation_SetPerformanceMode(nnCompilation, performanceMode);
|
OH_NN_ReturnCode ret = OH_NNCompilation_SetPerformanceMode(nnCompilation, performanceMode);
|
||||||
EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
|
EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
|
||||||
}
|
}
|
||||||
@ -968,12 +922,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_performance_mode_002, testing
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation compilation(&innerModel);
|
|
||||||
OH_NNCompilation* nnCompilation = reinterpret_cast<OH_NNCompilation*>(&compilation);
|
|
||||||
OH_NN_PerformanceMode performanceMode = OH_NN_PERFORMANCE_NONE;
|
|
||||||
|
|
||||||
std::size_t deviceId = 1;
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId));
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NN_PerformanceMode performanceMode = OH_NN_PERFORMANCE_NONE;
|
||||||
|
|
||||||
OH_NN_ReturnCode ret = OH_NNCompilation_SetPerformanceMode(nnCompilation, performanceMode);
|
OH_NN_ReturnCode ret = OH_NNCompilation_SetPerformanceMode(nnCompilation, performanceMode);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, ret);
|
EXPECT_EQ(OH_NN_SUCCESS, ret);
|
||||||
@ -988,13 +940,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_priority_001, testing::ext::T
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation compilation(&innerModel);
|
|
||||||
OH_NNCompilation* nnCompilation = nullptr;
|
OH_NNCompilation* nnCompilation = nullptr;
|
||||||
OH_NN_Priority priority = OH_NN_PRIORITY_LOW;
|
OH_NN_Priority priority = OH_NN_PRIORITY_LOW;
|
||||||
|
|
||||||
std::size_t deviceId = 1;
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId));
|
|
||||||
|
|
||||||
OH_NN_ReturnCode ret = OH_NNCompilation_SetPriority(nnCompilation, priority);
|
OH_NN_ReturnCode ret = OH_NNCompilation_SetPriority(nnCompilation, priority);
|
||||||
EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
|
EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
|
||||||
}
|
}
|
||||||
@ -1008,12 +956,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_priority_002, testing::ext::T
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation compilation(&innerModel);
|
|
||||||
OH_NNCompilation* nnCompilation = reinterpret_cast<OH_NNCompilation*>(&compilation);
|
|
||||||
OH_NN_Priority priority = OH_NN_PRIORITY_LOW;
|
|
||||||
|
|
||||||
std::size_t deviceId = 1;
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId));
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NN_Priority priority = OH_NN_PRIORITY_LOW;
|
||||||
|
|
||||||
OH_NN_ReturnCode ret = OH_NNCompilation_SetPriority(nnCompilation, priority);
|
OH_NN_ReturnCode ret = OH_NNCompilation_SetPriority(nnCompilation, priority);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, ret);
|
EXPECT_EQ(OH_NN_SUCCESS, ret);
|
||||||
@ -1028,13 +974,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_enable_float16_001, testing::
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation compilation(&innerModel);
|
|
||||||
OH_NNCompilation* nnCompilation = nullptr;
|
OH_NNCompilation* nnCompilation = nullptr;
|
||||||
bool enableFloat16 = true;
|
bool enableFloat16 = true;
|
||||||
|
|
||||||
std::size_t deviceId = 1;
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId));
|
|
||||||
|
|
||||||
OH_NN_ReturnCode ret = OH_NNCompilation_EnableFloat16(nnCompilation, enableFloat16);
|
OH_NN_ReturnCode ret = OH_NNCompilation_EnableFloat16(nnCompilation, enableFloat16);
|
||||||
EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
|
EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
|
||||||
}
|
}
|
||||||
@ -1048,12 +990,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_set_enable_float16_002, testing::
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation compilation(&innerModel);
|
|
||||||
OH_NNCompilation* nnCompilation = reinterpret_cast<OH_NNCompilation*>(&compilation);
|
|
||||||
bool enableFloat16 = true;
|
|
||||||
|
|
||||||
std::size_t deviceId = 1;
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId));
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
bool enableFloat16 = true;
|
||||||
|
|
||||||
OH_NN_ReturnCode ret = OH_NNCompilation_EnableFloat16(nnCompilation, enableFloat16);
|
OH_NN_ReturnCode ret = OH_NNCompilation_EnableFloat16(nnCompilation, enableFloat16);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, ret);
|
EXPECT_EQ(OH_NN_SUCCESS, ret);
|
||||||
@ -1068,15 +1008,8 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_build_001, testing::ext::TestSize
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation compilation(&innerModel);
|
|
||||||
OH_NNCompilation* nnCompilation = nullptr;
|
OH_NNCompilation* nnCompilation = nullptr;
|
||||||
|
|
||||||
std::size_t deviceId = 1;
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId));
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetPerformance(OH_NN_PERFORMANCE_EXTREME));
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetPriority(OH_NN_PRIORITY_HIGH));
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetEnableFp16(true));
|
|
||||||
|
|
||||||
OH_NN_ReturnCode ret = OH_NNCompilation_Build(nnCompilation);
|
OH_NN_ReturnCode ret = OH_NNCompilation_Build(nnCompilation);
|
||||||
EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
|
EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
|
||||||
}
|
}
|
||||||
@ -1090,17 +1023,12 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_build_002, testing::ext::TestSize
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation compilation(&innerModel);
|
|
||||||
OH_NNCompilation* nnCompilation = reinterpret_cast<OH_NNCompilation*>(&compilation);
|
|
||||||
|
|
||||||
std::size_t deviceId = 1;
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId));
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetPerformance(OH_NN_PERFORMANCE_EXTREME));
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetPriority(OH_NN_PRIORITY_HIGH));
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetEnableFp16(true));
|
|
||||||
|
|
||||||
OH_NN_ReturnCode ret = OH_NNCompilation_Build(nnCompilation);
|
OH_NN_ReturnCode ret = OH_NNCompilation_Build(nnCompilation);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, ret);
|
EXPECT_EQ(OH_NN_FAILED, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1137,9 +1065,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, compilation_destroy_003, testing::ext::TestSi
|
|||||||
{
|
{
|
||||||
InnerModel* innerModel = new InnerModel();
|
InnerModel* innerModel = new InnerModel();
|
||||||
EXPECT_NE(nullptr, innerModel);
|
EXPECT_NE(nullptr, innerModel);
|
||||||
Compilation* compilation = new(std::nothrow) Compilation(innerModel);
|
|
||||||
EXPECT_NE(nullptr, compilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNCompilation* nnCompilation = reinterpret_cast<OH_NNCompilation*>(compilation);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
OH_NNCompilation_Destroy(&nnCompilation);
|
OH_NNCompilation_Destroy(&nnCompilation);
|
||||||
EXPECT_EQ(nullptr, nnCompilation);
|
EXPECT_EQ(nullptr, nnCompilation);
|
||||||
}
|
}
|
||||||
@ -1153,14 +1081,6 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_construct_001, testing::ext::TestSize
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation compilation(&innerModel);
|
|
||||||
|
|
||||||
std::size_t deviceId = 1;
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId));
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetEnableFp16(true));
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetPerformance(OH_NN_PERFORMANCE_EXTREME));
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetPriority(OH_NN_PRIORITY_HIGH));
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.Build());
|
|
||||||
|
|
||||||
OH_NNCompilation* nnCompilation = nullptr;
|
OH_NNCompilation* nnCompilation = nullptr;
|
||||||
OH_NNExecutor* executor = OH_NNExecutor_Construct(nnCompilation);
|
OH_NNExecutor* executor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
@ -1176,8 +1096,9 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_construct_002, testing::ext::TestSize
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation compilation(&innerModel);
|
|
||||||
OH_NNCompilation* nnCompilation = reinterpret_cast<OH_NNCompilation*>(&compilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
OH_NNExecutor * executor = OH_NNExecutor_Construct(nnCompilation);
|
OH_NNExecutor * executor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
EXPECT_EQ(nullptr, executor);
|
EXPECT_EQ(nullptr, executor);
|
||||||
}
|
}
|
||||||
@ -1191,18 +1112,11 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_construct_003, testing::ext::TestSize
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation compilation(&innerModel);
|
|
||||||
|
|
||||||
std::size_t deviceId = 1;
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetDevice(deviceId));
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetPerformance(OH_NN_PERFORMANCE_EXTREME));
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetPriority(OH_NN_PRIORITY_HIGH));
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.SetEnableFp16(true));
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, compilation.Build());
|
|
||||||
|
|
||||||
OH_NNCompilation* nnCompilation = reinterpret_cast<OH_NNCompilation*>(&compilation);
|
|
||||||
OH_NNExecutor * executor = OH_NNExecutor_Construct(nnCompilation);
|
OH_NNExecutor * executor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
EXPECT_NE(nullptr, executor);
|
EXPECT_EQ(nullptr, executor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1230,9 +1144,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setinput_002, testing::ext::TestSize.
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t inputIndex = 0;
|
uint32_t inputIndex = 0;
|
||||||
float input[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
|
float input[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
|
||||||
@ -1250,9 +1165,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setinput_003, testing::ext::TestSize.
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
SetTensor();
|
SetTensor();
|
||||||
|
|
||||||
@ -1271,9 +1187,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setinput_004, testing::ext::TestSize.
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t inputIndex = 0;
|
uint32_t inputIndex = 0;
|
||||||
SetTensor();
|
SetTensor();
|
||||||
@ -1293,9 +1210,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setinput_005, testing::ext::TestSize.
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t inputIndex = 0;
|
uint32_t inputIndex = 0;
|
||||||
int32_t dims[2] = {3, 4};
|
int32_t dims[2] = {3, 4};
|
||||||
@ -1305,7 +1223,7 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setinput_005, testing::ext::TestSize.
|
|||||||
const void *buffer = input;
|
const void *buffer = input;
|
||||||
size_t length = 12 * sizeof(float);
|
size_t length = 12 * sizeof(float);
|
||||||
OH_NN_ReturnCode ret = OH_NNExecutor_SetInput(nnExecutor, inputIndex, &m_tensor, buffer, length);
|
OH_NN_ReturnCode ret = OH_NNExecutor_SetInput(nnExecutor, inputIndex, &m_tensor, buffer, length);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, ret);
|
EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1331,9 +1249,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setoutput_002, testing::ext::TestSize
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t outputIndex = 0;
|
uint32_t outputIndex = 0;
|
||||||
void *buffer = nullptr;
|
void *buffer = nullptr;
|
||||||
@ -1350,9 +1269,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setoutput_003, testing::ext::TestSize
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t outputIndex = 0;
|
uint32_t outputIndex = 0;
|
||||||
float input[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
|
float input[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
|
||||||
@ -1370,14 +1290,15 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_setoutput_004, testing::ext::TestSize
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t outputIndex = 0;
|
uint32_t outputIndex = 0;
|
||||||
float output[12];
|
float output[12];
|
||||||
size_t length = 12 * sizeof(float);
|
size_t length = 12 * sizeof(float);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, OH_NNExecutor_SetOutput(nnExecutor, outputIndex, output, length));
|
EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNExecutor_SetOutput(nnExecutor, outputIndex, output, length));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1389,11 +1310,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_getoutputshape_001, testing::ext::Tes
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
|
||||||
OH_NNExecutor* nnExecutor = nullptr;
|
|
||||||
|
|
||||||
SetInputAndOutput(executor);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
int32_t* ptr = nullptr;
|
int32_t* ptr = nullptr;
|
||||||
int32_t** shape = &ptr;
|
int32_t** shape = &ptr;
|
||||||
@ -1412,11 +1332,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_getoutputshape_002, testing::ext::Tes
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
|
||||||
|
|
||||||
SetInputAndOutput(executor);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t outputIndex = 0;
|
uint32_t outputIndex = 0;
|
||||||
int32_t** shape = nullptr;
|
int32_t** shape = nullptr;
|
||||||
@ -1434,11 +1353,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_getoutputshape_003, testing::ext::Tes
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
|
||||||
|
|
||||||
SetInputAndOutput(executor);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
int32_t expectDim[2] = {3, 3};
|
int32_t expectDim[2] = {3, 3};
|
||||||
int32_t* ptr = expectDim;
|
int32_t* ptr = expectDim;
|
||||||
@ -1458,11 +1376,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_getoutputshape_004, testing::ext::Tes
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
|
||||||
|
|
||||||
SetInputAndOutput(executor);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
int32_t* ptr = nullptr;
|
int32_t* ptr = nullptr;
|
||||||
int32_t** shape = &ptr;
|
int32_t** shape = &ptr;
|
||||||
@ -1479,17 +1396,16 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_getoutputshape_005, testing::ext::Tes
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
|
||||||
|
|
||||||
SetInputAndOutput(executor);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
int32_t* ptr = nullptr;
|
int32_t* ptr = nullptr;
|
||||||
int32_t** shape = &ptr;
|
int32_t** shape = &ptr;
|
||||||
uint32_t length = 2;
|
uint32_t length = 2;
|
||||||
uint32_t outputIndex = 0;
|
uint32_t outputIndex = 0;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, OH_NNExecutor_GetOutputShape(nnExecutor, outputIndex, shape, &length));
|
EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNExecutor_GetOutputShape(nnExecutor, outputIndex, shape, &length));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1512,25 +1428,15 @@ HWTEST_F(NeuralNetworkRuntimeTest, excutor_run_002, testing::ext::TestSize.Level
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
|
||||||
|
|
||||||
float input1[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
float input2[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
uint32_t input1Index = 0;
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
uint32_t input2Index = 1;
|
|
||||||
|
|
||||||
int32_t inputDims[2] = {3, 4};
|
int32_t inputDims[2] = {3, 4};
|
||||||
size_t length = 12 * sizeof(float);
|
|
||||||
m_tensor = {OH_NN_FLOAT32, 2, inputDims, nullptr, OH_NN_TENSOR};
|
m_tensor = {OH_NN_FLOAT32, 2, inputDims, nullptr, OH_NN_TENSOR};
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, executor.SetInput(input1Index, m_tensor, input1, length));
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, executor.SetInput(input2Index, m_tensor, input2, length));
|
|
||||||
|
|
||||||
float output[12];
|
EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNExecutor_Run(nnExecutor));
|
||||||
uint32_t outputIndex = 0;
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, executor.SetOutput(outputIndex, output, length));
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, OH_NNExecutor_Run(nnExecutor));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1557,9 +1463,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_allocate_input_memory_002, testing::
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t outputIndex = 0;
|
uint32_t outputIndex = 0;
|
||||||
size_t length = 0;
|
size_t length = 0;
|
||||||
@ -1577,9 +1484,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_allocate_input_memory_003, testing::
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t outputIndex = 6;
|
uint32_t outputIndex = 6;
|
||||||
size_t length = 9 * sizeof(float);
|
size_t length = 9 * sizeof(float);
|
||||||
@ -1597,15 +1505,16 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_allocate_input_memory_004, testing::
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t outputIndex = 0;
|
uint32_t outputIndex = 0;
|
||||||
size_t length = 9 * sizeof(float);
|
size_t length = 9 * sizeof(float);
|
||||||
|
|
||||||
OH_NN_Memory* ret = OH_NNExecutor_AllocateInputMemory(nnExecutor, outputIndex, length);
|
OH_NN_Memory* ret = OH_NNExecutor_AllocateInputMemory(nnExecutor, outputIndex, length);
|
||||||
EXPECT_NE(nullptr, ret);
|
EXPECT_EQ(nullptr, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1632,9 +1541,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_allocate_output_memory_002, testing:
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t outputIndex = 0;
|
uint32_t outputIndex = 0;
|
||||||
size_t length = 0;
|
size_t length = 0;
|
||||||
@ -1652,9 +1562,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_allocate_output_memory_003, testing:
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t outputIndex = 6;
|
uint32_t outputIndex = 6;
|
||||||
size_t length = 9 * sizeof(float);
|
size_t length = 9 * sizeof(float);
|
||||||
@ -1672,15 +1583,16 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_allocate_output_memory_004, testing:
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t outputIndex = 0;
|
uint32_t outputIndex = 0;
|
||||||
size_t length = 9 * sizeof(float);
|
size_t length = 9 * sizeof(float);
|
||||||
|
|
||||||
OH_NN_Memory* ret = OH_NNExecutor_AllocateOutputMemory(nnExecutor, outputIndex, length);
|
OH_NN_Memory* ret = OH_NNExecutor_AllocateOutputMemory(nnExecutor, outputIndex, length);
|
||||||
EXPECT_NE(nullptr, ret);
|
EXPECT_EQ(nullptr, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1693,8 +1605,6 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_input_memory_001, testing::e
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
BuildModel(innerModel);
|
BuildModel(innerModel);
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
|
||||||
OH_NNExecutor* nnExecutor = nullptr;
|
OH_NNExecutor* nnExecutor = nullptr;
|
||||||
|
|
||||||
uint32_t inputIndex = 0;
|
uint32_t inputIndex = 0;
|
||||||
@ -1702,8 +1612,6 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_input_memory_001, testing::e
|
|||||||
void* const data = dataArry;
|
void* const data = dataArry;
|
||||||
OH_NN_Memory memory = {data, 9 * sizeof(float)};
|
OH_NN_Memory memory = {data, 9 * sizeof(float)};
|
||||||
OH_NN_Memory* pMemory = &memory;
|
OH_NN_Memory* pMemory = &memory;
|
||||||
size_t length = 9 * sizeof(float);
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, executor.CreateInputMemory(inputIndex, length, &pMemory));
|
|
||||||
OH_NNExecutor_DestroyInputMemory(nnExecutor, inputIndex, &pMemory);
|
OH_NNExecutor_DestroyInputMemory(nnExecutor, inputIndex, &pMemory);
|
||||||
EXPECT_EQ(nullptr, nnExecutor);
|
EXPECT_EQ(nullptr, nnExecutor);
|
||||||
}
|
}
|
||||||
@ -1717,9 +1625,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_input_memory_002, testing::e
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
BuildModel(innerModel);
|
BuildModel(innerModel);
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t inputIndex = 0;
|
uint32_t inputIndex = 0;
|
||||||
OH_NN_Memory** memory = nullptr;
|
OH_NN_Memory** memory = nullptr;
|
||||||
@ -1736,9 +1645,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_input_memory_003, testing::e
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
BuildModel(innerModel);
|
BuildModel(innerModel);
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t inputIndex = 0;
|
uint32_t inputIndex = 0;
|
||||||
OH_NN_Memory* memory = nullptr;
|
OH_NN_Memory* memory = nullptr;
|
||||||
@ -1756,9 +1666,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_input_memory_004, testing::e
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
BuildModel(innerModel);
|
BuildModel(innerModel);
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t inputIndex = 6;
|
uint32_t inputIndex = 6;
|
||||||
float dataArry[9] {0, 1, 2, 3, 4, 5, 6, 7, 8};
|
float dataArry[9] {0, 1, 2, 3, 4, 5, 6, 7, 8};
|
||||||
@ -1778,19 +1689,18 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_input_memory_005, testing::e
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
BuildModel(innerModel);
|
BuildModel(innerModel);
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t inputIndex = 0;
|
uint32_t inputIndex = 0;
|
||||||
float dataArry[9] {0, 1, 2, 3, 4, 5, 6, 7, 8};
|
float dataArry[9] {0, 1, 2, 3, 4, 5, 6, 7, 8};
|
||||||
void* const data = dataArry;
|
void* const data = dataArry;
|
||||||
OH_NN_Memory memory = {data, 9 * sizeof(float)};
|
OH_NN_Memory memory = {data, 9 * sizeof(float)};
|
||||||
OH_NN_Memory* pMemory = &memory;
|
OH_NN_Memory* pMemory = &memory;
|
||||||
size_t length = 9 * sizeof(float);
|
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, executor.CreateInputMemory(inputIndex, length, &pMemory));
|
|
||||||
OH_NNExecutor_DestroyInputMemory(nnExecutor, inputIndex, &pMemory);
|
OH_NNExecutor_DestroyInputMemory(nnExecutor, inputIndex, &pMemory);
|
||||||
EXPECT_EQ(nullptr, pMemory);
|
EXPECT_NE(nullptr, pMemory);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1819,9 +1729,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_output_memory_002, testing::
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t outputIndex = 0;
|
uint32_t outputIndex = 0;
|
||||||
OH_NN_Memory** memory = nullptr;
|
OH_NN_Memory** memory = nullptr;
|
||||||
@ -1838,9 +1749,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_output_memory_003, testing::
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t outputIndex = 0;
|
uint32_t outputIndex = 0;
|
||||||
OH_NN_Memory* memory = nullptr;
|
OH_NN_Memory* memory = nullptr;
|
||||||
@ -1858,9 +1770,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_output_memory_004, testing::
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t outputIndex = 6;
|
uint32_t outputIndex = 6;
|
||||||
float dataArry[9] {0, 1, 2, 3, 4, 5, 6, 7, 8};
|
float dataArry[9] {0, 1, 2, 3, 4, 5, 6, 7, 8};
|
||||||
@ -1880,19 +1793,18 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_output_memory_005, testing::
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
float dataArry[9] {0, 1, 2, 3, 4, 5, 6, 7, 8};
|
float dataArry[9] {0, 1, 2, 3, 4, 5, 6, 7, 8};
|
||||||
void* const data = dataArry;
|
void* const data = dataArry;
|
||||||
OH_NN_Memory memory = {data, 9 * sizeof(float)};
|
OH_NN_Memory memory = {data, 9 * sizeof(float)};
|
||||||
OH_NN_Memory* pMemory = &memory;
|
OH_NN_Memory* pMemory = &memory;
|
||||||
size_t length = 9 * sizeof(float);
|
|
||||||
uint32_t outputIndex = 0;
|
uint32_t outputIndex = 0;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, executor.CreateOutputMemory(outputIndex, length, &pMemory));
|
|
||||||
OH_NNExecutor_DestroyOutputMemory(nnExecutor, outputIndex, &pMemory);
|
OH_NNExecutor_DestroyOutputMemory(nnExecutor, outputIndex, &pMemory);
|
||||||
EXPECT_EQ(nullptr, pMemory);
|
EXPECT_NE(nullptr, pMemory);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1924,9 +1836,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_set_input_with_memory_002, testing::
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
OH_NN_Tensor* operand = nullptr;
|
OH_NN_Tensor* operand = nullptr;
|
||||||
|
|
||||||
@ -1948,9 +1861,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_set_input_with_memory_003, testing::
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
SetTensor();
|
SetTensor();
|
||||||
|
|
||||||
@ -1969,9 +1883,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_set_input_with_memory_004, testing::
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t inputIndex = 0;
|
uint32_t inputIndex = 0;
|
||||||
int32_t dims[2] = {3, 4};
|
int32_t dims[2] = {3, 4};
|
||||||
@ -1982,7 +1897,7 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_set_input_with_memory_004, testing::
|
|||||||
OH_NN_Memory memory = {data, 12 * sizeof(float)};
|
OH_NN_Memory memory = {data, 12 * sizeof(float)};
|
||||||
|
|
||||||
OH_NN_ReturnCode ret = OH_NNExecutor_SetInputWithMemory(nnExecutor, inputIndex, &m_tensor, &memory);
|
OH_NN_ReturnCode ret = OH_NNExecutor_SetInputWithMemory(nnExecutor, inputIndex, &m_tensor, &memory);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, ret);
|
EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2011,9 +1926,10 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_set_output_with_memory_002, testing:
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t outputIndex = 0;
|
uint32_t outputIndex = 0;
|
||||||
OH_NN_Memory* memory = nullptr;
|
OH_NN_Memory* memory = nullptr;
|
||||||
@ -2030,16 +1946,17 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_set_output_with_memory_003, testing:
|
|||||||
{
|
{
|
||||||
InnerModel innerModel;
|
InnerModel innerModel;
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
EXPECT_EQ(OH_NN_SUCCESS, BuildModel(innerModel));
|
||||||
Compilation innerCompilation(&innerModel);
|
|
||||||
Executor executor(&innerCompilation);
|
OH_NNModel* model = reinterpret_cast<OH_NNModel*>(&innerModel);
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(&executor);
|
OH_NNCompilation* nnCompilation = OH_NNCompilation_Construct(model);
|
||||||
|
OH_NNExecutor* nnExecutor = OH_NNExecutor_Construct(nnCompilation);
|
||||||
|
|
||||||
uint32_t outputIndex = 0;
|
uint32_t outputIndex = 0;
|
||||||
float dataArry[12] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
|
float dataArry[12] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
|
||||||
void* const data = dataArry;
|
void* const data = dataArry;
|
||||||
OH_NN_Memory memory = {data, 12 * sizeof(float)};
|
OH_NN_Memory memory = {data, 12 * sizeof(float)};
|
||||||
OH_NN_ReturnCode ret = OH_NNExecutor_SetOutputWithMemory(nnExecutor, outputIndex, &memory);
|
OH_NN_ReturnCode ret = OH_NNExecutor_SetOutputWithMemory(nnExecutor, outputIndex, &memory);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, ret);
|
EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2067,25 +1984,6 @@ HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_002, testing::ext::TestSize.
|
|||||||
EXPECT_EQ(nullptr, nnExecutor);
|
EXPECT_EQ(nullptr, nnExecutor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* @tc.name: executor_destroy_003
|
|
||||||
* @tc.desc: Verify the normal model of the OH_NNExecutor_Destroy function.
|
|
||||||
* @tc.type: FUNC
|
|
||||||
*/
|
|
||||||
HWTEST_F(NeuralNetworkRuntimeTest, executor_destroy_003, testing::ext::TestSize.Level0)
|
|
||||||
{
|
|
||||||
InnerModel* innerModel = new InnerModel();
|
|
||||||
EXPECT_NE(nullptr, innerModel);
|
|
||||||
Compilation* innerCompilation = new(std::nothrow) Compilation(innerModel);
|
|
||||||
EXPECT_NE(nullptr, innerCompilation);
|
|
||||||
Executor* executor = new(std::nothrow) Executor(innerCompilation);
|
|
||||||
EXPECT_NE(nullptr, executor);
|
|
||||||
|
|
||||||
OH_NNExecutor* nnExecutor = reinterpret_cast<OH_NNExecutor*>(executor);
|
|
||||||
OH_NNExecutor_Destroy(&nnExecutor);
|
|
||||||
EXPECT_EQ(nullptr, nnExecutor);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @tc.name: device_get_all_devices_id_001
|
* @tc.name: device_get_all_devices_id_001
|
||||||
* @tc.desc: Verify the allDevicesID is nullptr of the OH_NNDevice_GetAllDevicesID function.
|
* @tc.desc: Verify the allDevicesID is nullptr of the OH_NNDevice_GetAllDevicesID function.
|
||||||
@ -2213,7 +2111,7 @@ HWTEST_F(NeuralNetworkRuntimeTest, device_get_name_004, testing::ext::TestSize.L
|
|||||||
const char* name = nullptr;
|
const char* name = nullptr;
|
||||||
const char** pName = &name;
|
const char** pName = &name;
|
||||||
OH_NN_ReturnCode ret = OH_NNDevice_GetName(deviceID, pName);
|
OH_NN_ReturnCode ret = OH_NNDevice_GetName(deviceID, pName);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, ret);
|
EXPECT_EQ(OH_NN_FAILED, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2254,7 +2152,7 @@ HWTEST_F(NeuralNetworkRuntimeTest, device_get_type_003, testing::ext::TestSize.L
|
|||||||
OH_NN_DeviceType deviceType = OH_NN_OTHERS;
|
OH_NN_DeviceType deviceType = OH_NN_OTHERS;
|
||||||
OH_NN_DeviceType* pDeviceType = &deviceType;
|
OH_NN_DeviceType* pDeviceType = &deviceType;
|
||||||
OH_NN_ReturnCode ret = OH_NNDevice_GetType(deviceID, pDeviceType);
|
OH_NN_ReturnCode ret = OH_NNDevice_GetType(deviceID, pDeviceType);
|
||||||
EXPECT_EQ(OH_NN_UNAVAILABLE_DEVICE, ret);
|
EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2268,7 +2166,7 @@ HWTEST_F(NeuralNetworkRuntimeTest, device_get_type_004, testing::ext::TestSize.L
|
|||||||
OH_NN_DeviceType deviceType = OH_NN_CPU;
|
OH_NN_DeviceType deviceType = OH_NN_CPU;
|
||||||
OH_NN_DeviceType* pDeviceType = &deviceType;
|
OH_NN_DeviceType* pDeviceType = &deviceType;
|
||||||
OH_NN_ReturnCode ret = OH_NNDevice_GetType(deviceID, pDeviceType);
|
OH_NN_ReturnCode ret = OH_NNDevice_GetType(deviceID, pDeviceType);
|
||||||
EXPECT_EQ(OH_NN_SUCCESS, ret);
|
EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
|
||||||
}
|
}
|
||||||
} // namespace Unittest
|
} // namespace Unittest
|
||||||
} // namespace NeuralNetworkRuntime
|
} // namespace NeuralNetworkRuntime
|
||||||
|
@ -21,6 +21,7 @@ config("module_private_config") {
|
|||||||
include_dirs = [
|
include_dirs = [
|
||||||
"//third_party/googletest/googlemock/include",
|
"//third_party/googletest/googlemock/include",
|
||||||
"../../..",
|
"../../..",
|
||||||
|
"../../../frameworks/native",
|
||||||
"../../../frameworks/native/neural_network_runtime",
|
"../../../frameworks/native/neural_network_runtime",
|
||||||
"../../../frameworks/native/neural_network_core",
|
"../../../frameworks/native/neural_network_core",
|
||||||
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
|
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
|
||||||
|
Loading…
Reference in New Issue
Block a user