Expression Templates Library (ETL)
less_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_sless_equal)
36  || (all_double_precision<L, R> && impl::egblas::has_dless_equal)
37  || (all_complex_single_precision<L, R> && impl::egblas::has_cless_equal)
38  || (all_complex_double_precision<L, R> && impl::egblas::has_zless_equal);
39 
44  static constexpr int complexity() {
45  return 1;
46  }
47 
54  static constexpr bool apply(const T& lhs, const T& rhs) noexcept {
55  return lhs <= rhs;
56  }
57 
65  template <typename X, typename Y, typename YY>
66  static auto gpu_compute_hint(const X& x, const Y& y, YY& yy) noexcept {
67  decltype(auto) t1 = smart_gpu_compute_hint(x, yy);
68  decltype(auto) t2 = smart_gpu_compute_hint(y, yy);
69 
70  auto t3 = force_temporary_gpu_dim_only_t<bool>(t1);
71 
72  constexpr size_t inca = gpu_inc<decltype(x)>;
73  constexpr size_t incb = gpu_inc<decltype(y)>;
74 
75  impl::egblas::less_equal(etl::size(yy), t1.gpu_memory(), inca, t2.gpu_memory(), incb, t3.gpu_memory(), 1);
76 
77  return t3;
78  }
79 
86  template <typename X, typename Y, typename YY>
87  static YY& gpu_compute(const X& x, const Y& y, YY& yy) noexcept {
88  decltype(auto) t1 = smart_gpu_compute_hint(x, yy);
89  decltype(auto) t2 = smart_gpu_compute_hint(y, yy);
90 
91  constexpr size_t inca = gpu_inc<decltype(x)>;
92  constexpr size_t incb = gpu_inc<decltype(y)>;
93 
94  impl::egblas::less_equal(etl::size(yy), t1.gpu_memory(), inca, t2.gpu_memory(), incb, yy.gpu_memory(), 1);
95 
96  yy.validate_gpu();
97  yy.invalidate_cpu();
98 
99  return yy;
100  }
101 
106  static std::string desc() noexcept {
107  return "<";
108  }
109 };
110 
111 } //end of namespace etl
static std::string desc() noexcept
Returns a textual representation of the operator.
Definition: less_equal.hpp:106
static constexpr bool apply(const T &lhs, const T &rhs) noexcept
Apply the unary operator on lhs and rhs.
Definition: less_equal.hpp:54
EGBLAS wrappers for the less_equal operation.
static auto gpu_compute_hint(const X &x, const Y &y, YY &yy) noexcept
Compute the result of the operation using the GPU.
Definition: less_equal.hpp:66
static constexpr bool vectorizable
Indicates if the expression is vectorizable using the given vector mode.
Definition: less_equal.hpp:29
static constexpr int complexity()
Estimate the complexity of operator.
Definition: less_equal.hpp:44
static YY & gpu_compute(const X &x, const Y &y, YY &yy) noexcept
Compute the result of the operation using the GPU.
Definition: less_equal.hpp:87
static constexpr bool thread_safe
Indicates if the operator is thread safe or not.
Definition: less_equal.hpp:20
Root namespace for the ETL library.
Definition: adapter.hpp:15
static constexpr bool gpu_computable
Indicates if the operator can be computed on GPU.
Definition: less_equal.hpp:35
Binary operator for element less than or equal comparison.
Definition: less_equal.hpp:18
constexpr size_t size(const E &expr) noexcept
Returns the size of the given ETL expression.
Definition: helpers.hpp:108
static constexpr bool linear
Indicates if the operator is linear or not.
Definition: less_equal.hpp:19
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 desc_func
Indicates if the description must be printed as function.
Definition: less_equal.hpp:21