diff options
author | Xusong Wang <xusongw@google.com> | 2019-01-21 23:16:20 -0800 |
---|---|---|
committer | Xusong Wang <xusongw@google.com> | 2019-02-12 13:58:44 -0800 |
commit | 1bbaa6a446ed683721a7574e08eb124ed9184768 (patch) | |
tree | c321faf26d01f3bf4715e743ebaca2d97e0c1633 /nn/runtime/test/TestExecution.cpp | |
parent | 119830162cbf159e3cb6befd4494e724ba4e9ca6 (diff) | |
download | ml-1bbaa6a446ed683721a7574e08eb124ed9184768.tar.gz |
Handle output shapes in ExecutionBuilder.
Let ExecutionBuilder correctly handle the output shapes, either
retrieved from a whole model execution, or combined from multiple
execution steps.
The output shapes are handled with on_finish() at the time
driver/fallback called notify().
Test: NeuralNetworksTest_static
Change-Id: Ibeda48f39befaed55d5f16a582b1354267b3e25d
Merged-In: Ibeda48f39befaed55d5f16a582b1354267b3e25d
(cherry picked from commit dd6832093b3eaa0361f443bedb8ba4b8db017518)
Diffstat (limited to 'nn/runtime/test/TestExecution.cpp')
-rw-r--r-- | nn/runtime/test/TestExecution.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/nn/runtime/test/TestExecution.cpp b/nn/runtime/test/TestExecution.cpp index a8576cc50..a327b5cba 100644 --- a/nn/runtime/test/TestExecution.cpp +++ b/nn/runtime/test/TestExecution.cpp @@ -83,6 +83,10 @@ class TestPreparedModel12 : public V1_2::IPreparedModel { CHECK(mPreparedModelV1_2 != nullptr) << "V1_2 prepared model is nullptr."; if (mErrorStatus == ErrorStatus::NONE) { return mPreparedModelV1_2->execute_1_2(request, measure, callback); + } else if (mErrorStatus == ErrorStatus::OUTPUT_INSUFFICIENT_SIZE) { + OutputShape shape = {.dimensions = {1}, .isSufficient = false}; + callback->notify_1_2(mErrorStatus, {shape}, kBadTiming); + return ErrorStatus::NONE; } else { callback->notify_1_2(mErrorStatus, {}, kBadTiming); return ErrorStatus::NONE; @@ -97,6 +101,10 @@ class TestPreparedModel12 : public V1_2::IPreparedModel { request, measure, [&cb](ErrorStatus error, const hidl_vec<OutputShape>& outputShapes, const Timing& timing) { cb(error, outputShapes, timing); }); + } else if (mErrorStatus == ErrorStatus::OUTPUT_INSUFFICIENT_SIZE) { + OutputShape shape = {.dimensions = {1}, .isSufficient = false}; + cb(mErrorStatus, {shape}, kBadTiming); + return Void(); } else { cb(mErrorStatus, {}, kBadTiming); return Void(); @@ -421,6 +429,7 @@ class ExecutionTestTemplate float mInputBuffer; float mOutputBuffer; const float kOutputBufferExpected = 3; + const std::vector<uint32_t> kOutputDimensionsExpected = {1}; private: static WrapperModel makeModel() { @@ -457,6 +466,17 @@ template<class DriverClass> void ExecutionTestTemplate<DriverClass>::TestWait() ASSERT_EQ(mOutputBuffer, kOutputBufferExpected); } std::vector<uint32_t> dimensions; + if (kExpectResult == Result::OUTPUT_INSUFFICIENT_SIZE) { + // Only one output operand, hardcoded as index 0. + ASSERT_EQ(execution.getOutputOperandDimensions(0, &dimensions), + Result::OUTPUT_INSUFFICIENT_SIZE); + } else { + ASSERT_EQ(execution.getOutputOperandDimensions(0, &dimensions), Result::NO_ERROR); + } + if (kExpectResult == Result::NO_ERROR || + kExpectResult == Result::OUTPUT_INSUFFICIENT_SIZE) { + ASSERT_EQ(dimensions, kOutputDimensionsExpected); + } } { SCOPED_TRACE("compute"); @@ -466,6 +486,18 @@ template<class DriverClass> void ExecutionTestTemplate<DriverClass>::TestWait() if (kExpectResult == Result::NO_ERROR) { ASSERT_EQ(mOutputBuffer, kOutputBufferExpected); } + std::vector<uint32_t> dimensions; + if (kExpectResult == Result::OUTPUT_INSUFFICIENT_SIZE) { + // Only one output operand, hardcoded as index 0. + ASSERT_EQ(execution.getOutputOperandDimensions(0, &dimensions), + Result::OUTPUT_INSUFFICIENT_SIZE); + } else { + ASSERT_EQ(execution.getOutputOperandDimensions(0, &dimensions), Result::NO_ERROR); + } + if (kExpectResult == Result::NO_ERROR || + kExpectResult == Result::OUTPUT_INSUFFICIENT_SIZE) { + ASSERT_EQ(dimensions, kOutputDimensionsExpected); + } } } @@ -488,12 +520,14 @@ INSTANTIATE_TEST_CASE_P(Flavor, ExecutionTest12, kTestValues); class ExecutionTest11 : public ExecutionTestTemplate<TestDriver11> {}; TEST_P(ExecutionTest11, Wait) { + if (kForceErrorStatus == ErrorStatus::OUTPUT_INSUFFICIENT_SIZE) return; TestWait(); } INSTANTIATE_TEST_CASE_P(Flavor, ExecutionTest11, kTestValues); class ExecutionTest10 : public ExecutionTestTemplate<TestDriver10> {}; TEST_P(ExecutionTest10, Wait) { + if (kForceErrorStatus == ErrorStatus::OUTPUT_INSUFFICIENT_SIZE) return; TestWait(); } INSTANTIATE_TEST_CASE_P(Flavor, ExecutionTest10, kTestValues); |