Resolve param value for softmax at frontend (#5348)
author오형석/On-Device Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Fri, 7 Jun 2019 06:03:45 +0000 (15:03 +0900)
committer이춘석/On-Device Lab(SR)/Staff Engineer/삼성전자 <chunseok.lee@samsung.com>
Fri, 7 Jun 2019 06:03:45 +0000 (15:03 +0900)
* Resolve param value for softmax at frontend

Remove index param in softmax node and resolve value at frontend
Rename param name scale to beta (generally used)

Signed-off-by: Hyeongseok Oh <hseok82.oh@samsung.com>
* Remove unused variable in tflite loader

contrib/tflite_loader/loader.cc
runtimes/neurun/backend/acl_cl/StageGenerator.cc
runtimes/neurun/backend/acl_neon/StageGenerator.cc
runtimes/neurun/backend/cpu/StageGenerator.cc
runtimes/neurun/core/include/model/operation/SoftmaxNode.h
runtimes/neurun/core/src/compiler/OperationValidator.cc
runtimes/neurun/frontend/nnapi/wrapper/OperationFactory.cc

index f71a5ec..4096d04 100644 (file)
@@ -237,12 +237,7 @@ void Loader::loadSoftmax(const tflite::Operator *op)
   model::operation::SoftmaxNode::Param param;
   const auto *options = op->builtin_options_as_SoftmaxOptions();
   // Beta
-  model::Shape shape;
-  model::TypeInfo type_info(neurun::model::DataType::FLOAT32);
-  const float &beta = options->beta();
-  const uint8_t *ptr = reinterpret_cast<const uint8_t *>(&beta);
-  auto scale_index = createOperand<float>(ptr, shape, type_info);
-  param.scale_index = scale_index;
+  param.beta = options->beta();
 
   std::unique_ptr<model::Operation> new_op(
       new model::operation::SoftmaxNode(inputs, outputs, param));
index a5e4c55..ed28c77 100644 (file)
@@ -855,20 +855,19 @@ void StageGenerator::visit(const model::operation::SoftmaxNode &node)
 {
   const auto output_index{node.getOutputs().at(0)};
   const auto input_index{node.getInputs().at(model::operation::SoftmaxNode::Input::INPUT)};
-  const auto scale_index{node.param().scale_index};
 
   struct Param
   {
     model::OperandIndex output_index;
     model::OperandIndex input_index;
-    float scale;
+    float beta;
   };
 
   Param param;
 
   param.output_index = output_index;
   param.input_index = input_index;
-  param.scale = _ctx.at(scale_index).asScalar<float>();
+  param.beta = node.param().beta;
 
   auto tensors = _tensor_builder;
 
@@ -878,7 +877,7 @@ void StageGenerator::visit(const model::operation::SoftmaxNode &node)
 
     auto fn = nnfw::cpp14::make_unique<::arm_compute::CLSoftmaxLayer>();
 
-    fn->configure(input_alloc->handle(), output_alloc->handle(), param.scale);
+    fn->configure(input_alloc->handle(), output_alloc->handle(), param.beta);
 
     auto acl_fn = asAclFunction(std::move(fn));
 
index 704b9fc..c164524 100644 (file)
@@ -718,20 +718,19 @@ void StageGenerator::visit(const model::operation::SoftmaxNode &node)
 {
   const auto output_index{node.getOutputs().at(0)};
   const auto input_index{node.getInputs().at(model::operation::SoftmaxNode::Input::INPUT)};
-  const auto scale_index{node.param().scale_index};
 
   struct Param
   {
     model::OperandIndex output_index;
     model::OperandIndex input_index;
-    float scale;
+    float beta;
   };
 
   Param param;
 
   param.output_index = output_index;
   param.input_index = input_index;
-  param.scale = _ctx.at(scale_index).asScalar<float>();
+  param.beta = node.param().beta;
 
   auto tensors = _tensor_builder;
 
@@ -741,7 +740,7 @@ void StageGenerator::visit(const model::operation::SoftmaxNode &node)
 
     auto fn = nnfw::cpp14::make_unique<::arm_compute::NESoftmaxLayer>();
 
-    fn->configure(input_alloc->handle(), output_alloc->handle(), param.scale);
+    fn->configure(input_alloc->handle(), output_alloc->handle(), param.beta);
 
     auto acl_fn = asAclFunction(std::move(fn));
 
index 1c79e4b..dc8e220 100644 (file)
@@ -458,7 +458,6 @@ void StageGenerator::visit(const model::operation::SoftmaxNode &node)
 {
   const auto output_index{node.getOutputs().at(0)};
   const auto input_index{node.getInputs().at(model::operation::SoftmaxNode::Input::INPUT)};
-  const auto scale_index{node.param().scale_index};
 
   struct Param
   {
@@ -468,7 +467,7 @@ void StageGenerator::visit(const model::operation::SoftmaxNode &node)
     ::neurun::backend::cpu::kernel::Shape ofm_shape;
     ::neurun::backend::cpu::kernel::Shape ifm_shape;
 
-    float scale;
+    float beta;
   };
 
   Param param;
@@ -479,7 +478,7 @@ void StageGenerator::visit(const model::operation::SoftmaxNode &node)
   param.ofm_shape = ::neurun::backend::cpu::kernel::getShape(_ctx.at(output_index));
   param.ifm_shape = ::neurun::backend::cpu::kernel::getShape(_ctx.at(input_index));
 
-  param.scale = _ctx.at(scale_index).asScalar<float>();
+  param.beta = node.param().beta;
 
   auto tensors = _tensor_builder;
 
@@ -489,7 +488,7 @@ void StageGenerator::visit(const model::operation::SoftmaxNode &node)
 
     auto fn = nnfw::cpp14::make_unique<::neurun::backend::cpu::kernel::SoftMaxLayer>();
 
-    fn->configure(input_alloc->buffer(), param.ifm_shape, param.scale, output_alloc->buffer(),
+    fn->configure(input_alloc->buffer(), param.ifm_shape, param.beta, output_alloc->buffer(),
                   param.ofm_shape);
 
     builder.append(std::move(fn));
index fe39dfd..d344cb4 100644 (file)
@@ -38,7 +38,7 @@ public:
 
   struct Param
   {
-    OperandIndex scale_index;
+    float beta;
   };
 
 public:
index 5968a47..d4b6956 100644 (file)
@@ -60,13 +60,11 @@ void OperationValidator::visit(const model::operation::SoftmaxNode &node)
 
   const auto output_index{node.getOutputs().at(0)};
   const auto input_index{node.getInputs().at(0)};
-  const auto scale_index{node.param().scale_index};
 
   UNUSED_RELEASE(output_index);
   UNUSED_RELEASE(input_index);
 
   assert(_ctx.at(output_index).shape().rank() == _ctx.at(input_index).shape().rank());
-  assert(_ctx.at(scale_index).shape().rank() == 0);
 }
 
 void OperationValidator::visit(const model::operation::PermuteNode &node)
index ebef235..50337b1 100644 (file)
@@ -378,7 +378,7 @@ OperationFactory::OperationFactory()
   };
 
   _map[ANEURALNETWORKS_SOFTMAX] = [](const OperationFactory::Param &init_param,
-                                     neurun::model::Operands &) {
+                                     Operands &operands) {
     assert(init_param.input_count == 2 && init_param.output_count == 1);
 
     // Each input should be interpreted as follows:
@@ -389,8 +389,10 @@ OperationFactory::OperationFactory()
     OperandIndexSequence inputs{init_param.inputs[0]};
     OperandIndexSequence outputs{init_param.outputs[0]};
 
+    const auto beta_index = OperandIndex{init_param.inputs[1]};
+
     operation::SoftmaxNode::Param param;
-    param.scale_index = OperandIndex{init_param.inputs[1]};
+    param.beta = operands.at(beta_index).asScalar<float>();
 
     return new operation::SoftmaxNode{inputs, outputs, param};
   };