[Topkv2 OP] add nnapi delegate for Topk_v2 operation (#1463)
author최성진/동작제어Lab(SR)/Principal Engineer/삼성전자 <lotieye.choi@samsung.com>
Fri, 1 Jun 2018 01:18:30 +0000 (10:18 +0900)
committer오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Fri, 1 Jun 2018 01:18:30 +0000 (10:18 +0900)
* [Topkv2 OP] add nnapi delegate for Topk_v2 operation

This commit add nnapi delegate for Topk_v2 operation.
-change output order (output_value is first and output_index is second)

Signed-off-by: SungJin Choi <lotieye.choi@samsung.com>
* [Topkv2 OP] add nnapi delegate for Topk_v2 operation

This commit add nnapi delegate for Topk_v2 operation.
-change output order (output_value is first and output_index is second)

Signed-off-by: SungJin Choi <lotieye.choi@samsung.com>
libs/support/tflite/src/nnapi_delegate.cpp
runtimes/nn/common/CpuExecutor.cpp
runtimes/nn/runtime/NeuralNetworks.cpp

index f1dbd38..6d93d11 100644 (file)
@@ -344,6 +344,12 @@ void AddOpsAndParams(tflite::Interpreter *interpreter, ANeuralNetworksModel *nn_
             augmented_inputs.data(), static_cast<uint32_t>(node.outputs->size),
             reinterpret_cast<uint32_t *>(node.outputs->data)));
         continue;
+      case tflite::BuiltinOperator_TOPK_V2:
+        CHECK_NN(ANeuralNetworksModel_addOperationEx(
+            nn_model, ANEURALNETWORKS_TOPK_V2_EX, static_cast<uint32_t>(augmented_inputs.size()),
+            augmented_inputs.data(), static_cast<uint32_t>(node.outputs->size),
+            reinterpret_cast<uint32_t *>(node.outputs->data)));
+        continue;
       case tflite::BuiltinOperator_CONCAT_EMBEDDINGS:
       case tflite::BuiltinOperator_LSH_PROJECTION:
       case tflite::BuiltinOperator_SVDF:
@@ -364,7 +370,6 @@ void AddOpsAndParams(tflite::Interpreter *interpreter, ANeuralNetworksModel *nn_
       case tflite::BuiltinOperator_GATHER:
       case tflite::BuiltinOperator_SPACE_TO_BATCH_ND:
       case tflite::BuiltinOperator_BATCH_TO_SPACE_ND:
-      case tflite::BuiltinOperator_TOPK_V2:
       case tflite::BuiltinOperator_TRANSPOSE:
       case tflite::BuiltinOperator_MEAN:
       case tflite::BuiltinOperator_SPLIT:
index 829d202..76f2410 100644 (file)
@@ -1453,10 +1453,10 @@ int CpuExecutor::executeOperation(const Operation &operation)
       const RunTimeOperandInfo &input = mOperands[ins[0]];
       const int32_t &k = getScalarData<int32_t>(mOperands[ins[1]]);
 
-      RunTimeOperandInfo &outputIndexes = mOperands[outs[0]];
-      RunTimeOperandInfo &outputValues = mOperands[outs[1]];
-      Shape outIndexesShape = outputIndexes.shape();
+      RunTimeOperandInfo &outputValues = mOperands[outs[0]];
+      RunTimeOperandInfo &outputIndexes = mOperands[outs[1]];
       Shape outValuesShape = outputValues.shape();
+      Shape outIndexesShape = outputIndexes.shape();
 
       success = topk_v2Prepare(input.shape(), k, &outIndexesShape, &outValuesShape) &&
                 setInfoAndAllocateIfNeeded(&outputIndexes, outIndexesShape) &&
index f796d32..f622bc1 100644 (file)
@@ -356,6 +356,9 @@ OperationType getOperationType(ANeuralNetworksOperationTypeEx _type)
     case ANEURALNETWORKS_SUB_EX:
       type = OperationType::SUB;
       break;
+    case ANEURALNETWORKS_TOPK_V2_EX:
+      type = OperationType::TOPK_V2;
+      break;
     default:
       type = static_cast<OperationType>(_type);
       break;