You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

opr_impl.cpp 2.9 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * \file dnn/src/arm_common/lstm_cell/opr_impl.cpp
  3. * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  4. *
  5. * Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
  6. *
  7. * Unless required by applicable law or agreed to in writing, software
  8. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  9. * ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. */
  11. #include "src/arm_common/lstm_cell/opr_impl.h"
  12. #include "src/common/lstm_cell.h"
  13. #include "src/naive/handle.h"
  14. #include "./cell_kernel.h"
  15. #include "midout.h"
  16. MIDOUT_DECL(megdnn_arm_common_lstm_cell)
  17. using namespace megdnn;
  18. using namespace arm_common;
  19. void LSTMCellImpl::exec(
  20. _megdnn_tensor_in input, _megdnn_tensor_in weight_ih, _megdnn_tensor_in bias_ih,
  21. _megdnn_tensor_in hx, _megdnn_tensor_in weight_hh, _megdnn_tensor_in bias_hh,
  22. _megdnn_tensor_in cx, _megdnn_tensor_out h_new, _megdnn_tensor_out c_new,
  23. _megdnn_tensor_out gates, _megdnn_workspace workspace) {
  24. //! only float32 and {1, xx} shape bias will be optimized
  25. MIDOUT_BEGIN(megdnn_arm_common_lstm_cell, midout_iv(0)) {
  26. if (!LstmCellCompute::is_optimized(
  27. input.layout, weight_ih.layout, bias_ih.layout, hx.layout,
  28. weight_hh.layout, bias_hh.layout, cx.layout, h_new.layout,
  29. c_new.layout, gates.layout)) {
  30. naive::LSTMCellImpl::exec(
  31. input, weight_ih, bias_ih, hx, weight_hh, bias_hh, cx, h_new, c_new,
  32. gates, workspace);
  33. } else {
  34. LstmCellCompute::run(
  35. input, weight_ih, bias_ih, hx, weight_hh, bias_hh, cx, h_new, c_new,
  36. gates, workspace, handle());
  37. }
  38. }
  39. MIDOUT_END();
  40. }
  41. size_t LSTMCellImpl::get_workspace_in_bytes(
  42. const TensorLayout& input, const TensorLayout& weight_ih,
  43. const TensorLayout& bias_ih, const TensorLayout& hx,
  44. const TensorLayout& weight_hh, const TensorLayout& bias_hh,
  45. const TensorLayout& cx, const TensorLayout& h_new, const TensorLayout& c_new,
  46. const TensorLayout& gates) {
  47. MIDOUT_BEGIN(megdnn_arm_common_lstm_cell, midout_iv(1)) {
  48. if (!LstmCellCompute::is_optimized(
  49. input, weight_ih, bias_ih, hx, weight_hh, bias_hh, cx, h_new, c_new,
  50. gates)) {
  51. return naive::LSTMCellImpl::get_workspace_in_bytes(
  52. input, weight_ih, bias_ih, hx, weight_hh, bias_hh, cx, h_new, c_new,
  53. gates);
  54. } else {
  55. return LstmCellCompute::get_workspace_bundle(
  56. input, weight_ih, bias_ih, hx, weight_hh, bias_hh, cx, h_new,
  57. c_new, gates)
  58. .total_size_in_bytes();
  59. }
  60. }
  61. MIDOUT_END();
  62. }
  63. // vim: syntax=cpp.doxygen