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_power.c 2.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #include "common.h"
  2. extern gotoblas_t gotoblas_POWER6;
  3. extern gotoblas_t gotoblas_POWER8;
  4. #if (!defined __GNUC__) || ( __GNUC__ >= 6)
  5. extern gotoblas_t gotoblas_POWER9;
  6. #endif
  7. //#if (!defined __GNUC__) || ( __GNUC__ >= 11) \
  8. // || (__GNUC__ == 10 && __GNUC_MINOR__ >= 2)
  9. //#define HAVE_P10_SUPPORT 1
  10. //#endif
  11. #ifdef HAVE_P10_SUPPORT
  12. extern gotoblas_t gotoblas_POWER10;
  13. #endif
  14. extern void openblas_warning(int verbose, const char *msg);
  15. static char *corename[] = {
  16. "unknown",
  17. "POWER6",
  18. "POWER8",
  19. "POWER9",
  20. "POWER10"
  21. };
  22. #define NUM_CORETYPES 4
  23. char *gotoblas_corename(void) {
  24. if (gotoblas == &gotoblas_POWER6) return corename[1];
  25. if (gotoblas == &gotoblas_POWER8) return corename[2];
  26. #if (!defined __GNUC__) || ( __GNUC__ >= 6)
  27. if (gotoblas == &gotoblas_POWER9) return corename[3];
  28. #endif
  29. #ifdef HAVE_P10_SUPPORT
  30. if (gotoblas == &gotoblas_POWER10) return corename[4];
  31. #endif
  32. return corename[0];
  33. }
  34. static gotoblas_t *get_coretype(void) {
  35. if (__builtin_cpu_is("power6") || __builtin_cpu_is("power6x"))
  36. return &gotoblas_POWER6;
  37. if (__builtin_cpu_is("power8"))
  38. return &gotoblas_POWER8;
  39. #if (!defined __GNUC__) || ( __GNUC__ >= 6)
  40. if (__builtin_cpu_is("power9"))
  41. return &gotoblas_POWER9;
  42. #endif
  43. #ifdef HAVE_P10_SUPPORT
  44. if (__builtin_cpu_supports ("arch_3_1") && __builtin_cpu_supports ("mma"))
  45. return &gotoblas_POWER10;
  46. #endif
  47. /* Fall back to the POWER9 implementation if the toolchain is too old or the MMA feature is not set */
  48. #if (!defined __GNUC__) || ( __GNUC__ >= 6)
  49. if (__builtin_cpu_is("power10"))
  50. return &gotoblas_POWER9;
  51. #endif
  52. return NULL;
  53. }
  54. static gotoblas_t *force_coretype(char * coretype) {
  55. int i ;
  56. int found = -1;
  57. char message[128];
  58. for ( i = 0 ; i < NUM_CORETYPES; i++)
  59. {
  60. if (!strncasecmp(coretype, corename[i], 20))
  61. {
  62. found = i;
  63. break;
  64. }
  65. }
  66. switch (found)
  67. {
  68. case 1: return (&gotoblas_POWER6);
  69. case 2: return (&gotoblas_POWER8);
  70. #if (!defined __GNUC__) || ( __GNUC__ >= 6)
  71. case 3: return (&gotoblas_POWER9);
  72. #endif
  73. #ifdef HAVE_P10_SUPPORT
  74. case 4: return (&gotoblas_POWER10);
  75. #endif
  76. default: return NULL;
  77. }
  78. snprintf(message, 128, "Core not found: %s\n", coretype);
  79. openblas_warning(1, message);
  80. }
  81. void gotoblas_dynamic_init(void) {
  82. char coremsg[128];
  83. char coren[22];
  84. char *p;
  85. if (gotoblas) return;
  86. p = getenv("OPENBLAS_CORETYPE");
  87. if ( p )
  88. {
  89. gotoblas = force_coretype(p);
  90. }
  91. else
  92. {
  93. gotoblas = get_coretype();
  94. }
  95. if (gotoblas == NULL)
  96. {
  97. snprintf(coremsg, 128, "Falling back to POWER8 core\n");
  98. openblas_warning(1, coremsg);
  99. gotoblas = &gotoblas_POWER8;
  100. }
  101. if (gotoblas && gotoblas -> init) {
  102. strncpy(coren,gotoblas_corename(),20);
  103. sprintf(coremsg, "Core: %s\n",coren);
  104. openblas_warning(2, coremsg);
  105. gotoblas -> init();
  106. } else {
  107. openblas_warning(0, "OpenBLAS : Architecture Initialization failed. No initialization function found.\n");
  108. exit(1);
  109. }
  110. }
  111. void gotoblas_dynamic_quit(void) {
  112. gotoblas = NULL;
  113. }