10 #include "etl/expr/base_temporary_expr.hpp" 19 template <
typename A,
bool Stable>
41 template <same_dimensions_and_order<A> C>
42 static void check([[maybe_unused]]
const A&
a, [[maybe_unused]]
const C& c) {
43 if constexpr (all_fast<A, C>) {
59 if (
cudnn_enabled && all_homogeneous<A, C> && all_floating<A, C> && !no_gpu) {
66 #ifdef ETL_MANUAL_SELECT 83 return select_default_impl<C>(
false);
99 standard_evaluator::pre_assign_rhs(
a);
103 constexpr_select
auto impl = select_impl<C>();
110 if constexpr (Stable) {
118 if constexpr (Stable) {
119 for (
size_t i = 0; i < etl::dim<0>(c); ++i) {
124 for (
size_t i = 0; i < etl::dim<0>(c); ++i) {
129 cpp_unreachable(
"Invalid selection for batch_softmax");
140 template <
typename L>
149 template <
typename L>
158 template <
typename L>
167 template <
typename L>
176 template <
typename L>
188 return os <<
"batch_softmax(" << expr.
_a <<
")";
196 template <
typename A,
bool Stable>
203 static constexpr
bool is_etl =
true;
208 static constexpr
bool is_linear =
true;
210 static constexpr
bool is_value =
false;
211 static constexpr
bool is_direct =
true;
212 static constexpr
bool is_generator =
false;
213 static constexpr
bool is_padded =
false;
214 static constexpr
bool is_aligned =
true;
215 static constexpr
bool is_temporary =
true;
216 static constexpr
bool gpu_computable = is_gpu_t<value_type> &&
cuda_enabled;
224 template <vector_mode_t V>
232 static constexpr
size_t dim() {
259 static constexpr
size_t size() {
value_t< A > value_type
The value type of the expression.
Definition: batch_softmax_expr.hpp:201
static constexpr batch_softmax_impl select_impl()
Select the best possible implementation for the batch softmax operation.
Definition: batch_softmax_expr.hpp:82
batch_softmax_impl
Enumeration describing the different implementations of CCE.
Definition: batch_softmax_impl.hpp:20
std::add_lvalue_reference_t< A > a()
Returns the sub expression.
Definition: base_temporary_expr.hpp:489
auto max(L &&lhs, R &&rhs)
Create an expression with the max value of lhs or rhs.
Definition: expression_builder.hpp:65
void std_assign_evaluate(Expr &&expr, Result &&result)
Evaluation of the expr into result.
Definition: evaluator.hpp:1176
void assign_mul_to(L &&lhs) const
Multiply the given left-hand-side expression.
Definition: batch_softmax_expr.hpp:159
static size_t dim(const expr_t &e, size_t d)
Returns the dth dimension of the expression.
Definition: batch_softmax_expr.hpp:242
constexpr bool is_magic_view
Traits indicating if the given ETL type is a magic view expression.
Definition: traits.hpp:311
auto softmax(E &&e)
Return the softmax function of the given ETL expression.
Definition: function_expression_builder.hpp:253
static constexpr auto storage_order
The sub storage order.
Definition: batch_softmax_expr.hpp:26
static constexpr batch_softmax_impl select_default_impl(bool no_gpu)
Select the best possible implementation for the batch softmax operation.
Definition: batch_softmax_expr.hpp:58
order
Storage order of a matrix.
Definition: order.hpp:15
static void check([[maybe_unused]] const A &a, [[maybe_unused]] const C &c)
Validate the function dimensions.
Definition: batch_softmax_expr.hpp:42
constexpr bool cuda_enabled
Indicates if CUDA is available.
Definition: config.hpp:94
static constexpr size_t dim()
Returns the DDth dimension of the expression.
Definition: batch_softmax_expr.hpp:232
static constexpr size_t size()
Returns the size of the expression.
Definition: batch_softmax_expr.hpp:259
A _a
The sub expression reference.
Definition: base_temporary_expr.hpp:447
constexpr bool is_fast
Traits to test if the given ETL expresion type is fast (sizes known at compile-time) ...
Definition: traits.hpp:588
std::true_type vectorizable
Indicates if the expression is vectorizable using the given vector mode.
Definition: batch_softmax_expr.hpp:225
Traits to get information about ETL types.
Definition: tmp.hpp:68
Root namespace for the ETL library.
Definition: adapter.hpp:15
context & local_context()
Return the configuration context of the current thread.
Definition: context.hpp:50
static constexpr size_t dimensions()
Return the number of dimensions of the expression.
Definition: traits_base.hpp:31
auto dim(E &&value, size_t i) -> detail::identity_helper< E, dim_view< detail::build_identity_type< E >, D >>
Return a view representing the ith Dth dimension.
Definition: view_expression_builder.hpp:25
static constexpr size_t dimensions()
Returns the number of dimensions of the expression.
Definition: batch_softmax_expr.hpp:267
constexpr bool cudnn_enabled
Indicates if the NVIDIA CUDNN library is available for ETL.
Definition: config.hpp:114
bool cpu
Force CPU evaluation.
Definition: context.hpp:29
friend std::ostream & operator<<(std::ostream &os, const batch_softmax_expr &expr)
Print a representation of the expression on the given stream.
Definition: batch_softmax_expr.hpp:187
value_t< A > value_type
The type of value of the expression.
Definition: batch_softmax_expr.hpp:21
void std_mod_evaluate(Expr &&expr, Result &&result)
Compound modulo evaluation of the expr into result.
Definition: evaluator.hpp:1271
void std_mul_evaluate(Expr &&expr, Result &&result)
Compound multiply evaluation of the expr into result.
Definition: evaluator.hpp:1233
constexpr bool is_transformer
Traits indicating if the given ETL type is a transformer expression.
Definition: traits.hpp:297
value_t< E > sum(E &&values)
Returns the sum of all the values contained in the given expression.
Definition: expression_builder.hpp:624
decltype(auto) smart_forward_gpu(E &expr)
Smart forwarding for a temporary expression that will be computed in GPU.
Definition: helpers.hpp:343
constexpr size_t size(const E &expr) noexcept
Returns the size of the given ETL expression.
Definition: helpers.hpp:108
void assign_mod_to(L &&lhs) const
Modulo the given left-hand-side expression.
Definition: batch_softmax_expr.hpp:177
constexpr bool is_view
Traits indicating if the given ETL type is a view expression.
Definition: traits.hpp:304
auto exp(E &&value) -> detail::unary_helper< E, exp_unary_op >
Apply exponential on each value of the given expression.
Definition: function_expression_builder.hpp:154
static constexpr int complexity() noexcept
Estimate the complexity of computation.
Definition: batch_softmax_expr.hpp:275
static constexpr bool is_fast
Indicates if T is a fast structure.
Definition: traits_base.hpp:25
void assign_to(C &&c) const
Assign to a matrix of the same storage order.
Definition: batch_softmax_expr.hpp:93
auto stable_softmax(E &&e)
Returns the softmax function of the given ETL expression. This version is implemented so that numeric...
Definition: function_expression_builder.hpp:268
static size_t size(const expr_t &e)
Returns the size of the expression.
Definition: batch_softmax_expr.hpp:251
void std_sub_evaluate(Expr &&expr, Result &&result)
Compound subtract evaluation of the expr into result.
Definition: evaluator.hpp:1214
Abstract base class for temporary unary expression.
Definition: base_temporary_expr.hpp:443
constexpr bool is_thread_safe
Traits to test if the given ETL expresion type is thread safe.
Definition: traits.hpp:687
std::decay_t< A > sub_expr_t
The sub expression type.
Definition: batch_softmax_expr.hpp:199
A batch softmax function expression.
Definition: batch_softmax_expr.hpp:20
void assign_div_to(L &&lhs) const
Divide the given left-hand-side expression.
Definition: batch_softmax_expr.hpp:168
typename decay_traits< E >::value_type value_t
Traits to extract the value type out of an ETL type.
Definition: tmp.hpp:81
void std_div_evaluate(Expr &&expr, Result &&result)
Compound divide evaluation of the expr into result.
Definition: evaluator.hpp:1252
void inc_counter([[maybe_unused]] const char *name)
Increase the given counter.
Definition: counters.hpp:25
void std_add_evaluate(Expr &&expr, Result &&result)
Compound add evaluation of the expr into result.
Definition: evaluator.hpp:1195
void assign_add_to(L &&lhs) const
Add to the given left-hand-side expression.
Definition: batch_softmax_expr.hpp:141
batch_softmax_expr(A a)
Construct a new expression.
Definition: batch_softmax_expr.hpp:32
void assign_sub_to(L &&lhs) const
Sub from the given left-hand-side expression.
Definition: batch_softmax_expr.hpp:150