Expression Templates Library (ETL)
logical_xor.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 
10 #include "etl/impl/egblas/xor.hpp"
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 = impl::egblas::has_bxor;
36 
41  static constexpr int complexity() {
42  return 1;
43  }
44 
51  static constexpr bool apply(const T& lhs, const T& rhs) noexcept {
52  return lhs != rhs;
53  }
54 
62  template <typename X, typename Y, typename YY>
63  static auto gpu_compute_hint(const X& x, const Y& y, YY& yy) noexcept {
64  decltype(auto) t1 = smart_gpu_compute_hint(x, yy);
65  decltype(auto) t2 = smart_gpu_compute_hint(y, yy);
66 
67  auto t3 = force_temporary_gpu_dim_only_t<bool>(t1);
68 
69  impl::egblas::logical_xor(etl::size(yy), t1.gpu_memory(), 1, t2.gpu_memory(), 1, t3.gpu_memory(), 1);
70 
71  return t3;
72  }
73 
80  template <typename X, typename Y, typename YY>
81  static YY& gpu_compute(const X& x, const Y& y, YY& yy) noexcept {
82  decltype(auto) t1 = smart_gpu_compute_hint(x, yy);
83  decltype(auto) t2 = smart_gpu_compute_hint(y, yy);
84 
85  impl::egblas::logical_xor(etl::size(yy), t1.gpu_memory(), 1, t2.gpu_memory(), 1, yy.gpu_memory(), 1);
86 
87  yy.validate_gpu();
88  yy.invalidate_cpu();
89 
90  return yy;
91  }
92 
97  static std::string desc() noexcept {
98  return "^";
99  }
100 };
101 
102 } //end of namespace etl
EGBLAS wrappers for the xor operation.
static std::string desc() noexcept
Returns a textual representation of the operator.
Definition: logical_xor.hpp:97
Binary operator for elementwise logical XOR computation.
Definition: logical_xor.hpp:18
static constexpr bool desc_func
Indicates if the description must be printed as function.
Definition: logical_xor.hpp:21
static constexpr int complexity()
Estimate the complexity of operator.
Definition: logical_xor.hpp:41
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: logical_xor.hpp:20
static constexpr bool gpu_computable
Indicates if the operator can be computed on GPU.
Definition: logical_xor.hpp:35
static YY & gpu_compute(const X &x, const Y &y, YY &yy) noexcept
Compute the result of the operation using the GPU.
Definition: logical_xor.hpp:81
constexpr size_t size(const E &expr) noexcept
Returns the size of the given ETL expression.
Definition: helpers.hpp:108
static constexpr bool apply(const T &lhs, const T &rhs) noexcept
Apply the unary operator on lhs and rhs.
Definition: logical_xor.hpp:51
static auto gpu_compute_hint(const X &x, const Y &y, YY &yy) noexcept
Compute the result of the operation using the GPU.
Definition: logical_xor.hpp:63
static constexpr bool vectorizable
Indicates if the expression is vectorizable using the given vector mode.
Definition: logical_xor.hpp:29
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 linear
Indicates if the operator is linear or not.
Definition: logical_xor.hpp:19
auto logical_xor(LE &&lhs, RE &&rhs)
Builds an expression representing the elementwise logical xor of lhs and rhs.
Definition: binary_expression_builder.hpp:496