1 /*
2  * Copyright (C) 2020 The Android Open Source Project
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 #ifndef ANDROID_PACKAGES_MODULES_NEURALNETWORKS_COMMON_TYPES_OPERATIONS_QLSTM_H
18 #define ANDROID_PACKAGES_MODULES_NEURALNETWORKS_COMMON_TYPES_OPERATIONS_QLSTM_H
19 
20 #include "OperationsValidationUtils.h"
21 
22 namespace android::nn::qlstm {
23 
24 // Inputs
25 constexpr uint32_t kNumInputs = 32;
26 
27 constexpr uint32_t kInputTensor = 0;
28 // Input weight tensors of size: [numUnits, inputSize].
29 constexpr uint32_t kInputToInputWeightsTensor = 1;
30 constexpr uint32_t kInputToForgetWeightsTensor = 2;
31 constexpr uint32_t kInputToCellWeightsTensor = 3;
32 constexpr uint32_t kInputToOutputWeightsTensor = 4;
33 
34 // Recurrent weight tensors of size [numUnits, outputSize].
35 constexpr uint32_t kRecurrentToInputWeightsTensor = 5;
36 constexpr uint32_t kRecurrentToForgetWeightsTensor = 6;
37 constexpr uint32_t kRecurrentToCellWeightsTensor = 7;
38 constexpr uint32_t kRecurrentToOutputWeightsTensor = 8;
39 
40 // For peephole (optional).
41 // Cell to input/forget/output weights of size [numUnits].
42 constexpr uint32_t kCellToInputWeightsTensor = 9;
43 constexpr uint32_t kCellToForgetWeightsTensor = 10;
44 constexpr uint32_t kCellToOutputWeightsTensor = 11;
45 
46 // Gates bias tensors of size [numUnits].
47 constexpr uint32_t kInputGateBiasTensor = 12;
48 constexpr uint32_t kForgetGateBiasTensor = 13;
49 constexpr uint32_t kCellGateBiasTensor = 14;
50 constexpr uint32_t kOutputGateBiasTensor = 15;
51 
52 // Projection weight tensor of size [outputSize, numUnits].
53 constexpr uint32_t kProjectionWeightsTensor = 16;
54 // Projection bias tensor of size [outputSize].
55 constexpr uint32_t kProjectionBiasTensor = 17;
56 
57 // Output from the previous time step, as tensor
58 // of size [numBatches, outputSize].
59 constexpr uint32_t kPrevOutputTensor = 18;
60 
61 // Cell state from the previous time step, as tensor
62 // of size [numBatches, numUnits].
63 constexpr uint32_t kPrevCellStateTensor = 19;
64 
65 // Layer normalization tensors of size [numUnits].
66 constexpr uint32_t kInputLayerNormTensor = 20;
67 constexpr uint32_t kForgetLayerNormTensor = 21;
68 constexpr uint32_t kCellLayerNormTensor = 22;
69 constexpr uint32_t kOutputLayerNormTensor = 23;
70 
71 // Clipping.
72 constexpr uint32_t kCellClip = 24;
73 constexpr uint32_t kProjectionClip = 25;
74 
75 // Scales of the result of matmul, i.e. input to layer normalization.
76 constexpr uint32_t kInputIntermediateScale = 26;
77 constexpr uint32_t kForgetIntermediateScale = 27;
78 constexpr uint32_t kCellIntermediateScale = 28;
79 constexpr uint32_t kOutputIntermediateScale = 29;
80 
81 // Zero point and scale of hidden state.
82 constexpr uint32_t kHiddenStateZeroPoint = 30;
83 constexpr uint32_t kHiddenStateScale = 31;
84 
85 // Outputs:
86 constexpr uint32_t kNumOutputs = 3;
87 constexpr uint32_t kOutputStateOutTensor = 0;
88 constexpr uint32_t kCellStateOutTensor = 1;
89 constexpr uint32_t kOutputTensor = 2;
90 
91 }  // namespace android::nn::qlstm
92 
93 #endif  // ANDROID_PACKAGES_MODULES_NEURALNETWORKS_COMMON_TYPES_OPERATIONS_QLSTM_H
94