diff options
author | Przemyslaw Szczepaniak <pszczepaniak@google.com> | 2018-12-19 12:07:03 +0000 |
---|---|---|
committer | Michael K. Sanders <mks@google.com> | 2019-01-09 11:56:50 +0000 |
commit | 6419e67113c3b77268900b241a1a27255d9b6cfa (patch) | |
tree | 438bf30eaea1b11ab9268db878fe0d7833d98914 /nn/runtime/test/TestNeuralNetworksWrapper.h | |
parent | 8ebaf89d6365104e053e46eeb19d37ae1b83b7ed (diff) | |
download | ml-6419e67113c3b77268900b241a1a27255d9b6cfa.tar.gz |
Replace ANNOperandType::ExtraParams with a function call.
Exending ANeuralNetworkOperandType struct with new fields may be problematic
and difficult to maintain in longer term. This change turns recently introduced
ANNOperandType.extraParams field into a function call:
ANeuralNetworksModel_setOperandSymmPerChannelQuant(...)
that associates ANeuralNetworksSymmPerChannelQuant struct with an operand.
+ added to NeuralNetworks.h an ANDROID_Q ifdef for operand types added in Q.
Bug: 119249581
Test: NeuralNetworksTest_static
Change-Id: Idebe86ce1ca8f3a31dbfe7b21de4dd45df380a38
Merged-In: Idebe86ce1ca8f3a31dbfe7b21de4dd45df380a38
(cherry picked from commit 2df5477fecc92ed93459b79f5b1b1d2de309ae86)
Diffstat (limited to 'nn/runtime/test/TestNeuralNetworksWrapper.h')
-rw-r--r-- | nn/runtime/test/TestNeuralNetworksWrapper.h | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/nn/runtime/test/TestNeuralNetworksWrapper.h b/nn/runtime/test/TestNeuralNetworksWrapper.h index 1031d2ba4..c475fb809 100644 --- a/nn/runtime/test/TestNeuralNetworksWrapper.h +++ b/nn/runtime/test/TestNeuralNetworksWrapper.h @@ -23,6 +23,7 @@ #include "NeuralNetworks.h" #include <math.h> +#include <optional> #include <vector> namespace android { @@ -67,9 +68,11 @@ struct SymmPerChannelQuantParams { SymmPerChannelQuantParams(std::vector<float> scalesVec, uint32_t channelDim) : scales(std::move(scalesVec)) { - params = {.scaleCount = static_cast<uint32_t>(scales.size()), - .scales = scales.size() > 0 ? scales.data() : nullptr, - .channelDim = channelDim}; + params = { + .channelDim = channelDim, + .scaleCount = static_cast<uint32_t>(scales.size()), + .scales = scales.size() > 0 ? scales.data() : nullptr, + }; } }; @@ -77,10 +80,10 @@ struct OperandType { ANeuralNetworksOperandType operandType; std::vector<uint32_t> dimensions; - SymmPerChannelQuantParams channelQuant; + std::optional<SymmPerChannelQuantParams> channelQuant; OperandType(Type type, std::vector<uint32_t> d, float scale = 0.0f, int32_t zeroPoint = 0) - : dimensions(std::move(d)), channelQuant({}, 0) { + : dimensions(std::move(d)), channelQuant(std::nullopt) { operandType = { .type = static_cast<int32_t>(type), .dimensionCount = static_cast<uint32_t>(dimensions.size()), @@ -99,10 +102,6 @@ struct OperandType { .dimensions = dimensions.size() > 0 ? dimensions.data() : nullptr, .scale = scale, .zeroPoint = zeroPoint, - .extraParams = - { - .channelQuant = channelQuant.params, - }, }; } }; @@ -193,6 +192,13 @@ class Model { ANEURALNETWORKS_NO_ERROR) { mValid = false; } + if (type->channelQuant) { + if (ANeuralNetworksModel_setOperandSymmPerChannelQuantParams( + mModel, mNextOperandId, &type->channelQuant.value().params) != + ANEURALNETWORKS_NO_ERROR) { + mValid = false; + } + } return mNextOperandId++; } |