| 53 | } |
| 54 | |
| 55 | size_t RNNImpl::get_workspace_in_bytes( |
| 56 | const TensorLayout& input, const TensorLayout& hx, |
| 57 | const TensorLayout& flatten_weights, const TensorLayout& output, |
| 58 | const TensorLayout& /*hy*/, const TensorLayout& /*reserve_space*/) { |
| 59 | auto _param = param(); |
| 60 | size_t D = _param.bidirectional ? 2 : 1; |
| 61 | size_t last_dim = std::max(input.shape[2], D * hx.shape[1]); |
| 62 | TensorLayout last_input = {{input.shape[0], input.shape[1], last_dim}, input.dtype}; |
| 63 | size_t workspace_size = rnn::get_workspace_in_bytes<RNNCellForward>( |
| 64 | last_input, flatten_weights, param().hidden_size, |
| 65 | param().bidirectional ? 2 : 1, this->handle()); |
| 66 | if (!param().bias) { // use fake bias (all 0) |
| 67 | TensorLayout bias_layout = {{param().hidden_size}, flatten_weights.dtype}; |
| 68 | workspace_size += bias_layout.span().dist_byte(); |
| 69 | } |
| 70 | workspace_size += output.span().dist_byte(); |
| 71 | return workspace_size; |
| 72 | } |
| 73 | |
| 74 | size_t RNNImpl::get_reserve_size_in_bytes(const TensorLayout& input) { |
| 75 | size_t num_layers = param().num_layers; |
no test coverage detected