diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2020-06-23 09:04:35 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-06-23 09:04:35 +0000 |
commit | 4bc856326596c857bdda632c3240e92c540f2cb5 (patch) | |
tree | ef2daa91c3d35d4c0cf284f60a9bc768359f185b /nn/runtime | |
parent | b79f98913281823803824ac578772f44e5f40e21 (diff) | |
parent | 0fda6bb19a6fa83fe512dd6889b71e3ab37709bc (diff) | |
download | ml-4bc856326596c857bdda632c3240e92c540f2cb5.tar.gz |
Merge "Add HAL-level validation for CF operands of unknown size" into rvc-dev
Diffstat (limited to 'nn/runtime')
-rw-r--r-- | nn/runtime/ExecutionPlan.cpp | 5 | ||||
-rw-r--r-- | nn/runtime/Manager.cpp | 4 | ||||
-rw-r--r-- | nn/runtime/ModelBuilder.cpp | 17 |
3 files changed, 16 insertions, 10 deletions
diff --git a/nn/runtime/ExecutionPlan.cpp b/nn/runtime/ExecutionPlan.cpp index 1f540805f..1797475ac 100644 --- a/nn/runtime/ExecutionPlan.cpp +++ b/nn/runtime/ExecutionPlan.cpp @@ -555,6 +555,11 @@ int ExecutionStep::finishStepModel(const ModelBuilder* mainModel, bool* hasOutpu [](auto& e) { return e.second; }); NN_RETURN_IF_ERROR(mStepModel.identifyInputsAndOutputs(inputs.size(), inputs.data(), outputs.size(), outputs.data())); + // TODO: Model::finish() should use ValidationMode::RUNTIME when sending the + // step model to CpuDevice. Right now, this is harmless because the only + // difference in validation occurs with control flow operations and inputs + // or outputs of unknown size and we never send control flow operations to + // CpuDevice. We need to address this if this behavior changes (b/151634976). NN_RETURN_IF_ERROR(mStepModel.finish()); // TODO: Move compilation elsewhere? diff --git a/nn/runtime/Manager.cpp b/nn/runtime/Manager.cpp index 634cd2aec..50d118000 100644 --- a/nn/runtime/Manager.cpp +++ b/nn/runtime/Manager.cpp @@ -657,8 +657,8 @@ std::pair<int, std::shared_ptr<PreparedModel>> CpuDevice::prepareModel( << "Should never call prepareModel with cache information on CpuDevice"; const Model model = makeModel(); - if (!validateModel(model) || !validateExecutionPreference(preference) || - !validatePriority(priority)) { + if (!validateModel(model, ValidationMode::RUNTIME) || + !validateExecutionPreference(preference) || !validatePriority(priority)) { return {ANEURALNETWORKS_OP_FAILED, nullptr}; } if (hasDeadlinePassed(deadline)) { diff --git a/nn/runtime/ModelBuilder.cpp b/nn/runtime/ModelBuilder.cpp index 8669203de..73ec1af8c 100644 --- a/nn/runtime/ModelBuilder.cpp +++ b/nn/runtime/ModelBuilder.cpp @@ -388,13 +388,14 @@ int ModelBuilder::addOperation(ANeuralNetworksOperationType type, uint32_t input auto getOutputOperand = [this](const Operand& modelOperand, uint32_t index) -> const Operand* { return &getReferencedModel(modelOperand)->getOutputOperand(index); }; - NN_RETURN_IF_ERROR(validateOperation(type, inputCount, inputs, outputCount, outputs, mOperands, - HalVersion::LATEST, - {.isValidSubgraphReference = isValidSubgraphReference, - .getSubgraphInputCount = getInputCount, - .getSubgraphOutputCount = getOutputCount, - .getSubgraphInputOperand = getInputOperand, - .getSubgraphOutputOperand = getOutputOperand})); + NN_RETURN_IF_ERROR(validateOperation( + type, inputCount, inputs, outputCount, outputs, mOperands, HalVersion::LATEST, + {.isValidSubgraphReference = isValidSubgraphReference, + .getSubgraphInputCount = getInputCount, + .getSubgraphOutputCount = getOutputCount, + .getSubgraphInputOperand = getInputOperand, + .getSubgraphOutputOperand = getOutputOperand, + .allowControlFlowOperationWithOperandOfUnknownSize = true})); uint32_t operationIndex = operationCount(); if (operationIndex >= MAX_NUMBER_OF_OPERATIONS) { @@ -523,7 +524,7 @@ int ModelBuilder::finish() { // a CONSTANT_REFERENCE operand will not have correct .poolIndex, and // validation will not work properly. const Model modelForValidation = makeHidlModel(); - if (!validateModel(modelForValidation)) { + if (!validateModel(modelForValidation, ValidationMode::RUNTIME)) { LOG(ERROR) << "ANeuralNetworksModel_finish called on invalid model"; mInvalidModel = true; return ANEURALNETWORKS_BAD_DATA; |