diff options
author | Xusong Wang <xusongw@google.com> | 2018-10-25 18:49:54 -0700 |
---|---|---|
committer | Xusong Wang <xusongw@google.com> | 2018-12-14 14:40:37 -0800 |
commit | 8e75d66ae0e398656175d3dcc8e6b9ab7c7077ce (patch) | |
tree | 8949255587822f03dc43e9c39b8d088aa823f367 /nn/runtime/test/TestPartitioning.cpp | |
parent | c7734f3a11dcfbdacf10585da2261b1f74ebfa43 (diff) | |
download | ml-8e75d66ae0e398656175d3dcc8e6b9ab7c7077ce.tar.gz |
Wrap the CpuExecutor as a device during compilation step.
Make Device a common interface for abstraction of CPU fallback as
well as the actual driver devices. Modify the compilation steps, mainly
the partitioner, to accommodate the change.
Make all possible compilation outcomes plan-based, even for the CPU
fallback, which is a SIMPLE body running on CPU only.
Add validation for invalid empty model and create validation test.
Add validation for empty device list passed to introspection and control
API and create tests.
Bug: 72506261
Test: NeuralNetworksTest_static
Change-Id: Ic63036716afb8a0156c77e0cf43456e490783deb
Merged-In: Ic63036716afb8a0156c77e0cf43456e490783deb
(cherry picked from commit 8e0bbbd6b982156823be0ce336f8af2090b47bed)
Diffstat (limited to 'nn/runtime/test/TestPartitioning.cpp')
-rw-r--r-- | nn/runtime/test/TestPartitioning.cpp | 62 |
1 files changed, 32 insertions, 30 deletions
diff --git a/nn/runtime/test/TestPartitioning.cpp b/nn/runtime/test/TestPartitioning.cpp index 37804d3f0..c7445ca21 100644 --- a/nn/runtime/test/TestPartitioning.cpp +++ b/nn/runtime/test/TestPartitioning.cpp @@ -445,21 +445,17 @@ protected: uint32_t mOperationMask; PartitioningDriver::OEM mOEM; }; - static std::vector<std::shared_ptr<Device>> - makeDevices(std::vector<DeviceSpecification> specifications) { + static std::vector<std::shared_ptr<Device>> makeDevices( + std::vector<DeviceSpecification> specifications) { std::vector<std::shared_ptr<Device>> devices; for (const auto& specification : specifications) { - devices.push_back(std::make_shared<Device>( - specification.mName, - new PartitioningDriver(specification.mName.c_str(), - specification.mCapabilities, - specification.mOperationMask, - specification.mOEM))); - if (!devices.back()->initialize()) { - EXPECT_NE("failed to initialize device", nullptr); - return {}; - } + auto device = DeviceManager::forTest_makeDriverDevice( + specification.mName, + new PartitioningDriver(specification.mName.c_str(), specification.mCapabilities, + specification.mOperationMask, specification.mOEM)); + devices.push_back(device); } + devices.push_back(DeviceManager::getCpuDevice()); return devices; } @@ -740,8 +736,8 @@ protected: /*-------------------------------------------------------------------------------------*/ - bool compare(std::shared_ptr<const ExecutionStep> step, - const WrapperModel* model, std::shared_ptr<Device> device) { + bool compare(std::shared_ptr<const ExecutionStep> step, const WrapperModel* model, + std::shared_ptr<Device> device) { return (step->getDevice() == device) && compare(step->getSubModel(), reinterpret_cast<const ModelBuilder*>(model->getHandle())); @@ -775,18 +771,20 @@ TEST_F(PartitioningTest, SimpleModel) { ASSERT_STREQ(planA.forTest_simpleGetDevice()->getName(), "good"); // Simple partition (two devices are each capable of everything, none better than CPU). - const auto devicesC = makeDevices( - { - {"bad", { .float32Performance = { .execTime = 1.1, .powerUsage = 1.1 }, - .quantized8Performance = { .execTime = 1.1, .powerUsage = 1.1 } }, ~0U}, - {"bad2", { .float32Performance = { .execTime = 1.0, .powerUsage = 1.0 }, - .quantized8Performance = { .execTime = 1.0, .powerUsage = 1.0 } }, ~0U} - }); + const auto devicesC = + makeDevices({{"bad", + {.float32Performance = {.execTime = 1.1, .powerUsage = 1.1}, + .quantized8Performance = {.execTime = 1.1, .powerUsage = 1.1}}, + ~0U}, + {"bad2", + {.float32Performance = {.execTime = 1.0, .powerUsage = 1.0}, + .quantized8Performance = {.execTime = 1.0, .powerUsage = 1.0}}, + ~0U}}); ExecutionPlan planC; ASSERT_EQ(model.partitionTheWork(devicesC, ExecutePreference::PREFER_LOW_POWER, &planC), ANEURALNETWORKS_NO_ERROR); ASSERT_EQ(planC.forTest_getKind(), ExecutionPlan::Kind::SIMPLE); - ASSERT_EQ(planC.forTest_simpleGetDevice(), nullptr); + ASSERT_EQ(planC.forTest_simpleGetDevice(), DeviceManager::getCpuDevice()); // Compound partition (two devices, each is capable of one of the // two operations). We could do more extensive checking here -- @@ -931,7 +929,8 @@ TEST_F(PartitioningTest, Cpu) { model1.identifyInputsAndOutputs({ m1Opnd0, m1Opnd3, m1Opnd2 }, { m1Opnd4, m1Opnd5 }); model1.finish(); ASSERT_TRUE(model1.isValid()); - ASSERT_NO_FATAL_FAILURE(ASSERT_TRUE(compare(step1, &model1, nullptr))); + ASSERT_NO_FATAL_FAILURE( + ASSERT_TRUE(compare(step1, &model1, DeviceManager::getCpuDevice()))); ASSERT_EQ(step1->getModelInputs(), (RemapVectorType{ { opnd0, m1Opnd0 } })); ASSERT_EQ(step1->getModelOutputs(), @@ -992,21 +991,24 @@ TEST_F(PartitioningTest, SetPartitioning) { }); // Test kPartitioningNo. We should not even attempt partitioning, - // so there should be no execution plan. + // so there should be a SIMPLE plan on CPU. PartitioningCompilation cPNo(&model, devices); ASSERT_EQ(cPNo.setPartitioning(DeviceManager::kPartitioningNo), Result::NO_ERROR); ASSERT_EQ(cPNo.finish(), Result::NO_ERROR); - ASSERT_EQ(cPNo.getExecutionPlan().forTest_getKind(), ExecutionPlan::Kind::EMPTY); + ASSERT_EQ(cPNo.getExecutionPlan().forTest_getKind(), ExecutionPlan::Kind::SIMPLE); + ASSERT_EQ(cPNo.getExecutionPlan().forTest_simpleGetDevice(), DeviceManager::getCpuDevice()); // Test kPartitioningWithFallback. We should attempt // partitioning, reach the end of the partitioning process (so we - // have an execution plan), discover the dimensionless - // intermediate operand, and still return success (because of - // fallback). + // have an unsuccessful execution plan), discover the dimensionless + // intermediate operand, then fallback to CPU with a SIMPLE plan, and + // finally return success. PartitioningCompilation cPWithFallback(&model, devices); ASSERT_EQ(cPWithFallback.setPartitioning(DeviceManager::kPartitioningWithFallback), Result::NO_ERROR); ASSERT_EQ(cPWithFallback.finish(), Result::NO_ERROR); - ASSERT_EQ(cPWithFallback.getExecutionPlan().forTest_getKind(), ExecutionPlan::Kind::ERROR); + ASSERT_EQ(cPWithFallback.getExecutionPlan().forTest_getKind(), ExecutionPlan::Kind::SIMPLE); + ASSERT_EQ(cPWithFallback.getExecutionPlan().forTest_simpleGetDevice(), + DeviceManager::getCpuDevice()); // Test kPartitioningWithoutFallback. We should attempt // partitioning, and fail. @@ -1140,7 +1142,7 @@ TEST_F(PartitioningTest, OemOperations) { ASSERT_NE(compilationIndecisiveOEM.finish(), Result::NO_ERROR); // Verify that we get an error if there are no drivers (only CPU fallback). - PartitioningCompilation compilationNoDrivers(&model, {} /* no drivers */); + PartitioningCompilation compilationNoDrivers(&model, makeDevices({}) /* no drivers */); ASSERT_EQ(compilationNoDrivers.finish(), Result::BAD_DATA); } |