summaryrefslogtreecommitdiff
path: root/compiler/luci/lang/include
diff options
context:
space:
mode:
authorChunseok Lee <chunseok.lee@samsung.com>2020-10-28 12:16:55 +0900
committerChunseok Lee <chunseok.lee@samsung.com>2020-10-28 12:16:55 +0900
commitc55f8a6db48cda9d3a78048338b7f18c4cca62b8 (patch)
tree761ee8e171e5203f5c598ad93b2e7e0bc2e31aa2 /compiler/luci/lang/include
parent74476a2d0296bdad70a2f7f90bc7419a8b05bffd (diff)
downloadnnfw-c55f8a6db48cda9d3a78048338b7f18c4cca62b8.tar.gz
nnfw-c55f8a6db48cda9d3a78048338b7f18c4cca62b8.tar.bz2
nnfw-c55f8a6db48cda9d3a78048338b7f18c4cca62b8.zip
Diffstat (limited to 'compiler/luci/lang/include')
-rw-r--r--compiler/luci/lang/include/luci/IR/AttrFusedActFunc.h4
-rw-r--r--compiler/luci/lang/include/luci/IR/CircleNodeDecl.h8
-rw-r--r--compiler/luci/lang/include/luci/IR/CircleNodes.h2
-rw-r--r--compiler/luci/lang/include/luci/IR/CircleNodes.lst2
-rw-r--r--compiler/luci/lang/include/luci/IR/Nodes/CircleDequantize.h40
-rw-r--r--compiler/luci/lang/include/luci/IR/Nodes/CircleUnidirectionalSequenceLSTM.h115
-rw-r--r--compiler/luci/lang/include/luci/IR/SparsityParam.h233
7 files changed, 403 insertions, 1 deletions
diff --git a/compiler/luci/lang/include/luci/IR/AttrFusedActFunc.h b/compiler/luci/lang/include/luci/IR/AttrFusedActFunc.h
index 2abae604b..3f21d5858 100644
--- a/compiler/luci/lang/include/luci/IR/AttrFusedActFunc.h
+++ b/compiler/luci/lang/include/luci/IR/AttrFusedActFunc.h
@@ -28,7 +28,9 @@ enum class FusedActFunc
NONE,
RELU,
RELU_N1_TO_1,
- RELU6
+ RELU6,
+ TANH,
+ SIGN_BIT
};
} // namespace luci
diff --git a/compiler/luci/lang/include/luci/IR/CircleNodeDecl.h b/compiler/luci/lang/include/luci/IR/CircleNodeDecl.h
index 967103e3c..edec9d18b 100644
--- a/compiler/luci/lang/include/luci/IR/CircleNodeDecl.h
+++ b/compiler/luci/lang/include/luci/IR/CircleNodeDecl.h
@@ -25,6 +25,7 @@
#include "CircleOpcode.h"
#include "CircleNodeVisitor.forward.h"
#include "CircleQuantParam.h"
+#include "SparsityParam.h"
#include <memory>
@@ -54,6 +55,12 @@ struct CircleNode : public loco::Node,
_quantparam = std::move(quantparam);
}
+ SparsityParam *sparsityparam(void) const { return _sparsityparam.get(); }
+ void sparsityparam(std::unique_ptr<SparsityParam> &&sparsityparam)
+ {
+ _sparsityparam = std::move(sparsityparam);
+ }
+
ShapeStatus shape_status(void) const { return _shape_status; }
void shape_status(ShapeStatus ss) { _shape_status = ss; }
@@ -63,6 +70,7 @@ struct CircleNode : public loco::Node,
private:
NodeName _name;
std::unique_ptr<CircleQuantParam> _quantparam;
+ std::unique_ptr<SparsityParam> _sparsityparam;
ShapeStatus _shape_status{ShapeStatus::UNDEFINED};
int32_t _op_version = 1;
};
diff --git a/compiler/luci/lang/include/luci/IR/CircleNodes.h b/compiler/luci/lang/include/luci/IR/CircleNodes.h
index 25b86d2e9..fde0b612b 100644
--- a/compiler/luci/lang/include/luci/IR/CircleNodes.h
+++ b/compiler/luci/lang/include/luci/IR/CircleNodes.h
@@ -34,6 +34,7 @@
#include "Nodes/CircleCustom.h"
#include "Nodes/CircleDepthToSpace.h"
#include "Nodes/CircleDepthwiseConv2D.h"
+#include "Nodes/CircleDequantize.h"
#include "Nodes/CircleDiv.h"
#include "Nodes/CircleElu.h"
#include "Nodes/CircleEqual.h"
@@ -120,6 +121,7 @@
#include "Nodes/CircleTopKV2.h"
#include "Nodes/CircleTranspose.h"
#include "Nodes/CircleTransposeConv.h"
+#include "Nodes/CircleUnidirectionalSequenceLSTM.h"
#include "Nodes/CircleUnique.h"
#include "Nodes/CircleUnpack.h"
#include "Nodes/CircleWhere.h"
diff --git a/compiler/luci/lang/include/luci/IR/CircleNodes.lst b/compiler/luci/lang/include/luci/IR/CircleNodes.lst
index 9f0a1b16e..b9d545893 100644
--- a/compiler/luci/lang/include/luci/IR/CircleNodes.lst
+++ b/compiler/luci/lang/include/luci/IR/CircleNodes.lst
@@ -27,6 +27,7 @@ CIRCLE_NODE(COS, luci::CircleCos)
CIRCLE_NODE(CUSTOM, luci::CircleCustom)
CIRCLE_NODE(DEPTH_TO_SPACE, luci::CircleDepthToSpace)
CIRCLE_NODE(DEPTHWISE_CONV_2D, luci::CircleDepthwiseConv2D)
+CIRCLE_NODE(DEQUANTIZE, luci::CircleDequantize)
CIRCLE_NODE(DIV, luci::CircleDiv)
CIRCLE_NODE(ELU, luci::CircleElu)
CIRCLE_NODE(EQUAL, luci::CircleEqual)
@@ -113,6 +114,7 @@ CIRCLE_NODE(TILE, luci::CircleTile)
CIRCLE_NODE(TOPK_V2, luci::CircleTopKV2)
CIRCLE_NODE(TRANSPOSE, luci::CircleTranspose)
CIRCLE_NODE(TRANSPOSE_CONV, luci::CircleTransposeConv)
+CIRCLE_NODE(UNIDIRECTIONAL_SEQUENCE_LSTM, luci::CircleUnidirectionalSequenceLSTM)
CIRCLE_NODE(UNIQUE, luci::CircleUnique)
CIRCLE_NODE(UNPACK, luci::CircleUnpack)
CIRCLE_NODE(WHERE, luci::CircleWhere)
diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleDequantize.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleDequantize.h
new file mode 100644
index 000000000..847c5dfc5
--- /dev/null
+++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleDequantize.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __LUCI_IR_CIRCELEDEQUANTIZE_H__
+#define __LUCI_IR_CIRCELEDEQUANTIZE_H__
+
+#include "luci/IR/CircleNodeDecl.h"
+#include "luci/IR/CircleOpcode.h"
+
+#include "luci/IR/LuciNodeMixins.h"
+
+namespace luci
+{
+
+/**
+ * @brief DEQUANTIZE in Circle
+ */
+class CircleDequantize final : public FixedArityNode<1, CircleNodeImpl<CircleOpcode::DEQUANTIZE>>
+{
+public:
+ loco::Node *input(void) const { return at(0)->node(); }
+ void input(loco::Node *node) { at(0)->node(node); }
+};
+
+} // namespace luci
+
+#endif // __LUCI_IR_CIRCELEDEQUANTIZE_H__
diff --git a/compiler/luci/lang/include/luci/IR/Nodes/CircleUnidirectionalSequenceLSTM.h b/compiler/luci/lang/include/luci/IR/Nodes/CircleUnidirectionalSequenceLSTM.h
new file mode 100644
index 000000000..4352b045b
--- /dev/null
+++ b/compiler/luci/lang/include/luci/IR/Nodes/CircleUnidirectionalSequenceLSTM.h
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __LUCI_IR_CIRCLEUNIDIRECTIONALSEQUENCELSTM_H__
+#define __LUCI_IR_CIRCLEUNIDIRECTIONALSEQUENCELSTM_H__
+
+#include "luci/IR/CircleNodeDecl.h"
+#include "luci/IR/CircleOpcode.h"
+
+#include "luci/IR/AttrFusedActFunc.h"
+#include "luci/IR/LuciNodeMixins.h"
+
+namespace luci
+{
+
+/**
+ * @brief UNIDIRECTIONAL_SEQUENCE_LSTM in Circle
+ */
+class CircleUnidirectionalSequenceLSTM final
+ : public FixedArityNode<24, CircleNodeImpl<CircleOpcode::UNIDIRECTIONAL_SEQUENCE_LSTM>>,
+ public LuciNodeMixin<LuciNodeTrait::FusedActFunc>
+{
+public:
+ loco::Node *input(void) const { return at(0)->node(); }
+ void input(loco::Node *node) { at(0)->node(node); }
+
+ loco::Node *input_to_input_weights(void) const { return at(1)->node(); }
+ void input_to_input_weights(loco::Node *node) { at(1)->node(node); }
+ loco::Node *input_to_forget_weights(void) const { return at(2)->node(); }
+ void input_to_forget_weights(loco::Node *node) { at(2)->node(node); }
+ loco::Node *input_to_cell_weights(void) const { return at(3)->node(); }
+ void input_to_cell_weights(loco::Node *node) { at(3)->node(node); }
+ loco::Node *input_to_output_weights(void) const { return at(4)->node(); }
+ void input_to_output_weights(loco::Node *node) { at(4)->node(node); }
+
+ loco::Node *recurrent_to_input_weights(void) const { return at(5)->node(); }
+ void recurrent_to_input_weights(loco::Node *node) { at(5)->node(node); }
+ loco::Node *recurrent_to_forget_weights(void) const { return at(6)->node(); }
+ void recurrent_to_forget_weights(loco::Node *node) { at(6)->node(node); }
+ loco::Node *recurrent_to_cell_weights(void) const { return at(7)->node(); }
+ void recurrent_to_cell_weights(loco::Node *node) { at(7)->node(node); }
+ loco::Node *recurrent_to_output_weights(void) const { return at(8)->node(); }
+ void recurrent_to_output_weights(loco::Node *node) { at(8)->node(node); }
+
+ loco::Node *cell_to_input_weights(void) const { return at(9)->node(); }
+ void cell_to_input_weights(loco::Node *node) { at(9)->node(node); }
+ loco::Node *cell_to_forget_weights(void) const { return at(10)->node(); }
+ void cell_to_forget_weights(loco::Node *node) { at(10)->node(node); }
+ loco::Node *cell_to_output_weights(void) const { return at(11)->node(); }
+ void cell_to_output_weights(loco::Node *node) { at(11)->node(node); }
+
+ loco::Node *input_gate_bias(void) const { return at(12)->node(); }
+ void input_gate_bias(loco::Node *node) { at(12)->node(node); }
+ loco::Node *forget_gate_bias(void) const { return at(13)->node(); }
+ void forget_gate_bias(loco::Node *node) { at(13)->node(node); }
+ loco::Node *cell_gate_bias(void) const { return at(14)->node(); }
+ void cell_gate_bias(loco::Node *node) { at(14)->node(node); }
+ loco::Node *output_gate_bias(void) const { return at(15)->node(); }
+ void output_gate_bias(loco::Node *node) { at(15)->node(node); }
+
+ loco::Node *projection_weights(void) const { return at(16)->node(); }
+ void projection_weights(loco::Node *node) { at(16)->node(node); }
+ loco::Node *projection_bias(void) const { return at(17)->node(); }
+ void projection_bias(loco::Node *node) { at(17)->node(node); }
+
+ loco::Node *activation_state(void) const { return at(18)->node(); }
+ void activation_state(loco::Node *node) { at(18)->node(node); }
+ loco::Node *cell_state(void) const { return at(19)->node(); }
+ void cell_state(loco::Node *node) { at(19)->node(node); }
+
+ loco::Node *input_layer_norm_coefficients(void) const { return at(20)->node(); }
+ void input_layer_norm_coefficients(loco::Node *node) { at(20)->node(node); }
+ loco::Node *forget_layer_norm_coefficients(void) const { return at(21)->node(); }
+ void forget_layer_norm_coefficients(loco::Node *node) { at(21)->node(node); }
+ loco::Node *cell_layer_norm_coefficients(void) const { return at(22)->node(); }
+ void cell_layer_norm_coefficients(loco::Node *node) { at(22)->node(node); }
+ loco::Node *output_layer_norm_coefficients(void) const { return at(23)->node(); }
+ void output_layer_norm_coefficients(loco::Node *node) { at(23)->node(node); }
+
+public:
+ float cell_clip(void) const { return _cell_clip; }
+ void cell_clip(float cell_clip) { _cell_clip = cell_clip; }
+ float proj_clip(void) const { return _proj_clip; }
+ void proj_clip(float proj_clip) { _proj_clip = proj_clip; }
+ bool time_major(void) const { return _time_major; }
+ void time_major(bool time_major) { _time_major = time_major; }
+ bool asymmetric_quantize_inputs(void) const { return _asymmetric_quantize_inputs; }
+ void asymmetric_quantize_inputs(bool asymmetric_quantize_inputs)
+ {
+ _asymmetric_quantize_inputs = asymmetric_quantize_inputs;
+ }
+
+private:
+ float _cell_clip = 0.0f;
+ float _proj_clip = 0.0f;
+ bool _time_major = false;
+ bool _asymmetric_quantize_inputs = false;
+};
+
+} // namespace luci
+
+#endif // __LUCI_IR_CIRCLEUNIDIRECTIONALSEQUENCELSTM_H__
diff --git a/compiler/luci/lang/include/luci/IR/SparsityParam.h b/compiler/luci/lang/include/luci/IR/SparsityParam.h
new file mode 100644
index 000000000..f471e5ef9
--- /dev/null
+++ b/compiler/luci/lang/include/luci/IR/SparsityParam.h
@@ -0,0 +1,233 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __LUCI_IR_SPARSITYPARAM_H__
+#define __LUCI_IR_SPARSITYPARAM_H__
+
+#include <cstdint>
+#include <stdexcept>
+#include <utility>
+#include <vector>
+
+namespace luci
+{
+
+enum DimensionType
+{
+ DENSE,
+ SPARSE_CSR,
+};
+
+enum SparseIndexVectorType
+{
+ NONE,
+ I32,
+ U16,
+ U8,
+};
+
+class SparseIndexVector
+{
+public:
+ SparseIndexVector() = default;
+ SparseIndexVector(const SparseIndexVectorType &type, const std::vector<int32_t> &sparse_index_vec)
+ : _type{type}
+ {
+ switch (type)
+ {
+ case SparseIndexVectorType::NONE:
+ break;
+ case SparseIndexVectorType::I32:
+ {
+ _vec_ptr = static_cast<void *>(
+ new std::vector<int32_t>(sparse_index_vec.begin(), sparse_index_vec.end()));
+ break;
+ }
+ case SparseIndexVectorType::U16:
+ {
+ auto new_vec = new std::vector<uint16_t>(sparse_index_vec.size());
+ for (uint32_t idx = 0; idx < sparse_index_vec.size(); idx++)
+ {
+ new_vec->at(idx) = static_cast<uint16_t>(sparse_index_vec.at(idx));
+ }
+ _vec_ptr = static_cast<void *>(new_vec);
+ break;
+ }
+ case SparseIndexVectorType::U8:
+ {
+ auto new_vec = new std::vector<uint8_t>(sparse_index_vec.size());
+ for (uint32_t idx = 0; idx < sparse_index_vec.size(); idx++)
+ {
+ new_vec->at(idx) = static_cast<uint8_t>(sparse_index_vec.at(idx));
+ }
+ _vec_ptr = static_cast<void *>(new_vec);
+ break;
+ }
+ default:
+ std::runtime_error("Invalid SparseIndexVectorType");
+ }
+ }
+
+ SparseIndexVector(SparseIndexVectorType type, const void *sparse_index_vec) : _type{type}
+ {
+ switch (type)
+ {
+ case SparseIndexVectorType::NONE:
+ break;
+ case SparseIndexVectorType::I32:
+ {
+ const std::vector<int32_t> *vec =
+ static_cast<const std::vector<int32_t> *>(sparse_index_vec);
+ _vec_ptr = static_cast<void *>(new std::vector<int32_t>(vec->begin(), vec->end()));
+ break;
+ }
+ case SparseIndexVectorType::U16:
+ {
+ const std::vector<uint16_t> *vec =
+ static_cast<const std::vector<uint16_t> *>(sparse_index_vec);
+ _vec_ptr = static_cast<void *>(new std::vector<uint16_t>(vec->begin(), vec->end()));
+ break;
+ }
+ case SparseIndexVectorType::U8:
+ {
+ const std::vector<uint8_t> *vec =
+ static_cast<const std::vector<uint8_t> *>(sparse_index_vec);
+ _vec_ptr = static_cast<void *>(new std::vector<uint8_t>(vec->begin(), vec->end()));
+ break;
+ }
+ default:
+ std::runtime_error("Invalid SparseIndexVectorType");
+ }
+ }
+
+ SparseIndexVector(const SparseIndexVector &sparse_index_vec)
+ : SparseIndexVector(sparse_index_vec._type, sparse_index_vec._vec_ptr)
+ {
+ }
+
+ SparseIndexVector(SparseIndexVector &&sparse_index_vec)
+ : _type{sparse_index_vec._type}, _vec_ptr{std::exchange(sparse_index_vec._vec_ptr, nullptr)}
+ {
+ }
+
+ SparseIndexVector &operator=(const SparseIndexVector &sparse_index_vec)
+ {
+ return *this = SparseIndexVector(sparse_index_vec);
+ }
+
+ SparseIndexVector &operator=(SparseIndexVector &&sparse_index_vector)
+ {
+ std::swap(_vec_ptr, sparse_index_vector._vec_ptr);
+ std::swap(_type, sparse_index_vector._type);
+ return *this;
+ }
+
+ ~SparseIndexVector()
+ {
+ switch (_type)
+ {
+ case SparseIndexVectorType::NONE:
+ break;
+ case SparseIndexVectorType::I32:
+ {
+ auto vec_ptr = static_cast<std::vector<int32_t> *>(_vec_ptr);
+ delete vec_ptr;
+ break;
+ }
+ case SparseIndexVectorType::U16:
+ {
+ auto vec_ptr = static_cast<std::vector<uint16_t> *>(_vec_ptr);
+ delete vec_ptr;
+ break;
+ }
+ case SparseIndexVectorType::U8:
+ {
+ auto vec_ptr = static_cast<std::vector<uint8_t> *>(_vec_ptr);
+ delete vec_ptr;
+ break;
+ }
+ default:
+ break;
+ }
+ _vec_ptr = nullptr;
+ _type = SparseIndexVectorType::NONE;
+ }
+
+public:
+ SparseIndexVectorType type(void) const { return _type; }
+
+public:
+ const std::vector<int32_t> *as_int32_vector(void) const
+ {
+ return _type == SparseIndexVectorType::I32 ? static_cast<const std::vector<int32_t> *>(_vec_ptr)
+ : nullptr;
+ }
+ const std::vector<uint16_t> *as_uint16_vector(void) const
+ {
+ return _type == SparseIndexVectorType::U16
+ ? static_cast<const std::vector<uint16_t> *>(_vec_ptr)
+ : nullptr;
+ }
+ const std::vector<uint8_t> *as_uint8_vector(void) const
+ {
+ return _type == SparseIndexVectorType::U8 ? static_cast<const std::vector<uint8_t> *>(_vec_ptr)
+ : nullptr;
+ }
+
+private:
+ SparseIndexVectorType _type{SparseIndexVectorType::NONE};
+ void *_vec_ptr{nullptr};
+};
+
+class DimMetaData
+{
+public:
+ DimMetaData() = delete;
+ DimMetaData(DimensionType format, int32_t dense_size) : _format{format}, _dense_size{dense_size}
+ {
+ // DO NOTHING
+ }
+ DimMetaData(DimensionType format, int32_t dense_size, const SparseIndexVector &array_segments,
+ const SparseIndexVector &array_indices)
+ : _format{format}, _dense_size{dense_size}, _array_segments{array_segments},
+ _array_indices{array_indices}
+ {
+ // DO NOTHING
+ }
+
+public:
+ DimensionType format(void) const { return _format; }
+ int32_t dense_size(void) const { return _dense_size; }
+ const SparseIndexVector &array_segments(void) const { return _array_segments; }
+ const SparseIndexVector &array_indices(void) const { return _array_indices; }
+
+private:
+ DimensionType _format{DimensionType::DENSE};
+ int32_t _dense_size{0};
+ SparseIndexVector _array_segments;
+ SparseIndexVector _array_indices;
+};
+
+struct SparsityParam
+{
+ std::vector<int32_t> traversal_order;
+ std::vector<int32_t> block_map;
+ std::vector<DimMetaData> dim_metadata;
+};
+
+} // namespace luci
+
+#endif // __LUCI_IR_SPARSITYPARAM_H__