HMSBEAGLE  1.0.0
GPUImplHelper.h
1 /*
2  * @brief GPU implementation helper functions
3  *
4  * Copyright 2009 Phylogenetic Likelihood Working Group
5  *
6  * This file is part of BEAGLE.
7  *
8  * BEAGLE is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as
10  * published by the Free Software Foundation, either version 3 of
11  * the License, or (at your option) any later version.
12  *
13  * BEAGLE is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with BEAGLE. If not, see
20  * <http://www.gnu.org/licenses/>.
21  *
22  * @author Marc Suchard
23  * @author Daniel Ayres
24  */
25 
26 #ifndef __GPUImplHelper__
27 #define __GPUImplHelper__
28 
29 #ifdef HAVE_CONFIG_H
30 #include "libhmsbeagle/config.h"
31 #endif
32 
33 #include "libhmsbeagle/GPU/GPUImplDefs.h"
34 
35 void checkHostMemory(void* ptr);
36 
40 template<typename Real>
41 void transposeSquareMatrix(Real* mat,
42  int size) {
43  for (int i = 0; i < size - 1; i++) {
44  for (int j = i + 1; j < size; j++) {
45  Real tmp = mat[i * size + j];
46  mat[i * size + j] = mat[j * size + i];
47  mat[j * size + i] = tmp;
48  }
49  }
50 }
51 
52 template<typename Real>
53 void printfVector(Real* ptr,
54  int length) {
55  fprintf(stderr, "[ %1.5e", ptr[0]);
56  int i;
57  for (i = 1; i < length; i++)
58  fprintf(stderr, " %1.5e", ptr[i]);
59  fprintf(stderr, " ]\n");
60 }
61 
62 void printfInt(int* ptr,
63  int length);
64 
65 #endif // __GPUImplHelper__