SIRIUS 7.5.0
Electronic structure library and applications
linalg_spla.hpp
Go to the documentation of this file.
1// Copyright (c) 2013-2020 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 linalg_spla.hpp
21 *
22 * \brief Interface to SPLA library
23 */
24
25#ifndef __LINALG_SPLA_HPP__
26#define __LINALG_SPLA_HPP__
27
28#include <memory>
29#include <spla/spla.hpp>
30#include "blas_lapack.h"
31
32namespace sirius {
33
34namespace splablas {
35
36inline SplaOperation
37get_spla_operation(char c)
38{
39 switch (c) {
40 case 'n':
41 case 'N': {
42 return SPLA_OP_NONE;
43 }
44 case 't':
45 case 'T': {
46 return SPLA_OP_TRANSPOSE;
47 }
48 case 'c':
49 case 'C': {
50 return SPLA_OP_CONJ_TRANSPOSE;
51 }
52 default: {
53 throw std::runtime_error("get_spla_operation(): wrong operation");
54 }
55 }
56 return SPLA_OP_NONE; // make compiler happy
57}
58
59std::shared_ptr<::spla::Context>& get_handle_ptr();
60
61inline void
62set_handle_ptr(std::shared_ptr<::spla::Context> ptr)
63{
64 get_handle_ptr() = std::move(ptr);
65}
66
67inline void
68reset_handle(SplaProcessingUnit op = SPLA_PU_HOST)
69{
70 get_handle_ptr().reset(new ::spla::Context{op});
71}
72
73inline void
74sgemm(char transa, char transb, ftn_int m, ftn_int n, ftn_int k, ftn_single const* alpha, ftn_single const* A,
75 ftn_int lda, ftn_single const* B, ftn_int ldb, ftn_single const* beta, ftn_single* C, ftn_int ldc)
76{
77 ::spla::gemm(get_spla_operation(transa), get_spla_operation(transb), m, n, k, *alpha, A, lda, B, ldb, *beta, C, ldc,
78 *get_handle_ptr());
79}
80
81inline void
82dgemm(char transa, char transb, ftn_int m, ftn_int n, ftn_int k, ftn_double const* alpha, ftn_double const* A,
83 ftn_int lda, ftn_double const* B, ftn_int ldb, ftn_double const* beta, ftn_double* C, ftn_int ldc)
84{
85 ::spla::gemm(get_spla_operation(transa), get_spla_operation(transb), m, n, k, *alpha, A, lda, B, ldb, *beta, C, ldc,
86 *get_handle_ptr());
87}
88
89inline void
90cgemm(char transa, char transb, ftn_int m, ftn_int n, ftn_int k, ftn_complex const* alpha, ftn_complex const* A,
91 ftn_int lda, ftn_complex const* B, ftn_int ldb, ftn_complex const* beta, ftn_complex* C, ftn_int ldc)
92{
93 ::spla::gemm(get_spla_operation(transa), get_spla_operation(transb), m, n, k, *alpha, A, lda, B, ldb, *beta, C, ldc,
94 *get_handle_ptr());
95}
96
97inline void
98zgemm(char transa, char transb, ftn_int m, ftn_int n, ftn_int k, ftn_double_complex const* alpha,
99 ftn_double_complex const* A, ftn_int lda, ftn_double_complex const* B, ftn_int ldb,
100 ftn_double_complex const* beta, ftn_double_complex* C, ftn_int ldc)
101{
102 ::spla::gemm(get_spla_operation(transa), get_spla_operation(transb), m, n, k, *alpha, A, lda, B, ldb, *beta, C, ldc,
103 *get_handle_ptr());
104}
105} // namespace splablas
106} // namespace sirius
107
108#endif // __LINALG_SPLA_HPP__
Interface to some BLAS/LAPACK functions.
Namespace of the SIRIUS library.
Definition: sirius.f90:5