Reference documentation for deal.II version GIT 35969cdc9b 2023-12-09 01:10:02+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
cuda_vector.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2016 - 2023 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_cuda_vector_h
17 #define dealii_cuda_vector_h
18 
19 #include <deal.II/base/config.h>
20 
23 #include <deal.II/base/index_set.h>
24 
26 
27 #ifdef DEAL_II_WITH_CUDA
28 
30 
31 // Forward declarations
32 # ifndef DOXYGEN
33 namespace LinearAlgebra
34 {
35  template <typename Number>
36  class ReadWriteVector;
37 }
38 # endif
39 
40 namespace LinearAlgebra
41 {
45  namespace CUDAWrappers
46  {
55  template <typename Number>
56  class Vector
57  {
58  public:
59  using value_type = Number;
62 
66  Vector();
67 
71  Vector(const Vector<Number> &V);
72 
76  Vector(Vector<Number> &&) noexcept = default;
77 
88  explicit Vector(const size_type n);
89 
93  Vector &
94  operator=(const Vector<Number> &v);
95 
99  Vector &
100  operator=(Vector<Number> &&v) noexcept = default;
101 
114  void
115  swap(Vector<Number> &v);
116 
122  void
123  reinit(const size_type n, const bool omit_zeroing_entries = false);
124 
129  void
130  reinit(const Vector<Number> &V, const bool omit_zeroing_entries = false);
131 
140  void
142  const ReadWriteVector<Number> &V,
143  const VectorOperation::values operation,
144  const std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
145  &communication_pattern = {});
146 
150  DEAL_II_DEPRECATED void
151  import(const ReadWriteVector<Number> &V,
152  VectorOperation::values operation,
153  std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
154  communication_pattern = {})
155  {
156  import_elements(V, operation, communication_pattern);
157  }
158 
164  operator=(const Number s);
165 
170  operator*=(const Number factor);
171 
176  operator/=(const Number factor);
177 
182  operator+=(const Vector<Number> &V);
183 
188  operator-=(const Vector<Number> &V);
189 
193  Number
194  operator*(const Vector<Number> &V) const;
195 
199  void
200  add(const Number a);
201 
205  void
206  add(const Number a, const Vector<Number> &V);
207 
211  void
212  add(const Number a,
213  const Vector<Number> &V,
214  const Number b,
215  const Vector<Number> &W);
216 
221  void
222  sadd(const Number s, const Number a, const Vector<Number> &V);
223 
229  void
230  scale(const Vector<Number> &scaling_factors);
231 
235  void
236  equ(const Number a, const Vector<Number> &V);
237 
241  bool
242  all_zero() const;
243 
247  value_type
248  mean_value() const;
249 
254  real_type
255  l1_norm() const;
256 
261  real_type
262  l2_norm() const;
263 
267  real_type
268  norm_sqr() const;
269 
274  real_type
275  linfty_norm() const;
276 
296  Number
297  add_and_dot(const Number a,
298  const Vector<Number> &V,
299  const Vector<Number> &W);
300 
305  Number *
306  get_values() const;
307 
311  size_type
312  size() const;
313 
318  ::IndexSet
319  locally_owned_elements() const;
320 
324  void
325  print(std::ostream &out,
326  const unsigned int precision = 2,
327  const bool scientific = true,
328  const bool across = true) const;
329 
333  std::size_t
334  memory_consumption() const;
335 
342 
343  private:
347  std::unique_ptr<Number[], void (*)(Number *)> val;
348 
353  };
354  } // namespace CUDAWrappers
355 } // namespace LinearAlgebra
356 
357 // ---------------------------- Inline functions --------------------------
358 
366 template <typename Number>
367 inline void
370 {
371  u.swap(v);
372 }
373 
374 namespace LinearAlgebra
375 {
376  namespace CUDAWrappers
377  {
378  template <typename Number>
379  inline Number *
381  {
382  return val.get();
383  }
384 
385 
386 
387  template <typename Number>
388  inline typename Vector<Number>::size_type
390  {
391  return n_elements;
392  }
393 
394 
395  template <typename Number>
396  inline IndexSet
398  {
399  return complete_index_set(n_elements);
400  }
401 
402 
403 
404  template <typename Number>
405  inline void
407  {
408  std::swap(val, v.val);
409  std::swap(n_elements, v.n_elements);
410  }
411  } // namespace CUDAWrappers
412 } // namespace LinearAlgebra
413 
415 
416 #endif
417 
418 #endif
Vector(Vector< Number > &&) noexcept=default
void equ(const Number a, const Vector< Number > &V)
Definition: cuda_vector.cc:393
types::global_dof_index size_type
Definition: cuda_vector.h:60
void sadd(const Number s, const Number a, const Vector< Number > &V)
Definition: cuda_vector.cc:354
Number add_and_dot(const Number a, const Vector< Number > &V, const Vector< Number > &W)
Definition: cuda_vector.cc:532
std::unique_ptr< Number[], void(*)(Number *)> val
Definition: cuda_vector.h:347
typename numbers::NumberTraits< Number >::real_type real_type
Definition: cuda_vector.h:61
Vector< Number > & operator*=(const Number factor)
Definition: cuda_vector.cc:191
void import_elements(const ReadWriteVector< Number > &V, const VectorOperation::values operation, const std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > &communication_pattern={})
Definition: cuda_vector.cc:129
Vector & operator=(const Vector< Number > &v)
Definition: cuda_vector.cc:66
Vector< Number > & operator+=(const Vector< Number > &V)
Definition: cuda_vector.cc:222
void scale(const Vector< Number > &scaling_factors)
Definition: cuda_vector.cc:375
::IndexSet locally_owned_elements() const
Definition: cuda_vector.h:397
void print(std::ostream &out, const unsigned int precision=2, const bool scientific=true, const bool across=true) const
Definition: cuda_vector.cc:567
Number operator*(const Vector< Number > &V) const
Definition: cuda_vector.cc:260
void swap(Vector< Number > &v)
Definition: cuda_vector.h:406
void reinit(const size_type n, const bool omit_zeroing_entries=false)
Definition: cuda_vector.cc:97
Vector< Number > & operator-=(const Vector< Number > &V)
Definition: cuda_vector.cc:241
std::size_t memory_consumption() const
Definition: cuda_vector.cc:603
Vector< Number > & operator/=(const Number factor)
Definition: cuda_vector.cc:206
void swap(LinearAlgebra::CUDAWrappers::Vector< Number > &u, LinearAlgebra::CUDAWrappers::Vector< Number > &v)
Definition: cuda_vector.h:368
#define DEAL_II_DEPRECATED
Definition: config.h:178
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:477
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:478
void swap(LinearAlgebra::CUDAWrappers::Vector< Number > &u, LinearAlgebra::CUDAWrappers::Vector< Number > &v)
Definition: cuda_vector.h:368
#define DeclException0(Exception0)
Definition: exceptions.h:472
static ::ExceptionBase & ExcVectorTypeNotCompatible()
IndexSet complete_index_set(const IndexSet::size_type N)
Definition: index_set.h:1189
static const char V
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
unsigned int global_dof_index
Definition: types.h:82