Expression Templates Library (ETL)
dot.hpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c) 2014-2023 Baptiste Wicht
3 // Distributed under the terms of the MIT License.
4 // (See accompanying file LICENSE or copy at
5 // http://opensource.org/licenses/MIT)
6 //=======================================================================
7 
13 #pragma once
14 
15 #ifdef ETL_BLAS_MODE
16 #include "cblas.h" //For ddot/sdot
17 #endif
18 
19 namespace etl::impl::blas {
20 
21 #ifdef ETL_BLAS_MODE
22 
29 template <typename A, typename B>
30 value_t<A> dot(const A& a, const B& b) {
31  if constexpr (all_dma<A, B>) {
32  a.ensure_cpu_up_to_date();
33  b.ensure_cpu_up_to_date();
34 
35  if constexpr (all_single_precision<A, B>) {
36  return cblas_sdot(etl::size(a), a.memory_start(), 1, b.memory_start(), 1);
37  } else {
38  return cblas_ddot(etl::size(a), a.memory_start(), 1, b.memory_start(), 1);
39  }
40  } else {
41  cpp_unreachable("BLAS not enabled/available");
42  return 0.0;
43  }
44 }
45 
46 #else
47 
48 //COVERAGE_EXCLUDE_BEGIN
49 
53 template <typename A, typename B>
54 value_t<A> dot(const A& /*a*/, const B& /*b*/) {
55  cpp_unreachable("BLAS not enabled/available");
56  return 0.0;
57 }
58 
59  //COVERAGE_EXCLUDE_END
60 
61 #endif
62 
63 } //end of namespace etl::impl::blas
value_t< A > dot(const A &a, const B &b)
Returns the dot product of the two given expressions.
Definition: expression_builder.hpp:594
Definition: dot.hpp:19
typename decay_traits< E >::value_type value_t
Traits to extract the value type out of an ETL type.
Definition: tmp.hpp:81