1 //
2 //  GeometryUnary.cpp
3 //  MNN
4 //
5 //  Created by MNN on 2020/07/27.
6 //  Copyright © 2018, Alibaba Group Holding Limited
7 //
8 
9 #include "geometry/GeometryComputer.hpp"
10 #include "core/OpCommonUtils.hpp"
11 #include "geometry/GeometryComputerUtils.hpp"
12 
13 namespace MNN {
14 class GeometryUnary : public GeometryComputer {
15 public:
onCompute(const Op * op,const std::vector<Tensor * > & inputs,const std::vector<Tensor * > & outputs,Context & context,CommandBuffer & res) const16     virtual bool onCompute(const Op* op, const std::vector<Tensor*>& inputs, const std::vector<Tensor*>& outputs, Context& context, CommandBuffer& res) const override {
17         MNN_ASSERT(1 == inputs.size());
18         MNN_ASSERT(1 == outputs.size());
19         auto input = inputs[0];
20         auto output = outputs[0];
21         UnaryOpOperation unaryType;
22         switch (op->type()) {
23             case OpType_TanH:
24                 unaryType = UnaryOpOperation_TANH;
25                 break;
26             case OpType_Sigmoid:
27                 unaryType = UnaryOpOperation_SIGMOID;
28                 break;
29             default:
30                 break;
31         }
32         auto cmd = GeometryComputerUtils::makeUnary(unaryType, input, output);
33         res.command.emplace_back(std::move(cmd));
34         return true;
35     }
36 };
37 
_create()38 static void _create() {
39     std::shared_ptr<GeometryComputer> comp(new GeometryUnary);
40     GeometryComputer::registerGeometryComputer(comp, {OpType_TanH, OpType_Sigmoid});
41 }
42 
43 REGISTER_GEOMETRY(GeometryUnary, _create);
44 
45 } // namespace MNN
46