Reference documentation for deal.II version Git 193422c69f 2020-07-08 17:07:46 +0200
\(\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 - 2019 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 
22 #include <deal.II/base/index_set.h>
23 
26 
27 #ifdef DEAL_II_WITH_CUDA
28 
30 
31 // Forward declarations
32 # ifndef DOXYGEN
33 class CommunicationPatternBase;
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(
145  const ReadWriteVector<Number> & V,
146  VectorOperation::values operation,
147  std::shared_ptr<const CommunicationPatternBase> communication_pattern =
148  std::shared_ptr<const CommunicationPatternBase>()) override;
149 
154  virtual Vector<Number> &
155  operator=(const Number s) override;
156 
160  virtual Vector<Number> &
161  operator*=(const Number factor) override;
162 
166  virtual Vector<Number> &
167  operator/=(const Number factor) override;
168 
172  virtual Vector<Number> &
173  operator+=(const VectorSpaceVector<Number> &V) override;
174 
178  virtual Vector<Number> &
179  operator-=(const VectorSpaceVector<Number> &V) override;
180 
184  virtual Number
185  operator*(const VectorSpaceVector<Number> &V) const override;
186 
190  virtual void
191  add(const Number a) override;
192 
196  virtual void
197  add(const Number a, const VectorSpaceVector<Number> &V) override;
198 
202  virtual void
203  add(const Number a,
204  const VectorSpaceVector<Number> &V,
205  const Number b,
206  const VectorSpaceVector<Number> &W) override;
207 
212  virtual void
213  sadd(const Number s,
214  const Number a,
215  const VectorSpaceVector<Number> &V) override;
216 
222  virtual void
223  scale(const VectorSpaceVector<Number> &scaling_factors) override;
224 
228  virtual void
229  equ(const Number a, const VectorSpaceVector<Number> &V) override;
230 
234  virtual bool
235  all_zero() const override;
236 
240  virtual value_type
241  mean_value() const override;
242 
247  virtual real_type
248  l1_norm() const override;
249 
254  virtual real_type
255  l2_norm() const override;
256 
260  real_type
261  norm_sqr() const;
262 
267  virtual real_type
268  linfty_norm() const override;
269 
289  virtual Number
290  add_and_dot(const Number a,
291  const VectorSpaceVector<Number> &V,
292  const VectorSpaceVector<Number> &W) override;
293 
298  Number *
299  get_values() const;
300 
304  virtual size_type
305  size() const override;
306 
311  virtual ::IndexSet
312  locally_owned_elements() const override;
313 
317  virtual void
318  print(std::ostream & out,
319  const unsigned int precision = 2,
320  const bool scientific = true,
321  const bool across = true) const override;
322 
326  virtual std::size_t
327  memory_consumption() const override;
328 
335 
336  private:
340  std::unique_ptr<Number[], void (*)(Number *)> val;
341 
346  };
347  } // namespace CUDAWrappers
348 } // namespace LinearAlgebra
349 
350 // ---------------------------- Inline functions --------------------------
351 
359 template <typename Number>
360 inline void
362  LinearAlgebra::CUDAWrappers::Vector<Number> &v)
363 {
364  u.swap(v);
365 }
366 
367 namespace LinearAlgebra
368 {
369  namespace CUDAWrappers
370  {
371  template <typename Number>
372  inline Number *
374  {
375  return val.get();
376  }
377 
378 
379 
380  template <typename Number>
381  inline typename Vector<Number>::size_type
383  {
384  return n_elements;
385  }
386 
387 
388  template <typename Number>
389  inline IndexSet
391  {
393  }
394 
395 
396 
397  template <typename Number>
398  inline void
400  {
401  std::swap(val, v.val);
403  }
404  } // namespace CUDAWrappers
405 } // namespace LinearAlgebra
406 
408 
409 #endif
410 
411 #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:340
virtual real_type l1_norm() const override
static const char V
STL namespace.
virtual void swap(Vector< Number > &v)
Definition: cuda_vector.h:399
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:390
virtual void add(const Number a) override
#define DeclException0(Exception0)
Definition: exceptions.h:470
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:363
static ::ExceptionBase & ExcVectorTypeNotCompatible()
virtual bool all_zero() const override
typename VectorSpaceVector< Number >::value_type value_type
Definition: cuda_vector.h:58
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
typename numbers::NumberTraits< Number >::real_type real_type
IndexSet complete_index_set(const IndexSet::size_type N)
Definition: index_set.h:1011
virtual std::size_t memory_consumption() const override
virtual real_type l2_norm() const override
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:362
virtual void scale(const VectorSpaceVector< Number > &scaling_factors) override
virtual void sadd(const Number s, const Number a, const VectorSpaceVector< Number > &V) override
void swap(LinearAlgebra::CUDAWrappers::Vector< Number > &u, LinearAlgebra::CUDAWrappers::Vector< Number > &v)
Definition: cuda_vector.h:361
virtual void import(const ReadWriteVector< Number > &V, VectorOperation::values operation, std::shared_ptr< const CommunicationPatternBase > communication_pattern=std::shared_ptr< const CommunicationPatternBase >()) override
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:382
virtual real_type linfty_norm() const override