Expression Templates Library (ETL)
equal.hpp
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 
8 #pragma once
9 
11 
12 namespace etl {
13 
17 template <typename T>
19  static constexpr bool linear = true;
20  static constexpr bool thread_safe = true;
21  static constexpr bool desc_func = false;
22 
28  template <vector_mode_t V>
29  static constexpr bool vectorizable = false;
30 
34  template <typename L, typename R>
35  static constexpr bool gpu_computable = (all_single_precision<L, R> && impl::egblas::has_sequal) || (all_double_precision<L, R> && impl::egblas::has_dequal)
36  || (all_complex_single_precision<L, R> && impl::egblas::has_cequal)
37  || (all_complex_double_precision<L, R> && impl::egblas::has_zequal);
38 
43  static constexpr int complexity() {
44  return 1;
45  }
46 
53  static constexpr bool apply(const T& lhs, const T& rhs) noexcept {
54  return lhs == rhs;
55  }
56 
64  template <typename X, typename Y, typename YY>
65  static auto gpu_compute_hint(const X& x, const Y& y, const YY& yy) noexcept {
66  decltype(auto) t1 = smart_gpu_compute_hint(x, yy);
67  decltype(auto) t2 = smart_gpu_compute_hint(y, yy);
68 
69  auto t3 = force_temporary_gpu_dim_only_t<bool>(t1);
70 
71  constexpr size_t inca = gpu_inc<decltype(x)>;
72  constexpr size_t incb = gpu_inc<decltype(y)>;
73 
74  impl::egblas::equal(etl::size(yy), t1.gpu_memory(), inca, t2.gpu_memory(), incb, t3.gpu_memory(), 1);
75 
76  return t3;
77  }
78 
85  template <typename X, typename Y, typename YY>
86  static YY& gpu_compute(const X& x, const Y& y, YY& yy) noexcept {
87  decltype(auto) t1 = smart_gpu_compute_hint(x, yy);
88  decltype(auto) t2 = smart_gpu_compute_hint(y, yy);
89 
90  constexpr size_t inca = gpu_inc<decltype(x)>;
91  constexpr size_t incb = gpu_inc<decltype(y)>;
92 
93  impl::egblas::equal(etl::size(yy), t1.gpu_memory(), inca, t2.gpu_memory(), incb, yy.gpu_memory(), 1);
94 
95  yy.validate_gpu();
96  yy.invalidate_cpu();
97 
98  return yy;
99  }
100 
105  static std::string desc() noexcept {
106  return "==";
107  }
108 };
109 
110 } //end of namespace etl
static YY & gpu_compute(const X &x, const Y &y, YY &yy) noexcept
Compute the result of the operation using the GPU.
Definition: equal.hpp:86
static constexpr bool vectorizable
Indicates if the expression is vectorizable using the given vector mode.
Definition: equal.hpp:29
static constexpr bool apply(const T &lhs, const T &rhs) noexcept
Apply the unary operator on lhs and rhs.
Definition: equal.hpp:53
static auto gpu_compute_hint(const X &x, const Y &y, const YY &yy) noexcept
Compute the result of the operation using the GPU.
Definition: equal.hpp:65
EGBLAS wrappers for the equal operation.
Root namespace for the ETL library.
Definition: adapter.hpp:15
static constexpr bool thread_safe
Indicates if the operator is thread safe or not.
Definition: equal.hpp:20
Binary operator for element wise equality.
Definition: equal.hpp:18
static constexpr bool linear
Indicates if the operator is linear or not.
Definition: equal.hpp:19
static constexpr int complexity()
Estimate the complexity of operator.
Definition: equal.hpp:43
constexpr size_t size(const E &expr) noexcept
Returns the size of the given ETL expression.
Definition: helpers.hpp:108
static std::string desc() noexcept
Returns a textual representation of the operator.
Definition: equal.hpp:105
decltype(auto) smart_gpu_compute_hint(E &expr, Y &y)
Compute the expression into a representation that is GPU up to date.
Definition: helpers.hpp:368
static constexpr bool gpu_computable
Indicates if the operator can be computed on GPU.
Definition: equal.hpp:35
static constexpr bool desc_func
Indicates if the description must be printed as function.
Definition: equal.hpp:21