Skip to content

Commit

Permalink
Get rid of VectorSpaceVector in the Cuda Vector class.
Browse files Browse the repository at this point in the history
  • Loading branch information
bangerth committed Jul 4, 2023
1 parent bd1bf2c commit 5e6391f
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 172 deletions.
128 changes: 62 additions & 66 deletions include/deal.II/lac/cuda_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,20 @@ namespace LinearAlgebra
namespace CUDAWrappers
{
/**
* This class implements a vector using CUDA for use on Nvidia GPUs. This
* class is derived from the LinearAlgebra::VectorSpaceVector class.
* This class implements a vector using CUDA for use on Nvidia GPUs.
*
* @note Only float and double are supported.
*
* @see CUDAWrappers
* @ingroup Vectors
*/
template <typename Number>
class Vector : public VectorSpaceVector<Number>
class Vector
{
public:
using value_type = typename VectorSpaceVector<Number>::value_type;
using size_type = typename VectorSpaceVector<Number>::size_type;
using real_type = typename VectorSpaceVector<Number>::real_type;
using value_type = Number;
using size_type = types::global_dof_index;
using real_type = typename numbers::NumberTraits<Number>::real_type;

/**
* Constructor. Create a vector of dimension zero.
Expand Down Expand Up @@ -110,10 +109,10 @@ namespace LinearAlgebra
* <tt>swap(u,v)</tt> that simply calls <tt>u.swap(v)</tt>, again in
* analogy to standard functions.
*
* This function is virtual in order to allow for derived classes to
* This function is in order to allow for derived classes to
* handle memory separately.
*/
virtual void
void
swap(Vector<Number> &v);

/**
Expand All @@ -128,9 +127,8 @@ namespace LinearAlgebra
* Change the dimension to that of the vector V. The elements of V are not
* copied.
*/
virtual void
reinit(const VectorSpaceVector<Number> &V,
const bool omit_zeroing_entries = false) override;
void
reinit(const Vector<Number> &V, const bool omit_zeroing_entries = false);

/**
* Import all the element from the input vector @p V.
Expand All @@ -140,21 +138,21 @@ namespace LinearAlgebra
* for distributed vectors. This is the function that should be used to
* copy a vector to the GPU.
*/
virtual void
void
import_elements(
const ReadWriteVector<Number> &V,
VectorOperation::values operation,
std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
communication_pattern = {}) override;
communication_pattern = {});

/**
* @deprecated Use import_elements() instead.
*/
DEAL_II_DEPRECATED virtual void
DEAL_II_DEPRECATED void
import(const ReadWriteVector<Number> &V,
VectorOperation::values operation,
std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
communication_pattern = {}) override
communication_pattern = {})
{
import_elements(V, operation, communication_pattern);
}
Expand All @@ -163,108 +161,106 @@ namespace LinearAlgebra
* Sets all elements of the vector to the scalar @p s. This operation is
* only allowed if @p s is equal to zero.
*/
virtual Vector<Number> &
operator=(const Number s) override;
Vector<Number> &
operator=(const Number s);

/**
* Multiply the entive vector by a fixed factor.
*/
virtual Vector<Number> &
operator*=(const Number factor) override;
Vector<Number> &
operator*=(const Number factor);

/**
* Divide the entire vector by a fixed factor.
*/
virtual Vector<Number> &
operator/=(const Number factor) override;
Vector<Number> &
operator/=(const Number factor);

/**
* Add the vector @p V to the present one.
*/
virtual Vector<Number> &
operator+=(const VectorSpaceVector<Number> &V) override;
Vector<Number> &
operator+=(const Vector<Number> &V);

/**
* Subtract the vector @p V from the present one.
*/
virtual Vector<Number> &
operator-=(const VectorSpaceVector<Number> &V) override;
Vector<Number> &
operator-=(const Vector<Number> &V);

/**
* Return the scalar product of two vectors.
*/
virtual Number
operator*(const VectorSpaceVector<Number> &V) const override;
Number
operator*(const Vector<Number> &V) const;

/**
* Add @p to all components. Note that @p a is a scalar not a vector.
*/
virtual void
add(const Number a) override;
void
add(const Number a);

/**
* Simple addition of a multiple of a vector, i.e. <tt>*this += a*V</tt>.
*/
virtual void
add(const Number a, const VectorSpaceVector<Number> &V) override;
void
add(const Number a, const Vector<Number> &V);

/**
* Multiple additions of scaled vectors, i.e. <tt>*this += a*V+b*W</tt>.
*/
virtual void
add(const Number a,
const VectorSpaceVector<Number> &V,
const Number b,
const VectorSpaceVector<Number> &W) override;
void
add(const Number a,
const Vector<Number> &V,
const Number b,
const Vector<Number> &W);

/**
* Scaling and simple addition of a multiple of a vector, i.e. <tt>*this
* = s*(*this)+a*V</tt>
*/
virtual void
sadd(const Number s,
const Number a,
const VectorSpaceVector<Number> &V) override;
void
sadd(const Number s, const Number a, const Vector<Number> &V);

/**
* Scale each element of this vector by the corresponding element in the
* argument. This function is mostly meant to simulate multiplication
* (and immediate re-assignment) by a diagonal scaling matrix.
*/
virtual void
scale(const VectorSpaceVector<Number> &scaling_factors) override;
void
scale(const Vector<Number> &scaling_factors);

/**
* Assignment <tt>*this = a*V</tt>.
*/
virtual void
equ(const Number a, const VectorSpaceVector<Number> &V) override;
void
equ(const Number a, const Vector<Number> &V);

/**
* Return whether the vector contains only elements with value zero.
*/
virtual bool
all_zero() const override;
bool
all_zero() const;

/**
* Return the mean value of all the entries of this vector.
*/
virtual value_type
mean_value() const override;
value_type
mean_value() const;

/**
* Return the l<sub>1</sub> norm of the vector (i.e., the sum of the
* absolute values of all entries among all processors).
*/
virtual real_type
l1_norm() const override;
real_type
l1_norm() const;

/**
* Return the l<sub>2</sub> norm of the vector (i.e., the square root of
* the sum of the square of all entries among all processors).
*/
virtual real_type
l2_norm() const override;
real_type
l2_norm() const;

/**
* Return the square of the $l_2$-norm.
Expand All @@ -276,8 +272,8 @@ namespace LinearAlgebra
* Return the maximum norm of the vector (i.e., the maximum absolute
* value among all entries and among all processors).
*/
virtual real_type
linfty_norm() const override;
real_type
linfty_norm() const;

/**
* Perform a combined operation of a vector addition and a subsequent
Expand All @@ -298,10 +294,10 @@ namespace LinearAlgebra
* For complex-valued vectors, the scalar product in the second step is
* implemented as $\left<v,w\right>=\sum_i v_i \bar{w_i}$.
*/
virtual Number
add_and_dot(const Number a,
const VectorSpaceVector<Number> &V,
const VectorSpaceVector<Number> &W) override;
Number
add_and_dot(const Number a,
const Vector<Number> &V,
const Vector<Number> &W);

/**
* Return the pointer to the underlying array. Ownership still resides
Expand All @@ -313,30 +309,30 @@ namespace LinearAlgebra
/**
* Return the size of the vector.
*/
virtual size_type
size() const override;
size_type
size() const;

/**
* Return an index set that describe which elements of this vector are
* owned by the current processor, i.e. [0, size).
*/
virtual dealii::IndexSet
locally_owned_elements() const override;
dealii::IndexSet
locally_owned_elements() const;

/**
* Print the vector to the output stream @p out.
*/
virtual void
void
print(std::ostream & out,
const unsigned int precision = 2,
const bool scientific = true,
const bool across = true) const override;
const bool across = true) const;

/**
* Return the memory consumption of this class in bytes.
*/
virtual std::size_t
memory_consumption() const override;
std::size_t
memory_consumption() const;

/**
* Attempt to perform an operation between two incompatible vector types.
Expand Down

0 comments on commit 5e6391f

Please sign in to comment.