resize.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*************************************************************************
  2. * Copyright (C) [2019] by Cambricon, Inc. All rights reserved
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  13. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  15. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. * THE SOFTWARE.
  19. *************************************************************************/
  20. /**
  21. * @file resize.h
  22. *
  23. * This file contains a declaration of the MluResize class.
  24. */
  25. #ifndef EASYBANG_RESIZE_H_
  26. #define EASYBANG_RESIZE_H_
  27. #include <string>
  28. #include "cnrt.h"
  29. #include "cxxutil/edk_attribute.h"
  30. #include "cxxutil/exception.h"
  31. namespace edk {
  32. class MluResizePrivate;
  33. /**
  34. * @brief Mlu resize operator helper class
  35. */
  36. class MluResize {
  37. public:
  38. /**
  39. * @brief Construct a new Mlu Resize object
  40. */
  41. MluResize();
  42. /**
  43. * @brief Destroy the Mlu Resize object
  44. */
  45. ~MluResize();
  46. /**
  47. * @brief Params to initialize resize operator
  48. */
  49. struct Attr {
  50. /// Input image resolution
  51. uint32_t src_w{0}, src_h{0};
  52. /// Input image stride
  53. uint32_t src_stride_y{0}, src_stride_uv{0};
  54. /// Output image resolution
  55. uint32_t dst_w{0}, dst_h{0};
  56. /// Kernel batch size
  57. int batch_size = 1;
  58. int core = 4;
  59. uint32_t channel_id = 0;
  60. };
  61. /**
  62. * @brief Set the mlu task queue
  63. *
  64. * @param queue mlu task queue on which run kernel
  65. * @param exclusive mlu task queue is exclusive. Therefore it could be destroied.
  66. */
  67. void SetMluQueue(cnrtQueue_t queue, bool exclusive = false);
  68. /**
  69. * @brief Destroy the mlu task queue
  70. */
  71. void DestroyMluQueue();
  72. /**
  73. * @brief Get the mlu task queue
  74. *
  75. * @return cnrtQueue_t
  76. */
  77. cnrtQueue_t GetMluQueue() const;
  78. /**
  79. * @brief Initialize operator
  80. *
  81. * @param attr Params to initialize operator
  82. */
  83. bool Init(const Attr& attr);
  84. /**
  85. * @brief Get operator attribute
  86. *
  87. * @return attribute
  88. */
  89. const Attr& GetAttr();
  90. /**
  91. * @brief Deinitialize resources
  92. */
  93. void Destroy();
  94. /**
  95. * @brief Get the last error string while get an false or -1 from InvokeOp or SyncOneOutput
  96. *
  97. * @return Last error message
  98. */
  99. std::string GetLastError() const;
  100. /**
  101. * @brief Batching up one yuv image
  102. *
  103. * @param src_y input y plane in MLU memory
  104. * @param src_uv input uv plane in MLU memory
  105. */
  106. void BatchingUp(void* src_y, void* src_uv);
  107. /**
  108. * @brief Execute Operator and return an operator output (a whole batch)
  109. *
  110. * @param dst_y Operator output y plane in MLU memory, containing a whole batch
  111. * @param dst_uv Operator output uv plane in MLU memory, containing a whole batch
  112. * @return Return false if execute failed
  113. */
  114. bool SyncOneOutput(void* dst_y, void* dst_uv);
  115. private:
  116. MluResizePrivate* d_ptr_ = nullptr;
  117. MluResize(const MluResize&) = delete;
  118. MluResize& operator=(const MluResize&) = delete;
  119. }; // class MluResize
  120. } // namespace edk
  121. #endif // EASYBANG_RESIZE_H_