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

Method get_workspace_in_bytes

dnn/src/naive/rnn/opr_impl.cpp:55–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53}
54
55size_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
74size_t RNNImpl::get_reserve_size_in_bytes(const TensorLayout& input) {
75 size_t num_layers = param().num_layers;

Calls 5

maxFunction · 0.85
dist_byteMethod · 0.80
spanMethod · 0.80
paramFunction · 0.50
handleMethod · 0.45

Tested by

no test coverage detected