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 35 kB

7 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176
  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. #define gotoblas_SAPPHIRERAPIDS gotoblas_SANDYBRIDGE
  270. #else
  271. extern gotoblas_t gotoblas_HASWELL;
  272. extern gotoblas_t gotoblas_ZEN;
  273. #ifndef NO_AVX512
  274. extern gotoblas_t gotoblas_SKYLAKEX;
  275. extern gotoblas_t gotoblas_COOPERLAKE;
  276. extern gotoblas_t gotoblas_SAPPHIRERAPIDS;
  277. #else
  278. #define gotoblas_SKYLAKEX gotoblas_HASWELL
  279. #define gotoblas_COOPERLAKE gotoblas_HASWELL
  280. #define gotoblas_SAPPHIRERAPIDS gotoblas_HASWELL
  281. #endif
  282. #endif
  283. #else
  284. //Use NEHALEM kernels for sandy bridge
  285. #define gotoblas_SANDYBRIDGE gotoblas_NEHALEM
  286. #define gotoblas_HASWELL gotoblas_NEHALEM
  287. #define gotoblas_SKYLAKEX gotoblas_NEHALEM
  288. #define gotoblas_COOPERLAKE gotoblas_NEHALEM
  289. #define gotoblas_SAPPHIRERAPIDS gotoblas_NEHALEM
  290. #define gotoblas_BULLDOZER gotoblas_BARCELONA
  291. #define gotoblas_PILEDRIVER gotoblas_BARCELONA
  292. #define gotoblas_STEAMROLLER gotoblas_BARCELONA
  293. #define gotoblas_EXCAVATOR gotoblas_BARCELONA
  294. #define gotoblas_ZEN gotoblas_BARCELONA
  295. #endif
  296. #endif // DYNAMIC_LIST
  297. #define VENDOR_INTEL 1
  298. #define VENDOR_AMD 2
  299. #define VENDOR_CENTAUR 3
  300. #define VENDOR_HYGON 4
  301. #define VENDOR_ZHAOXIN 5
  302. #define VENDOR_UNKNOWN 99
  303. #define BITMASK(a, b, c) ((((a) >> (b)) & (c)))
  304. #ifndef NO_AVX
  305. static inline void xgetbv(int op, int * eax, int * edx){
  306. //Use binary code for xgetbv
  307. __asm__ __volatile__
  308. (".byte 0x0f, 0x01, 0xd0": "=a" (*eax), "=d" (*edx) : "c" (op) : "cc");
  309. }
  310. #endif
  311. int support_avx(){
  312. #ifndef NO_AVX
  313. int eax, ebx, ecx, edx;
  314. int ret=0;
  315. cpuid(1, &eax, &ebx, &ecx, &edx);
  316. if ((ecx & (1 << 28)) != 0 && (ecx & (1 << 27)) != 0 && (ecx & (1 << 26)) != 0){
  317. xgetbv(0, &eax, &edx);
  318. if((eax & 6) == 6){
  319. ret=1; //OS support AVX
  320. }
  321. }
  322. return ret;
  323. #else
  324. return 0;
  325. #endif
  326. }
  327. int support_avx2(){
  328. #ifndef NO_AVX2
  329. int eax, ebx, ecx=0, edx;
  330. int ret=0;
  331. if (!support_avx())
  332. return 0;
  333. cpuid(7, &eax, &ebx, &ecx, &edx);
  334. if((ebx & (1<<5)) != 0)
  335. ret=1; //AVX2 flag is set
  336. return ret;
  337. #else
  338. return 0;
  339. #endif
  340. }
  341. int support_avx512(){
  342. #if !defined(NO_AVX) && !defined(NO_AVX512)
  343. int eax, ebx, ecx, edx;
  344. int ret=0;
  345. if (!support_avx())
  346. return 0;
  347. cpuid(7, &eax, &ebx, &ecx, &edx);
  348. if((ebx & (1<<5)) == 0){
  349. ret=0; //cpu does not have avx2 flag
  350. }
  351. if((ebx & (1<<31)) != 0){ //AVX512VL flag is set
  352. xgetbv(0, &eax, &edx);
  353. if((eax & 0xe0) == 0xe0)
  354. ret=1; //OS supports saving zmm register
  355. }
  356. return ret;
  357. #else
  358. return 0;
  359. #endif
  360. }
  361. int support_avx512_bf16(){
  362. #if !defined(NO_AVX) && !defined(NO_AVX512)
  363. int eax, ebx, ecx, edx;
  364. int ret=0;
  365. if (!support_avx512())
  366. return 0;
  367. cpuid_count(7, 1, &eax, &ebx, &ecx, &edx);
  368. if((eax & 32) == 32){
  369. ret=1; // CPUID.7.1:EAX[bit 5] indicates whether avx512_bf16 supported or not
  370. }
  371. return ret;
  372. #else
  373. return 0;
  374. #endif
  375. }
  376. #define BIT_AMX_TILE 0x01000000
  377. #define BIT_AMX_BF16 0x00400000
  378. #define BIT_AMX_ENBD 0x00060000
  379. int support_amx_bf16() {
  380. #if !defined(NO_AVX) && !defined(NO_AVX512)
  381. int eax, ebx, ecx, edx;
  382. int ret=0;
  383. if (!support_avx512())
  384. return 0;
  385. // CPUID.7.0:EDX indicates AMX support
  386. cpuid_count(7, 0, &eax, &ebx, &ecx, &edx);
  387. if ((edx & BIT_AMX_TILE) && (edx & BIT_AMX_BF16)) {
  388. // CPUID.D.0:EAX[17:18] indicates AMX enabled
  389. cpuid_count(0xd, 0, &eax, &ebx, &ecx, &edx);
  390. if ((eax & BIT_AMX_ENBD) == BIT_AMX_ENBD)
  391. ret = 1;
  392. }
  393. return ret;
  394. #else
  395. return 0;
  396. #endif
  397. }
  398. extern void openblas_warning(int verbose, const char * msg);
  399. #define FALLBACK_VERBOSE 1
  400. #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"
  401. #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"
  402. #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"
  403. #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"
  404. static int get_vendor(void){
  405. int eax, ebx, ecx, edx;
  406. union
  407. {
  408. char vchar[16];
  409. int vint[4];
  410. } vendor;
  411. cpuid(0, &eax, &ebx, &ecx, &edx);
  412. *(&vendor.vint[0]) = ebx;
  413. *(&vendor.vint[1]) = edx;
  414. *(&vendor.vint[2]) = ecx;
  415. vendor.vchar[12] = '\0';
  416. if (!strcmp(vendor.vchar, "GenuineIntel")) return VENDOR_INTEL;
  417. if (!strcmp(vendor.vchar, "AuthenticAMD")) return VENDOR_AMD;
  418. if (!strcmp(vendor.vchar, "CentaurHauls")) return VENDOR_CENTAUR;
  419. if (!strcmp(vendor.vchar, " Shanghai ")) return VENDOR_ZHAOXIN;
  420. if (!strcmp(vendor.vchar, "HygonGenuine")) return VENDOR_HYGON;
  421. if ((eax == 0) || ((eax & 0x500) != 0)) return VENDOR_INTEL;
  422. return VENDOR_UNKNOWN;
  423. }
  424. static gotoblas_t *get_coretype(void){
  425. int eax, ebx, ecx, edx;
  426. int family, exfamily, model, vendor, exmodel, stepping;
  427. cpuid(1, &eax, &ebx, &ecx, &edx);
  428. family = BITMASK(eax, 8, 0x0f);
  429. exfamily = BITMASK(eax, 20, 0xff);
  430. model = BITMASK(eax, 4, 0x0f);
  431. exmodel = BITMASK(eax, 16, 0x0f);
  432. stepping = BITMASK(eax, 0, 0x0f);
  433. vendor = get_vendor();
  434. if (vendor == VENDOR_INTEL){
  435. switch (family) {
  436. case 0x6:
  437. switch (exmodel) {
  438. case 0:
  439. if (model <= 0x7) return &gotoblas_KATMAI;
  440. if ((model == 0x8) || (model == 0xa) || (model == 0xb)) return &gotoblas_COPPERMINE;
  441. if ((model == 0x9) || (model == 0xd)) return &gotoblas_BANIAS;
  442. if (model == 14) return &gotoblas_BANIAS;
  443. if (model == 15) return &gotoblas_CORE2;
  444. return NULL;
  445. case 1:
  446. if (model == 6) return &gotoblas_CORE2;
  447. if (model == 7) return &gotoblas_PENRYN;
  448. if (model == 13) return &gotoblas_DUNNINGTON;
  449. if ((model == 10) || (model == 11) || (model == 14) || (model == 15)) return &gotoblas_NEHALEM;
  450. if (model == 12) return &gotoblas_ATOM;
  451. return NULL;
  452. case 2:
  453. //Intel Core (Clarkdale) / Core (Arrandale)
  454. // Pentium (Clarkdale) / Pentium Mobile (Arrandale)
  455. // Xeon (Clarkdale), 32nm
  456. if (model == 5) return &gotoblas_NEHALEM;
  457. //Intel Xeon Processor 5600 (Westmere-EP)
  458. //Xeon Processor E7 (Westmere-EX)
  459. //Xeon E7540
  460. if (model == 12 || model == 14 || model == 15) return &gotoblas_NEHALEM;
  461. //Intel Core i5-2000 /i7-2000 (Sandy Bridge)
  462. //Intel Core i7-3000 / Xeon E5
  463. if (model == 10 || model == 13) {
  464. if(support_avx())
  465. return &gotoblas_SANDYBRIDGE;
  466. else{
  467. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  468. return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels.
  469. }
  470. }
  471. return NULL;
  472. case 3:
  473. //Intel Sandy Bridge 22nm (Ivy Bridge?)
  474. if (model == 10 || model == 14) {
  475. if(support_avx())
  476. return &gotoblas_SANDYBRIDGE;
  477. else{
  478. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  479. return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels.
  480. }
  481. }
  482. //Intel Haswell
  483. if (model == 12 || model == 15) {
  484. if(support_avx2())
  485. return &gotoblas_HASWELL;
  486. if(support_avx()) {
  487. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  488. return &gotoblas_SANDYBRIDGE;
  489. } else {
  490. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  491. return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels.
  492. }
  493. }
  494. //Intel Broadwell
  495. if (model == 13) {
  496. if(support_avx2())
  497. return &gotoblas_HASWELL;
  498. if(support_avx()) {
  499. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  500. return &gotoblas_SANDYBRIDGE;
  501. } else {
  502. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  503. return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels.
  504. }
  505. }
  506. if (model == 7) return &gotoblas_ATOM; //Bay Trail
  507. return NULL;
  508. case 4:
  509. //Intel Haswell
  510. if (model == 5 || model == 6) {
  511. if(support_avx2())
  512. return &gotoblas_HASWELL;
  513. if(support_avx()) {
  514. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  515. return &gotoblas_SANDYBRIDGE;
  516. } else {
  517. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  518. return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels.
  519. }
  520. }
  521. //Intel Broadwell
  522. if (model == 7 || model == 15) {
  523. if(support_avx2())
  524. return &gotoblas_HASWELL;
  525. if(support_avx()) {
  526. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  527. return &gotoblas_SANDYBRIDGE;
  528. } else {
  529. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  530. return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels.
  531. }
  532. }
  533. //Intel Skylake
  534. if (model == 14) {
  535. if(support_avx2())
  536. return &gotoblas_HASWELL;
  537. if(support_avx()) {
  538. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  539. return &gotoblas_SANDYBRIDGE;
  540. } else {
  541. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  542. return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels.
  543. }
  544. }
  545. //Intel Braswell / Avoton
  546. if (model == 12 || model == 13) {
  547. return &gotoblas_NEHALEM;
  548. }
  549. return NULL;
  550. case 5:
  551. //Intel Broadwell
  552. if (model == 6) {
  553. if(support_avx2())
  554. return &gotoblas_HASWELL;
  555. if(support_avx()) {
  556. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  557. return &gotoblas_SANDYBRIDGE;
  558. } else {
  559. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  560. return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels.
  561. }
  562. }
  563. if (model == 5) {
  564. // Intel Cooperlake
  565. if(support_avx512_bf16())
  566. return &gotoblas_COOPERLAKE;
  567. // Intel Skylake X
  568. if (support_avx512())
  569. return &gotoblas_SKYLAKEX;
  570. if(support_avx2()){
  571. openblas_warning(FALLBACK_VERBOSE, HASWELL_FALLBACK);
  572. return &gotoblas_HASWELL;
  573. }
  574. if(support_avx()) {
  575. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  576. return &gotoblas_SANDYBRIDGE;
  577. } else {
  578. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  579. return &gotoblas_NEHALEM;
  580. }
  581. }
  582. //Intel Skylake
  583. if (model == 14) {
  584. if(support_avx2())
  585. return &gotoblas_HASWELL;
  586. if(support_avx()) {
  587. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  588. return &gotoblas_SANDYBRIDGE;
  589. } else {
  590. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  591. return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels.
  592. }
  593. }
  594. //Intel Phi Knights Landing
  595. if (model == 7) {
  596. if(support_avx2()){
  597. openblas_warning(FALLBACK_VERBOSE, HASWELL_FALLBACK);
  598. return &gotoblas_HASWELL;
  599. }
  600. if(support_avx()) {
  601. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  602. return &gotoblas_SANDYBRIDGE;
  603. } else {
  604. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  605. return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels.
  606. }
  607. }
  608. //Apollo Lake or Denverton
  609. if (model == 12 || model == 15) {
  610. return &gotoblas_NEHALEM;
  611. }
  612. return NULL;
  613. case 6:
  614. if (model == 6) {
  615. // Cannon Lake
  616. if(support_avx2())
  617. return &gotoblas_HASWELL;
  618. if(support_avx()) {
  619. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  620. return &gotoblas_SANDYBRIDGE;
  621. } else {
  622. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  623. return &gotoblas_NEHALEM;
  624. }
  625. }
  626. if (model == 10 || model == 12){
  627. // Ice Lake SP
  628. if(support_avx512_bf16())
  629. return &gotoblas_COOPERLAKE;
  630. if (support_avx512())
  631. return &gotoblas_SKYLAKEX;
  632. if(support_avx2())
  633. return &gotoblas_HASWELL;
  634. if(support_avx()) {
  635. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  636. return &gotoblas_SANDYBRIDGE;
  637. } else {
  638. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  639. return &gotoblas_NEHALEM;
  640. }
  641. }
  642. return NULL;
  643. case 7:
  644. if (model == 10) // Goldmont Plus
  645. return &gotoblas_NEHALEM;
  646. if (model == 13 || model == 14) {
  647. // Ice Lake
  648. if (support_avx512())
  649. return &gotoblas_SKYLAKEX;
  650. if(support_avx2()){
  651. openblas_warning(FALLBACK_VERBOSE, HASWELL_FALLBACK);
  652. return &gotoblas_HASWELL;
  653. }
  654. if(support_avx()) {
  655. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  656. return &gotoblas_SANDYBRIDGE;
  657. } else {
  658. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  659. return &gotoblas_NEHALEM;
  660. }
  661. }
  662. return NULL;
  663. case 8:
  664. if (model == 12 || model == 13) { // Tiger Lake
  665. if (support_avx512())
  666. return &gotoblas_SKYLAKEX;
  667. if(support_avx2()){
  668. openblas_warning(FALLBACK_VERBOSE, HASWELL_FALLBACK);
  669. return &gotoblas_HASWELL;
  670. }
  671. if(support_avx()) {
  672. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  673. return &gotoblas_SANDYBRIDGE;
  674. } else {
  675. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  676. return &gotoblas_NEHALEM;
  677. }
  678. }
  679. if (model == 14 ) { // Kaby Lake, Coffee Lake
  680. if(support_avx2())
  681. return &gotoblas_HASWELL;
  682. if(support_avx()) {
  683. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  684. return &gotoblas_SANDYBRIDGE;
  685. } else {
  686. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  687. return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels.
  688. }
  689. }
  690. if (model == 15){ // Sapphire Rapids
  691. if(support_amx_bf16())
  692. return &gotoblas_SAPPHIRERAPIDS;
  693. if(support_avx512_bf16())
  694. return &gotoblas_COOPERLAKE;
  695. if (support_avx512())
  696. return &gotoblas_SKYLAKEX;
  697. if(support_avx2())
  698. return &gotoblas_HASWELL;
  699. if(support_avx()) {
  700. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  701. return &gotoblas_SANDYBRIDGE;
  702. } else {
  703. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  704. return &gotoblas_NEHALEM;
  705. }
  706. }
  707. return NULL;
  708. case 9:
  709. if (model == 7 || model == 10) { // Alder Lake
  710. if(support_avx512_bf16())
  711. return &gotoblas_COOPERLAKE;
  712. if (support_avx512())
  713. return &gotoblas_SKYLAKEX;
  714. if(support_avx2()){
  715. return &gotoblas_HASWELL;
  716. }
  717. if(support_avx()) {
  718. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  719. return &gotoblas_SANDYBRIDGE;
  720. } else {
  721. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  722. return &gotoblas_NEHALEM;
  723. }
  724. }
  725. if (model == 14 ) { // Kaby Lake, Coffee Lake
  726. if(support_avx2())
  727. return &gotoblas_HASWELL;
  728. if(support_avx()) {
  729. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  730. return &gotoblas_SANDYBRIDGE;
  731. } else {
  732. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  733. return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels.
  734. }
  735. }
  736. return NULL;
  737. case 10:
  738. if (model == 5 || model == 6) {
  739. if(support_avx2())
  740. return &gotoblas_HASWELL;
  741. if(support_avx()) {
  742. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  743. return &gotoblas_SANDYBRIDGE;
  744. } else {
  745. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  746. return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels.
  747. }
  748. }
  749. if (model == 7) {
  750. if (support_avx512())
  751. return &gotoblas_SKYLAKEX;
  752. if(support_avx2())
  753. return &gotoblas_HASWELL;
  754. if(support_avx()) {
  755. openblas_warning(FALLBACK_VERBOSE, SANDYBRIDGE_FALLBACK);
  756. return &gotoblas_SANDYBRIDGE;
  757. } else {
  758. openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
  759. return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels.
  760. }
  761. }
  762. return NULL;
  763. }
  764. break;
  765. case 0xf:
  766. if (model <= 0x2) return &gotoblas_NORTHWOOD;
  767. return &gotoblas_PRESCOTT;
  768. }
  769. }
  770. if (vendor == VENDOR_AMD || vendor == VENDOR_HYGON){
  771. if (family <= 0xe) {
  772. // Verify that CPU has 3dnow and 3dnowext before claiming it is Athlon
  773. cpuid(0x80000000, &eax, &ebx, &ecx, &edx);
  774. if ( (eax & 0xffff) >= 0x01) {
  775. cpuid(0x80000001, &eax, &ebx, &ecx, &edx);
  776. if ((edx & (1 << 30)) == 0 || (edx & (1u << 31)) == 0)
  777. return NULL;
  778. }
  779. else
  780. return NULL;
  781. return &gotoblas_ATHLON;
  782. }
  783. if (family == 0xf){
  784. if ((exfamily == 0) || (exfamily == 2)) {
  785. if (ecx & (1 << 0)) return &gotoblas_OPTERON_SSE3;
  786. else return &gotoblas_OPTERON;
  787. } else if (exfamily == 5 || exfamily == 7) {
  788. return &gotoblas_BOBCAT;
  789. } else if (exfamily == 6) {
  790. if(model == 1){
  791. //AMD Bulldozer Opteron 6200 / Opteron 4200 / AMD FX-Series
  792. if(support_avx())
  793. return &gotoblas_BULLDOZER;
  794. else{
  795. openblas_warning(FALLBACK_VERBOSE, BARCELONA_FALLBACK);
  796. return &gotoblas_BARCELONA; //OS doesn't support AVX. Use old kernels.
  797. }
  798. }else if(model == 2 || model == 3){
  799. //AMD Bulldozer Opteron 6300 / Opteron 4300 / Opteron 3300
  800. if(support_avx())
  801. return &gotoblas_PILEDRIVER;
  802. else{
  803. openblas_warning(FALLBACK_VERBOSE, BARCELONA_FALLBACK);
  804. return &gotoblas_BARCELONA; //OS doesn't support AVX. Use old kernels.
  805. }
  806. }else if(model == 5){
  807. if(support_avx())
  808. return &gotoblas_EXCAVATOR;
  809. else{
  810. openblas_warning(FALLBACK_VERBOSE, BARCELONA_FALLBACK);
  811. return &gotoblas_BARCELONA; //OS doesn't support AVX. Use old kernels.
  812. }
  813. }else if(model == 0 || model == 8){
  814. if (exmodel == 1) {
  815. //AMD Trinity
  816. if(support_avx())
  817. return &gotoblas_PILEDRIVER;
  818. else{
  819. openblas_warning(FALLBACK_VERBOSE, BARCELONA_FALLBACK);
  820. return &gotoblas_BARCELONA; //OS doesn't support AVX. Use old kernels.
  821. }
  822. }else if (exmodel == 3) {
  823. //AMD STEAMROLLER
  824. if(support_avx())
  825. return &gotoblas_STEAMROLLER;
  826. else{
  827. openblas_warning(FALLBACK_VERBOSE, BARCELONA_FALLBACK);
  828. return &gotoblas_BARCELONA; //OS doesn't support AVX. Use old kernels.
  829. }
  830. }else if (exmodel == 6) {
  831. if(support_avx())
  832. return &gotoblas_EXCAVATOR;
  833. else{
  834. openblas_warning(FALLBACK_VERBOSE, BARCELONA_FALLBACK);
  835. return &gotoblas_BARCELONA; //OS doesn't support AVX. Use old kernels.
  836. }
  837. }
  838. }
  839. } else if (exfamily == 8) {
  840. /* if (model == 1 || model == 8) */ {
  841. if(support_avx())
  842. return &gotoblas_ZEN;
  843. else{
  844. openblas_warning(FALLBACK_VERBOSE, BARCELONA_FALLBACK);
  845. return &gotoblas_BARCELONA; //OS doesn't support AVX. Use old kernels.
  846. }
  847. }
  848. } else if (exfamily == 9) {
  849. if(support_avx())
  850. return &gotoblas_ZEN;
  851. else{
  852. openblas_warning(FALLBACK_VERBOSE, BARCELONA_FALLBACK);
  853. return &gotoblas_BARCELONA; //OS doesn't support AVX. Use old kernels.
  854. }
  855. } else if (exfamily == 10) {
  856. if(support_avx512_bf16())
  857. return &gotoblas_COOPERLAKE;
  858. if(support_avx512())
  859. return &gotoblas_SKYLAKEX;
  860. if(support_avx())
  861. return &gotoblas_ZEN;
  862. else{
  863. openblas_warning(FALLBACK_VERBOSE, BARCELONA_FALLBACK);
  864. return &gotoblas_BARCELONA; //OS doesn't support AVX. Use old kernels.
  865. }
  866. }else {
  867. return NULL;
  868. }
  869. }
  870. }
  871. if (vendor == VENDOR_CENTAUR) {
  872. switch (family) {
  873. case 0x6:
  874. if (model == 0xf && stepping < 0xe)
  875. return &gotoblas_NANO;
  876. return &gotoblas_NEHALEM;
  877. case 0x7:
  878. switch (exmodel) {
  879. case 5:
  880. case 6:
  881. if (support_avx2())
  882. return &gotoblas_ZEN;
  883. else
  884. return &gotoblas_DUNNINGTON;
  885. default:
  886. return &gotoblas_NEHALEM;
  887. }
  888. default:
  889. if (family >= 0x8)
  890. return &gotoblas_NEHALEM;
  891. }
  892. }
  893. if (vendor == VENDOR_ZHAOXIN) {
  894. switch (family) {
  895. case 0x7:
  896. switch (exmodel) {
  897. case 5:
  898. if (support_avx2())
  899. return &gotoblas_ZEN;
  900. else
  901. return &gotoblas_DUNNINGTON;
  902. default:
  903. return &gotoblas_NEHALEM;
  904. }
  905. default:
  906. return &gotoblas_NEHALEM;
  907. }
  908. }
  909. return NULL;
  910. }
  911. static char *corename[] = {
  912. "Unknown",
  913. "Katmai",
  914. "Coppermine",
  915. "Northwood",
  916. "Prescott",
  917. "Banias",
  918. "Atom",
  919. "Core2",
  920. "Penryn",
  921. "Dunnington",
  922. "Nehalem",
  923. "Athlon",
  924. "Opteron",
  925. "Opteron_SSE3",
  926. "Barcelona",
  927. "Nano",
  928. "Sandybridge",
  929. "Bobcat",
  930. "Bulldozer",
  931. "Piledriver",
  932. "Haswell",
  933. "Steamroller",
  934. "Excavator",
  935. "Zen",
  936. "SkylakeX",
  937. "Cooperlake",
  938. "SapphireRapids"
  939. };
  940. char *gotoblas_corename(void) {
  941. if (gotoblas == &gotoblas_KATMAI) return corename[ 1];
  942. if (gotoblas == &gotoblas_COPPERMINE) return corename[ 2];
  943. if (gotoblas == &gotoblas_NORTHWOOD) return corename[ 3];
  944. if (gotoblas == &gotoblas_PRESCOTT) return corename[ 4];
  945. if (gotoblas == &gotoblas_BANIAS) return corename[ 5];
  946. if (gotoblas == &gotoblas_ATOM)
  947. #ifdef DYNAMIC_OLDER
  948. return corename[ 6];
  949. #else
  950. return corename[10];
  951. #endif
  952. if (gotoblas == &gotoblas_CORE2) return corename[ 7];
  953. if (gotoblas == &gotoblas_PENRYN)
  954. #ifdef DYNAMIC_OLDER
  955. return corename[ 8];
  956. #else
  957. return corename[7];
  958. #endif
  959. if (gotoblas == &gotoblas_DUNNINGTON)
  960. #ifdef DYNAMIC_OLDER
  961. return corename[ 9];
  962. #else
  963. return corename[7];
  964. #endif
  965. if (gotoblas == &gotoblas_NEHALEM) return corename[10];
  966. if (gotoblas == &gotoblas_ATHLON) return corename[11];
  967. if (gotoblas == &gotoblas_OPTERON_SSE3)
  968. #ifdef DYNAMIC_OLDER
  969. return corename[12];
  970. #else
  971. return corename[7];
  972. #endif
  973. if (gotoblas == &gotoblas_OPTERON)
  974. #ifdef DYNAMIC_OLDER
  975. return corename[13];
  976. #else
  977. return corename[7];
  978. #endif
  979. if (gotoblas == &gotoblas_BARCELONA) return corename[14];
  980. if (gotoblas == &gotoblas_NANO)
  981. #ifdef DYNAMIC_OLDER
  982. return corename[15];
  983. #else
  984. return corename[10];
  985. #endif
  986. if (gotoblas == &gotoblas_SANDYBRIDGE) return corename[16];
  987. if (gotoblas == &gotoblas_BOBCAT)
  988. #ifdef DYNAMIC_OLDER
  989. return corename[17];
  990. #else
  991. return corename[7];
  992. #endif
  993. if (gotoblas == &gotoblas_BULLDOZER) return corename[18];
  994. if (gotoblas == &gotoblas_PILEDRIVER) return corename[19];
  995. if (gotoblas == &gotoblas_HASWELL) return corename[20];
  996. if (gotoblas == &gotoblas_STEAMROLLER) return corename[21];
  997. if (gotoblas == &gotoblas_EXCAVATOR) return corename[22];
  998. if (gotoblas == &gotoblas_ZEN) return corename[23];
  999. if (gotoblas == &gotoblas_SKYLAKEX) return corename[24];
  1000. if (gotoblas == &gotoblas_COOPERLAKE) return corename[25];
  1001. if (gotoblas == &gotoblas_SAPPHIRERAPIDS) return corename[26];
  1002. return corename[0];
  1003. }
  1004. static gotoblas_t *force_coretype(char *coretype){
  1005. int i ;
  1006. int found = -1;
  1007. char message[128];
  1008. //char mname[20];
  1009. for ( i=1 ; i <= 25; i++)
  1010. {
  1011. if (!strncasecmp(coretype,corename[i],20))
  1012. {
  1013. found = i;
  1014. break;
  1015. }
  1016. }
  1017. if (found < 0)
  1018. {
  1019. //strncpy(mname,coretype,20);
  1020. snprintf(message, 128, "Core not found: %s\n",coretype);
  1021. openblas_warning(1, message);
  1022. return(NULL);
  1023. }
  1024. switch (found)
  1025. {
  1026. case 25: return (&gotoblas_COOPERLAKE);
  1027. case 24: return (&gotoblas_SKYLAKEX);
  1028. case 23: return (&gotoblas_ZEN);
  1029. case 22: return (&gotoblas_EXCAVATOR);
  1030. case 21: return (&gotoblas_STEAMROLLER);
  1031. case 20: return (&gotoblas_HASWELL);
  1032. case 19: return (&gotoblas_PILEDRIVER);
  1033. case 18: return (&gotoblas_BULLDOZER);
  1034. case 17: return (&gotoblas_BOBCAT);
  1035. case 16: return (&gotoblas_SANDYBRIDGE);
  1036. case 15: return (&gotoblas_NANO);
  1037. case 14: return (&gotoblas_BARCELONA);
  1038. case 13: return (&gotoblas_OPTERON);
  1039. case 12: return (&gotoblas_OPTERON_SSE3);
  1040. case 11: return (&gotoblas_ATHLON);
  1041. case 10: return (&gotoblas_NEHALEM);
  1042. case 9: return (&gotoblas_DUNNINGTON);
  1043. case 8: return (&gotoblas_PENRYN);
  1044. case 7: return (&gotoblas_CORE2);
  1045. case 6: return (&gotoblas_ATOM);
  1046. case 5: return (&gotoblas_BANIAS);
  1047. case 4: return (&gotoblas_PRESCOTT);
  1048. case 3: return (&gotoblas_NORTHWOOD);
  1049. case 2: return (&gotoblas_COPPERMINE);
  1050. case 1: return (&gotoblas_KATMAI);
  1051. }
  1052. return(NULL);
  1053. }
  1054. void gotoblas_dynamic_init(void) {
  1055. char coremsg[128];
  1056. char coren[22];
  1057. char *p;
  1058. if (gotoblas) return;
  1059. p = getenv("OPENBLAS_CORETYPE");
  1060. if ( p )
  1061. {
  1062. gotoblas = force_coretype(p);
  1063. }
  1064. else
  1065. {
  1066. gotoblas = get_coretype();
  1067. }
  1068. #ifdef ARCH_X86
  1069. if (gotoblas == NULL) gotoblas = &gotoblas_KATMAI;
  1070. #else
  1071. if (gotoblas == NULL) {
  1072. if (support_avx512_bf16()) gotoblas = &gotoblas_COOPERLAKE;
  1073. else if (support_avx512()) gotoblas = &gotoblas_SKYLAKEX;
  1074. else if (support_avx2()) gotoblas = &gotoblas_HASWELL;
  1075. else if (support_avx()) gotoblas = &gotoblas_SANDYBRIDGE;
  1076. else gotoblas = &gotoblas_PRESCOTT;
  1077. }
  1078. /* sanity check, if 64bit pointer we can't have a 32 bit cpu */
  1079. if (sizeof(void*) == 8) {
  1080. if (gotoblas == &gotoblas_KATMAI ||
  1081. gotoblas == &gotoblas_COPPERMINE ||
  1082. gotoblas == &gotoblas_NORTHWOOD ||
  1083. gotoblas == &gotoblas_BANIAS ||
  1084. gotoblas == &gotoblas_ATHLON)
  1085. gotoblas = &gotoblas_PRESCOTT;
  1086. }
  1087. #endif
  1088. if (gotoblas && gotoblas -> init) {
  1089. strncpy(coren,gotoblas_corename(),20);
  1090. sprintf(coremsg, "Core: %s\n",coren);
  1091. openblas_warning(2, coremsg);
  1092. gotoblas -> init();
  1093. } else {
  1094. openblas_warning(0, "OpenBLAS : Architecture Initialization failed. No initialization function found.\n");
  1095. exit(1);
  1096. }
  1097. }
  1098. void gotoblas_dynamic_quit(void) {
  1099. gotoblas = NULL;
  1100. }