Expression Templates Library (ETL)
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
etl::adapter< Matrix > Struct Template Reference

A base class for adapters. More...

#include <adapter.hpp>

Inheritance diagram for etl::adapter< Matrix >:
Inheritance graph
[legend]

Public Types

using matrix_t = Matrix
 The adapted matrix type.
 
using expr_t = matrix_t
 The wrapped expression type.
 
using value_type = value_t< matrix_t >
 The value type.
 
using memory_type = value_type *
 The memory type.
 
using const_memory_type = const value_type *
 The const memory type.
 
template<typename V = default_vec>
using vec_type = typename V::template vec_type< value_type >
 The vectorization type for V.
 

Public Member Functions

 adapter () noexcept
 Construct a new matrix and fill it with zeros. More...
 
 adapter (value_type value) noexcept
 Construct a new adapter matrix and fill it witht the given value. More...
 
 adapter (size_t dim) noexcept
 Construct a new adapter matrix and fill it with zeros. More...
 
 adapter (size_t dim, value_type value) noexcept
 Construct a new adapter matrix and fill it witht the given value. More...
 
 adapter (const adapter &rhs)=default
 Construct a adapter by copy. More...
 
adapteroperator= (const adapter &rhs)=default
 Assign to the matrix by copy. More...
 
 adapter (adapter &&rhs) noexcept=default
 Construct a adapter by move. More...
 
adapteroperator= (adapter &&rhs) noexcept=default
 Assign to the matrix by move. More...
 
const value_typeoperator() (size_t i, size_t j) const noexcept
 Access the (i, j) element of the 2D matrix. More...
 
const value_typeoperator[] (size_t i) const noexcept
 Returns the element at the given index. More...
 
value_typeoperator[] (size_t i) noexcept
 Returns the element at the given index. More...
 
value_type read_flat (size_t i) const noexcept
 
memory_type memory_start () noexcept
 Returns a pointer to the first element in memory. More...
 
const_memory_type memory_start () const noexcept
 Returns a pointer to the first element in memory. More...
 
memory_type memory_end () noexcept
 Returns a pointer to the past-the-end element in memory. More...
 
const_memory_type memory_end () const noexcept
 Returns a pointer to the past-the-end element in memory. More...
 
template<typename V = default_vec>
vec_type< V > load (size_t i) const noexcept
 Load several elements of the matrix at once. More...
 
template<typename V = default_vec>
vec_type< V > loadu (size_t i) const noexcept
 Load several elements of the matrix at once. More...
 
template<typename V = default_vec>
void stream (vec_type< V > in, size_t i) noexcept
 Store several elements in the matrix at once, using non-temporal stores. More...
 
template<typename V = default_vec>
void store (vec_type< V > in, size_t i) noexcept
 Store several elements in the matrix at once. More...
 
template<typename V = default_vec>
void storeu (vec_type< V > in, size_t i) noexcept
 Store several elements in the matrix at once. More...
 
template<typename E >
bool alias (const E &rhs) const noexcept
 Test if this expression aliases with the given expression. More...
 
template<typename Y >
auto & gpu_compute_hint ([[maybe_unused]] Y &y)
 Return a GPU computed version of this expression. More...
 
template<typename Y >
const auto & gpu_compute_hint ([[maybe_unused]] Y &y) const
 Return a GPU computed version of this expression. More...
 
template<typename L >
void assign_to (L &&lhs) const
 Assign to the given left-hand-side expression. More...
 
template<typename L >
void assign_add_to (L &&lhs) const
 Add to the given left-hand-side expression. More...
 
template<typename L >
void assign_sub_to (L &&lhs) const
 Sub from the given left-hand-side expression. More...
 
template<typename L >
void assign_mul_to (L &&lhs) const
 Multiply the given left-hand-side expression. More...
 
template<typename L >
void assign_div_to (L &&lhs) const
 Divide the given left-hand-side expression. More...
 
template<typename L >
void assign_mod_to (L &&lhs) const
 Modulo the given left-hand-side expression. More...
 
void visit ([[maybe_unused]] const detail::evaluator_visitor &visitor) const
 Apply the given visitor to this expression and its descendants. More...
 
value_typegpu_memory () const noexcept
 Return GPU memory of this expression, if any. More...
 
void gpu_evict () const noexcept
 Evict the expression from GPU.
 
void invalidate_cpu () const noexcept
 Invalidates the CPU memory.
 
void invalidate_gpu () const noexcept
 Invalidates the GPU memory.
 
void validate_cpu () const noexcept
 Validates the CPU memory.
 
void validate_gpu () const noexcept
 Validates the GPU memory.
 
void ensure_gpu_allocated () const
 Ensures that the GPU memory is allocated and that the GPU memory is up to date (to undefined value).
 
void ensure_gpu_up_to_date () const
 Allocate memory on the GPU for the expression and copy the values into the GPU.
 
void ensure_cpu_up_to_date () const
 Copy back from the GPU to the expression memory if necessary.
 
void gpu_copy_from (const value_type *gpu_memory) const
 Copy from GPU to GPU. More...
 
bool is_cpu_up_to_date () const noexcept
 Indicates if the CPU memory is up to date. More...
 
bool is_gpu_up_to_date () const noexcept
 Indicates if the GPU memory is up to date. More...
 

Static Public Member Functions

static constexpr size_t dimensions () noexcept
 Returns the number of dimensions of the matrix. More...
 

Protected Attributes

matrix_t value
 The adapted matrix.
 

Detailed Description

template<typename Matrix>
struct etl::adapter< Matrix >

A base class for adapters.

Constructor & Destructor Documentation

◆ adapter() [1/6]

template<typename Matrix >
etl::adapter< Matrix >::adapter ( )
inlinenoexcept

Construct a new matrix and fill it with zeros.

This constructor can only be used when the matrix is fast

◆ adapter() [2/6]

template<typename Matrix >
etl::adapter< Matrix >::adapter ( value_type  value)
inlineexplicitnoexcept

Construct a new adapter matrix and fill it witht the given value.

Parameters
valueThe value to fill the matrix with

This constructor can only be used when the matrix is fast

◆ adapter() [3/6]

template<typename Matrix >
etl::adapter< Matrix >::adapter ( size_t  dim)
inlineexplicitnoexcept

Construct a new adapter matrix and fill it with zeros.

Parameters
dimThe dimension of the matrix

◆ adapter() [4/6]

template<typename Matrix >
etl::adapter< Matrix >::adapter ( size_t  dim,
value_type  value 
)
inlinenoexcept

Construct a new adapter matrix and fill it witht the given value.

Parameters
valueThe value to fill the matrix with
dimThe dimension of the matrix

◆ adapter() [5/6]

template<typename Matrix >
etl::adapter< Matrix >::adapter ( const adapter< Matrix > &  rhs)
default

Construct a adapter by copy.

Parameters
rhsThe right-hand-side matrix

◆ adapter() [6/6]

template<typename Matrix >
etl::adapter< Matrix >::adapter ( adapter< Matrix > &&  rhs)
defaultnoexcept

Construct a adapter by move.

Parameters
rhsThe right-hand-side matrix

Member Function Documentation

◆ alias()

template<typename Matrix >
template<typename E >
bool etl::adapter< Matrix >::alias ( const E &  rhs) const
inlinenoexcept

Test if this expression aliases with the given expression.

Parameters
rhsThe other expression to test
Returns
true if the two expressions aliases, false otherwise

◆ assign_add_to()

template<typename Matrix >
template<typename L >
void etl::adapter< Matrix >::assign_add_to ( L &&  lhs) const
inline

Add to the given left-hand-side expression.

Parameters
lhsThe expression to which assign

◆ assign_div_to()

template<typename Matrix >
template<typename L >
void etl::adapter< Matrix >::assign_div_to ( L &&  lhs) const
inline

Divide the given left-hand-side expression.

Parameters
lhsThe expression to which assign

◆ assign_mod_to()

template<typename Matrix >
template<typename L >
void etl::adapter< Matrix >::assign_mod_to ( L &&  lhs) const
inline

Modulo the given left-hand-side expression.

Parameters
lhsThe expression to which assign

◆ assign_mul_to()

template<typename Matrix >
template<typename L >
void etl::adapter< Matrix >::assign_mul_to ( L &&  lhs) const
inline

Multiply the given left-hand-side expression.

Parameters
lhsThe expression to which assign

◆ assign_sub_to()

template<typename Matrix >
template<typename L >
void etl::adapter< Matrix >::assign_sub_to ( L &&  lhs) const
inline

Sub from the given left-hand-side expression.

Parameters
lhsThe expression to which assign

◆ assign_to()

template<typename Matrix >
template<typename L >
void etl::adapter< Matrix >::assign_to ( L &&  lhs) const
inline

Assign to the given left-hand-side expression.

Parameters
lhsThe expression to which assign

◆ dimensions()

template<typename Matrix >
static constexpr size_t etl::adapter< Matrix >::dimensions ( )
inlinestaticnoexcept

Returns the number of dimensions of the matrix.

Returns
the number of dimensions of the matrix

◆ gpu_compute_hint() [1/2]

template<typename Matrix >
template<typename Y >
auto& etl::adapter< Matrix >::gpu_compute_hint ( [[maybe_unused] ] Y &  y)
inline

Return a GPU computed version of this expression.

Returns
a GPU-computed ETL expression for this expression

◆ gpu_compute_hint() [2/2]

template<typename Matrix >
template<typename Y >
const auto& etl::adapter< Matrix >::gpu_compute_hint ( [[maybe_unused] ] Y &  y) const
inline

Return a GPU computed version of this expression.

Returns
a GPU-computed ETL expression for this expression

◆ gpu_copy_from()

template<typename Matrix >
void etl::adapter< Matrix >::gpu_copy_from ( const value_type gpu_memory) const
inline

Copy from GPU to GPU.

Parameters
gpu_memoryPointer to CPU memory

◆ gpu_memory()

template<typename Matrix >
value_type* etl::adapter< Matrix >::gpu_memory ( ) const
inlinenoexcept

Return GPU memory of this expression, if any.

Returns
a pointer to the GPU memory or nullptr if not allocated in GPU.

◆ is_cpu_up_to_date()

template<typename Matrix >
bool etl::adapter< Matrix >::is_cpu_up_to_date ( ) const
inlinenoexcept

Indicates if the CPU memory is up to date.

Returns
true if the CPU memory is up to date, false otherwise.

◆ is_gpu_up_to_date()

template<typename Matrix >
bool etl::adapter< Matrix >::is_gpu_up_to_date ( ) const
inlinenoexcept

Indicates if the GPU memory is up to date.

Returns
true if the GPU memory is up to date, false otherwise.

◆ load()

template<typename Matrix >
template<typename V = default_vec>
vec_type<V> etl::adapter< Matrix >::load ( size_t  i) const
inlinenoexcept

Load several elements of the matrix at once.

Parameters
iThe position at which to start. This will be aligned from the beginning (multiple of the vector size).
Template Parameters
VThe vectorization mode to use
Returns
a vector containing several elements of the matrix

◆ loadu()

template<typename Matrix >
template<typename V = default_vec>
vec_type<V> etl::adapter< Matrix >::loadu ( size_t  i) const
inlinenoexcept

Load several elements of the matrix at once.

Parameters
iThe position at which to start. This will be aligned from the beginning (multiple of the vector size).
Template Parameters
VThe vectorization mode to use
Returns
a vector containing several elements of the matrix

◆ memory_end() [1/2]

template<typename Matrix >
memory_type etl::adapter< Matrix >::memory_end ( )
inlinenoexcept

Returns a pointer to the past-the-end element in memory.

Returns
a pointer tot the past-the-end element in memory.

This should only be used by ETL itself in order not to void the adapter guarantee.

◆ memory_end() [2/2]

template<typename Matrix >
const_memory_type etl::adapter< Matrix >::memory_end ( ) const
inlinenoexcept

Returns a pointer to the past-the-end element in memory.

Returns
a pointer tot the past-the-end element in memory.

This should only be used by ETL itself in order not to void the adapter guarantee.

◆ memory_start() [1/2]

template<typename Matrix >
memory_type etl::adapter< Matrix >::memory_start ( )
inlinenoexcept

Returns a pointer to the first element in memory.

Returns
a pointer tot the first element in memory.

This should only be used by ETL itself in order not to void the adapter guarantee.

◆ memory_start() [2/2]

template<typename Matrix >
const_memory_type etl::adapter< Matrix >::memory_start ( ) const
inlinenoexcept

Returns a pointer to the first element in memory.

Returns
a pointer tot the first element in memory.

This should only be used by ETL itself in order not to void the adapter guarantee.

◆ operator()()

template<typename Matrix >
const value_type& etl::adapter< Matrix >::operator() ( size_t  i,
size_t  j 
) const
inlinenoexcept

Access the (i, j) element of the 2D matrix.

Parameters
iThe index of the first dimension
jThe index of the second dimension
Returns
a reference to the (i,j) element

Accessing an element outside the matrix results in Undefined Behaviour.

◆ operator=() [1/2]

template<typename Matrix >
adapter& etl::adapter< Matrix >::operator= ( const adapter< Matrix > &  rhs)
default

Assign to the matrix by copy.

Parameters
rhsThe right-hand-side matrix
Returns
a reference to the assigned matrix

◆ operator=() [2/2]

template<typename Matrix >
adapter& etl::adapter< Matrix >::operator= ( adapter< Matrix > &&  rhs)
defaultnoexcept

Assign to the matrix by move.

Parameters
rhsThe right-hand-side matrix
Returns
a reference to the assigned matrix

◆ operator[]() [1/2]

template<typename Matrix >
const value_type& etl::adapter< Matrix >::operator[] ( size_t  i) const
inlinenoexcept

Returns the element at the given index.

Parameters
iThe index
Returns
a reference to the element at the given index.

◆ operator[]() [2/2]

template<typename Matrix >
value_type& etl::adapter< Matrix >::operator[] ( size_t  i)
inlinenoexcept

Returns the element at the given index.

Parameters
iThe index
Returns
a reference to the element at the given index.

◆ read_flat()

template<typename Matrix >
value_type etl::adapter< Matrix >::read_flat ( size_t  i) const
inlinenoexcept
Returns
the value at the given index This function never alters the state of the container.
Parameters
iThe index
Returns
the value at the given index.

◆ store()

template<typename Matrix >
template<typename V = default_vec>
void etl::adapter< Matrix >::store ( vec_type< V >  in,
size_t  i 
)
inlinenoexcept

Store several elements in the matrix at once.

Parameters
inThe several elements to store
iThe position at which to start. This will be aligned from the beginning (multiple of the vector size).
Template Parameters
VThe vectorization mode to use

◆ storeu()

template<typename Matrix >
template<typename V = default_vec>
void etl::adapter< Matrix >::storeu ( vec_type< V >  in,
size_t  i 
)
inlinenoexcept

Store several elements in the matrix at once.

Parameters
inThe several elements to store
iThe position at which to start. This will be aligned from the beginning (multiple of the vector size).
Template Parameters
VThe vectorization mode to use

◆ stream()

template<typename Matrix >
template<typename V = default_vec>
void etl::adapter< Matrix >::stream ( vec_type< V >  in,
size_t  i 
)
inlinenoexcept

Store several elements in the matrix at once, using non-temporal stores.

Parameters
inThe several elements to store
iThe position at which to start. This will be aligned from the beginning (multiple of the vector size).
Template Parameters
VThe vectorization mode to use

◆ visit()

template<typename Matrix >
void etl::adapter< Matrix >::visit ( [[maybe_unused] ] const detail::evaluator_visitor visitor) const
inline

Apply the given visitor to this expression and its descendants.

Parameters
visitorThe visitor to apply

The documentation for this struct was generated from the following file: