10 #include "etl/expr/base_temporary_expr.hpp" 13 #include "etl/impl/std/gemm.hpp" 14 #include "etl/impl/std/strassen_mmul.hpp" 15 #include "etl/impl/blas/gemm.hpp" 16 #include "etl/impl/vec/gemm.hpp" 17 #include "etl/impl/vec/gemm_conv.hpp" 18 #include "etl/impl/cublas/gemm.hpp" 26 template <etl_expr A, etl_expr B,
bool Strassen>
66 static void check([[maybe_unused]]
const A&
a, [[maybe_unused]]
const B&
b, [[maybe_unused]]
const C& c) {
67 if constexpr (all_fast<A, B, C>) {
68 static_assert(dim<1, A>() == dim<0, B>()
69 && dim<0, A>() == dim<0, C>()
70 && dim<1, B>() == dim<1, C>(),
71 "Invalid sizes for multiplication");
73 cpp_assert(dim<1>(a) == dim<0>(b)
74 && dim<0>(a) == dim<0>(c)
75 && dim<1>(b) == dim<1>(c),
76 "Invalid sizes for multiplication");
86 template <
typename AA,
typename BB,
typename C>
91 constexpr
bool homo = all_homogeneous<AA, BB, C>;
93 if (cublas && homo && !no_gpu) {
95 }
else if (blas && homo) {
106 #ifdef ETL_MANUAL_SELECT 112 template <
typename AA,
typename BB,
typename C>
123 std::cerr <<
"Forced selection to CUBLAS gemm implementation, but not possible for this expression" 133 std::cerr <<
"Forced selection to BLAS gemm implementation, but not possible for this expression" << std::endl;
142 std::cerr <<
"Forced selection to VEC gemm implementation, but not possible for this expression" << std::endl;
164 template <
typename AA,
typename BB,
typename C>
166 return select_default_gemm_impl<AA, BB, C>(
false);
177 template <
typename AA,
typename BB,
typename C>
179 constexpr_select
auto impl = select_gemm_impl<AA, BB, C>();
183 if constexpr (is_transpose_expr<AA>&& is_transpose_expr<BB>) {
197 cpp_unreachable(
"invalid selection of gemm");
199 }
else if constexpr (!is_transpose_expr<AA> && is_transpose_expr<BB>) {
213 cpp_unreachable(
"Invalid selection of gemm");
215 }
else if constexpr (is_transpose_expr<AA> && !is_transpose_expr<BB>) {
229 cpp_unreachable(
"Invalid selection of gemm");
245 cpp_unreachable(
"Invalid selection of gemm");
256 template <etl_expr C>
265 if constexpr (!Strassen) {
276 template <etl_expr L>
285 template <etl_expr L>
294 template <etl_expr L>
303 template <etl_expr L>
312 template <etl_expr L>
324 return os << expr.
_a <<
" * " << expr.
_b;
332 template <
typename A,
typename B,
bool Strassen>
341 static constexpr
bool is_etl =
true;
346 static constexpr
bool is_linear =
false;
348 static constexpr
bool is_value =
false;
349 static constexpr
bool is_direct =
true;
350 static constexpr
bool is_generator =
false;
351 static constexpr
bool is_padded =
false;
352 static constexpr
bool is_aligned =
true;
353 static constexpr
bool is_temporary =
true;
362 template <vector_mode_t V>
363 static constexpr
bool vectorizable =
true;
370 static constexpr
size_t dim() {
401 static constexpr
size_t size() {
430 template <etl_2d A, etl_2d B>
441 template <etl_2d A, etl_2d B>
454 template <etl_2d A, etl_2d B>
465 template <etl_2d A, etl_2d B>
479 template <etl_2d A, etl_2d B, etl_2d C>
493 template <etl_2d A, etl_2d B>
505 template <etl_2d A, etl_2d B, etl_2d C>
void assign_to(C &&c) const
Assign to a matrix of the same storage order.
Definition: gemm_expr.hpp:257
A transposition expression.
Definition: gemm_expr.hpp:27
gemm_impl
Enumeration describing the different matrix-matrix multiplication implementations.
Definition: gemm_impl.hpp:21
B _b
The sub expression reference.
Definition: base_temporary_expr.hpp:534
auto mul(A &&a, B &&b)
Multiply two matrices together.
Definition: gemm_expr.hpp:442
static constexpr size_t dim()
Returns the DDth dimension of the expression.
Definition: gemm_expr.hpp:370
void assign_mul_to(L &&lhs) const
Multiply the given left-hand-side expression.
Definition: gemm_expr.hpp:295
constexpr bool is_magic_view
Traits indicating if the given ETL type is a magic view expression.
Definition: traits.hpp:311
static constexpr size_t dimensions()
Returns the number of dimensions of the expression.
Definition: gemm_expr.hpp:409
void assign_mod_to(L &&lhs) const
Modulo the given left-hand-side expression.
Definition: gemm_expr.hpp:313
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: gemm_expr.hpp:277
static size_t size(const expr_t &e)
Returns the size of the expression.
Definition: gemm_expr.hpp:393
auto strassen_mul(A &&a, B &&b)
Multiply two matrices together using strassen.
Definition: gemm_expr.hpp:494
constexpr bool vectorize_impl
Indicates if the implementations can be automatically vectorized by ETL.
Definition: config.hpp:35
constexpr bool vec_enabled
Indicates if vectorization is available in any format.
Definition: config.hpp:220
order
Storage order of a matrix.
Definition: order.hpp:15
constexpr bool cuda_enabled
Indicates if CUDA is available.
Definition: config.hpp:94
static constexpr auto storage_order
The sub storage order.
Definition: gemm_expr.hpp:33
Abstract base class for temporary binary expression.
Definition: base_temporary_expr.hpp:529
auto operator*(LE &&lhs, RE rhs)
Builds an expression representing the multiplication of lhs and rhs (scalar)
Definition: binary_expression_builder.hpp:149
static constexpr gemm_impl select_gemm_impl()
Select the best implementation of GEMM.
Definition: gemm_expr.hpp:165
std::add_lvalue_reference_t< B > b()
Returns the sub expression.
Definition: base_temporary_expr.hpp:593
void apply_raw(AA &&a, BB &&b, C &&c) const
Compute C = trans(A) * trans(B)
Definition: gemm_expr.hpp:178
static void check([[maybe_unused]] const A &a, [[maybe_unused]] const B &b, [[maybe_unused]] const C &c)
Assert for the validity of the matrix-matrix multiplication operation.
Definition: gemm_expr.hpp:66
constexpr bool is_fast
Traits to test if the given ETL expresion type is fast (sizes known at compile-time) ...
Definition: traits.hpp:588
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
value_t< A > value_type
The value type of the expression.
Definition: gemm_expr.hpp:339
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
void assign_div_to(L &&lhs) const
Divide the given left-hand-side expression.
Definition: gemm_expr.hpp:304
gemm_expr(A a, B b)
Construct a new expression.
Definition: gemm_expr.hpp:47
constexpr bool cublas_enabled
Indicates if the NVIDIA CUBLAS library is available for ETL.
Definition: config.hpp:99
gemm_expr(A a, B b, value_type alpha)
Construct a new expression.
Definition: gemm_expr.hpp:55
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
bool cpu
Force CPU evaluation.
Definition: context.hpp:29
static constexpr size_t size()
Returns the size of the expression.
Definition: gemm_expr.hpp:401
void std_mod_evaluate(Expr &&expr, Result &&result)
Compound modulo evaluation of the expr into result.
Definition: evaluator.hpp:1271
void assign_sub_to(L &&lhs) const
Sub from the given left-hand-side expression.
Definition: gemm_expr.hpp:286
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
std::decay_t< A > left_expr_t
The left sub expression type.
Definition: gemm_expr.hpp:335
decltype(auto) smart_forward_gpu(E &expr)
Smart forwarding for a temporary expression that will be computed in GPU.
Definition: helpers.hpp:343
static constexpr int complexity() noexcept
Estimate the complexity of computation.
Definition: gemm_expr.hpp:417
constexpr bool is_view
Traits indicating if the given ETL type is a view expression.
Definition: traits.hpp:304
std::decay_t< B > right_expr_t
The right sub expression type.
Definition: gemm_expr.hpp:336
value_t< A > value_type
The type of value of the expression.
Definition: gemm_expr.hpp:28
static constexpr bool is_fast
Indicates if T is a fast structure.
Definition: traits_base.hpp:25
friend std::ostream & operator<<(std::ostream &os, const gemm_expr &expr)
Print a representation of the expression on the given stream.
Definition: gemm_expr.hpp:323
void std_sub_evaluate(Expr &&expr, Result &&result)
Compound subtract evaluation of the expr into result.
Definition: evaluator.hpp:1214
decltype(auto) smart_forward(E &expr)
Smart forwarding for a temporary expression.
Definition: helpers.hpp:323
constexpr bool cblas_enabled
Indicates if a BLAS library is available for ETL.
Definition: config.hpp:76
constexpr bool is_thread_safe
Traits to test if the given ETL expresion type is thread safe.
Definition: traits.hpp:687
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
static constexpr bool gpu_computable
Indicates if the temporary expression can be directly evaluated using only GPU.
Definition: gemm_expr.hpp:39
void inc_counter([[maybe_unused]] const char *name)
Increase the given counter.
Definition: counters.hpp:25
static constexpr gemm_impl select_default_gemm_impl(bool no_gpu)
Select an implementation of GEMM, not considering local context.
Definition: gemm_expr.hpp:87
std::add_lvalue_reference_t< A > a()
Returns the sub expression.
Definition: base_temporary_expr.hpp:577
const value_type alpha
The alpha multiplicator.
Definition: gemm_expr.hpp:41
static size_t dim(const expr_t &e, size_t d)
Returns the dth dimension of the expression.
Definition: gemm_expr.hpp:380
void std_add_evaluate(Expr &&expr, Result &&result)
Compound add evaluation of the expr into result.
Definition: evaluator.hpp:1195