diff options
author | Chunseok Lee <chunseok.lee@samsung.com> | 2020-12-14 14:43:04 +0900 |
---|---|---|
committer | Chunseok Lee <chunseok.lee@samsung.com> | 2020-12-14 14:43:04 +0900 |
commit | 12d88feea8573f8490629cf62fc342b152e57d65 (patch) | |
tree | 3c734cc4d629834d2d523f4575ef84cd64684e57 /compiler/luci/lang/include | |
parent | d6b371e095d737922187a518b8faba1ef6f3a2b1 (diff) | |
download | nnfw-12d88feea8573f8490629cf62fc342b152e57d65.tar.gz nnfw-12d88feea8573f8490629cf62fc342b152e57d65.tar.bz2 nnfw-12d88feea8573f8490629cf62fc342b152e57d65.zip |
Imported Upstream version 1.11.0upstream/1.11.0
Diffstat (limited to 'compiler/luci/lang/include')
147 files changed, 7836 insertions, 0 deletions
diff --git a/compiler/luci/lang/include/luci/IR/AttrDilation.h b/compiler/luci/lang/include/luci/IR/AttrDilation.h new file mode 100644 index 000000000..c2b28d77d --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/AttrDilation.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_ATTRDILATION_H__ +#define __LUCI_IR_ATTRDILATION_H__ + +#include <stdint.h> + +namespace luci +{ + +class Dilation final +{ +public: + Dilation() : _w(1), _h(1) {} + + int32_t w() const { return _w; } + void w(int32_t w) { _w = w; } + + int32_t h() const { return _h; } + void h(int32_t h) { _h = h; } + +private: + int32_t _w; + int32_t _h; +}; + +} // namespace luci + +#endif // __LUCI_IR_ATTRDILATION_H__ diff --git a/compiler/luci/lang/include/luci/IR/AttrFilter.h b/compiler/luci/lang/include/luci/IR/AttrFilter.h new file mode 100644 index 000000000..7909fa523 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/AttrFilter.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_ATTRFILTER_H__ +#define __LUCI_IR_ATTRFILTER_H__ + +#include <stdint.h> + +namespace luci +{ + +class Filter final +{ +public: + Filter() : _w(1), _h(1) {} + + int32_t w() const { return _w; } + void w(int32_t w) { _w = w; } + + int32_t h() const { return _h; } + void h(int32_t h) { _h = h; } + +private: + int32_t _w; + int32_t _h; +}; + +} // namespace luci + +#endif // __LUCI_IR_ATTRFILTER_H__ diff --git a/compiler/luci/lang/include/luci/IR/AttrFusedActFunc.h b/compiler/luci/lang/include/luci/IR/AttrFusedActFunc.h new file mode 100644 index 000000000..3f21d5858 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/AttrFusedActFunc.h @@ -0,0 +1,38 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_ATTRFUSEDACTFUNC_H__ +#define __LUCI_IR_ATTRFUSEDACTFUNC_H__ + +namespace luci +{ + +// TODO Divide into TFL version and Circle version when they go different approach +enum class FusedActFunc +{ + UNDEFINED, // This is not defined by TFLite or Circle. This was added to + // prevent programming error. + NONE, + RELU, + RELU_N1_TO_1, + RELU6, + TANH, + SIGN_BIT +}; + +} // namespace luci + +#endif // __LUCI_IR_ATTRFUSEDACTFUNC_H__ diff --git a/compiler/luci/lang/include/luci/IR/AttrMirrorPadMode.h b/compiler/luci/lang/include/luci/IR/AttrMirrorPadMode.h new file mode 100644 index 000000000..7ca9d5d99 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/AttrMirrorPadMode.h @@ -0,0 +1,33 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_ATTR_MIRROR_PAD_MODE_H__ +#define __LUCI_IR_ATTR_MIRROR_PAD_MODE_H__ + +namespace luci +{ + +enum class MirrorPadMode +{ + UNDEFINED, // This is not defined by Circle. This was added to prevent programming error. + + REFLECT, + SYMMETRIC, +}; + +} // namespace luci + +#endif // __LUCI_IR_ATTR_MIRROR_PAD_MODE_H__ diff --git a/compiler/luci/lang/include/luci/IR/AttrPadding.h b/compiler/luci/lang/include/luci/IR/AttrPadding.h new file mode 100644 index 000000000..5c295e0cd --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/AttrPadding.h @@ -0,0 +1,33 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_ATTRPADDING_H__ +#define __LUCI_IR_ATTRPADDING_H__ + +namespace luci +{ + +enum class Padding +{ + UNDEFINED, // This is not defined by TFLite. This was added to prevent programming error. + + SAME, + VALID, +}; + +} // namespace luci + +#endif // __LUCI_IR_ATTRPADDING_H__ diff --git a/compiler/luci/lang/include/luci/IR/AttrStride.h b/compiler/luci/lang/include/luci/IR/AttrStride.h new file mode 100644 index 000000000..654967d73 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/AttrStride.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_ATTRSTRIDE_H__ +#define __LUCI_IR_ATTRSTRIDE_H__ + +#include <stdint.h> + +namespace luci +{ + +class Stride final +{ +public: + Stride() : _w(1), _h(1) {} + + int32_t w() const { return _w; } + void w(int32_t w) { _w = w; } + + int32_t h() const { return _h; } + void h(int32_t h) { _h = h; } + +private: + int32_t _w; + int32_t _h; +}; + +} // namespace luci + +#endif // __LUCI_IR_ATTRSTRIDE_H__ diff --git a/compiler/luci/lang/include/luci/IR/CircleDialect.h b/compiler/luci/lang/include/luci/IR/CircleDialect.h new file mode 100644 index 000000000..1b25dc9c2 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/CircleDialect.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLEDIALECT_H__ +#define __LUCI_IR_CIRCLEDIALECT_H__ + +#include <loco/IR/Dialect.h> + +namespace luci +{ + +/** + * @brief A singleton for Circle Dialect + */ +class CircleDialect final : public loco::Dialect +{ +private: + CircleDialect(); + +public: + CircleDialect(const CircleDialect &) = delete; + CircleDialect(CircleDialect &&) = delete; + +public: + static loco::Dialect *get(void); +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLEDIALECT_H__ diff --git a/compiler/luci/lang/include/luci/IR/CircleNode.h b/compiler/luci/lang/include/luci/IR/CircleNode.h new file mode 100644 index 000000000..92816ef04 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/CircleNode.h @@ -0,0 +1,23 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLENODE_H__ +#define __LUCI_IR_CIRCLENODE_H__ + +#include "CircleNodeDecl.h" +#include "CircleNodeImpl.h" + +#endif // __LUCI_IR_CIRCLENODE_H__ diff --git a/compiler/luci/lang/include/luci/IR/CircleNodeDecl.h b/compiler/luci/lang/include/luci/IR/CircleNodeDecl.h new file mode 100644 index 000000000..e6410d154 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/CircleNodeDecl.h @@ -0,0 +1,93 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLENODEDECL_H__ +#define __LUCI_IR_CIRCLENODEDECL_H__ + +#include <loco/IR/Dialect.h> +#include <loco/IR/Node.h> +#include <loco/IR/NodeMixins.h> +#include <luci/IR/CircleShapeSignature.h> +#include <luci/IR/PropertyShapeStatus.h> + +#include "CircleOpcode.h" +#include "CircleNodeVisitor.forward.h" +#include "CircleQuantParam.h" +#include "SparsityParam.h" + +#include <memory> + +namespace luci +{ + +using NodeName = std::string; + +struct CircleNode : public loco::Node, + public loco::NodeMixin<loco::NodeTrait::DataType>, + public loco::NodeMixin<loco::NodeTrait::TensorShape> +{ + virtual ~CircleNode() = default; + + const loco::Dialect *dialect(void) const final; + virtual CircleOpcode opcode(void) const = 0; + + template <typename T> T accept(CircleNodeVisitorBase<T> *) const; + template <typename T> T accept(CircleNodeMutableVisitorBase<T> *); + + NodeName name(void) const { return _name; } + void name(const NodeName &name) { _name = name; } + + CircleQuantParam *quantparam(void) const { return _quantparam.get(); } + void quantparam(std::unique_ptr<CircleQuantParam> &&quantparam) + { + _quantparam = std::move(quantparam); + } + + SparsityParam *sparsityparam(void) const { return _sparsityparam.get(); } + void sparsityparam(std::unique_ptr<SparsityParam> &&sparsityparam) + { + _sparsityparam = std::move(sparsityparam); + } + + const ShapeSignature &shape_signature(void) const { return _shape_signature; } + void shape_signature(const ShapeSignature &ss) { _shape_signature = ss; } + + ShapeStatus shape_status(void) const { return _shape_status; } + void shape_status(ShapeStatus ss) { _shape_status = ss; } + + int32_t op_version(void) const { return _op_version; } + void op_version(int32_t op_version) { _op_version = op_version; } + +private: + NodeName _name; + std::unique_ptr<CircleQuantParam> _quantparam; + std::unique_ptr<SparsityParam> _sparsityparam; + ShapeSignature _shape_signature; + ShapeStatus _shape_status{ShapeStatus::UNDEFINED}; + int32_t _op_version = 1; +}; + +template <CircleOpcode Code> struct CircleNodeImpl : public CircleNode +{ + virtual ~CircleNodeImpl() = default; + + uint32_t opnum(void) const final { return static_cast<uint32_t>(Code); } + CircleOpcode opcode(void) const final { return Code; } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLENODEDECL_H__ diff --git a/compiler/luci/lang/include/luci/IR/CircleNodeImpl.h b/compiler/luci/lang/include/luci/IR/CircleNodeImpl.h new file mode 100644 index 000000000..a6b9488db --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/CircleNodeImpl.h @@ -0,0 +1,69 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLENODEIMPL_H__ +#define __LUCI_IR_CIRCLENODEIMPL_H__ + +#include "CircleNodes.h" + +#include <oops/InternalExn.h> + +#include <cassert> + +namespace luci +{ + +template <typename T> T CircleNode::accept(CircleNodeVisitorBase<T> *v) const +{ + switch (this->opcode()) + { +#define CIRCLE_NODE(OPCODE, CLASS) \ + \ + case CircleOpcode::OPCODE: \ + return v->visit(dynamic_cast<const CLASS *>(this)); + +#include "CircleNodes.lst" +#undef CIRCLE_NODE + + default: + break; + } + + INTERNAL_EXN("CircleNode::accept(CircleNodeVisitorBase) not handled"); +} + +template <typename T> T CircleNode::accept(CircleNodeMutableVisitorBase<T> *v) +{ + switch (this->opcode()) + { +#define CIRCLE_NODE(OPCODE, CLASS) \ + \ + case CircleOpcode::OPCODE: \ + return v->visit(dynamic_cast<CLASS *>(this)); + +#include "CircleNodes.lst" +#undef CIRCLE_NODE + + default: + break; + } + + INTERNAL_EXN("CircleNode::accept(CircleNodeMutableVisitorBase) not handled"); +} + +} // namespace luci + +#endif // __LUCI_IR_CIRCLENODEIMPL_H__ diff --git a/compiler/luci/lang/include/luci/IR/CircleNodeVisitor.forward.h b/compiler/luci/lang/include/luci/IR/CircleNodeVisitor.forward.h new file mode 100644 index 000000000..70901ca87 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/CircleNodeVisitor.forward.h @@ -0,0 +1,30 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLENODE_VISITOR_FORWARD_H__ +#define __LUCI_IR_CIRCLENODE_VISITOR_FORWARD_H__ + +namespace luci +{ + +// NOTE These forward declarations SHOULD BE aligned with Node delcarations in +// "CircleNodeVisitor.h" +template <typename T> struct CircleNodeVisitorBase; +template <typename T> struct CircleNodeMutableVisitorBase; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLENODE_VISITOR_FORWARD_H__ diff --git a/compiler/luci/lang/include/luci/IR/CircleNodeVisitor.h b/compiler/luci/lang/include/luci/IR/CircleNodeVisitor.h new file mode 100644 index 000000000..43339fe84 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/CircleNodeVisitor.h @@ -0,0 +1,87 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLENODE_VISITOR_H__ +#define __LUCI_IR_CIRCLENODE_VISITOR_H__ + +#include "CircleNode.h" +#include "CircleNodes.h" + +#include <oops/InternalExn.h> + +namespace luci +{ + +/** + * DO NOT use this class. Use CircleNodeVisitor instead. + */ +template <typename T> struct CircleNodeVisitorBase +{ + virtual ~CircleNodeVisitorBase() = default; + +#define CIRCLE_NODE(OPCODE, CIRCLE_CLASS) virtual T visit(const CIRCLE_CLASS *) = 0; + +#include "CircleNodes.lst" +#undef CIRCLE_NODE +}; + +template <typename T> struct CircleNodeVisitor : public CircleNodeVisitorBase<T> +{ + virtual ~CircleNodeVisitor() = default; + +#define CIRCLE_NODE(OPCODE, CIRCLE_CLASS) \ + virtual T visit(const CIRCLE_CLASS *node) { return visit(static_cast<const CircleNode *>(node)); } + +#include "CircleNodes.lst" + +#undef CIRCLE_NODE + + /// @brief Default fallback + virtual T visit(const CircleNode *) { INTERNAL_EXN("CircleNodeVisitor: NYI node"); } +}; + +/** + * DO NOT use this class. Use CircleNodeMutableVisitor instead. + */ +template <typename T> struct CircleNodeMutableVisitorBase +{ + virtual ~CircleNodeMutableVisitorBase() = default; + +#define CIRCLE_NODE(OPCODE, CIRCLE_CLASS) virtual T visit(CIRCLE_CLASS *) = 0; + +#include "CircleNodes.lst" + +#undef CIRCLE_NODE +}; + +template <typename T> struct CircleNodeMutableVisitor : public CircleNodeMutableVisitorBase<T> +{ + virtual ~CircleNodeMutableVisitor() = default; + +#define CIRCLE_NODE(OPCODE, CIRCLE_CLASS) \ + virtual T visit(CIRCLE_CLASS *node) { return visit(static_cast<CircleNode *>(node)); } + +#include "CircleNodes.lst" + +#undef CIRCLE_NODE + + /// @brief Default fallback + virtual T visit(CircleNode *) { INTERNAL_EXN("CircleNodeMutableVisitor: NYI node"); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CircleNode_VISITOR_H__ diff --git a/compiler/luci/lang/include/luci/IR/CircleNodes.h b/compiler/luci/lang/include/luci/IR/CircleNodes.h new file mode 100644 index 000000000..fde0b612b --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/CircleNodes.h @@ -0,0 +1,176 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLENODES_H__ +#define __LUCI_IR_CIRCLENODES_H__ + +#include "Nodes/CircleAbs.h" +#include "Nodes/CircleAdd.h" +#include "Nodes/CircleAddN.h" +#include "Nodes/CircleArgMax.h" +#include "Nodes/CircleArgMin.h" +#include "Nodes/CircleAveragePool2D.h" +#include "Nodes/CircleBatchMatMul.h" +#include "Nodes/CircleBatchToSpaceND.h" +#include "Nodes/CircleCast.h" +#include "Nodes/CircleCeil.h" +#include "Nodes/CircleConcatenation.h" +#include "Nodes/CircleConst.h" +#include "Nodes/CircleConv2D.h" +#include "Nodes/CircleCos.h" +#include "Nodes/CircleCustom.h" +#include "Nodes/CircleDepthToSpace.h" +#include "Nodes/CircleDepthwiseConv2D.h" +#include "Nodes/CircleDequantize.h" +#include "Nodes/CircleDiv.h" +#include "Nodes/CircleElu.h" +#include "Nodes/CircleEqual.h" +#include "Nodes/CircleExp.h" +#include "Nodes/CircleExpandDims.h" +#include "Nodes/CircleFill.h" +#include "Nodes/CircleFloor.h" +#include "Nodes/CircleFloorDiv.h" +#include "Nodes/CircleFloorMod.h" +#include "Nodes/CircleFullyConnected.h" +#include "Nodes/CircleGather.h" +#include "Nodes/CircleGatherNd.h" +#include "Nodes/CircleGreater.h" +#include "Nodes/CircleGreaterEqual.h" +#include "Nodes/CircleIf.h" +#include "Nodes/CircleL2Normalize.h" +#include "Nodes/CircleL2Pool2D.h" +#include "Nodes/CircleLeakyRelu.h" +#include "Nodes/CircleLess.h" +#include "Nodes/CircleLessEqual.h" +#include "Nodes/CircleLocalResponseNormalization.h" +#include "Nodes/CircleLog.h" +#include "Nodes/CircleLogicalAnd.h" +#include "Nodes/CircleLogicalNot.h" +#include "Nodes/CircleLogicalOr.h" +#include "Nodes/CircleLogistic.h" +#include "Nodes/CircleLogSoftmax.h" +#include "Nodes/CircleMatrixDiag.h" +#include "Nodes/CircleMatrixSetDiag.h" +#include "Nodes/CircleMaximum.h" +#include "Nodes/CircleMaxPool2D.h" +#include "Nodes/CircleMean.h" +#include "Nodes/CircleMinimum.h" +#include "Nodes/CircleMirrorPad.h" +#include "Nodes/CircleMul.h" +#include "Nodes/CircleNeg.h" +#include "Nodes/CircleNonMaxSuppressionV4.h" +#include "Nodes/CircleNonMaxSuppressionV5.h" +#include "Nodes/CircleNotEqual.h" +#include "Nodes/CircleOneHot.h" +#include "Nodes/CirclePack.h" +#include "Nodes/CirclePad.h" +#include "Nodes/CirclePadV2.h" +#include "Nodes/CirclePow.h" +#include "Nodes/CirclePRelu.h" +#include "Nodes/CircleRange.h" +#include "Nodes/CircleRank.h" +#include "Nodes/CircleReduceAny.h" +#include "Nodes/CircleReduceMax.h" +#include "Nodes/CircleReduceMin.h" +#include "Nodes/CircleReduceProd.h" +#include "Nodes/CircleRelu.h" +#include "Nodes/CircleRelu6.h" +#include "Nodes/CircleReluN1To1.h" +#include "Nodes/CircleReshape.h" +#include "Nodes/CircleResizeBilinear.h" +#include "Nodes/CircleResizeNearestNeighbor.h" +#include "Nodes/CircleReverseSequence.h" +#include "Nodes/CircleReverseV2.h" +#include "Nodes/CircleRound.h" +#include "Nodes/CircleRsqrt.h" +#include "Nodes/CircleScatterNd.h" +#include "Nodes/CircleSegmentSum.h" +#include "Nodes/CircleSelect.h" +#include "Nodes/CircleSelectV2.h" +#include "Nodes/CircleShape.h" +#include "Nodes/CircleSin.h" +#include "Nodes/CircleSlice.h" +#include "Nodes/CircleSoftmax.h" +#include "Nodes/CircleSpaceToBatchND.h" +#include "Nodes/CircleSpaceToDepth.h" +#include "Nodes/CircleSparseToDense.h" +#include "Nodes/CircleSplit.h" +#include "Nodes/CircleSplitV.h" +#include "Nodes/CircleSqrt.h" +#include "Nodes/CircleSquare.h" +#include "Nodes/CircleSquaredDifference.h" +#include "Nodes/CircleSqueeze.h" +#include "Nodes/CircleStridedSlice.h" +#include "Nodes/CircleSub.h" +#include "Nodes/CircleSum.h" +#include "Nodes/CircleTanh.h" +#include "Nodes/CircleTile.h" +#include "Nodes/CircleTopKV2.h" +#include "Nodes/CircleTranspose.h" +#include "Nodes/CircleTransposeConv.h" +#include "Nodes/CircleUnidirectionalSequenceLSTM.h" +#include "Nodes/CircleUnique.h" +#include "Nodes/CircleUnpack.h" +#include "Nodes/CircleWhere.h" +#include "Nodes/CircleWhile.h" +#include "Nodes/CircleZerosLike.h" +// Circle only +#include "Nodes/CircleBCQFullyConnected.h" +#include "Nodes/CircleBCQGather.h" +#include "Nodes/CircleInstanceNorm.h" +// Virtual nodes +#include "Nodes/CircleInput.h" +#include "Nodes/CircleOutput.h" +#include "Nodes/CircleCustomOut.h" +#include "Nodes/CircleIfOut.h" +#include "Nodes/CircleNonMaxSuppressionV4Out.h" +#include "Nodes/CircleNonMaxSuppressionV5Out.h" +#include "Nodes/CircleUnpackOut.h" +#include "Nodes/CircleUniqueOut.h" +#include "Nodes/CircleSplitOut.h" +#include "Nodes/CircleSplitVOut.h" +#include "Nodes/CircleTopKV2Out.h" +#include "Nodes/CircleWhileOut.h" + +#include <loco/IR/Graph.h> + +namespace luci +{ + +/** + * @brief Set both CircleReshape's 2nd input as CircleConst, and newShape attribute + * with same value + * @note Shape inference for TFLReshape forces them to be same + * + * TODO find better place for this helper + */ +void set_new_shape(CircleReshape *node, int32_t *base, uint32_t size); + +/// @brief Link GraphOutput with CircleOutput node +void link(loco::GraphOutput *, CircleOutput *); + +/// @brief Link GraphInput with CircleInput node +void link(loco::GraphInput *, CircleInput *); + +/// @brief Find a CircleOutput node with a given output index +CircleOutput *output_node(loco::Graph *g, const loco::GraphOutputIndex &index); + +/// @brief Find a Pull node with a given input index +CircleInput *input_node(loco::Graph *g, const loco::GraphInputIndex &index); + +} // namespace luci + +#endif // __LUCI_IR_CIRCLENODES_H__ diff --git a/compiler/luci/lang/include/luci/IR/CircleNodes.lst b/compiler/luci/lang/include/luci/IR/CircleNodes.lst new file mode 100644 index 000000000..b9d545893 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/CircleNodes.lst @@ -0,0 +1,142 @@ +#ifndef CIRCLE_NODE +#error "Define CIRCLE_NODE" +#endif // CIRCLE_NODE + +// +// PLEASE SORT NODE DECLS IN ALPHABETICAL ORDER +// +// Naming rule: Follow names in TensorFlow C++ source; same as TFDialect +// ex) for AvgPool, tensorflow/core/ops/nn_ops.cc +// REGISTER_OP("AvgPool") <-- OPCODE: AvgPool. Prefix `Circle` for CLASS name +// .Input("value: T") <-- Input name is 'value' +// + +CIRCLE_NODE(ABS, luci::CircleAbs) +CIRCLE_NODE(ADD, luci::CircleAdd) +CIRCLE_NODE(ADD_N, luci::CircleAddN) +CIRCLE_NODE(ARG_MAX, luci::CircleArgMax) +CIRCLE_NODE(ARG_MIN, luci::CircleArgMin) +CIRCLE_NODE(AVERAGE_POOL_2D, luci::CircleAveragePool2D) +CIRCLE_NODE(BATCH_TO_SPACE_ND, luci::CircleBatchToSpaceND) +CIRCLE_NODE(BATCHMATMUL, luci::CircleBatchMatMul) +CIRCLE_NODE(CAST, luci::CircleCast) +CIRCLE_NODE(CEIL, luci::CircleCeil) +CIRCLE_NODE(CONCATENATION, luci::CircleConcatenation) +CIRCLE_NODE(CONV_2D, luci::CircleConv2D) +CIRCLE_NODE(COS, luci::CircleCos) +CIRCLE_NODE(CUSTOM, luci::CircleCustom) +CIRCLE_NODE(DEPTH_TO_SPACE, luci::CircleDepthToSpace) +CIRCLE_NODE(DEPTHWISE_CONV_2D, luci::CircleDepthwiseConv2D) +CIRCLE_NODE(DEQUANTIZE, luci::CircleDequantize) +CIRCLE_NODE(DIV, luci::CircleDiv) +CIRCLE_NODE(ELU, luci::CircleElu) +CIRCLE_NODE(EQUAL, luci::CircleEqual) +CIRCLE_NODE(EXP, luci::CircleExp) +CIRCLE_NODE(EXPAND_DIMS, luci::CircleExpandDims) +CIRCLE_NODE(FILL, luci::CircleFill) +CIRCLE_NODE(FLOOR, luci::CircleFloor) +CIRCLE_NODE(FLOOR_DIV, luci::CircleFloorDiv) +CIRCLE_NODE(FLOOR_MOD, luci::CircleFloorMod) +CIRCLE_NODE(FULLY_CONNECTED, luci::CircleFullyConnected) +CIRCLE_NODE(GATHER, luci::CircleGather) +CIRCLE_NODE(GATHER_ND, luci::CircleGatherNd) +CIRCLE_NODE(GREATER, luci::CircleGreater) +CIRCLE_NODE(GREATER_EQUAL, luci::CircleGreaterEqual) +CIRCLE_NODE(IF, luci::CircleIf) +CIRCLE_NODE(L2_NORMALIZATION, luci::CircleL2Normalize) +CIRCLE_NODE(L2_POOL_2D, luci::CircleL2Pool2D) +CIRCLE_NODE(LEAKY_RELU, luci::CircleLeakyRelu) +CIRCLE_NODE(LESS, luci::CircleLess) +CIRCLE_NODE(LESS_EQUAL, luci::CircleLessEqual) +CIRCLE_NODE(LOCAL_RESPONSE_NORMALIZATION, luci::CircleLocalResponseNormalization) +CIRCLE_NODE(LOG, luci::CircleLog) +CIRCLE_NODE(LOGICAL_AND, luci::CircleLogicalAnd) +CIRCLE_NODE(LOGICAL_NOT, luci::CircleLogicalNot) +CIRCLE_NODE(LOGICAL_OR, luci::CircleLogicalOr) +CIRCLE_NODE(LOGISTIC, luci::CircleLogistic) +CIRCLE_NODE(LOG_SOFTMAX, luci::CircleLogSoftmax) +CIRCLE_NODE(MATRIX_DIAG, luci::CircleMatrixDiag) +CIRCLE_NODE(MAX_POOL_2D, luci::CircleMaxPool2D) +CIRCLE_NODE(MATRIX_SET_DIAG, luci::CircleMatrixSetDiag) +CIRCLE_NODE(MAXIMUM, luci::CircleMaximum) +CIRCLE_NODE(MEAN, luci::CircleMean) +CIRCLE_NODE(MINIMUM, luci::CircleMinimum) +CIRCLE_NODE(MIRROR_PAD, luci::CircleMirrorPad) +CIRCLE_NODE(MUL, luci::CircleMul) +CIRCLE_NODE(NEG, luci::CircleNeg) +CIRCLE_NODE(NON_MAX_SUPPRESSION_V4, luci::CircleNonMaxSuppressionV4) +CIRCLE_NODE(NON_MAX_SUPPRESSION_V5, luci::CircleNonMaxSuppressionV5) +CIRCLE_NODE(NOT_EQUAL, luci::CircleNotEqual) +CIRCLE_NODE(ONE_HOT, luci::CircleOneHot) +CIRCLE_NODE(PACK, luci::CirclePack) +CIRCLE_NODE(PAD, luci::CirclePad) +CIRCLE_NODE(PADV2, luci::CirclePadV2) +CIRCLE_NODE(POW, luci::CirclePow) +CIRCLE_NODE(PRELU, luci::CirclePRelu) +CIRCLE_NODE(RANGE, luci::CircleRange) +CIRCLE_NODE(RANK, luci::CircleRank) +CIRCLE_NODE(REDUCE_ANY, luci::CircleReduceAny) +CIRCLE_NODE(REDUCE_MAX, luci::CircleReduceMax) +CIRCLE_NODE(REDUCE_MIN, luci::CircleReduceMin) +CIRCLE_NODE(REDUCE_PROD, luci::CircleReduceProd) +CIRCLE_NODE(RELU, luci::CircleRelu) +CIRCLE_NODE(RELU6, luci::CircleRelu6) +CIRCLE_NODE(RELU_N1_TO_1, luci::CircleReluN1To1) +CIRCLE_NODE(RESHAPE, luci::CircleReshape) +CIRCLE_NODE(RESIZE_BILINEAR, luci::CircleResizeBilinear) +CIRCLE_NODE(RESIZE_NEAREST_NEIGHBOR, luci::CircleResizeNearestNeighbor) +CIRCLE_NODE(REVERSE_SEQUENCE, luci::CircleReverseSequence) +CIRCLE_NODE(REVERSE_V2, luci::CircleReverseV2) +CIRCLE_NODE(ROUND, luci::CircleRound) +CIRCLE_NODE(RSQRT, luci::CircleRsqrt) +CIRCLE_NODE(SCATTER_ND, luci::CircleScatterNd) +CIRCLE_NODE(SEGMENT_SUM, luci::CircleSegmentSum) +CIRCLE_NODE(SELECT, luci::CircleSelect) +CIRCLE_NODE(SELECT_V2, luci::CircleSelectV2) +CIRCLE_NODE(SHAPE, luci::CircleShape) +CIRCLE_NODE(SIN, luci::CircleSin) +CIRCLE_NODE(SLICE, luci::CircleSlice) +CIRCLE_NODE(SOFTMAX, luci::CircleSoftmax) +CIRCLE_NODE(SPACE_TO_BATCH_ND, luci::CircleSpaceToBatchND) +CIRCLE_NODE(SPACE_TO_DEPTH, luci::CircleSpaceToDepth) +CIRCLE_NODE(SPARSE_TO_DENSE, luci::CircleSparseToDense) +CIRCLE_NODE(SPLIT, luci::CircleSplit) +CIRCLE_NODE(SPLIT_V, luci::CircleSplitV) +CIRCLE_NODE(SQRT, luci::CircleSqrt) +CIRCLE_NODE(SQUARE, luci::CircleSquare) +CIRCLE_NODE(SQUARED_DIFFERENCE, luci::CircleSquaredDifference) +CIRCLE_NODE(SQUEEZE, luci::CircleSqueeze) +CIRCLE_NODE(STRIDED_SLICE, luci::CircleStridedSlice) +CIRCLE_NODE(SUB, luci::CircleSub) +CIRCLE_NODE(SUM, luci::CircleSum) +CIRCLE_NODE(TANH, luci::CircleTanh) +CIRCLE_NODE(TILE, luci::CircleTile) +CIRCLE_NODE(TOPK_V2, luci::CircleTopKV2) +CIRCLE_NODE(TRANSPOSE, luci::CircleTranspose) +CIRCLE_NODE(TRANSPOSE_CONV, luci::CircleTransposeConv) +CIRCLE_NODE(UNIDIRECTIONAL_SEQUENCE_LSTM, luci::CircleUnidirectionalSequenceLSTM) +CIRCLE_NODE(UNIQUE, luci::CircleUnique) +CIRCLE_NODE(UNPACK, luci::CircleUnpack) +CIRCLE_NODE(WHERE, luci::CircleWhere) +CIRCLE_NODE(WHILE, luci::CircleWhile) +CIRCLE_NODE(ZEROS_LIKE, luci::CircleZerosLike) +// Circle Only +CIRCLE_NODE(BCQ_FULLY_CONNECTED, luci::CircleBCQFullyConnected) +CIRCLE_NODE(BCQ_GATHER, luci::CircleBCQGather) +CIRCLE_NODE(INSTANCE_NORM, luci::CircleInstanceNorm) +// Virtual node(s) +CIRCLE_NODE(CIRCLECONST, luci::CircleConst) +CIRCLE_NODE(CIRCLEINPUT, luci::CircleInput) +CIRCLE_NODE(CIRCLEOUTPUT, luci::CircleOutput) +CIRCLE_NODE(CIRCLEOUTPUTDUMMY, luci::CircleOutputDummy) +CIRCLE_NODE(CIRCLEOUTPUTEXCLUDE, luci::CircleOutputExclude) +CIRCLE_NODE(CIRCLECUSTOMOUT, luci::CircleCustomOut) +CIRCLE_NODE(CIRCLEIFOUT, luci::CircleIfOut) +CIRCLE_NODE(CIRCLENONMAXSUPPRESSIONV4OUT, luci::CircleNonMaxSuppressionV4Out) +CIRCLE_NODE(CIRCLENONMAXSUPPRESSIONV5OUT, luci::CircleNonMaxSuppressionV5Out) +CIRCLE_NODE(CIRCLESPLITOUT, luci::CircleSplitOut) +CIRCLE_NODE(CIRCLESPLITVOUT, luci::CircleSplitVOut) +CIRCLE_NODE(CIRCLETOPKV2OUT, luci::CircleTopKV2Out) +CIRCLE_NODE(CIRCLEUNIQUEOUT, luci::CircleUniqueOut) +CIRCLE_NODE(CIRCLEUNPACKOUT, luci::CircleUnpackOut) +CIRCLE_NODE(CIRCLEWHILEOUT, luci::CircleWhileOut) diff --git a/compiler/luci/lang/include/luci/IR/CircleOpcode.h b/compiler/luci/lang/include/luci/IR/CircleOpcode.h new file mode 100644 index 000000000..703b70da2 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/CircleOpcode.h @@ -0,0 +1,32 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLEOPCODE_H__ +#define __LUCI_IR_CIRCLEOPCODE_H__ + +namespace luci +{ + +enum class CircleOpcode +{ +#define CIRCLE_NODE(OPCODE, CLASS) OPCODE, +#include "CircleNodes.lst" +#undef CIRCLE_NODE +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLEOPCODE_H__ diff --git a/compiler/luci/lang/include/luci/IR/CircleQuantParam.h b/compiler/luci/lang/include/luci/IR/CircleQuantParam.h new file mode 100644 index 000000000..694437303 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/CircleQuantParam.h @@ -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. + */ + +#ifndef __LUCI_IR_CIRCLEQUANTPARAM_H__ +#define __LUCI_IR_CIRCLEQUANTPARAM_H__ + +#include <cstdint> +#include <vector> + +namespace luci +{ + +struct CircleQuantParam +{ + std::vector<float> min; + std::vector<float> max; + std::vector<float> scale; + std::vector<int64_t> zerop; + int32_t quantized_dimension{0}; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLEQUANTPARAM_H__ diff --git a/compiler/luci/lang/include/luci/IR/CircleShapeSignature.h b/compiler/luci/lang/include/luci/IR/CircleShapeSignature.h new file mode 100644 index 000000000..970f1b521 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/CircleShapeSignature.h @@ -0,0 +1,51 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_SHAPE_SIGNATURE_H__ +#define __LUCI_IR_SHAPE_SIGNATURE_H__ + +#include <stdint.h> +#include <vector> + +namespace luci +{ + +class ShapeSignature +{ +public: + ShapeSignature() = default; + + ShapeSignature(const std::vector<int32_t> &shape_signature) + { + _shape_signature = shape_signature; + } + +public: + const std::vector<int32_t> &as_vector() const { return _shape_signature; } + + int32_t dim(uint32_t d) const { return _shape_signature.at(d); } + int32_t &dim(uint32_t d) { return _shape_signature.at(d); } + + uint32_t rank(void) const { return _shape_signature.size(); } + void rank(uint32_t rank) { _shape_signature.resize(rank); } + +private: + std::vector<int32_t> _shape_signature{}; +}; + +} // namespace luci + +#endif // __LUCI_IR_SHAPE_SIGNATURE_H__ diff --git a/compiler/luci/lang/include/luci/IR/LuciNodeMixins.h b/compiler/luci/lang/include/luci/IR/LuciNodeMixins.h new file mode 100644 index 000000000..c1bb0db11 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/LuciNodeMixins.h @@ -0,0 +1,107 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_LUCINODEMIXINS_H__ +#define __LUCI_IR_LUCINODEMIXINS_H__ + +#include "luci/IR/AttrFusedActFunc.h" + +#include <loco/IR/Node.h> +#include <loco/IR/NodeMixins.h> + +#include <vector> + +namespace luci +{ + +/// @brief enumeration of mixin class +enum class LuciNodeTrait +{ + FusedActFunc, + Bias +}; + +template <LuciNodeTrait T> class LuciNodeMixin; + +template <> class LuciNodeMixin<LuciNodeTrait::FusedActFunc> +{ +public: + LuciNodeMixin() = default; + +public: + FusedActFunc fusedActivationFunction() const { return _fused_act_fun; } + void fusedActivationFunction(FusedActFunc fused_act_fun) { _fused_act_fun = fused_act_fun; } + +private: + FusedActFunc _fused_act_fun = FusedActFunc::UNDEFINED; +}; + +/** + * @brief Mixin class for nodes that has a bias input + */ +template <> class LuciNodeMixin<LuciNodeTrait::Bias> +{ +public: + LuciNodeMixin() = default; + +public: + virtual loco::Node *bias(void) const = 0; /// @brief get the input for bias. + virtual void bias(loco::Node *node) = 0; /// @brief set the input for bias. +}; + +/** + * @brief Nodes with the fixed number of inputs + * + * TODO Deprecated this class, and use loco::FixedArity instead + */ +template <unsigned N, typename Base> class FixedArityNode : public Base +{ +public: + FixedArityNode() + { + _args.resize(N); + for (uint32_t n = 0; n < N; ++n) + { + _args[n] = std::make_unique<loco::Use>(this); + } + } + + virtual ~FixedArityNode() = default; + +public: + unsigned arity(void) const final { return N; } + + loco::Node *arg(uint32_t n) const final { return _args.at(n)->node(); } + + void drop(void) final + { + for (uint32_t n = 0; n < N; ++n) + { + _args.at(n)->node(nullptr); + } + } + +protected: + // This API allows inherited classes to access "_args" field. + loco::Use *at(unsigned n) const { return _args.at(n).get(); } + +private: + std::vector<std::unique_ptr<loco::Use>> _args{}; +}; + +} // namespace luci + +#endif // __LUCI_IR_LUCINODEMIXINS_H__ diff --git a/compiler/luci/lang/include/luci/IR/Module.h b/compiler/luci/lang/include/luci/IR/Module.h new file mode 100644 index 000000000..30eac59ce --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Module.h @@ -0,0 +1,70 @@ +/* + * 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. + */ + +#ifndef __LUCI_MODULE_H__ +#define __LUCI_MODULE_H__ + +#include <loco/IR/Graph.h> + +#include <memory> +#include <vector> + +namespace luci +{ + +/** + * @brief Collection of 'loco::Graph's + */ +class Module final +{ +public: + Module() = default; + + // Copy/Move is not allowed for Module + Module(const Module &) = delete; + Module(Module &&) = delete; + + ~Module() = default; + +public: + size_t size(void) const { return _graphs.size(); } + +public: + void add(std::unique_ptr<loco::Graph> &&g); + + /** + * @brief provide main graph + */ + loco::Graph *graph(void) const; + + /** + * @brief provide graph with an index + * + * @note graph(0) is interpreted as a main graph + */ + loco::Graph *graph(size_t idx) const; + + // TODO provide graph accessor with a name + +private: + std::vector<std::unique_ptr<loco::Graph>> _graphs; +}; + +std::unique_ptr<Module> make_module(void); + +} // namespace luci + +#endif // __LUCI_MODULE_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleAbs.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleAbs.h new file mode 100644 index 000000000..45dba15bf --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleAbs.h @@ -0,0 +1,40 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCELABS_H__ +#define __LUCI_IR_CIRCELABS_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief ABS in Circle + */ +class CircleAbs final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::ABS>> +{ +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCELABS_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleAdd.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleAdd.h new file mode 100644 index 000000000..f26eccd1a --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleAdd.h @@ -0,0 +1,45 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCELADD_H__ +#define __LUCI_IR_CIRCELADD_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/AttrFusedActFunc.h" +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief ADD in Circle + */ +class CircleAdd final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::ADD>>, + public LuciNodeMixin<LuciNodeTrait::FusedActFunc> +{ +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } + + loco::Node *y(void) const { return at(1)->node(); } + void y(loco::Node *node) { at(1)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCELADD_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleAddN.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleAddN.h new file mode 100644 index 000000000..6ba4a96bc --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleAddN.h @@ -0,0 +1,46 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCEL_ADD_N_H__ +#define __LUCI_IR_CIRCEL_ADD_N_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/VariadicArityNode.h" + +namespace luci +{ + +/** + * @brief ADD_N in Circle + */ +class CircleAddN final : public VariadicArityNode<CircleNodeImpl<CircleOpcode::ADD_N>> +{ +public: + CircleAddN(uint32_t arity) : VariadicArityNode<CircleNodeImpl<CircleOpcode::ADD_N>>(arity) + { + assert(arity >= 1); + } + +public: + Node *inputs(uint32_t index) const { return at(index)->node(); } + void inputs(uint32_t index, Node *node) { at(index)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCEL_ADD_N_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleArgMax.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleArgMax.h new file mode 100644 index 000000000..dbc4b2b3a --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleArgMax.h @@ -0,0 +1,50 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCELARGMAX_H__ +#define __LUCI_IR_CIRCELARGMAX_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief ARG_MAX in Circle + */ +class CircleArgMax final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::ARG_MAX>> +{ +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + + loco::Node *dimension(void) const { return at(1)->node(); } + void dimension(loco::Node *node) { at(1)->node(node); } + +public: + loco::DataType output_type(void) const { return _output_type; } + void output_type(loco::DataType ot) { _output_type = ot; } + +private: + loco::DataType _output_type{loco::DataType::S64}; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCELARGMAX_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleArgMin.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleArgMin.h new file mode 100644 index 000000000..8cb561983 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleArgMin.h @@ -0,0 +1,50 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCELARGMIN_H__ +#define __LUCI_IR_CIRCELARGMIN_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief ARG_Min in Circle + */ +class CircleArgMin final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::ARG_MIN>> +{ +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + + loco::Node *dimension(void) const { return at(1)->node(); } + void dimension(loco::Node *node) { at(1)->node(node); } + +public: + loco::DataType output_type(void) const { return _output_type; } + void output_type(loco::DataType ot) { _output_type = ot; } + +private: + loco::DataType _output_type{loco::DataType::S64}; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCELARGMIN_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleAveragePool2D.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleAveragePool2D.h new file mode 100644 index 000000000..0b43b40c8 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleAveragePool2D.h @@ -0,0 +1,63 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLEAVERAGEPOOL2D_H__ +#define __LUCI_IR_CIRCLEAVERAGEPOOL2D_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/AttrFilter.h" +#include "luci/IR/AttrPadding.h" +#include "luci/IR/AttrStride.h" +#include "luci/IR/AttrFusedActFunc.h" +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief AVERAGE_POOL_2D in Circle + */ +class CircleAveragePool2D final + : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::AVERAGE_POOL_2D>>, + public LuciNodeMixin<LuciNodeTrait::FusedActFunc> +{ +public: + CircleAveragePool2D() : _padding(Padding::UNDEFINED) { /* empty */} + +public: + loco::Node *value(void) const { return at(0)->node(); } + void value(loco::Node *node) { at(0)->node(node); } + + Padding padding() const { return _padding; } + void padding(Padding padding) { _padding = padding; } + + const Filter *filter(void) const { return &_filter; } + Filter *filter(void) { return &_filter; } + + const Stride *stride(void) const { return &_stride; } + Stride *stride(void) { return &_stride; } + +private: + Padding _padding; + Stride _stride; + Filter _filter; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLEAVERAGEPOOL2D_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleBCQFullyConnected.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleBCQFullyConnected.h new file mode 100644 index 000000000..7d12d593a --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleBCQFullyConnected.h @@ -0,0 +1,66 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLEBCQFULLYCONNECTED_H__ +#define __LUCI_IR_CIRCLEBCQFULLYCONNECTED_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/AttrFusedActFunc.h" +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief BCQ_FULLY_CONNECTED in Circle + */ +class CircleBCQFullyConnected final + : public FixedArityNode<5, CircleNodeImpl<CircleOpcode::BCQ_FULLY_CONNECTED>>, + public LuciNodeMixin<LuciNodeTrait::FusedActFunc>, + public LuciNodeMixin<LuciNodeTrait::Bias> +{ +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + + loco::Node *weights_scales(void) const { return at(1)->node(); } + void weights_scales(loco::Node *node) { at(1)->node(node); } + + loco::Node *weights_binary(void) const { return at(2)->node(); } + void weights_binary(loco::Node *node) { at(2)->node(node); } + + loco::Node *bias(void) const override { return at(3)->node(); } + void bias(loco::Node *node) override { at(3)->node(node); } + + loco::Node *weights_clusters(void) const { return at(4)->node(); } + void weights_clusters(loco::Node *node) { at(4)->node(node); } + +public: + int32_t weights_hidden_size(void) const { return _weights_hidden_size; } + void weights_hidden_size(int32_t weights_hidden_size) + { + _weights_hidden_size = weights_hidden_size; + } + +private: + int32_t _weights_hidden_size = 0; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLEBCQFULLYCONNECTED_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleBCQGather.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleBCQGather.h new file mode 100644 index 000000000..f7638261d --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleBCQGather.h @@ -0,0 +1,60 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLEBCQGATHER_H__ +#define __LUCI_IR_CIRCLEBCQGATHER_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief BCQ_GATHER in Circle + */ +class CircleBCQGather final : public FixedArityNode<4, CircleNodeImpl<CircleOpcode::BCQ_GATHER>> +{ +public: + loco::Node *input_scales(void) const { return at(0)->node(); } + void input_scales(loco::Node *node) { at(0)->node(node); } + + loco::Node *input_binary(void) const { return at(1)->node(); } + void input_binary(loco::Node *node) { at(1)->node(node); } + + loco::Node *indices(void) const { return at(2)->node(); } + void indices(loco::Node *node) { at(2)->node(node); } + + loco::Node *input_clusters(void) const { return at(3)->node(); } + void input_clusters(loco::Node *node) { at(3)->node(node); } + +public: + int32_t axis(void) const { return _axis; } + void axis(int32_t axis) { _axis = axis; } + + int32_t input_hidden_size(void) const { return _input_hidden_size; } + void input_hidden_size(int32_t input_hidden_size) { _input_hidden_size = input_hidden_size; } + +private: + int32_t _axis = 0; + int32_t _input_hidden_size = 0; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLEBCQGATHER_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleBatchMatMul.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleBatchMatMul.h new file mode 100644 index 000000000..19999924e --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleBatchMatMul.h @@ -0,0 +1,54 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCELBATCHMATMUL_H__ +#define __LUCI_IR_CIRCELBATCHMATMUL_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief BATCHMATMUL in Circle + */ +class CircleBatchMatMul final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::BATCHMATMUL>> +{ +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } + + loco::Node *y(void) const { return at(1)->node(); } + void y(loco::Node *node) { at(1)->node(node); } + +public: + bool adj_x(void) const { return _adj_x; } + void adj_x(bool arg) { _adj_x = arg; } + + bool adj_y(void) const { return _adj_y; } + void adj_y(bool arg) { _adj_y = arg; } + +private: + bool _adj_x = false; + bool _adj_y = false; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCELBATCHMATMUL_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleBatchToSpaceND.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleBatchToSpaceND.h new file mode 100644 index 000000000..67c0a2102 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleBatchToSpaceND.h @@ -0,0 +1,47 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLEBATCHTOSPACEND_H__ +#define __LUCI_IR_CIRCLEBATCHTOSPACEND_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief BATCH_TO_SPACE_ND in Circle + */ +class CircleBatchToSpaceND final + : public FixedArityNode<3, CircleNodeImpl<CircleOpcode::BATCH_TO_SPACE_ND>> +{ +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + + loco::Node *block_shape(void) const { return at(1)->node(); } + void block_shape(loco::Node *node) { at(1)->node(node); } + + loco::Node *crops(void) const { return at(2)->node(); } + void crops(loco::Node *node) { at(2)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLEBATCHTOSPACEND_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleCast.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleCast.h new file mode 100644 index 000000000..9a89d0b2b --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleCast.h @@ -0,0 +1,51 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCELECAST_H__ +#define __LUCI_IR_CIRCELECAST_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief CAST in Circle + */ +class CircleCast final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::CAST>> +{ +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } + +public: + loco::DataType in_data_type(void) const { return _in_data_type; } + void in_data_type(loco::DataType it) { _in_data_type = it; } + + loco::DataType out_data_type(void) const { return _out_data_type; } + void out_data_type(loco::DataType ot) { _out_data_type = ot; } + +private: + loco::DataType _in_data_type{loco::DataType::FLOAT32}; + loco::DataType _out_data_type{loco::DataType::FLOAT32}; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCELECAST_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleCeil.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleCeil.h new file mode 100644 index 000000000..8a8715dcf --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleCeil.h @@ -0,0 +1,40 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_CEIL_H__ +#define __LUCI_IR_CIRCLE_CEIL_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief CEIL in Circle + */ +class CircleCeil final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::CEIL>> +{ +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_CEIL_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleConcatenation.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleConcatenation.h new file mode 100644 index 000000000..dea1a4613 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleConcatenation.h @@ -0,0 +1,72 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLECONCATENATION_H__ +#define __LUCI_IR_CIRCLECONCATENATION_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/AttrFusedActFunc.h" +#include "luci/IR/LuciNodeMixins.h" +#include "luci/IR/VariadicArityNode.h" + +#include <cassert> + +namespace luci +{ + +/** + * @brief CONCATENATION in Circle + */ +class CircleConcatenation final + : public VariadicArityNode<CircleNodeImpl<CircleOpcode::CONCATENATION>>, + public LuciNodeMixin<LuciNodeTrait::FusedActFunc> +{ +public: + CircleConcatenation(uint32_t arity) + : VariadicArityNode<CircleNodeImpl<CircleOpcode::CONCATENATION>>(arity) + { + // TODO Support when arity is 0 + assert(arity >= 1); + } + +public: + uint32_t numValues(void) const { return arity(); } + +public: + Node *values(uint32_t index) const + { + assert(index < numValues()); + return at(index)->node(); + } + void values(uint32_t index, Node *node) + { + assert(index < numValues()); + at(index)->node(node); + } + +public: + int32_t axis(void) const { return _axis; } + void axis(int32_t axis) { _axis = axis; } + +private: + int32_t _axis{0}; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLECONCATENATION_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleConst.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleConst.h new file mode 100644 index 000000000..250282049 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleConst.h @@ -0,0 +1,54 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLECONST_H__ +#define __LUCI_IR_CIRCLECONST_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +#include <loco/IR/DataTypeTraits.h> + +namespace luci +{ + +/** + * @brief Class to build tensor data + * @note This will not be exported as a specific op + */ +class CircleConst final : public FixedArityNode<0, CircleNodeImpl<CircleOpcode::CIRCLECONST>> +{ +public: + CircleConst() = default; + +public: + template <loco::DataType DT> uint32_t size(void) const; + template <loco::DataType DT> void size(uint32_t size); + template <loco::DataType DT> const typename loco::DataTypeImpl<DT>::Type &at(uint32_t n) const; + template <loco::DataType DT> typename loco::DataTypeImpl<DT>::Type &at(uint32_t n); + + template <loco::DataType DT> const typename loco::DataTypeImpl<DT>::Type &scalar(void) const; + template <loco::DataType DT> typename loco::DataTypeImpl<DT>::Type &scalar(void); + +private: + std::vector<uint8_t> _data; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLECONST_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleConv2D.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleConv2D.h new file mode 100644 index 000000000..13657cee4 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleConv2D.h @@ -0,0 +1,67 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLECONV2D_H__ +#define __LUCI_IR_CIRCLECONV2D_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/AttrPadding.h" +#include "luci/IR/AttrStride.h" +#include "luci/IR/AttrDilation.h" +#include "luci/IR/AttrFusedActFunc.h" +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief CONV_2D in Circle + */ +class CircleConv2D final : public FixedArityNode<3, CircleNodeImpl<CircleOpcode::CONV_2D>>, + public LuciNodeMixin<LuciNodeTrait::FusedActFunc>, + public LuciNodeMixin<LuciNodeTrait::Bias> +{ +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + + loco::Node *filter(void) const { return at(1)->node(); } + void filter(loco::Node *node) { at(1)->node(node); } + + loco::Node *bias(void) const override { return at(2)->node(); } + void bias(loco::Node *node) override { at(2)->node(node); } + +public: + Padding padding() const { return _padding; } + void padding(Padding padding) { _padding = padding; } + + const Stride *stride(void) const { return &_stride; } + Stride *stride(void) { return &_stride; } + + const Dilation *dilation(void) const { return &_dilation; } + Dilation *dilation(void) { return &_dilation; } + +private: + Padding _padding = Padding::UNDEFINED; + Stride _stride; + Dilation _dilation; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLECONV2D_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleCos.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleCos.h new file mode 100644 index 000000000..07ced620a --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleCos.h @@ -0,0 +1,40 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_COS_H__ +#define __LUCI_IR_CIRCLE_COS_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief COS in Circle + */ +class CircleCos final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::COS>> +{ +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_COS_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleCustom.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleCustom.h new file mode 100644 index 000000000..6c722b766 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleCustom.h @@ -0,0 +1,61 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLECUSTOM_H__ +#define __LUCI_IR_CIRCLECUSTOM_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/VariadicArityNode.h" + +namespace luci +{ + +/** + * @brief CUSTOM in Circle + */ +class CircleCustom final : public VariadicArityNode<CircleNodeImpl<CircleOpcode::CUSTOM>> +{ +public: + CircleCustom(uint32_t arity) : VariadicArityNode<CircleNodeImpl<CircleOpcode::CUSTOM>>(arity) + { + // TODO Support when arity is 0 + assert(arity >= 1); + } + +public: + uint32_t numInputs(void) const { return arity(); } + +public: + Node *inputs(uint32_t index) const { return at(index)->node(); } + void inputs(uint32_t index, Node *node) { at(index)->node(node); } + + const std::vector<uint8_t> &custom_options(void) const { return _custom_options; } + void custom_options(const std::vector<uint8_t> &custom_options) + { + _custom_options = custom_options; + } + + const std::string &custom_code(void) const { return _custom_code; } + void custom_code(const std::string &custom_code) { _custom_code = custom_code; } + +private: + std::vector<uint8_t> _custom_options; + std::string _custom_code; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLECUSTOM_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleCustomOut.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleCustomOut.h new file mode 100644 index 000000000..36b8e4aed --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleCustomOut.h @@ -0,0 +1,51 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_CUSTOMOUT_H__ +#define __LUCI_IR_CIRCLE_CUSTOMOUT_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief Virtual CIRCLECUSTOMOUT in Circle + */ +class CircleCustomOut final + : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::CIRCLECUSTOMOUT>> +{ +public: + CircleCustomOut() = default; + +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + +public: + int32_t index(void) const { return _index; } + void index(int32_t index) { _index = index; } + +private: + int32_t _index{-1}; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_CUSTOMOUT_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleDepthToSpace.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleDepthToSpace.h new file mode 100644 index 000000000..e19282b97 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleDepthToSpace.h @@ -0,0 +1,48 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_DEPTHTOSPACE_H__ +#define __LUCI_IR_CIRCLE_DEPTHTOSPACE_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief DEPTH_TO_SPACE in Circle + */ +class CircleDepthToSpace final + : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::DEPTH_TO_SPACE>> +{ +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + +public: + int block_size(void) const { return _block_size; } + void block_size(int block_size) { _block_size = block_size; } + +private: + int _block_size{0}; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_DEPTHTOSPACE_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleDepthwiseConv2D.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleDepthwiseConv2D.h new file mode 100644 index 000000000..eb058cec1 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleDepthwiseConv2D.h @@ -0,0 +1,73 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLEDEPTHWISECONV2D_H__ +#define __LUCI_IR_CIRCLEDEPTHWISECONV2D_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/AttrDilation.h" +#include "luci/IR/AttrFilter.h" +#include "luci/IR/AttrPadding.h" +#include "luci/IR/AttrStride.h" +#include "luci/IR/AttrFusedActFunc.h" +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief DEPTHWISE_CONV_2D in Circle + */ +class CircleDepthwiseConv2D final + : public FixedArityNode<3, CircleNodeImpl<CircleOpcode::DEPTHWISE_CONV_2D>>, + public LuciNodeMixin<LuciNodeTrait::FusedActFunc>, + public LuciNodeMixin<LuciNodeTrait::Bias> +{ +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + + loco::Node *filter(void) const { return at(1)->node(); } + void filter(loco::Node *node) { at(1)->node(node); } + + loco::Node *bias(void) const override { return at(2)->node(); } + void bias(loco::Node *node) override { at(2)->node(node); } + +public: + Padding padding() const { return _padding; } + void padding(Padding padding) { _padding = padding; } + + const Stride *stride(void) const { return &_stride; } + Stride *stride(void) { return &_stride; } + + int32_t depthMultiplier(void) const { return _depth_multiplier; } + void depthMultiplier(int32_t arg) { _depth_multiplier = arg; } + + const Dilation *dilation(void) const { return &_dilation; } + Dilation *dilation(void) { return &_dilation; } + +private: + Padding _padding = Padding::UNDEFINED; + Stride _stride; + int32_t _depth_multiplier = 0; + Dilation _dilation; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLEDEPTHWISECONV2D_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleDequantize.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleDequantize.h new file mode 100644 index 000000000..847c5dfc5 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleDequantize.h @@ -0,0 +1,40 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCELEDEQUANTIZE_H__ +#define __LUCI_IR_CIRCELEDEQUANTIZE_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief DEQUANTIZE in Circle + */ +class CircleDequantize final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::DEQUANTIZE>> +{ +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCELEDEQUANTIZE_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleDiv.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleDiv.h new file mode 100644 index 000000000..1d4d3a239 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleDiv.h @@ -0,0 +1,51 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLEDIV_H__ +#define __LUCI_IR_CIRCLEDIV_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/AttrFilter.h" +#include "luci/IR/AttrPadding.h" +#include "luci/IR/AttrStride.h" +#include "luci/IR/AttrFusedActFunc.h" +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief DIV in Circle + */ +class CircleDiv final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::DIV>>, + public LuciNodeMixin<LuciNodeTrait::FusedActFunc> +{ +public: + CircleDiv() = default; + +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } + + loco::Node *y(void) const { return at(1)->node(); } + void y(loco::Node *node) { at(1)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLEDIV_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleElu.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleElu.h new file mode 100644 index 000000000..fbb2f3533 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleElu.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLEELU_H__ +#define __LUCI_IR_CIRCLEELU_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief ELU in Circle + */ +class CircleElu final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::ELU>> +{ +public: + CircleElu() = default; + +public: + loco::Node *features(void) const { return at(0)->node(); } + void features(loco::Node *node) { at(0)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLEELU_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleEqual.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleEqual.h new file mode 100644 index 000000000..2087d097a --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleEqual.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_EQUAL_H__ +#define __LUCI_IR_CIRCLE_EQUAL_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief EQUAL in Circle + */ +class CircleEqual final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::EQUAL>> +{ +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } + + loco::Node *y(void) const { return at(1)->node(); } + void y(loco::Node *node) { at(1)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_EQUAL_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleExp.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleExp.h new file mode 100644 index 000000000..97aecb30a --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleExp.h @@ -0,0 +1,40 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_EXP_H__ +#define __LUCI_IR_CIRCLE_EXP_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief EXP in Circle + */ +class CircleExp final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::EXP>> +{ +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_EXP_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleExpandDims.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleExpandDims.h new file mode 100644 index 000000000..f70219614 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleExpandDims.h @@ -0,0 +1,46 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLEEXPAND_DIMS_H__ +#define __LUCI_IR_CIRCLEEXPAND_DIMS_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief EXPAND_DIMS in Circle + */ +class CircleExpandDims final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::EXPAND_DIMS>> +{ +public: + CircleExpandDims() = default; + +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + + loco::Node *axis(void) const { return at(1)->node(); } + void axis(loco::Node *node) { at(1)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLEEXPAND_DIMS_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleFill.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleFill.h new file mode 100644 index 000000000..bfc65274a --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleFill.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCEFILL_H__ +#define __LUCI_IR_CIRCEFILL_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief FILL in Circle + */ +class CircleFill final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::FILL>> +{ +public: + loco::Node *dims(void) const { return at(0)->node(); } + void dims(loco::Node *node) { at(0)->node(node); } + + loco::Node *value(void) const { return at(1)->node(); } + void value(loco::Node *node) { at(1)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCEFILL_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleFloor.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleFloor.h new file mode 100644 index 000000000..7e10547b6 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleFloor.h @@ -0,0 +1,40 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_FLOOR_H__ +#define __LUCI_IR_CIRCLE_FLOOR_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief FLOOR in Circle + */ +class CircleFloor final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::FLOOR>> +{ +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_FLOOR_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleFloorDiv.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleFloorDiv.h new file mode 100644 index 000000000..ba9db010c --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleFloorDiv.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_FLOOR_DIV_H__ +#define __LUCI_IR_CIRCLE_FLOOR_DIV_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief FLOOR_DIV in Circle + */ +class CircleFloorDiv final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::FLOOR_DIV>> +{ +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } + + loco::Node *y(void) const { return at(1)->node(); } + void y(loco::Node *node) { at(1)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_FLOOR_DIV_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleFloorMod.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleFloorMod.h new file mode 100644 index 000000000..4d13717a0 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleFloorMod.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_FLOOR_MOD_H__ +#define __LUCI_IR_CIRCLE_FLOOR_MOD_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief FLOOR_MOD in Circle + */ +class CircleFloorMod final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::FLOOR_MOD>> +{ +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } + + loco::Node *y(void) const { return at(1)->node(); } + void y(loco::Node *node) { at(1)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_FLOOR_MOD_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleFullyConnected.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleFullyConnected.h new file mode 100644 index 000000000..d78f39494 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleFullyConnected.h @@ -0,0 +1,50 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLEFULLYCONNECTED_H__ +#define __LUCI_IR_CIRCLEFULLYCONNECTED_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/AttrFusedActFunc.h" +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief FULLY_CONNECTED in Circle + */ +class CircleFullyConnected final + : public FixedArityNode<3, CircleNodeImpl<CircleOpcode::FULLY_CONNECTED>>, + public LuciNodeMixin<LuciNodeTrait::FusedActFunc>, + public LuciNodeMixin<LuciNodeTrait::Bias> +{ +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + + loco::Node *weights(void) const { return at(1)->node(); } + void weights(loco::Node *node) { at(1)->node(node); } + + loco::Node *bias(void) const override { return at(2)->node(); } + void bias(loco::Node *node) override { at(2)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLEFULLYCONNECTED_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleGather.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleGather.h new file mode 100644 index 000000000..1e8c4982a --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleGather.h @@ -0,0 +1,50 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLEGATHER_H__ +#define __LUCI_IR_CIRCLEGATHER_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief GATHER in Circle + */ +class CircleGather final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::GATHER>> +{ +public: + loco::Node *params(void) const { return at(0)->node(); } + void params(loco::Node *node) { at(0)->node(node); } + + loco::Node *indices(void) const { return at(1)->node(); } + void indices(loco::Node *node) { at(1)->node(node); } + +public: + int32_t axis(void) const { return _axis; } + void axis(int32_t axis) { _axis = axis; } + +private: + int32_t _axis = 0; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLEGATHER_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleGatherNd.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleGatherNd.h new file mode 100644 index 000000000..3423a8216 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleGatherNd.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLEGATHER_ND_H__ +#define __LUCI_IR_CIRCLEGATHER_ND_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief GATHER_ND in Circle + */ +class CircleGatherNd final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::GATHER_ND>> +{ +public: + loco::Node *params(void) const { return at(0)->node(); } + void params(loco::Node *node) { at(0)->node(node); } + + loco::Node *indices(void) const { return at(1)->node(); } + void indices(loco::Node *node) { at(1)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLEGATHER_ND_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleGreater.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleGreater.h new file mode 100644 index 000000000..040a4e338 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleGreater.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_GREATER_H__ +#define __LUCI_IR_CIRCLE_GREATER_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief Greater in Circle + */ +class CircleGreater final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::GREATER>> +{ +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } + + loco::Node *y(void) const { return at(1)->node(); } + void y(loco::Node *node) { at(1)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_GREATER_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleGreaterEqual.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleGreaterEqual.h new file mode 100644 index 000000000..82bdab212 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleGreaterEqual.h @@ -0,0 +1,44 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_GREATEREQUAL_H__ +#define __LUCI_IR_CIRCLE_GREATEREQUAL_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief GREATER EQUAL in Circle + */ +class CircleGreaterEqual final + : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::GREATER_EQUAL>> +{ +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } + + loco::Node *y(void) const { return at(1)->node(); } + void y(loco::Node *node) { at(1)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_GREATEREQUAL_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleIf.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleIf.h new file mode 100644 index 000000000..2f9eac211 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleIf.h @@ -0,0 +1,79 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_IF_H__ +#define __LUCI_IR_CIRCLE_IF_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/VariadicArityNode.h" + +#include <cassert> + +namespace luci +{ + +/** + * @brief IF in Circle + */ +class CircleIf final : public VariadicArityNode<CircleNodeImpl<CircleOpcode::IF>> +{ +public: + CircleIf(uint32_t arity, uint32_t out) + : VariadicArityNode<CircleNodeImpl<CircleOpcode::IF>>(arity + 1), _output_count(out) + { + assert(arity > 0); + assert(out > 0); + } + +public: + uint32_t input_count(void) const { return arity() - 1; } + uint32_t output_count(void) const { return _output_count; } + +public: + Node *cond(void) const { return at(0)->node(); } + void cond(Node *node) { at(0)->node(node); } + + Node *input(uint32_t index) const { return at(index + 1)->node(); } + void input(uint32_t index, Node *node) { at(index + 1)->node(node); } + +public: + int32_t then_branch(void) const { return _then_branch; } + void then_branch(int32_t then_branch) { _then_branch = then_branch; } + + int32_t else_branch(void) const { return _else_branch; } + void else_branch(int32_t else_branch) { _else_branch = else_branch; } + +public: + loco::Graph *then_graph(void) const { return _then_graph; } + void then_graph(loco::Graph *then_graph) { _then_graph = then_graph; } + + loco::Graph *else_graph(void) const { return _else_graph; } + void else_graph(loco::Graph *else_graph) { _else_graph = else_graph; } + +private: + uint32_t _output_count{0}; + int32_t _then_branch{-1}; + int32_t _else_branch{-1}; + + loco::Graph *_then_graph{nullptr}; + loco::Graph *_else_graph{nullptr}; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_IF_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleIfOut.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleIfOut.h new file mode 100644 index 000000000..3654e943b --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleIfOut.h @@ -0,0 +1,50 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_IFOUT_H__ +#define __LUCI_IR_CIRCLE_IFOUT_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief Virtual CIRCLEIFOUT in Circle + */ +class CircleIfOut final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::CIRCLEIFOUT>> +{ +public: + CircleIfOut() = default; + +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + +public: + int32_t index(void) const { return _index; } + void index(int32_t index) { _index = index; } + +private: + int32_t _index{-1}; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_IFOUT_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleInput.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleInput.h new file mode 100644 index 000000000..4a7d36a4e --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleInput.h @@ -0,0 +1,52 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLEINPUT_H__ +#define __LUCI_IR_CIRCLEINPUT_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +#include <loco/IR/DataTypeTraits.h> +#include <loco/IR/GraphInputIndex.h> + +namespace luci +{ + +/** + * @brief CircleNode used for Input of the Graph + * @note This will not be exported as a specific op + */ +class CircleInput final : public FixedArityNode<0, CircleNodeImpl<CircleOpcode::CIRCLEINPUT>> +{ +public: + CircleInput() = default; + +public: + void index(const loco::GraphInputIndex &index); + loco::GraphInputIndex index(void) const; + + bool indexed(void) const { return _index != -1; } + +private: + int64_t _index = -1; // Uninitialized +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLEINPUT_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleInstanceNorm.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleInstanceNorm.h new file mode 100644 index 000000000..db0faa05e --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleInstanceNorm.h @@ -0,0 +1,56 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLEINSTANCENORM_H__ +#define __LUCI_IR_CIRCLEINSTANCENORM_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/AttrFusedActFunc.h" +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief INSTANCE_NORM in Circle + */ +class CircleInstanceNorm final + : public FixedArityNode<3, CircleNodeImpl<CircleOpcode::INSTANCE_NORM>>, + public LuciNodeMixin<LuciNodeTrait::FusedActFunc> +{ +public: + /// @note Currently only support FLOAT32 as input node + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + + loco::Node *gamma(void) const { return at(1)->node(); } + void gamma(loco::Node *node) { at(1)->node(node); } + + loco::Node *beta(void) const { return at(2)->node(); } + void beta(loco::Node *node) { at(2)->node(node); } + + float epsilon() const { return _epsilon; } + void epsilon(float epsilon) { _epsilon = epsilon; } + +private: + float _epsilon = 1e-05; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLEINSTANCENORM_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleL2Normalize.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleL2Normalize.h new file mode 100644 index 000000000..efa932d95 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleL2Normalize.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCEL2NORMALIZE_H__ +#define __LUCI_IR_CIRCEL2NORMALIZE_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/AttrFusedActFunc.h" +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief L2_NORMALIZATION in Circle + */ +class CircleL2Normalize final + : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::L2_NORMALIZATION>>, + public LuciNodeMixin<LuciNodeTrait::FusedActFunc> +{ +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCEL2NORMALIZE_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleL2Pool2D.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleL2Pool2D.h new file mode 100644 index 000000000..7c76ee5d0 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleL2Pool2D.h @@ -0,0 +1,62 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_L2_POOL2D_H__ +#define __LUCI_IR_CIRCLE_L2_POOL2D_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/AttrFilter.h" +#include "luci/IR/AttrPadding.h" +#include "luci/IR/AttrStride.h" +#include "luci/IR/AttrFusedActFunc.h" +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief L2_POOL_2D in Circle + */ +class CircleL2Pool2D final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::L2_POOL_2D>>, + public LuciNodeMixin<LuciNodeTrait::FusedActFunc> +{ +public: + CircleL2Pool2D() : _padding(Padding::UNDEFINED) { /* empty */} + +public: + loco::Node *value(void) const { return at(0)->node(); } + void value(loco::Node *node) { at(0)->node(node); } + + Padding padding() const { return _padding; } + void padding(Padding padding) { _padding = padding; } + + const Filter *filter(void) const { return &_filter; } + Filter *filter(void) { return &_filter; } + + const Stride *stride(void) const { return &_stride; } + Stride *stride(void) { return &_stride; } + +private: + Padding _padding; + Stride _stride; + Filter _filter; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_L2_POOL2D_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleLeakyRelu.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleLeakyRelu.h new file mode 100644 index 000000000..d6ac97fc0 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleLeakyRelu.h @@ -0,0 +1,49 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_LEAKY_RELU_H__ +#define __LUCI_IR_CIRCLE_LEAKY_RELU_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief LEAKY_RELU in Circle + */ +class CircleLeakyRelu final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::LEAKY_RELU>> +{ +public: + CircleLeakyRelu() = default; + +public: + loco::Node *features(void) const { return at(0)->node(); } + void features(loco::Node *node) { at(0)->node(node); } + + float alpha() const { return _alpha; } + void alpha(float alpha) { _alpha = alpha; } + +private: + float _alpha = 0.2f; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_LEAKY_RELU_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleLess.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleLess.h new file mode 100644 index 000000000..cd6cf1872 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleLess.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_LESS_H__ +#define __LUCI_IR_CIRCLE_LESS_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief LESS in Circle + */ +class CircleLess final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::LESS>> +{ +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } + + loco::Node *y(void) const { return at(1)->node(); } + void y(loco::Node *node) { at(1)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_LESS_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleLessEqual.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleLessEqual.h new file mode 100644 index 000000000..4c7c6a49b --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleLessEqual.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_LESSEQUAL_H__ +#define __LUCI_IR_CIRCLE_LESSEQUAL_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief LESS_EQUAL in Circle + */ +class CircleLessEqual final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::LESS_EQUAL>> +{ +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } + + loco::Node *y(void) const { return at(1)->node(); } + void y(loco::Node *node) { at(1)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_LESSEQUAL_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleLocalResponseNormalization.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleLocalResponseNormalization.h new file mode 100644 index 000000000..8ad2b40fd --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleLocalResponseNormalization.h @@ -0,0 +1,60 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLELOCAL_RESPONSE_NORMALIZATION_H__ +#define __LUCI_IR_CIRCLELOCAL_RESPONSE_NORMALIZATION_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief LOCAL_RESPONSE_NORMALIZATION in Circle + */ +class CircleLocalResponseNormalization final + : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::LOCAL_RESPONSE_NORMALIZATION>> +{ +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + +public: + int32_t radius(void) const { return _radius; } + void radius(int32_t radius) { _radius = radius; } + + float bias(void) const { return _bias; } + void bias(float bias) { _bias = bias; } + + float alpha(void) const { return _alpha; } + void alpha(float alpha) { _alpha = alpha; } + + float beta(void) const { return _beta; } + void beta(float beta) { _beta = beta; } + +private: + int32_t _radius{5}; + float _bias{1.0f}; + float _alpha{1.0f}; + float _beta{0.5f}; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLELOCAL_RESPONSE_NORMALIZATION_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleLog.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleLog.h new file mode 100644 index 000000000..aeb13fed9 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleLog.h @@ -0,0 +1,40 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_LOG_H__ +#define __LUCI_IR_CIRCLE_LOG_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief LOG in Circle + */ +class CircleLog final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::LOG>> +{ +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_LOG_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleLogSoftmax.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleLogSoftmax.h new file mode 100644 index 000000000..5dfd2c1f9 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleLogSoftmax.h @@ -0,0 +1,40 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_LOG_SOFTMAX_H__ +#define __LUCI_IR_CIRCLE_LOG_SOFTMAX_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief LOG_SOFTMAX in Circle + */ +class CircleLogSoftmax final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::LOG_SOFTMAX>> +{ +public: + loco::Node *logits(void) const { return at(0)->node(); } + void logits(loco::Node *node) { at(0)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_LOG_SOFTMAX_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleLogicalAnd.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleLogicalAnd.h new file mode 100644 index 000000000..975f6dbc7 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleLogicalAnd.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_LOGICALAND_H__ +#define __LUCI_IR_CIRCLE_LOGICALAND_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief LOGICAL_AND in Circle + */ +class CircleLogicalAnd final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::LOGICAL_AND>> +{ +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } + + loco::Node *y(void) const { return at(1)->node(); } + void y(loco::Node *node) { at(1)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_LOGICALAND_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleLogicalNot.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleLogicalNot.h new file mode 100644 index 000000000..749dbe518 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleLogicalNot.h @@ -0,0 +1,40 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_LOGICALNOT_H__ +#define __LUCI_IR_CIRCLE_LOGICALNOT_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief LOGICAL_NOT in Circle + */ +class CircleLogicalNot final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::LOGICAL_NOT>> +{ +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_LOGICALNOT_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleLogicalOr.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleLogicalOr.h new file mode 100644 index 000000000..570be57af --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleLogicalOr.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_LOGICALOR_H__ +#define __LUCI_IR_CIRCLE_LOGICALOR_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief LOGICAL_OR in Circle + */ +class CircleLogicalOr final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::LOGICAL_OR>> +{ +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } + + loco::Node *y(void) const { return at(1)->node(); } + void y(loco::Node *node) { at(1)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_LOGICALOR_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleLogistic.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleLogistic.h new file mode 100644 index 000000000..8328cb328 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleLogistic.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_LOGISTIC_H__ +#define __LUCI_IR_CIRCLE_LOGISTIC_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief LOGISTIC in Circle + */ +class CircleLogistic final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::LOGISTIC>> +{ +public: + CircleLogistic() = default; + +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_LOGISTIC_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleMatrixDiag.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleMatrixDiag.h new file mode 100644 index 000000000..dca6538c3 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleMatrixDiag.h @@ -0,0 +1,40 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLEMATRIXDIAG_H__ +#define __LUCI_IR_CIRCLEMATRIXDIAG_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief MATRIX_DIAG in Circle + */ +class CircleMatrixDiag final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::MATRIX_DIAG>> +{ +public: + loco::Node *diagonal(void) const { return at(0)->node(); } + void diagonal(loco::Node *node) { at(0)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLEMATRIXDIAG_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleMatrixSetDiag.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleMatrixSetDiag.h new file mode 100644 index 000000000..c1f5f3023 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleMatrixSetDiag.h @@ -0,0 +1,44 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLEMATRIXSETDIAG_H__ +#define __LUCI_IR_CIRCLEMATRIXSETDIAG_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief MATRIX_SET_DIAG in Circle + */ +class CircleMatrixSetDiag final + : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::MATRIX_SET_DIAG>> +{ +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + + loco::Node *diagonal(void) const { return at(1)->node(); } + void diagonal(loco::Node *node) { at(1)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLEMATRIXSETDIAG_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleMaxPool2D.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleMaxPool2D.h new file mode 100644 index 000000000..1eb6532ff --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleMaxPool2D.h @@ -0,0 +1,62 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLEMAXPOOL2D_H__ +#define __LUCI_IR_CIRCLEMAXPOOL2D_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/AttrFilter.h" +#include "luci/IR/AttrPadding.h" +#include "luci/IR/AttrStride.h" +#include "luci/IR/AttrFusedActFunc.h" +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief MAX_POOL_2D in Circle + */ +class CircleMaxPool2D final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::MAX_POOL_2D>>, + public LuciNodeMixin<LuciNodeTrait::FusedActFunc> +{ +public: + CircleMaxPool2D() : _padding(Padding::UNDEFINED) { /* empty */} + +public: + loco::Node *value(void) const { return at(0)->node(); } + void value(loco::Node *node) { at(0)->node(node); } + + Padding padding() const { return _padding; } + void padding(Padding padding) { _padding = padding; } + + const Filter *filter(void) const { return &_filter; } + Filter *filter(void) { return &_filter; } + + const Stride *stride(void) const { return &_stride; } + Stride *stride(void) { return &_stride; } + +private: + Padding _padding; + Stride _stride; + Filter _filter; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLEMAXPOOL2D_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleMaximum.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleMaximum.h new file mode 100644 index 000000000..6f789bc14 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleMaximum.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLEMAXIMUM_H__ +#define __LUCI_IR_CIRCLEMAXIMUM_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief MAXIMUM in Circle + */ +class CircleMaximum final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::MAXIMUM>> +{ +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } + + loco::Node *y(void) const { return at(1)->node(); } + void y(loco::Node *node) { at(1)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLEMAXIMUM_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleMean.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleMean.h new file mode 100644 index 000000000..7f8aeb5aa --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleMean.h @@ -0,0 +1,50 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLEMEAN_H__ +#define __LUCI_IR_CIRCLEMEAN_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief MEAN in Circle + */ +class CircleMean final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::MEAN>> +{ +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + + loco::Node *reduction_indices(void) const { return at(1)->node(); } + void reduction_indices(loco::Node *node) { at(1)->node(node); } + +public: + bool keep_dims(void) const { return _keep_dims; } + void keep_dims(bool keep_dims) { _keep_dims = keep_dims; } + +private: + bool _keep_dims = false; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLEMEAN_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleMinimum.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleMinimum.h new file mode 100644 index 000000000..79d5a6f17 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleMinimum.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLEMINIMUM_H__ +#define __LUCI_IR_CIRCLEMINIMUM_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief MINIMUM in Circle + */ +class CircleMinimum final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::MINIMUM>> +{ +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } + + loco::Node *y(void) const { return at(1)->node(); } + void y(loco::Node *node) { at(1)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLEMINIMUM_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleMirrorPad.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleMirrorPad.h new file mode 100644 index 000000000..68db8f6f3 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleMirrorPad.h @@ -0,0 +1,54 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_MIRRORPAD_H__ +#define __LUCI_IR_CIRCLE_MIRRORPAD_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" +#include "luci/IR/AttrMirrorPadMode.h" + +namespace luci +{ + +/** + * @brief MIRROR_PAD in Circle + */ +class CircleMirrorPad final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::MIRROR_PAD>> +{ +public: + CircleMirrorPad() = default; + +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + + loco::Node *paddings(void) const { return at(1)->node(); } + void paddings(loco::Node *node) { at(1)->node(node); } + +public: + MirrorPadMode mode(void) const { return _mode; } + void mode(MirrorPadMode mode) { _mode = mode; } + +private: + MirrorPadMode _mode{MirrorPadMode::REFLECT}; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_MIRRORPAD_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleMul.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleMul.h new file mode 100644 index 000000000..67e897170 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleMul.h @@ -0,0 +1,45 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLEMUL_H__ +#define __LUCI_IR_CIRCLEMUL_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/AttrFusedActFunc.h" +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief MUL in Circle + */ +class CircleMul final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::MUL>>, + public LuciNodeMixin<LuciNodeTrait::FusedActFunc> +{ +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } + + loco::Node *y(void) const { return at(1)->node(); } + void y(loco::Node *node) { at(1)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLEMUL_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleNeg.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleNeg.h new file mode 100644 index 000000000..4149ac4a7 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleNeg.h @@ -0,0 +1,40 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLENEG_H__ +#define __LUCI_IR_CIRCLENEG_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief NEG in Circle + */ +class CircleNeg final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::NEG>> +{ +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLENEG_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleNonMaxSuppressionV4.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleNonMaxSuppressionV4.h new file mode 100644 index 000000000..69f3368c0 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleNonMaxSuppressionV4.h @@ -0,0 +1,53 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_NON_MAX_SUPPRESSION_V4_H__ +#define __LUCI_IR_CIRCLE_NON_MAX_SUPPRESSION_V4_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief NON_MAX_SUPPRESSION_V4 in Circle + */ +class CircleNonMaxSuppressionV4 final + : public FixedArityNode<5, CircleNodeImpl<CircleOpcode::NON_MAX_SUPPRESSION_V4>> +{ +public: + loco::Node *boxes(void) const { return at(0)->node(); } + void boxes(loco::Node *node) { at(0)->node(node); } + + loco::Node *scores(void) const { return at(1)->node(); } + void scores(loco::Node *node) { at(1)->node(node); } + + loco::Node *max_output_size(void) const { return at(2)->node(); } + void max_output_size(loco::Node *node) { at(2)->node(node); } + + loco::Node *iou_threshold(void) const { return at(3)->node(); } + void iou_threshold(loco::Node *node) { at(3)->node(node); } + + loco::Node *score_threshold(void) const { return at(4)->node(); } + void score_threshold(loco::Node *node) { at(4)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_NON_MAX_SUPPRESSION_V4_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleNonMaxSuppressionV4Out.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleNonMaxSuppressionV4Out.h new file mode 100644 index 000000000..a24dc3e9c --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleNonMaxSuppressionV4Out.h @@ -0,0 +1,51 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_NONMAXSUPPRESSIONV4OUT_H__ +#define __LUCI_IR_CIRCLE_NONMAXSUPPRESSIONV4OUT_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief Virtual NONMAXSUPPRESSIONV4OUT in Circle + */ +class CircleNonMaxSuppressionV4Out final + : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::CIRCLENONMAXSUPPRESSIONV4OUT>> +{ +public: + CircleNonMaxSuppressionV4Out() = default; + +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + +public: + int32_t index(void) const { return _index; } + void index(int32_t index) { _index = index; } + +private: + int32_t _index{-1}; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_NONMAXSUPPRESSIONV4OUT_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleNonMaxSuppressionV5.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleNonMaxSuppressionV5.h new file mode 100644 index 000000000..52d682147 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleNonMaxSuppressionV5.h @@ -0,0 +1,56 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_NON_MAX_SUPPRESSION_V5_H__ +#define __LUCI_IR_CIRCLE_NON_MAX_SUPPRESSION_V5_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief NON_MAX_SUPPRESSION_V5 in Circle + */ +class CircleNonMaxSuppressionV5 final + : public FixedArityNode<6, CircleNodeImpl<CircleOpcode::NON_MAX_SUPPRESSION_V5>> +{ +public: + loco::Node *boxes(void) const { return at(0)->node(); } + void boxes(loco::Node *node) { at(0)->node(node); } + + loco::Node *scores(void) const { return at(1)->node(); } + void scores(loco::Node *node) { at(1)->node(node); } + + loco::Node *max_output_size(void) const { return at(2)->node(); } + void max_output_size(loco::Node *node) { at(2)->node(node); } + + loco::Node *iou_threshold(void) const { return at(3)->node(); } + void iou_threshold(loco::Node *node) { at(3)->node(node); } + + loco::Node *score_threshold(void) const { return at(4)->node(); } + void score_threshold(loco::Node *node) { at(4)->node(node); } + + loco::Node *soft_nms_sigma(void) const { return at(5)->node(); } + void soft_nms_sigma(loco::Node *node) { at(5)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_NON_MAX_SUPPRESSION_V5_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleNonMaxSuppressionV5Out.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleNonMaxSuppressionV5Out.h new file mode 100644 index 000000000..0c6989cc7 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleNonMaxSuppressionV5Out.h @@ -0,0 +1,51 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_NONMAXSUPPRESSIONV5OUT_H__ +#define __LUCI_IR_CIRCLE_NONMAXSUPPRESSIONV5OUT_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief Virtual NONMAXSUPPRESSIONV5OUT in Circle + */ +class CircleNonMaxSuppressionV5Out final + : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::CIRCLENONMAXSUPPRESSIONV5OUT>> +{ +public: + CircleNonMaxSuppressionV5Out() = default; + +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + +public: + int32_t index(void) const { return _index; } + void index(int32_t index) { _index = index; } + +private: + int32_t _index{-1}; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_NONMAXSUPPRESSIONV5OUT_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleNotEqual.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleNotEqual.h new file mode 100644 index 000000000..cca7a5e22 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleNotEqual.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_NOTEQUAL_H__ +#define __LUCI_IR_CIRCLE_NOTEQUAL_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief NOT EQUAL in Circle + */ +class CircleNotEqual final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::NOT_EQUAL>> +{ +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } + + loco::Node *y(void) const { return at(1)->node(); } + void y(loco::Node *node) { at(1)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_NOTEQUAL_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleOneHot.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleOneHot.h new file mode 100644 index 000000000..665e01d48 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleOneHot.h @@ -0,0 +1,56 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLEONEHOT_H__ +#define __LUCI_IR_CIRCLEONEHOT_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief ONEHOT in Circle + */ +class CircleOneHot final : public FixedArityNode<4, CircleNodeImpl<CircleOpcode::ONE_HOT>> +{ +public: + loco::Node *indices(void) const { return at(0)->node(); } + void indices(loco::Node *node) { at(0)->node(node); } + + loco::Node *depth(void) const { return at(1)->node(); } + void depth(loco::Node *node) { at(1)->node(node); } + + loco::Node *on_value(void) const { return at(2)->node(); } + void on_value(loco::Node *node) { at(2)->node(node); } + + loco::Node *off_value(void) const { return at(3)->node(); } + void off_value(loco::Node *node) { at(3)->node(node); } + +public: + int32_t axis(void) const { return _axis; } + void axis(int32_t axis) { _axis = axis; } + +private: + int32_t _axis = -1; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLEONEHOT_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleOutput.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleOutput.h new file mode 100644 index 000000000..67e55f1a1 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleOutput.h @@ -0,0 +1,75 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLEOUTPUT_H__ +#define __LUCI_IR_CIRCLEOUTPUT_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +#include <loco/IR/GraphOutputIndex.h> + +namespace luci +{ + +/** + * @brief CircleNode for Output of the Graph + * @note This will not be exported as a specific op + */ +class CircleOutput final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::CIRCLEOUTPUT>> +{ +public: + CircleOutput() = default; + + void index(const loco::GraphOutputIndex &index); + loco::GraphOutputIndex index(void) const; + + bool indexed(void) const { return _index != -1; } + +public: + loco::Node *from(void) const { return at(0)->node(); } + void from(loco::Node *node) { at(0)->node(node); } + +private: + int64_t _index = -1; // Uninitialized +}; + +/** + * @brief Temporary DummyNode used with dangle CircleNode + */ +// TODO remove CircleOutputDummy +class CircleOutputDummy final + : public FixedArityNode<0, CircleNodeImpl<CircleOpcode::CIRCLEOUTPUTDUMMY>> +{ +public: + CircleOutputDummy() = default; +}; + +/** + * @brief CircleOutputExclude is used to specifying not exported nodes + */ +class CircleOutputExclude final + : public FixedArityNode<0, CircleNodeImpl<CircleOpcode::CIRCLEOUTPUTEXCLUDE>> +{ +public: + CircleOutputExclude() = default; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLEOUTPUT_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CirclePRelu.h b/compiler/luci/lang/include/luci/IR/Nodes/CirclePRelu.h new file mode 100644 index 000000000..693777512 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CirclePRelu.h @@ -0,0 +1,46 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_PRELU_H__ +#define __LUCI_IR_PRELU_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief PRelu in Circle + */ +class CirclePRelu final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::PRELU>> +{ +public: + CirclePRelu() = default; + +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + + loco::Node *alpha(void) const { return at(1)->node(); } + void alpha(loco::Node *node) { at(1)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_PRELU_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CirclePack.h b/compiler/luci/lang/include/luci/IR/Nodes/CirclePack.h new file mode 100644 index 000000000..8330b585a --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CirclePack.h @@ -0,0 +1,67 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLEPACK_H__ +#define __LUCI_IR_CIRCLEPACK_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/VariadicArityNode.h" + +#include <cassert> + +namespace luci +{ + +/** + * @brief PACK in Circle + */ +class CirclePack final : public VariadicArityNode<CircleNodeImpl<CircleOpcode::PACK>> +{ +public: + CirclePack(uint32_t arity) : VariadicArityNode<CircleNodeImpl<CircleOpcode::PACK>>(arity) + { + // TODO Support when arity is 0 + assert(arity >= 1); + } + +public: + uint32_t values_count(void) const { return arity(); } + +public: + Node *values(uint32_t index) const + { + assert(index < values_count()); + return at(index)->node(); + } + void values(uint32_t index, Node *node) + { + assert(index < values_count()); + at(index)->node(node); + } + +public: + int32_t axis(void) const { return _axis; } + void axis(int32_t axis) { _axis = axis; } + +private: + int32_t _axis{0}; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLEPACK_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CirclePad.h b/compiler/luci/lang/include/luci/IR/Nodes/CirclePad.h new file mode 100644 index 000000000..31599bda0 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CirclePad.h @@ -0,0 +1,46 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLEPAD_H__ +#define __LUCI_IR_CIRCLEPAD_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief PAD in Circle + */ +class CirclePad final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::PAD>> +{ +public: + CirclePad() = default; + +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + + loco::Node *paddings(void) const { return at(1)->node(); } + void paddings(loco::Node *node) { at(1)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLEPAD_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CirclePadV2.h b/compiler/luci/lang/include/luci/IR/Nodes/CirclePadV2.h new file mode 100644 index 000000000..563cfd9a4 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CirclePadV2.h @@ -0,0 +1,49 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLEPADV2_H__ +#define __LUCI_IR_CIRCLEPADV2_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief PADV2 in Circle + */ +class CirclePadV2 final : public FixedArityNode<3, CircleNodeImpl<CircleOpcode::PADV2>> +{ +public: + CirclePadV2() = default; + +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + + loco::Node *paddings(void) const { return at(1)->node(); } + void paddings(loco::Node *node) { at(1)->node(node); } + + loco::Node *constant_values(void) const { return at(2)->node(); } + void constant_values(loco::Node *node) { at(2)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLEPADV2_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CirclePow.h b/compiler/luci/lang/include/luci/IR/Nodes/CirclePow.h new file mode 100644 index 000000000..006e3dd86 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CirclePow.h @@ -0,0 +1,46 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_POW_H__ +#define __LUCI_IR_POW_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief POW in Circle + */ +class CirclePow final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::POW>> +{ +public: + CirclePow() = default; + +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } + + loco::Node *y(void) const { return at(1)->node(); } + void y(loco::Node *node) { at(1)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_POW_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleRange.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleRange.h new file mode 100644 index 000000000..977a37a52 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleRange.h @@ -0,0 +1,46 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLERANGE_H__ +#define __LUCI_IR_CIRCLERANGE_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief RANGE in Circle + */ +class CircleRange final : public FixedArityNode<3, CircleNodeImpl<CircleOpcode::RANGE>> +{ +public: + loco::Node *start(void) const { return at(0)->node(); } + void start(loco::Node *node) { at(0)->node(node); } + + loco::Node *limit(void) const { return at(1)->node(); } + void limit(loco::Node *node) { at(1)->node(node); } + + loco::Node *delta(void) const { return at(2)->node(); } + void delta(loco::Node *node) { at(2)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLERANGE_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleRank.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleRank.h new file mode 100644 index 000000000..ba6d67f69 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleRank.h @@ -0,0 +1,40 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLERANK_H__ +#define __LUCI_IR_CIRCLERANK_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief RANK in Circle + */ +class CircleRank final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::RANK>> +{ +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLERANK_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleReduceAny.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleReduceAny.h new file mode 100644 index 000000000..0456be863 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleReduceAny.h @@ -0,0 +1,50 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_REDUCE_ANY_H__ +#define __LUCI_IR_CIRCLE_REDUCE_ANY_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief REDUCE_ANY in Circle + */ +class CircleReduceAny final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::REDUCE_ANY>> +{ +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + + loco::Node *reduction_indices(void) const { return at(1)->node(); } + void reduction_indices(loco::Node *node) { at(1)->node(node); } + +public: + bool keep_dims(void) const { return _keep_dims; } + void keep_dims(bool keep_dims) { _keep_dims = keep_dims; } + +private: + bool _keep_dims = false; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_REDUCE_ANY_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleReduceMax.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleReduceMax.h new file mode 100644 index 000000000..925c977e5 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleReduceMax.h @@ -0,0 +1,50 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_REDUCE_MAX_H__ +#define __LUCI_IR_CIRCLE_REDUCE_MAX_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief REDUCE_MAX in Circle + */ +class CircleReduceMax final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::REDUCE_MAX>> +{ +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + + loco::Node *reduction_indices(void) const { return at(1)->node(); } + void reduction_indices(loco::Node *node) { at(1)->node(node); } + +public: + bool keep_dims(void) const { return _keep_dims; } + void keep_dims(bool keep_dims) { _keep_dims = keep_dims; } + +private: + bool _keep_dims = false; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_REDUCE_MAX_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleReduceMin.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleReduceMin.h new file mode 100644 index 000000000..fd789ae5e --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleReduceMin.h @@ -0,0 +1,50 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_REDUCE_MIN_H__ +#define __LUCI_IR_CIRCLE_REDUCE_MIN_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief REDUCE_MIN in Circle + */ +class CircleReduceMin final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::REDUCE_MIN>> +{ +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + + loco::Node *reduction_indices(void) const { return at(1)->node(); } + void reduction_indices(loco::Node *node) { at(1)->node(node); } + +public: + bool keep_dims(void) const { return _keep_dims; } + void keep_dims(bool keep_dims) { _keep_dims = keep_dims; } + +private: + bool _keep_dims = false; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_REDUCE_MIN_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleReduceProd.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleReduceProd.h new file mode 100644 index 000000000..b7d226255 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleReduceProd.h @@ -0,0 +1,50 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_REDUCE_PROD_H__ +#define __LUCI_IR_CIRCLE_REDUCE_PROD_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief REDUCE_PROD in Circle + */ +class CircleReduceProd final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::REDUCE_PROD>> +{ +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + + loco::Node *reduction_indices(void) const { return at(1)->node(); } + void reduction_indices(loco::Node *node) { at(1)->node(node); } + +public: + bool keep_dims(void) const { return _keep_dims; } + void keep_dims(bool keep_dims) { _keep_dims = keep_dims; } + +private: + bool _keep_dims = false; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_REDUCE_PROD_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleRelu.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleRelu.h new file mode 100644 index 000000000..91272d2bf --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleRelu.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLERELU_H__ +#define __LUCI_IR_CIRCLERELU_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief RELU in Circle + */ +class CircleRelu final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::RELU>> +{ +public: + CircleRelu() = default; + +public: + loco::Node *features(void) const { return at(0)->node(); } + void features(loco::Node *node) { at(0)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLERELU_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleRelu6.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleRelu6.h new file mode 100644 index 000000000..b4274ded9 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleRelu6.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLERELU6_H__ +#define __LUCI_IR_CIRCLERELU6_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief RELU6 in Circle + */ +class CircleRelu6 final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::RELU6>> +{ +public: + CircleRelu6() = default; + +public: + loco::Node *features(void) const { return at(0)->node(); } + void features(loco::Node *node) { at(0)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLERELU6_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleReluN1To1.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleReluN1To1.h new file mode 100644 index 000000000..a5c5710c2 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleReluN1To1.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_RELU_N1_TO_1_H__ +#define __LUCI_IR_CIRCLE_RELU_N1_TO_1_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief RELU_N1_TO_1 in Circle + */ +class CircleReluN1To1 final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::RELU_N1_TO_1>> +{ +public: + CircleReluN1To1() = default; + +public: + loco::Node *features(void) const { return at(0)->node(); } + void features(loco::Node *node) { at(0)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_RELU_N1_TO_1_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleReshape.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleReshape.h new file mode 100644 index 000000000..b13144f7e --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleReshape.h @@ -0,0 +1,68 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLERESHAPE_H__ +#define __LUCI_IR_CIRCLERESHAPE_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief RESHAPE in Circle + */ +class CircleReshape final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::RESHAPE>> +{ +public: + CircleReshape() = default; + +public: + loco::Node *tensor(void) const { return at(0)->node(); } + void tensor(loco::Node *node) { at(0)->node(node); } + + // NOTE shape is optional and can be CircleConst or any other type + // and also can be CircleOutputDummy when reshape option does not exist + loco::Node *shape(void) const { return at(1)->node(); } + void shape(loco::Node *node) { at(1)->node(node); } + +public: + class Shape + { + public: + uint32_t rank(void) const { return _shape.size(); } + void rank(uint32_t rank) { _shape.resize(rank); } + + int32_t dim(uint32_t n) const { return _shape.at(n); } + int32_t &dim(uint32_t n) { return _shape.at(n); } + + private: + std::vector<int32_t> _shape; + }; + + const Shape *newShape(void) const { return &_new_shape; } + Shape *newShape(void) { return &_new_shape; } + +private: + Shape _new_shape; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLERESHAPE_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleResizeBilinear.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleResizeBilinear.h new file mode 100644 index 000000000..3c8223338 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleResizeBilinear.h @@ -0,0 +1,57 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLERESIZE_BILINEAR_H__ +#define __LUCI_IR_CIRCLERESIZE_BILINEAR_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief RESIZE_BILINEAR in Circle + */ +class CircleResizeBilinear final + : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::RESIZE_BILINEAR>> +{ +public: + CircleResizeBilinear() = default; + +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + + loco::Node *size(void) const { return at(1)->node(); } + void size(loco::Node *node) { at(1)->node(node); } + + bool align_corners() const { return _align_corners; } + void align_corners(bool value) { _align_corners = value; } + + bool half_pixel_centers() const { return _half_pixel_centers; } + void half_pixel_centers(bool value) { _half_pixel_centers = value; } + +private: + bool _align_corners = false; + bool _half_pixel_centers = false; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLERESIZE_BILINEAR_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleResizeNearestNeighbor.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleResizeNearestNeighbor.h new file mode 100644 index 000000000..dc32ebee7 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleResizeNearestNeighbor.h @@ -0,0 +1,53 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLERESSIZE_NEAREST_NEIGHBOR_H__ +#define __LUCI_IR_CIRCLERESSIZE_NEAREST_NEIGHBOR_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief RESIZE_NEAREST_NEIGHBOR in Circle + */ +class CircleResizeNearestNeighbor final + : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::RESIZE_NEAREST_NEIGHBOR>> +{ +public: + CircleResizeNearestNeighbor() = default; + +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + + loco::Node *size(void) const { return at(1)->node(); } + void size(loco::Node *node) { at(1)->node(node); } + + bool align_corners() const { return _align_corners; } + void align_corners(bool value) { _align_corners = value; } + +private: + bool _align_corners = false; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLERESSIZE_NEAREST_NEIGHBOR_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleReverseSequence.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleReverseSequence.h new file mode 100644 index 000000000..b0766dd3e --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleReverseSequence.h @@ -0,0 +1,58 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLEREVERSESEQUENCE_H__ +#define __LUCI_IR_CIRCLEREVERSESEQUENCE_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief REVERSE_SEQUENCE in Circle + */ +class CircleReverseSequence final + : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::REVERSE_SEQUENCE>> +{ +public: + CircleReverseSequence() = default; + +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + + loco::Node *seq_lengths(void) const { return at(1)->node(); } + void seq_lengths(loco::Node *node) { at(1)->node(node); } + +public: + int seq_axis(void) const { return _seq_axis; } + void seq_axis(int seq_axis) { _seq_axis = seq_axis; } + + int batch_axis(void) const { return _batch_axis; } + void batch_axis(int batch_axis) { _batch_axis = batch_axis; } + +private: + int _seq_axis{0}; + int _batch_axis{0}; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLEREVERSESEQUENCE_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleReverseV2.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleReverseV2.h new file mode 100644 index 000000000..71d9f65aa --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleReverseV2.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLEREVERSE_V2_H__ +#define __LUCI_IR_CIRCLEREVERSE_V2_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief ReverseV2 in Circle + */ +class CircleReverseV2 final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::REVERSE_V2>> +{ +public: + loco::Node *tensor(void) const { return at(0)->node(); } + void tensor(loco::Node *node) { at(0)->node(node); } + + loco::Node *axis(void) const { return at(1)->node(); } + void axis(loco::Node *node) { at(1)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLEREVERSE_V2_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleRound.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleRound.h new file mode 100644 index 000000000..30296ce9e --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleRound.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLEROUND_H__ +#define __LUCI_IR_CIRCLEROUND_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief ROUND in Circle + */ +class CircleRound final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::ROUND>> +{ +public: + CircleRound() = default; + +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLEROUND_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleRsqrt.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleRsqrt.h new file mode 100644 index 000000000..873397bce --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleRsqrt.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLERSQRT_H__ +#define __LUCI_IR_CIRCLERSQRT_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief RSQRT in Circle + */ +class CircleRsqrt final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::RSQRT>> +{ +public: + CircleRsqrt() = default; + +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLERSQRT_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleScatterNd.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleScatterNd.h new file mode 100644 index 000000000..9f93a0a80 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleScatterNd.h @@ -0,0 +1,46 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLESCATTER_ND_H__ +#define __LUCI_IR_CIRCLESCATTER_ND_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief SCATTER_ND in Circle + */ +class CircleScatterNd final : public FixedArityNode<3, CircleNodeImpl<CircleOpcode::SCATTER_ND>> +{ +public: + loco::Node *indices(void) const { return at(0)->node(); } + void indices(loco::Node *node) { at(0)->node(node); } + + loco::Node *updates(void) const { return at(1)->node(); } + void updates(loco::Node *node) { at(1)->node(node); } + + loco::Node *shape(void) const { return at(2)->node(); } + void shape(loco::Node *node) { at(2)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLESCATTER_ND_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleSegmentSum.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleSegmentSum.h new file mode 100644 index 000000000..416d617b2 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleSegmentSum.h @@ -0,0 +1,46 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_SEGMENT_SUM_H__ +#define __LUCI_IR_CIRCLE_SEGMENT_SUM_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief SEGMENT_SUM in Circle + */ +class CircleSegmentSum final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::SEGMENT_SUM>> +{ +public: + CircleSegmentSum() = default; + +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + + loco::Node *segment_ids(void) const { return at(1)->node(); } + void segment_ids(loco::Node *node) { at(1)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_SEGMENT_SUM_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleSelect.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleSelect.h new file mode 100644 index 000000000..727647168 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleSelect.h @@ -0,0 +1,49 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_SELECT_H__ +#define __LUCI_IR_CIRCLE_SELECT_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief SELECT in Circle + */ +class CircleSelect final : public FixedArityNode<3, CircleNodeImpl<CircleOpcode::SELECT>> +{ +public: + CircleSelect() = default; + +public: + loco::Node *condition(void) const { return at(0)->node(); } + void condition(loco::Node *node) { at(0)->node(node); } + + loco::Node *t(void) const { return at(1)->node(); } + void t(loco::Node *node) { at(1)->node(node); } + + loco::Node *e(void) const { return at(2)->node(); } + void e(loco::Node *node) { at(2)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_SELECT_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleSelectV2.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleSelectV2.h new file mode 100644 index 000000000..7ac3c0524 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleSelectV2.h @@ -0,0 +1,49 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_SELECT_V2_H__ +#define __LUCI_IR_CIRCLE_SELECT_V2_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief SELECT_V2 in Circle + */ +class CircleSelectV2 final : public FixedArityNode<3, CircleNodeImpl<CircleOpcode::SELECT_V2>> +{ +public: + CircleSelectV2() = default; + +public: + loco::Node *condition(void) const { return at(0)->node(); } + void condition(loco::Node *node) { at(0)->node(node); } + + loco::Node *t(void) const { return at(1)->node(); } + void t(loco::Node *node) { at(1)->node(node); } + + loco::Node *e(void) const { return at(2)->node(); } + void e(loco::Node *node) { at(2)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_SELECT_V2_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleShape.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleShape.h new file mode 100644 index 000000000..ff20ce684 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleShape.h @@ -0,0 +1,50 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_SHAPE_H__ +#define __LUCI_IR_CIRCLE_SHAPE_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief SHAPE in Circle + */ +class CircleShape final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::SHAPE>> +{ +public: + CircleShape() = default; + +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + +public: + loco::DataType out_type(void) const { return _out_type; } + void out_type(loco::DataType ot) { _out_type = ot; } + +private: + loco::DataType _out_type{loco::DataType::S32}; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_SHAPE_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleSin.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleSin.h new file mode 100644 index 000000000..5624db253 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleSin.h @@ -0,0 +1,40 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_SIN_H__ +#define __LUCI_IR_CIRCLE_SIN_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief SIN in Circle + */ +class CircleSin final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::SIN>> +{ +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_SIN_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleSlice.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleSlice.h new file mode 100644 index 000000000..a2113643d --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleSlice.h @@ -0,0 +1,46 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_SLICE_H__ +#define __LUCI_IR_SLICE_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief SLICE in Circle + */ +class CircleSlice final : public FixedArityNode<3, CircleNodeImpl<CircleOpcode::SLICE>> +{ +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + + loco::Node *begin(void) const { return at(1)->node(); } + void begin(loco::Node *node) { at(1)->node(node); } + + loco::Node *size(void) const { return at(2)->node(); } + void size(loco::Node *node) { at(2)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_SLICE_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleSoftmax.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleSoftmax.h new file mode 100644 index 000000000..7166a329b --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleSoftmax.h @@ -0,0 +1,47 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLESOFTMAX_H__ +#define __LUCI_IR_CIRCLESOFTMAX_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief SOFTMAX in Circle + */ +class CircleSoftmax final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::SOFTMAX>> +{ +public: + loco::Node *logits(void) const { return at(0)->node(); } + void logits(loco::Node *node) { at(0)->node(node); } + +public: + float beta(void) const { return _beta; } + void beta(float beta) { _beta = beta; } + +private: + float _beta{0.0f}; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLESOFTMAX_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleSpaceToBatchND.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleSpaceToBatchND.h new file mode 100644 index 000000000..042ebffcd --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleSpaceToBatchND.h @@ -0,0 +1,47 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_SPACETOBATCHND_H__ +#define __LUCI_IR_CIRCLE_SPACETOBATCHND_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief SPACE_TO_BATCH_ND in Circle + */ +class CircleSpaceToBatchND final + : public FixedArityNode<3, CircleNodeImpl<CircleOpcode::SPACE_TO_BATCH_ND>> +{ +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + + loco::Node *block_shape(void) const { return at(1)->node(); } + void block_shape(loco::Node *node) { at(1)->node(node); } + + loco::Node *paddings(void) const { return at(2)->node(); } + void paddings(loco::Node *node) { at(2)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_SPACETOBATCHND_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleSpaceToDepth.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleSpaceToDepth.h new file mode 100644 index 000000000..420a4cb96 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleSpaceToDepth.h @@ -0,0 +1,48 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_SPACETODEPTH_H__ +#define __LUCI_IR_CIRCLE_SPACETODEPTH_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief SPACE_TO_DEPTH in Circle + */ +class CircleSpaceToDepth final + : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::SPACE_TO_DEPTH>> +{ +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + +public: + int block_size(void) const { return _block_size; } + void block_size(int block_size) { _block_size = block_size; } + +private: + int _block_size{0}; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_SPACETODEPTH_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleSparseToDense.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleSparseToDense.h new file mode 100644 index 000000000..7e80304b0 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleSparseToDense.h @@ -0,0 +1,57 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCELSPARSETODENSE_H__ +#define __LUCI_IR_CIRCELSPARSETODENSE_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief SPARSE_TO_DENSE in Circle + */ +class CircleSparseToDense final + : public FixedArityNode<4, CircleNodeImpl<CircleOpcode::SPARSE_TO_DENSE>> +{ +public: + loco::Node *indices(void) const { return at(0)->node(); } + void indices(loco::Node *node) { at(0)->node(node); } + + loco::Node *output_shape(void) const { return at(1)->node(); } + void output_shape(loco::Node *node) { at(1)->node(node); } + + loco::Node *values(void) const { return at(2)->node(); } + void values(loco::Node *node) { at(2)->node(node); } + + loco::Node *default_value(void) const { return at(3)->node(); } + void default_value(loco::Node *node) { at(3)->node(node); } + +public: + bool validate_indices(void) const { return _validate_indices; } + void validate_indices(bool validate_indices) { _validate_indices = validate_indices; } + +private: + bool _validate_indices{false}; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCELSPARSETODENSE_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleSplit.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleSplit.h new file mode 100644 index 000000000..0eda19501 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleSplit.h @@ -0,0 +1,51 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_SPLIT_H__ +#define __LUCI_IR_CIRCLE_SPLIT_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief SPLIT in Circle + */ +class CircleSplit final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::SPLIT>> +{ +public: + loco::Node *split_dim(void) const { return at(0)->node(); } + void split_dim(loco::Node *node) { at(0)->node(node); } + + loco::Node *input(void) const { return at(1)->node(); } + void input(loco::Node *node) { at(1)->node(node); } + +public: + // NOTE it is num_split() not num_splits() as we follow TF name + int32_t num_split(void) const { return _num_split; } + void num_split(int32_t num_split) { _num_split = num_split; } + +private: + int32_t _num_split{0}; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_SPLIT_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleSplitOut.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleSplitOut.h new file mode 100644 index 000000000..6bf4a9fef --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleSplitOut.h @@ -0,0 +1,50 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_SPLITOUT_H__ +#define __LUCI_IR_CIRCLE_SPLITOUT_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief Virtual CIRCLESPLITOUT in Circle + */ +class CircleSplitOut final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::CIRCLESPLITOUT>> +{ +public: + CircleSplitOut() = default; + +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + +public: + int32_t index(void) const { return _index; } + void index(int32_t index) { _index = index; } + +private: + int32_t _index{-1}; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_SPLITOUT_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleSplitV.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleSplitV.h new file mode 100644 index 000000000..1b7d55534 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleSplitV.h @@ -0,0 +1,54 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_SPLIT_V_H__ +#define __LUCI_IR_CIRCLE_SPLIT_V_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief SPLIT_V in Circle + */ +class CircleSplitV final : public FixedArityNode<3, CircleNodeImpl<CircleOpcode::SPLIT_V>> +{ +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + + loco::Node *size_splits(void) const { return at(1)->node(); } + void size_splits(loco::Node *node) { at(1)->node(node); } + + loco::Node *split_dim(void) const { return at(2)->node(); } + void split_dim(loco::Node *node) { at(2)->node(node); } + +public: + // NOTE it is num_split() not num_splits() as we follow TF name + int32_t num_split(void) const { return _num_split; } + void num_split(int32_t num_split) { _num_split = num_split; } + +private: + int32_t _num_split{0}; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_SPLIT_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleSplitVOut.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleSplitVOut.h new file mode 100644 index 000000000..d3b2f1e5a --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleSplitVOut.h @@ -0,0 +1,51 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_SPLITVOUT_H__ +#define __LUCI_IR_CIRCLE_SPLITVOUT_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief Virtual CIRCLESPLITVOUT in Circle + */ +class CircleSplitVOut final + : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::CIRCLESPLITVOUT>> +{ +public: + CircleSplitVOut() = default; + +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + +public: + int32_t index(void) const { return _index; } + void index(int32_t index) { _index = index; } + +private: + int32_t _index{-1}; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_SPLITVOUT_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleSqrt.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleSqrt.h new file mode 100644 index 000000000..c96ca8498 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleSqrt.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLESQRT_H__ +#define __LUCI_IR_CIRCLESQRT_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief SQRT in Circle + */ +class CircleSqrt final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::SQRT>> +{ +public: + CircleSqrt() = default; + +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLESQRT_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleSquare.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleSquare.h new file mode 100644 index 000000000..a29edfe82 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleSquare.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLESQUARE_H__ +#define __LUCI_IR_CIRCLESQUARE_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief SQUARE in Circle + */ +class CircleSquare final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::SQUARE>> +{ +public: + CircleSquare() = default; + +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLESQUARE_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleSquaredDifference.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleSquaredDifference.h new file mode 100644 index 000000000..b5b39f920 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleSquaredDifference.h @@ -0,0 +1,47 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLESQUAREDIFFERENCE_H__ +#define __LUCI_IR_CIRCLESQUAREDIFFERENCE_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief SQUARED_DIFFERENCE in Circle + */ +class CircleSquaredDifference final + : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::SQUARED_DIFFERENCE>> +{ +public: + CircleSquaredDifference() = default; + +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } + + loco::Node *y(void) const { return at(1)->node(); } + void y(loco::Node *node) { at(1)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLESQUAREDIFFERENCE_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleSqueeze.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleSqueeze.h new file mode 100644 index 000000000..f175f1411 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleSqueeze.h @@ -0,0 +1,50 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLESQUEEZE_H__ +#define __LUCI_IR_CIRCLESQUEEZE_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief SQUEEZE in Circle + */ +class CircleSqueeze final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::SQUEEZE>> +{ +public: + CircleSqueeze() = default; + +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + +public: + const std::vector<int32_t> &squeeze_dims() const { return _squeeze_dims; } + void squeeze_dims(const std::vector<int32_t> &squeeze_dims) { _squeeze_dims = squeeze_dims; }; + +private: + std::vector<int32_t> _squeeze_dims{}; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLESQUEEZE_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleStridedSlice.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleStridedSlice.h new file mode 100644 index 000000000..98799fec1 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleStridedSlice.h @@ -0,0 +1,73 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_STRIDEDSLICE_H__ +#define __LUCI_IR_STRIDEDSLICE_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief STRIDED_SLICE in Circle + */ +class CircleStridedSlice final + : public FixedArityNode<4, CircleNodeImpl<CircleOpcode::STRIDED_SLICE>> +{ +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + + loco::Node *begin(void) const { return at(1)->node(); } + void begin(loco::Node *node) { at(1)->node(node); } + + loco::Node *end(void) const { return at(2)->node(); } + void end(loco::Node *node) { at(2)->node(node); } + + loco::Node *strides(void) const { return at(3)->node(); } + void strides(loco::Node *node) { at(3)->node(node); } + +public: + int32_t begin_mask() const { return _begin_mask; } + void begin_mask(int32_t mask) { _begin_mask = mask; } + + int32_t end_mask() const { return _end_mask; } + void end_mask(int32_t mask) { _end_mask = mask; } + + int32_t ellipsis_mask() const { return _ellipsis_mask; } + void ellipsis_mask(int32_t mask) { _ellipsis_mask = mask; } + + int32_t new_axis_mask() const { return _new_axis_mask; } + void new_axis_mask(int32_t mask) { _new_axis_mask = mask; } + + int32_t shrink_axis_mask() const { return _shrink_axis_mask; } + void shrink_axis_mask(int32_t mask) { _shrink_axis_mask = mask; } + +private: + int32_t _begin_mask{0}; + int32_t _end_mask{0}; + int32_t _ellipsis_mask{0}; + int32_t _new_axis_mask{0}; + int32_t _shrink_axis_mask{0}; +}; + +} // namespace luci + +#endif // __LUCI_IR_STRIDEDSLICE_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleSub.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleSub.h new file mode 100644 index 000000000..08208f942 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleSub.h @@ -0,0 +1,48 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLESUB_H__ +#define __LUCI_IR_CIRCLESUB_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/AttrFusedActFunc.h" +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief SUB in Circle + */ +class CircleSub final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::SUB>>, + public LuciNodeMixin<LuciNodeTrait::FusedActFunc> +{ +public: + CircleSub() = default; + +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } + + loco::Node *y(void) const { return at(1)->node(); } + void y(loco::Node *node) { at(1)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLESUB_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleSum.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleSum.h new file mode 100644 index 000000000..21faa76fe --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleSum.h @@ -0,0 +1,50 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLESUM_H__ +#define __LUCI_IR_CIRCLESUM_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief SUM in Circle + */ +class CircleSum final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::SUM>> +{ +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + + loco::Node *reduction_indices(void) const { return at(1)->node(); } + void reduction_indices(loco::Node *node) { at(1)->node(node); } + +public: + bool keep_dims(void) const { return _keep_dims; } + void keep_dims(bool keep_dims) { _keep_dims = keep_dims; } + +private: + bool _keep_dims = false; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLESUM_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleTanh.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleTanh.h new file mode 100644 index 000000000..f7444921f --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleTanh.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLETANH_H__ +#define __LUCI_IR_CIRCLETANH_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief TANH in Circle + */ +class CircleTanh final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::TANH>> +{ +public: + CircleTanh() = default; + +public: + loco::Node *x(void) const { return at(0)->node(); } + void x(loco::Node *node) { at(0)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLETANH_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleTile.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleTile.h new file mode 100644 index 000000000..96e1f69c6 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleTile.h @@ -0,0 +1,46 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLETILE_H__ +#define __LUCI_IR_CIRCLETILE_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief TILE in Circle + */ +class CircleTile final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::TILE>> +{ +public: + CircleTile() = default; + +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + + loco::Node *multiples(void) const { return at(1)->node(); } + void multiples(loco::Node *node) { at(1)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLETILE_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleTopKV2.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleTopKV2.h new file mode 100644 index 000000000..3b2b5abb7 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleTopKV2.h @@ -0,0 +1,46 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_TOPK_V2_H__ +#define __LUCI_IR_CIRCLE_TOPK_V2_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief TOPK_V2 in Circle + */ +class CircleTopKV2 final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::TOPK_V2>> +{ +public: + CircleTopKV2() = default; + +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + + loco::Node *k(void) const { return at(1)->node(); } + void k(loco::Node *node) { at(1)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_TOPK_V2_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleTopKV2Out.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleTopKV2Out.h new file mode 100644 index 000000000..5a6dd0c02 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleTopKV2Out.h @@ -0,0 +1,51 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_TOPK_V2_OUT_H__ +#define __LUCI_IR_CIRCLE_TOPK_V2_OUT_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief Virtual CIRCLETOPKV2OUT in Circle + */ +class CircleTopKV2Out final + : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::CIRCLETOPKV2OUT>> +{ +public: + CircleTopKV2Out() = default; + +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + +public: + int32_t index(void) const { return _index; } + void index(int32_t index) { _index = index; } + +private: + int32_t _index{-1}; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_TOPK_V2_OUT_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleTranspose.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleTranspose.h new file mode 100644 index 000000000..095cd6746 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleTranspose.h @@ -0,0 +1,49 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLETRANSPOSE_H__ +#define __LUCI_IR_CIRCLETRANSPOSE_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief TRANSPOSE in Circle + */ +class CircleTranspose final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::TRANSPOSE>> +{ +public: + CircleTranspose() = default; + +public: + /// @brief Get the input node to transpose + loco::Node *a(void) const { return at(0)->node(); } + + /// @brief Set the input node to transpose + void a(loco::Node *node) { at(0)->node(node); } + + loco::Node *perm(void) const { return at(1)->node(); } + void perm(loco::Node *node) { at(1)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLETRANSPOSE_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleTransposeConv.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleTransposeConv.h new file mode 100644 index 000000000..e355102d6 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleTransposeConv.h @@ -0,0 +1,79 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLETRANSPOSECONV_H__ +#define __LUCI_IR_CIRCLETRANSPOSECONV_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/AttrPadding.h" +#include "luci/IR/AttrStride.h" +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief TRANSPOSE_CONV in Circle + * + * @note Argument node function names are from TensorFlow. So referring 'in' and + * 'out' acutally means 'out' and 'in' of the this node. + */ +class CircleTransposeConv final + : public FixedArityNode<4, CircleNodeImpl<CircleOpcode::TRANSPOSE_CONV>>, + public LuciNodeMixin<LuciNodeTrait::Bias> +{ +public: + loco::Node *inputSizes(void) const { return at(0)->node(); } + void inputSizes(Node *node) { at(0)->node(node); } + + loco::Node *filter(void) const { return at(1)->node(); } + void filter(Node *node) { at(1)->node(node); } + + loco::Node *outBackprop(void) const { return at(2)->node(); } + void outBackprop(Node *node) { at(2)->node(node); } + + /** + * @note "bias" is optional. When this node has no conceptual bias, "bias()" + * expected to be `luci::CircleOutputExclude` type. + * + * <Comment on tflite TRANSPOSE_CONV> + * + * (Circle node has no dependency on tflite, but just for information on converting) + * Before TF v2.3.0, tflite TRANSPOSE_CONV didn't support fused bias as argument. + * From TF v2.3.0, tflite TRANSPOSE_CONV supports bias as optional 4th argument. + * + * Ref: https://github.com/tensorflow/tensorflow/commit/43b8f6e710 + */ + loco::Node *bias(void) const override { return at(3)->node(); } + void bias(loco::Node *node) override { at(3)->node(node); } + +public: + const Padding &padding(void) const { return _padding; } + void padding(const Padding &padding) { _padding = padding; } + + const Stride *stride(void) const { return &_stride; } + Stride *stride(void) { return &_stride; } + +private: + Padding _padding{Padding::UNDEFINED}; + Stride _stride; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLETRANSPOSECONV_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleUnidirectionalSequenceLSTM.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleUnidirectionalSequenceLSTM.h new file mode 100644 index 000000000..4352b045b --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleUnidirectionalSequenceLSTM.h @@ -0,0 +1,115 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLEUNIDIRECTIONALSEQUENCELSTM_H__ +#define __LUCI_IR_CIRCLEUNIDIRECTIONALSEQUENCELSTM_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/AttrFusedActFunc.h" +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief UNIDIRECTIONAL_SEQUENCE_LSTM in Circle + */ +class CircleUnidirectionalSequenceLSTM final + : public FixedArityNode<24, CircleNodeImpl<CircleOpcode::UNIDIRECTIONAL_SEQUENCE_LSTM>>, + public LuciNodeMixin<LuciNodeTrait::FusedActFunc> +{ +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + + loco::Node *input_to_input_weights(void) const { return at(1)->node(); } + void input_to_input_weights(loco::Node *node) { at(1)->node(node); } + loco::Node *input_to_forget_weights(void) const { return at(2)->node(); } + void input_to_forget_weights(loco::Node *node) { at(2)->node(node); } + loco::Node *input_to_cell_weights(void) const { return at(3)->node(); } + void input_to_cell_weights(loco::Node *node) { at(3)->node(node); } + loco::Node *input_to_output_weights(void) const { return at(4)->node(); } + void input_to_output_weights(loco::Node *node) { at(4)->node(node); } + + loco::Node *recurrent_to_input_weights(void) const { return at(5)->node(); } + void recurrent_to_input_weights(loco::Node *node) { at(5)->node(node); } + loco::Node *recurrent_to_forget_weights(void) const { return at(6)->node(); } + void recurrent_to_forget_weights(loco::Node *node) { at(6)->node(node); } + loco::Node *recurrent_to_cell_weights(void) const { return at(7)->node(); } + void recurrent_to_cell_weights(loco::Node *node) { at(7)->node(node); } + loco::Node *recurrent_to_output_weights(void) const { return at(8)->node(); } + void recurrent_to_output_weights(loco::Node *node) { at(8)->node(node); } + + loco::Node *cell_to_input_weights(void) const { return at(9)->node(); } + void cell_to_input_weights(loco::Node *node) { at(9)->node(node); } + loco::Node *cell_to_forget_weights(void) const { return at(10)->node(); } + void cell_to_forget_weights(loco::Node *node) { at(10)->node(node); } + loco::Node *cell_to_output_weights(void) const { return at(11)->node(); } + void cell_to_output_weights(loco::Node *node) { at(11)->node(node); } + + loco::Node *input_gate_bias(void) const { return at(12)->node(); } + void input_gate_bias(loco::Node *node) { at(12)->node(node); } + loco::Node *forget_gate_bias(void) const { return at(13)->node(); } + void forget_gate_bias(loco::Node *node) { at(13)->node(node); } + loco::Node *cell_gate_bias(void) const { return at(14)->node(); } + void cell_gate_bias(loco::Node *node) { at(14)->node(node); } + loco::Node *output_gate_bias(void) const { return at(15)->node(); } + void output_gate_bias(loco::Node *node) { at(15)->node(node); } + + loco::Node *projection_weights(void) const { return at(16)->node(); } + void projection_weights(loco::Node *node) { at(16)->node(node); } + loco::Node *projection_bias(void) const { return at(17)->node(); } + void projection_bias(loco::Node *node) { at(17)->node(node); } + + loco::Node *activation_state(void) const { return at(18)->node(); } + void activation_state(loco::Node *node) { at(18)->node(node); } + loco::Node *cell_state(void) const { return at(19)->node(); } + void cell_state(loco::Node *node) { at(19)->node(node); } + + loco::Node *input_layer_norm_coefficients(void) const { return at(20)->node(); } + void input_layer_norm_coefficients(loco::Node *node) { at(20)->node(node); } + loco::Node *forget_layer_norm_coefficients(void) const { return at(21)->node(); } + void forget_layer_norm_coefficients(loco::Node *node) { at(21)->node(node); } + loco::Node *cell_layer_norm_coefficients(void) const { return at(22)->node(); } + void cell_layer_norm_coefficients(loco::Node *node) { at(22)->node(node); } + loco::Node *output_layer_norm_coefficients(void) const { return at(23)->node(); } + void output_layer_norm_coefficients(loco::Node *node) { at(23)->node(node); } + +public: + float cell_clip(void) const { return _cell_clip; } + void cell_clip(float cell_clip) { _cell_clip = cell_clip; } + float proj_clip(void) const { return _proj_clip; } + void proj_clip(float proj_clip) { _proj_clip = proj_clip; } + bool time_major(void) const { return _time_major; } + void time_major(bool time_major) { _time_major = time_major; } + bool asymmetric_quantize_inputs(void) const { return _asymmetric_quantize_inputs; } + void asymmetric_quantize_inputs(bool asymmetric_quantize_inputs) + { + _asymmetric_quantize_inputs = asymmetric_quantize_inputs; + } + +private: + float _cell_clip = 0.0f; + float _proj_clip = 0.0f; + bool _time_major = false; + bool _asymmetric_quantize_inputs = false; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLEUNIDIRECTIONALSEQUENCELSTM_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleUnique.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleUnique.h new file mode 100644 index 000000000..719a72362 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleUnique.h @@ -0,0 +1,47 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCELUNIQUE_H__ +#define __LUCI_IR_CIRCELUNIQUE_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief Unique in Circle + */ +class CircleUnique final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::UNIQUE>> +{ +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + +public: + loco::DataType idx_out_type(void) const { return _idx_out_type; } + void output_type(loco::DataType ot) { _idx_out_type = ot; } + +private: + loco::DataType _idx_out_type{loco::DataType::S32}; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCELUNIQUE_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleUniqueOut.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleUniqueOut.h new file mode 100644 index 000000000..f846403e0 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleUniqueOut.h @@ -0,0 +1,51 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_UNIQUEOUT_H__ +#define __LUCI_IR_CIRCLE_UNIQUEOUT_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief Virtual CIRCLEUNIQUEOUT in Circle + */ +class CircleUniqueOut final + : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::CIRCLEUNIQUEOUT>> +{ +public: + CircleUniqueOut() = default; + +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + +public: + int32_t index(void) const { return _index; } + void index(int32_t index) { _index = index; } + +private: + int32_t _index{-1}; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_UNIQUEOUT_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleUnpack.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleUnpack.h new file mode 100644 index 000000000..cb91d7e6a --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleUnpack.h @@ -0,0 +1,54 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_UNPACK_H__ +#define __LUCI_IR_CIRCLE_UNPACK_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief UNPACK in Circle + */ +class CircleUnpack final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::UNPACK>> +{ +public: + CircleUnpack() = default; + +public: + loco::Node *value(void) const { return at(0)->node(); } + void value(loco::Node *node) { at(0)->node(node); } + +public: + int32_t num(void) const { return _num; } + void num(int32_t num) { _num = num; } + + int32_t axis(void) const { return _axis; } + void axis(int32_t axis) { _axis = axis; } + +private: + int32_t _num{0}; + int32_t _axis{0}; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_UNPACK_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleUnpackOut.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleUnpackOut.h new file mode 100644 index 000000000..6f24578a1 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleUnpackOut.h @@ -0,0 +1,51 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_UNPACKOUT_H__ +#define __LUCI_IR_CIRCLE_UNPACKOUT_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief Virtual CIRCLEUNPACKOUT in Circle + */ +class CircleUnpackOut final + : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::CIRCLEUNPACKOUT>> +{ +public: + CircleUnpackOut() = default; + +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + +public: + int32_t index(void) const { return _index; } + void index(int32_t index) { _index = index; } + +private: + int32_t _index{0}; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_UNPACKOUT_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleWhere.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleWhere.h new file mode 100644 index 000000000..51eda3d6e --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleWhere.h @@ -0,0 +1,45 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_WHERE_H__ +#define __LUCI_IR_CIRCLE_WHERE_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +#include <cassert> + +namespace luci +{ + +/** + * @brief WHERE in Circle + */ +class CircleWhere final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::WHERE>> +{ +public: + CircleWhere() = default; + +public: + loco::Node *condition() const { return at(0)->node(); } + void condition(loco::Node *node) { at(0)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_WHERE_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleWhile.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleWhile.h new file mode 100644 index 000000000..40ec96414 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleWhile.h @@ -0,0 +1,79 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_WHILE_H__ +#define __LUCI_IR_CIRCLE_WHILE_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/VariadicArityNode.h" + +#include <cassert> + +namespace luci +{ + +/** + * @brief WHILE in Circle + */ +class CircleWhile final : public VariadicArityNode<CircleNodeImpl<CircleOpcode::WHILE>> +{ +public: + CircleWhile(uint32_t arity, uint32_t out) + : VariadicArityNode<CircleNodeImpl<CircleOpcode::WHILE>>(arity), _output_count(out) + { + assert(arity > 0); + assert(out > 0); + + // input and output must have the same size + assert(arity == out); + } + +public: + uint32_t input_count(void) const { return arity(); } + uint32_t output_count(void) const { return _output_count; } + +public: + Node *input(uint32_t index) const { return at(index)->node(); } + void input(uint32_t index, Node *node) { at(index)->node(node); } + +public: + int32_t cond_branch(void) const { return _cond_branch; } + void cond_branch(int32_t cond_branch) { _cond_branch = cond_branch; } + + int32_t body_branch(void) const { return _body_branch; } + void body_branch(int32_t body_branch) { _body_branch = body_branch; } + +public: + loco::Graph *cond_graph(void) const { return _cond_graph; } + void cond_graph(loco::Graph *cond_graph) { _cond_graph = cond_graph; } + + loco::Graph *body_graph(void) const { return _body_graph; } + void body_graph(loco::Graph *body_graph) { _body_graph = body_graph; } + +private: + uint32_t _output_count{0}; + int32_t _cond_branch{-1}; + int32_t _body_branch{-1}; + + loco::Graph *_cond_graph{nullptr}; + loco::Graph *_body_graph{nullptr}; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_WHILE_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleWhileOut.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleWhileOut.h new file mode 100644 index 000000000..cdf617848 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleWhileOut.h @@ -0,0 +1,50 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_WHILEOUT_H__ +#define __LUCI_IR_CIRCLE_WHILEOUT_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief Virtual CIRCLEWHILEOUT in Circle + */ +class CircleWhileOut final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::CIRCLEWHILEOUT>> +{ +public: + CircleWhileOut() = default; + +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + +public: + int32_t index(void) const { return _index; } + void index(int32_t index) { _index = index; } + +private: + int32_t _index{-1}; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_WHILEOUT_H__ diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleZerosLike.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleZerosLike.h new file mode 100644 index 000000000..d3b6d272a --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleZerosLike.h @@ -0,0 +1,46 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_CIRCLE_ZEROS_LIKE_H__ +#define __LUCI_IR_CIRCLE_ZEROS_LIKE_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief ZEROS_LIKE in Circle + */ +class CircleZerosLike final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::ZEROS_LIKE>> +{ +public: + CircleZerosLike() = default; + +public: + /// @brief Get the input node + loco::Node *input(void) const { return at(0)->node(); } + + /// @brief Set the input node + void input(loco::Node *node) { at(0)->node(node); } +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLE_ZEROS_LIKE_H__ diff --git a/compiler/luci/lang/include/luci/IR/PropertyShapeStatus.h b/compiler/luci/lang/include/luci/IR/PropertyShapeStatus.h new file mode 100644 index 000000000..179a8ab3c --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/PropertyShapeStatus.h @@ -0,0 +1,38 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_PROPERTY_SHAPE_STATUS_H__ +#define __LUCI_IR_PROPERTY_SHAPE_STATUS_H__ + +namespace luci +{ + +/** + * @brief ShapeStatus is to remember circle node shape status. + * @note This is not an attribute from the file but inner status of a node. + * Shape with [] is scalar but sometimes it acts as dynamic shape. + */ +enum class ShapeStatus +{ + UNDEFINED, // Shape status is undefined + + NOSHAPE, // shape is unknown; to distinguish from scalar + VALID, // shape is valid +}; + +} // namespace luci + +#endif // __LUCI_IR_PROPERTY_SHAPE_STATUS_H__ diff --git a/compiler/luci/lang/include/luci/IR/SparsityParam.h b/compiler/luci/lang/include/luci/IR/SparsityParam.h new file mode 100644 index 000000000..f471e5ef9 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/SparsityParam.h @@ -0,0 +1,233 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_SPARSITYPARAM_H__ +#define __LUCI_IR_SPARSITYPARAM_H__ + +#include <cstdint> +#include <stdexcept> +#include <utility> +#include <vector> + +namespace luci +{ + +enum DimensionType +{ + DENSE, + SPARSE_CSR, +}; + +enum SparseIndexVectorType +{ + NONE, + I32, + U16, + U8, +}; + +class SparseIndexVector +{ +public: + SparseIndexVector() = default; + SparseIndexVector(const SparseIndexVectorType &type, const std::vector<int32_t> &sparse_index_vec) + : _type{type} + { + switch (type) + { + case SparseIndexVectorType::NONE: + break; + case SparseIndexVectorType::I32: + { + _vec_ptr = static_cast<void *>( + new std::vector<int32_t>(sparse_index_vec.begin(), sparse_index_vec.end())); + break; + } + case SparseIndexVectorType::U16: + { + auto new_vec = new std::vector<uint16_t>(sparse_index_vec.size()); + for (uint32_t idx = 0; idx < sparse_index_vec.size(); idx++) + { + new_vec->at(idx) = static_cast<uint16_t>(sparse_index_vec.at(idx)); + } + _vec_ptr = static_cast<void *>(new_vec); + break; + } + case SparseIndexVectorType::U8: + { + auto new_vec = new std::vector<uint8_t>(sparse_index_vec.size()); + for (uint32_t idx = 0; idx < sparse_index_vec.size(); idx++) + { + new_vec->at(idx) = static_cast<uint8_t>(sparse_index_vec.at(idx)); + } + _vec_ptr = static_cast<void *>(new_vec); + break; + } + default: + std::runtime_error("Invalid SparseIndexVectorType"); + } + } + + SparseIndexVector(SparseIndexVectorType type, const void *sparse_index_vec) : _type{type} + { + switch (type) + { + case SparseIndexVectorType::NONE: + break; + case SparseIndexVectorType::I32: + { + const std::vector<int32_t> *vec = + static_cast<const std::vector<int32_t> *>(sparse_index_vec); + _vec_ptr = static_cast<void *>(new std::vector<int32_t>(vec->begin(), vec->end())); + break; + } + case SparseIndexVectorType::U16: + { + const std::vector<uint16_t> *vec = + static_cast<const std::vector<uint16_t> *>(sparse_index_vec); + _vec_ptr = static_cast<void *>(new std::vector<uint16_t>(vec->begin(), vec->end())); + break; + } + case SparseIndexVectorType::U8: + { + const std::vector<uint8_t> *vec = + static_cast<const std::vector<uint8_t> *>(sparse_index_vec); + _vec_ptr = static_cast<void *>(new std::vector<uint8_t>(vec->begin(), vec->end())); + break; + } + default: + std::runtime_error("Invalid SparseIndexVectorType"); + } + } + + SparseIndexVector(const SparseIndexVector &sparse_index_vec) + : SparseIndexVector(sparse_index_vec._type, sparse_index_vec._vec_ptr) + { + } + + SparseIndexVector(SparseIndexVector &&sparse_index_vec) + : _type{sparse_index_vec._type}, _vec_ptr{std::exchange(sparse_index_vec._vec_ptr, nullptr)} + { + } + + SparseIndexVector &operator=(const SparseIndexVector &sparse_index_vec) + { + return *this = SparseIndexVector(sparse_index_vec); + } + + SparseIndexVector &operator=(SparseIndexVector &&sparse_index_vector) + { + std::swap(_vec_ptr, sparse_index_vector._vec_ptr); + std::swap(_type, sparse_index_vector._type); + return *this; + } + + ~SparseIndexVector() + { + switch (_type) + { + case SparseIndexVectorType::NONE: + break; + case SparseIndexVectorType::I32: + { + auto vec_ptr = static_cast<std::vector<int32_t> *>(_vec_ptr); + delete vec_ptr; + break; + } + case SparseIndexVectorType::U16: + { + auto vec_ptr = static_cast<std::vector<uint16_t> *>(_vec_ptr); + delete vec_ptr; + break; + } + case SparseIndexVectorType::U8: + { + auto vec_ptr = static_cast<std::vector<uint8_t> *>(_vec_ptr); + delete vec_ptr; + break; + } + default: + break; + } + _vec_ptr = nullptr; + _type = SparseIndexVectorType::NONE; + } + +public: + SparseIndexVectorType type(void) const { return _type; } + +public: + const std::vector<int32_t> *as_int32_vector(void) const + { + return _type == SparseIndexVectorType::I32 ? static_cast<const std::vector<int32_t> *>(_vec_ptr) + : nullptr; + } + const std::vector<uint16_t> *as_uint16_vector(void) const + { + return _type == SparseIndexVectorType::U16 + ? static_cast<const std::vector<uint16_t> *>(_vec_ptr) + : nullptr; + } + const std::vector<uint8_t> *as_uint8_vector(void) const + { + return _type == SparseIndexVectorType::U8 ? static_cast<const std::vector<uint8_t> *>(_vec_ptr) + : nullptr; + } + +private: + SparseIndexVectorType _type{SparseIndexVectorType::NONE}; + void *_vec_ptr{nullptr}; +}; + +class DimMetaData +{ +public: + DimMetaData() = delete; + DimMetaData(DimensionType format, int32_t dense_size) : _format{format}, _dense_size{dense_size} + { + // DO NOTHING + } + DimMetaData(DimensionType format, int32_t dense_size, const SparseIndexVector &array_segments, + const SparseIndexVector &array_indices) + : _format{format}, _dense_size{dense_size}, _array_segments{array_segments}, + _array_indices{array_indices} + { + // DO NOTHING + } + +public: + DimensionType format(void) const { return _format; } + int32_t dense_size(void) const { return _dense_size; } + const SparseIndexVector &array_segments(void) const { return _array_segments; } + const SparseIndexVector &array_indices(void) const { return _array_indices; } + +private: + DimensionType _format{DimensionType::DENSE}; + int32_t _dense_size{0}; + SparseIndexVector _array_segments; + SparseIndexVector _array_indices; +}; + +struct SparsityParam +{ + std::vector<int32_t> traversal_order; + std::vector<int32_t> block_map; + std::vector<DimMetaData> dim_metadata; +}; + +} // namespace luci + +#endif // __LUCI_IR_SPARSITYPARAM_H__ diff --git a/compiler/luci/lang/include/luci/IR/VariadicArityNode.h b/compiler/luci/lang/include/luci/IR/VariadicArityNode.h new file mode 100644 index 000000000..e83d90978 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/VariadicArityNode.h @@ -0,0 +1,69 @@ +/* + * 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. + */ + +#ifndef __LUCI_IR_VARIADICARITYNODES_H__ +#define __LUCI_IR_VARIADICARITYNODES_H__ + +#include <loco/IR/Node.h> +#include <loco/IR/Use.h> + +#include <vector> +#include <memory> +#include <cassert> + +namespace luci +{ + +/** + * @brief Nodes with the variadic inputs + */ +template <typename Base> class VariadicArityNode : public Base +{ +public: + VariadicArityNode(uint32_t arity) + { + for (uint32_t n = 0; n < arity; ++n) + { + _args.push_back(std::make_unique<loco::Use>(this)); + } + }; + + virtual ~VariadicArityNode() = default; + +public: + uint32_t arity(void) const final { return _args.size(); } + + loco::Node *arg(uint32_t n) const final { return _args.at(n)->node(); } + + void drop(void) final + { + for (uint32_t n = 0; n < _args.size(); ++n) + { + _args.at(n)->node(nullptr); + } + } + +protected: + // This API allows inherited classes to access "_args" field. + loco::Use *at(uint32_t n) const { return _args.at(n).get(); } + +private: + std::vector<std::unique_ptr<loco::Use>> _args; +}; + +} // namespace luci + +#endif // __LUCI_IR_VARIADICARITYNODES_H__ |