diff options
author | David Gross <dgross@google.com> | 2019-03-15 17:26:32 -0700 |
---|---|---|
committer | David Gross <dgross@google.com> | 2019-03-22 10:43:47 -0700 |
commit | 2d47c80c8efd6fdef008cea8f3afef93766d7042 (patch) | |
tree | be47d7eaaa409738ccddca03dd240a2b2b0fc2bc /neuralnetworks | |
parent | c8b3d162c286f121b5bad0b0306692756c4bfb8e (diff) | |
download | android_hardware_interfaces-2d47c80c8efd6fdef008cea8f3afef93766d7042.tar.gz android_hardware_interfaces-2d47c80c8efd6fdef008cea8f3afef93766d7042.tar.bz2 android_hardware_interfaces-2d47c80c8efd6fdef008cea8f3afef93766d7042.zip |
Add @V1_2::Capabilities to support all non extension operand types.
Performance information in Capabilities is used by the runtime when
it selects the appropriate processor to distribute work to. Prior to
this CL, Capabilities can only distinguish between float and non-float
data types -- so, for example, float16 and float32 performance is
considered to be the same, and performance for all non-float data types is
considered to be the same.
Bug: 124041010
Test: NeuralNetworksTest_static
Test: VtsHalNeuralnetworksV1_2TargetTest --hal_service_instance=android.hardware.neuralnetworks@1.2::IDevice/sample-all
Change-Id: I83fb5920c1c75afbd7750d793a0b8f3e72a0552c
Merged-In: I83fb5920c1c75afbd7750d793a0b8f3e72a0552c
(cherry picked from commit 632b4bd9b0ba0b26a40c3f81fad724f8c07179fe)
Diffstat (limited to 'neuralnetworks')
-rw-r--r-- | neuralnetworks/1.2/IDevice.hal | 11 | ||||
-rw-r--r-- | neuralnetworks/1.2/types.hal | 33 | ||||
-rw-r--r-- | neuralnetworks/1.2/vts/functional/BasicTests.cpp | 27 |
3 files changed, 70 insertions, 1 deletions
diff --git a/neuralnetworks/1.2/IDevice.hal b/neuralnetworks/1.2/IDevice.hal index b9fa38870..43e2c563c 100644 --- a/neuralnetworks/1.2/IDevice.hal +++ b/neuralnetworks/1.2/IDevice.hal @@ -76,6 +76,17 @@ interface IDevice extends @1.1::IDevice { getType() generates (ErrorStatus status, DeviceType type); /** + * Gets the capabilities of a driver. + * + * @return status Error status of the call, must be: + * - NONE if successful + * - DEVICE_UNAVAILABLE if driver is offline or busy + * - GENERAL_FAILURE if there is an unspecified error + * @return capabilities Capabilities of the driver. + */ + getCapabilities_1_2() generates (ErrorStatus status, Capabilities capabilities); + + /** * Gets information about extensions supported by the driver implementation. * * All extension operations and operands must be fully supported for the diff --git a/neuralnetworks/1.2/types.hal b/neuralnetworks/1.2/types.hal index 918048bd3..77e1eb3c2 100644 --- a/neuralnetworks/1.2/types.hal +++ b/neuralnetworks/1.2/types.hal @@ -4583,6 +4583,39 @@ enum DeviceType : int32_t { }; /** + * The capabilities of a driver. + * + * Performance of an operation comes from the type of its first operand. + * This represents performance for non extension operand types. + */ +struct Capabilities { + /** + * Driver performance when operating on float32 data but performing + * calculations with range and/or precision as low as that of the IEEE + * 754 16-bit floating-point format. + */ + PerformanceInfo relaxedFloat32toFloat16PerformanceScalar; + PerformanceInfo relaxedFloat32toFloat16PerformanceTensor; + + /** + * Driver performance when operating on a particular data type. + * In the case of float32 data, this is used when the calculations + * are not relaxed. + */ + struct OperandPerformance { + OperandType type; + PerformanceInfo info; + }; + + /** + * Performance by operand type. Must be sorted by OperandType. + * If a particular OperandType is not present in operandPerformance, + * its performance is treated as { .execTime = FLT_MAX, .powerUsage = FLT_MAX }. + */ + vec<OperandPerformance> operandPerformance; +}; + +/** * Describes one operation of the model's graph. */ struct Operation { diff --git a/neuralnetworks/1.2/vts/functional/BasicTests.cpp b/neuralnetworks/1.2/vts/functional/BasicTests.cpp index 365a750fd..61aa5716f 100644 --- a/neuralnetworks/1.2/vts/functional/BasicTests.cpp +++ b/neuralnetworks/1.2/vts/functional/BasicTests.cpp @@ -25,7 +25,7 @@ namespace V1_2 { namespace vts { namespace functional { -using V1_1::Capabilities; +using V1_0::PerformanceInfo; // create device test TEST_F(NeuralnetworksHidlTest, CreateDevice) {} @@ -37,6 +37,31 @@ TEST_F(NeuralnetworksHidlTest, StatusTest) { EXPECT_EQ(DeviceStatus::AVAILABLE, static_cast<DeviceStatus>(status)); } +// initialization +TEST_F(NeuralnetworksHidlTest, GetCapabilitiesTest) { + using OperandPerformance = Capabilities::OperandPerformance; + Return<void> ret = device->getCapabilities_1_2([](ErrorStatus status, + const Capabilities& capabilities) { + EXPECT_EQ(ErrorStatus::NONE, status); + + auto isPositive = [](const PerformanceInfo& perf) { + return perf.execTime > 0.0f && perf.powerUsage > 0.0f; + }; + + EXPECT_TRUE(isPositive(capabilities.relaxedFloat32toFloat16PerformanceScalar)); + EXPECT_TRUE(isPositive(capabilities.relaxedFloat32toFloat16PerformanceTensor)); + const auto& opPerf = capabilities.operandPerformance; + EXPECT_TRUE(std::all_of( + opPerf.begin(), opPerf.end(), + [isPositive](const OperandPerformance& a) { return isPositive(a.info); })); + EXPECT_TRUE(std::is_sorted(opPerf.begin(), opPerf.end(), + [](const OperandPerformance& a, const OperandPerformance& b) { + return a.type < b.type; + })); + }); + EXPECT_TRUE(ret.isOk()); +} + // device version test TEST_F(NeuralnetworksHidlTest, GetDeviceVersionStringTest) { Return<void> ret = device->getVersionString([](ErrorStatus status, const hidl_string& version) { |