Expression Templates Library (ETL)
direct_fill.hpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c) 2014-2023 Baptiste Wicht
3 // Distributed under the terms of the MIT License.
4 // (See accompanying file LICENSE or copy at
5 // http://opensource.org/licenses/MIT)
6 //=======================================================================
7 
13 #pragma once
14 
16 
17 namespace etl {
18 
24 template <typename E, typename V>
25 void direct_fill(E&& mat, V value) {
26  if constexpr (is_single_precision<E> && egblas_enabled && impl::egblas::has_scalar_sset) {
27  value_t<E> value_conv = value;
28 
29  if (mat.gpu_memory()) {
30  impl::egblas::scalar_set(mat.gpu_memory(), etl::size(mat), 1, value_conv);
31 
32  mat.validate_gpu();
33  }
34 
35  std::fill(mat.memory_start(), mat.memory_end(), value_conv);
36 
37  mat.validate_cpu();
38  } else if constexpr (is_double_precision<E> && egblas_enabled && impl::egblas::has_scalar_dset) {
39  value_t<E> value_conv = value;
40 
41  if (mat.gpu_memory()) {
42  impl::egblas::scalar_set(mat.gpu_memory(), etl::size(mat), 1, value_conv);
43 
44  mat.validate_gpu();
45  }
46 
47  std::fill(mat.memory_start(), mat.memory_end(), value_conv);
48 
49  mat.validate_cpu();
50  } else {
51  std::fill(mat.memory_start(), mat.memory_end(), value);
52 
53  mat.validate_cpu();
54  mat.invalidate_gpu();
55  }
56 }
57 
58 } //end of namespace etl
Root namespace for the ETL library.
Definition: adapter.hpp:15
constexpr bool egblas_enabled
Indicates if the EGBLAS library is available for ETL.
Definition: config.hpp:119
void direct_fill(E &&mat, V value)
Fill the given ETL value class with the given value.
Definition: direct_fill.hpp:25
constexpr size_t size(const E &expr) noexcept
Returns the size of the given ETL expression.
Definition: helpers.hpp:108
EGBLAS wrappers for the scalar_set operation.
typename decay_traits< E >::value_type value_t
Traits to extract the value type out of an ETL type.
Definition: tmp.hpp:81