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
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175
  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. if (support_avx2())
  881. return &gotoblas_ZEN;
  882. else
  883. return &gotoblas_DUNNINGTON;
  884. default:
  885. return &gotoblas_NEHALEM;
  886. }
  887. default:
  888. if (family >= 0x8)
  889. return &gotoblas_NEHALEM;
  890. }
  891. }
  892. if (vendor == VENDOR_ZHAOXIN) {
  893. switch (family) {
  894. case 0x7:
  895. switch (exmodel) {
  896. case 5:
  897. if (support_avx2())
  898. return &gotoblas_ZEN;
  899. else
  900. return &gotoblas_DUNNINGTON;
  901. default:
  902. return &gotoblas_NEHALEM;
  903. }
  904. default:
  905. return &gotoblas_NEHALEM;
  906. }
  907. }
  908. return NULL;
  909. }
  910. static char *corename[] = {
  911. "Unknown",
  912. "Katmai",
  913. "Coppermine",
  914. "Northwood",
  915. "Prescott",
  916. "Banias",
  917. "Atom",
  918. "Core2",
  919. "Penryn",
  920. "Dunnington",
  921. "Nehalem",
  922. "Athlon",
  923. "Opteron",
  924. "Opteron_SSE3",
  925. "Barcelona",
  926. "Nano",
  927. "Sandybridge",
  928. "Bobcat",
  929. "Bulldozer",
  930. "Piledriver",
  931. "Haswell",
  932. "Steamroller",
  933. "Excavator",
  934. "Zen",
  935. "SkylakeX",
  936. "Cooperlake",
  937. "SapphireRapids"
  938. };
  939. char *gotoblas_corename(void) {
  940. if (gotoblas == &gotoblas_KATMAI) return corename[ 1];
  941. if (gotoblas == &gotoblas_COPPERMINE) return corename[ 2];
  942. if (gotoblas == &gotoblas_NORTHWOOD) return corename[ 3];
  943. if (gotoblas == &gotoblas_PRESCOTT) return corename[ 4];
  944. if (gotoblas == &gotoblas_BANIAS) return corename[ 5];
  945. if (gotoblas == &gotoblas_ATOM)
  946. #ifdef DYNAMIC_OLDER
  947. return corename[ 6];
  948. #else
  949. return corename[10];
  950. #endif
  951. if (gotoblas == &gotoblas_CORE2) return corename[ 7];
  952. if (gotoblas == &gotoblas_PENRYN)
  953. #ifdef DYNAMIC_OLDER
  954. return corename[ 8];
  955. #else
  956. return corename[7];
  957. #endif
  958. if (gotoblas == &gotoblas_DUNNINGTON)
  959. #ifdef DYNAMIC_OLDER
  960. return corename[ 9];
  961. #else
  962. return corename[7];
  963. #endif
  964. if (gotoblas == &gotoblas_NEHALEM) return corename[10];
  965. if (gotoblas == &gotoblas_ATHLON) return corename[11];
  966. if (gotoblas == &gotoblas_OPTERON_SSE3)
  967. #ifdef DYNAMIC_OLDER
  968. return corename[12];
  969. #else
  970. return corename[7];
  971. #endif
  972. if (gotoblas == &gotoblas_OPTERON)
  973. #ifdef DYNAMIC_OLDER
  974. return corename[13];
  975. #else
  976. return corename[7];
  977. #endif
  978. if (gotoblas == &gotoblas_BARCELONA) return corename[14];
  979. if (gotoblas == &gotoblas_NANO)
  980. #ifdef DYNAMIC_OLDER
  981. return corename[15];
  982. #else
  983. return corename[10];
  984. #endif
  985. if (gotoblas == &gotoblas_SANDYBRIDGE) return corename[16];
  986. if (gotoblas == &gotoblas_BOBCAT)
  987. #ifdef DYNAMIC_OLDER
  988. return corename[17];
  989. #else
  990. return corename[7];
  991. #endif
  992. if (gotoblas == &gotoblas_BULLDOZER) return corename[18];
  993. if (gotoblas == &gotoblas_PILEDRIVER) return corename[19];
  994. if (gotoblas == &gotoblas_HASWELL) return corename[20];
  995. if (gotoblas == &gotoblas_STEAMROLLER) return corename[21];
  996. if (gotoblas == &gotoblas_EXCAVATOR) return corename[22];
  997. if (gotoblas == &gotoblas_ZEN) return corename[23];
  998. if (gotoblas == &gotoblas_SKYLAKEX) return corename[24];
  999. if (gotoblas == &gotoblas_COOPERLAKE) return corename[25];
  1000. if (gotoblas == &gotoblas_SAPPHIRERAPIDS) return corename[26];
  1001. return corename[0];
  1002. }
  1003. static gotoblas_t *force_coretype(char *coretype){
  1004. int i ;
  1005. int found = -1;
  1006. char message[128];
  1007. //char mname[20];
  1008. for ( i=1 ; i <= 25; i++)
  1009. {
  1010. if (!strncasecmp(coretype,corename[i],20))
  1011. {
  1012. found = i;
  1013. break;
  1014. }
  1015. }
  1016. if (found < 0)
  1017. {
  1018. //strncpy(mname,coretype,20);
  1019. snprintf(message, 128, "Core not found: %s\n",coretype);
  1020. openblas_warning(1, message);
  1021. return(NULL);
  1022. }
  1023. switch (found)
  1024. {
  1025. case 25: return (&gotoblas_COOPERLAKE);
  1026. case 24: return (&gotoblas_SKYLAKEX);
  1027. case 23: return (&gotoblas_ZEN);
  1028. case 22: return (&gotoblas_EXCAVATOR);
  1029. case 21: return (&gotoblas_STEAMROLLER);
  1030. case 20: return (&gotoblas_HASWELL);
  1031. case 19: return (&gotoblas_PILEDRIVER);
  1032. case 18: return (&gotoblas_BULLDOZER);
  1033. case 17: return (&gotoblas_BOBCAT);
  1034. case 16: return (&gotoblas_SANDYBRIDGE);
  1035. case 15: return (&gotoblas_NANO);
  1036. case 14: return (&gotoblas_BARCELONA);
  1037. case 13: return (&gotoblas_OPTERON);
  1038. case 12: return (&gotoblas_OPTERON_SSE3);
  1039. case 11: return (&gotoblas_ATHLON);
  1040. case 10: return (&gotoblas_NEHALEM);
  1041. case 9: return (&gotoblas_DUNNINGTON);
  1042. case 8: return (&gotoblas_PENRYN);
  1043. case 7: return (&gotoblas_CORE2);
  1044. case 6: return (&gotoblas_ATOM);
  1045. case 5: return (&gotoblas_BANIAS);
  1046. case 4: return (&gotoblas_PRESCOTT);
  1047. case 3: return (&gotoblas_NORTHWOOD);
  1048. case 2: return (&gotoblas_COPPERMINE);
  1049. case 1: return (&gotoblas_KATMAI);
  1050. }
  1051. return(NULL);
  1052. }
  1053. void gotoblas_dynamic_init(void) {
  1054. char coremsg[128];
  1055. char coren[22];
  1056. char *p;
  1057. if (gotoblas) return;
  1058. p = getenv("OPENBLAS_CORETYPE");
  1059. if ( p )
  1060. {
  1061. gotoblas = force_coretype(p);
  1062. }
  1063. else
  1064. {
  1065. gotoblas = get_coretype();
  1066. }
  1067. #ifdef ARCH_X86
  1068. if (gotoblas == NULL) gotoblas = &gotoblas_KATMAI;
  1069. #else
  1070. if (gotoblas == NULL) {
  1071. if (support_avx512_bf16()) gotoblas = &gotoblas_COOPERLAKE;
  1072. else if (support_avx512()) gotoblas = &gotoblas_SKYLAKEX;
  1073. else if (support_avx2()) gotoblas = &gotoblas_HASWELL;
  1074. else if (support_avx()) gotoblas = &gotoblas_SANDYBRIDGE;
  1075. else gotoblas = &gotoblas_PRESCOTT;
  1076. }
  1077. /* sanity check, if 64bit pointer we can't have a 32 bit cpu */
  1078. if (sizeof(void*) == 8) {
  1079. if (gotoblas == &gotoblas_KATMAI ||
  1080. gotoblas == &gotoblas_COPPERMINE ||
  1081. gotoblas == &gotoblas_NORTHWOOD ||
  1082. gotoblas == &gotoblas_BANIAS ||
  1083. gotoblas == &gotoblas_ATHLON)
  1084. gotoblas = &gotoblas_PRESCOTT;
  1085. }
  1086. #endif
  1087. if (gotoblas && gotoblas -> init) {
  1088. strncpy(coren,gotoblas_corename(),20);
  1089. sprintf(coremsg, "Core: %s\n",coren);
  1090. openblas_warning(2, coremsg);
  1091. gotoblas -> init();
  1092. } else {
  1093. openblas_warning(0, "OpenBLAS : Architecture Initialization failed. No initialization function found.\n");
  1094. exit(1);
  1095. }
  1096. }
  1097. void gotoblas_dynamic_quit(void) {
  1098. gotoblas = NULL;
  1099. }