Reference documentation for deal.II version 9.3.0
\(\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 - 2021 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 
27 
28 #ifdef DEAL_II_WITH_CUDA
29 
31 
32 // Forward declarations
33 # ifndef DOXYGEN
34 template <typename Number>
35 class ReadWriteVector;
36 # endif
37 
38 namespace LinearAlgebra
39 {
43  namespace CUDAWrappers
44  {
54  template <typename Number>
55  class Vector : public VectorSpaceVector<Number>
56  {
57  public:
61 
65  Vector();
66 
70  Vector(const Vector<Number> &V);
71 
75  Vector(Vector<Number> &&) noexcept = default;
76 
87  explicit Vector(const size_type n);
88 
92  Vector &
93  operator=(const Vector<Number> &v);
94 
98  Vector &
99  operator=(Vector<Number> &&v) noexcept = default;
100 
116  virtual void
117  swap(Vector<Number> &v);
118 
124  void
125  reinit(const size_type n, const bool omit_zeroing_entries = false);
126 
131  virtual void
132  reinit(const VectorSpaceVector<Number> &V,
133  const bool omit_zeroing_entries = false) override;
134 
143  virtual void
144  import(const ReadWriteVector<Number> &V,
145  VectorOperation::values operation,
146  std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
147  communication_pattern = {}) override;
148 
153  virtual Vector<Number> &
154  operator=(const Number s) override;
155 
159  virtual Vector<Number> &
160  operator*=(const Number factor) override;
161 
165  virtual Vector<Number> &
166  operator/=(const Number factor) override;
167 
171  virtual Vector<Number> &
172  operator+=(const VectorSpaceVector<Number> &V) override;
173 
177  virtual Vector<Number> &
178  operator-=(const VectorSpaceVector<Number> &V) override;
179 
183  virtual Number
184  operator*(const VectorSpaceVector<Number> &V) const override;
185 
189  virtual void
190  add(const Number a) override;
191 
195  virtual void
196  add(const Number a, const VectorSpaceVector<Number> &V) override;
197 
201  virtual void
202  add(const Number a,
204  const Number b,
205  const VectorSpaceVector<Number> &W) override;
206 
211  virtual void
212  sadd(const Number s,
213  const Number a,
214  const VectorSpaceVector<Number> &V) override;
215 
221  virtual void
222  scale(const VectorSpaceVector<Number> &scaling_factors) override;
223 
227  virtual void
228  equ(const Number a, const VectorSpaceVector<Number> &V) override;
229 
233  virtual bool
234  all_zero() const override;
235 
239  virtual value_type
240  mean_value() const override;
241 
246  virtual real_type
247  l1_norm() const override;
248 
253  virtual real_type
254  l2_norm() const override;
255 
259  real_type
260  norm_sqr() const;
261 
266  virtual real_type
267  linfty_norm() const override;
268 
288  virtual Number
289  add_and_dot(const Number a,
291  const VectorSpaceVector<Number> &W) override;
292 
297  Number *
298  get_values() const;
299 
303  virtual size_type
304  size() const override;
305 
310  virtual ::IndexSet
311  locally_owned_elements() const override;
312 
316  virtual void
317  print(std::ostream & out,
318  const unsigned int precision = 2,
319  const bool scientific = true,
320  const bool across = true) const override;
321 
325  virtual std::size_t
326  memory_consumption() const override;
327 
334 
335  private:
339  std::unique_ptr<Number[], void (*)(Number *)> val;
340 
345  };
346  } // namespace CUDAWrappers
347 } // namespace LinearAlgebra
348 
349 // ---------------------------- Inline functions --------------------------
350 
358 template <typename Number>
359 inline void
362 {
363  u.swap(v);
364 }
365 
366 namespace LinearAlgebra
367 {
368  namespace CUDAWrappers
369  {
370  template <typename Number>
371  inline Number *
373  {
374  return val.get();
375  }
376 
377 
378 
379  template <typename Number>
380  inline typename Vector<Number>::size_type
382  {
383  return n_elements;
384  }
385 
386 
387  template <typename Number>
388  inline IndexSet
390  {
392  }
393 
394 
395 
396  template <typename Number>
397  inline void
399  {
400  std::swap(val, v.val);
402  }
403  } // namespace CUDAWrappers
404 } // namespace LinearAlgebra
405 
407 
408 #endif
409 
410 #endif
virtual Number add_and_dot(const Number a, const VectorSpaceVector< Number > &V, const VectorSpaceVector< Number > &W) override
typename VectorSpaceVector< Number >::size_type size_type
Definition: cuda_vector.h:59
virtual void equ(const Number a, const VectorSpaceVector< Number > &V) override
void reinit(const size_type n, const bool omit_zeroing_entries=false)
std::unique_ptr< Number[], void(*)(Number *)> val
Definition: cuda_vector.h:339
virtual Vector< Number > & operator-=(const VectorSpaceVector< Number > &V) override
virtual real_type l1_norm() const override
static const char V
STL namespace.
virtual void swap(Vector< Number > &v)
Definition: cuda_vector.h:398
virtual value_type mean_value() const override
typename VectorSpaceVector< Number >::real_type real_type
Definition: cuda_vector.h:60
virtual ::IndexSet locally_owned_elements() const override
Definition: cuda_vector.h:389
virtual void add(const Number a) override
#define DeclException0(Exception0)
Definition: exceptions.h:470
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:395
static ::ExceptionBase & ExcVectorTypeNotCompatible()
Vector & operator=(const Vector< Number > &v)
virtual Vector< Number > & operator*=(const Number factor) override
virtual bool all_zero() const override
typename VectorSpaceVector< Number >::value_type value_type
Definition: cuda_vector.h:58
virtual Number operator*(const VectorSpaceVector< Number > &V) const override
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
virtual Vector< Number > & operator/=(const Number factor) override
typename numbers::NumberTraits< Number >::real_type real_type
IndexSet complete_index_set(const IndexSet::size_type N)
Definition: index_set.h:1013
virtual std::size_t memory_consumption() const override
virtual real_type l2_norm() const override
virtual Vector< Number > & operator+=(const VectorSpaceVector< Number > &V) override
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:394
virtual void scale(const VectorSpaceVector< Number > &scaling_factors) override
virtual void sadd(const Number s, const Number a, const VectorSpaceVector< Number > &V) override
virtual void import(const ReadWriteVector< Number > &V, VectorOperation::values operation, std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > communication_pattern={}) override
void swap(LinearAlgebra::CUDAWrappers::Vector< Number > &u, LinearAlgebra::CUDAWrappers::Vector< Number > &v)
Definition: cuda_vector.h:360
virtual void print(std::ostream &out, const unsigned int precision=2, const bool scientific=true, const bool across=true) const override
virtual size_type size() const override
Definition: cuda_vector.h:381
virtual real_type linfty_norm() const override