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.

memory.c 33 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449
  1. /*****************************************************************************
  2. Copyright (c) 2011-2014, The OpenBLAS Project
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are
  6. met:
  7. 1. Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. 2. Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in
  11. the documentation and/or other materials provided with the
  12. distribution.
  13. 3. Neither the name of the OpenBLAS project nor the names of
  14. its contributors may be used to endorse or promote products
  15. derived from this software without specific prior written
  16. permission.
  17. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  18. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  21. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  23. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  24. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  25. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  26. USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. **********************************************************************************/
  28. /*********************************************************************/
  29. /* Copyright 2009, 2010 The University of Texas at Austin. */
  30. /* All rights reserved. */
  31. /* */
  32. /* Redistribution and use in source and binary forms, with or */
  33. /* without modification, are permitted provided that the following */
  34. /* conditions are met: */
  35. /* */
  36. /* 1. Redistributions of source code must retain the above */
  37. /* copyright notice, this list of conditions and the following */
  38. /* disclaimer. */
  39. /* */
  40. /* 2. Redistributions in binary form must reproduce the above */
  41. /* copyright notice, this list of conditions and the following */
  42. /* disclaimer in the documentation and/or other materials */
  43. /* provided with the distribution. */
  44. /* */
  45. /* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */
  46. /* AUSTIN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, */
  47. /* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
  48. /* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
  49. /* DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT */
  50. /* AUSTIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */
  51. /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
  52. /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */
  53. /* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */
  54. /* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
  55. /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
  56. /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */
  57. /* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
  58. /* POSSIBILITY OF SUCH DAMAGE. */
  59. /* */
  60. /* The views and conclusions contained in the software and */
  61. /* documentation are those of the authors and should not be */
  62. /* interpreted as representing official policies, either expressed */
  63. /* or implied, of The University of Texas at Austin. */
  64. /*********************************************************************/
  65. //#undef DEBUG
  66. #include "common.h"
  67. #include <errno.h>
  68. #ifdef OS_WINDOWS
  69. #define ALLOC_WINDOWS
  70. #ifndef MEM_LARGE_PAGES
  71. #define MEM_LARGE_PAGES 0x20000000
  72. #endif
  73. #else
  74. #define ALLOC_MMAP
  75. #define ALLOC_MALLOC
  76. #endif
  77. #include <stdlib.h>
  78. #include <stdio.h>
  79. #include <fcntl.h>
  80. #ifndef OS_WINDOWS
  81. #include <sys/mman.h>
  82. #ifndef NO_SYSV_IPC
  83. #include <sys/shm.h>
  84. #endif
  85. #include <sys/ipc.h>
  86. #endif
  87. #include <sys/types.h>
  88. #ifdef OS_LINUX
  89. #include <sys/sysinfo.h>
  90. #include <sched.h>
  91. #include <errno.h>
  92. #include <linux/unistd.h>
  93. #include <sys/syscall.h>
  94. #endif
  95. #if defined(OS_FREEBSD) || defined(OS_DARWIN)
  96. #include <sys/sysctl.h>
  97. #include <sys/resource.h>
  98. #endif
  99. #if defined(OS_WINDOWS) && (defined(__MINGW32__) || defined(__MINGW64__))
  100. #include <conio.h>
  101. #undef printf
  102. #define printf _cprintf
  103. #endif
  104. #ifdef OS_LINUX
  105. #ifndef MPOL_PREFERRED
  106. #define MPOL_PREFERRED 1
  107. #endif
  108. #endif
  109. #if (defined(PPC440) || !defined(OS_LINUX) || defined(HPL)) && !defined(NO_WARMUP)
  110. #define NO_WARMUP
  111. #endif
  112. #ifndef SHM_HUGETLB
  113. #define SHM_HUGETLB 04000
  114. #endif
  115. #ifndef FIXED_PAGESIZE
  116. #define FIXED_PAGESIZE 4096
  117. #endif
  118. #define BITMASK(a, b, c) ((((a) >> (b)) & (c)))
  119. #if defined(_MSC_VER) && !defined(__clang__)
  120. #define CONSTRUCTOR __cdecl
  121. #define DESTRUCTOR __cdecl
  122. #elif defined(OS_DARWIN) && defined(C_GCC)
  123. #define CONSTRUCTOR __attribute__ ((constructor))
  124. #define DESTRUCTOR __attribute__ ((destructor))
  125. #else
  126. #define CONSTRUCTOR __attribute__ ((constructor(101)))
  127. #define DESTRUCTOR __attribute__ ((destructor(101)))
  128. #endif
  129. #ifdef DYNAMIC_ARCH
  130. gotoblas_t *gotoblas = NULL;
  131. #endif
  132. extern void openblas_warning(int verbose, const char * msg);
  133. #ifndef SMP
  134. #define blas_cpu_number 1
  135. #define blas_num_threads 1
  136. /* Dummy Function */
  137. int goto_get_num_procs (void) { return 1;};
  138. void goto_set_num_threads(int num_threads) {};
  139. #else
  140. #ifdef OS_LINUX
  141. #ifndef NO_AFFINITY
  142. int get_num_procs(void);
  143. #else
  144. int get_num_procs(void) {
  145. static int nums = 0;
  146. if (!nums) nums = sysconf(_SC_NPROCESSORS_ONLN);
  147. return nums;
  148. }
  149. #endif
  150. #endif
  151. #ifdef OS_ANDROID
  152. int get_num_procs(void) {
  153. static int nums = 0;
  154. if (!nums) nums = sysconf(_SC_NPROCESSORS_ONLN);
  155. return nums;
  156. }
  157. #endif
  158. #ifdef OS_WINDOWS
  159. int get_num_procs(void) {
  160. static int nums = 0;
  161. if (nums == 0) {
  162. SYSTEM_INFO sysinfo;
  163. GetSystemInfo(&sysinfo);
  164. nums = sysinfo.dwNumberOfProcessors;
  165. }
  166. return nums;
  167. }
  168. #endif
  169. #if defined(OS_FREEBSD)
  170. int get_num_procs(void) {
  171. static int nums = 0;
  172. int m[2];
  173. size_t len;
  174. if (nums == 0) {
  175. m[0] = CTL_HW;
  176. m[1] = HW_NCPU;
  177. len = sizeof(int);
  178. sysctl(m, 2, &nums, &len, NULL, 0);
  179. }
  180. return nums;
  181. }
  182. #endif
  183. #if defined(OS_DARWIN)
  184. int get_num_procs(void) {
  185. static int nums = 0;
  186. size_t len;
  187. if (nums == 0){
  188. len = sizeof(int);
  189. sysctlbyname("hw.physicalcpu", &nums, &len, NULL, 0);
  190. }
  191. return nums;
  192. }
  193. /*
  194. void set_stack_limit(int limitMB){
  195. int result=0;
  196. struct rlimit rl;
  197. rlim_t StackSize;
  198. StackSize=limitMB*1024*1024;
  199. result=getrlimit(RLIMIT_STACK, &rl);
  200. if(result==0){
  201. if(rl.rlim_cur < StackSize){
  202. rl.rlim_cur=StackSize;
  203. result=setrlimit(RLIMIT_STACK, &rl);
  204. if(result !=0){
  205. fprintf(stderr, "OpenBLAS: set stack limit error =%d\n", result);
  206. }
  207. }
  208. }
  209. }
  210. */
  211. #endif
  212. /*
  213. OpenBLAS uses the numbers of CPU cores in multithreading.
  214. It can be set by openblas_set_num_threads(int num_threads);
  215. */
  216. int blas_cpu_number = 0;
  217. /*
  218. The numbers of threads in the thread pool.
  219. This value is equal or large than blas_cpu_number. This means some threads are sleep.
  220. */
  221. int blas_num_threads = 0;
  222. int goto_get_num_procs (void) {
  223. return blas_cpu_number;
  224. }
  225. void openblas_fork_handler()
  226. {
  227. // This handler shuts down the OpenBLAS-managed PTHREAD pool when OpenBLAS is
  228. // built with "make USE_OPENMP=0".
  229. // Hanging can still happen when OpenBLAS is built against the libgomp
  230. // implementation of OpenMP. The problem is tracked at:
  231. // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60035
  232. // In the mean time build with USE_OPENMP=0 or link against another
  233. // implementation of OpenMP.
  234. #if !(defined(OS_WINDOWS) || defined(OS_ANDROID)) && defined(SMP_SERVER)
  235. int err;
  236. err = pthread_atfork ((void (*)(void)) BLASFUNC(blas_thread_shutdown), NULL, NULL);
  237. if(err != 0)
  238. openblas_warning(0, "OpenBLAS Warning ... cannot install fork handler. You may meet hang after fork.\n");
  239. #endif
  240. }
  241. int blas_get_cpu_number(void){
  242. env_var_t p;
  243. #if defined(OS_LINUX) || defined(OS_WINDOWS) || defined(OS_FREEBSD) || defined(OS_DARWIN) || defined(OS_ANDROID)
  244. int max_num;
  245. #endif
  246. int blas_goto_num = 0;
  247. int blas_omp_num = 0;
  248. if (blas_num_threads) return blas_num_threads;
  249. #if defined(OS_LINUX) || defined(OS_WINDOWS) || defined(OS_FREEBSD) || defined(OS_DARWIN) || defined(OS_ANDROID)
  250. max_num = get_num_procs();
  251. #endif
  252. blas_goto_num = 0;
  253. #ifndef USE_OPENMP
  254. if (readenv(p,"OPENBLAS_NUM_THREADS")) blas_goto_num = atoi(p);
  255. if (blas_goto_num < 0) blas_goto_num = 0;
  256. if (blas_goto_num == 0) {
  257. if (readenv(p,"GOTO_NUM_THREADS")) blas_goto_num = atoi(p);
  258. if (blas_goto_num < 0) blas_goto_num = 0;
  259. }
  260. #endif
  261. blas_omp_num = 0;
  262. if (readenv(p,"OMP_NUM_THREADS")) blas_omp_num = atoi(p);
  263. if (blas_omp_num < 0) blas_omp_num = 0;
  264. if (blas_goto_num > 0) blas_num_threads = blas_goto_num;
  265. else if (blas_omp_num > 0) blas_num_threads = blas_omp_num;
  266. else blas_num_threads = MAX_CPU_NUMBER;
  267. #if defined(OS_LINUX) || defined(OS_WINDOWS) || defined(OS_FREEBSD) || defined(OS_DARWIN) || defined(OS_ANDROID)
  268. if (blas_num_threads > max_num) blas_num_threads = max_num;
  269. #endif
  270. if (blas_num_threads > MAX_CPU_NUMBER) blas_num_threads = MAX_CPU_NUMBER;
  271. #ifdef DEBUG
  272. printf( "Adjusted number of threads : %3d\n", blas_num_threads);
  273. #endif
  274. blas_cpu_number = blas_num_threads;
  275. return blas_num_threads;
  276. }
  277. #endif
  278. int openblas_get_num_procs(void) {
  279. #ifndef SMP
  280. return 1;
  281. #else
  282. return get_num_procs();
  283. #endif
  284. }
  285. int openblas_get_num_threads(void) {
  286. #ifndef SMP
  287. return 1;
  288. #else
  289. return blas_get_cpu_number();
  290. #endif
  291. }
  292. struct release_t {
  293. void *address;
  294. void (*func)(struct release_t *);
  295. long attr;
  296. };
  297. int hugetlb_allocated = 0;
  298. static struct release_t release_info[NUM_BUFFERS];
  299. static int release_pos = 0;
  300. #if defined(OS_LINUX) && !defined(NO_WARMUP)
  301. static int hot_alloc = 0;
  302. #endif
  303. #ifdef ALLOC_MMAP
  304. static void alloc_mmap_free(struct release_t *release){
  305. if (munmap(release -> address, BUFFER_SIZE)) {
  306. printf("OpenBLAS : munmap failed\n");
  307. }
  308. }
  309. #ifdef NO_WARMUP
  310. static void *alloc_mmap(void *address){
  311. void *map_address;
  312. if (address){
  313. map_address = mmap(address,
  314. BUFFER_SIZE,
  315. MMAP_ACCESS, MMAP_POLICY | MAP_FIXED, -1, 0);
  316. } else {
  317. map_address = mmap(address,
  318. BUFFER_SIZE,
  319. MMAP_ACCESS, MMAP_POLICY, -1, 0);
  320. }
  321. if (map_address != (void *)-1) {
  322. release_info[release_pos].address = map_address;
  323. release_info[release_pos].func = alloc_mmap_free;
  324. release_pos ++;
  325. }
  326. #ifdef OS_LINUX
  327. my_mbind(map_address, BUFFER_SIZE, MPOL_PREFERRED, NULL, 0, 0);
  328. #endif
  329. return map_address;
  330. }
  331. #else
  332. #define BENCH_ITERATION 4
  333. #define SCALING 2
  334. static inline BLASULONG run_bench(BLASULONG address, BLASULONG size) {
  335. BLASULONG original, *p;
  336. BLASULONG start, stop, min;
  337. int iter, i, count;
  338. min = (BLASULONG)-1;
  339. original = *(BLASULONG *)(address + size - PAGESIZE);
  340. *(BLASULONG *)(address + size - PAGESIZE) = (BLASULONG)address;
  341. for (iter = 0; iter < BENCH_ITERATION; iter ++ ) {
  342. p = (BLASULONG *)address;
  343. count = size / PAGESIZE;
  344. start = rpcc();
  345. for (i = 0; i < count; i ++) {
  346. p = (BLASULONG *)(*p);
  347. }
  348. stop = rpcc();
  349. if (min > stop - start) min = stop - start;
  350. }
  351. *(BLASULONG *)(address + size - PAGESIZE + 0) = original;
  352. *(BLASULONG *)(address + size - PAGESIZE + 8) = (BLASULONG)p;
  353. return min;
  354. }
  355. static void *alloc_mmap(void *address){
  356. void *map_address, *best_address;
  357. BLASULONG best, start, current;
  358. BLASULONG allocsize;
  359. if (address){
  360. /* Just give up use advanced operation */
  361. map_address = mmap(address, BUFFER_SIZE, MMAP_ACCESS, MMAP_POLICY | MAP_FIXED, -1, 0);
  362. #ifdef OS_LINUX
  363. my_mbind(map_address, BUFFER_SIZE, MPOL_PREFERRED, NULL, 0, 0);
  364. #endif
  365. } else {
  366. #if defined(OS_LINUX) && !defined(NO_WARMUP)
  367. if (hot_alloc == 0) {
  368. map_address = mmap(NULL, BUFFER_SIZE, MMAP_ACCESS, MMAP_POLICY, -1, 0);
  369. #ifdef OS_LINUX
  370. my_mbind(map_address, BUFFER_SIZE, MPOL_PREFERRED, NULL, 0, 0);
  371. #endif
  372. } else {
  373. #endif
  374. map_address = mmap(NULL, BUFFER_SIZE * SCALING,
  375. MMAP_ACCESS, MMAP_POLICY, -1, 0);
  376. if (map_address != (void *)-1) {
  377. #ifdef OS_LINUX
  378. #ifdef DEBUG
  379. int ret=0;
  380. ret=my_mbind(map_address, BUFFER_SIZE * SCALING, MPOL_PREFERRED, NULL, 0, 0);
  381. if(ret==-1){
  382. int errsv=errno;
  383. perror("OpenBLAS alloc_mmap:");
  384. printf("error code=%d,\tmap_address=%lx\n",errsv,map_address);
  385. }
  386. #else
  387. my_mbind(map_address, BUFFER_SIZE * SCALING, MPOL_PREFERRED, NULL, 0, 0);
  388. #endif
  389. #endif
  390. allocsize = DGEMM_P * DGEMM_Q * sizeof(double);
  391. start = (BLASULONG)map_address;
  392. current = (SCALING - 1) * BUFFER_SIZE;
  393. while(current > 0) {
  394. *(BLASLONG *)start = (BLASLONG)start + PAGESIZE;
  395. start += PAGESIZE;
  396. current -= PAGESIZE;
  397. }
  398. *(BLASLONG *)(start - PAGESIZE) = (BLASULONG)map_address;
  399. start = (BLASULONG)map_address;
  400. best = (BLASULONG)-1;
  401. best_address = map_address;
  402. while ((start + allocsize < (BLASULONG)map_address + (SCALING - 1) * BUFFER_SIZE)) {
  403. current = run_bench(start, allocsize);
  404. if (best > current) {
  405. best = current;
  406. best_address = (void *)start;
  407. }
  408. start += PAGESIZE;
  409. }
  410. if ((BLASULONG)best_address > (BLASULONG)map_address)
  411. munmap(map_address, (BLASULONG)best_address - (BLASULONG)map_address);
  412. munmap((void *)((BLASULONG)best_address + BUFFER_SIZE), (SCALING - 1) * BUFFER_SIZE + (BLASULONG)map_address - (BLASULONG)best_address);
  413. map_address = best_address;
  414. #if defined(OS_LINUX) && !defined(NO_WARMUP)
  415. hot_alloc = 2;
  416. #endif
  417. }
  418. }
  419. #if defined(OS_LINUX) && !defined(NO_WARMUP)
  420. }
  421. #endif
  422. if (map_address != (void *)-1) {
  423. release_info[release_pos].address = map_address;
  424. release_info[release_pos].func = alloc_mmap_free;
  425. release_pos ++;
  426. }
  427. return map_address;
  428. }
  429. #endif
  430. #endif
  431. #ifdef ALLOC_MALLOC
  432. static void alloc_malloc_free(struct release_t *release){
  433. free(release -> address);
  434. }
  435. static void *alloc_malloc(void *address){
  436. void *map_address;
  437. map_address = (void *)malloc(BUFFER_SIZE + FIXED_PAGESIZE);
  438. if (map_address == (void *)NULL) map_address = (void *)-1;
  439. if (map_address != (void *)-1) {
  440. release_info[release_pos].address = map_address;
  441. release_info[release_pos].func = alloc_malloc_free;
  442. release_pos ++;
  443. }
  444. return map_address;
  445. }
  446. #endif
  447. #ifdef ALLOC_QALLOC
  448. void *qalloc(int flags, size_t bytes);
  449. void *qfree (void *address);
  450. #define QNONCACHE 0x1
  451. #define QCOMMS 0x2
  452. #define QFAST 0x4
  453. static void alloc_qalloc_free(struct release_t *release){
  454. qfree(release -> address);
  455. }
  456. static void *alloc_qalloc(void *address){
  457. void *map_address;
  458. map_address = (void *)qalloc(QCOMMS | QFAST, BUFFER_SIZE + FIXED_PAGESIZE);
  459. if (map_address == (void *)NULL) map_address = (void *)-1;
  460. if (map_address != (void *)-1) {
  461. release_info[release_pos].address = map_address;
  462. release_info[release_pos].func = alloc_qalloc_free;
  463. release_pos ++;
  464. }
  465. return (void *)(((BLASULONG)map_address + FIXED_PAGESIZE - 1) & ~(FIXED_PAGESIZE - 1));
  466. }
  467. #endif
  468. #ifdef ALLOC_WINDOWS
  469. static void alloc_windows_free(struct release_t *release){
  470. VirtualFree(release -> address, BUFFER_SIZE, MEM_DECOMMIT);
  471. }
  472. static void *alloc_windows(void *address){
  473. void *map_address;
  474. map_address = VirtualAlloc(address,
  475. BUFFER_SIZE,
  476. MEM_RESERVE | MEM_COMMIT,
  477. PAGE_READWRITE);
  478. if (map_address == (void *)NULL) map_address = (void *)-1;
  479. if (map_address != (void *)-1) {
  480. release_info[release_pos].address = map_address;
  481. release_info[release_pos].func = alloc_windows_free;
  482. release_pos ++;
  483. }
  484. return map_address;
  485. }
  486. #endif
  487. #ifdef ALLOC_DEVICEDRIVER
  488. #ifndef DEVICEDRIVER_NAME
  489. #define DEVICEDRIVER_NAME "/dev/mapper"
  490. #endif
  491. static void alloc_devicedirver_free(struct release_t *release){
  492. if (munmap(release -> address, BUFFER_SIZE)) {
  493. printf("OpenBLAS : Bugphysarea unmap failed.\n");
  494. }
  495. if (close(release -> attr)) {
  496. printf("OpenBLAS : Bugphysarea close failed.\n");
  497. }
  498. }
  499. static void *alloc_devicedirver(void *address){
  500. int fd;
  501. void *map_address;
  502. if ((fd = open(DEVICEDRIVER_NAME, O_RDWR | O_SYNC)) < 0) {
  503. return (void *)-1;
  504. }
  505. map_address = mmap(address, BUFFER_SIZE,
  506. PROT_READ | PROT_WRITE,
  507. MAP_FILE | MAP_SHARED,
  508. fd, 0);
  509. if (map_address != (void *)-1) {
  510. release_info[release_pos].address = map_address;
  511. release_info[release_pos].attr = fd;
  512. release_info[release_pos].func = alloc_devicedirver_free;
  513. release_pos ++;
  514. }
  515. return map_address;
  516. }
  517. #endif
  518. #ifdef ALLOC_SHM
  519. static void alloc_shm_free(struct release_t *release){
  520. if (shmdt(release -> address)) {
  521. printf("OpenBLAS : Shared memory unmap failed.\n");
  522. }
  523. }
  524. static void *alloc_shm(void *address){
  525. void *map_address;
  526. int shmid;
  527. shmid = shmget(IPC_PRIVATE, BUFFER_SIZE,IPC_CREAT | 0600);
  528. map_address = (void *)shmat(shmid, address, 0);
  529. if (map_address != (void *)-1){
  530. #ifdef OS_LINUX
  531. my_mbind(map_address, BUFFER_SIZE, MPOL_PREFERRED, NULL, 0, 0);
  532. #endif
  533. shmctl(shmid, IPC_RMID, 0);
  534. release_info[release_pos].address = map_address;
  535. release_info[release_pos].attr = shmid;
  536. release_info[release_pos].func = alloc_shm_free;
  537. release_pos ++;
  538. }
  539. return map_address;
  540. }
  541. #if defined OS_LINUX || defined OS_AIX || defined __sun__ || defined OS_WINDOWS
  542. static void alloc_hugetlb_free(struct release_t *release){
  543. #if defined(OS_LINUX) || defined(OS_AIX)
  544. if (shmdt(release -> address)) {
  545. printf("OpenBLAS : Hugepage unmap failed.\n");
  546. }
  547. #endif
  548. #ifdef __sun__
  549. munmap(release -> address, BUFFER_SIZE);
  550. #endif
  551. #ifdef OS_WINDOWS
  552. VirtualFree(release -> address, BUFFER_SIZE, MEM_LARGE_PAGES | MEM_DECOMMIT);
  553. #endif
  554. }
  555. static void *alloc_hugetlb(void *address){
  556. void *map_address = (void *)-1;
  557. #if defined(OS_LINUX) || defined(OS_AIX)
  558. int shmid;
  559. shmid = shmget(IPC_PRIVATE, BUFFER_SIZE,
  560. #ifdef OS_LINUX
  561. SHM_HUGETLB |
  562. #endif
  563. #ifdef OS_AIX
  564. SHM_LGPAGE | SHM_PIN |
  565. #endif
  566. IPC_CREAT | SHM_R | SHM_W);
  567. if (shmid != -1) {
  568. map_address = (void *)shmat(shmid, address, SHM_RND);
  569. #ifdef OS_LINUX
  570. my_mbind(map_address, BUFFER_SIZE, MPOL_PREFERRED, NULL, 0, 0);
  571. #endif
  572. if (map_address != (void *)-1){
  573. shmctl(shmid, IPC_RMID, 0);
  574. }
  575. }
  576. #endif
  577. #ifdef __sun__
  578. struct memcntl_mha mha;
  579. mha.mha_cmd = MHA_MAPSIZE_BSSBRK;
  580. mha.mha_flags = 0;
  581. mha.mha_pagesize = HUGE_PAGESIZE;
  582. memcntl(NULL, 0, MC_HAT_ADVISE, (char *)&mha, 0, 0);
  583. map_address = (BLASULONG)memalign(HUGE_PAGESIZE, BUFFER_SIZE);
  584. #endif
  585. #ifdef OS_WINDOWS
  586. HANDLE hToken;
  587. TOKEN_PRIVILEGES tp;
  588. if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken) != TRUE) return (void *) -1;
  589. tp.PrivilegeCount = 1;
  590. tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
  591. if (LookupPrivilegeValue(NULL, SE_LOCK_MEMORY_NAME, &tp.Privileges[0].Luid) != TRUE) {
  592. CloseHandle(hToken);
  593. return (void*)-1;
  594. }
  595. if (AdjustTokenPrivileges(hToken, FALSE, &tp, 0, NULL, NULL) != TRUE) {
  596. CloseHandle(hToken);
  597. return (void*)-1;
  598. }
  599. map_address = (void *)VirtualAlloc(address,
  600. BUFFER_SIZE,
  601. MEM_LARGE_PAGES | MEM_RESERVE | MEM_COMMIT,
  602. PAGE_READWRITE);
  603. tp.Privileges[0].Attributes = 0;
  604. AdjustTokenPrivileges(hToken, FALSE, &tp, 0, NULL, NULL);
  605. if (map_address == (void *)NULL) map_address = (void *)-1;
  606. #endif
  607. if (map_address != (void *)-1){
  608. release_info[release_pos].address = map_address;
  609. release_info[release_pos].func = alloc_hugetlb_free;
  610. release_pos ++;
  611. }
  612. return map_address;
  613. }
  614. #endif
  615. #endif
  616. #ifdef ALLOC_HUGETLBFILE
  617. static int hugetlb_pid = 0;
  618. static void alloc_hugetlbfile_free(struct release_t *release){
  619. if (munmap(release -> address, BUFFER_SIZE)) {
  620. printf("OpenBLAS : HugeTLBfs unmap failed.\n");
  621. }
  622. if (close(release -> attr)) {
  623. printf("OpenBLAS : HugeTLBfs close failed.\n");
  624. }
  625. }
  626. static void *alloc_hugetlbfile(void *address){
  627. void *map_address = (void *)-1;
  628. int fd;
  629. char filename[64];
  630. if (!hugetlb_pid) hugetlb_pid = getpid();
  631. sprintf(filename, "%s/gotoblas.%d", HUGETLB_FILE_NAME, hugetlb_pid);
  632. if ((fd = open(filename, O_RDWR | O_CREAT, 0700)) < 0) {
  633. return (void *)-1;
  634. }
  635. unlink(filename);
  636. map_address = mmap(address, BUFFER_SIZE,
  637. PROT_READ | PROT_WRITE,
  638. MAP_SHARED,
  639. fd, 0);
  640. if (map_address != (void *)-1) {
  641. release_info[release_pos].address = map_address;
  642. release_info[release_pos].attr = fd;
  643. release_info[release_pos].func = alloc_hugetlbfile_free;
  644. release_pos ++;
  645. }
  646. return map_address;
  647. }
  648. #endif
  649. /* Global lock for memory allocation */
  650. #if defined(USE_PTHREAD_LOCK)
  651. static pthread_mutex_t alloc_lock = PTHREAD_MUTEX_INITIALIZER;
  652. #elif defined(USE_PTHREAD_SPINLOCK)
  653. static pthread_spinlock_t alloc_lock = 0;
  654. #else
  655. static BLASULONG alloc_lock = 0UL;
  656. #endif
  657. #ifdef SEEK_ADDRESS
  658. static BLASULONG base_address = 0UL;
  659. #else
  660. static BLASULONG base_address = BASE_ADDRESS;
  661. #endif
  662. static volatile struct {
  663. BLASULONG lock;
  664. void *addr;
  665. #if defined(WHEREAMI) && !defined(USE_OPENMP)
  666. int pos;
  667. #endif
  668. int used;
  669. #ifndef __64BIT__
  670. char dummy[48];
  671. #else
  672. char dummy[40];
  673. #endif
  674. } memory[NUM_BUFFERS];
  675. static int memory_initialized = 0;
  676. /* Memory allocation routine */
  677. /* procpos ... indicates where it comes from */
  678. /* 0 : Level 3 functions */
  679. /* 1 : Level 2 functions */
  680. /* 2 : Thread */
  681. void *blas_memory_alloc(int procpos){
  682. int position;
  683. #if defined(WHEREAMI) && !defined(USE_OPENMP)
  684. int mypos;
  685. #endif
  686. void *map_address;
  687. void *(*memoryalloc[])(void *address) = {
  688. #ifdef ALLOC_DEVICEDRIVER
  689. alloc_devicedirver,
  690. #endif
  691. /* Hugetlb implicitly assumes ALLOC_SHM */
  692. #ifdef ALLOC_SHM
  693. alloc_shm,
  694. #endif
  695. #if ((defined ALLOC_SHM) && (defined OS_LINUX || defined OS_AIX || defined __sun__ || defined OS_WINDOWS))
  696. alloc_hugetlb,
  697. #endif
  698. #ifdef ALLOC_MMAP
  699. alloc_mmap,
  700. #endif
  701. #ifdef ALLOC_QALLOC
  702. alloc_qalloc,
  703. #endif
  704. #ifdef ALLOC_WINDOWS
  705. alloc_windows,
  706. #endif
  707. #ifdef ALLOC_MALLOC
  708. alloc_malloc,
  709. #endif
  710. NULL,
  711. };
  712. void *(**func)(void *address);
  713. if (!memory_initialized) {
  714. LOCK_COMMAND(&alloc_lock);
  715. if (!memory_initialized) {
  716. #if defined(WHEREAMI) && !defined(USE_OPENMP)
  717. for (position = 0; position < NUM_BUFFERS; position ++){
  718. memory[position].addr = (void *)0;
  719. memory[position].pos = -1;
  720. memory[position].used = 0;
  721. memory[position].lock = 0;
  722. }
  723. #endif
  724. #ifdef DYNAMIC_ARCH
  725. gotoblas_dynamic_init();
  726. #endif
  727. #if defined(SMP) && defined(OS_LINUX) && !defined(NO_AFFINITY)
  728. gotoblas_affinity_init();
  729. #endif
  730. #ifdef SMP
  731. if (!blas_num_threads) blas_cpu_number = blas_get_cpu_number();
  732. #endif
  733. #if defined(ARCH_X86) || defined(ARCH_X86_64) || defined(ARCH_IA64) || defined(ARCH_MIPS64)
  734. #ifndef DYNAMIC_ARCH
  735. blas_set_parameter();
  736. #endif
  737. #endif
  738. memory_initialized = 1;
  739. }
  740. UNLOCK_COMMAND(&alloc_lock);
  741. }
  742. #ifdef DEBUG
  743. printf("Alloc Start ...\n");
  744. #endif
  745. #if defined(WHEREAMI) && !defined(USE_OPENMP)
  746. mypos = WhereAmI();
  747. position = mypos;
  748. while (position > NUM_BUFFERS) position >>= 1;
  749. do {
  750. if (!memory[position].used && (memory[position].pos == mypos)) {
  751. blas_lock(&memory[position].lock);
  752. if (!memory[position].used) goto allocation;
  753. blas_unlock(&memory[position].lock);
  754. }
  755. position ++;
  756. } while (position < NUM_BUFFERS);
  757. #endif
  758. position = 0;
  759. do {
  760. if (!memory[position].used) {
  761. blas_lock(&memory[position].lock);
  762. if (!memory[position].used) goto allocation;
  763. blas_unlock(&memory[position].lock);
  764. }
  765. position ++;
  766. } while (position < NUM_BUFFERS);
  767. goto error;
  768. allocation :
  769. #ifdef DEBUG
  770. printf(" Position -> %d\n", position);
  771. #endif
  772. memory[position].used = 1;
  773. blas_unlock(&memory[position].lock);
  774. if (!memory[position].addr) {
  775. do {
  776. #ifdef DEBUG
  777. printf("Allocation Start : %lx\n", base_address);
  778. #endif
  779. map_address = (void *)-1;
  780. func = &memoryalloc[0];
  781. while ((func != NULL) && (map_address == (void *) -1)) {
  782. map_address = (*func)((void *)base_address);
  783. #ifdef ALLOC_DEVICEDRIVER
  784. if ((*func == alloc_devicedirver) && (map_address == (void *)-1)) {
  785. fprintf(stderr, "OpenBLAS Warning ... Physically contigous allocation was failed.\n");
  786. }
  787. #endif
  788. #ifdef ALLOC_HUGETLBFILE
  789. if ((*func == alloc_hugetlbfile) && (map_address == (void *)-1)) {
  790. #ifndef OS_WINDOWS
  791. fprintf(stderr, "OpenBLAS Warning ... HugeTLB(File) allocation was failed.\n");
  792. #endif
  793. }
  794. #endif
  795. #if (defined ALLOC_SHM) && (defined OS_LINUX || defined OS_AIX || defined __sun__ || defined OS_WINDOWS)
  796. if ((*func == alloc_hugetlb) && (map_address != (void *)-1)) hugetlb_allocated = 1;
  797. #endif
  798. func ++;
  799. }
  800. #ifdef DEBUG
  801. printf(" Success -> %08lx\n", map_address);
  802. #endif
  803. if (((BLASLONG) map_address) == -1) base_address = 0UL;
  804. if (base_address) base_address += BUFFER_SIZE + FIXED_PAGESIZE;
  805. } while ((BLASLONG)map_address == -1);
  806. memory[position].addr = map_address;
  807. #ifdef DEBUG
  808. printf(" Mapping Succeeded. %p(%d)\n", (void *)memory[position].addr, position);
  809. #endif
  810. }
  811. #if defined(WHEREAMI) && !defined(USE_OPENMP)
  812. if (memory[position].pos == -1) memory[position].pos = mypos;
  813. #endif
  814. #ifdef DYNAMIC_ARCH
  815. if (memory_initialized == 1) {
  816. LOCK_COMMAND(&alloc_lock);
  817. if (memory_initialized == 1) {
  818. if (!gotoblas) gotoblas_dynamic_init();
  819. memory_initialized = 2;
  820. }
  821. UNLOCK_COMMAND(&alloc_lock);
  822. }
  823. #endif
  824. #ifdef DEBUG
  825. printf("Mapped : %p %3d\n\n",
  826. (void *)memory[position].addr, position);
  827. #endif
  828. return (void *)memory[position].addr;
  829. error:
  830. printf("BLAS : Program is Terminated. Because you tried to allocate too many memory regions.\n");
  831. return NULL;
  832. }
  833. void blas_memory_free(void *free_area){
  834. int position;
  835. #ifdef DEBUG
  836. printf("Unmapped Start : %p ...\n", free_area);
  837. #endif
  838. position = 0;
  839. while ((memory[position].addr != free_area)
  840. && (position < NUM_BUFFERS)) position++;
  841. if (memory[position].addr != free_area) goto error;
  842. #ifdef DEBUG
  843. printf(" Position : %d\n", position);
  844. #endif
  845. // arm: ensure all writes are finished before other thread takes this memory
  846. WMB;
  847. memory[position].used = 0;
  848. #ifdef DEBUG
  849. printf("Unmap Succeeded.\n\n");
  850. #endif
  851. return;
  852. error:
  853. printf("BLAS : Bad memory unallocation! : %4d %p\n", position, free_area);
  854. #ifdef DEBUG
  855. for (position = 0; position < NUM_BUFFERS; position++)
  856. printf("%4ld %p : %d\n", position, memory[position].addr, memory[position].used);
  857. #endif
  858. return;
  859. }
  860. void *blas_memory_alloc_nolock(int unused) {
  861. void *map_address;
  862. map_address = (void *)malloc(BUFFER_SIZE + FIXED_PAGESIZE);
  863. return map_address;
  864. }
  865. void blas_memory_free_nolock(void * map_address) {
  866. free(map_address);
  867. }
  868. void blas_shutdown(void){
  869. int pos;
  870. #ifdef SMP
  871. BLASFUNC(blas_thread_shutdown)();
  872. #endif
  873. LOCK_COMMAND(&alloc_lock);
  874. for (pos = 0; pos < release_pos; pos ++) {
  875. release_info[pos].func(&release_info[pos]);
  876. }
  877. #ifdef SEEK_ADDRESS
  878. base_address = 0UL;
  879. #else
  880. base_address = BASE_ADDRESS;
  881. #endif
  882. for (pos = 0; pos < NUM_BUFFERS; pos ++){
  883. memory[pos].addr = (void *)0;
  884. memory[pos].used = 0;
  885. #if defined(WHEREAMI) && !defined(USE_OPENMP)
  886. memory[pos].pos = -1;
  887. #endif
  888. memory[pos].lock = 0;
  889. }
  890. UNLOCK_COMMAND(&alloc_lock);
  891. return;
  892. }
  893. #if defined(OS_LINUX) && !defined(NO_WARMUP)
  894. #ifdef SMP
  895. #if defined(USE_PTHREAD_LOCK)
  896. static pthread_mutex_t init_lock = PTHREAD_MUTEX_INITIALIZER;
  897. #elif defined(USE_PTHREAD_SPINLOCK)
  898. static pthread_spinlock_t init_lock = 0;
  899. #else
  900. static BLASULONG init_lock = 0UL;
  901. #endif
  902. #endif
  903. static void _touch_memory(blas_arg_t *arg, BLASLONG *range_m, BLASLONG *range_n,
  904. void *sa, void *sb, BLASLONG pos) {
  905. #if !defined(ARCH_POWER) && !defined(ARCH_SPARC)
  906. size_t size;
  907. BLASULONG buffer;
  908. size = BUFFER_SIZE - PAGESIZE;
  909. buffer = (BLASULONG)sa + GEMM_OFFSET_A;
  910. #if defined(OS_LINUX) && !defined(NO_WARMUP)
  911. if (hot_alloc != 2) {
  912. #endif
  913. #ifdef SMP
  914. LOCK_COMMAND(&init_lock);
  915. #endif
  916. while (size > 0) {
  917. *(int *)buffer = size;
  918. buffer += PAGESIZE;
  919. size -= PAGESIZE;
  920. }
  921. #ifdef SMP
  922. UNLOCK_COMMAND(&init_lock);
  923. #endif
  924. size = MIN((BUFFER_SIZE - PAGESIZE), L2_SIZE);
  925. buffer = (BLASULONG)sa + GEMM_OFFSET_A;
  926. while (size > 0) {
  927. *(int *)buffer = size;
  928. buffer += 64;
  929. size -= 64;
  930. }
  931. #if defined(OS_LINUX) && !defined(NO_WARMUP)
  932. }
  933. #endif
  934. #endif
  935. }
  936. #ifdef SMP
  937. static void _init_thread_memory(void *buffer) {
  938. blas_queue_t queue[MAX_CPU_NUMBER];
  939. int num_cpu;
  940. for (num_cpu = 0; num_cpu < blas_num_threads; num_cpu++) {
  941. blas_queue_init(&queue[num_cpu]);
  942. queue[num_cpu].mode = BLAS_DOUBLE | BLAS_REAL;
  943. queue[num_cpu].routine = &_touch_memory;
  944. queue[num_cpu].args = NULL;
  945. queue[num_cpu].next = &queue[num_cpu + 1];
  946. }
  947. queue[num_cpu - 1].next = NULL;
  948. queue[0].sa = buffer;
  949. exec_blas(num_cpu, queue);
  950. }
  951. #endif
  952. static void gotoblas_memory_init(void) {
  953. void *buffer;
  954. hot_alloc = 1;
  955. buffer = (void *)blas_memory_alloc(0);
  956. #ifdef SMP
  957. if (blas_cpu_number == 0) blas_get_cpu_number();
  958. #ifdef SMP_SERVER
  959. if (blas_server_avail == 0) blas_thread_init();
  960. #endif
  961. _init_thread_memory((void *)((BLASULONG)buffer + GEMM_OFFSET_A));
  962. #else
  963. _touch_memory(NULL, NULL, NULL, (void *)((BLASULONG)buffer + GEMM_OFFSET_A), NULL, 0);
  964. #endif
  965. blas_memory_free(buffer);
  966. }
  967. #endif
  968. /* Initialization for all function; this function should be called before main */
  969. static int gotoblas_initialized = 0;
  970. void CONSTRUCTOR gotoblas_init(void) {
  971. if (gotoblas_initialized) return;
  972. #ifdef SMP
  973. openblas_fork_handler();
  974. #endif
  975. #ifdef PROFILE
  976. moncontrol (0);
  977. #endif
  978. #ifdef DYNAMIC_ARCH
  979. gotoblas_dynamic_init();
  980. #endif
  981. #if defined(SMP) && defined(OS_LINUX) && !defined(NO_AFFINITY)
  982. gotoblas_affinity_init();
  983. #endif
  984. #if defined(OS_LINUX) && !defined(NO_WARMUP)
  985. gotoblas_memory_init();
  986. #endif
  987. #ifdef SMP
  988. if (blas_cpu_number == 0) blas_get_cpu_number();
  989. #ifdef SMP_SERVER
  990. if (blas_server_avail == 0) blas_thread_init();
  991. #endif
  992. #endif
  993. #ifdef FUNCTION_PROFILE
  994. gotoblas_profile_init();
  995. #endif
  996. gotoblas_initialized = 1;
  997. #ifdef PROFILE
  998. moncontrol (1);
  999. #endif
  1000. }
  1001. void DESTRUCTOR gotoblas_quit(void) {
  1002. if (gotoblas_initialized == 0) return;
  1003. blas_shutdown();
  1004. #ifdef PROFILE
  1005. moncontrol (0);
  1006. #endif
  1007. #ifdef FUNCTION_PROFILE
  1008. gotoblas_profile_quit();
  1009. #endif
  1010. #if defined(SMP) && defined(OS_LINUX) && !defined(NO_AFFINITY)
  1011. gotoblas_affinity_quit();
  1012. #endif
  1013. #ifdef DYNAMIC_ARCH
  1014. gotoblas_dynamic_quit();
  1015. #endif
  1016. gotoblas_initialized = 0;
  1017. #ifdef PROFILE
  1018. moncontrol (1);
  1019. #endif
  1020. }
  1021. #if defined(_MSC_VER) && !defined(__clang__)
  1022. BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
  1023. {
  1024. switch (ul_reason_for_call)
  1025. {
  1026. case DLL_PROCESS_ATTACH:
  1027. gotoblas_init();
  1028. break;
  1029. case DLL_THREAD_ATTACH:
  1030. break;
  1031. case DLL_THREAD_DETACH:
  1032. break;
  1033. case DLL_PROCESS_DETACH:
  1034. gotoblas_quit();
  1035. break;
  1036. default:
  1037. break;
  1038. }
  1039. return TRUE;
  1040. }
  1041. #endif
  1042. #if (defined(C_PGI) || (!defined(C_SUN) && defined(F_INTERFACE_SUN))) && (defined(ARCH_X86) || defined(ARCH_X86_64))
  1043. /* Don't call me; this is just work around for PGI / Sun bug */
  1044. void gotoblas_dummy_for_PGI(void) {
  1045. gotoblas_init();
  1046. gotoblas_quit();
  1047. #if 0
  1048. asm ("\t.section\t.ctors,\"aw\",@progbits; .align 8; .quad gotoblas_init; .section .text");
  1049. asm ("\t.section\t.dtors,\"aw\",@progbits; .align 8; .quad gotoblas_quit; .section .text");
  1050. #else
  1051. asm (".section .init,\"ax\"; call gotoblas_init@PLT; .section .text");
  1052. asm (".section .fini,\"ax\"; call gotoblas_quit@PLT; .section .text");
  1053. #endif
  1054. }
  1055. #endif