From d721f0edd0971c00c5b8c083fbc08e018b73832b Mon Sep 17 00:00:00 2001 From: Slava Shklyaev Date: Wed, 11 Nov 2020 14:02:25 +0000 Subject: Use sensible Capabilities in test drivers Although zero PerformanceInfo::execTime or powerUsage is not explicitly prohibited by the spec, it makes little sense and the new HAL device wrappers (change Iec6ae739) do not accept zero PerformanceInfo. Bug: 170289677 Test: NNT_static Change-Id: I6cc0af5f30ad980e4866badacd9ae8d2c9f87022 Merged-In: I6cc0af5f30ad980e4866badacd9ae8d2c9f87022 (cherry picked from commit e72232d73cd95c8a0383430d5b491744367b2303) --- nn/runtime/test/HalUtils.h | 37 ++++++++++++++++++++++++++ nn/runtime/test/TestExtensions.cpp | 3 ++- nn/runtime/test/TestFailingDriver.cpp | 6 ++--- nn/runtime/test/TestPartitioning.cpp | 15 +++-------- nn/runtime/test/TestRemoveDefaultArguments.cpp | 3 ++- 5 files changed, 46 insertions(+), 18 deletions(-) create mode 100644 nn/runtime/test/HalUtils.h diff --git a/nn/runtime/test/HalUtils.h b/nn/runtime/test/HalUtils.h new file mode 100644 index 000000000..a1cb5b13d --- /dev/null +++ b/nn/runtime/test/HalUtils.h @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_FRAMEWORKS_ML_NN_RUNTIME_TEST_HAL_UTILS_H +#define ANDROID_FRAMEWORKS_ML_NN_RUNTIME_TEST_HAL_UTILS_H + +#include "HalInterfaces.h" +#include "Utils.h" + +namespace android::nn { + +// Creates valid V1_3::Capabilities. +inline V1_3::Capabilities makeCapabilities(float perf) { + const V1_0::PerformanceInfo perfInfo = {.execTime = perf, .powerUsage = perf}; + return {.relaxedFloat32toFloat16PerformanceScalar = perfInfo, + .relaxedFloat32toFloat16PerformanceTensor = perfInfo, + .operandPerformance = nonExtensionOperandPerformance(perfInfo), + .ifPerformance = perfInfo, + .whilePerformance = perfInfo}; +}; + +} // namespace android::nn + +#endif // ANDROID_FRAMEWORKS_ML_NN_RUNTIME_TEST_HAL_UTILS_H diff --git a/nn/runtime/test/TestExtensions.cpp b/nn/runtime/test/TestExtensions.cpp index da13073e2..d9fa96d7c 100644 --- a/nn/runtime/test/TestExtensions.cpp +++ b/nn/runtime/test/TestExtensions.cpp @@ -20,6 +20,7 @@ #include #include "HalInterfaces.h" +#include "HalUtils.h" #include "Manager.h" #include "NeuralNetworks.h" #include "NeuralNetworksExtensions.h" @@ -56,7 +57,7 @@ class TestDriver : public SampleDriver { } hardware::Return getCapabilities_1_3(getCapabilities_1_3_cb cb) override { - cb(V1_3::ErrorStatus::NONE, {/* Placeholder zero-filled capabilities. */}); + cb(V1_3::ErrorStatus::NONE, ::android::nn::makeCapabilities(1.0)); return hardware::Void(); } diff --git a/nn/runtime/test/TestFailingDriver.cpp b/nn/runtime/test/TestFailingDriver.cpp index d2e30a656..a7a0aa5d9 100644 --- a/nn/runtime/test/TestFailingDriver.cpp +++ b/nn/runtime/test/TestFailingDriver.cpp @@ -22,6 +22,7 @@ #include "CompilationBuilder.h" #include "ExecutionPlan.h" +#include "HalUtils.h" #include "Manager.h" #include "SampleDriverPartial.h" #include "TestNeuralNetworksWrapper.h" @@ -51,10 +52,7 @@ class FailingTestDriver : public SampleDriverPartial { FailingTestDriver() : SampleDriverPartial(kTestDriverName, &mEmptyOperationResolver) {} hardware::Return getCapabilities_1_3(getCapabilities_1_3_cb cb) override { - cb(V1_3::ErrorStatus::NONE, - {.operandPerformance = {{.type = V1_3::OperandType::TENSOR_FLOAT32, - .info = {.execTime = 0.1, // Faster than CPU. - .powerUsage = 0.1}}}}); + cb(V1_3::ErrorStatus::NONE, makeCapabilities(0.1)); // Faster than CPU. return hardware::Void(); } diff --git a/nn/runtime/test/TestPartitioning.cpp b/nn/runtime/test/TestPartitioning.cpp index 939612a78..8e705afb9 100644 --- a/nn/runtime/test/TestPartitioning.cpp +++ b/nn/runtime/test/TestPartitioning.cpp @@ -33,6 +33,7 @@ #include "ControlFlow.h" #include "ExecutionPlan.h" #include "HalInterfaces.h" +#include "HalUtils.h" #include "Manager.h" #include "ModelBuilder.h" #include "NeuralNetworks.h" @@ -175,16 +176,6 @@ using WrapperSymmPerChannelQuantParams = ::android::nn::test_wrapper::SymmPerCha using WrapperType = ::android::nn::test_wrapper::Type; using android::sp; -V1_3::Capabilities makeCapabilities(float perf) { - V1_0::PerformanceInfo perfInfo = {.execTime = perf, .powerUsage = perf}; - return {.relaxedFloat32toFloat16PerformanceScalar = perfInfo, - .relaxedFloat32toFloat16PerformanceTensor = perfInfo, - .operandPerformance = - ::android::nn::nonExtensionOperandPerformance(perfInfo), - .ifPerformance = perfInfo, - .whilePerformance = perfInfo}; -}; - void update(V1_3::Capabilities* capabilities, V1_3::OperandType type, float perf) { V1_0::PerformanceInfo perfInfo = {.execTime = perf, .powerUsage = perf}; ::android::nn::update(&capabilities->operandPerformance, type, perfInfo); @@ -2056,7 +2047,7 @@ TEST_F(PartitioningTest, Perf) { model.finish(); ASSERT_TRUE(model.isValid()); - const V1_3::Capabilities baseCapabilities = makeCapabilities(0.5); + const V1_3::Capabilities baseCapabilities = ::android::nn::makeCapabilities(0.5); { // better than base @@ -2846,7 +2837,7 @@ TEST_F(PerfTest, Lookup) { // We'll use this to ensure that we can save and then recover a type's performance. auto typePerf = [](V1_3::OperandType type) { return float(static_cast(type)); }; - V1_3::Capabilities capabilities = makeCapabilities(-1.0f); + V1_3::Capabilities capabilities = ::android::nn::makeCapabilities(-1.0f); for (uint32_t type = static_cast(V1_3::OperandTypeRange::FUNDAMENTAL_MIN); type <= static_cast(V1_3::OperandTypeRange::FUNDAMENTAL_MAX); ++type) { diff --git a/nn/runtime/test/TestRemoveDefaultArguments.cpp b/nn/runtime/test/TestRemoveDefaultArguments.cpp index daef6bf60..6b7283f44 100644 --- a/nn/runtime/test/TestRemoveDefaultArguments.cpp +++ b/nn/runtime/test/TestRemoveDefaultArguments.cpp @@ -23,6 +23,7 @@ #include #include "GeneratedTestUtils.h" +#include "HalUtils.h" #include "Manager.h" #include "SampleDriverPartial.h" #include "TestNeuralNetworksWrapper.h" @@ -113,7 +114,7 @@ class TestDriver : public SampleDriverPartial { TestDriver() : SampleDriverPartial(kTestDriverName) {} hardware::Return getCapabilities_1_3(getCapabilities_1_3_cb cb) override { - cb(V1_3::ErrorStatus::NONE, {/* Placeholder zero-filled capabilities. */}); + cb(V1_3::ErrorStatus::NONE, makeCapabilities(1.0)); return hardware::Void(); } -- cgit v1.2.3