1
0

metric.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Adapted from https://github.com/InternLM/lmdeploy
  3. * Copyright (c) OpenMMLab. All rights reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. #pragma once
  18. #include <array>
  19. #include <iomanip>
  20. #include <sstream>
  21. #include <string>
  22. #include <vector>
  23. namespace aphrodite {
  24. namespace autoquant {
  25. struct Metric {
  26. int id;
  27. bool feasible;
  28. bool prefer;
  29. std::array<int, 3> cta_shape;
  30. std::array<int, 3> warp_shape;
  31. int warps;
  32. int stages;
  33. int max_active_ctas;
  34. float smem;
  35. float cta_cnt_m;
  36. float cta_cnt_n;
  37. float cta_iter_k;
  38. float grid_size;
  39. int active_ctas;
  40. float waves;
  41. float waves1;
  42. float occupancy;
  43. float tile_efficiency;
  44. float wave_efficiency;
  45. float grid_a0;
  46. float grid_b0;
  47. float grid_a1;
  48. float grid_b1;
  49. float grid_mm;
  50. float grid_sum;
  51. float grid_norm;
  52. float cta_sum;
  53. float cta_wave;
  54. int best;
  55. float time;
  56. int count;
  57. };
  58. inline void DumpMetrics(std::ostream& os, const std::vector<Metric>& metrics, const std::vector<int>& indices = {})
  59. {
  60. auto dump_shape = [](const std::array<int, 3>& shape) {
  61. std::stringstream ss;
  62. ss << std::setw(4) << shape[0] << std::setw(4) << shape[1] << std::setw(4) << shape[2];
  63. return ss.str();
  64. };
  65. std::vector<std::tuple<std::string, int>> infos{
  66. {"id", 4}, {"valid", 6}, {"cta_mnk", 14}, {"warp_mnk", 14}, {"warps", 6}, {"stages", 8},
  67. {"smem", 8}, {"cta_cnt_m", 10}, {"cta_cnt_n", 10}, {"cta_iter_k", 11}, {"max_ctas", 9}, {"act_ctas", 10},
  68. {"waves", 12}, {"waves1", 12}, {"occupancy", 12}, {"%tile", 10}, {"%wave", 10}, {"grid_a0", 12},
  69. {"grid_b0", 12}, {"grid_a1", 12}, {"grid_b1", 12}, {"grid_mm", 12}, {"grid_sum", 12}, {"cta_cnt", 8},
  70. {"cta_sum", 8}, {"cta_wave", 9}, {"grid_norm", 12}, {"time", 12}, {"best", 7}};
  71. for (const auto& [name, width] : infos) {
  72. os << std::setw(width) << name;
  73. }
  74. os << "\n";
  75. for (size_t i = 0; i < metrics.size(); ++i) {
  76. auto& metric = indices.empty() ? metrics[i] : metrics[indices[i]];
  77. int c = 0;
  78. os << std::setw(std::get<1>(infos[c++])) << metric.id;
  79. os << std::setw(std::get<1>(infos[c++])) << metric.feasible;
  80. os << std::setw(std::get<1>(infos[c++])) << dump_shape(metric.cta_shape);
  81. os << std::setw(std::get<1>(infos[c++])) << dump_shape(metric.warp_shape);
  82. os << std::setw(std::get<1>(infos[c++])) << metric.warps;
  83. os << std::setw(std::get<1>(infos[c++])) << metric.stages;
  84. os << std::setw(std::get<1>(infos[c++])) << metric.smem;
  85. os << std::setw(std::get<1>(infos[c++])) << metric.cta_cnt_m;
  86. os << std::setw(std::get<1>(infos[c++])) << metric.cta_cnt_n;
  87. os << std::setw(std::get<1>(infos[c++])) << metric.cta_iter_k;
  88. os << std::setw(std::get<1>(infos[c++])) << metric.max_active_ctas;
  89. os << std::setw(std::get<1>(infos[c++])) << metric.active_ctas;
  90. os << std::setw(std::get<1>(infos[c++])) << metric.waves;
  91. os << std::setw(std::get<1>(infos[c++])) << metric.waves1;
  92. os << std::setw(std::get<1>(infos[c++])) << metric.occupancy;
  93. os << std::setw(std::get<1>(infos[c++])) << metric.tile_efficiency;
  94. os << std::setw(std::get<1>(infos[c++])) << metric.wave_efficiency;
  95. os << std::setw(std::get<1>(infos[c++])) << metric.grid_a0;
  96. os << std::setw(std::get<1>(infos[c++])) << metric.grid_b0;
  97. os << std::setw(std::get<1>(infos[c++])) << metric.grid_a1;
  98. os << std::setw(std::get<1>(infos[c++])) << metric.grid_b1;
  99. os << std::setw(std::get<1>(infos[c++])) << metric.grid_mm;
  100. os << std::setw(std::get<1>(infos[c++])) << metric.grid_sum;
  101. os << std::setw(std::get<1>(infos[c++])) << metric.grid_size;
  102. os << std::setw(std::get<1>(infos[c++])) << metric.cta_sum;
  103. os << std::setw(std::get<1>(infos[c++])) << metric.cta_wave;
  104. os << std::setw(std::get<1>(infos[c++])) << metric.grid_norm;
  105. os << std::setw(std::get<1>(infos[c++])) << metric.time * 1000 / metric.count;
  106. os << std::setw(std::get<1>(infos[c++])) << (metric.best ? "*" : "");
  107. os << "\n";
  108. }
  109. }
  110. } // namespace autoquant
  111. } // namespace aphrodite