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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. return NULL;
  48. }
  49. static gotoblas_t *force_coretype(char * coretype) {
  50. int i ;
  51. int found = -1;
  52. char message[128];
  53. for ( i = 0 ; i < NUM_CORETYPES; i++)
  54. {
  55. if (!strncasecmp(coretype, corename[i], 20))
  56. {
  57. found = i;
  58. break;
  59. }
  60. }
  61. switch (found)
  62. {
  63. case 1: return (&gotoblas_POWER6);
  64. case 2: return (&gotoblas_POWER8);
  65. #if (!defined __GNUC__) || ( __GNUC__ >= 6)
  66. case 3: return (&gotoblas_POWER9);
  67. #endif
  68. #ifdef HAVE_P10_SUPPORT
  69. case 4: return (&gotoblas_POWER10);
  70. #endif
  71. default: return NULL;
  72. }
  73. snprintf(message, 128, "Core not found: %s\n", coretype);
  74. openblas_warning(1, message);
  75. }
  76. void gotoblas_dynamic_init(void) {
  77. char coremsg[128];
  78. char coren[22];
  79. char *p;
  80. if (gotoblas) return;
  81. p = getenv("OPENBLAS_CORETYPE");
  82. if ( p )
  83. {
  84. gotoblas = force_coretype(p);
  85. }
  86. else
  87. {
  88. gotoblas = get_coretype();
  89. }
  90. if (gotoblas == NULL)
  91. {
  92. snprintf(coremsg, 128, "Falling back to POWER8 core\n");
  93. openblas_warning(1, coremsg);
  94. gotoblas = &gotoblas_POWER8;
  95. }
  96. if (gotoblas && gotoblas -> init) {
  97. strncpy(coren,gotoblas_corename(),20);
  98. sprintf(coremsg, "Core: %s\n",coren);
  99. openblas_warning(2, coremsg);
  100. gotoblas -> init();
  101. } else {
  102. openblas_warning(0, "OpenBLAS : Architecture Initialization failed. No initialization function found.\n");
  103. exit(1);
  104. }
  105. }
  106. void gotoblas_dynamic_quit(void) {
  107. gotoblas = NULL;
  108. }