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.

blas_server_win32.c 19 kB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  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 <stdio.h>
  39. #include <stdlib.h>
  40. #include "common.h"
  41. #if !defined(unlikely)
  42. #ifdef __GNUC__
  43. #define unlikely(x) __builtin_expect(!!(x), 0)
  44. #else
  45. #define unlikely(x) (x)
  46. #endif
  47. #endif
  48. #ifdef SMP_DEBUG
  49. # define MT_TRACE(...) fprintf(stderr, __VA_ARGS__)
  50. #else
  51. # define MT_TRACE(...)
  52. #endif
  53. /* This is a thread implementation for Win32 lazy implementation */
  54. /* Thread server common information */
  55. static blas_queue_t *work_queue = NULL;
  56. static HANDLE kickoff_event = NULL;
  57. static CRITICAL_SECTION queue_lock;
  58. /* We need this global for checking if initialization is finished. */
  59. int blas_server_avail = 0;
  60. int blas_omp_threads_local = 1;
  61. static void * blas_thread_buffer[MAX_CPU_NUMBER];
  62. /* Local Variables */
  63. static BLASULONG server_lock = 0;
  64. static HANDLE blas_threads [MAX_CPU_NUMBER];
  65. static DWORD blas_threads_id[MAX_CPU_NUMBER];
  66. static volatile int thread_target; // target num of live threads, volatile for cross-thread reads
  67. //Prototypes
  68. static void exec_threads(int , blas_queue_t *, int);
  69. static void adjust_thread_buffers();
  70. //
  71. // Legacy code path
  72. //
  73. static void legacy_exec(void *func, int mode, blas_arg_t *args, void *sb) {
  74. if (!(mode & BLAS_COMPLEX)) {
  75. #ifdef EXPRECISION
  76. if ((mode & BLAS_PREC) == BLAS_XDOUBLE){
  77. /* REAL / Extended Double */
  78. void (*afunc)(BLASLONG, BLASLONG, BLASLONG, xdouble,
  79. xdouble *, BLASLONG, xdouble *, BLASLONG,
  80. xdouble *, BLASLONG, void *) = func;
  81. afunc(args -> m, args -> n, args -> k,
  82. ((xdouble *)args -> alpha)[0],
  83. args -> a, args -> lda,
  84. args -> b, args -> ldb,
  85. args -> c, args -> ldc, sb);
  86. } else
  87. #endif
  88. if ((mode & BLAS_PREC) == BLAS_DOUBLE) {
  89. /* REAL / Double */
  90. void (*afunc)(BLASLONG, BLASLONG, BLASLONG, double,
  91. double *, BLASLONG, double *, BLASLONG,
  92. double *, BLASLONG, void *) = func;
  93. afunc(args -> m, args -> n, args -> k,
  94. ((double *)args -> alpha)[0],
  95. args -> a, args -> lda,
  96. args -> b, args -> ldb,
  97. args -> c, args -> ldc, sb);
  98. } else if ((mode & BLAS_PREC) == BLAS_SINGLE) {
  99. /* REAL / Single */
  100. void (*afunc)(BLASLONG, BLASLONG, BLASLONG, float,
  101. float *, BLASLONG, float *, BLASLONG,
  102. float *, BLASLONG, void *) = func;
  103. afunc(args -> m, args -> n, args -> k,
  104. ((float *)args -> alpha)[0],
  105. args -> a, args -> lda,
  106. args -> b, args -> ldb,
  107. args -> c, args -> ldc, sb);
  108. #ifdef BUILD_BFLOAT16
  109. } else if ((mode & BLAS_PREC) == BLAS_BFLOAT16) {
  110. /* REAL / BFLOAT16 */
  111. void (*afunc)(BLASLONG, BLASLONG, BLASLONG, bfloat16,
  112. bfloat16 *, BLASLONG, bfloat16 *, BLASLONG,
  113. bfloat16 *, BLASLONG, void *) = func;
  114. afunc(args -> m, args -> n, args -> k,
  115. ((bfloat16 *)args -> alpha)[0],
  116. args -> a, args -> lda,
  117. args -> b, args -> ldb,
  118. args -> c, args -> ldc, sb);
  119. } else if ((mode & BLAS_PREC) == BLAS_STOBF16) {
  120. /* REAL / BLAS_STOBF16 */
  121. void (*afunc)(BLASLONG, BLASLONG, BLASLONG, float,
  122. float *, BLASLONG, bfloat16 *, BLASLONG,
  123. float *, BLASLONG, void *) = func;
  124. afunc(args -> m, args -> n, args -> k,
  125. ((float *)args -> alpha)[0],
  126. args -> a, args -> lda,
  127. args -> b, args -> ldb,
  128. args -> c, args -> ldc, sb);
  129. } else if ((mode & BLAS_PREC) == BLAS_DTOBF16) {
  130. /* REAL / BLAS_DTOBF16 */
  131. void (*afunc)(BLASLONG, BLASLONG, BLASLONG, double,
  132. double *, BLASLONG, bfloat16 *, BLASLONG,
  133. double *, BLASLONG, void *) = func;
  134. afunc(args -> m, args -> n, args -> k,
  135. ((double *)args -> alpha)[0],
  136. args -> a, args -> lda,
  137. args -> b, args -> ldb,
  138. args -> c, args -> ldc, sb);
  139. #endif
  140. } else {
  141. /* REAL / Other types in future */
  142. }
  143. } else {
  144. #ifdef EXPRECISION
  145. if ((mode & BLAS_PREC) == BLAS_XDOUBLE) {
  146. /* COMPLEX / Extended Double */
  147. void (*afunc)(BLASLONG, BLASLONG, BLASLONG, xdouble, xdouble,
  148. xdouble *, BLASLONG, xdouble *, BLASLONG,
  149. xdouble *, BLASLONG, void *) = func;
  150. afunc(args -> m, args -> n, args -> k,
  151. ((xdouble *)args -> alpha)[0],
  152. ((xdouble *)args -> alpha)[1],
  153. args -> a, args -> lda,
  154. args -> b, args -> ldb,
  155. args -> c, args -> ldc, sb);
  156. } else
  157. #endif
  158. if ((mode & BLAS_PREC) == BLAS_DOUBLE) {
  159. /* COMPLEX / Double */
  160. void (*afunc)(BLASLONG, BLASLONG, BLASLONG, double, double,
  161. double *, BLASLONG, double *, BLASLONG,
  162. double *, BLASLONG, void *) = func;
  163. afunc(args -> m, args -> n, args -> k,
  164. ((double *)args -> alpha)[0],
  165. ((double *)args -> alpha)[1],
  166. args -> a, args -> lda,
  167. args -> b, args -> ldb,
  168. args -> c, args -> ldc, sb);
  169. } else if ((mode & BLAS_PREC) == BLAS_SINGLE) {
  170. /* COMPLEX / Single */
  171. void (*afunc)(BLASLONG, BLASLONG, BLASLONG, float, float,
  172. float *, BLASLONG, float *, BLASLONG,
  173. float *, BLASLONG, void *) = func;
  174. afunc(args -> m, args -> n, args -> k,
  175. ((float *)args -> alpha)[0],
  176. ((float *)args -> alpha)[1],
  177. args -> a, args -> lda,
  178. args -> b, args -> ldb,
  179. args -> c, args -> ldc, sb);
  180. } else {
  181. /* COMPLEX / Other types in future */
  182. }
  183. }
  184. }
  185. //
  186. // This is a main routine of threads. Each thread waits until job is queued.
  187. //
  188. static DWORD WINAPI blas_thread_server(void *arg) {
  189. /* Thread identifier */
  190. BLASLONG cpu = (BLASLONG)arg;
  191. blas_queue_t *queue;
  192. MT_TRACE("Server[%2ld] Thread is started!\n", cpu);
  193. while (1) {
  194. /* Waiting for Queue */
  195. MT_TRACE("Server[%2ld] Waiting for Queue.\n", cpu);
  196. // event raised when work is added to the queue
  197. WaitForSingleObject(kickoff_event, INFINITE);
  198. if (cpu > thread_target - 2) {
  199. //MT_TRACE("thread [%d] exiting.\n", cpu);
  200. break; // excess thread, so worker thread exits
  201. }
  202. MT_TRACE("Server[%2ld] Got it.\n", cpu);
  203. EnterCriticalSection(&queue_lock);
  204. queue = work_queue;
  205. if (queue)
  206. work_queue = work_queue->next;
  207. LeaveCriticalSection(&queue_lock);
  208. if(queue) {
  209. exec_threads(cpu, queue, 0);
  210. } else {
  211. continue; //if queue == NULL
  212. }
  213. MT_TRACE("Server[%2ld] Finished!\n", cpu);
  214. queue->finished = 1;
  215. }
  216. /* Shutdown procedure */
  217. MT_TRACE("Server[%2ld] Shutdown!\n", cpu);
  218. return 0;
  219. }
  220. //
  221. // Initializing routine
  222. //
  223. int blas_thread_init(void) {
  224. BLASLONG i;
  225. if (blas_server_avail || (blas_cpu_number <= 1)) return 0;
  226. LOCK_COMMAND(&server_lock);
  227. adjust_thread_buffers();
  228. MT_TRACE("Initializing Thread(Num. threads = %d)\n", blas_cpu_number);
  229. if (!blas_server_avail) {
  230. // create the kickoff Event
  231. kickoff_event = CreateEvent(NULL, TRUE, FALSE, NULL);
  232. thread_target = blas_cpu_number;
  233. InitializeCriticalSection(&queue_lock);
  234. for(i = 0; i < blas_cpu_number - 1; i++) {
  235. //MT_TRACE("thread_init: creating thread [%d]\n", i);
  236. blas_threads[i] = CreateThread(NULL, 0,
  237. blas_thread_server, (void *)i,
  238. 0, &blas_threads_id[i]);
  239. }
  240. blas_server_avail = 1;
  241. }
  242. UNLOCK_COMMAND(&server_lock);
  243. return 0;
  244. }
  245. //
  246. // User can call one of two routines.
  247. // exec_blas_async ... immediately returns after jobs are queued.
  248. // exec_blas ... returns after jobs are finished.
  249. //
  250. int exec_blas_async(BLASLONG pos, blas_queue_t *queue) {
  251. #if defined(SMP_SERVER)
  252. // Handle lazy re-init of the thread-pool after a POSIX fork
  253. // on Cygwin or as delayed init when a static library is used
  254. if (unlikely(blas_server_avail == 0)) blas_thread_init();
  255. #endif
  256. blas_queue_t *current;
  257. current = queue;
  258. while (current) {
  259. current -> position = pos;
  260. #ifdef CONSISTENT_FPCSR
  261. __asm__ __volatile__ ("fnstcw %0" : "=m" (current -> x87_mode));
  262. __asm__ __volatile__ ("stmxcsr %0" : "=m" (current -> sse_mode));
  263. #endif
  264. current->finished = 0;
  265. current = current -> next;
  266. pos ++;
  267. }
  268. EnterCriticalSection(&queue_lock);
  269. if (!work_queue)
  270. {
  271. work_queue = queue;
  272. }
  273. else
  274. {
  275. blas_queue_t *queue_item = work_queue;
  276. // find the end of the work queue
  277. while (queue_item->next)
  278. queue_item = queue_item->next;
  279. // add new work to the end
  280. queue_item->next = queue;
  281. }
  282. LeaveCriticalSection(&queue_lock);
  283. SetEvent(kickoff_event);
  284. return 0;
  285. }
  286. //
  287. // Join. Wait for all queued tasks to complete
  288. //
  289. int exec_blas_async_wait(BLASLONG num, blas_queue_t *queue) {
  290. MT_TRACE("Synchronization Waiting.\n");
  291. while (num) {
  292. MT_TRACE("Waiting Queue ..\n");
  293. while (!queue->finished)
  294. YIELDING;
  295. queue = queue->next;
  296. num--;
  297. }
  298. MT_TRACE("Completely Done.\n\n");
  299. // if work was added to the queue after this batch we can't sleep the worker threads
  300. // by resetting the event
  301. EnterCriticalSection(&queue_lock);
  302. if (work_queue == NULL)
  303. ResetEvent(kickoff_event);
  304. LeaveCriticalSection(&queue_lock);
  305. return 0;
  306. }
  307. //
  308. // Execute Threads
  309. //
  310. int exec_blas(BLASLONG num, blas_queue_t *queue) {
  311. #if defined(SMP_SERVER) && defined(OS_CYGWIN_NT)
  312. // Handle lazy re-init of the thread-pool after a POSIX fork
  313. if (unlikely(blas_server_avail == 0)) blas_thread_init();
  314. #endif
  315. #ifndef ALL_THREADED
  316. int (*routine)(blas_arg_t *, void *, void *, double *, double *, BLASLONG);
  317. #endif
  318. if ((num <= 0) || (queue == NULL)) return 0;
  319. //Redirect to caller's callback routine
  320. if (openblas_threads_callback_) {
  321. int buf_index = 0, i = 0;
  322. #ifndef USE_SIMPLE_THREADED_LEVEL3
  323. for (i = 0; i < num; i ++)
  324. queue[i].position = i;
  325. #endif
  326. openblas_threads_callback_(1, (openblas_dojob_callback) exec_threads, num, sizeof(blas_queue_t), (void*) queue, buf_index);
  327. return 0;
  328. }
  329. if ((num > 1) && queue -> next)
  330. exec_blas_async(1, queue -> next);
  331. routine = queue -> routine;
  332. if (queue -> mode & BLAS_LEGACY) {
  333. legacy_exec(routine, queue -> mode, queue -> args, queue -> sb);
  334. } else {
  335. if (queue -> mode & BLAS_PTHREAD) {
  336. void (*pthreadcompat)(void *) = queue -> routine;
  337. (pthreadcompat)(queue -> args);
  338. } else
  339. (routine)(queue -> args, queue -> range_m, queue -> range_n,
  340. queue -> sa, queue -> sb, 0);
  341. }
  342. if ((num > 1) && queue -> next)
  343. exec_blas_async_wait(num - 1, queue -> next);
  344. return 0;
  345. }
  346. //
  347. // Shutdown procedure, but user don't have to call this routine. The
  348. // kernel automatically kill threads.
  349. //
  350. int BLASFUNC(blas_thread_shutdown)(void) {
  351. int i;
  352. if (!blas_server_avail) return 0;
  353. LOCK_COMMAND(&server_lock);
  354. //Free buffers allocated for threads
  355. for(i=0; i<MAX_CPU_NUMBER; i++){
  356. if(blas_thread_buffer[i]!=NULL){
  357. blas_memory_free(blas_thread_buffer[i]);
  358. blas_thread_buffer[i]=NULL;
  359. }
  360. }
  361. if (blas_server_avail) {
  362. for (i = 0; i < blas_num_threads - 1; i++) {
  363. // Could also just use WaitForMultipleObjects
  364. DWORD wait_thread_value = WaitForSingleObject(blas_threads[i], 50);
  365. #ifndef OS_WINDOWSSTORE
  366. // TerminateThread is only available with WINAPI_DESKTOP and WINAPI_SYSTEM not WINAPI_APP in UWP
  367. if (WAIT_OBJECT_0 != wait_thread_value) {
  368. TerminateThread(blas_threads[i],0);
  369. }
  370. #endif
  371. CloseHandle(blas_threads[i]);
  372. }
  373. blas_server_avail = 0;
  374. }
  375. UNLOCK_COMMAND(&server_lock);
  376. return 0;
  377. }
  378. //
  379. // Legacy function to set numbef of threads
  380. //
  381. void goto_set_num_threads(int num_threads)
  382. {
  383. long i;
  384. #if defined(SMP_SERVER) && defined(OS_CYGWIN_NT)
  385. // Handle lazy re-init of the thread-pool after a POSIX fork
  386. if (unlikely(blas_server_avail == 0)) blas_thread_init();
  387. #endif
  388. if (num_threads < 1) num_threads = blas_cpu_number;
  389. if (num_threads > MAX_CPU_NUMBER) num_threads = MAX_CPU_NUMBER;
  390. if (blas_server_avail && num_threads < blas_num_threads) {
  391. LOCK_COMMAND(&server_lock);
  392. thread_target = num_threads;
  393. SetEvent(kickoff_event);
  394. for (i = num_threads - 1; i < blas_num_threads - 1; i++) {
  395. //MT_TRACE("set_num_threads: waiting on thread [%d] to quit.\n", i);
  396. WaitForSingleObject(blas_threads[i], INFINITE);
  397. //MT_TRACE("set_num_threads: thread [%d] has quit.\n", i);
  398. CloseHandle(blas_threads[i]);
  399. }
  400. blas_num_threads = num_threads;
  401. ResetEvent(kickoff_event);
  402. UNLOCK_COMMAND(&server_lock);
  403. }
  404. if (num_threads > blas_num_threads) {
  405. LOCK_COMMAND(&server_lock);
  406. thread_target = num_threads;
  407. //increased_threads = 1;
  408. if (!blas_server_avail) {
  409. // create the kickoff Event
  410. kickoff_event = CreateEvent(NULL, TRUE, FALSE, NULL);
  411. InitializeCriticalSection(&queue_lock);
  412. blas_server_avail = 1;
  413. }
  414. for (i = (blas_num_threads > 0) ? blas_num_threads - 1 : 0; i < num_threads - 1; i++) {
  415. //MT_TRACE("set_num_threads: creating thread [%d]\n", i);
  416. blas_threads[i] = CreateThread(NULL, 0,
  417. blas_thread_server, (void *)i,
  418. 0, &blas_threads_id[i]);
  419. }
  420. blas_num_threads = num_threads;
  421. UNLOCK_COMMAND(&server_lock);
  422. }
  423. blas_cpu_number = num_threads;
  424. }
  425. //
  426. // Openblas function to set thread count
  427. //
  428. void openblas_set_num_threads(int num)
  429. {
  430. goto_set_num_threads(num);
  431. }
  432. static void adjust_thread_buffers() {
  433. int i=0;
  434. //adjust buffer for each thread
  435. for(i=0; i < blas_cpu_number; i++){
  436. if(blas_thread_buffer[i] == NULL){
  437. blas_thread_buffer[i] = blas_memory_alloc(2);
  438. }
  439. }
  440. for(; i < MAX_CPU_NUMBER; i++){
  441. if(blas_thread_buffer[i] != NULL){
  442. blas_memory_free(blas_thread_buffer[i]);
  443. blas_thread_buffer[i] = NULL;
  444. }
  445. }
  446. }
  447. //Indivitual threads work executor, Helps in setting by synchronization environment and calling inner_threads routine
  448. static void exec_threads(int cpu, blas_queue_t *queue, int buf_index) {
  449. void *buffer, *sa, *sb;
  450. buffer = blas_thread_buffer[cpu];
  451. sa = queue -> sa;
  452. sb = queue -> sb;
  453. int (*routine)(blas_arg_t *, void *, void *, void *, void *, BLASLONG) = queue -> routine;
  454. #ifdef CONSISTENT_FPCSR
  455. __asm__ __volatile__ ("ldmxcsr %0" : : "m" (queue -> sse_mode));
  456. __asm__ __volatile__ ("fldcw %0" : : "m" (queue -> x87_mode));
  457. #endif
  458. MT_TRACE("Server[%2ld] Started. Mode = 0x%03x M = %3ld N=%3ld K=%3ld\n",
  459. cpu, queue->mode, queue-> args ->m, queue->args->n, queue->args->k);
  460. // fprintf(stderr, "queue start[%ld]!!!\n", cpu);
  461. #ifdef MONITOR
  462. main_status[cpu] = MAIN_RUNNING1;
  463. #endif
  464. if (sa == NULL)
  465. sa = (void *)((BLASLONG)buffer + GEMM_OFFSET_A);
  466. if (sb == NULL) {
  467. if (!(queue -> mode & BLAS_COMPLEX)) {
  468. #ifdef EXPRECISION
  469. if ((queue -> mode & BLAS_PREC) == BLAS_XDOUBLE) {
  470. sb = (void *)(((BLASLONG)sa + ((XGEMM_P * XGEMM_Q * sizeof(xdouble)
  471. + GEMM_ALIGN) & ~GEMM_ALIGN)) + GEMM_OFFSET_B);
  472. } else
  473. #endif
  474. if ((queue -> mode & BLAS_PREC) == BLAS_DOUBLE) {
  475. #ifdef BUILD_DOUBLE
  476. sb = (void *)(((BLASLONG)sa + ((DGEMM_P * DGEMM_Q * sizeof(double)
  477. + GEMM_ALIGN) & ~GEMM_ALIGN)) + GEMM_OFFSET_B);
  478. #endif
  479. } else if ((queue -> mode & BLAS_PREC) == BLAS_SINGLE) {
  480. #ifdef BUILD_SINGLE
  481. sb = (void *)(((BLASLONG)sa + ((SGEMM_P * SGEMM_Q * sizeof(float)
  482. + GEMM_ALIGN) & ~GEMM_ALIGN)) + GEMM_OFFSET_B);
  483. #endif
  484. } else {
  485. /* Other types in future */
  486. }
  487. } else {
  488. #ifdef EXPRECISION
  489. if ((queue -> mode & BLAS_PREC) == BLAS_XDOUBLE){
  490. sb = (void *)(((BLASLONG)sa + ((XGEMM_P * XGEMM_Q * 2 * sizeof(xdouble)
  491. + GEMM_ALIGN) & ~GEMM_ALIGN)) + GEMM_OFFSET_B);
  492. } else
  493. #endif
  494. if ((queue -> mode & BLAS_PREC) == BLAS_DOUBLE){
  495. #ifdef BUILD_COMPLEX16
  496. sb = (void *)(((BLASLONG)sa + ((ZGEMM_P * ZGEMM_Q * 2 * sizeof(double)
  497. + GEMM_ALIGN) & ~GEMM_ALIGN)) + GEMM_OFFSET_B);
  498. #endif
  499. } else if ((queue -> mode & BLAS_PREC) == BLAS_SINGLE) {
  500. #ifdef BUILD_COMPLEX
  501. sb = (void *)(((BLASLONG)sa + ((CGEMM_P * CGEMM_Q * 2 * sizeof(float)
  502. + GEMM_ALIGN) & ~GEMM_ALIGN)) + GEMM_OFFSET_B);
  503. #endif
  504. } else {
  505. /* Other types in future */
  506. }
  507. }
  508. queue->sb=sb;
  509. }
  510. #ifdef MONITOR
  511. main_status[cpu] = MAIN_RUNNING2;
  512. #endif
  513. if (!(queue -> mode & BLAS_LEGACY)) {
  514. (routine)(queue -> args, queue -> range_m, queue -> range_n, sa, sb, queue -> position);
  515. } else {
  516. legacy_exec(routine, queue -> mode, queue -> args, sb);
  517. }
  518. }