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.

0001-fix-arm-linux-fix-some-build-warnings-and-errors.patch 11 kB

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

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