36 using assignable_base_type::operator=;
54 slice_view(
sub_type sub,
size_t first,
size_t last) : sub(sub), first(first), last(last) {}
63 return sub[first * (
etl::size(sub) / dim<0>(sub)) + j];
65 const auto sa = dim<0>(sub);
67 return sub[(j % ss) * sa + j / ss + first];
78 return sub[first * (
etl::size(sub) / dim<0>(sub)) + j];
80 const auto sa = dim<0>(sub);
82 return sub[(j % ss) * sa + j / ss + first];
94 return sub.read_flat(first * (
etl::size(sub) / dim<0>(sub)) + j);
96 const auto sa = dim<0>(sub);
98 return sub.read_flat((j % ss) * sa + j / ss + first);
107 template <
typename... S>
109 return sub(i + first, static_cast<size_t>(args)...);
117 template <
typename... S>
119 return sub(i + first, static_cast<size_t>(args)...);
137 template <
typename V = default_vec>
138 auto load(
size_t x)
const noexcept {
139 return sub.template loadu<V>(x + first * (
etl::size(sub) / etl::dim<0>(sub)));
148 template <
typename V = default_vec>
149 auto loadu(
size_t x)
const noexcept {
150 return sub.template loadu<V>(x + first * (
etl::size(sub) / etl::dim<0>(sub)));
158 template <
typename E>
159 bool alias(
const E& rhs)
const noexcept {
160 return sub.alias(rhs);
169 template <
typename L>
178 template <
typename L>
187 template <
typename L>
196 template <
typename L>
205 template <
typename L>
214 template <
typename L>
235 sub.ensure_cpu_up_to_date();
244 sub.ensure_gpu_up_to_date();
251 template <
typename T>
270 template <
typename V = default_vec>
273 using assignable_base_type::operator=;
281 const size_t sub_size;
285 mutable bool cpu_up_to_date;
286 mutable bool gpu_up_to_date;
297 slice_view(
sub_type sub,
size_t first,
size_t last) : sub(sub), first(first), last(last), sub_size((
etl::size(sub) / etl::dim<0>(sub)) * (last - first)) {
300 standard_evaluator::pre_assign_rhs(*
this);
303 this->memory = this->sub.memory_start() + first * (
etl::size(this->sub) / etl::dim<0>(this->sub));
306 this->cpu_up_to_date = this->sub.is_cpu_up_to_date();
307 this->gpu_up_to_date = this->sub.is_gpu_up_to_date();
309 cpp_assert(this->memory,
"Invalid memory");
318 if (!this->cpu_up_to_date) {
319 if (sub.is_gpu_up_to_date()) {
320 sub.invalidate_cpu();
327 if (!this->gpu_up_to_date) {
328 if (sub.is_cpu_up_to_date()) {
329 sub.invalidate_gpu();
375 template <
typename... S>
378 return memory[
dyn_index(*
this, i, args...)];
386 template <
typename... S>
390 return memory[
dyn_index(*
this, i, args...)];
408 template <
typename V = default_vec>
409 auto load(
size_t x)
const noexcept {
419 template <
typename V = default_vec>
430 template <
typename V = default_vec>
441 template <
typename V = default_vec>
453 template <
typename V = default_vec>
454 auto loadu(
size_t x)
const noexcept {
463 template <
typename E>
464 bool alias(
const E& rhs)
const noexcept {
465 if constexpr (is_dma<E>) {
466 return memory_alias(memory_start(), memory_end(), rhs.memory_start(), rhs.memory_end());
468 return sub.alias(rhs);
476 template <
typename Y>
486 template <
typename Y>
513 return memory + sub_size;
521 return memory + sub_size;
530 template <
typename L>
539 template <
typename L>
548 template <
typename L>
557 template <
typename L>
566 template <
typename L>
575 template <
typename L>
597 return sub.gpu_memory() + first * (
etl::size(sub) / etl::dim<0>(sub));
611 this->cpu_up_to_date =
false;
618 this->gpu_up_to_date =
false;
625 this->cpu_up_to_date =
true;
632 this->gpu_up_to_date =
true;
641 sub.ensure_gpu_allocated();
648 sub.ensure_gpu_allocated();
651 if (!this->gpu_up_to_date) {
652 cuda_check_assert(cudaMemcpy(
const_cast<std::remove_const_t<value_type>*
>(
gpu_memory()),
653 const_cast<std::remove_const_t<value_type>*
>(memory_start()), sub_size *
sizeof(
value_type), cudaMemcpyHostToDevice));
655 this->gpu_up_to_date =
true;
668 if (!this->cpu_up_to_date) {
669 cuda_check_assert(cudaMemcpy(
const_cast<std::remove_const_t<value_type>*
>(memory_start()),
670 const_cast<std::remove_const_t<value_type>*
>(
gpu_memory()), sub_size *
sizeof(
value_type), cudaMemcpyDeviceToHost));
676 this->cpu_up_to_date =
true;
684 cpp_assert(sub.gpu_memory(),
"GPU must be allocated before copy");
687 cuda_check_assert(cudaMemcpy(
const_cast<std::remove_const_t<value_type>*
>(
gpu_memory()),
const_cast<std::remove_const_t<value_type>*
>(new_gpu_memory),
688 sub_size *
sizeof(
value_type), cudaMemcpyDeviceToDevice));
691 gpu_up_to_date =
true;
692 cpu_up_to_date =
false;
700 return cpu_up_to_date;
708 return gpu_up_to_date;
715 template <
typename T>
722 static constexpr
bool is_etl =
true;
727 static constexpr
bool is_linear = sub_traits::is_linear;
729 static constexpr
bool is_value =
false;
730 static constexpr
bool is_direct = fast_slice_view_able<T>;
731 static constexpr
bool is_generator =
false;
732 static constexpr
bool is_padded =
false;
733 static constexpr
bool is_aligned =
false;
734 static constexpr
bool is_temporary = sub_traits::is_temporary;
735 static constexpr
bool gpu_computable = is_direct;
736 static constexpr
order storage_order = sub_traits::storage_order;
743 template <vector_mode_t V>
744 static constexpr
bool vectorizable = sub_traits::template vectorizable<V>&& storage_order ==
order::RowMajor;
752 return (sub_traits::size(v.sub) /
sub_traits::dim(v.sub, 0)) * (v.last - v.first);
763 return v.last - v.first;
774 return sub_traits::dimensions();
CRTP class to inject iterators functions.
Definition: iterable.hpp:23
void assign_add_to(L &&lhs) const
Add to the given left-hand-side expression.
Definition: dyn_matrix_view.hpp:217
void ensure_gpu_allocated() const
Ensures that the GPU memory is allocated and that the GPU memory is up to date (to undefined value)...
Definition: sub_view.hpp:717
Definition: expr_fwd.hpp:71
void std_assign_evaluate(Expr &&expr, Result &&result)
Evaluation of the expr into result.
Definition: evaluator.hpp:1176
bool alias(const E &rhs) const noexcept
Test if this expression aliases with the given expression.
Definition: dyn_matrix_view.hpp:197
void assign_div_to(L &&lhs) const
Divide the given left-hand-side expression.
Definition: dyn_matrix_view.hpp:244
value_t< sub_type > value_type
The value contained in the expression.
Definition: dyn_matrix_view.hpp:31
void assign_mul_to(L &&lhs) const
Multiply the given left-hand-side expression.
Definition: dyn_matrix_view.hpp:235
constexpr bool is_magic_view
Traits indicating if the given ETL type is a magic view expression.
Definition: traits.hpp:311
const_memory_t< sub_type > const_memory_type
The const memory access type.
Definition: dyn_matrix_view.hpp:33
void assign_to(L &&lhs) const
Assign to the given left-hand-side expression.
Definition: dyn_matrix_view.hpp:208
order
Storage order of a matrix.
Definition: order.hpp:15
typename V::template vec_type< value_type > vec_type
The vectorization type for V.
Definition: dyn_matrix_view.hpp:43
static constexpr int complexity() noexcept
Estimate the complexity of computation.
Definition: slice_view.hpp:781
bool is_cpu_up_to_date() const noexcept
Indicates if the CPU memory is up to date.
Definition: sub_view.hpp:777
std::conditional_t< std::is_lvalue_reference_v< S >, const value_t< T > &, value_t< T > > const_return_helper
Definition: traits.hpp:872
void gpu_copy_from([[maybe_unused]] const value_type *new_gpu_memory) const
Copy from GPU to GPU.
Definition: sub_view.hpp:761
T sub_type
The sub type.
Definition: dyn_matrix_view.hpp:30
memory_t< sub_type > memory_type
The memory acess type.
Definition: dyn_matrix_view.hpp:32
void gpu_evict() const noexcept
Evict the expression from GPU.
Definition: sub_view.hpp:681
CRTP class to inject functions testing values of the expressions.
Definition: value_testable.hpp:26
static size_t size(const expr_t &v)
Returns the size of the given expression.
Definition: slice_view.hpp:751
constexpr bool is_fast
Traits to test if the given ETL expresion type is fast (sizes known at compile-time) ...
Definition: traits.hpp:588
auto end() noexcept
Return an iterator to the past-the-end element of the matrix.
Definition: iterable.hpp:59
auto load(size_t x) const noexcept
Load several elements of the expression at once.
Definition: dyn_matrix_view.hpp:143
Traits to get information about ETL types.
Definition: tmp.hpp:68
Root namespace for the ETL library.
Definition: adapter.hpp:15
std::conditional_t< std::is_const_v< std::remove_reference_t< S > >, const value_t< T > &, std::conditional_t< std::is_lvalue_reference_v< S > &&!std::is_const_v< T >, value_t< T > &, value_t< T > >> return_helper
Definition: traits.hpp:866
bool memory_alias(const P1 *a_begin, const P1 *a_end, const P2 *b_begin, const P2 *b_end)
Test if two memory ranges overlap.
Definition: helpers.hpp:264
void invalidate_gpu() const noexcept
Invalidates the GPU memory.
Definition: sub_view.hpp:695
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< std::is_const_v< std::remove_reference_t< S > >, typename std::decay_t< S >::const_memory_type, typename std::decay_t< S >::memory_type > memory_t
Traits to extract the direct memory type out of an ETL type.
Definition: tmp.hpp:88
void store(vec_type< V > in, size_t i) noexcept
Store several elements in the matrix at once.
Definition: dyn_matrix_view.hpp:176
void stream(vec_type< V > in, size_t i) noexcept
Store several elements in the matrix at once, using non-temporal store.
Definition: dyn_matrix_view.hpp:165
typename std::decay_t< S >::const_memory_type const_memory_t
Traits to extract the direct const memory type out of an ETL type.
Definition: tmp.hpp:94
void ensure_cpu_up_to_date() const
Ensures that the GPU memory is allocated and that the GPU memory is up to date (to undefined value)...
Definition: dyn_matrix_view.hpp:271
Visitor to perform local evaluation when necessary.
Definition: eval_visitors.hpp:23
static size_t dim(const expr_t &v, size_t d)
Returns the dth dimension of the given expression.
Definition: slice_view.hpp:761
std::decay_t< T > sub_expr_t
The sub expression type.
Definition: slice_view.hpp:718
void invalidate_cpu() const noexcept
Invalidates the CPU memory.
Definition: sub_view.hpp:688
Configurable iterator for ETL expressions.
Definition: iterator.hpp:24
void storeu(vec_type< V > in, size_t i) noexcept
Store several elements in the matrix at once.
Definition: dyn_matrix_view.hpp:187
void std_mod_evaluate(Expr &&expr, Result &&result)
Compound modulo evaluation of the expr into result.
Definition: evaluator.hpp:1271
auto begin() noexcept
Return an iterator to the first element of the matrix.
Definition: iterable.hpp:46
const_return_type operator()(size_t j) const
Access to the element at the given position.
Definition: dyn_matrix_view.hpp:89
value_type read_flat(size_t j) const noexcept
Returns the value at the given index This function never has side effects.
Definition: dyn_matrix_view.hpp:111
void std_mul_evaluate(Expr &&expr, Result &&result)
Compound multiply evaluation of the expr into result.
Definition: evaluator.hpp:1233
auto loadu(size_t x) const noexcept
Load several elements of the expression at once.
Definition: dyn_matrix_view.hpp:154
constexpr bool is_transformer
Traits indicating if the given ETL type is a transformer expression.
Definition: traits.hpp:297
void visit(detail::evaluator_visitor &visitor) const
Apply the given visitor to this expression and its descendants.
Definition: dyn_matrix_view.hpp:263
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
bool is_gpu_up_to_date() const noexcept
Indicates if the GPU memory is up to date.
Definition: sub_view.hpp:785
void ensure_gpu_up_to_date() const
Copy back from the GPU to the expression memory if necessary.
Definition: dyn_matrix_view.hpp:280
Definition: expr_fwd.hpp:59
auto sub(E &&value, size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o, size_t p) -> sub_matrix_4d< detail::build_identity_type< E >, false >
Returns view representing a sub matrix view of the given expression.
Definition: view_expression_builder.hpp:100
void validate_gpu() const noexcept
Validates the GPU memory.
Definition: sub_view.hpp:709
CRTP class to inject assign operations to matrix and vector structures.
Definition: assignable.hpp:25
typename etl_traits< sub_expr_t >::value_type value_type
The value type.
Definition: slice_view.hpp:720
void std_sub_evaluate(Expr &&expr, Result &&result)
Compound subtract evaluation of the expr into result.
Definition: evaluator.hpp:1214
void assign_mod_to(L &&lhs) const
Modulo the given left-hand-side expression.
Definition: dyn_matrix_view.hpp:253
const_return_type operator[](size_t j) const
Returns the element at the given index.
Definition: dyn_matrix_view.hpp:71
constexpr bool is_thread_safe
Traits to test if the given ETL expresion type is thread safe.
Definition: traits.hpp:687
static constexpr size_t dimensions()
Returns the number of expressions for this type.
Definition: slice_view.hpp:773
const auto & gpu_compute_hint([[maybe_unused]] Y &y) const
Return a GPU computed version of this expression.
Definition: sub_view.hpp:653
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 validate_cpu() const noexcept
Validates the CPU memory.
Definition: sub_view.hpp:702
value_type * gpu_memory() const noexcept
Return GPU memory of this expression, if any.
Definition: sub_view.hpp:674
void std_add_evaluate(Expr &&expr, Result &&result)
Compound add evaluation of the expr into result.
Definition: evaluator.hpp:1195
const_return_helper< sub_type, decltype(std::declval< sub_type >()[0])> const_return_type
The const type return by the view.
Definition: dyn_matrix_view.hpp:35
return_helper< sub_type, decltype(std::declval< sub_type >()[0])> return_type
The type returned by the view.
Definition: dyn_matrix_view.hpp:34
size_t dyn_index([[maybe_unused]] const T &expression, size_t i) noexcept(assert_nothrow)
Compute the index for a 1D dynamic matrix.
Definition: index.hpp:187
void assign_sub_to(L &&lhs) const
Sub from the given left-hand-side expression.
Definition: dyn_matrix_view.hpp:226