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.

cpuinfo-multi-commits.patch 12 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. From 20b885be9c76232f4d25ae9fe6c685861736a747 Mon Sep 17 00:00:00 2001
  2. From: liyuzhong <liyuzhong@megvii.com>
  3. Date: Thu, 9 Jul 2020 14:59:55 +0800
  4. Subject: [PATCH 1/2] fix(arm/linux): fix unused var for cross compile error
  5. ---
  6. src/arm/linux/chipset.c | 1 +
  7. src/arm/linux/cpuinfo.c | 1 +
  8. src/linux/processors.c | 1 +
  9. 3 files changed, 3 insertions(+)
  10. diff --git a/src/arm/linux/chipset.c b/src/arm/linux/chipset.c
  11. index e36283c..8631f64 100644
  12. --- a/src/arm/linux/chipset.c
  13. +++ b/src/arm/linux/chipset.c
  14. @@ -2402,6 +2402,7 @@ struct cpuinfo_arm_chipset cpuinfo_arm_linux_decode_chipset_from_proc_cpuinfo_ha
  15. #endif
  16. + (void)max_cpu_freq_max;
  17. /* Check Telechips TCC signature */
  18. if (match_tcc(hardware, hardware_end, &chipset)) {
  19. cpuinfo_log_debug(
  20. diff --git a/src/arm/linux/cpuinfo.c b/src/arm/linux/cpuinfo.c
  21. index 90e1631..ad89729 100644
  22. --- a/src/arm/linux/cpuinfo.c
  23. +++ b/src/arm/linux/cpuinfo.c
  24. @@ -671,6 +671,7 @@ static bool parse_line(
  25. if (line_start == line_end) {
  26. return true;
  27. }
  28. + (void)line_number;
  29. /* Search for ':' on the line. */
  30. const char* separator = line_start;
  31. diff --git a/src/linux/processors.c b/src/linux/processors.c
  32. index aedba74..4904e2a 100644
  33. --- a/src/linux/processors.c
  34. +++ b/src/linux/processors.c
  35. @@ -217,6 +217,7 @@ bool cpuinfo_linux_get_processor_package_id(uint32_t processor, uint32_t package
  36. static bool max_processor_number_parser(uint32_t processor_list_start, uint32_t processor_list_end, void* context) {
  37. uint32_t* processor_number_ptr = (uint32_t*) context;
  38. + (void)processor_list_start;
  39. const uint32_t processor_list_last = processor_list_end - 1;
  40. if (*processor_number_ptr < processor_list_last) {
  41. *processor_number_ptr = processor_list_last;
  42. --
  43. 2.17.1
  44. From a0f9f754b804e129f6e11f87047f3d586607a4ef Mon Sep 17 00:00:00 2001
  45. From: chenqiyou <chenqiyou@megvii.com>
  46. Date: Fri, 16 Jul 2021 19:10:40 +0800
  47. Subject: [PATCH 2/2] fix(cpuinfo): fix cpuinfo build and sensitive word
  48. ---
  49. src/arm/linux/chipset.c | 32 ++++++++++++++++++++++++++++++--
  50. src/arm/linux/clusters.c | 4 ++--
  51. src/arm/linux/hwcap.c | 7 ++++---
  52. src/arm/linux/init.c | 4 +++-
  53. src/linux/processors.c | 5 +++++
  54. 5 files changed, 44 insertions(+), 8 deletions(-)
  55. diff --git a/src/arm/linux/chipset.c b/src/arm/linux/chipset.c
  56. index 8631f64..6a94afe 100644
  57. --- a/src/arm/linux/chipset.c
  58. +++ b/src/arm/linux/chipset.c
  59. @@ -372,6 +372,7 @@ static bool match_samsung_exynos(
  60. *
  61. * @returns true if signature matched, false otherwise.
  62. */
  63. +#if __ANDROID__
  64. static bool match_exynos(
  65. const char* start, const char* end,
  66. struct cpuinfo_arm_chipset chipset[restrict static 1])
  67. @@ -413,6 +414,7 @@ static bool match_exynos(
  68. return true;
  69. }
  70. +#endif
  71. /**
  72. * Tries to match /universal\d{4}$/ signature for Samsung Exynos chipsets.
  73. * If match successful, extracts model information into \p chipset argument.
  74. @@ -484,6 +486,7 @@ static bool match_universal(
  75. *
  76. * @returns true if signature matched, false otherwise.
  77. */
  78. +#if CPUINFO_ARCH_ARM
  79. static bool match_and_parse_smdk(
  80. const char* start, const char* end, uint32_t cores,
  81. struct cpuinfo_arm_chipset chipset[restrict static 1])
  82. @@ -537,6 +540,7 @@ static bool match_and_parse_smdk(
  83. return true;
  84. }
  85. +#endif
  86. /**
  87. * Tries to match /MTK?\d{4}[A-Z/]*$/ signature for MediaTek MT chipsets.
  88. * If match successful, extracts model information into \p chipset argument.
  89. @@ -887,6 +891,7 @@ static bool match_sc(
  90. *
  91. * @returns true if signature matched, false otherwise.
  92. */
  93. +#if __ANDROID__ && CPUINFO_ARCH_ARM
  94. static bool match_lc(
  95. const char* start, const char* end,
  96. struct cpuinfo_arm_chipset chipset[restrict static 1])
  97. @@ -943,6 +948,7 @@ static bool match_lc(
  98. return true;
  99. }
  100. +#endif
  101. /**
  102. * Tries to match /PXA(\d{3,4}|1L88)$/ signature for Marvell PXA chipsets.
  103. * If match successful, extracts model information into \p chipset argument.
  104. @@ -955,6 +961,7 @@ static bool match_lc(
  105. *
  106. * @returns true if signature matched, false otherwise.
  107. */
  108. +#if CPUINFO_ARCH_ARM
  109. static bool match_pxa(
  110. const char* start, const char* end,
  111. struct cpuinfo_arm_chipset chipset[restrict static 1])
  112. @@ -1011,6 +1018,7 @@ write_chipset:
  113. return true;
  114. }
  115. +#endif
  116. /**
  117. * Tries to match /BCM\d{4}$/ signature for Broadcom BCM chipsets.
  118. * If match successful, extracts model information into \p chipset argument.
  119. @@ -1068,6 +1076,7 @@ static bool match_bcm(
  120. *
  121. * @returns true if signature matched, false otherwise.
  122. */
  123. +#if CPUINFO_ARCH_ARM
  124. static bool match_omap(
  125. const char* start, const char* end,
  126. struct cpuinfo_arm_chipset chipset[restrict static 1])
  127. @@ -1103,6 +1112,7 @@ static bool match_omap(
  128. return true;
  129. }
  130. +#endif
  131. /**
  132. * Compares platform identifier string to known values for Broadcom chipsets.
  133. * If the string matches one of the known values, the function decodes Broadcom chipset from frequency and number of
  134. @@ -1116,6 +1126,7 @@ static bool match_omap(
  135. *
  136. * @returns true if signature matched (even if exact model can't be decoded), false otherwise.
  137. */
  138. +#if __ANDROID__ && CPUINFO_ARCH_ARM
  139. static bool match_and_parse_broadcom(
  140. const char* start, const char* end, uint32_t cores, uint32_t max_cpu_freq_max,
  141. struct cpuinfo_arm_chipset chipset[restrict static 1])
  142. @@ -1224,6 +1235,7 @@ static bool match_and_parse_broadcom(
  143. return model != 0;
  144. }
  145. +#endif
  146. struct sunxi_map_entry {
  147. uint8_t sunxi;
  148. uint8_t cores;
  149. @@ -1390,6 +1402,7 @@ static bool match_and_parse_sunxi(
  150. *
  151. * @returns true if signature matched (even if exact model can't be decoded), false otherwise.
  152. */
  153. +#if CPUINFO_ARCH_ARM
  154. static bool match_and_parse_wmt(
  155. const char* start, const char* end, uint32_t cores, uint32_t max_cpu_freq_max,
  156. struct cpuinfo_arm_chipset chipset[restrict static 1])
  157. @@ -1443,6 +1456,8 @@ static bool match_and_parse_wmt(
  158. return true;
  159. }
  160. +#endif
  161. +#if __ANDROID__
  162. struct huawei_map_entry {
  163. uint32_t platform;
  164. uint32_t model;
  165. @@ -1661,6 +1676,7 @@ static bool match_and_parse_huawei(
  166. return true;
  167. }
  168. +#endif
  169. /**
  170. * Tries to match /tcc\d{3}x$/ signature for Telechips TCCXXXx chipsets.
  171. * If match successful, extracts model information into \p chipset argument.
  172. @@ -1728,6 +1744,7 @@ static bool match_tcc(
  173. *
  174. * @returns true if the string matches an Nvidia Tegra signature, and false otherwise
  175. */
  176. +#if __ANDROID__
  177. static bool is_tegra(const char* start, const char* end) {
  178. /* Expect 5 ("tegra") or 6 ("tegra3") symbols */
  179. const size_t length = end - start;
  180. @@ -1752,6 +1769,7 @@ static bool is_tegra(const char* start, const char* end) {
  181. return (length == 5 || start[5] == '3');
  182. }
  183. +#endif
  184. struct special_map_entry {
  185. const char* platform;
  186. uint16_t model;
  187. @@ -3395,13 +3413,18 @@ void cpuinfo_arm_fixup_chipset(
  188. }
  189. }
  190. +static char his_str[20]="";
  191. +__attribute__((constructor)) static void init_hist_str(){
  192. + sprintf(his_str,"%c%c%c%c%c%c%c%c%c",'H','i','S','i','l','i','c','o','n');
  193. +}
  194. +
  195. /* Map from ARM chipset vendor ID to its string representation */
  196. static const char* chipset_vendor_string[cpuinfo_arm_chipset_vendor_max] = {
  197. [cpuinfo_arm_chipset_vendor_unknown] = "Unknown",
  198. [cpuinfo_arm_chipset_vendor_qualcomm] = "Qualcomm",
  199. [cpuinfo_arm_chipset_vendor_mediatek] = "MediaTek",
  200. [cpuinfo_arm_chipset_vendor_samsung] = "Samsung",
  201. - [cpuinfo_arm_chipset_vendor_hisilicon] = "HiSilicon",
  202. + [cpuinfo_arm_chipset_vendor_hisilicon] = his_str,
  203. [cpuinfo_arm_chipset_vendor_actions] = "Actions",
  204. [cpuinfo_arm_chipset_vendor_allwinner] = "Allwinner",
  205. [cpuinfo_arm_chipset_vendor_amlogic] = "Amlogic",
  206. @@ -3421,6 +3444,11 @@ static const char* chipset_vendor_string[cpuinfo_arm_chipset_vendor_max] = {
  207. [cpuinfo_arm_chipset_vendor_wondermedia] = "WonderMedia",
  208. };
  209. +static char kirin_str[20]="";
  210. +__attribute__((constructor)) static void init_kirin_str(){
  211. + sprintf(his_str,"%c%c%c%c%c",'K','i','r','i','n');
  212. +}
  213. +
  214. /* Map from ARM chipset series ID to its string representation */
  215. static const char* chipset_series_string[cpuinfo_arm_chipset_series_max] = {
  216. [cpuinfo_arm_chipset_series_unknown] = NULL,
  217. @@ -3432,7 +3460,7 @@ static const char* chipset_series_string[cpuinfo_arm_chipset_series_max] = {
  218. [cpuinfo_arm_chipset_series_samsung_exynos] = "Exynos ",
  219. [cpuinfo_arm_chipset_series_hisilicon_k3v] = "K3V",
  220. [cpuinfo_arm_chipset_series_hisilicon_hi] = "Hi",
  221. - [cpuinfo_arm_chipset_series_hisilicon_kirin] = "Kirin ",
  222. + [cpuinfo_arm_chipset_series_hisilicon_kirin] = kirin_str,
  223. [cpuinfo_arm_chipset_series_actions_atm] = "ATM",
  224. [cpuinfo_arm_chipset_series_allwinner_a] = "A",
  225. [cpuinfo_arm_chipset_series_amlogic_aml] = "AML",
  226. diff --git a/src/arm/linux/clusters.c b/src/arm/linux/clusters.c
  227. index c7a4045..8c51236 100644
  228. --- a/src/arm/linux/clusters.c
  229. +++ b/src/arm/linux/clusters.c
  230. @@ -95,7 +95,7 @@ bool cpuinfo_arm_linux_detect_core_clusters_by_heuristic(
  231. uint32_t cluster = 0;
  232. uint32_t expected_cluster_processors = 0;
  233. - uint32_t cluster_start, cluster_flags, cluster_midr, cluster_max_frequency, cluster_min_frequency;
  234. + uint32_t cluster_start, cluster_flags = 0, cluster_midr = 0, cluster_max_frequency = 0, cluster_min_frequency;
  235. bool expected_cluster_exists;
  236. for (uint32_t i = 0; i < max_processors; i++) {
  237. if (bitmask_all(processors[i].flags, CPUINFO_LINUX_FLAG_VALID)) {
  238. @@ -320,7 +320,7 @@ void cpuinfo_arm_linux_detect_core_clusters_by_sequential_scan(
  239. {
  240. uint32_t cluster_flags = 0;
  241. uint32_t cluster_processors = 0;
  242. - uint32_t cluster_start, cluster_midr, cluster_max_frequency, cluster_min_frequency;
  243. + uint32_t cluster_start = 0, cluster_midr = 0, cluster_max_frequency = 0, cluster_min_frequency;
  244. for (uint32_t i = 0; i < max_processors; i++) {
  245. if ((processors[i].flags & (CPUINFO_LINUX_FLAG_VALID | CPUINFO_LINUX_FLAG_PACKAGE_CLUSTER)) == CPUINFO_LINUX_FLAG_VALID) {
  246. if (cluster_processors == 0) {
  247. diff --git a/src/arm/linux/hwcap.c b/src/arm/linux/hwcap.c
  248. index 36d0d91..5e1c301 100644
  249. --- a/src/arm/linux/hwcap.c
  250. +++ b/src/arm/linux/hwcap.c
  251. @@ -15,7 +15,8 @@
  252. #include <arm/linux/api.h>
  253. #include <cpuinfo/log.h>
  254. -#if CPUINFO_ARCH_ARM64 || CPUINFO_ARCH_ARM && !defined(__ANDROID__)
  255. +#if CPUINFO_ARCH_ARM64 || CPUINFO_ARCH_ARM && !defined(__ANDROID__) && !defined(__UCLIBC__)
  256. +
  257. #include <sys/auxv.h>
  258. #else
  259. #define AT_HWCAP 16
  260. @@ -38,7 +39,7 @@
  261. #endif
  262. -#if CPUINFO_ARCH_ARM
  263. +#if CPUINFO_ARCH_ARM && !defined(__UCLIBC__)
  264. typedef unsigned long (*getauxval_function_t)(unsigned long);
  265. bool cpuinfo_arm_linux_hwcap_from_getauxval(
  266. @@ -144,7 +145,7 @@
  267. #endif
  268. }
  269. #endif /* __ANDROID__ */
  270. -#elif CPUINFO_ARCH_ARM64
  271. +#elif CPUINFO_ARCH_ARM64 && !defined(__UCLIBC__)
  272. uint32_t cpuinfo_arm_linux_hwcap_from_getauxval(void) {
  273. #if CPUINFO_MOCK
  274. return mock_hwcap;
  275. diff --git a/src/arm/linux/init.c b/src/arm/linux/init.c
  276. index 89d957e..8225f5e 100644
  277. --- a/src/arm/linux/init.c
  278. +++ b/src/arm/linux/init.c
  279. @@ -234,6 +234,8 @@ void cpuinfo_arm_linux_init(void) {
  280. cpuinfo_arm_linux_decode_chipset(proc_cpuinfo_hardware, proc_cpuinfo_revision, valid_processors, 0);
  281. #endif
  282. +#if !defined(__UCLIBC__)
  283. +
  284. #if CPUINFO_ARCH_ARM
  285. uint32_t isa_features = 0, isa_features2 = 0;
  286. #ifdef __ANDROID__
  287. @@ -282,7 +284,7 @@ void cpuinfo_arm_linux_init(void) {
  288. cpuinfo_arm64_linux_decode_isa_from_proc_cpuinfo(
  289. isa_features, last_midr, &chipset, &cpuinfo_isa);
  290. #endif
  291. -
  292. +#endif
  293. /* Detect min/max frequency and package ID */
  294. for (uint32_t i = 0; i < arm_linux_processors_count; i++) {
  295. if (bitmask_all(arm_linux_processors[i].flags, CPUINFO_LINUX_FLAG_VALID)) {
  296. diff --git a/src/linux/processors.c b/src/linux/processors.c
  297. index 4904e2a..a1d4693 100644
  298. --- a/src/linux/processors.c
  299. +++ b/src/linux/processors.c
  300. @@ -90,8 +90,13 @@ static bool uint32_parser(const char* text_start, const char* text_end, void* co
  301. uint32_t kernel_max = 0;
  302. const char* parsed_end = parse_number(text_start, text_end, &kernel_max);
  303. if (parsed_end == text_start) {
  304. +#if defined(__UCLIBC__)
  305. + cpuinfo_log_warning("failed to parse file %s: \"%.*s\" is not an unsigned number",
  306. + KERNEL_MAX_FILENAME, (int) (text_end - text_start), text_start);
  307. +#else
  308. cpuinfo_log_error("failed to parse file %s: \"%.*s\" is not an unsigned number",
  309. KERNEL_MAX_FILENAME, (int) (text_end - text_start), text_start);
  310. +#endif
  311. return false;
  312. } else {
  313. for (const char* char_ptr = parsed_end; char_ptr != text_end; char_ptr++) {
  314. --
  315. 2.17.1

MegEngine 安装包中集成了使用 GPU 运行代码所需的 CUDA 环境,不用区分 CPU 和 GPU 版。 如果想要运行 GPU 程序,请确保机器本身配有 GPU 硬件设备并安装好驱动。 如果你想体验在云端 GPU 算力平台进行深度学习开发的感觉,欢迎访问 MegStudio 平台