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

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