diff options
Diffstat (limited to 'compiler/luci/lang')
97 files changed, 4335 insertions, 0 deletions
diff --git a/compiler/luci/lang/CMakeLists.txt b/compiler/luci/lang/CMakeLists.txt new file mode 100644 index 000000000..564e777fb --- /dev/null +++ b/compiler/luci/lang/CMakeLists.txt @@ -0,0 +1,22 @@ +file(GLOB_RECURSE SOURCES "src/*.cpp") +file(GLOB_RECURSE TESTS "src/*.test.cpp") +list(REMOVE_ITEM SOURCES ${TESTS}) + +add_library(luci_lang SHARED ${SOURCES}) +target_include_directories(luci_lang PRIVATE src) +target_include_directories(luci_lang PUBLIC include) +target_link_libraries(luci_lang PUBLIC loco) +target_link_libraries(luci_lang PUBLIC oops) +target_link_libraries(luci_lang PRIVATE nncc_common) + +install(TARGETS luci_lang DESTINATION lib) + +if(NOT ENABLE_TEST) + return() +endif(NOT ENABLE_TEST) + +nnas_find_package(GTest REQUIRED) + +GTest_AddTest(luci_lang_test ${TESTS}) +target_include_directories(luci_lang_test PRIVATE src) +target_link_libraries(luci_lang_test luci_lang) diff --git a/compiler/luci/lang/README.md b/compiler/luci/lang/README.md new file mode 100644 index 000000000..ea0e3d5da --- /dev/null +++ b/compiler/luci/lang/README.md @@ -0,0 +1,3 @@ +# luci-lang + +`luci-lang` provides TensorFlow Lite and Circle Dialect IR 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..2abae604b --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/AttrFusedActFunc.h @@ -0,0 +1,36 @@ +/* + * 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 +}; + +} // namespace luci + +#endif // __LUCI_IR_ATTRFUSEDACTFUNC_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..b87bdf9d0 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/CircleNodeDecl.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_CIRCLENODEDECL_H__ +#define __LUCI_IR_CIRCLENODEDECL_H__ + +#include <loco/IR/Node.h> +#include <loco/IR/Dialect.h> + +#include "CircleOpcode.h" +#include "CircleNodeVisitor.forward.h" +#include "CircleQuantParam.h" + +#include <memory> + +namespace luci +{ + +using NodeName = std::string; + +struct CircleNode : public loco::Node +{ + 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); + } + +private: + NodeName _name; + std::unique_ptr<CircleQuantParam> _quantparam; +}; + +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..bdcfc9c9d --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/CircleNodeImpl.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_IR_CIRCLENODEIMPL_H__ +#define __LUCI_IR_CIRCLENODEIMPL_H__ + +#include "CircleNodes.h" +#include "CircleNodeVisitor.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..cc822842b --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/CircleNodes.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_CIRCLENODES_H__ +#define __LUCI_IR_CIRCLENODES_H__ + +#include "Nodes/CircleAbs.h" +#include "Nodes/CircleAdd.h" +#include "Nodes/CircleArgMax.h" +#include "Nodes/CircleAveragePool2D.h" +#include "Nodes/CircleBatchToSpaceND.h" +#include "Nodes/CircleConcatenation.h" +#include "Nodes/CircleConst.h" +#include "Nodes/CircleConv2D.h" +#include "Nodes/CircleCos.h" +#include "Nodes/CircleDepthwiseConv2D.h" +#include "Nodes/CircleDiv.h" +#include "Nodes/CircleEqual.h" +#include "Nodes/CircleExp.h" +#include "Nodes/CircleFullyConnected.h" +#include "Nodes/CircleGather.h" +#include "Nodes/CircleLogicalNot.h" +#include "Nodes/CircleLogicalOr.h" +#include "Nodes/CircleMaximum.h" +#include "Nodes/CircleMaxPool2D.h" +#include "Nodes/CircleMean.h" +#include "Nodes/CircleMul.h" +#include "Nodes/CirclePack.h" +#include "Nodes/CirclePad.h" +#include "Nodes/CircleRelu6.h" +#include "Nodes/CircleRelu.h" +#include "Nodes/CircleReshape.h" +#include "Nodes/CircleRsqrt.h" +#include "Nodes/CircleSoftmax.h" +#include "Nodes/CircleSqrt.h" +#include "Nodes/CircleSquaredDifference.h" +#include "Nodes/CircleSub.h" +#include "Nodes/CircleTransposeConv.h" +#include "Nodes/CircleTranspose.h" +// Circle only +#include "Nodes/CircleInstanceNorm.h" +// Virtual nodes +#include "Nodes/CircleInput.h" +#include "Nodes/CircleOutput.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); + +} // 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..ca3f7fb0f --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/CircleNodes.lst @@ -0,0 +1,52 @@ +#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(ARG_MAX, luci::CircleArgMax) +CIRCLE_NODE(AVERAGE_POOL_2D, luci::CircleAveragePool2D) +CIRCLE_NODE(BATCH_TO_SPACE_ND, luci::CircleBatchToSpaceND) +CIRCLE_NODE(CONCATENATION, luci::CircleConcatenation) +CIRCLE_NODE(CONST, luci::CircleConst) +CIRCLE_NODE(CONV_2D, luci::CircleConv2D) +CIRCLE_NODE(COS, luci::CircleCos) +CIRCLE_NODE(DEPTHWISE_CONV_2D, luci::CircleDepthwiseConv2D) +CIRCLE_NODE(DIV, luci::CircleDiv) +CIRCLE_NODE(EQUAL, luci::CircleEqual) +CIRCLE_NODE(EXP, luci::CircleExp) +CIRCLE_NODE(FULLY_CONNECTED, luci::CircleFullyConnected) +CIRCLE_NODE(GATHER, luci::CircleGather) +CIRCLE_NODE(LOGICAL_NOT, luci::CircleLogicalNot) +CIRCLE_NODE(LOGICAL_OR, luci::CircleLogicalOr) +CIRCLE_NODE(MAXIMUM, luci::CircleMaximum) +CIRCLE_NODE(MAX_POOL_2D, luci::CircleMaxPool2D) +CIRCLE_NODE(MEAN, luci::CircleMean) +CIRCLE_NODE(MUL, luci::CircleMul) +CIRCLE_NODE(PACK, luci::CirclePack) +CIRCLE_NODE(PAD, luci::CirclePad) +CIRCLE_NODE(RELU, luci::CircleRelu) +CIRCLE_NODE(RELU6, luci::CircleRelu6) +CIRCLE_NODE(RESHAPE, luci::CircleReshape) +CIRCLE_NODE(RSQRT, luci::CircleRsqrt) +CIRCLE_NODE(SOFTMAX, luci::CircleSoftmax) +CIRCLE_NODE(SQRT, luci::CircleSqrt) +CIRCLE_NODE(SQUARED_DIFFERENCE, luci::CircleSquaredDifference) +CIRCLE_NODE(SUB, luci::CircleSub) +// TODO TFLTanh +CIRCLE_NODE(TRANSPOSE, luci::CircleTranspose) +CIRCLE_NODE(TRANSPOSE_CONV, luci::CircleTransposeConv) +// Circle Only +CIRCLE_NODE(INSTANCE_NORM, luci::CircleInstanceNorm) +// Virtual node(s) +CIRCLE_NODE(CIRCLEINPUT, luci::CircleInput) +CIRCLE_NODE(CIRCLEOUTPUT, luci::CircleOutput) 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..7253e657b --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/CircleQuantParam.h @@ -0,0 +1,36 @@ +/* + * 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; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLEQUANTPARAM_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..b18ac5dc4 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/LuciNodeMixins.h @@ -0,0 +1,104 @@ +/* + * 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> + +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() + { + 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::array<std::unique_ptr<loco::Use>, N> _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/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/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/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/CircleConcatenation.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleConcatenation.h new file mode 100644 index 000000000..8a6778a2f --- /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; +}; + +} // 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..089836eb9 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleConst.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_CIRCLECONST_H__ +#define __LUCI_IR_CIRCLECONST_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/AttrFusedActFunc.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::CONST>>, + public loco::NodeMixin<loco::NodeTrait::DataType>, + public loco::NodeMixin<loco::NodeTrait::TensorShape> +{ +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..54318e65c --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleConv2D.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_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/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; } + +private: + Padding _padding = Padding::UNDEFINED; + Stride _stride; +}; + +} // 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/CircleDepthwiseConv2D.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleDepthwiseConv2D.h new file mode 100644 index 000000000..15ee62ba7 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleDepthwiseConv2D.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_CIRCLEDEPTHWISECONV2D_H__ +#define __LUCI_IR_CIRCLEDEPTHWISECONV2D_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 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; } + +private: + Padding _padding = Padding::UNDEFINED; + Stride _stride; + int32_t _depth_multiplier = 0; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLEDEPTHWISECONV2D_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/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/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..489596c04 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleGather.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_CIRCLEGATHER_H__ +#define __LUCI_IR_CIRCLEGATHER_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/AttrFusedActFunc.h" +#include "luci/IR/LuciNodeMixins.h" + +namespace luci +{ + +/** + * @brief GATHER in Circle + */ +class CircleGather final : public FixedArityNode<2, CircleNodeImpl<CircleOpcode::GATHER>> +{ +public: + loco::Node *input(void) const { return at(0)->node(); } + void input(loco::Node *node) { at(0)->node(node); } + + loco::Node *positions(void) const { return at(1)->node(); } + void positions(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/CircleInput.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleInput.h new file mode 100644 index 000000000..2c4d60253 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleInput.h @@ -0,0 +1,55 @@ +/* + * 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/AttrFusedActFunc.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 loco::NodeMixin<loco::NodeTrait::DataType>, + public loco::NodeMixin<loco::NodeTrait::TensorShape> +{ +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/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/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..cf7305e3a --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleMaximum.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_CIRCLEMAXIMUM_H__ +#define __LUCI_IR_CIRCLEMAXIMUM_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/AttrFusedActFunc.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..6fd791450 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleMean.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_CIRCLEMEAN_H__ +#define __LUCI_IR_CIRCLEMEAN_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/AttrFusedActFunc.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/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/CircleOutput.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleOutput.h new file mode 100644 index 000000000..c65317ad1 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleOutput.h @@ -0,0 +1,55 @@ +/* + * 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/AttrFusedActFunc.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 +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLEOUTPUT_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/CircleRelu.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleRelu.h new file mode 100644 index 000000000..afb2c667a --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleRelu.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_CIRCLERELU_H__ +#define __LUCI_IR_CIRCLERELU_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/AttrFusedActFunc.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..b313a5557 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleRelu6.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_CIRCLERELU6_H__ +#define __LUCI_IR_CIRCLERELU6_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/AttrFusedActFunc.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/CircleReshape.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleReshape.h new file mode 100644 index 000000000..a3a2a3f31 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleReshape.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_CIRCLERESHAPE_H__ +#define __LUCI_IR_CIRCLERESHAPE_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/AttrFusedActFunc.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); } + + // TODO Make this input optional. That is, loco system does not emit error + // with this input being null + 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/CircleRsqrt.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleRsqrt.h new file mode 100644 index 000000000..44d22ef22 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleRsqrt.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_CIRCLERSQRT_H__ +#define __LUCI_IR_CIRCLERSQRT_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/AttrFusedActFunc.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/CircleSoftmax.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleSoftmax.h new file mode 100644 index 000000000..4ea3c4b0e --- /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; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLESOFTMAX_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..bc1f39d90 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleSqrt.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_CIRCLESQRT_H__ +#define __LUCI_IR_CIRCLESQRT_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/AttrFusedActFunc.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/CircleSquaredDifference.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleSquaredDifference.h new file mode 100644 index 000000000..ff337dfbe --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleSquaredDifference.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_CIRCLESQUAREDIFFERENCE_H__ +#define __LUCI_IR_CIRCLESQUAREDIFFERENCE_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/AttrFusedActFunc.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/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/CircleTranspose.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleTranspose.h new file mode 100644 index 000000000..198b56afd --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleTranspose.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_CIRCLETRANSPOSE_H__ +#define __LUCI_IR_CIRCLETRANSPOSE_H__ + +#include "luci/IR/CircleNodeDecl.h" +#include "luci/IR/CircleOpcode.h" + +#include "luci/IR/AttrFusedActFunc.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..54a0d010c --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleTransposeConv.h @@ -0,0 +1,64 @@ +/* + * 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/AttrFusedActFunc.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<3, CircleNodeImpl<CircleOpcode::TRANSPOSE_CONV>> +{ +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); } + +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; + Stride _stride; +}; + +} // namespace luci + +#endif // __LUCI_IR_CIRCLETRANSPOSECONV_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..a4814ee48 --- /dev/null +++ b/compiler/luci/lang/include/luci/IR/VariadicArityNode.h @@ -0,0 +1,77 @@ +/* + * 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 + { + assert(n < _args.size()); + 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 + { + assert(n < _args.size()); + return _args.at(n).get(); + } + +private: + std::vector<std::unique_ptr<loco::Use>> _args; +}; + +} // namespace luci + +#endif // __LUCI_IR_VARIADICARITYNODES_H__ diff --git a/compiler/luci/lang/src/Check.h b/compiler/luci/lang/src/Check.h new file mode 100644 index 000000000..e05ec904a --- /dev/null +++ b/compiler/luci/lang/src/Check.h @@ -0,0 +1,35 @@ +/* + * 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 __CHECK_H__ +#define __CHECK_H__ + +#include <stdexcept> +#include <cassert> +#include <iostream> + +// TODO Add macro for Release version + +#define LUCI_ASSERT(condition, msg) \ + { \ + if (!(condition)) \ + { \ + std::cerr << "[assert failed] " << (msg) << ". " << std::endl; \ + assert((condition)); \ + } \ + } + +#endif // __CHECK_H__ diff --git a/compiler/luci/lang/src/CircleDialect.cpp b/compiler/luci/lang/src/CircleDialect.cpp new file mode 100644 index 000000000..e1c925de4 --- /dev/null +++ b/compiler/luci/lang/src/CircleDialect.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "luci/IR/CircleDialect.h" +#include "luci/IR/Nodes/CircleInput.h" +#include "luci/IR/Nodes/CircleOutput.h" + +#include <loco/IR/Graph.h> +#include <loco/IR/GraphInputIndex.h> +#include <loco/IR/GraphOutputIndex.h> + +#include <cassert> +#include <memory> + +namespace +{ + +struct GiiQueryServiceImpl final : public loco::GraphInputIndexQueryService +{ + bool associated(const loco::Node *node) const final + { + if (auto circleinput = dynamic_cast<const luci::CircleInput *>(node)) + { + return circleinput->indexed(); + } + return false; + } + + loco::GraphOutputIndex index(const loco::Node *node) const final + { + assert(associated(node)); + auto circleinput = dynamic_cast<const luci::CircleInput *>(node); + assert(circleinput != nullptr); + return circleinput->index(); + } +}; + +struct GoiQueryServiceImpl final : public loco::GraphOutputIndexQueryService +{ + bool associated(const loco::Node *node) const final + { + if (auto circleoutput = dynamic_cast<const luci::CircleOutput *>(node)) + { + return circleoutput->indexed(); + } + return false; + } + + loco::GraphOutputIndex index(const loco::Node *node) const final + { + assert(associated(node)); + auto circleoutput = dynamic_cast<const luci::CircleOutput *>(node); + assert(circleoutput != nullptr); + return circleoutput->index(); + } +}; + +} // namespace + +namespace luci +{ + +CircleDialect::CircleDialect() +{ + service<loco::GraphInputIndexQueryService>(std::make_unique<GiiQueryServiceImpl>()); + service<loco::GraphOutputIndexQueryService>(std::make_unique<GoiQueryServiceImpl>()); +} + +loco::Dialect *CircleDialect::get(void) +{ + static CircleDialect d; + return &d; +} + +} // namespace luci diff --git a/compiler/luci/lang/src/CircleDialect.test.cpp b/compiler/luci/lang/src/CircleDialect.test.cpp new file mode 100644 index 000000000..78221f199 --- /dev/null +++ b/compiler/luci/lang/src/CircleDialect.test.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "luci/IR/CircleDialect.h" + +#include <gtest/gtest.h> + +TEST(CircleDialectTest, get_P) +{ + auto d = luci::CircleDialect::get(); + + // get() SHOULD return a valid(non-null) pointer + ASSERT_NE(d, nullptr); + // The return value SHOULD be stable across multiple invocations + ASSERT_EQ(d, luci::CircleDialect::get()); +} + +TEST(CircleDialectTest, get_N) +{ + // TBD +} diff --git a/compiler/luci/lang/src/CircleNode.cpp b/compiler/luci/lang/src/CircleNode.cpp new file mode 100644 index 000000000..cc273ba91 --- /dev/null +++ b/compiler/luci/lang/src/CircleNode.cpp @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "luci/IR/CircleNode.h" +#include "luci/IR/CircleDialect.h" + +namespace luci +{ + +const loco::Dialect *CircleNode::dialect(void) const { return CircleDialect::get(); } + +} // namespace luci diff --git a/compiler/luci/lang/src/CircleNodes.cpp b/compiler/luci/lang/src/CircleNodes.cpp new file mode 100644 index 000000000..76ff7ec5a --- /dev/null +++ b/compiler/luci/lang/src/CircleNodes.cpp @@ -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. + */ + +#include "luci/IR/CircleNodes.h" + +#include "Check.h" + +#include <loco.h> + +namespace luci +{ + +void set_new_shape(CircleReshape *node, int32_t *base, uint32_t size) +{ + // Check node does not have both of new shape infos + LUCI_ASSERT(node->shape() == nullptr, "node already has shape input"); + LUCI_ASSERT(node->newShape()->rank() == 0, "node already has newShape attribute"); + + const loco::DataType S32 = loco::DataType::S32; + + // Set 2nd input as CircleConst + auto const_shape_node = node->graph()->nodes()->create<CircleConst>(); + const_shape_node->rank(1); + const_shape_node->dim(0) = size; + const_shape_node->dtype(S32); + const_shape_node->size<S32>(size); + for (uint32_t axis = 0; axis < size; ++axis) + const_shape_node->at<S32>(axis) = base[axis]; + node->shape(const_shape_node); + + // Set newShape attribute + node->newShape()->rank(size); + for (uint32_t axis = 0; axis < size; ++axis) + node->newShape()->dim(axis) = base[axis]; +} + +} // namespace luci diff --git a/compiler/luci/lang/src/LuciNodeMixins.cpp b/compiler/luci/lang/src/LuciNodeMixins.cpp new file mode 100644 index 000000000..660cbe1a5 --- /dev/null +++ b/compiler/luci/lang/src/LuciNodeMixins.cpp @@ -0,0 +1,18 @@ +/* + * 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. + */ + +// This is to validate LuciNodeMixins.h +#include "luci/IR/LuciNodeMixins.h" diff --git a/compiler/luci/lang/src/Module.cpp b/compiler/luci/lang/src/Module.cpp new file mode 100644 index 000000000..e52d897a5 --- /dev/null +++ b/compiler/luci/lang/src/Module.cpp @@ -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. + */ + +#include "luci/IR/Module.h" + +#include <stdexcept> + +namespace luci +{ + +void Module::add(std::unique_ptr<loco::Graph> &&g) +{ + if (g.get() == nullptr) + throw std::invalid_argument("Module: Graph cannot be null"); + + _graphs.emplace_back(std::move(g)); +} + +loco::Graph *Module::graph(void) const +{ + auto &graph = _graphs.at(0); + return graph.get(); +} + +loco::Graph *Module::graph(size_t idx) const +{ + auto &graph = _graphs.at(idx); + return graph.get(); +} + +std::unique_ptr<Module> make_module(void) { return std::make_unique<Module>(); } + +} // namespace loco diff --git a/compiler/luci/lang/src/Module.test.cpp b/compiler/luci/lang/src/Module.test.cpp new file mode 100644 index 000000000..f60319944 --- /dev/null +++ b/compiler/luci/lang/src/Module.test.cpp @@ -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. + */ + +#include "luci/IR/Module.h" + +#include <gtest/gtest.h> + +TEST(ModuleTest, consturctor) +{ + auto gs = luci::make_module(); + + GTEST_SUCCEED(); +} + +TEST(ModuleTest, add) +{ + auto m = luci::make_module(); + auto g = loco::make_graph(); + auto g_ptr = g.get(); + + m->add(std::move(g)); + + ASSERT_EQ(m->graph(), g_ptr); + ASSERT_EQ(m->graph(0), g_ptr); +} + +TEST(ModuleTest, add_more) +{ + auto m = luci::make_module(); + auto g1 = loco::make_graph(); + auto g2 = loco::make_graph(); + auto g3 = loco::make_graph(); + auto g1_ptr = g1.get(); + auto g2_ptr = g2.get(); + auto g3_ptr = g3.get(); + + m->add(std::move(g1)); + m->add(std::move(g2)); + m->add(std::move(g3)); + + ASSERT_EQ(m->size(), 3); + ASSERT_EQ(m->graph(), g1_ptr); + ASSERT_EQ(m->graph(0), g1_ptr); + ASSERT_EQ(m->graph(1), g2_ptr); + ASSERT_EQ(m->graph(2), g3_ptr); +} + +TEST(ModuleTest, add_nullptr_NEG) +{ + auto m = luci::make_module(); + + EXPECT_THROW(m->add(nullptr), std::invalid_argument); +} + +TEST(ModuleTest, graph_index_overflow_NEG) +{ + auto m = luci::make_module(); + + EXPECT_ANY_THROW(m->graph(100)); +} diff --git a/compiler/luci/lang/src/Nodes/CircleAbs.test.cpp b/compiler/luci/lang/src/Nodes/CircleAbs.test.cpp new file mode 100644 index 000000000..847f1500b --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleAbs.test.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "luci/IR/Nodes/CircleAbs.h" + +#include "luci/IR/CircleDialect.h" + +#include <gtest/gtest.h> + +TEST(CircleAbsTest, constructor) +{ + luci::CircleAbs abs_node; + + ASSERT_EQ(abs_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(abs_node.opcode(), luci::CircleOpcode::ABS); + + ASSERT_EQ(abs_node.x(), nullptr); +} diff --git a/compiler/luci/lang/src/Nodes/CircleAdd.test.cpp b/compiler/luci/lang/src/Nodes/CircleAdd.test.cpp new file mode 100644 index 000000000..a7701963d --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleAdd.test.cpp @@ -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. + */ + +#include "luci/IR/Nodes/CircleAdd.h" + +#include "luci/IR/CircleDialect.h" + +#include <gtest/gtest.h> + +TEST(CircleAddTest, constructor_P) +{ + luci::CircleAdd add_node; + + ASSERT_EQ(add_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(add_node.opcode(), luci::CircleOpcode::ADD); + + ASSERT_EQ(add_node.x(), nullptr); + ASSERT_EQ(add_node.y(), nullptr); +} diff --git a/compiler/luci/lang/src/Nodes/CircleArgMax.test.cpp b/compiler/luci/lang/src/Nodes/CircleArgMax.test.cpp new file mode 100644 index 000000000..6b2cff11c --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleArgMax.test.cpp @@ -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. + */ + +#include "luci/IR/Nodes/CircleArgMax.h" + +#include "luci/IR/CircleDialect.h" + +#include <gtest/gtest.h> + +TEST(CircleArgMaxTest, constructor_P) +{ + luci::CircleArgMax add_node; + + ASSERT_EQ(add_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(add_node.opcode(), luci::CircleOpcode::ARG_MAX); + + ASSERT_EQ(add_node.input(), nullptr); + ASSERT_EQ(add_node.dimension(), nullptr); +} diff --git a/compiler/luci/lang/src/Nodes/CircleBatchToSpaceND.test.cpp b/compiler/luci/lang/src/Nodes/CircleBatchToSpaceND.test.cpp new file mode 100644 index 000000000..e995718a1 --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleBatchToSpaceND.test.cpp @@ -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. + */ + +#include "luci/IR/Nodes/CircleBatchToSpaceND.h" + +#include "luci/IR/CircleDialect.h" + +#include <gtest/gtest.h> + +TEST(CircleBatchToSpaceNDTest, constructor) +{ + luci::CircleBatchToSpaceND bts_node; + + ASSERT_EQ(bts_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(bts_node.opcode(), luci::CircleOpcode::BATCH_TO_SPACE_ND); + + ASSERT_EQ(bts_node.input(), nullptr); + ASSERT_EQ(bts_node.block_shape(), nullptr); + ASSERT_EQ(bts_node.crops(), nullptr); +} diff --git a/compiler/luci/lang/src/Nodes/CircleConcatenation.test.cpp b/compiler/luci/lang/src/Nodes/CircleConcatenation.test.cpp new file mode 100644 index 000000000..7167682b2 --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleConcatenation.test.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "luci/IR/Nodes/CircleConcatenation.h" + +#include "luci/IR/CircleDialect.h" + +#include <gtest/gtest.h> + +TEST(CircleConcatenationTest, constructor_P) +{ + luci::CircleConcatenation concat_node(3); + + ASSERT_EQ(concat_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(concat_node.opcode(), luci::CircleOpcode::CONCATENATION); + + ASSERT_EQ(concat_node.numValues(), 3); + ASSERT_EQ(concat_node.values(0), nullptr); + ASSERT_EQ(concat_node.values(1), nullptr); + ASSERT_EQ(concat_node.values(2), nullptr); + ASSERT_EQ(concat_node.fusedActivationFunction(), luci::FusedActFunc::UNDEFINED); +} diff --git a/compiler/luci/lang/src/Nodes/CircleConst.cpp b/compiler/luci/lang/src/Nodes/CircleConst.cpp new file mode 100644 index 000000000..1c46884d8 --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleConst.cpp @@ -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. + */ + +#include "luci/IR/Nodes/CircleConst.h" + +#include <cassert> + +namespace luci +{ + +template <loco::DataType DT> uint32_t CircleConst::size(void) const +{ + assert(dtype() == DT); + assert(_data.size() % sizeof(typename loco::DataTypeImpl<DT>::Type) == 0); + return _data.size() / sizeof(typename loco::DataTypeImpl<DT>::Type); +} + +template <loco::DataType DT> void CircleConst::size(uint32_t l) +{ + assert(dtype() == DT); + _data.resize(l * sizeof(typename loco::DataTypeImpl<DT>::Type)); +} + +template <loco::DataType DT> +const typename loco::DataTypeImpl<DT>::Type &CircleConst::at(uint32_t n) const +{ + assert(dtype() == DT); + assert(n < size<DT>()); + return *(reinterpret_cast<const typename loco::DataTypeImpl<DT>::Type *>(_data.data()) + n); +} + +template <loco::DataType DT> typename loco::DataTypeImpl<DT>::Type &CircleConst::at(uint32_t n) +{ + assert(dtype() == DT); + assert(n < size<DT>()); + return *(reinterpret_cast<typename loco::DataTypeImpl<DT>::Type *>(_data.data()) + n); +} + +template <loco::DataType DT> +const typename loco::DataTypeImpl<DT>::Type &CircleConst::scalar(void) const +{ + assert(dtype() == DT); + return *(reinterpret_cast<const typename loco::DataTypeImpl<DT>::Type *>(_data.data())); +} + +template <loco::DataType DT> typename loco::DataTypeImpl<DT>::Type &CircleConst::scalar(void) +{ + assert(dtype() == DT); + return *(reinterpret_cast<typename loco::DataTypeImpl<DT>::Type *>(_data.data())); +} + +#define INSTANTIATE(DT) \ + template uint32_t CircleConst::size<DT>(void) const; \ + template void CircleConst::size<DT>(uint32_t); \ + template const typename loco::DataTypeImpl<DT>::Type &CircleConst::at<DT>(uint32_t) const; \ + template typename loco::DataTypeImpl<DT>::Type &CircleConst::at<DT>(uint32_t); \ + template const typename loco::DataTypeImpl<DT>::Type &CircleConst::scalar<DT>(void) const; \ + template typename loco::DataTypeImpl<DT>::Type &CircleConst::scalar<DT>(void); + +INSTANTIATE(loco::DataType::S32); +INSTANTIATE(loco::DataType::FLOAT32); +INSTANTIATE(loco::DataType::U8); + +#undef INSTANTIATE + +} // namespace luci diff --git a/compiler/luci/lang/src/Nodes/CircleConv2D.test.cpp b/compiler/luci/lang/src/Nodes/CircleConv2D.test.cpp new file mode 100644 index 000000000..7931c7eba --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleConv2D.test.cpp @@ -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. + */ + +#include "luci/IR/Nodes/CircleConv2D.h" + +#include "luci/IR/CircleDialect.h" + +#include <gtest/gtest.h> + +TEST(CircleConv2Dest, constructor_P) +{ + luci::CircleConv2D conv2d_node; + + ASSERT_EQ(conv2d_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(conv2d_node.opcode(), luci::CircleOpcode::CONV_2D); + + ASSERT_EQ(conv2d_node.input(), nullptr); + ASSERT_EQ(conv2d_node.filter(), nullptr); + ASSERT_EQ(conv2d_node.bias(), nullptr); +} diff --git a/compiler/luci/lang/src/Nodes/CircleCos.test.cpp b/compiler/luci/lang/src/Nodes/CircleCos.test.cpp new file mode 100644 index 000000000..34c2cfdf0 --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleCos.test.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "luci/IR/Nodes/CircleCos.h" + +#include "luci/IR/CircleDialect.h" + +#include <gtest/gtest.h> + +TEST(CircleCosTest, constructor_P) +{ + luci::CircleCos cos_node; + + ASSERT_EQ(cos_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(cos_node.opcode(), luci::CircleOpcode::COS); + + ASSERT_EQ(cos_node.x(), nullptr); +} diff --git a/compiler/luci/lang/src/Nodes/CircleDepthwiseConv2D.test.cpp b/compiler/luci/lang/src/Nodes/CircleDepthwiseConv2D.test.cpp new file mode 100644 index 000000000..bbc1ea543 --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleDepthwiseConv2D.test.cpp @@ -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. + */ + +#include "luci/IR/Nodes/CircleDepthwiseConv2D.h" + +#include "luci/IR/CircleDialect.h" + +#include <gtest/gtest.h> + +TEST(CircleDepthwiseConv2DTest, constructor_P) +{ + luci::CircleDepthwiseConv2D dw_conv2d_node; + + ASSERT_EQ(dw_conv2d_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(dw_conv2d_node.opcode(), luci::CircleOpcode::DEPTHWISE_CONV_2D); + + ASSERT_EQ(dw_conv2d_node.input(), nullptr); + ASSERT_EQ(dw_conv2d_node.filter(), nullptr); + ASSERT_EQ(dw_conv2d_node.bias(), nullptr); + ASSERT_EQ(dw_conv2d_node.padding(), luci::Padding::UNDEFINED); + ASSERT_EQ(dw_conv2d_node.stride()->h(), 1); + ASSERT_EQ(dw_conv2d_node.stride()->w(), 1); + ASSERT_EQ(dw_conv2d_node.depthMultiplier(), 0); + ASSERT_EQ(dw_conv2d_node.fusedActivationFunction(), luci::FusedActFunc::UNDEFINED); +} diff --git a/compiler/luci/lang/src/Nodes/CircleDiv.test.cpp b/compiler/luci/lang/src/Nodes/CircleDiv.test.cpp new file mode 100644 index 000000000..e950cc6be --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleDiv.test.cpp @@ -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. + */ + +#include "luci/IR/Nodes/CircleDiv.h" + +#include "luci/IR/CircleDialect.h" + +#include <gtest/gtest.h> + +TEST(CircleDivTest, constructor_P) +{ + luci::CircleDiv div_node; + + ASSERT_EQ(div_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(div_node.opcode(), luci::CircleOpcode::DIV); + + ASSERT_EQ(div_node.x(), nullptr); + ASSERT_EQ(div_node.y(), nullptr); +} diff --git a/compiler/luci/lang/src/Nodes/CircleEqual.test.cpp b/compiler/luci/lang/src/Nodes/CircleEqual.test.cpp new file mode 100644 index 000000000..e2757f094 --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleEqual.test.cpp @@ -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. + */ + +#include "luci/IR/Nodes/CircleEqual.h" + +#include "luci/IR/CircleDialect.h" + +#include <gtest/gtest.h> + +TEST(CircleEqualTest, constructor_P) +{ + luci::CircleEqual or_node; + + ASSERT_EQ(or_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(or_node.opcode(), luci::CircleOpcode::EQUAL); + + ASSERT_EQ(or_node.x(), nullptr); + ASSERT_EQ(or_node.y(), nullptr); +} diff --git a/compiler/luci/lang/src/Nodes/CircleExp.test.cpp b/compiler/luci/lang/src/Nodes/CircleExp.test.cpp new file mode 100644 index 000000000..db10d0b03 --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleExp.test.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "luci/IR/Nodes/CircleExp.h" + +#include "luci/IR/CircleDialect.h" + +#include <gtest/gtest.h> + +TEST(CircleExpTest, constructor) +{ + luci::CircleExp exp_node; + + ASSERT_EQ(exp_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(exp_node.opcode(), luci::CircleOpcode::EXP); + + ASSERT_EQ(exp_node.x(), nullptr); +} diff --git a/compiler/luci/lang/src/Nodes/CircleFullyConnected.test.cpp b/compiler/luci/lang/src/Nodes/CircleFullyConnected.test.cpp new file mode 100644 index 000000000..994dcd239 --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleFullyConnected.test.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "luci/IR/Nodes/CircleFullyConnected.h" + +#include "luci/IR/CircleDialect.h" + +#include <gtest/gtest.h> + +TEST(CircleFullyConnectedTest, constructor) +{ + luci::CircleFullyConnected fc_node; + + ASSERT_EQ(fc_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(fc_node.opcode(), luci::CircleOpcode::FULLY_CONNECTED); + + ASSERT_EQ(fc_node.input(), nullptr); + ASSERT_EQ(fc_node.weights(), nullptr); + ASSERT_EQ(fc_node.bias(), nullptr); + ASSERT_EQ(fc_node.fusedActivationFunction(), luci::FusedActFunc::UNDEFINED); +} diff --git a/compiler/luci/lang/src/Nodes/CircleGather.test.cpp b/compiler/luci/lang/src/Nodes/CircleGather.test.cpp new file mode 100644 index 000000000..4eace9a02 --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleGather.test.cpp @@ -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. + */ + +#include "luci/IR/Nodes/CircleGather.h" + +#include "luci/IR/CircleDialect.h" + +#include <gtest/gtest.h> + +TEST(CircleGatherTest, constructor) +{ + luci::CircleGather gather_node; + + ASSERT_EQ(gather_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(gather_node.opcode(), luci::CircleOpcode::GATHER); + + ASSERT_EQ(gather_node.input(), nullptr); + ASSERT_EQ(gather_node.positions(), nullptr); + ASSERT_EQ(gather_node.axis(), 0); +} diff --git a/compiler/luci/lang/src/Nodes/CircleInput.cpp b/compiler/luci/lang/src/Nodes/CircleInput.cpp new file mode 100644 index 000000000..dcf54f3b0 --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleInput.cpp @@ -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. + */ + +#include "luci/IR/Nodes/CircleInput.h" + +#include <cassert> +#include <limits> + +namespace luci +{ + +void CircleInput::index(const loco::GraphInputIndex &index) +{ + // CircleInput internally stores "GraphInputIndex" as int64_t + _index = static_cast<int64_t>(index); +} + +loco::GraphInputIndex CircleInput::index(void) const +{ + assert(_index >= std::numeric_limits<loco::GraphInputIndex>::min()); + assert(_index <= std::numeric_limits<loco::GraphInputIndex>::max()); + return static_cast<loco::GraphInputIndex>(_index); +} + +} // namespace luci diff --git a/compiler/luci/lang/src/Nodes/CircleInstanceNorm.test.cpp b/compiler/luci/lang/src/Nodes/CircleInstanceNorm.test.cpp new file mode 100644 index 000000000..b87e81791 --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleInstanceNorm.test.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "luci/IR/Nodes/CircleInstanceNorm.h" + +#include "luci/IR/CircleDialect.h" + +#include <gtest/gtest.h> + +TEST(CircleInstanceNormTest, constructor) +{ + luci::CircleInstanceNorm instance_norm; + + ASSERT_EQ(instance_norm.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(instance_norm.opcode(), luci::CircleOpcode::INSTANCE_NORM); + + ASSERT_EQ(instance_norm.input(), nullptr); + ASSERT_EQ(instance_norm.gamma(), nullptr); + ASSERT_EQ(instance_norm.beta(), nullptr); + ASSERT_FLOAT_EQ(instance_norm.epsilon(), 1e-05); + ASSERT_EQ(instance_norm.fusedActivationFunction(), luci::FusedActFunc::UNDEFINED); +} diff --git a/compiler/luci/lang/src/Nodes/CircleLogicalNot.test.cpp b/compiler/luci/lang/src/Nodes/CircleLogicalNot.test.cpp new file mode 100644 index 000000000..360dd4711 --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleLogicalNot.test.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "luci/IR/Nodes/CircleLogicalNot.h" + +#include "luci/IR/CircleDialect.h" + +#include <gtest/gtest.h> + +TEST(CircleLogicalNotTest, constructor_P) +{ + luci::CircleLogicalNot not_node; + + ASSERT_EQ(not_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(not_node.opcode(), luci::CircleOpcode::LOGICAL_NOT); + + ASSERT_EQ(not_node.x(), nullptr); +} diff --git a/compiler/luci/lang/src/Nodes/CircleLogicalOr.test.cpp b/compiler/luci/lang/src/Nodes/CircleLogicalOr.test.cpp new file mode 100644 index 000000000..039db4afc --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleLogicalOr.test.cpp @@ -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. + */ + +#include "luci/IR/Nodes/CircleLogicalOr.h" + +#include "luci/IR/CircleDialect.h" + +#include <gtest/gtest.h> + +TEST(CircleLogicalOrTest, constructor_P) +{ + luci::CircleLogicalOr or_node; + + ASSERT_EQ(or_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(or_node.opcode(), luci::CircleOpcode::LOGICAL_OR); + + ASSERT_EQ(or_node.x(), nullptr); + ASSERT_EQ(or_node.y(), nullptr); +} diff --git a/compiler/luci/lang/src/Nodes/CircleMaxPool2D.test.cpp b/compiler/luci/lang/src/Nodes/CircleMaxPool2D.test.cpp new file mode 100644 index 000000000..874ecec0e --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleMaxPool2D.test.cpp @@ -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. + */ + +#include "luci/IR/Nodes/CircleMaxPool2D.h" + +#include "luci/IR/CircleDialect.h" + +#include <gtest/gtest.h> + +TEST(CircleMaxPool2DTest, constructor_P) +{ + luci::CircleMaxPool2D maxpool2d_node; + + ASSERT_EQ(maxpool2d_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(maxpool2d_node.opcode(), luci::CircleOpcode::MAX_POOL_2D); + + ASSERT_EQ(maxpool2d_node.value(), nullptr); + ASSERT_NE(maxpool2d_node.filter(), nullptr); + ASSERT_NE(maxpool2d_node.stride(), nullptr); +} diff --git a/compiler/luci/lang/src/Nodes/CircleMaximum.test.cpp b/compiler/luci/lang/src/Nodes/CircleMaximum.test.cpp new file mode 100644 index 000000000..efe62f11a --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleMaximum.test.cpp @@ -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. + */ + +#include "luci/IR/Nodes/CircleMaximum.h" + +#include "luci/IR/CircleDialect.h" + +#include <gtest/gtest.h> + +TEST(CircleMaximumTest, constructor_P) +{ + luci::CircleMaximum max_node; + + ASSERT_EQ(max_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(max_node.opcode(), luci::CircleOpcode::MAXIMUM); + + ASSERT_EQ(max_node.x(), nullptr); + ASSERT_EQ(max_node.y(), nullptr); +} diff --git a/compiler/luci/lang/src/Nodes/CircleMul.test.cpp b/compiler/luci/lang/src/Nodes/CircleMul.test.cpp new file mode 100644 index 000000000..f9eca42f9 --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleMul.test.cpp @@ -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. + */ + +#include "luci/IR/Nodes/CircleMul.h" + +#include "luci/IR/CircleDialect.h" + +#include <gtest/gtest.h> + +TEST(CircleMulTest, constructor_P) +{ + luci::CircleMul mul_node; + + ASSERT_EQ(mul_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(mul_node.opcode(), luci::CircleOpcode::MUL); + + ASSERT_EQ(mul_node.x(), nullptr); + ASSERT_EQ(mul_node.y(), nullptr); +} diff --git a/compiler/luci/lang/src/Nodes/CircleOutput.cpp b/compiler/luci/lang/src/Nodes/CircleOutput.cpp new file mode 100644 index 000000000..31380456f --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleOutput.cpp @@ -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. + */ + +#include "luci/IR/Nodes/CircleOutput.h" + +#include <cassert> +#include <limits> + +namespace luci +{ + +void CircleOutput::index(const loco::GraphOutputIndex &index) +{ + // CircleOutput internally stores "GraphOutputIndex" as int64_t + _index = static_cast<int64_t>(index); +} + +loco::GraphOutputIndex CircleOutput::index(void) const +{ + assert(_index >= std::numeric_limits<loco::GraphOutputIndex>::min()); + assert(_index <= std::numeric_limits<loco::GraphOutputIndex>::max()); + return static_cast<loco::GraphOutputIndex>(_index); +} + +} // namespace luci diff --git a/compiler/luci/lang/src/Nodes/CirclePack.test.cpp b/compiler/luci/lang/src/Nodes/CirclePack.test.cpp new file mode 100644 index 000000000..5c9a96f7c --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CirclePack.test.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "luci/IR/Nodes/CirclePack.h" + +#include "luci/IR/CircleDialect.h" + +#include <gtest/gtest.h> + +TEST(CirclePackTest, constructor) +{ + luci::CirclePack pack_node(3); + + ASSERT_EQ(pack_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(pack_node.opcode(), luci::CircleOpcode::PACK); + + ASSERT_EQ(pack_node.axis(), 0); + ASSERT_EQ(pack_node.values_count(), 3); + ASSERT_EQ(pack_node.values(0), nullptr); + ASSERT_EQ(pack_node.values(1), nullptr); + ASSERT_EQ(pack_node.values(2), nullptr); +} diff --git a/compiler/luci/lang/src/Nodes/CirclePad.test.cpp b/compiler/luci/lang/src/Nodes/CirclePad.test.cpp new file mode 100644 index 000000000..3a23fa0f0 --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CirclePad.test.cpp @@ -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. + */ + +#include "luci/IR/Nodes/CirclePad.h" + +#include "luci/IR/CircleDialect.h" + +#include <gtest/gtest.h> + +TEST(CirclePadTest, constructor_P) +{ + luci::CirclePad pad_node; + + ASSERT_EQ(pad_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(pad_node.opcode(), luci::CircleOpcode::PAD); + + ASSERT_EQ(pad_node.input(), nullptr); + ASSERT_EQ(pad_node.paddings(), nullptr); +} diff --git a/compiler/luci/lang/src/Nodes/CircleRelu.test.cpp b/compiler/luci/lang/src/Nodes/CircleRelu.test.cpp new file mode 100644 index 000000000..19ea88aa6 --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleRelu.test.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "luci/IR/Nodes/CircleRelu.h" + +#include "luci/IR/CircleDialect.h" + +#include <gtest/gtest.h> + +TEST(CircleReluTest, constructor_P) +{ + luci::CircleRelu relu_node; + + ASSERT_EQ(relu_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(relu_node.opcode(), luci::CircleOpcode::RELU); + + ASSERT_EQ(relu_node.features(), nullptr); +} diff --git a/compiler/luci/lang/src/Nodes/CircleRelu6.test.cpp b/compiler/luci/lang/src/Nodes/CircleRelu6.test.cpp new file mode 100644 index 000000000..74bf2e86a --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleRelu6.test.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "luci/IR/Nodes/CircleRelu6.h" + +#include "luci/IR/CircleDialect.h" + +#include <gtest/gtest.h> + +TEST(CircleRelu6Test, constructor_P) +{ + luci::CircleRelu6 relu6_node; + + ASSERT_EQ(relu6_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(relu6_node.opcode(), luci::CircleOpcode::RELU6); + + ASSERT_EQ(relu6_node.features(), nullptr); +} diff --git a/compiler/luci/lang/src/Nodes/CircleReshape.test.cpp b/compiler/luci/lang/src/Nodes/CircleReshape.test.cpp new file mode 100644 index 000000000..7bc2d32a4 --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleReshape.test.cpp @@ -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. + */ + +#include "luci/IR/Nodes/CircleReshape.h" + +#include "luci/IR/CircleDialect.h" + +#include <gtest/gtest.h> + +TEST(CircleReshapeTest, constructor_P) +{ + luci::CircleReshape reshape; + + ASSERT_EQ(reshape.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(reshape.opcode(), luci::CircleOpcode::RESHAPE); + + ASSERT_EQ(reshape.tensor(), nullptr); + ASSERT_EQ(reshape.shape(), nullptr); + ASSERT_EQ(reshape.newShape()->rank(), 0); +} + +TEST(CircleReshapeTest, alloc_new_shape_P) +{ + luci::CircleReshape reshape; + + reshape.newShape()->rank(2); + ASSERT_EQ(reshape.newShape()->rank(), 2); + + reshape.newShape()->dim(0) = 0; + reshape.newShape()->dim(1) = 1; + + auto &const_reshape = const_cast<const luci::CircleReshape &>(reshape); + ASSERT_EQ(const_reshape.newShape()->dim(0), 0); + ASSERT_EQ(const_reshape.newShape()->dim(1), 1); +} diff --git a/compiler/luci/lang/src/Nodes/CircleRsqrt.test.cpp b/compiler/luci/lang/src/Nodes/CircleRsqrt.test.cpp new file mode 100644 index 000000000..51f6bab36 --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleRsqrt.test.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "luci/IR/Nodes/CircleRsqrt.h" + +#include "luci/IR/CircleDialect.h" + +#include <gtest/gtest.h> + +TEST(CircleRsqrtTest, constructor) +{ + luci::CircleRsqrt rsqrt_node; + + ASSERT_EQ(rsqrt_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(rsqrt_node.opcode(), luci::CircleOpcode::RSQRT); + + ASSERT_EQ(rsqrt_node.x(), nullptr); +} diff --git a/compiler/luci/lang/src/Nodes/CircleSoftmax.test.cpp b/compiler/luci/lang/src/Nodes/CircleSoftmax.test.cpp new file mode 100644 index 000000000..7e994490c --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleSoftmax.test.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "luci/IR/Nodes/CircleSoftmax.h" + +#include "luci/IR/CircleDialect.h" + +#include <gtest/gtest.h> + +TEST(CircleSoftmaxTest, constructor_P) +{ + luci::CircleSoftmax softmax_node; + + ASSERT_EQ(softmax_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(softmax_node.opcode(), luci::CircleOpcode::SOFTMAX); + + ASSERT_EQ(softmax_node.logits(), nullptr); +} diff --git a/compiler/luci/lang/src/Nodes/CircleSqrt.test.cpp b/compiler/luci/lang/src/Nodes/CircleSqrt.test.cpp new file mode 100644 index 000000000..6cfb3bc94 --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleSqrt.test.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "luci/IR/Nodes/CircleSqrt.h" + +#include "luci/IR/CircleDialect.h" + +#include <gtest/gtest.h> + +TEST(CircleSqrtTest, constructor_P) +{ + luci::CircleSqrt sqrt_node; + + ASSERT_EQ(sqrt_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(sqrt_node.opcode(), luci::CircleOpcode::SQRT); + + ASSERT_EQ(sqrt_node.x(), nullptr); +} diff --git a/compiler/luci/lang/src/Nodes/CircleSquaredDifference.test.cpp b/compiler/luci/lang/src/Nodes/CircleSquaredDifference.test.cpp new file mode 100644 index 000000000..71df189b9 --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleSquaredDifference.test.cpp @@ -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. + */ + +#include "luci/IR/Nodes/CircleSquaredDifference.h" + +#include "luci/IR/CircleDialect.h" + +#include <gtest/gtest.h> + +TEST(CircleSquaredDifferenceTest, constructor_P) +{ + luci::CircleSquaredDifference sd_node; + + ASSERT_EQ(sd_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(sd_node.opcode(), luci::CircleOpcode::SQUARED_DIFFERENCE); + + ASSERT_EQ(sd_node.x(), nullptr); + ASSERT_EQ(sd_node.y(), nullptr); +} diff --git a/compiler/luci/lang/src/Nodes/CircleSub.test.cpp b/compiler/luci/lang/src/Nodes/CircleSub.test.cpp new file mode 100644 index 000000000..ebb29446a --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleSub.test.cpp @@ -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. + */ + +#include "luci/IR/Nodes/CircleSub.h" + +#include "luci/IR/CircleDialect.h" + +#include <gtest/gtest.h> + +TEST(CircleSubTest, constructor_P) +{ + luci::CircleSub sub_node; + + ASSERT_EQ(sub_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(sub_node.opcode(), luci::CircleOpcode::SUB); + + ASSERT_EQ(sub_node.x(), nullptr); + ASSERT_EQ(sub_node.y(), nullptr); +} diff --git a/compiler/luci/lang/src/Nodes/CircleTranspose.test.cpp b/compiler/luci/lang/src/Nodes/CircleTranspose.test.cpp new file mode 100644 index 000000000..7233869e6 --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleTranspose.test.cpp @@ -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. + */ + +#include "luci/IR/Nodes/CircleTranspose.h" + +#include "luci/IR/CircleDialect.h" + +#include <gtest/gtest.h> + +TEST(CircleTransposeTest, constructor_P) +{ + luci::CircleTranspose tr_node; + + ASSERT_EQ(tr_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(tr_node.opcode(), luci::CircleOpcode::TRANSPOSE); + + ASSERT_EQ(tr_node.a(), nullptr); + ASSERT_EQ(tr_node.perm(), nullptr); +} diff --git a/compiler/luci/lang/src/Nodes/CircleTransposeConv.test.cpp b/compiler/luci/lang/src/Nodes/CircleTransposeConv.test.cpp new file mode 100644 index 000000000..9615082d9 --- /dev/null +++ b/compiler/luci/lang/src/Nodes/CircleTransposeConv.test.cpp @@ -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. + */ + +#include "luci/IR/Nodes/CircleTransposeConv.h" + +#include "luci/IR/CircleDialect.h" + +#include <gtest/gtest.h> + +TEST(CircleTransposeConvTest, constructor_P) +{ + luci::CircleTransposeConv trc_node; + + ASSERT_EQ(trc_node.dialect(), luci::CircleDialect::get()); + ASSERT_EQ(trc_node.opcode(), luci::CircleOpcode::TRANSPOSE_CONV); + + ASSERT_EQ(trc_node.inputSizes(), nullptr); + ASSERT_EQ(trc_node.filter(), nullptr); + ASSERT_EQ(trc_node.outBackprop(), nullptr); +} |