hl_recurrent_apply.cuh 7.6 KB
Newer Older
1
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
Z
zhangjinchao01 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192

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 HL_RECURRENT_APPLY_CUH_
#define HL_RECURRENT_APPLY_CUH_

#include "hl_base.h"
#include "hl_activation_functions.h"
#include "hl_lstm_ops.cuh"
#include "hl_gpu_lstm.cuh"
#include "hl_cpu_lstm.cuh"
#include "hl_gru_ops.cuh"
#include "hl_gpu_gru.cuh"
#include "hl_cpu_gru.cuh"

/**
 * @brief   Cpu lstm forward one sequence.
 *
 * @param[in]   op                  hl_lstm_ops.cuh
 * @param[out]  value               hl_lstm_value type.
 * @param[in]   frameSize           frame size.
 * @param[in]   active_node         active input type.
 * @param[in]   active_gate         active state type.
 * @param[in]   active_state        actvie gate type.
 */
template<class Op>
extern void hl_cpu_lstm_forward(Op op,
                                hl_lstm_value value,
                                int frameSize,
                                hl_activation_mode_t active_node,
                                hl_activation_mode_t active_gate,
                                hl_activation_mode_t active_state);

/**
 * @brief   Cpu lstm backward one sequence.
 *
 * @param[in]   op                  hl_lstm_ops.cuh
 * @param[in]   value               lstm value.
 * @param[out]  grad                output gradient.
 * @param[in]   frameSize           frame size.
 * @param[in]   active_node         active input type.
 * @param[in]   active_gate         active state type.
 * @param[in]   active_state        actvie gate type.
 */
template<class Op>
extern void hl_cpu_lstm_backward(Op op,
                                 hl_lstm_value value,
                                 hl_lstm_grad grad,
                                 int frameSize,
                                 hl_activation_mode_t active_node,
                                 hl_activation_mode_t active_gate,
                                 hl_activation_mode_t active_state);

/**
 * @brief   Gpu lstm batch forward.
 *
 * @param[in]   op                  hl_lstm_ops.cuh
 * @param[out]  value               lstm value.
 * @param[in]   frameSize           frame size.
 * @param[in]   batchSize           size of current batch.
 * @param[in]   active_node         active input type.
 * @param[in]   active_gate         active state type.
 * @param[in]   active_state        actvie gate type.
 */
template<class Op>
extern void hl_gpu_lstm_forward(Op op,
                                hl_lstm_value value,
                                int frameSize,
                                int batchSize,
                                hl_activation_mode_t active_node,
                                hl_activation_mode_t active_gate,
                                hl_activation_mode_t active_state);

/**
 * @brief   Gpu lstm batch backward.
 *
 * @param[in]   op                  hl_lstm_ops.cuh
 * @param[out]  value               lstm value.
 * @param[out]  grad                lstm gradient.
 * @param[in]   frameSize           frame size.
 * @param[in]   batchSize           size of current batch.
 * @param[in]   active_node         active input type.
 * @param[in]   active_gate         active state type.
 * @param[in]   active_state        actvie gate type.
 */
template<class Op>
extern void hl_gpu_lstm_backward(Op op,
                                 hl_lstm_value value,
                                 hl_lstm_grad grad,
                                 int frameSize,
                                 int batchSize,
                                 hl_activation_mode_t active_node,
                                 hl_activation_mode_t active_gate,
                                 hl_activation_mode_t active_state);

/**
 * @brief   Cpu gru forward.
 *
 * @param[in]     opResetOutput   hl_gru_ops.cuh
 * @param[in]     opFinalOutput   hl_gru_ops.cuh
 * @param[in,out] value           gru value.
 * @param[in]     frameSize       frame length/size.
 * @param[in]     batchSize       size of current batch.
 * @param[in]     active_node     active input type.
 * @param[in]     active_gate     active state type.
 */
template<class OpResetOutput, class OpFinalOutput>
extern void hl_cpu_gru_forward(OpResetOutput opResetOutput,
                               OpFinalOutput opFinalOutput,
                               hl_gru_value value,
                               int frameSize,
                               int batchSize,
                               hl_activation_mode_t active_node,
                               hl_activation_mode_t active_gate);

/**
 * @brief   Cpu gru forward.
 *
 * @param[in]     opStateGrad     hl_gru_ops.cuh
 * @param[in]     opResetGrad     hl_gru_ops.cuh
 * @param[in]     value           gru value.
 * @param[in,out] grad            gru gradient.
 * @param[in]     frameSize       frame length/size.
 * @param[in]     batchSize       size of current batch.
 * @param[in]     active_node     active input type.
 * @param[in]     active_gate     active state type.
 */
template<class OpStateGrad, class OpResetGrad>
extern void hl_cpu_gru_backward(OpStateGrad opStateGrad,
                                OpResetGrad opResetGrad,
                                hl_gru_value value,
                                hl_gru_grad  grad,
                                int frameSize,
                                int batchSize,
                                hl_activation_mode_t active_node,
                                hl_activation_mode_t active_gate);

/**
 * @brief   Gpu gru forward.
 *
 * @param[in]     opResetOutput   hl_gru_ops.cuh
 * @param[in]     opFinalOutput   hl_gru_ops.cuh
 * @param[in,out] value           gru value.
 * @param[in]     frameSize       frame length/size.
 * @param[in]     batchSize       size of current batch.
 * @param[in]     active_node     active input type.
 * @param[in]     active_gate     active state type.
 */
template<class OpResetOutput, class OpFinalOutput>
extern void hl_gpu_gru_forward(OpResetOutput opResetOutput,
                               OpFinalOutput opFinalOutput,
                               hl_gru_value value,
                               int frameSize,
                               int batchSize,
                               hl_activation_mode_t active_node,
                               hl_activation_mode_t active_gate);

/**
 * @brief   Gpu gru forward.
 *
 * @param[in]     opStateGrad     hl_gru_ops.cuh
 * @param[in]     opResetGrad     hl_gru_ops.cuh
 * @param[in]     value           gru value.
 * @param[in,out] grad            gru gradient.
 * @param[in]     frameSize       frame length/size.
 * @param[in]     batchSize       size of current batch.
 * @param[in]     active_node     active input type.
 * @param[in]     active_gate     active state type.
 */
template<class OpStateGrad, class OpResetGrad>
extern void hl_gpu_gru_backward(OpStateGrad opStateGrad,
                                OpResetGrad opResetGrad,
                                hl_gru_value value,
                                hl_gru_grad  grad,
                                int frameSize,
                                int batchSize,
                                hl_activation_mode_t active_node,
                                hl_activation_mode_t active_gate);

#endif /* HL_RECURRENT_APPLY_CUH_ */