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.

dynamic.c 34 kB

7 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174
  1. /*********************************************************************/
  2. /* Copyright 2009, 2010 The University of Texas at Austin. */
  3. /* All rights reserved. */
  4. /* */
  5. /* Redistribution and use in source and binary forms, with or */
  6. /* without modification, are permitted provided that the following */
  7. /* conditions are met: */
  8. /* */
  9. /* 1. Redistributions of source code must retain the above */
  10. /* copyright notice, this list of conditions and the following */
  11. /* disclaimer. */
  12. /* */
  13. /* 2. Redistributions in binary form must reproduce the above */
  14. /* copyright notice, this list of conditions and the following */
  15. /* disclaimer in the documentation and/or other materials */
  16. /* provided with the distribution. */
  17. /* */
  18. /* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */
  19. /* AUSTIN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, */
  20. /* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
  21. /* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
  22. /* DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT */
  23. /* AUSTIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */
  24. /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
  25. /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */
  26. /* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */
  27. /* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
  28. /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
  29. /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */
  30. /* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
  31. /* POSSIBILITY OF SUCH DAMAGE. */
  32. /* */
  33. /* The views and conclusions contained in the software and */
  34. /* documentation are those of the authors and should not be */
  35. /* interpreted as representing official policies, either expressed */
  36. /* or implied, of The University of Texas at Austin. */
  37. /*********************************************************************/
  38. #include "common.h"
  39. #ifdef _MSC_VER
  40. #define strncasecmp _strnicmp
  41. #define strcasecmp _stricmp
  42. #endif
  43. #ifdef ARCH_X86
  44. #define EXTERN extern
  45. #else
  46. #define EXTERN
  47. #endif
  48. #ifdef DYNAMIC_LIST
  49. extern gotoblas_t gotoblas_PRESCOTT;
  50. #ifdef DYN_ATHLON
  51. extern gotoblas_t gotoblas_ATHLON;
  52. #else
  53. #define gotoblas_ATHLON gotoblas_PRESCOTT
  54. #endif
  55. #ifdef DYN_KATMAI
  56. extern gotoblas_t gotoblas_KATMAI;
  57. #else
  58. #define gotoblas_KATMAI gotoblas_PRESCOTT
  59. #endif
  60. #ifdef DYN_BANIAS
  61. extern gotoblas_t gotoblas_BANIAS;
  62. #else
  63. #define gotoblas_BANIAS gotoblas_PRESCOTT
  64. #endif
  65. #ifdef DYN_COPPERMINE
  66. extern gotoblas_t gotoblas_COPPERMINE;
  67. #else
  68. #define gotoblas_COPPERMINE gotoblas_PRESCOTT
  69. #endif
  70. #ifdef DYN_NORTHWOOD
  71. extern gotoblas_t gotoblas_NORTHWOOD;
  72. #else
  73. #define gotoblas_NORTHWOOD gotoblas_PRESCOTT
  74. #endif
  75. #ifdef DYN_CORE2
  76. extern gotoblas_t gotoblas_CORE2;
  77. #else
  78. #define gotoblas_CORE2 gotoblas_PRESCOTT
  79. #endif
  80. #ifdef DYN_NEHALEM
  81. extern gotoblas_t gotoblas_NEHALEM;
  82. #else
  83. #define gotoblas_NEHALEM gotoblas_PRESCOTT
  84. #endif
  85. #ifdef DYN_BARCELONA
  86. extern gotoblas_t gotoblas_BARCELONA;
  87. #elif defined(DYN_NEHALEM)
  88. #define gotoblas_BARCELONA gotoblas_NEHALEM
  89. #else
  90. #define gotoblas_BARCELONA gotoblas_PRESCOTT
  91. #endif
  92. #ifdef DYN_ATOM
  93. extern gotoblas_t gotoblas_ATOM;
  94. #elif defined(DYN_NEHALEM)
  95. #define gotoblas_ATOM gotoblas_NEHALEM
  96. #else
  97. #define gotoblas_ATOM gotoblas_PRESCOTT
  98. #endif
  99. #ifdef DYN_NANO
  100. extern gotoblas_t gotoblas_NANO;
  101. #else
  102. #define gotoblas_NANO gotoblas_PRESCOTT
  103. #endif
  104. #ifdef DYN_PENRYN
  105. extern gotoblas_t gotoblas_PENRYN;
  106. #else
  107. #define gotoblas_PENRYN gotoblas_PRESCOTT
  108. #endif
  109. #ifdef DYN_DUNNINGTON
  110. extern gotoblas_t gotoblas_DUNNINGTON;
  111. #else
  112. #define gotoblas_DUNNINGTON gotoblas_PRESCOTT
  113. #endif
  114. #ifdef DYN_OPTERON
  115. extern gotoblas_t gotoblas_OPTERON;
  116. #else
  117. #define gotoblas_OPTERON gotoblas_PRESCOTT
  118. #endif
  119. #ifdef DYN_OPTERON_SSE3
  120. extern gotoblas_t gotoblas_OPTERON_SSE3;
  121. #else
  122. #define gotoblas_OPTERON_SSE3 gotoblas_PRESCOTT
  123. #endif
  124. #ifdef DYN_BOBCAT
  125. extern gotoblas_t gotoblas_BOBCAT;
  126. #elif defined(DYN_NEHALEM)
  127. #define gotoblas_BOBCAT gotoblas_NEHALEM
  128. #else
  129. #define gotoblas_BOBCAT gotoblas_PRESCOTT
  130. #endif
  131. #ifdef DYN_SANDYBRIDGE
  132. extern gotoblas_t gotoblas_SANDYBRIDGE;
  133. #elif defined(DYN_NEHALEM)
  134. #define gotoblas_SANDYBRIDGE gotoblas_NEHALEM
  135. #else
  136. #define gotoblas_SANDYBRIDGE gotoblas_PRESCOTT
  137. #endif
  138. #ifdef DYN_BULLDOZER
  139. extern gotoblas_t gotoblas_BULLDOZER;
  140. #elif defined(DYN_SANDYBRIDGE)
  141. #define gotoblas_BULLDOZER gotoblas_SANDYBRIDGE
  142. #elif defined(DYN_NEHALEM)
  143. #define gotoblas_BULLDOZER gotoblas_NEHALEM
  144. #else
  145. #define gotoblas_BULLDOZER gotoblas_PRESCOTT
  146. #endif
  147. #ifdef DYN_PILEDRIVER
  148. extern gotoblas_t gotoblas_PILEDRIVER;
  149. #elif defined(DYN_SANDYBRIDGE)
  150. #define gotoblas_PILEDRIVER gotoblas_SANDYBRIDGE
  151. #elif defined(DYN_NEHALEM)
  152. #define gotoblas_PILEDRIVER gotoblas_NEHALEM
  153. #else
  154. #define gotoblas_PILEDRIVER gotoblas_PRESCOTT
  155. #endif
  156. #ifdef DYN_STEAMROLLER
  157. extern gotoblas_t gotoblas_STEAMROLLER;
  158. #elif defined(DYN_SANDYBRIDGE)
  159. #define gotoblas_STEAMROLLER gotoblas_SANDYBRIDGE
  160. #elif defined(DYN_NEHALEM)
  161. #define gotoblas_STEAMROLLER gotoblas_NEHALEM
  162. #else
  163. #define gotoblas_STEAMROLLER gotoblas_PRESCOTT
  164. #endif
  165. #ifdef DYN_EXCAVATOR
  166. extern gotoblas_t gotoblas_EXCAVATOR;
  167. #elif defined(DYN_SANDYBRIDGE)
  168. #define gotoblas_EXCAVATOR gotoblas_SANDYBRIDGE
  169. #elif defined(DYN_NEHALEM)
  170. #define gotoblas_EXCAVATOR gotoblas_NEHALEM
  171. #else
  172. #define gotoblas_EXCAVATOR gotoblas_PRESCOTT
  173. #endif
  174. #ifdef DYN_HASWELL
  175. extern gotoblas_t gotoblas_HASWELL;
  176. #elif defined(DYN_SANDYBRIDGE)
  177. #define gotoblas_HASWELL gotoblas_SANDYBRIDGE
  178. #elif defined(DYN_NEHALEM)
  179. #define gotoblas_HASWELL gotoblas_NEHALEM
  180. #else
  181. #define gotoblas_HASWELL gotoblas_PRESCOTT
  182. #endif
  183. #ifdef DYN_ZEN
  184. extern gotoblas_t gotoblas_ZEN;
  185. #elif defined(DYN_HASWELL)
  186. #define gotoblas_ZEN gotoblas_HASWELL
  187. #elif defined(DYN_SANDYBRIDGE)
  188. #define gotoblas_ZEN gotoblas_SANDYBRIDGE
  189. #elif defined(DYN_NEHALEM)
  190. #define gotoblas_ZEN gotoblas_NEHALEM
  191. #else
  192. #define gotoblas_ZEN gotoblas_PRESCOTT
  193. #endif
  194. #ifdef DYN_SKYLAKEX
  195. extern gotoblas_t gotoblas_SKYLAKEX;
  196. #elif defined(DYN_HASWELL)
  197. #define gotoblas_SKYLAKEX gotoblas_HASWELL
  198. #elif defined(DYN_SANDYBRIDGE)
  199. #define gotoblas_SKYLAKEX gotoblas_SANDYBRIDGE
  200. #elif defined(DYN_NEHALEM)
  201. #define gotoblas_SKYLAKEX gotoblas_NEHALEM
  202. #else
  203. #define gotoblas_SKYLAKEX gotoblas_PRESCOTT
  204. #endif
  205. #ifdef DYN_COOPERLAKE
  206. extern gotoblas_t gotoblas_COOPERLAKE;
  207. #elif defined(DYN_SKYLAKEX)
  208. #define gotoblas_COOPERLAKE gotoblas_SKYLAKEX
  209. #elif defined(DYN_HASWELL)
  210. #define gotoblas_COOPERLAKE gotoblas_HASWELL
  211. #elif defined(DYN_SANDYBRIDGE)
  212. #define gotoblas_COOPERLAKE gotoblas_SANDYBRIDGE
  213. #elif defined(DYN_NEHALEM)
  214. #define gotoblas_COOPERLAKE gotoblas_NEHALEM
  215. #else
  216. #define gotoblas_COOPERLAKE gotoblas_PRESCOTT
  217. #endif
  218. #ifdef DYN_SAPPHIRERAPIDS
  219. extern gotoblas_t gotoblas_SAPPHIRERAPIDS;
  220. #elif defined(DYN_SKYLAKEX)
  221. #define gotoblas_SAPPHIRERAPIDS gotoblas_SKYLAKEX
  222. #elif defined(DYN_HASWELL)
  223. #define gotoblas_SAPPHIRERAPIDS gotoblas_HASWELL
  224. #elif defined(DYN_SANDYBRIDGE)
  225. #define gotoblas_SAPPHIRERAPIDS gotoblas_SANDYBRIDGE
  226. #elif defined(DYN_NEHALEM)
  227. #define gotoblas_SAPPHIRERAPIDS gotoblas_NEHALEM
  228. #else
  229. #define gotoblas_SAPPHIRERAPIDS gotoblas_PRESCOTT
  230. #endif
  231. #else // not DYNAMIC_LIST
  232. EXTERN gotoblas_t gotoblas_KATMAI;
  233. EXTERN gotoblas_t gotoblas_COPPERMINE;
  234. EXTERN gotoblas_t gotoblas_NORTHWOOD;
  235. EXTERN gotoblas_t gotoblas_BANIAS;
  236. EXTERN gotoblas_t gotoblas_ATHLON;
  237. extern gotoblas_t gotoblas_PRESCOTT;
  238. extern gotoblas_t gotoblas_CORE2;
  239. extern gotoblas_t gotoblas_NEHALEM;
  240. extern gotoblas_t gotoblas_BARCELONA;
  241. #ifdef DYNAMIC_OLDER
  242. extern gotoblas_t gotoblas_ATOM;
  243. extern gotoblas_t gotoblas_NANO;
  244. extern gotoblas_t gotoblas_PENRYN;
  245. extern gotoblas_t gotoblas_DUNNINGTON;
  246. extern gotoblas_t gotoblas_OPTERON;
  247. extern gotoblas_t gotoblas_OPTERON_SSE3;
  248. extern gotoblas_t gotoblas_BOBCAT;
  249. #else
  250. #define gotoblas_ATOM gotoblas_NEHALEM
  251. #define gotoblas_NANO gotoblas_NEHALEM
  252. #define gotoblas_PENRYN gotoblas_CORE2
  253. #define gotoblas_DUNNINGTON gotoblas_CORE2
  254. #define gotoblas_OPTERON gotoblas_CORE2
  255. #define gotoblas_OPTERON_SSE3 gotoblas_CORE2
  256. #define gotoblas_BOBCAT gotoblas_CORE2
  257. #endif
  258. #ifndef NO_AVX
  259. extern gotoblas_t gotoblas_SANDYBRIDGE;
  260. extern gotoblas_t gotoblas_BULLDOZER;
  261. extern gotoblas_t gotoblas_PILEDRIVER;
  262. extern gotoblas_t gotoblas_STEAMROLLER;
  263. extern gotoblas_t gotoblas_EXCAVATOR;
  264. #ifdef NO_AVX2
  265. #define gotoblas_HASWELL gotoblas_SANDYBRIDGE
  266. #define gotoblas_SKYLAKEX gotoblas_SANDYBRIDGE
  267. #define gotoblas_COOPERLAKE gotoblas_SANDYBRIDGE
  268. #define gotoblas_ZEN gotoblas_SANDYBRIDGE
  269. #else
  270. extern gotoblas_t gotoblas_HASWELL;
  271. extern gotoblas_t gotoblas_ZEN;
  272. #ifndef NO_AVX512
  273. extern gotoblas_t gotoblas_SKYLAKEX;
  274. extern gotoblas_t gotoblas_COOPERLAKE;
  275. extern gotoblas_t gotoblas_SAPPHIRERAPIDS;
  276. #else
  277. #define gotoblas_SKYLAKEX gotoblas_HASWELL
  278. #define gotoblas_COOPERLAKE gotoblas_HASWELL
  279. #define gotoblas_SAPPHIRERAPIDS gotoblas_HASWELL
  280. #endif
  281. #endif
  282. #else
  283. //Use NEHALEM kernels for sandy bridge
  284. #define gotoblas_SANDYBRIDGE gotoblas_NEHALEM
  285. #define gotoblas_HASWELL gotoblas_NEHALEM
  286. #define gotoblas_SKYLAKEX gotoblas_NEHALEM
  287. #define gotoblas_COOPERLAKE gotoblas_NEHALEM
  288. #define gotoblas_SAPPHIRERAPIDS gotoblas_NEHALEM
  289. #define gotoblas_BULLDOZER gotoblas_BARCELONA
  290. #define gotoblas_PILEDRIVER gotoblas_BARCELONA
  291. #define gotoblas_STEAMROLLER gotoblas_BARCELONA
  292. #define gotoblas_EXCAVATOR gotoblas_BARCELONA
  293. #define gotoblas_ZEN gotoblas_BARCELONA
  294. #endif
  295. #endif // DYNAMIC_LIST
  296. #define VENDOR_INTEL 1
  297. #define VENDOR_AMD 2
  298. #define VENDOR_CENTAUR 3
  299. #define VENDOR_HYGON 4
  300. #define VENDOR_ZHAOXIN 5
  301. #define VENDOR_UNKNOWN 99
  302. #define BITMASK(a, b, c) ((((a) >> (b)) & (c)))
  303. #ifndef NO_AVX
  304. static inline void xgetbv(int op, int * eax, int * edx){
  305. //Use binary code for xgetbv
  306. __asm__ __volatile__
  307. (".byte 0x0f, 0x01, 0xd0": "=a" (*eax), "=d" (*edx) : "c" (op) : "cc");
  308. }
  309. #endif
  310. int support_avx(){
  311. #ifndef NO_AVX
  312. int eax, ebx, ecx, edx;
  313. int ret=0;
  314. cpuid(1, &eax, &ebx, &ecx, &edx);
  315. if ((ecx & (1 << 28)) != 0 && (ecx & (1 << 27)) != 0 && (ecx & (1 << 26)) != 0){
  316. xgetbv(0, &eax, &edx);
  317. if((eax & 6) == 6){
  318. ret=1; //OS support AVX
  319. }
  320. }
  321. return ret;
  322. #else
  323. return 0;
  324. #endif
  325. }
  326. int support_avx2(){
  327. #ifndef NO_AVX2
  328. int eax, ebx, ecx=0, edx;
  329. int ret=0;
  330. if (!support_avx())
  331. return 0;
  332. cpuid(7, &eax, &ebx, &ecx, &edx);
  333. if((ebx & (1<<5)) != 0)
  334. ret=1; //AVX2 flag is set
  335. return ret;
  336. #else
  337. return 0;
  338. #endif
  339. }
  340. int support_avx512(){
  341. #if !defined(NO_AVX) && !defined(NO_AVX512)
  342. int eax, ebx, ecx, edx;
  343. int ret=0;
  344. if (!support_avx())
  345. return 0;
  346. cpuid(7, &eax, &ebx, &ecx, &edx);
  347. if((ebx & (1<<5)) == 0){
  348. ret=0; //cpu does not have avx2 flag
  349. }
  350. if((ebx & (1<<31)) != 0){ //AVX512VL flag is set
  351. xgetbv(0, &eax, &edx);
  352. if((eax & 0xe0) == 0xe0)
  353. ret=1; //OS supports saving zmm register
  354. }
  355. return ret;
  356. #else
  357. return 0;
  358. #endif
  359. }
  360. int support_avx512_bf16(){
  361. #if !defined(NO_AVX) && !defined(NO_AVX512)
  362. int eax, ebx, ecx, edx;
  363. int ret=0;
  364. if (!support_avx512())
  365. return 0;
  366. cpuid_count(7, 1, &eax, &ebx, &ecx, &edx);
  367. if((eax & 32) == 32){
  368. ret=1; // CPUID.7.1:EAX[bit 5] indicates whether avx512_bf16 supported or not
  369. }
  370. return ret;
  371. #else
  372. return 0;
  373. #endif
  374. }
  375. #define BIT_AMX_TILE 0x01000000
  376. #define BIT_AMX_BF16 0x00400000
  377. #define BIT_AMX_ENBD 0x00060000
  378. int support_amx_bf16() {
  379. #if !defined(NO_AVX) && !defined(NO_AVX512)
  380. int eax, ebx, ecx, edx;
  381. int ret=0;
  382. if (!support_avx512())
  383. return 0;
  384. // CPUID.7.0:EDX indicates AMX support
  385. cpuid_count(7, 0, &eax, &ebx, &ecx, &edx);
  386. if ((edx & BIT_AMX_TILE) && (edx & BIT_AMX_BF16)) {
  387. // CPUID.D.0:EAX[17:18] indicates AMX enabled
  388. cpuid_count(0xd, 0, &eax, &ebx, &ecx, &edx);
  389. if ((eax & BIT_AMX_ENBD) == BIT_AMX_ENBD)
  390. ret = 1;
  391. }
  392. return ret;
  393. #else
  394. return 0;
  395. #endif
  396. }
  397. extern void openblas_warning(int verbose, const char * msg);
  398. #define FALLBACK_VERBOSE 1
  399. #define NEHALEM_FALLBACK "OpenBLAS : Your OS does not support AVX instructions. OpenBLAS is using Nehalem kernels as a fallback, which may give poorer performance.\n"
  400. #define SANDYBRIDGE_FALLBACK "OpenBLAS : Your OS does not support AVX2 instructions. OpenBLAS is using Sandybridge kernels as a fallback, which may give poorer performance.\n"
  401. #define HASWELL_FALLBACK "OpenBLAS : Your OS does not support AVX512VL instructions. OpenBLAS is using Haswell kernels as a fallback, which may give poorer performance.\n"
  402. #define BARCELONA_FALLBACK "OpenBLAS : Your OS does not support AVX instructions. OpenBLAS is using Barcelona kernels as a fallback, which may give poorer performance.\n"
  403. static int get_vendor(void){
  404. int eax, ebx, ecx, edx;
  405. union
  406. {
  407. char vchar[16];
  408. int vint[4];
  409. } vendor;
  410. cpuid(0, &eax, &ebx, &ecx, &edx);
  411. *(&vendor.vint[0]) = ebx;
  412. *(&vendor.vint[1]) = edx;
  413. *(&vendor.vint[2]) = ecx;
  414. vendor.vchar[12] = '\0';
  415. if (!strcmp(vendor.vchar, "GenuineIntel")) return VENDOR_INTEL;
  416. if (!strcmp(vendor.vchar, "AuthenticAMD")) return VENDOR_AMD;
  417. if (!strcmp(vendor.vchar, "CentaurHauls")) return VENDOR_CENTAUR;
  418. if (!strcmp(vendor.vchar, " Shanghai ")) return VENDOR_ZHAOXIN;
  419. if (!strcmp(vendor.vchar, "HygonGenuine")) return VENDOR_HYGON;
  420. if ((eax == 0) || ((eax & 0x500) != 0)) return VENDOR_INTEL;
  421. return VENDOR_UNKNOWN;
  422. }
  423. static gotoblas_t *get_coretype(void){
  424. int eax, ebx, ecx, edx;
  425. int family, exfamily, model, vendor, exmodel, stepping;
  426. cpuid(1, &eax, &ebx, &ecx, &edx);
  427. family = BITMASK(eax, 8, 0x0f);
  428. exfamily = BITMASK(eax, 20, 0xff);
  429. model = BITMASK(eax, 4, 0x0f);
  430. exmodel = BITMASK(eax, 16, 0x0f);
  431. stepping = BITMASK(eax, 0, 0x0f);
  432. vendor = get_vendor();
  433. if (vendor == VENDOR_INTEL){
  434. switch (family) {
  435. case 0x6:
  436. switch (exmodel) {
  437. case 0:
  438. if (model <= 0x7) return &gotoblas_KATMAI;
  439. if ((model == 0x8) || (model == 0xa) || (model == 0xb)) return &gotoblas_COPPERMINE;
  440. if ((model == 0x9) || (model == 0xd)) return &gotoblas_BANIAS;
  441. if (model == 14) return &gotoblas_BANIAS;
  442. if (model == 15) return &gotoblas_CORE2;
  443. return NULL;
  444. case 1:
  445. if (model == 6) return &gotoblas_CORE2;
  446. if (model == 7) return &gotoblas_PENRYN;
  447. if (model == 13) return &gotoblas_DUNNINGTON;
  448. if ((model == 10) || (model == 11) || (model == 14) || (model == 15)) return &gotoblas_NEHALEM;
  449. if (model == 12) return &gotoblas_ATOM;
  450. return NULL;
  451. case 2:
  452. //Intel Core (Clarkdale) / Core (Arrandale)
  453. // Pentium (Clarkdale) / Pentium Mobile (Arrandale)
  454. // Xeon (Clarkdale), 32nm
  455. if (model == 5) return &gotoblas_NEHALEM;
  456. //Intel Xeon Processor 5600 (Westmere-EP)
  457. //Xeon Processor E7 (Westmere-EX)
  458. //Xeon E7540
  459. if (model == 12 || model == 14 || model == 15) return &gotoblas_NEHALEM;
  460. //Intel Core i5-2000 /i7-2000 (Sandy Bridge)
  461. //Intel Core i7-3000 / Xeon E5
  462. if (model == 10 || model == 13) {
  463. if(support_avx())
  464. return &gotoblas_SANDYBRIDGE;
  465. else{
  466. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  467. return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels.
  468. }
  469. }
  470. return NULL;
  471. case 3:
  472. //Intel Sandy Bridge 22nm (Ivy Bridge?)
  473. if (model == 10 || model == 14) {
  474. if(support_avx())
  475. return &gotoblas_SANDYBRIDGE;
  476. else{
  477. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  478. return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels.
  479. }
  480. }
  481. //Intel Haswell
  482. if (model == 12 || model == 15) {
  483. if(support_avx2())
  484. return &gotoblas_HASWELL;
  485. if(support_avx()) {
  486. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  487. return &gotoblas_SANDYBRIDGE;
  488. } else {
  489. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  490. return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels.
  491. }
  492. }
  493. //Intel Broadwell
  494. if (model == 13) {
  495. if(support_avx2())
  496. return &gotoblas_HASWELL;
  497. if(support_avx()) {
  498. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  499. return &gotoblas_SANDYBRIDGE;
  500. } else {
  501. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  502. return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels.
  503. }
  504. }
  505. if (model == 7) return &gotoblas_ATOM; //Bay Trail
  506. return NULL;
  507. case 4:
  508. //Intel Haswell
  509. if (model == 5 || model == 6) {
  510. if(support_avx2())
  511. return &gotoblas_HASWELL;
  512. if(support_avx()) {
  513. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  514. return &gotoblas_SANDYBRIDGE;
  515. } else {
  516. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  517. return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels.
  518. }
  519. }
  520. //Intel Broadwell
  521. if (model == 7 || model == 15) {
  522. if(support_avx2())
  523. return &gotoblas_HASWELL;
  524. if(support_avx()) {
  525. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  526. return &gotoblas_SANDYBRIDGE;
  527. } else {
  528. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  529. return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels.
  530. }
  531. }
  532. //Intel Skylake
  533. if (model == 14) {
  534. if(support_avx2())
  535. return &gotoblas_HASWELL;
  536. if(support_avx()) {
  537. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  538. return &gotoblas_SANDYBRIDGE;
  539. } else {
  540. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  541. return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels.
  542. }
  543. }
  544. //Intel Braswell / Avoton
  545. if (model == 12 || model == 13) {
  546. return &gotoblas_NEHALEM;
  547. }
  548. return NULL;
  549. case 5:
  550. //Intel Broadwell
  551. if (model == 6) {
  552. if(support_avx2())
  553. return &gotoblas_HASWELL;
  554. if(support_avx()) {
  555. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  556. return &gotoblas_SANDYBRIDGE;
  557. } else {
  558. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  559. return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels.
  560. }
  561. }
  562. if (model == 5) {
  563. // Intel Cooperlake
  564. if(support_avx512_bf16())
  565. return &gotoblas_COOPERLAKE;
  566. // Intel Skylake X
  567. if (support_avx512())
  568. return &gotoblas_SKYLAKEX;
  569. if(support_avx2()){
  570. openblas_warning(FALLBACK_VERBOSE, HASWELL_FALLBACK);
  571. return &gotoblas_HASWELL;
  572. }
  573. if(support_avx()) {
  574. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  575. return &gotoblas_SANDYBRIDGE;
  576. } else {
  577. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  578. return &gotoblas_NEHALEM;
  579. }
  580. }
  581. //Intel Skylake
  582. if (model == 14) {
  583. if(support_avx2())
  584. return &gotoblas_HASWELL;
  585. if(support_avx()) {
  586. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  587. return &gotoblas_SANDYBRIDGE;
  588. } else {
  589. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  590. return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels.
  591. }
  592. }
  593. //Intel Phi Knights Landing
  594. if (model == 7) {
  595. if(support_avx2()){
  596. openblas_warning(FALLBACK_VERBOSE, HASWELL_FALLBACK);
  597. return &gotoblas_HASWELL;
  598. }
  599. if(support_avx()) {
  600. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  601. return &gotoblas_SANDYBRIDGE;
  602. } else {
  603. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  604. return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels.
  605. }
  606. }
  607. //Apollo Lake or Denverton
  608. if (model == 12 || model == 15) {
  609. return &gotoblas_NEHALEM;
  610. }
  611. return NULL;
  612. case 6:
  613. if (model == 6) {
  614. // Cannon Lake
  615. if(support_avx2())
  616. return &gotoblas_HASWELL;
  617. if(support_avx()) {
  618. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  619. return &gotoblas_SANDYBRIDGE;
  620. } else {
  621. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  622. return &gotoblas_NEHALEM;
  623. }
  624. }
  625. if (model == 10 || model == 12){
  626. // Ice Lake SP
  627. if(support_avx512_bf16())
  628. return &gotoblas_COOPERLAKE;
  629. if (support_avx512())
  630. return &gotoblas_SKYLAKEX;
  631. if(support_avx2())
  632. return &gotoblas_HASWELL;
  633. if(support_avx()) {
  634. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  635. return &gotoblas_SANDYBRIDGE;
  636. } else {
  637. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  638. return &gotoblas_NEHALEM;
  639. }
  640. }
  641. return NULL;
  642. case 7:
  643. if (model == 10) // Goldmont Plus
  644. return &gotoblas_NEHALEM;
  645. if (model == 13 || model == 14) {
  646. // Ice Lake
  647. if (support_avx512())
  648. return &gotoblas_SKYLAKEX;
  649. if(support_avx2()){
  650. openblas_warning(FALLBACK_VERBOSE, HASWELL_FALLBACK);
  651. return &gotoblas_HASWELL;
  652. }
  653. if(support_avx()) {
  654. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  655. return &gotoblas_SANDYBRIDGE;
  656. } else {
  657. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  658. return &gotoblas_NEHALEM;
  659. }
  660. }
  661. return NULL;
  662. case 8:
  663. if (model == 12 || model == 13) { // Tiger Lake
  664. if (support_avx512())
  665. return &gotoblas_SKYLAKEX;
  666. if(support_avx2()){
  667. openblas_warning(FALLBACK_VERBOSE, HASWELL_FALLBACK);
  668. return &gotoblas_HASWELL;
  669. }
  670. if(support_avx()) {
  671. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  672. return &gotoblas_SANDYBRIDGE;
  673. } else {
  674. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  675. return &gotoblas_NEHALEM;
  676. }
  677. }
  678. if (model == 14 ) { // Kaby Lake, Coffee Lake
  679. if(support_avx2())
  680. return &gotoblas_HASWELL;
  681. if(support_avx()) {
  682. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  683. return &gotoblas_SANDYBRIDGE;
  684. } else {
  685. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  686. return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels.
  687. }
  688. }
  689. if (model == 15){ // Sapphire Rapids
  690. if(support_amx_bf16())
  691. return &gotoblas_SAPPHIRERAPIDS;
  692. if(support_avx512_bf16())
  693. return &gotoblas_COOPERLAKE;
  694. if (support_avx512())
  695. return &gotoblas_SKYLAKEX;
  696. if(support_avx2())
  697. return &gotoblas_HASWELL;
  698. if(support_avx()) {
  699. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  700. return &gotoblas_SANDYBRIDGE;
  701. } else {
  702. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  703. return &gotoblas_NEHALEM;
  704. }
  705. }
  706. return NULL;
  707. case 9:
  708. if (model == 7 || model == 10) { // Alder Lake
  709. if(support_avx512_bf16())
  710. return &gotoblas_COOPERLAKE;
  711. if (support_avx512())
  712. return &gotoblas_SKYLAKEX;
  713. if(support_avx2()){
  714. return &gotoblas_HASWELL;
  715. }
  716. if(support_avx()) {
  717. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  718. return &gotoblas_SANDYBRIDGE;
  719. } else {
  720. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  721. return &gotoblas_NEHALEM;
  722. }
  723. }
  724. if (model == 14 ) { // Kaby Lake, Coffee Lake
  725. if(support_avx2())
  726. return &gotoblas_HASWELL;
  727. if(support_avx()) {
  728. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  729. return &gotoblas_SANDYBRIDGE;
  730. } else {
  731. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  732. return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels.
  733. }
  734. }
  735. return NULL;
  736. case 10:
  737. if (model == 5 || model == 6) {
  738. if(support_avx2())
  739. return &gotoblas_HASWELL;
  740. if(support_avx()) {
  741. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  742. return &gotoblas_SANDYBRIDGE;
  743. } else {
  744. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  745. return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels.
  746. }
  747. }
  748. if (model == 7) {
  749. if (support_avx512())
  750. return &gotoblas_SKYLAKEX;
  751. if(support_avx2())
  752. return &gotoblas_HASWELL;
  753. if(support_avx()) {
  754. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  755. return &gotoblas_SANDYBRIDGE;
  756. } else {
  757. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  758. return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels.
  759. }
  760. }
  761. return NULL;
  762. }
  763. break;
  764. case 0xf:
  765. if (model <= 0x2) return &gotoblas_NORTHWOOD;
  766. return &gotoblas_PRESCOTT;
  767. }
  768. }
  769. if (vendor == VENDOR_AMD || vendor == VENDOR_HYGON){
  770. if (family <= 0xe) {
  771. // Verify that CPU has 3dnow and 3dnowext before claiming it is Athlon
  772. cpuid(0x80000000, &eax, &ebx, &ecx, &edx);
  773. if ( (eax & 0xffff) >= 0x01) {
  774. cpuid(0x80000001, &eax, &ebx, &ecx, &edx);
  775. if ((edx & (1 << 30)) == 0 || (edx & (1u << 31)) == 0)
  776. return NULL;
  777. }
  778. else
  779. return NULL;
  780. return &gotoblas_ATHLON;
  781. }
  782. if (family == 0xf){
  783. if ((exfamily == 0) || (exfamily == 2)) {
  784. if (ecx & (1 << 0)) return &gotoblas_OPTERON_SSE3;
  785. else return &gotoblas_OPTERON;
  786. } else if (exfamily == 5 || exfamily == 7) {
  787. return &gotoblas_BOBCAT;
  788. } else if (exfamily == 6) {
  789. if(model == 1){
  790. //AMD Bulldozer Opteron 6200 / Opteron 4200 / AMD FX-Series
  791. if(support_avx())
  792. return &gotoblas_BULLDOZER;
  793. else{
  794. openblas_warning(FALLBACK_VERBOSE, BARCELONA_FALLBACK);
  795. return &gotoblas_BARCELONA; //OS doesn't support AVX. Use old kernels.
  796. }
  797. }else if(model == 2 || model == 3){
  798. //AMD Bulldozer Opteron 6300 / Opteron 4300 / Opteron 3300
  799. if(support_avx())
  800. return &gotoblas_PILEDRIVER;
  801. else{
  802. openblas_warning(FALLBACK_VERBOSE, BARCELONA_FALLBACK);
  803. return &gotoblas_BARCELONA; //OS doesn't support AVX. Use old kernels.
  804. }
  805. }else if(model == 5){
  806. if(support_avx())
  807. return &gotoblas_EXCAVATOR;
  808. else{
  809. openblas_warning(FALLBACK_VERBOSE, BARCELONA_FALLBACK);
  810. return &gotoblas_BARCELONA; //OS doesn't support AVX. Use old kernels.
  811. }
  812. }else if(model == 0 || model == 8){
  813. if (exmodel == 1) {
  814. //AMD Trinity
  815. if(support_avx())
  816. return &gotoblas_PILEDRIVER;
  817. else{
  818. openblas_warning(FALLBACK_VERBOSE, BARCELONA_FALLBACK);
  819. return &gotoblas_BARCELONA; //OS doesn't support AVX. Use old kernels.
  820. }
  821. }else if (exmodel == 3) {
  822. //AMD STEAMROLLER
  823. if(support_avx())
  824. return &gotoblas_STEAMROLLER;
  825. else{
  826. openblas_warning(FALLBACK_VERBOSE, BARCELONA_FALLBACK);
  827. return &gotoblas_BARCELONA; //OS doesn't support AVX. Use old kernels.
  828. }
  829. }else if (exmodel == 6) {
  830. if(support_avx())
  831. return &gotoblas_EXCAVATOR;
  832. else{
  833. openblas_warning(FALLBACK_VERBOSE, BARCELONA_FALLBACK);
  834. return &gotoblas_BARCELONA; //OS doesn't support AVX. Use old kernels.
  835. }
  836. }
  837. }
  838. } else if (exfamily == 8) {
  839. /* if (model == 1 || model == 8) */ {
  840. if(support_avx())
  841. return &gotoblas_ZEN;
  842. else{
  843. openblas_warning(FALLBACK_VERBOSE, BARCELONA_FALLBACK);
  844. return &gotoblas_BARCELONA; //OS doesn't support AVX. Use old kernels.
  845. }
  846. }
  847. } else if (exfamily == 9) {
  848. if(support_avx())
  849. return &gotoblas_ZEN;
  850. else{
  851. openblas_warning(FALLBACK_VERBOSE, BARCELONA_FALLBACK);
  852. return &gotoblas_BARCELONA; //OS doesn't support AVX. Use old kernels.
  853. }
  854. } else if (exfamily == 10) {
  855. if(support_avx512_bf16())
  856. return &gotoblas_COOPERLAKE;
  857. if(support_avx512())
  858. return &gotoblas_SKYLAKEX;
  859. if(support_avx())
  860. return &gotoblas_ZEN;
  861. else{
  862. openblas_warning(FALLBACK_VERBOSE, BARCELONA_FALLBACK);
  863. return &gotoblas_BARCELONA; //OS doesn't support AVX. Use old kernels.
  864. }
  865. }else {
  866. return NULL;
  867. }
  868. }
  869. }
  870. if (vendor == VENDOR_CENTAUR) {
  871. switch (family) {
  872. case 0x6:
  873. if (model == 0xf && stepping < 0xe)
  874. return &gotoblas_NANO;
  875. return &gotoblas_NEHALEM;
  876. case 0x7:
  877. switch (exmodel) {
  878. case 5:
  879. if (support_avx2())
  880. return &gotoblas_ZEN;
  881. else
  882. return &gotoblas_DUNNINGTON;
  883. default:
  884. return &gotoblas_NEHALEM;
  885. }
  886. default:
  887. if (family >= 0x8)
  888. return &gotoblas_NEHALEM;
  889. }
  890. }
  891. if (vendor == VENDOR_ZHAOXIN) {
  892. switch (family) {
  893. case 0x7:
  894. switch (exmodel) {
  895. case 5:
  896. if (support_avx2())
  897. return &gotoblas_ZEN;
  898. else
  899. return &gotoblas_DUNNINGTON;
  900. default:
  901. return &gotoblas_NEHALEM;
  902. }
  903. default:
  904. return &gotoblas_NEHALEM;
  905. }
  906. }
  907. return NULL;
  908. }
  909. static char *corename[] = {
  910. "Unknown",
  911. "Katmai",
  912. "Coppermine",
  913. "Northwood",
  914. "Prescott",
  915. "Banias",
  916. "Atom",
  917. "Core2",
  918. "Penryn",
  919. "Dunnington",
  920. "Nehalem",
  921. "Athlon",
  922. "Opteron",
  923. "Opteron_SSE3",
  924. "Barcelona",
  925. "Nano",
  926. "Sandybridge",
  927. "Bobcat",
  928. "Bulldozer",
  929. "Piledriver",
  930. "Haswell",
  931. "Steamroller",
  932. "Excavator",
  933. "Zen",
  934. "SkylakeX",
  935. "Cooperlake",
  936. "SapphireRapids"
  937. };
  938. char *gotoblas_corename(void) {
  939. if (gotoblas == &gotoblas_KATMAI) return corename[ 1];
  940. if (gotoblas == &gotoblas_COPPERMINE) return corename[ 2];
  941. if (gotoblas == &gotoblas_NORTHWOOD) return corename[ 3];
  942. if (gotoblas == &gotoblas_PRESCOTT) return corename[ 4];
  943. if (gotoblas == &gotoblas_BANIAS) return corename[ 5];
  944. if (gotoblas == &gotoblas_ATOM)
  945. #ifdef DYNAMIC_OLDER
  946. return corename[ 6];
  947. #else
  948. return corename[10];
  949. #endif
  950. if (gotoblas == &gotoblas_CORE2) return corename[ 7];
  951. if (gotoblas == &gotoblas_PENRYN)
  952. #ifdef DYNAMIC_OLDER
  953. return corename[ 8];
  954. #else
  955. return corename[7];
  956. #endif
  957. if (gotoblas == &gotoblas_DUNNINGTON)
  958. #ifdef DYNAMIC_OLDER
  959. return corename[ 9];
  960. #else
  961. return corename[7];
  962. #endif
  963. if (gotoblas == &gotoblas_NEHALEM) return corename[10];
  964. if (gotoblas == &gotoblas_ATHLON) return corename[11];
  965. if (gotoblas == &gotoblas_OPTERON_SSE3)
  966. #ifdef DYNAMIC_OLDER
  967. return corename[12];
  968. #else
  969. return corename[7];
  970. #endif
  971. if (gotoblas == &gotoblas_OPTERON)
  972. #ifdef DYNAMIC_OLDER
  973. return corename[13];
  974. #else
  975. return corename[7];
  976. #endif
  977. if (gotoblas == &gotoblas_BARCELONA) return corename[14];
  978. if (gotoblas == &gotoblas_NANO)
  979. #ifdef DYNAMIC_OLDER
  980. return corename[15];
  981. #else
  982. return corename[10];
  983. #endif
  984. if (gotoblas == &gotoblas_SANDYBRIDGE) return corename[16];
  985. if (gotoblas == &gotoblas_BOBCAT)
  986. #ifdef DYNAMIC_OLDER
  987. return corename[17];
  988. #else
  989. return corename[7];
  990. #endif
  991. if (gotoblas == &gotoblas_BULLDOZER) return corename[18];
  992. if (gotoblas == &gotoblas_PILEDRIVER) return corename[19];
  993. if (gotoblas == &gotoblas_HASWELL) return corename[20];
  994. if (gotoblas == &gotoblas_STEAMROLLER) return corename[21];
  995. if (gotoblas == &gotoblas_EXCAVATOR) return corename[22];
  996. if (gotoblas == &gotoblas_ZEN) return corename[23];
  997. if (gotoblas == &gotoblas_SKYLAKEX) return corename[24];
  998. if (gotoblas == &gotoblas_COOPERLAKE) return corename[25];
  999. if (gotoblas == &gotoblas_SAPPHIRERAPIDS) return corename[26];
  1000. return corename[0];
  1001. }
  1002. static gotoblas_t *force_coretype(char *coretype){
  1003. int i ;
  1004. int found = -1;
  1005. char message[128];
  1006. //char mname[20];
  1007. for ( i=1 ; i <= 25; i++)
  1008. {
  1009. if (!strncasecmp(coretype,corename[i],20))
  1010. {
  1011. found = i;
  1012. break;
  1013. }
  1014. }
  1015. if (found < 0)
  1016. {
  1017. //strncpy(mname,coretype,20);
  1018. snprintf(message, 128, "Core not found: %s\n",coretype);
  1019. openblas_warning(1, message);
  1020. return(NULL);
  1021. }
  1022. switch (found)
  1023. {
  1024. case 25: return (&gotoblas_COOPERLAKE);
  1025. case 24: return (&gotoblas_SKYLAKEX);
  1026. case 23: return (&gotoblas_ZEN);
  1027. case 22: return (&gotoblas_EXCAVATOR);
  1028. case 21: return (&gotoblas_STEAMROLLER);
  1029. case 20: return (&gotoblas_HASWELL);
  1030. case 19: return (&gotoblas_PILEDRIVER);
  1031. case 18: return (&gotoblas_BULLDOZER);
  1032. case 17: return (&gotoblas_BOBCAT);
  1033. case 16: return (&gotoblas_SANDYBRIDGE);
  1034. case 15: return (&gotoblas_NANO);
  1035. case 14: return (&gotoblas_BARCELONA);
  1036. case 13: return (&gotoblas_OPTERON);
  1037. case 12: return (&gotoblas_OPTERON_SSE3);
  1038. case 11: return (&gotoblas_ATHLON);
  1039. case 10: return (&gotoblas_NEHALEM);
  1040. case 9: return (&gotoblas_DUNNINGTON);
  1041. case 8: return (&gotoblas_PENRYN);
  1042. case 7: return (&gotoblas_CORE2);
  1043. case 6: return (&gotoblas_ATOM);
  1044. case 5: return (&gotoblas_BANIAS);
  1045. case 4: return (&gotoblas_PRESCOTT);
  1046. case 3: return (&gotoblas_NORTHWOOD);
  1047. case 2: return (&gotoblas_COPPERMINE);
  1048. case 1: return (&gotoblas_KATMAI);
  1049. }
  1050. return(NULL);
  1051. }
  1052. void gotoblas_dynamic_init(void) {
  1053. char coremsg[128];
  1054. char coren[22];
  1055. char *p;
  1056. if (gotoblas) return;
  1057. p = getenv("OPENBLAS_CORETYPE");
  1058. if ( p )
  1059. {
  1060. gotoblas = force_coretype(p);
  1061. }
  1062. else
  1063. {
  1064. gotoblas = get_coretype();
  1065. }
  1066. #ifdef ARCH_X86
  1067. if (gotoblas == NULL) gotoblas = &gotoblas_KATMAI;
  1068. #else
  1069. if (gotoblas == NULL) {
  1070. if (support_avx512_bf16()) gotoblas = &gotoblas_COOPERLAKE;
  1071. else if (support_avx512()) gotoblas = &gotoblas_SKYLAKEX;
  1072. else if (support_avx2()) gotoblas = &gotoblas_HASWELL;
  1073. else if (support_avx()) gotoblas = &gotoblas_SANDYBRIDGE;
  1074. else gotoblas = &gotoblas_PRESCOTT;
  1075. }
  1076. /* sanity check, if 64bit pointer we can't have a 32 bit cpu */
  1077. if (sizeof(void*) == 8) {
  1078. if (gotoblas == &gotoblas_KATMAI ||
  1079. gotoblas == &gotoblas_COPPERMINE ||
  1080. gotoblas == &gotoblas_NORTHWOOD ||
  1081. gotoblas == &gotoblas_BANIAS ||
  1082. gotoblas == &gotoblas_ATHLON)
  1083. gotoblas = &gotoblas_PRESCOTT;
  1084. }
  1085. #endif
  1086. if (gotoblas && gotoblas -> init) {
  1087. strncpy(coren,gotoblas_corename(),20);
  1088. sprintf(coremsg, "Core: %s\n",coren);
  1089. openblas_warning(2, coremsg);
  1090. gotoblas -> init();
  1091. } else {
  1092. openblas_warning(0, "OpenBLAS : Architecture Initialization failed. No initialization function found.\n");
  1093. exit(1);
  1094. }
  1095. }
  1096. void gotoblas_dynamic_quit(void) {
  1097. gotoblas = NULL;
  1098. }