diff options
author | Slava Shklyaev <slavash@google.com> | 2020-05-21 12:59:15 +0100 |
---|---|---|
committer | Slava Shklyaev <slavash@google.com> | 2020-06-12 12:44:23 +0100 |
commit | 4764e98fe28ade96cfb15a1b82012bd4374af9d3 (patch) | |
tree | 19ad7dc4590d56bb3af1eccffeeef94f608942f1 /nn/common | |
parent | be6a95c04abda0b2361cd2dceaf52500f4644ca2 (diff) | |
download | ml-4764e98fe28ade96cfb15a1b82012bd4374af9d3.tar.gz |
Relax control flow boundary operand dimension constraint
Also updates the NDK spec to mention the constraints and adds some
validation tests.
Bug: 132458982
Bug: 156918813
Test: NNT_static
Change-Id: Ia112e46da065a623a52ac1c402d28dcb963e5580
Merged-In: Ia112e46da065a623a52ac1c402d28dcb963e5580
(cherry picked from commit b7afd5952251561918940586acfae88e6722b6ad)
Diffstat (limited to 'nn/common')
-rw-r--r-- | nn/common/Utils.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/nn/common/Utils.cpp b/nn/common/Utils.cpp index 4e4d0e06a..188436f11 100644 --- a/nn/common/Utils.cpp +++ b/nn/common/Utils.cpp @@ -692,12 +692,18 @@ static int validateHalVersion(ANeuralNetworksOperationType opType, HalVersion ha return ANEURALNETWORKS_NO_ERROR; } -// Checks if two operands have the same types, shapes, and parameters. -// Omits lifetime, numberOfConsumers, and location. +// Checks if two operands have the same types, ranks (if specified), dimensions +// (if specified), scales, zeroPoints, and extraParams. static bool compatible(const Operand& a, const Operand& b) { NN_RET_CHECK(a.type == b.type) << toString(a.type) << " != " << toString(b.type); - NN_RET_CHECK(a.dimensions == b.dimensions) - << toString(a.dimensions) << " != " << toString(b.dimensions); + if (a.dimensions.size() != 0 && b.dimensions.size() != 0) { + NN_RET_CHECK_EQ(a.dimensions.size(), b.dimensions.size()) << "Incompatible dimensions"; + for (uint32_t i = 0, n = a.dimensions.size(); i < n; ++i) { + if (a.dimensions[i] != 0 && b.dimensions[i] != 0) { + NN_RET_CHECK_EQ(a.dimensions[i], b.dimensions[i]) << "Incompatible dimensions"; + } + } + } NN_RET_CHECK_EQ(a.scale, b.scale); NN_RET_CHECK_EQ(a.zeroPoint, b.zeroPoint); NN_RET_CHECK(a.extraParams == b.extraParams) |