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.

common.h 5.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. #pragma once
  2. #include <gflags/gflags.h>
  3. #include <memory>
  4. #include <unordered_map>
  5. DECLARE_int32(thread);
  6. namespace lar {
  7. /*!
  8. * \brief: state of model running
  9. */
  10. enum class RunStage {
  11. BEFORE_MODEL_LOAD = 0,
  12. AFTER_NETWORK_CREATED = 1,
  13. AFTER_MODEL_LOAD = 2,
  14. BEFORE_OUTSPEC_SET = 3,
  15. //! using for dump static memory information svg file
  16. AFTER_OUTSPEC_SET = 4,
  17. //! using for external c opr library
  18. MODEL_RUNNING = 5,
  19. //! using for output dumper
  20. AFTER_RUNNING_WAIT = 6,
  21. //! using for external c opr library
  22. AFTER_RUNNING_ITER = 7,
  23. AFTER_MODEL_RUNNING = 8,
  24. GLOBAL_OPTIMIZATION = 9,
  25. UPDATE_IO = 10,
  26. };
  27. /*!
  28. * \brief: type of different model
  29. */
  30. enum class ModelType {
  31. LITE_MODEL = 0,
  32. MEGDL_MODEL,
  33. UNKNOWN,
  34. };
  35. /*!
  36. * \brief: param for running model
  37. */
  38. struct RuntimeParam {
  39. RunStage stage = RunStage::AFTER_MODEL_LOAD;
  40. size_t warmup_iter; //! warm up number before running model
  41. size_t run_iter; //! iteration number for running model
  42. size_t threads = FLAGS_thread; //! thread number for running model (NOTE:it's
  43. //! different from multithread device )
  44. size_t testcase_num = 1; //! testcase number for model with testcase
  45. };
  46. /*!
  47. * \brief:layout type for running model optimization
  48. */
  49. enum class OptLayoutType {
  50. NCHW4 = 1 << 0,
  51. CHWN4 = 1 << 1,
  52. NCHW44 = 1 << 2,
  53. NCHW88 = 1 << 3,
  54. NCHW32 = 1 << 4,
  55. NCHW64 = 1 << 5,
  56. NHWCD4 = 1 << 6,
  57. NCHW44_DOT = 1 << 7
  58. };
  59. /**
  60. * base class to story option value
  61. */
  62. enum class JsonValueType {
  63. Bool = 0,
  64. Number,
  65. NumberInt32,
  66. NumberUint64,
  67. String,
  68. };
  69. struct Value {
  70. virtual JsonValueType get_type() const = 0;
  71. virtual std::string type_string() const = 0;
  72. virtual void reset_value() = 0;
  73. virtual ~Value() = default;
  74. };
  75. /**
  76. * class for double option
  77. */
  78. struct Number final : public Value {
  79. Number(double v) : m_val(v), m_default_val(v) {}
  80. static std::shared_ptr<Number> make(double v) {
  81. return std::make_shared<Number>(v);
  82. }
  83. void set_value(double v) { m_val = v; }
  84. double get_value() { return m_val; }
  85. double get_default() { return m_default_val; }
  86. void reset_value() override { m_val = m_default_val; }
  87. JsonValueType get_type() const override { return JsonValueType::Number; }
  88. std::string type_string() const override { return "Number"; }
  89. private:
  90. double m_val;
  91. double m_default_val;
  92. };
  93. /**
  94. * class for int32_t option
  95. */
  96. struct NumberInt32 final : public Value {
  97. NumberInt32(int32_t v) : m_val(v), m_default_val(v) {}
  98. static std::shared_ptr<NumberInt32> make(int32_t v) {
  99. return std::make_shared<NumberInt32>(v);
  100. }
  101. void set_value(int32_t v) { m_val = v; }
  102. int32_t get_value() { return m_val; }
  103. int32_t get_default() { return m_default_val; }
  104. void reset_value() override { m_val = m_default_val; }
  105. JsonValueType get_type() const override { return JsonValueType::NumberInt32; }
  106. std::string type_string() const override { return "NumberInt32"; }
  107. private:
  108. int32_t m_val;
  109. int32_t m_default_val;
  110. };
  111. /**
  112. * class for uint64 option
  113. */
  114. struct NumberUint64 final : public Value {
  115. NumberUint64(uint64_t v) : m_val(v), m_default_val(v) {}
  116. static std::shared_ptr<NumberUint64> make(uint64_t v) {
  117. return std::make_shared<NumberUint64>(v);
  118. }
  119. void set_value(uint64_t v) { m_val = v; }
  120. uint64_t get_value() { return m_val; }
  121. uint64_t get_default() { return m_default_val; }
  122. void reset_value() override { m_val = m_default_val; }
  123. JsonValueType get_type() const override { return JsonValueType::NumberUint64; }
  124. std::string type_string() const override { return "NumberUint64"; }
  125. private:
  126. uint64_t m_val;
  127. uint64_t m_default_val;
  128. };
  129. /**
  130. * class for boolean option
  131. */
  132. struct Bool final : public Value {
  133. Bool(bool v) : m_val(v), m_default_val(v) {}
  134. static std::shared_ptr<Bool> make(bool v) { return std::make_shared<Bool>(v); }
  135. void set_value(bool v) { m_val = v; }
  136. bool get_value() { return m_val; }
  137. bool get_default() { return m_default_val; }
  138. void reset_value() override { m_val = m_default_val; }
  139. JsonValueType get_type() const override { return JsonValueType::Bool; }
  140. std::string type_string() const override { return "Bool"; }
  141. private:
  142. bool m_val;
  143. bool m_default_val;
  144. };
  145. /**
  146. * class for string option
  147. */
  148. struct String final : public Value {
  149. String(std::string v) : m_val(v), m_default_val(v) {}
  150. static std::shared_ptr<String> make(const std::string& v) {
  151. return std::make_shared<String>(v);
  152. }
  153. void set_value(const std::string& v) { m_val = v; }
  154. std::string& get_value() { return m_val; }
  155. std::string get_default() { return m_default_val; }
  156. void reset_value() override { m_val = m_default_val; }
  157. JsonValueType get_type() const override { return JsonValueType::String; }
  158. std::string type_string() const override { return "String"; }
  159. private:
  160. std::string m_val;
  161. std::string m_default_val;
  162. };
  163. using OptionValMap = std::unordered_map<std::string, std::shared_ptr<lar::Value>>;
  164. } // namespace lar
  165. // vim: syntax=cpp.doxygen