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

Method backward_workspace_size_in_bytes

dnn/src/naive/rnn/rnn.cpp:104–139  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

102}
103
104size_t CellWeightsWrapperBase::backward_workspace_size_in_bytes(
105 Handle* handle, size_t batch_size, size_t hidden_size, size_t input_size,
106 size_t num_chunks, DType dtype) {
107 size_t gate_hidden_size = hidden_size * num_chunks;
108 TensorLayout tmp = {{batch_size, gate_hidden_size}, dtype};
109 TensorLayout bias_expanded = {{1, gate_hidden_size}, dtype};
110 TensorLayout wih = {{gate_hidden_size, input_size}, dtype};
111 TensorLayout whh = {{gate_hidden_size, hidden_size}, dtype};
112 TensorLayout x = {{batch_size, input_size}, dtype};
113 TensorLayout hx = {{batch_size, hidden_size}, dtype};
114 size_t workspace_size = 0;
115 auto matrixmul_opr = handle->create_operator<MatrixMulForward>();
116 matrixmul_opr->param().transposeA = false;
117 matrixmul_opr->param().transposeB = false;
118 // dx
119 workspace_size = std::max(
120 workspace_size, matrixmul_opr->get_workspace_in_bytes(tmp, wih, x));
121 // dhx
122 workspace_size = std::max(
123 workspace_size, matrixmul_opr->get_workspace_in_bytes(tmp, whh, hx));
124 // dwi
125 matrixmul_opr->param().transposeA = true;
126 workspace_size = std::max(
127 workspace_size, matrixmul_opr->get_workspace_in_bytes(tmp, x, wih));
128 // dwh
129 workspace_size = std::max(
130 workspace_size, matrixmul_opr->get_workspace_in_bytes(tmp, hx, whh));
131 // dbias
132 auto sum_opr = handle->create_operator<ReduceForward>();
133 sum_opr->param().mode = ReduceForward::Mode::SUM;
134 sum_opr->param().axis = 0;
135 workspace_size = std::max(
136 workspace_size, sum_opr->get_workspace_in_bytes(tmp, bias_expanded));
137 workspace_size += tmp.span().dist_byte();
138 return workspace_size;
139}
140
141RNNCellWeightWrapper::RNNCellWeightWrapper(
142 void* weight_ptr, size_t hidden_size, size_t input_size, bool has_bias,

Callers

nothing calls this directly

Calls 6

maxFunction · 0.85
dist_byteMethod · 0.80
spanMethod · 0.80
paramMethod · 0.45
deduce_layoutMethod · 0.45

Tested by

no test coverage detected