-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Micro op lstm #14599
Draft
chunseoklee
wants to merge
4
commits into
Samsung:master
Choose a base branch
from
chunseoklee:micro_op_lstm
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Micro op lstm #14599
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
180 changes: 180 additions & 0 deletions
180
onert-micro/onert-micro/include/execute/kernels/UnidirectionalSequenceLSTM.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
/* | ||
* Copyright (c) 2023 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 ONERT_MICRO_KERNELS_UNIDIRECTIONAL_SEQUENCE_LSTM_H | ||
#define ONERT_MICRO_KERNELS_UNIDIRECTIONAL_SEQUENCE_LSTM_H | ||
|
||
#include "OMStatus.h" | ||
|
||
#include "core/OMUtils.h" | ||
#include "core/OMKernelData.h" | ||
#include "core/OMDataType.h" | ||
|
||
#include "execute/OMKernelExecutionBuilder.h" | ||
#include "execute/OMUtils.h" | ||
#include "execute/OMRuntimeKernel.h" | ||
|
||
using namespace onert_micro::core; | ||
using namespace onert_micro::execute; | ||
|
||
namespace | ||
{ | ||
|
||
int dim(const circle::Tensor *x, int index) | ||
{ | ||
onert_micro::core::OMRuntimeShape shape(x); | ||
return shape.dims(index); | ||
} | ||
|
||
int num_elements(const circle::Tensor *x) | ||
{ | ||
onert_micro::core::OMRuntimeShape shape(x); | ||
return shape.flatSize(); | ||
} | ||
|
||
int num_dims(const circle::Tensor *x) | ||
{ | ||
onert_micro::core::OMRuntimeShape shape(x); | ||
return shape.dimensionsCount(); | ||
} | ||
|
||
} // namespace | ||
namespace onert_micro | ||
{ | ||
namespace lstm | ||
{ | ||
|
||
struct LSTMStruct | ||
{ | ||
LSTMStruct() = delete; | ||
LSTMStruct(const LSTMStruct &) = delete; | ||
|
||
explicit LSTMStruct(const OMExecuteArgs &execute_args) | ||
{ | ||
core::OMRuntimeContext &runtime_context = execute_args.runtime_context; | ||
core::OMRuntimeStorage &runtime_storage = execute_args.runtime_storage; | ||
uint16_t op_index = execute_args.kernel_index; | ||
|
||
execute::OMRuntimeKernel runtime_kernel; | ||
runtime_kernel.readKernel(op_index, runtime_context); | ||
|
||
for (int i; i < 24; i++) | ||
{ | ||
internal_tensors[i] = runtime_kernel.inputs[i]; | ||
} | ||
|
||
output_internal = runtime_kernel.outputs[0]; | ||
|
||
options = runtime_kernel.first_operator->builtin_options_as_UnidirectionalSequenceLSTMOptions(); | ||
} | ||
|
||
void validateTensorTypes() | ||
{ | ||
assert(input()->type() == (output_state()->type())); | ||
assert(output()->type() == (input()->type())); | ||
|
||
for (int32_t i = 1; i < 9; ++i) | ||
{ | ||
assert(internal_tensors[i] == nullptr or | ||
(input_to_forget_weights()->type()) == (internal_tensors[i])->type()); | ||
} | ||
|
||
for (int32_t i = 12; i < 16; ++i) | ||
{ | ||
assert(internal_tensors[i] == nullptr or | ||
(forget_gate_bias()->type()) == (internal_tensors[i]->type())); | ||
} | ||
} | ||
|
||
const circle::Tensor *input() { return internal_tensors[0]; }; | ||
|
||
const circle::Tensor *input_to_input_weights() { return internal_tensors[1]; }; | ||
const circle::Tensor *input_to_forget_weights() { return internal_tensors[2]; }; | ||
const circle::Tensor *input_to_cell_weights() { return internal_tensors[3]; }; | ||
const circle::Tensor *input_to_output_weights() { return internal_tensors[4]; }; | ||
|
||
const circle::Tensor *recurrent_to_input_weights() { return internal_tensors[5]; }; | ||
const circle::Tensor *recurrent_to_forget_weights() { return internal_tensors[6]; }; | ||
const circle::Tensor *recurrent_to_cell_weights() { return internal_tensors[7]; }; | ||
const circle::Tensor *recurrent_to_output_weights() { return internal_tensors[8]; }; | ||
|
||
const circle::Tensor *cell_to_input_weights() { return internal_tensors[9]; }; | ||
const circle::Tensor *cell_to_forget_weights() { return internal_tensors[10]; }; | ||
const circle::Tensor *cell_to_output_weights() { return internal_tensors[11]; }; | ||
|
||
const circle::Tensor *input_gate_bias() { return internal_tensors[12]; }; | ||
const circle::Tensor *forget_gate_bias() { return internal_tensors[13]; }; | ||
const circle::Tensor *cell_gate_bias() { return internal_tensors[14]; }; | ||
const circle::Tensor *output_gate_bias() { return internal_tensors[15]; }; | ||
|
||
const circle::Tensor *projection_weights() { return internal_tensors[16]; }; | ||
const circle::Tensor *projection_bias() { return internal_tensors[17]; }; | ||
|
||
const circle::Tensor *output_state() { return internal_tensors[18]; }; | ||
const circle::Tensor *cell_state() { return internal_tensors[19]; }; | ||
|
||
const circle::Tensor *input_layer_norm_coefficients() { return internal_tensors[20]; }; | ||
const circle::Tensor *forget_layer_norm_coefficients() { return internal_tensors[21]; }; | ||
const circle::Tensor *cell_layer_norm_coefficients() { return internal_tensors[22]; }; | ||
const circle::Tensor *output_layer_norm_coefficients() { return internal_tensors[23]; }; | ||
const circle::Tensor *output() { return output_internal; }; | ||
|
||
const circle::UnidirectionalSequenceLSTMOptions *options; | ||
|
||
const circle::Tensor *get_internal_tensor(int i) { return internal_tensors[i]; } | ||
|
||
private: | ||
const circle::Tensor *output_internal; | ||
const circle::Tensor *internal_tensors[24]; | ||
}; | ||
|
||
struct GateParameters | ||
{ | ||
FullyConnectedParams input_fc_params; | ||
FullyConnectedParams recurrent_fc_params; | ||
}; | ||
|
||
struct InterGateParameters | ||
{ | ||
BinaryArithmeticBroadcastParams forget_cell_mul_params; | ||
BinaryArithmeticBroadcastParams input_mul_params; | ||
BinaryArithmeticBroadcastParams output_mul_params; | ||
}; | ||
|
||
struct CellStateInfo | ||
{ | ||
float cell_clip; | ||
// clipping range for cell state only 16 bits cell is supported (could be | ||
// generalized through templatation) | ||
int16_t quantized_cell_clip; | ||
// 2^-cell_state_scale_power = cell state scale, required by integer tanh | ||
// computation | ||
int32_t cell_state_scale_power; | ||
}; | ||
|
||
struct LSTMParameters | ||
{ | ||
GateParameters forget_gate_parameters; | ||
GateParameters input_gate_parameters; | ||
GateParameters cell_gate_parameters; | ||
GateParameters output_gate_parameters; | ||
InterGateParameters inter_gate_parameters; | ||
}; | ||
|
||
} // namespace lstm | ||
} // namespace onert_micro | ||
|
||
#endif // ONERT_MICRO_KERNELS_UNIDIRECTIONAL_SEQUENCE_LSTM_H |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This statement without zero-initialization for
i
variable