SIRIUS 7.5.0
Electronic structure library and applications
magma.hpp
Go to the documentation of this file.
1// Copyright (c) 2013-2018 Anton Kozhevnikov, Thomas Schulthess
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without modification, are permitted provided that
5// the following conditions are met:
6//
7// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
8// following disclaimer.
9// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
10// and the following disclaimer in the documentation and/or other materials provided with the distribution.
11//
12// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
13// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
14// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
15// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
16// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
17// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
18// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19
20/** \file magma.hpp
21 *
22 * \brief Interface to some of the MAGMA functions.
23 */
24
25#ifndef __MAGMA_HPP__
26#define __MAGMA_HPP__
27
28#include <stdio.h>
29#include <assert.h>
30#include <magma.h>
31#include <magma_z.h>
32#include <magma_d.h>
33#include <cstring>
34
35#include "magma_threadsetting.h"
36
37namespace sirius {
38
39/// Interface to MAGMA functions.
40namespace magma {
41
42inline void init()
43{
44 magma_init();
45}
46
47inline void finalize()
48{
49 magma_finalize();
50}
51
52inline int spotrf(char uplo, int n, float* A, int lda)
53{
54 if (!(uplo == 'U' || uplo == 'L')) {
55 printf("magma_spotrf_wrapper: wrong uplo\n");
56 exit(-1);
57 }
58 magma_uplo_t magma_uplo = (uplo == 'U') ? MagmaUpper : MagmaLower;
59 magma_int_t info;
60 magma_spotrf_gpu(magma_uplo, n, A, lda, &info);
61 return info;
62}
63
64inline int dpotrf(char uplo, int n, double* A, int lda)
65{
66 if (!(uplo == 'U' || uplo == 'L')) {
67 printf("magma_dpotrf_wrapper: wrong uplo\n");
68 exit(-1);
69 }
70 magma_uplo_t magma_uplo = (uplo == 'U') ? MagmaUpper : MagmaLower;
71 magma_int_t info;
72 magma_dpotrf_gpu(magma_uplo, n, A, lda, &info);
73 return info;
74}
75
76inline int cpotrf(char uplo, int n, magmaFloatComplex* A, int lda)
77{
78 if (!(uplo == 'U' || uplo == 'L')) {
79 printf("magma_cpotrf_wrapper: wrong uplo\n");
80 exit(-1);
81 }
82 magma_uplo_t magma_uplo = (uplo == 'U') ? MagmaUpper : MagmaLower;
83 magma_int_t info;
84 magma_cpotrf_gpu(magma_uplo, n, A, lda, &info);
85 return info;
86}
87
88inline int zpotrf(char uplo, int n, magmaDoubleComplex* A, int lda)
89{
90 if (!(uplo == 'U' || uplo == 'L')) {
91 printf("magma_zpotrf_wrapper: wrong uplo\n");
92 exit(-1);
93 }
94 magma_uplo_t magma_uplo = (uplo == 'U') ? MagmaUpper : MagmaLower;
95 magma_int_t info;
96 magma_zpotrf_gpu(magma_uplo, n, A, lda, &info);
97 return info;
98}
99
100inline int strtri(char uplo, int n, float* A, int lda)
101{
102 if (!(uplo == 'U' || uplo == 'L')) {
103 printf("magma_strtri_wrapper: wrong uplo\n");
104 exit(-1);
105 }
106 magma_uplo_t magma_uplo = (uplo == 'U') ? MagmaUpper : MagmaLower;
107 magma_int_t info;
108 magma_strtri_gpu(magma_uplo, MagmaNonUnit, n, A, lda, &info);
109 return info;
110}
111
112inline int dtrtri(char uplo, int n, double* A, int lda)
113{
114 if (!(uplo == 'U' || uplo == 'L')) {
115 printf("magma_dtrtri_wrapper: wrong uplo\n");
116 exit(-1);
117 }
118 magma_uplo_t magma_uplo = (uplo == 'U') ? MagmaUpper : MagmaLower;
119 magma_int_t info;
120 magma_dtrtri_gpu(magma_uplo, MagmaNonUnit, n, A, lda, &info);
121 return info;
122}
123
124inline int ctrtri(char uplo, int n, magmaFloatComplex* A, int lda)
125{
126 if (!(uplo == 'U' || uplo == 'L')) {
127 printf("magma_ctrtri_wrapper: wrong uplo\n");
128 exit(-1);
129 }
130 magma_uplo_t magma_uplo = (uplo == 'U') ? MagmaUpper : MagmaLower;
131 magma_int_t info;
132 magma_ctrtri_gpu(magma_uplo, MagmaNonUnit, n, A, lda, &info);
133 return info;
134}
135
136inline int ztrtri(char uplo, int n, magmaDoubleComplex* A, int lda)
137{
138 if (!(uplo == 'U' || uplo == 'L')) {
139 printf("magma_ztrtri_wrapper: wrong uplo\n");
140 exit(-1);
141 }
142 magma_uplo_t magma_uplo = (uplo == 'U') ? MagmaUpper : MagmaLower;
143 magma_int_t info;
144 magma_ztrtri_gpu(magma_uplo, MagmaNonUnit, n, A, lda, &info);
145 return info;
146}
147
148} // namespace magma
149
150} // namespace sirius
151
152#endif
Internal MAGMA file which is missing in the standard installation.
Namespace of the SIRIUS library.
Definition: sirius.f90:5