MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / exec

Method exec

dnn/src/arm_common/lstm/opr_impl.cpp:13–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11using namespace arm_common;
12
13void LSTMImpl::exec(
14 _megdnn_tensor_in input, _megdnn_tensor_in hx, _megdnn_tensor_in cx,
15 _megdnn_tensor_in flatten_weights, _megdnn_tensor_out output,
16 _megdnn_tensor_out hy, _megdnn_tensor_out cy, _megdnn_tensor_out,
17 _megdnn_workspace workspace) {
18 MIDOUT_BEGIN(megdnn_arm_common_lstm, midout_iv(0)) {
19 size_t dir_size = param().bidirectional ? 2 : 1;
20 size_t num_layers = param().num_layers;
21 size_t hidden_size = param().hidden_size;
22
23 size_t seq_len = input.layout.shape[0];
24 size_t batch_size = input.layout.shape[1];
25 size_t input_size = input.layout.shape[2];
26
27 //! in order to support input ptr change in record, so this task should be
28 //! dispatch to device
29 auto&& cell_weights = get_all_cells<LstmCellWeight>(
30 dir_size, num_layers, input_size, hidden_size, param().bias,
31 flatten_weights);
32 auto&& cell_states_in = get_all_status<LstmStates>(
33 hx, cx, hidden_size, batch_size, num_layers, dir_size, hx.layout.dtype);
34 auto&& cell_states_out = get_all_status<LstmStates>(
35 hy, cy, hidden_size, batch_size, num_layers, dir_size, hy.layout.dtype);
36 auto&& inputs = split_tensor(
37 input, seq_len,
38 TensorLayout{{batch_size, input_size}, input.layout.dtype});
39 auto&& outputs = split_tensor(
40 output, seq_len,
41 TensorLayout{
42 {batch_size, dir_size * hidden_size}, output.layout.dtype});
43
44 auto workspace_bundle = get_workspace_bundle<LSTMCell>(
45 input.layout, output.layout, flatten_weights.layout, hidden_size,
46 dir_size, LstmStates::nr_states());
47
48 workspace_bundle.set(workspace.raw_ptr);
49 exec_kernel<LstmCellWeight, LSTMCell, LstmStates>(
50 cell_weights, inputs, cell_states_in, cell_states_out, outputs,
51 num_layers, dir_size, handle(), workspace_bundle);
52 }
53 MIDOUT_END();
54}
55
56size_t LSTMImpl::get_workspace_in_bytes(
57 const TensorLayout& input, const TensorLayout&, const TensorLayout&,

Callers

nothing calls this directly

Calls 3

MIDOUT_BEGINFunction · 0.50
paramFunction · 0.50
setMethod · 0.45

Tested by

no test coverage detected