1 /**
2 * Copyright 2021 Huawei Technologies Co., Ltd
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "nnacl/infer/lstm_grad_infer.h"
18 #include "nnacl/infer/infer_register.h"
19 #include "nnacl/infer/common_infer.h"
20 #include "nnacl/fp32_grad/lstm_grad_fp32.h"
21
LstmGradInferShape(const TensorC * const * inputs,size_t inputs_size,TensorC ** outputs,size_t outputs_size,OpParameter * parameter)22 int LstmGradInferShape(const TensorC *const *inputs, size_t inputs_size, TensorC **outputs, size_t outputs_size,
23 OpParameter *parameter) {
24 int check_ret = CheckAugmentNullSize(inputs, inputs_size, outputs, outputs_size, parameter, 11, 4);
25 if (check_ret != NNACL_OK) {
26 return check_ret;
27 }
28
29 const TensorC *input = inputs[0];
30 const TensorC *H = inputs[1];
31 const TensorC *C = inputs[2];
32 const TensorC *weight = inputs[3];
33 TensorC *output = outputs[0];
34 for (size_t i = 0; i < outputs_size; i++) {
35 SetDataTypeFormat(outputs[i], input);
36 }
37
38 if (!InferFlag(inputs, inputs_size)) {
39 return NNACL_INFER_INVALID;
40 }
41
42 if (input->shape_size_ != 3 || weight->shape_size_ != 3) {
43 return NNACL_ERR;
44 }
45
46 SetShapeArray(output, input->shape_, input->shape_size_);
47 SetShapeArray(outputs[SECOND_INPUT], H->shape_, H->shape_size_);
48 SetShapeArray(outputs[THIRD_INPUT], C->shape_, C->shape_size_);
49 SetShapeArray(outputs[FOURTH_INPUT], weight->shape_, weight->shape_size_);
50
51 return NNACL_OK;
52 }
53
54 REG_INFER(LSTMGrad, PrimType_LSTMGrad, LstmGradInferShape)
55