Reference documentation for deal.II version 9.2.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 - 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  {
55  template <typename Number>
56  class Vector : public VectorSpaceVector<Number>
57  {
58  public:
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 
117  virtual void
118  swap(Vector<Number> &v);
119 
125  void
126  reinit(const size_type n, const bool omit_zeroing_entries = false);
127 
132  virtual void
133  reinit(const VectorSpaceVector<Number> &V,
134  const bool omit_zeroing_entries = false) override;
135 
144  virtual void
145  import(
146  const ReadWriteVector<Number> & V,
147  VectorOperation::values operation,
148  std::shared_ptr<const CommunicationPatternBase> communication_pattern =
149  std::shared_ptr<const CommunicationPatternBase>()) override;
150 
155  virtual Vector<Number> &
156  operator=(const Number s) override;
157 
161  virtual Vector<Number> &
162  operator*=(const Number factor) override;
163 
167  virtual Vector<Number> &
168  operator/=(const Number factor) override;
169 
173  virtual Vector<Number> &
174  operator+=(const VectorSpaceVector<Number> &V) override;
175 
179  virtual Vector<Number> &
180  operator-=(const VectorSpaceVector<Number> &V) override;
181 
185  virtual Number
186  operator*(const VectorSpaceVector<Number> &V) const override;
187 
191  virtual void
192  add(const Number a) override;
193 
197  virtual void
198  add(const Number a, const VectorSpaceVector<Number> &V) override;
199 
203  virtual void
204  add(const Number a,
205  const VectorSpaceVector<Number> &V,
206  const Number b,
207  const VectorSpaceVector<Number> &W) override;
208 
213  virtual void
214  sadd(const Number s,
215  const Number a,
216  const VectorSpaceVector<Number> &V) override;
217 
223  virtual void
224  scale(const VectorSpaceVector<Number> &scaling_factors) override;
225 
229  virtual void
230  equ(const Number a, const VectorSpaceVector<Number> &V) override;
231 
235  virtual bool
236  all_zero() const override;
237 
241  virtual value_type
242  mean_value() const override;
243 
248  virtual real_type
249  l1_norm() const override;
250 
255  virtual real_type
256  l2_norm() const override;
257 
261  real_type
262  norm_sqr() const;
263 
268  virtual real_type
269  linfty_norm() const override;
270 
290  virtual Number
291  add_and_dot(const Number a,
292  const VectorSpaceVector<Number> &V,
293  const VectorSpaceVector<Number> &W) override;
294 
299  Number *
300  get_values() const;
301 
305  virtual size_type
306  size() const override;
307 
312  virtual ::IndexSet
313  locally_owned_elements() const override;
314 
318  virtual void
319  print(std::ostream & out,
320  const unsigned int precision = 2,
321  const bool scientific = true,
322  const bool across = true) const override;
323 
327  virtual std::size_t
328  memory_consumption() const override;
329 
336 
337  private:
341  std::unique_ptr<Number[], void (*)(Number *)> val;
342 
347  };
348  } // namespace CUDAWrappers
349 } // namespace LinearAlgebra
350 
351 // ---------------------------- Inline functions --------------------------
352 
361 template <typename Number>
362 inline void
364  LinearAlgebra::CUDAWrappers::Vector<Number> &v)
365 {
366  u.swap(v);
367 }
368 
369 namespace LinearAlgebra
370 {
371  namespace CUDAWrappers
372  {
373  template <typename Number>
374  inline Number *
376  {
377  return val.get();
378  }
379 
380 
381 
382  template <typename Number>
383  inline typename Vector<Number>::size_type
385  {
386  return n_elements;
387  }
388 
389 
390  template <typename Number>
391  inline IndexSet
393  {
395  }
396 
397 
398 
399  template <typename Number>
400  inline void
402  {
403  std::swap(val, v.val);
405  }
406  } // namespace CUDAWrappers
407 } // namespace LinearAlgebra
408 
410 
411 #endif
412 
413 #endif
LinearAlgebra::CUDAWrappers::Vector::mean_value
virtual value_type mean_value() const override
LinearAlgebra::CUDAWrappers::Vector::swap
virtual void swap(Vector< Number > &v)
Definition: cuda_vector.h:401
IndexSet
Definition: index_set.h:74
LinearAlgebra::CUDAWrappers::Vector::print
virtual void print(std::ostream &out, const unsigned int precision=2, const bool scientific=true, const bool across=true) const override
LinearAlgebra::CUDAWrappers::Vector::equ
virtual void equ(const Number a, const VectorSpaceVector< Number > &V) override
LinearAlgebra::CUDAWrappers::Vector::reinit
void reinit(const size_type n, const bool omit_zeroing_entries=false)
LinearAlgebra
Definition: communication_pattern_base.h:30
LinearAlgebra::CUDAWrappers::Vector::value_type
typename VectorSpaceVector< Number >::value_type value_type
Definition: cuda_vector.h:59
LAPACKSupport::V
static const char V
Definition: lapack_support.h:175
LinearAlgebra::CUDAWrappers::Vector::l2_norm
virtual real_type l2_norm() const override
VectorOperation
Definition: vector_operation.h:38
LinearAlgebra::CUDAWrappers::Vector::size_type
typename VectorSpaceVector< Number >::size_type size_type
Definition: cuda_vector.h:60
LinearAlgebra::VectorSpaceVector::real_type
typename numbers::NumberTraits< Number >::real_type real_type
Definition: vector_space_vector.h:62
LinearAlgebra::CUDAWrappers::Vector::val
std::unique_ptr< Number[], void(*)(Number *)> val
Definition: cuda_vector.h:341
LinearAlgebra::CUDAWrappers::Vector::linfty_norm
virtual real_type linfty_norm() const override
vector_space_vector.h
LinearAlgebra::CUDAWrappers::Vector
Definition: cuda_vector.h:56
LinearAlgebra::VectorSpaceVector::value_type
Number value_type
Definition: vector_space_vector.h:60
LinearAlgebra::CUDAWrappers::Vector::ExcVectorTypeNotCompatible
static ::ExceptionBase & ExcVectorTypeNotCompatible()
LinearAlgebra::CUDAWrappers::Vector::size
virtual size_type size() const override
Definition: cuda_vector.h:384
LinearAlgebra::CUDAWrappers::Vector::get_values
Number * get_values() const
Definition: cuda_vector.h:375
vector_operation.h
CUDAWrappers
Definition: cuda_size.h:23
index_set.h
LinearAlgebra::CUDAWrappers::Vector::n_elements
size_type n_elements
Definition: cuda_vector.h:346
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
LinearAlgebra::CUDAWrappers::Vector::import
virtual void import(const ReadWriteVector< Number > &V, VectorOperation::values operation, std::shared_ptr< const CommunicationPatternBase > communication_pattern=std::shared_ptr< const CommunicationPatternBase >()) override
LinearAlgebra::CUDAWrappers::Vector::norm_sqr
real_type norm_sqr() const
LinearAlgebra::CUDAWrappers::Vector::l1_norm
virtual real_type l1_norm() const override
Physics::Elasticity::Kinematics::b
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
LinearAlgebra::CUDAWrappers::Vector::all_zero
virtual bool all_zero() const override
LinearAlgebra::CUDAWrappers::Vector::locally_owned_elements
virtual ::IndexSet locally_owned_elements() const override
Definition: cuda_vector.h:392
LinearAlgebra::CUDAWrappers::Vector::add_and_dot
virtual Number add_and_dot(const Number a, const VectorSpaceVector< Number > &V, const VectorSpaceVector< Number > &W) override
LinearAlgebra::CUDAWrappers::Vector::memory_consumption
virtual std::size_t memory_consumption() const override
LinearAlgebra::ReadWriteVector
Definition: read_write_vector.h:131
exceptions.h
complete_index_set
IndexSet complete_index_set(const IndexSet::size_type N)
Definition: index_set.h:1014
unsigned int
LinearAlgebra::CUDAWrappers::Vector::add
virtual void add(const Number a) override
LinearAlgebra::VectorSpaceVector
Definition: vector_space_vector.h:57
DeclException0
#define DeclException0(Exception0)
Definition: exceptions.h:473
config.h
swap
void swap(LinearAlgebra::CUDAWrappers::Vector< Number > &u, LinearAlgebra::CUDAWrappers::Vector< Number > &v)
Definition: cuda_vector.h:363
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
LinearAlgebra::CUDAWrappers::Vector::sadd
virtual void sadd(const Number s, const Number a, const VectorSpaceVector< Number > &V) override
LinearAlgebra::CUDAWrappers::Vector::scale
virtual void scale(const VectorSpaceVector< Number > &scaling_factors) override
LinearAlgebra::CUDAWrappers::Vector::real_type
typename VectorSpaceVector< Number >::real_type real_type
Definition: cuda_vector.h:61
LinearAlgebra::CommunicationPatternBase
Definition: communication_pattern_base.h:42
LinearAlgebra::CUDAWrappers::Vector::Vector
Vector()