| 18 | } |
| 19 | |
| 20 | void LSTMCell::check_exec( |
| 21 | const TensorLayout& input, const TensorLayout& weight_ih, |
| 22 | const TensorLayout& bias_ih, const TensorLayout& hx, |
| 23 | const TensorLayout& weight_hh, const TensorLayout& bias_hh, |
| 24 | const TensorLayout& cx, const TensorLayout& h_new, const TensorLayout& c_new, |
| 25 | const TensorLayout& gates, size_t workspace_in_bytes) { |
| 26 | TensorLayout h_new_expected, c_new_expected, gates_expected; |
| 27 | auto errmsg = [&]() { |
| 28 | std::string msg; |
| 29 | msg.append("input="); |
| 30 | msg.append(input.to_string()); |
| 31 | msg.append(", weight_ih="); |
| 32 | msg.append(weight_ih.to_string()); |
| 33 | msg.append(", bias_ih="); |
| 34 | msg.append(bias_ih.to_string()); |
| 35 | msg.append(", hx="); |
| 36 | msg.append(hx.to_string()); |
| 37 | msg.append(", weight_hh="); |
| 38 | msg.append(weight_hh.to_string()); |
| 39 | msg.append(", bias_hh="); |
| 40 | msg.append(bias_hh.to_string()); |
| 41 | msg.append(", cx="); |
| 42 | msg.append(cx.to_string()); |
| 43 | return msg; |
| 44 | }; |
| 45 | #define ASSERT_BRIEF(_content) megdnn_assert(_content, "%s", errmsg().c_str()); |
| 46 | |
| 47 | ASSERT_BRIEF(input.ndim == 2) |
| 48 | ASSERT_BRIEF(input.shape[1] == weight_ih.shape[1]) |
| 49 | ASSERT_BRIEF(weight_ih.shape[0] == weight_hh.shape[0]) |
| 50 | ASSERT_BRIEF(weight_hh.shape[0] == 4 * weight_hh.shape[1]) |
| 51 | ASSERT_BRIEF(bias_ih.shape[0] == bias_hh.shape[0]) |
| 52 | ASSERT_BRIEF(hx.ndim == 2) |
| 53 | ASSERT_BRIEF(hx.shape[0] == input.shape[0]) |
| 54 | ASSERT_BRIEF(hx.shape[1] == cx.shape[1]) // hidden_size |
| 55 | ASSERT_BRIEF(cx.ndim == 2) |
| 56 | ASSERT_BRIEF(cx.shape[0] == input.shape[0]) |
| 57 | ASSERT_BRIEF(cx.shape[1] == weight_hh.shape[1]) |
| 58 | #undef ASSERT_BRIEF |
| 59 | |
| 60 | deduce_layout( |
| 61 | input, weight_ih, bias_ih, hx, weight_hh, bias_hh, cx, h_new_expected, |
| 62 | c_new_expected, gates_expected); |
| 63 | megdnn_assert_eq_layout(h_new_expected, h_new); |
| 64 | megdnn_assert_eq_layout(c_new_expected, c_new); |
| 65 | megdnn_assert_eq_layout(gates_expected, gates); |
| 66 | |
| 67 | auto required_workspace_in_bytes = get_workspace_in_bytes( |
| 68 | input, weight_ih, bias_ih, hx, weight_hh, bias_hh, cx, h_new, c_new, gates); |
| 69 | megdnn_assert(workspace_in_bytes >= required_workspace_in_bytes); |
| 70 | } |
| 71 | |
| 72 | } // namespace megdnn |
| 73 |
nothing calls this directly
no test coverage detected