Expression Templates Library (ETL)
plus.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 namespace etl {
11 
16 template <typename T>
17 struct plus_unary_op {
21  template <typename V = default_vec>
22  using vec_type = typename V::template vec_type<T>;
23 
24  static constexpr bool linear = true;
25  static constexpr bool thread_safe = true;
26 
32  template <vector_mode_t V>
33  static constexpr bool vectorizable = true;
34 
38  template <typename E>
39  static constexpr bool gpu_computable = cuda_enabled && !is_scalar<E>;
40 
45  static constexpr int complexity() {
46  return 1;
47  }
48 
54  static constexpr T apply(const T& x) noexcept {
55  return +x;
56  }
57 
64  template <typename V = default_vec>
65  static vec_type<V> load(const vec_type<V>& x) noexcept {
66  return x;
67  }
68 
76  template <typename X, typename Y>
77  static auto gpu_compute_hint(const X& x, Y& y) noexcept {
78  decltype(auto) t1 = smart_gpu_compute_hint(x, y);
79 
81  }
88  template <typename X, typename Y>
89  static Y& gpu_compute(const X& x, Y& y) noexcept {
90  return smart_gpu_compute(x, y);
91  }
92 
97  static std::string desc() noexcept {
98  return "+";
99  }
100 };
101 
102 } //end of namespace etl
static constexpr bool linear
Indicates if the operator is linear.
Definition: plus.hpp:24
Unary operation computing the plus operation.
Definition: plus.hpp:17
static std::string desc() noexcept
Returns a textual representation of the operator.
Definition: plus.hpp:97
static constexpr bool thread_safe
Indicates if the operator is thread safe or not.
Definition: plus.hpp:25
constexpr bool cuda_enabled
Indicates if CUDA is available.
Definition: config.hpp:94
static Y & gpu_compute(const X &x, Y &y) noexcept
Compute the result of the operation using the GPU.
Definition: plus.hpp:89
static constexpr bool vectorizable
Indicates if the expression is vectorizable using the given vector mode.
Definition: plus.hpp:33
static constexpr T apply(const T &x) noexcept
Apply the unary operator on x.
Definition: plus.hpp:54
static constexpr int complexity()
Estimate the complexity of operator.
Definition: plus.hpp:45
Root namespace for the ETL library.
Definition: adapter.hpp:15
typename V::template vec_type< T > vec_type
Definition: plus.hpp:22
static vec_type< V > load(const vec_type< V > &x) noexcept
Compute several applications of the operator at a time.
Definition: plus.hpp:65
decltype(auto) force_temporary_gpu_dim_only(E &&expr)
Force a temporary out of the expression, without copying its content.
Definition: temporary.hpp:223
static auto gpu_compute_hint(const X &x, Y &y) noexcept
Compute the result of the operation using the GPU.
Definition: plus.hpp:77
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
decltype(auto) smart_gpu_compute(X &x, Y &y)
Compute the expression into a representation that is GPU up to date and store this representation in ...
Definition: helpers.hpp:397
static constexpr bool gpu_computable
Indicates if the operator can be computed on GPU.
Definition: plus.hpp:39