TRIQS/nda
2.0.0
Multi-dimensional array library for C++
Toggle main menu visibility
Loading...
Searching...
No Matches
dot.hpp
Go to the documentation of this file.
1
// Copyright (c) 2019--present, The Simons Foundation
2
// This file is part of TRIQS/nda and is licensed under the Apache License, Version 2.0.
3
// SPDX-License-Identifier: Apache-2.0
4
// See LICENSE in the root of this distribution for details.
5
10
11
#pragma once
12
13
#include "
./interface/cxx_interface.hpp
"
14
#include "
../concepts.hpp
"
15
#include "
../macros.hpp
"
16
#include "
../mem/address_space.hpp
"
17
#include "
../traits.hpp
"
18
19
#ifndef NDA_HAVE_DEVICE
20
#include "
../device.hpp
"
21
#endif
// NDA_HAVE_DEVICE
22
23
namespace
nda::blas {
24
29
46
template
<MemoryVector X, MemoryVector Y>
47
requires
(
have_same_value_type_v<X, Y>
and
mem::have_compatible_addr_space<X, Y>
and
is_blas_lapack_v<get_value_t<X>
>)
48
auto
dot
(X
const
&x, Y
const
&y) {
49
// check the dimensions of the input/output arrays/views
50
EXPECTS(x.size() == y.size());
51
52
// perform actual library call
53
if
constexpr
(
mem::have_device_compatible_addr_space<X, Y>
) {
54
#if defined(NDA_HAVE_DEVICE)
55
return
device::dot(x.size(), x.data(), x.indexmap().strides()[0], y.data(), y.indexmap().strides()[0]);
56
#else
57
compile_error_no_gpu
();
58
return
get_value_t<X>
(0);
59
#endif
60
}
else
{
61
return
f77::dot(x.size(), x.data(), x.indexmap().strides()[0], y.data(), y.indexmap().strides()[0]);
62
}
63
}
64
81
template
<MemoryVector X, MemoryVector Y>
82
requires
(
have_same_value_type_v<X, Y>
and
mem::have_compatible_addr_space<X, Y>
and
is_blas_lapack_v<get_value_t<X>
>)
83
auto
dotc
(X
const
&x, Y
const
&y) {
84
// check the dimensions of the input/output arrays/views
85
EXPECTS(x.size() == y.size());
86
87
// perform actual library call
88
if
constexpr
(!
is_complex_v<get_value_t<X>
>) {
89
return
dot
(x, y);
90
}
else
if
constexpr
(
mem::have_device_compatible_addr_space<X, Y>
) {
91
#if defined(NDA_HAVE_DEVICE)
92
return
device::dotc(x.size(), x.data(), x.indexmap().strides()[0], y.data(), y.indexmap().strides()[0]);
93
#else
94
compile_error_no_gpu
();
95
return
get_value_t<X>
(0);
96
#endif
97
}
else
{
98
return
f77::dotc(x.size(), x.data(), x.indexmap().strides()[0], y.data(), y.indexmap().strides()[0]);
99
}
100
}
101
103
104
}
// namespace nda::blas
address_space.hpp
Provides definitions and type traits involving the different memory address spaces supported by nda.
cxx_interface.hpp
Provides a C++ interface for various BLAS routines.
concepts.hpp
Provides concepts for the nda library.
device.hpp
Provides GPU and non-GPU specific functionality.
nda::have_same_value_type_v
constexpr bool have_same_value_type_v
Constexpr variable that is true if all types in As have the same value type as A0.
Definition
traits.hpp:195
nda::get_value_t
std::decay_t< decltype(get_first_element(std::declval< A const >()))> get_value_t
Get the value type of an array/view or a scalar type.
Definition
traits.hpp:191
nda::blas::dot
auto dot(X const &x, Y const &y)
Interface to the BLAS dot and dotu routine.
Definition
dot.hpp:48
nda::blas::dotc
auto dotc(X const &x, Y const &y)
Interface to the BLAS dotc routine.
Definition
dot.hpp:83
nda::mem::have_compatible_addr_space
static constexpr bool have_compatible_addr_space
Constexpr variable that is true if all given types have compatible address spaces.
Definition
address_space.hpp:181
nda::mem::have_device_compatible_addr_space
static constexpr bool have_device_compatible_addr_space
Constexpr variable that is true if all given types have an address space compatible with Device.
Definition
address_space.hpp:177
nda::compile_error_no_gpu
void compile_error_no_gpu()
Trigger a compilation error in case GPU specific functionality is used without configuring the projec...
Definition
device.hpp:36
nda::is_complex_v
constexpr bool is_complex_v
Constexpr variable that is true if type T is a std::complex type.
Definition
traits.hpp:65
nda::is_blas_lapack_v
constexpr bool is_blas_lapack_v
Alias for nda::is_double_or_complex_v.
Definition
traits.hpp:92
macros.hpp
Macros used in the nda library.
traits.hpp
Provides type traits for the nda library.
nda
blas
dot.hpp
Generated by
1.17.0