10 #include "etl/expr/base_temporary_expr.hpp" 20 template <etl_2d A, etl_1d B>
34 (impl::egblas::has_sbias_batch_var && all_row_major<A> && all_single_precision<A>)
35 || (impl::egblas::has_dbias_batch_var && all_row_major<A> && all_double_precision<A>);
51 static void check([[maybe_unused]]
const A&
a, [[maybe_unused]]
const B&
b, [[maybe_unused]]
const C& c) {
52 if constexpr (all_fast<A, B, C>) {
53 static_assert(etl::dim<1, A>() == etl::dim<0, C>(),
"Invalid dimensions for bias_batch_var_2d");
54 static_assert(etl::dim<0, B>() == etl::dim<0, C>(),
"Invalid dimensions for bias_batch_var_2d");
56 cpp_assert(etl::dim<1>(a) == etl::dim<0>(c),
"Invalid dimensions for bias_batch_var_2d");
57 cpp_assert(etl::dim<0>(b) == etl::dim<0>(c),
"Invalid dimensions for bias_batch_var_2d");
78 const auto N = etl::dim<0>(
a);
79 const auto K = etl::dim<1>(
a);
81 if constexpr (impl::egblas::has_sbias_batch_var && all_row_major<A> && all_floating<A, L>) {
85 t1.ensure_gpu_up_to_date();
86 t2.ensure_gpu_up_to_date();
88 lhs.ensure_gpu_allocated();
90 impl::egblas::bias_batch_var(N, K, t1.gpu_memory(), 1, t2.gpu_memory(), 1, lhs.gpu_memory(), 1);
95 standard_evaluator::pre_assign_rhs(
a);
96 standard_evaluator::pre_assign_rhs(
b);
98 auto batch_fun_k = [&](
const size_t first,
const size_t last) {
99 for (
size_t k = first; k < last; ++k) {
102 for (
size_t bb = 0; bb < N; ++bb) {
103 mean += (
a(bb, k) -
b(k)) * (
a(bb, k) -
b(k));
113 lhs.invalidate_gpu();
121 template <etl_expr L>
126 standard_evaluator::pre_assign_rhs(
a);
127 standard_evaluator::pre_assign_rhs(
b);
136 auto batch_fun_k = [&](
const size_t first,
const size_t last) {
137 for (
size_t k = first; k < last; ++k) {
140 for (
size_t bb = 0; bb < N; ++bb) {
141 mean += (
a(bb, k) -
b(k)) * (
a(bb, k) -
b(k));
144 lhs(k) += mean /
static_cast<T
>(N);
155 template <etl_expr L>
160 standard_evaluator::pre_assign_rhs(
a);
161 standard_evaluator::pre_assign_rhs(
b);
170 auto batch_fun_k = [&](
const size_t first,
const size_t last) {
171 for (
size_t k = first; k < last; ++k) {
174 for (
size_t bb = 0; bb < N; ++bb) {
175 mean += (
a(bb, k) -
b(k)) * (
a(bb, k) -
b(k));
178 lhs(k) -= mean /
static_cast<T
>(N);
189 template <etl_expr L>
194 standard_evaluator::pre_assign_rhs(
a);
195 standard_evaluator::pre_assign_rhs(
b);
204 auto batch_fun_k = [&](
const size_t first,
const size_t last) {
205 for (
size_t k = first; k < last; ++k) {
208 for (
size_t bb = 0; bb < N; ++bb) {
209 mean += (
a(bb, k) -
b(k)) * (
a(bb, k) -
b(k));
212 lhs(k) *= mean /
static_cast<T
>(N);
223 template <etl_expr L>
228 standard_evaluator::pre_assign_rhs(
a);
229 standard_evaluator::pre_assign_rhs(
b);
238 auto batch_fun_k = [&](
const size_t first,
const size_t last) {
239 for (
size_t k = first; k < last; ++k) {
242 for (
size_t bb = 0; bb < N; ++bb) {
243 mean += (
a(bb, k) -
b(k)) * (
a(bb, k) -
b(k));
246 lhs(k) /= mean /
static_cast<T
>(N);
257 template <etl_expr L>
262 standard_evaluator::pre_assign_rhs(
a);
263 standard_evaluator::pre_assign_rhs(
b);
272 auto batch_fun_k = [&](
const size_t first,
const size_t last) {
273 for (
size_t k = first; k < last; ++k) {
276 for (
size_t bb = 0; bb < N; ++bb) {
277 mean += (
a(bb, k) -
b(k)) * (
a(bb, k) -
b(k));
280 lhs(k) %= mean /
static_cast<T
>(N);
294 return os <<
"bias_batch_var_2d(" << expr.
_a <<
")";
302 template <etl_2d A, etl_1d B>
309 static constexpr
bool is_etl =
true;
314 static constexpr
bool is_linear =
false;
316 static constexpr
bool is_value =
false;
317 static constexpr
bool is_direct =
true;
318 static constexpr
bool is_generator =
false;
319 static constexpr
bool is_padded =
false;
320 static constexpr
bool is_aligned =
true;
321 static constexpr
bool is_temporary =
true;
322 static constexpr
order storage_order = sub_traits::storage_order;
323 static constexpr
bool gpu_computable = is_gpu_t<value_type> &&
cuda_enabled;
330 template <vector_mode_t V>
331 static constexpr
bool vectorizable =
true;
348 static size_t dim(
const expr_t& e, [[maybe_unused]]
size_t d) {
349 cpp_assert(d == 0,
"Invalid dimensions access");
350 return etl::dim<1>(e.
_a);
358 static size_t size(
const expr_t& e) {
359 return etl::dim<1>(e.
_a);
366 static constexpr
size_t size() {
374 static constexpr
size_t dimensions() {
392 template <etl_2d A, etl_1d B>
value_t< E > mean(E &&values)
Returns the mean of all the values contained in the given expression.
Definition: expression_builder.hpp:650
constexpr int complexity([[maybe_unused]] const E &expr) noexcept
Return the complexity of the expression.
Definition: helpers.hpp:38
void engine_dispatch_1d_serial(Functor &&functor, size_t first, size_t last, size_t threshold, [[maybe_unused]] size_t n_threads=etl::threads)
Dispatch the elements of a range to a functor in a parallel manner, using the global thread engine...
Definition: parallel_support.hpp:734
constexpr bool is_magic_view
Traits indicating if the given ETL type is a magic view expression.
Definition: traits.hpp:311
A _a
The sub expression reference.
Definition: base_temporary_expr.hpp:533
void assign_add_to(L &&lhs) const
Add to the given left-hand-side expression.
Definition: bias_batch_var_2d_expr.hpp:122
order
Storage order of a matrix.
Definition: order.hpp:15
void assign_mul_to(L &&lhs) const
Multiply the given left-hand-side expression.
Definition: bias_batch_var_2d_expr.hpp:190
friend std::ostream & operator<<(std::ostream &os, const bias_batch_var_2d_expr &expr)
Print a representation of the expression on the given stream.
Definition: bias_batch_var_2d_expr.hpp:293
constexpr bool cuda_enabled
Indicates if CUDA is available.
Definition: config.hpp:94
static constexpr bool gpu_computable
Indicates if the temporary expression can be directly evaluated using only GPU.
Definition: bias_batch_var_2d_expr.hpp:33
EGBLAS wrappers for the bias_batch_sum operation.
Abstract base class for temporary binary expression.
Definition: base_temporary_expr.hpp:529
std::add_lvalue_reference_t< B > b()
Returns the sub expression.
Definition: base_temporary_expr.hpp:593
constexpr bool is_fast
Traits to test if the given ETL expresion type is fast (sizes known at compile-time) ...
Definition: traits.hpp:588
value_t< A > value_type
The type of value of the expression.
Definition: bias_batch_var_2d_expr.hpp:22
Traits to get information about ETL types.
Definition: tmp.hpp:68
Root namespace for the ETL library.
Definition: adapter.hpp:15
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
std::conditional_t< is_etl_value< T >, const std::decay_t< T > &, std::decay_t< T > > build_type
Helper to build the type for a sub expression.
Definition: expression_helpers.hpp:24
static void check([[maybe_unused]] const A &a, [[maybe_unused]] const B &b, [[maybe_unused]] const C &c)
Validate the transposition dimensions.
Definition: bias_batch_var_2d_expr.hpp:51
bias_batch_var_2d_expr(A a, B b)
Construct a new expression.
Definition: bias_batch_var_2d_expr.hpp:41
std::decay_t< A > sub_expr_t
The sub expression type.
Definition: bias_batch_var_2d_expr.hpp:305
bias_batch_var_2d_expr< detail::build_type< A >, detail::build_type< B > > bias_batch_var_2d(const A &a, const B &b)
Returns the transpose of the given expression.
Definition: bias_batch_var_2d_expr.hpp:393
void assign_mod_to(L &&lhs) const
Modulo the given left-hand-side expression.
Definition: bias_batch_var_2d_expr.hpp:258
constexpr bool is_transformer
Traits indicating if the given ETL type is a transformer expression.
Definition: traits.hpp:297
void assign_to(L &&lhs) const
Assign to a matrix of the same storage order.
Definition: bias_batch_var_2d_expr.hpp:68
decltype(auto) smart_forward_gpu(E &expr)
Smart forwarding for a temporary expression that will be computed in GPU.
Definition: helpers.hpp:343
void assign_div_to(L &&lhs) const
Divide the given left-hand-side expression.
Definition: bias_batch_var_2d_expr.hpp:224
constexpr size_t size(const E &expr) noexcept
Returns the size of the given ETL expression.
Definition: helpers.hpp:108
requires(D > 0) struct dyn_base
Matrix with run-time fixed dimensions.
Definition: dyn_base.hpp:113
constexpr bool is_view
Traits indicating if the given ETL type is a view expression.
Definition: traits.hpp:304
void assign_sub_to(L &&lhs) const
Sub from the given left-hand-side expression.
Definition: bias_batch_var_2d_expr.hpp:156
static constexpr bool is_fast
Indicates if T is a fast structure.
Definition: traits_base.hpp:25
static constexpr auto storage_order
The sub storage order.
Definition: bias_batch_var_2d_expr.hpp:27
constexpr bool is_thread_safe
Traits to test if the given ETL expresion type is thread safe.
Definition: traits.hpp:687
A transposition expression.
Definition: bias_batch_var_2d_expr.hpp:21
typename decay_traits< E >::value_type value_t
Traits to extract the value type out of an ETL type.
Definition: tmp.hpp:81
void inc_counter([[maybe_unused]] const char *name)
Increase the given counter.
Definition: counters.hpp:25
std::add_lvalue_reference_t< A > a()
Returns the sub expression.
Definition: base_temporary_expr.hpp:577
value_t< A > value_type
The value type of the expression.
Definition: bias_batch_var_2d_expr.hpp:307