kaldi-blas.h
Go to the documentation of this file.
1 // matrix/kaldi-blas.h
2 
3 // Copyright 2009-2011 Ondrej Glembek; Microsoft Corporation
4 
5 // See ../../COPYING for clarification regarding multiple authors
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 
11 // http://www.apache.org/licenses/LICENSE-2.0
12 
13 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16 // MERCHANTABLITY OR NON-INFRINGEMENT.
17 // See the Apache 2 License for the specific language governing permissions and
18 // limitations under the License.
19 #ifndef KALDI_MATRIX_KALDI_BLAS_H_
20 #define KALDI_MATRIX_KALDI_BLAS_H_
21 
22 // This file handles the #includes for BLAS, LAPACK and so on.
23 // It manipulates the declarations into a common format that kaldi can handle.
24 // However, the kaldi code will check whether HAVE_ATLAS is defined as that
25 // code is called a bit differently from CLAPACK that comes from other sources.
26 
27 // There are three alternatives:
28 // (i) you have ATLAS, which includes the ATLAS implementation of CBLAS
29 // plus a subset of CLAPACK (but with clapack_ in the function declarations).
30 // In this case, define HAVE_ATLAS and make sure the relevant directories are
31 // in the include path.
32 
33 // (ii) you have CBLAS (some implementation thereof) plus CLAPACK.
34 // In this case, define HAVE_CLAPACK.
35 // [Since CLAPACK depends on BLAS, the presence of BLAS is implicit].
36 
37 // (iii) you have the MKL library, which includes CLAPACK and CBLAS.
38 
39 // Note that if we are using ATLAS, no Svd implementation is supplied,
40 // so we define HAVE_Svd to be zero and this directs our implementation to
41 // supply its own "by hand" implementation which is based on TNT code.
42 
43 
44 
45 
46 #if (defined(HAVE_CLAPACK) && (defined(HAVE_ATLAS) || defined(HAVE_MKL))) \
47  || (defined(HAVE_ATLAS) && defined(HAVE_MKL))
48 #error "Do not define more than one of HAVE_CLAPACK, HAVE_ATLAS and HAVE_MKL"
49 #endif
50 
51 #ifdef HAVE_ATLAS
52  extern "C" {
53  #include "cblas.h"
54  #include "clapack.h"
55  }
56 #elif defined(HAVE_CLAPACK)
57  #ifdef __APPLE__
58  #ifndef __has_extension
59  #define __has_extension(x) 0
60  #endif
61  #define vImage_Utilities_h
62  #define vImage_CVUtilities_h
63  #include <Accelerate/Accelerate.h>
64  typedef __CLPK_integer integer;
65  typedef __CLPK_logical logical;
66  typedef __CLPK_real real;
67  typedef __CLPK_doublereal doublereal;
68  typedef __CLPK_complex complex;
69  typedef __CLPK_doublecomplex doublecomplex;
70  typedef __CLPK_ftnlen ftnlen;
71  #else
72  extern "C" {
73  // May be in /usr/[local]/include if installed; else this uses the one
74  // from the tools/CLAPACK_include directory.
75  #include <cblas.h>
76  #include <f2c.h>
77  #include <clapack.h>
78 
79  // get rid of macros from f2c.h -- these are dangerous.
80  #undef abs
81  #undef dabs
82  #undef min
83  #undef max
84  #undef dmin
85  #undef dmax
86  #undef bit_test
87  #undef bit_clear
88  #undef bit_set
89  }
90  #endif
91 #elif defined(HAVE_MKL)
92  extern "C" {
93  #include <mkl.h>
94  }
95 #elif defined(HAVE_OPENBLAS)
96  // getting cblas.h and lapacke.h from <openblas-install-dir>/.
97  // putting in "" not <> to search -I before system libraries.
98  #include "cblas.h"
99  #include "lapacke.h"
100  #undef I
101  #undef complex
102  // get rid of macros from f2c.h -- these are dangerous.
103  #undef abs
104  #undef dabs
105  #undef min
106  #undef max
107  #undef dmin
108  #undef dmax
109  #undef bit_test
110  #undef bit_clear
111  #undef bit_set
112 #else
113  #error "You need to define (using the preprocessor) either HAVE_CLAPACK or HAVE_ATLAS or HAVE_MKL (but not more than one)"
114 #endif
115 
116 #ifdef HAVE_OPENBLAS
117 typedef int KaldiBlasInt; // try int.
118 #endif
119 #ifdef HAVE_CLAPACK
120 typedef integer KaldiBlasInt;
121 #endif
122 #ifdef HAVE_MKL
123 typedef MKL_INT KaldiBlasInt;
124 #endif
125 
126 #ifdef HAVE_ATLAS
127 // in this case there is no need for KaldiBlasInt-- this typedef is only needed
128 // for Svd code which is not included in ATLAS (we re-implement it).
129 #endif
130 
131 
132 #endif // KALDI_MATRIX_KALDI_BLAS_H_
double real