Skip to content

Commit

Permalink
[onert] Add Shape inference for Pow and its test case (Samsung#1614)
Browse files Browse the repository at this point in the history
This PR adds shape inference for Pow and its test case.

Signed-off-by: LeeHanSol <[email protected]>
  • Loading branch information
hasw7569 authored Jun 5, 2020
1 parent 57fdecb commit 60af730
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 0 deletions.
2 changes: 2 additions & 0 deletions runtime/onert/core/include/util/ShapeInference.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class StaticInferer : public ir::OperationVisitor
// TODO write op starting from O
void visit(const ir::operation::Pack &op);
void visit(const ir::operation::Permute &op);
void visit(const ir::operation::Pow &op);
// TODO write op starting from Q
void visit(const ir::operation::Reshape &op);
void visit(const ir::operation::Round &op);
Expand Down Expand Up @@ -205,6 +206,7 @@ class DynamicInferer : public ir::OperationVisitor
// TODO write op starting from O
void visit(const ir::operation::Pack &op);
void visit(const ir::operation::Permute &op);
void visit(const ir::operation::Pow &op);
// TODO write op starting from Q
void visit(const ir::operation::Reshape &op);
void visit(const ir::operation::Round &op);
Expand Down
37 changes: 37 additions & 0 deletions runtime/onert/core/src/util/shapeinf/Pow.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "util/ShapeInference.h"

namespace onert
{
namespace shape_inference
{

void StaticInferer::visit(const ir::operation::Pow &op)
{
handleBinaryArithmeticOp(op, op.getInputs().at(ir::operation::Pow::Input::LHS),
op.getInputs().at(ir::operation::Pow::Input::RHS));
}

void DynamicInferer::visit(const ir::operation::Pow &op)
{
handleBinaryArithmeticOp(op, op.getInputs().at(ir::operation::Pow::Input::LHS),
op.getInputs().at(ir::operation::Pow::Input::RHS));
}

} // namespace shape_inference
} // namespace onert
1 change: 1 addition & 0 deletions tests/nnapi/nnapi_gtest.skip.aarch64-linux.acl_cl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ GeneratedTests.pow_2D_float_nnfw
GeneratedTests.pow_broadcast_float_nnfw
GeneratedTests.pow_broadcast_float_nnfw_2
GeneratedTests.pow_broadcast_float_nnfw_3
GeneratedTests.pow_dynamic_nnfw
GeneratedTests.range_ex_float_1
GeneratedTests.range_ex_float_2
GeneratedTests.reduce_all
Expand Down
1 change: 1 addition & 0 deletions tests/nnapi/nnapi_gtest.skip.aarch64-linux.acl_neon
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ GeneratedTests.pow_2D_float_nnfw
GeneratedTests.pow_broadcast_float_nnfw
GeneratedTests.pow_broadcast_float_nnfw_2
GeneratedTests.pow_broadcast_float_nnfw_3
GeneratedTests.pow_dynamic_nnfw
GeneratedTests.range_ex_float_1
GeneratedTests.range_ex_float_2
GeneratedTests.reduce_all
Expand Down
1 change: 1 addition & 0 deletions tests/nnapi/nnapi_gtest.skip.armv7l-linux.acl_cl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ GeneratedTests.pow_2D_float_nnfw
GeneratedTests.pow_broadcast_float_nnfw
GeneratedTests.pow_broadcast_float_nnfw_2
GeneratedTests.pow_broadcast_float_nnfw_3
GeneratedTests.pow_dynamic_nnfw
GeneratedTests.range_ex_float_1
GeneratedTests.range_ex_float_2
GeneratedTests.reduce_all
Expand Down
1 change: 1 addition & 0 deletions tests/nnapi/nnapi_gtest.skip.armv7l-linux.acl_neon
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ GeneratedTests.pow_2D_float_nnfw
GeneratedTests.pow_broadcast_float_nnfw
GeneratedTests.pow_broadcast_float_nnfw_2
GeneratedTests.pow_broadcast_float_nnfw_3
GeneratedTests.pow_dynamic_nnfw
GeneratedTests.range_ex_float_1
GeneratedTests.range_ex_float_2
GeneratedTests.reduce_all
Expand Down
1 change: 1 addition & 0 deletions tests/nnapi/nnapi_gtest.skip.noarch.interp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ GeneratedTests.pow_2D_float_nnfw
GeneratedTests.pow_broadcast_float_nnfw
GeneratedTests.pow_broadcast_float_nnfw_2
GeneratedTests.pow_broadcast_float_nnfw_3
GeneratedTests.pow_dynamic_nnfw
GeneratedTests.prelu
GeneratedTests.prelu_broadcast_float_1_nnfw
GeneratedTests.prelu_broadcast_quant8_1_nnfw
Expand Down
69 changes: 69 additions & 0 deletions tests/nnapi/specs/V1_2/pow_dynamic_nnfw.mod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#
# Copyright (C) 2018 The Android Open Source Project
# Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# refer to tanh_v1_dynamic.mod.py about the structore

# This adds reshape as the first op in a model and
# returns output of reshape, which is dynamic tensor

'''
Testing Pow op when the input is dynamic.
input [2, 3] shape [2] (value of shape will be [2, 3])
| |
+-------------+
|
Reshape (added by DynamicInputGenerator since it generates its output to be dynamic)
|
| dynamic tensor at compilation time but the shape will be [2, 3] at execution time
|
Pow
|
output (dynamic tensor, [2, 3] at execution time)
'''

import dynamic_tensor

model = Model()

model_input1_shape = [2, 3]

dynamic_layer = dynamic_tensor.DynamicInputGenerator(model, model_input1_shape, "TENSOR_FLOAT32")

test_node_input = dynamic_layer.getTestNodeInput()

i2 = Input("op2", "TENSOR_FLOAT32", "{2, 3}")
o1 = Output("op3", "TENSOR_FLOAT32", "{2, 3}")

model = model.Operation("POW", test_node_input, i2).To(o1) # Pow

model_input1_data = [1., 2., 3., 4., 5., 6.]
model_input2_data = [1., 2., 3., 0.5, 5., 2.]

input0 = {
dynamic_layer.getModelInput(): model_input1_data, # input 1
dynamic_layer.getShapeInput() : model_input1_shape,

i2: model_input2_data # input 2
}

output0 = {
o1: [1., 4., 27., 2., 3125., 36.]
}

# Instantiate an example
Example((input0, output0))

0 comments on commit 60af730

Please sign in to comment.