GemaCoreLib
The GeMA Core library
Loading...
Searching...
No Matches
gmBlas.h
Go to the documentation of this file.
1/************************************************************************
2**
3** Copyright (C) 2014 by Carlos Augusto Teixera Mendes
4** All rights reserved.
5**
6** This file is part of the "GeMA" software. It's use should respect
7** the terms in the license agreement that can be found together
8** with this source code.
9** It is provided AS IS, with NO WARRANTY OF ANY KIND,
10** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR
11** A PARTICULAR PURPOSE.
12**
13************************************************************************/
14
26#ifndef _GEMA_BLAS_H_
27#define _GEMA_BLAS_H_
28
29#include <assert.h>
30
31#ifdef GEMA_OPEN_BLAS
32
33extern "C"
34{
35 void openblas_set_num_threads(int num_threads);
36 int openblas_get_num_threads(void);
37}
38
39#define GEMA_BLAS_SET_NUM_THREADS(n) openblas_set_num_threads(n)
40#define GEMA_BLAS_GET_NUM_THREADS() openblas_get_num_threads()
41
42#elif defined GEMA_MKL_BLAS
43
44extern "C"
45{
46 void MKL_Set_Num_Threads(int num_threads);
47 int MKL_Get_Max_Threads(void);
48}
49
50
51#define GEMA_BLAS_SET_NUM_THREADS(n) MKL_Set_Num_Threads(n)
52#define GEMA_BLAS_GET_NUM_THREADS() MKL_Get_Max_Threads()
53
54#elif defined GEMA_AOCL_BLAS
55
56extern "C"
57{
58 void bli_thread_set_num_threads(int num_threads);
59 int bli_thread_get_num_threads(void);
60}
61
62#define GEMA_BLAS_SET_NUM_THREADS(n) bli_thread_set_num_threads(n)
63#define GEMA_BLAS_GET_NUM_THREADS() bli_thread_get_num_threads()
64
65#else
66
67#define GEMA_BLAS_SET_NUM_THREADS(n) ((void)0)
68#define GEMA_BLAS_GET_NUM_THREADS() (1)
69
70#endif
71
72// GmBlasLibName
73#if defined GEMA_MKL_BLAS
74constexpr const char* GmBlasLibName = "Intel Mkl";
75#elif defined GEMA_OPEN_BLAS
76constexpr const char* GmBlasLibName = "OpenBlas";
77#elif defined GEMA_AOCL_BLAS
78constexpr const char* GmBlasLibName = "AMD AOCL";
79#elif defined GEMA_STD_BLAS
80constexpr const char* GmBlasLibName = "Generic";
81#else
82constexpr const char* GmBlasLibName = "Unknown";
83#endif
84
85// GmArmaBlasConfigFlag e GmArmaLapackConfigFlag (either "no " or "")
86#ifdef ARMA_DONT_USE_BLAS
87constexpr const char* GmArmaBlasConfigFlag = "no ";
88#else
89constexpr const char* GmArmaBlasConfigFlag = "";
90#endif
91
92#ifdef ARMA_DONT_USE_LAPACK
93constexpr const char* GmArmaLapackConfigFlag = "no ";
94#else
95constexpr const char* GmArmaLapackConfigFlag = "";
96#endif
97
98
100inline void GmBlasInit(int maxThreads)
101{
102 assert(maxThreads > 0);
103 GEMA_BLAS_SET_NUM_THREADS(maxThreads);
104
105}
106
109{
110public:
111 GmBlasTempUpdateNumThreads(int nthreads)
112 {
113 if(nthreads)
114 {
115 _oldNumThreads = GEMA_BLAS_GET_NUM_THREADS();
116 GEMA_BLAS_SET_NUM_THREADS(nthreads);
117 }
118 else
119 _oldNumThreads = -1;
120 }
121
123 {
124 if(_oldNumThreads != -1) GEMA_BLAS_SET_NUM_THREADS(_oldNumThreads);
125 }
126private:
127
128 int _oldNumThreads;
129};
130
131
132#endif
A RAII class used to temporarily adjust the number of OpenBlas threads in effect. If the number of th...
Definition gmBlas.h:109
void GmBlasInit(int maxThreads)
Initializes Blas to use the given maximum number of threads.
Definition gmBlas.h:100