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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #include "common.h"
  2. extern gotoblas_t gotoblas_POWER6;
  3. extern gotoblas_t gotoblas_POWER8;
  4. #if (!defined C_GCC) || (GCC_VERSION >= 60000)
  5. extern gotoblas_t gotoblas_POWER9;
  6. #endif
  7. extern void openblas_warning(int verbose, const char *msg);
  8. static char *corename[] = {
  9. "unknown",
  10. "POWER6",
  11. "POWER8",
  12. "POWER9"
  13. };
  14. #define NUM_CORETYPES 4
  15. char *gotoblas_corename(void) {
  16. if (gotoblas == &gotoblas_POWER6) return corename[1];
  17. if (gotoblas == &gotoblas_POWER8) return corename[2];
  18. #if (!defined C_GCC) || (GCC_VERSION >= 60000)
  19. if (gotoblas == &gotoblas_POWER9) return corename[3];
  20. #endif
  21. return corename[0];
  22. }
  23. static gotoblas_t *get_coretype(void) {
  24. if (__builtin_cpu_is("power6") || __builtin_cpu_is("power6x"))
  25. return &gotoblas_POWER6;
  26. if (__builtin_cpu_is("power8"))
  27. return &gotoblas_POWER8;
  28. #if (!defined C_GCC) || (GCC_VERSION >= 60000)
  29. if (__builtin_cpu_is("power9"))
  30. return &gotoblas_POWER9;
  31. #endif
  32. return NULL;
  33. }
  34. static gotoblas_t *force_coretype(char * coretype) {
  35. int i ;
  36. int found = -1;
  37. char message[128];
  38. for ( i = 0 ; i < NUM_CORETYPES; i++)
  39. {
  40. if (!strncasecmp(coretype, corename[i], 20))
  41. {
  42. found = i;
  43. break;
  44. }
  45. }
  46. switch (found)
  47. {
  48. case 1: return (&gotoblas_POWER6);
  49. case 2: return (&gotoblas_POWER8);
  50. #if (!defined C_GCC) || (GCC_VERSION >= 60000)
  51. case 3: return (&gotoblas_POWER9);
  52. #endif
  53. default: return NULL;
  54. }
  55. snprintf(message, 128, "Core not found: %s\n", coretype);
  56. openblas_warning(1, message);
  57. }
  58. void gotoblas_dynamic_init(void) {
  59. char coremsg[128];
  60. char coren[22];
  61. char *p;
  62. if (gotoblas) return;
  63. p = getenv("OPENBLAS_CORETYPE");
  64. if ( p )
  65. {
  66. gotoblas = force_coretype(p);
  67. }
  68. else
  69. {
  70. gotoblas = get_coretype();
  71. }
  72. if (gotoblas == NULL)
  73. {
  74. snprintf(coremsg, 128, "Falling back to POWER8 core\n");
  75. openblas_warning(1, coremsg);
  76. gotoblas = &gotoblas_POWER8;
  77. }
  78. if (gotoblas && gotoblas -> init) {
  79. strncpy(coren,gotoblas_corename(),20);
  80. sprintf(coremsg, "Core: %s\n",coren);
  81. openblas_warning(2, coremsg);
  82. gotoblas -> init();
  83. } else {
  84. openblas_warning(0, "OpenBLAS : Architecture Initialization failed. No initialization function found.\n");
  85. exit(1);
  86. }
  87. }
  88. void gotoblas_dynamic_quit(void) {
  89. gotoblas = NULL;
  90. }