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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173
  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. case 0xf:
  764. if (model <= 0x2) return &gotoblas_NORTHWOOD;
  765. return &gotoblas_PRESCOTT;
  766. }
  767. }
  768. if (vendor == VENDOR_AMD || vendor == VENDOR_HYGON){
  769. if (family <= 0xe) {
  770. // Verify that CPU has 3dnow and 3dnowext before claiming it is Athlon
  771. cpuid(0x80000000, &eax, &ebx, &ecx, &edx);
  772. if ( (eax & 0xffff) >= 0x01) {
  773. cpuid(0x80000001, &eax, &ebx, &ecx, &edx);
  774. if ((edx & (1 << 30)) == 0 || (edx & (1u << 31)) == 0)
  775. return NULL;
  776. }
  777. else
  778. return NULL;
  779. return &gotoblas_ATHLON;
  780. }
  781. if (family == 0xf){
  782. if ((exfamily == 0) || (exfamily == 2)) {
  783. if (ecx & (1 << 0)) return &gotoblas_OPTERON_SSE3;
  784. else return &gotoblas_OPTERON;
  785. } else if (exfamily == 5 || exfamily == 7) {
  786. return &gotoblas_BOBCAT;
  787. } else if (exfamily == 6) {
  788. if(model == 1){
  789. //AMD Bulldozer Opteron 6200 / Opteron 4200 / AMD FX-Series
  790. if(support_avx())
  791. return &gotoblas_BULLDOZER;
  792. else{
  793. openblas_warning(FALLBACK_VERBOSE, BARCELONA_FALLBACK);
  794. return &gotoblas_BARCELONA; //OS doesn't support AVX. Use old kernels.
  795. }
  796. }else if(model == 2 || model == 3){
  797. //AMD Bulldozer Opteron 6300 / Opteron 4300 / Opteron 3300
  798. if(support_avx())
  799. return &gotoblas_PILEDRIVER;
  800. else{
  801. openblas_warning(FALLBACK_VERBOSE, BARCELONA_FALLBACK);
  802. return &gotoblas_BARCELONA; //OS doesn't support AVX. Use old kernels.
  803. }
  804. }else if(model == 5){
  805. if(support_avx())
  806. return &gotoblas_EXCAVATOR;
  807. else{
  808. openblas_warning(FALLBACK_VERBOSE, BARCELONA_FALLBACK);
  809. return &gotoblas_BARCELONA; //OS doesn't support AVX. Use old kernels.
  810. }
  811. }else if(model == 0 || model == 8){
  812. if (exmodel == 1) {
  813. //AMD Trinity
  814. if(support_avx())
  815. return &gotoblas_PILEDRIVER;
  816. else{
  817. openblas_warning(FALLBACK_VERBOSE, BARCELONA_FALLBACK);
  818. return &gotoblas_BARCELONA; //OS doesn't support AVX. Use old kernels.
  819. }
  820. }else if (exmodel == 3) {
  821. //AMD STEAMROLLER
  822. if(support_avx())
  823. return &gotoblas_STEAMROLLER;
  824. else{
  825. openblas_warning(FALLBACK_VERBOSE, BARCELONA_FALLBACK);
  826. return &gotoblas_BARCELONA; //OS doesn't support AVX. Use old kernels.
  827. }
  828. }else if (exmodel == 6) {
  829. if(support_avx())
  830. return &gotoblas_EXCAVATOR;
  831. else{
  832. openblas_warning(FALLBACK_VERBOSE, BARCELONA_FALLBACK);
  833. return &gotoblas_BARCELONA; //OS doesn't support AVX. Use old kernels.
  834. }
  835. }
  836. }
  837. } else if (exfamily == 8) {
  838. /* if (model == 1 || model == 8) */ {
  839. if(support_avx())
  840. return &gotoblas_ZEN;
  841. else{
  842. openblas_warning(FALLBACK_VERBOSE, BARCELONA_FALLBACK);
  843. return &gotoblas_BARCELONA; //OS doesn't support AVX. Use old kernels.
  844. }
  845. }
  846. } else if (exfamily == 9) {
  847. if(support_avx())
  848. return &gotoblas_ZEN;
  849. else{
  850. openblas_warning(FALLBACK_VERBOSE, BARCELONA_FALLBACK);
  851. return &gotoblas_BARCELONA; //OS doesn't support AVX. Use old kernels.
  852. }
  853. } else if (exfamily == 10) {
  854. if(support_avx512_bf16())
  855. return &gotoblas_COOPERLAKE;
  856. if(support_avx512())
  857. return &gotoblas_SKYLAKEX;
  858. if(support_avx())
  859. return &gotoblas_ZEN;
  860. else{
  861. openblas_warning(FALLBACK_VERBOSE, BARCELONA_FALLBACK);
  862. return &gotoblas_BARCELONA; //OS doesn't support AVX. Use old kernels.
  863. }
  864. }else {
  865. return NULL;
  866. }
  867. }
  868. }
  869. if (vendor == VENDOR_CENTAUR) {
  870. switch (family) {
  871. case 0x6:
  872. if (model == 0xf && stepping < 0xe)
  873. return &gotoblas_NANO;
  874. return &gotoblas_NEHALEM;
  875. case 0x7:
  876. switch (exmodel) {
  877. case 5:
  878. if (support_avx2())
  879. return &gotoblas_ZEN;
  880. else
  881. return &gotoblas_DUNNINGTON;
  882. default:
  883. return &gotoblas_NEHALEM;
  884. }
  885. default:
  886. if (family >= 0x8)
  887. return &gotoblas_NEHALEM;
  888. }
  889. }
  890. if (vendor == VENDOR_ZHAOXIN) {
  891. switch (family) {
  892. case 0x7:
  893. switch (exmodel) {
  894. case 5:
  895. if (support_avx2())
  896. return &gotoblas_ZEN;
  897. else
  898. return &gotoblas_DUNNINGTON;
  899. default:
  900. return &gotoblas_NEHALEM;
  901. }
  902. default:
  903. return &gotoblas_NEHALEM;
  904. }
  905. }
  906. return NULL;
  907. }
  908. static char *corename[] = {
  909. "Unknown",
  910. "Katmai",
  911. "Coppermine",
  912. "Northwood",
  913. "Prescott",
  914. "Banias",
  915. "Atom",
  916. "Core2",
  917. "Penryn",
  918. "Dunnington",
  919. "Nehalem",
  920. "Athlon",
  921. "Opteron",
  922. "Opteron_SSE3",
  923. "Barcelona",
  924. "Nano",
  925. "Sandybridge",
  926. "Bobcat",
  927. "Bulldozer",
  928. "Piledriver",
  929. "Haswell",
  930. "Steamroller",
  931. "Excavator",
  932. "Zen",
  933. "SkylakeX",
  934. "Cooperlake",
  935. "SapphireRapids"
  936. };
  937. char *gotoblas_corename(void) {
  938. if (gotoblas == &gotoblas_KATMAI) return corename[ 1];
  939. if (gotoblas == &gotoblas_COPPERMINE) return corename[ 2];
  940. if (gotoblas == &gotoblas_NORTHWOOD) return corename[ 3];
  941. if (gotoblas == &gotoblas_PRESCOTT) return corename[ 4];
  942. if (gotoblas == &gotoblas_BANIAS) return corename[ 5];
  943. if (gotoblas == &gotoblas_ATOM)
  944. #ifdef DYNAMIC_OLDER
  945. return corename[ 6];
  946. #else
  947. return corename[10];
  948. #endif
  949. if (gotoblas == &gotoblas_CORE2) return corename[ 7];
  950. if (gotoblas == &gotoblas_PENRYN)
  951. #ifdef DYNAMIC_OLDER
  952. return corename[ 8];
  953. #else
  954. return corename[7];
  955. #endif
  956. if (gotoblas == &gotoblas_DUNNINGTON)
  957. #ifdef DYNAMIC_OLDER
  958. return corename[ 9];
  959. #else
  960. return corename[7];
  961. #endif
  962. if (gotoblas == &gotoblas_NEHALEM) return corename[10];
  963. if (gotoblas == &gotoblas_ATHLON) return corename[11];
  964. if (gotoblas == &gotoblas_OPTERON_SSE3)
  965. #ifdef DYNAMIC_OLDER
  966. return corename[12];
  967. #else
  968. return corename[7];
  969. #endif
  970. if (gotoblas == &gotoblas_OPTERON)
  971. #ifdef DYNAMIC_OLDER
  972. return corename[13];
  973. #else
  974. return corename[7];
  975. #endif
  976. if (gotoblas == &gotoblas_BARCELONA) return corename[14];
  977. if (gotoblas == &gotoblas_NANO)
  978. #ifdef DYNAMIC_OLDER
  979. return corename[15];
  980. #else
  981. return corename[10];
  982. #endif
  983. if (gotoblas == &gotoblas_SANDYBRIDGE) return corename[16];
  984. if (gotoblas == &gotoblas_BOBCAT)
  985. #ifdef DYNAMIC_OLDER
  986. return corename[17];
  987. #else
  988. return corename[7];
  989. #endif
  990. if (gotoblas == &gotoblas_BULLDOZER) return corename[18];
  991. if (gotoblas == &gotoblas_PILEDRIVER) return corename[19];
  992. if (gotoblas == &gotoblas_HASWELL) return corename[20];
  993. if (gotoblas == &gotoblas_STEAMROLLER) return corename[21];
  994. if (gotoblas == &gotoblas_EXCAVATOR) return corename[22];
  995. if (gotoblas == &gotoblas_ZEN) return corename[23];
  996. if (gotoblas == &gotoblas_SKYLAKEX) return corename[24];
  997. if (gotoblas == &gotoblas_COOPERLAKE) return corename[25];
  998. if (gotoblas == &gotoblas_SAPPHIRERAPIDS) return corename[26];
  999. return corename[0];
  1000. }
  1001. static gotoblas_t *force_coretype(char *coretype){
  1002. int i ;
  1003. int found = -1;
  1004. char message[128];
  1005. //char mname[20];
  1006. for ( i=1 ; i <= 25; i++)
  1007. {
  1008. if (!strncasecmp(coretype,corename[i],20))
  1009. {
  1010. found = i;
  1011. break;
  1012. }
  1013. }
  1014. if (found < 0)
  1015. {
  1016. //strncpy(mname,coretype,20);
  1017. snprintf(message, 128, "Core not found: %s\n",coretype);
  1018. openblas_warning(1, message);
  1019. return(NULL);
  1020. }
  1021. switch (found)
  1022. {
  1023. case 25: return (&gotoblas_COOPERLAKE);
  1024. case 24: return (&gotoblas_SKYLAKEX);
  1025. case 23: return (&gotoblas_ZEN);
  1026. case 22: return (&gotoblas_EXCAVATOR);
  1027. case 21: return (&gotoblas_STEAMROLLER);
  1028. case 20: return (&gotoblas_HASWELL);
  1029. case 19: return (&gotoblas_PILEDRIVER);
  1030. case 18: return (&gotoblas_BULLDOZER);
  1031. case 17: return (&gotoblas_BOBCAT);
  1032. case 16: return (&gotoblas_SANDYBRIDGE);
  1033. case 15: return (&gotoblas_NANO);
  1034. case 14: return (&gotoblas_BARCELONA);
  1035. case 13: return (&gotoblas_OPTERON);
  1036. case 12: return (&gotoblas_OPTERON_SSE3);
  1037. case 11: return (&gotoblas_ATHLON);
  1038. case 10: return (&gotoblas_NEHALEM);
  1039. case 9: return (&gotoblas_DUNNINGTON);
  1040. case 8: return (&gotoblas_PENRYN);
  1041. case 7: return (&gotoblas_CORE2);
  1042. case 6: return (&gotoblas_ATOM);
  1043. case 5: return (&gotoblas_BANIAS);
  1044. case 4: return (&gotoblas_PRESCOTT);
  1045. case 3: return (&gotoblas_NORTHWOOD);
  1046. case 2: return (&gotoblas_COPPERMINE);
  1047. case 1: return (&gotoblas_KATMAI);
  1048. }
  1049. return(NULL);
  1050. }
  1051. void gotoblas_dynamic_init(void) {
  1052. char coremsg[128];
  1053. char coren[22];
  1054. char *p;
  1055. if (gotoblas) return;
  1056. p = getenv("OPENBLAS_CORETYPE");
  1057. if ( p )
  1058. {
  1059. gotoblas = force_coretype(p);
  1060. }
  1061. else
  1062. {
  1063. gotoblas = get_coretype();
  1064. }
  1065. #ifdef ARCH_X86
  1066. if (gotoblas == NULL) gotoblas = &gotoblas_KATMAI;
  1067. #else
  1068. if (gotoblas == NULL) {
  1069. if (support_avx512_bf16()) gotoblas = &gotoblas_COOPERLAKE;
  1070. else if (support_avx512()) gotoblas = &gotoblas_SKYLAKEX;
  1071. else if (support_avx2()) gotoblas = &gotoblas_HASWELL;
  1072. else if (support_avx()) gotoblas = &gotoblas_SANDYBRIDGE;
  1073. else gotoblas = &gotoblas_PRESCOTT;
  1074. }
  1075. /* sanity check, if 64bit pointer we can't have a 32 bit cpu */
  1076. if (sizeof(void*) == 8) {
  1077. if (gotoblas == &gotoblas_KATMAI ||
  1078. gotoblas == &gotoblas_COPPERMINE ||
  1079. gotoblas == &gotoblas_NORTHWOOD ||
  1080. gotoblas == &gotoblas_BANIAS ||
  1081. gotoblas == &gotoblas_ATHLON)
  1082. gotoblas = &gotoblas_PRESCOTT;
  1083. }
  1084. #endif
  1085. if (gotoblas && gotoblas -> init) {
  1086. strncpy(coren,gotoblas_corename(),20);
  1087. sprintf(coremsg, "Core: %s\n",coren);
  1088. openblas_warning(2, coremsg);
  1089. gotoblas -> init();
  1090. } else {
  1091. openblas_warning(0, "OpenBLAS : Architecture Initialization failed. No initialization function found.\n");
  1092. exit(1);
  1093. }
  1094. }
  1095. void gotoblas_dynamic_quit(void) {
  1096. gotoblas = NULL;
  1097. }