#include "core/modelIR/operations/ResizeOp.h"
#include "core/modelIR/operations/ScaleOp.h"
#include "core/modelIR/operations/SoftmaxOp.h"
+#include "core/modelIR/operations/SqrtOp.h"
#include "core/modelIR/operations/SqueezeOp.h"
#include "core/modelIR/operations/TanhOp.h"
#include "core/modelIR/operations/TransposeOp.h"
dotBuilder.updateWithOp(&op, node_info);
}
+void IrDotDumper::visit(ops::SqrtOp& op) {
+ auto node_info = DotIrNodeInfo().withType("Sqrt", op.getName())
+ .withInShapes(getInputShapes(op))
+ .withOutShapes(getOutputShapes(op));
+
+ dotBuilder.updateWithOp(&op, node_info);
+}
+
void IrDotDumper::visit(ops::ReduceFOp& op) {
static const std::map<ops::ReduceFOp::FuncType, const char*> types{
{ops::ReduceFOp::FuncType::mean, "mean"}
#include "core/modelIR/operations/ScaleOp.h"
#include "core/modelIR/operations/SoftmaxOp.h"
#include "core/modelIR/operations/SqueezeOp.h"
+#include "core/modelIR/operations/SqrtOp.h"
#include "core/modelIR/operations/TanhOp.h"
#include "core/modelIR/operations/TransposeOp.h"
#include "core/modelIR/operations/VariableOp.h"
void visit(ops::ScaleOp& op) override;
void visit(ops::SoftmaxOp& op) override;
void visit(ops::SqueezeOp& op) override;
+ void visit(ops::SqrtOp& op) override;
void visit(ops::TanhOp& op) override;
void visit(ops::TransposeOp& op) override;
void visit(ops::VariableOp& op) override;
--- /dev/null
+/*
+ * Copyright (c) 2018 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.
+ */
+
+#ifndef _NNC_CORE_IR_MODEL_SQRT_H_
+#define _NNC_CORE_IR_MODEL_SQRT_H_
+
+#include "core/modelIR/Operation.h"
+#include "core/modelIR/operations/CommonProps.h"
+
+namespace nnc {
+namespace mir {
+namespace ops {
+
+class SqrtOp : public Operation {
+public:
+ SqrtOp(const IODescriptor& arg) : Operation(Type::sqrt, {arg}) {
+ setOutputShape(0, getInputShape(0));
+ };
+};
+
+} // namespace ops
+} // namespace mir
+} // namespace nnc
+
+#endif //_NNC_CORE_IR_MODEL_SQRT_H_
HANDLE_OP(ELU, EluOp)
HANDLE_OP(squeeze, SqueezeOp)
HANDLE_OP(pad, PadOp)
+HANDLE_OP(sqrt, SqrtOp)
HANDLE_OP(reduceF, ReduceFOp)
HANDLE_OP(transpose, TransposeOp)
void visit(ops::ScaleOp& op) override;
void visit(ops::SoftmaxOp& op) override;
void visit(ops::SqueezeOp& op) override;
+ void visit(ops::SqrtOp& op) override;
void visit(ops::TanhOp& op) override;
void visit(ops::TransposeOp& op) override;
void visit(ops::VariableOp& op) override;
#include "core/modelIR/operations/ResizeOp.h"
#include "core/modelIR/operations/ScaleOp.h"
#include "core/modelIR/operations/SoftmaxOp.h"
+#include "core/modelIR/operations/SqrtOp.h"
#include "core/modelIR/operations/TanhOp.h"
#include "core/modelIR/operations/VariableOp.h"
assert(false && "Unimplemented operation: Squeeze");
}
+void AclCppOpGenerator::visit(ops::SqrtOp& op) {
+ assert(false && "Unimplemented operation: Sqrt");
+}
+
void AclCppOpGenerator::allocate(std::shared_ptr<ArtifactId> tensor_id) {
_allocates.push_back(tensor_id);
}
void AclCppOpGenerator::visit(mir::ops::GatherOp& op) {
assert(false && "Unimplemented operation: GatherOp");
}
-
}
// namespace nnc
void visit(mir::ops::ScaleOp& op) override;
void visit(mir::ops::SoftmaxOp& op) override;
void visit(mir::ops::SqueezeOp& op) override;
+ void visit(mir::ops::SqrtOp& op) override;
void visit(mir::ops::TanhOp& op) override;
void visit(mir::ops::TransposeOp& op) override;
void visit(mir::ops::VariableOp& op) override;
#include <cmath>
#include <cassert>
#include <vector>
+
#include "pass/PassException.h"
#include "passes/interpreter/Interpreter.h"
#include "core/modelIR/operations/ScaleOp.h"
#include "core/modelIR/operations/SoftmaxOp.h"
#include "core/modelIR/operations/SqueezeOp.h"
+#include "core/modelIR/operations/SqrtOp.h"
#include "core/modelIR/operations/TanhOp.h"
#include "core/modelIR/operations/TransposeOp.h"
#include "core/modelIR/operations/VariableOp.h"
var(op.getId()) = Pad(input, op)();
}
+void NNInterpreter::visit(ops::SqrtOp& op) {
+ mapByName(&op);
+ auto operand = op.getPrevNodes()[0];
+ auto input = Tensor<float>(var(operand.op->getId())[operand.index]);
+ var(op.getId()) = Fill<float>(op.getOutputShape(0), [&input](const Index id) {
+ return sqrt(input.at(id));
+ })();
+}
+
void NNInterpreter::visit(ops::ResizeOp& op) {
mapByName(&op);
auto operand = op.getPrevNodes()[0];
#include "cpp_depthwise_conv.generated.h"
#include "cpp_fully_connected.generated.h"
#include "cpp_pool.generated.h"
+#include "cpp_sqrt.generated.h"
#include "cpp_relu.generated.h"
#include "cpp_reduce.generated.h"
#include "cpp_softmax.generated.h"
out.write(cpp_elu, sizeof(cpp_elu));
out.write(cpp_tanh, sizeof(cpp_tanh));
out.write(cpp_pad, sizeof(cpp_pad));
+ out.write(cpp_sqrt, sizeof(cpp_sqrt));
out.write(cpp_conv_transpose, sizeof(cpp_conv_transpose));
out.write(cpp_transpose, sizeof(cpp_transpose));
out.write(cpp_gather, sizeof(cpp_gather));
#include "core/modelIR/operations/ScaleOp.h"
#include "core/modelIR/operations/SoftmaxOp.h"
#include "core/modelIR/operations/SqueezeOp.h"
+#include "core/modelIR/operations/SqrtOp.h"
#include "core/modelIR/operations/TanhOp.h"
#include "core/modelIR/operations/TransposeOp.h"
#include "core/modelIR/operations/VariableOp.h"
addOpDescr(&op, "reshape");
}
+void ModelAnalyzer::visit(ops::SqrtOp& op) {
+ addOpDescr(&op, "sqrtFN");
+}
+
void ModelAnalyzer::visit(mir::ops::PadOp& op) {
addOpDescr(&op, "pad");
}
void visit(mir::ops::ScaleOp& op) override;
void visit(mir::ops::SoftmaxOp& op) override;
void visit(mir::ops::SqueezeOp& op) override;
+ void visit(mir::ops::SqrtOp& op) override;
void visit(mir::ops::TanhOp& op) override;
void visit(mir::ops::TransposeOp& op) override;
void visit(mir::ops::VariableOp& op) override;
#include "core/modelIR/operations/ScaleOp.h"
#include "core/modelIR/operations/SoftmaxOp.h"
#include "core/modelIR/operations/SqueezeOp.h"
+#include "core/modelIR/operations/SqrtOp.h"
#include "core/modelIR/operations/TanhOp.h"
#include "core/modelIR/operations/TransposeOp.h"
}
}
+void Serializer::visit(mir::ops::SqrtOp& op) {
+ _curOp->_paramStartOffset = _buffer.size();
+ // no parameters to dump
+}
+
void Serializer::visit(mir::ops::ResizeOp& op) {
throw PassException("Not implemented yet");
}
void visit(mir::ops::ScaleOp& op) override;
void visit(mir::ops::SoftmaxOp& op) override;
void visit(mir::ops::SqueezeOp& op) override;
+ void visit(mir::ops::SqrtOp& op) override;
void visit(mir::ops::TanhOp& op) override;
void visit(mir::ops::TransposeOp& op) override;
void visit(mir::ops::VariableOp& op) override;
Pad(input, input_dims, left_paddings, right_paddings, output, output_dims);
}
+void sqrtFN(Tensor& out, const char* params, const Tensor& in) {
+ const float* input = in.getData();
+ const Dims<4> inp_d = shapeToDims(in.getShape());
+ // no params to deserialize
+
+ out.reShape(in.getShape());
+ Sqrt(input, inp_d, out.getData());
+}
+
void transpose(Tensor &out, const char *params, const Tensor &in) {
TransposeParams transpose_params;
transpose_params.perm_count = deserializeT<int32_t>(params);
--- /dev/null
+/*
+ * Copyright (c) 2018 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.
+ */
+
+inline void Sqrt(const float* input_data, const Dims<4>& input_dims, float* output_data) {
+
+ const auto input = MapAsVector(input_data, input_dims);
+ auto output = MapAsVector(output_data, input_dims);
+
+ output = input.array().sqrt();
+}
case BuiltinOperator_RESHAPE:
case BuiltinOperator_RESIZE_NEAREST_NEIGHBOR:
case BuiltinOperator_SQUEEZE:
+ case BuiltinOperator_SQRT:
case BuiltinOperator_PAD:
case BuiltinOperator_ADD:
case BuiltinOperator_MUL:
case BuiltinOperator_SQUEEZE:
outputs = _opCreator->createSqueeze(inputs, params, op->builtin_options_as<SqueezeOptions>());
break;
+ case BuiltinOperator_SQRT:
+ outputs = _opCreator->createSqrt(inputs, params);
+ break;
case BuiltinOperator_ADD:
outputs = _opCreator->createAdd(inputs, params, op->builtin_options_as<AddOptions>());
break;
#include "core/modelIR/operations/ReshapeOp.h"
#include "core/modelIR/operations/SqueezeOp.h"
#include "core/modelIR/operations/PadOp.h"
+#include "core/modelIR/operations/SqrtOp.h"
#include "core/modelIR/Tensor.h"
#include "core/modelIR/ShapeRange.h"
#include "pass/PassException.h"
return {addFusedActivation(inputs[0], activationType)};
}
+std::vector<mir::Operation*>
+TFLiteOpCreator::createSqrt(InputOps& inputs, InputParams&) {
+ return createOp<ops::SqrtOp>(ActivationFunctionType_NONE, inputs[0]->getOutput(0));
+}
+
} // namespace nnc
std::vector<mir::Operation*> convertResizeNN(InputOps, InputParams,
const ::tflite::ResizeNearestNeighborOptions*);
+ std::vector<mir::Operation*> createSqrt(InputOps, InputParams);
+
std::vector<mir::Operation*> createSqueeze(InputOps& inputs, InputParams& params,
const ::tflite::SqueezeOptions* opts);
#include "code_snippets/cpp_reduce.def"
#include "code_snippets/cpp_relu.def"
#include "code_snippets/cpp_softmax.def"
+#include "code_snippets/cpp_sqrt.def"
#include "code_snippets/cpp_tanh.def"
#include "code_snippets/cpp_transpose.def"
#include "core/modelIR/operations/Deconv2DOp.h"
#include "core/modelIR/operations/TanhOp.h"
#include "core/modelIR/operations/PadOp.h"
+#include "core/modelIR/operations/SqrtOp.h"
// various headers
#include "core/modelIR/TensorVariant.h"
}
}
-
TEST(cpp_operations_test, softmax)
{
// iterate over number of dimensions in tensor
createAndRunTestGraph(opGenerator, reshape, inputNTensors, aInputTensor);
}
+TEST(cpp_operations_test, sqrtTest) {
+ // test prerequisites
+ vector<int> shape_data{2, 3, 4, 5};
+ Tensor a_input_tensor;
+ vector<unique_ptr<mir::TensorVariant>> input_n_tensor(1);
+ fillTensors(input_n_tensor[0], a_input_tensor, shape_data, 1.0f);
+ auto op_generator = [](mir::Graph& g, const std::vector<mir::IODescriptor>& inputs) {
+ return g.create<mir::ops::SqrtOp>("y", inputs[0]);
+ };
+ createAndRunTestGraph(op_generator, sqrtFN, input_n_tensor, a_input_tensor);
+}
+
TEST(cpp_operations_test, pad) {
// test on matrix 2x3
vector<int> input_shape{2,3};