Device Vector

template<typename NumType>
class DeviceVector : public BaseVector<NumType>

Implementation of a Vector class on the NVIDIA GPU system, referred to as the device system.

Template Parameters
  • NumType: Number type (double and float currently supported).

Public Functions

DeviceVector()

Default constructor.

virtual ~DeviceVector()

Destructor.

virtual void allocate(int n)

Allocate a size of n to the vector.

Parameters
  • n: The size of vector.

virtual void clear()

Clear vector.

virtual void copy_from(const NumType *w)

Copy from the inputted data to the vector.

Note
allocate should be called first.
Parameters
  • w: The pointer to the data (on the device system) to copy from.

virtual void copy_from(const BaseVector<NumType> &w)

Copy from the inputted vector to itself.

Parameters
  • w: The vector to copy from.

virtual void copy_from_host(const NumType *w)

Copy from the inputted data to the vector.

Note
allocate should be called first.
Parameters
  • w: The pointer to the data (on the host system) to copy from.

virtual void copy_to(NumType *w) const

Output the vector’s values.

Note
device memory should be allocated to w before calling this function.
Parameters
  • w: The pointer to the data (on the device system) to copy to.

virtual void copy_to(BaseVector<NumType> &w) const

Copy the vector to outputted vector.

Parameters
  • w: The vector to copy to.

virtual void copy_to_host(NumType *w) const

Output the vector’s values.

Note
device memory should be allocated to w before calling this function.
Parameters
  • w: The pointer to the data (on the host system) to copy to.

virtual NumType norm() const

Return
The L2 norm of the vector.

virtual NumType dot(const BaseVector<NumType> &w) const

Return the dot product between itself and another vector.

Return
The dot product.
Parameters
  • w: The other vector

virtual void zeros()

Sets all values of the vector to zero.

virtual void ones()

Sets all values of the vector to one.

virtual void scale(NumType alpha)

Scale the vector.

Parameters
  • alpha: the value by which to scale the vector.

virtual void add(NumType alpha, const BaseVector<NumType> &w, NumType beta)

v = alpha * v + beta * w, where v is the vector itself.

Parameters
  • alpha: The value in the above equation.
  • w: The vector in the above equation.
  • beta: The value in the above equation.

virtual void add_scale(NumType alpha, const BaseVector<NumType> &w)

v = v + alpha * w, where v is the vector itself.

Parameters
  • alpha: The value in the above equation.
  • w: The vector in the above equation.

virtual void scale_add(NumType alpha, const BaseVector<NumType> &w)

v = alpha * v + w, where v is the vector itself.

Parameters
  • alpha: The value in the above equation.
  • w: The vector in the above equation.

virtual void elementwise_multiply(const BaseVector<NumType> &w)

v = v .* w, where v is the vector itself and .* is the elementwise multiplication operator.

Parameters
  • w: The vector in the above equation.

virtual void elementwise_multiply(const BaseVector<NumType> &w, const BaseVector<NumType> &z)

v = w .* z, where v is the vector itself and .* is the elementwise multiplication operator.

Parameters
  • w: The vector in the above equation.
  • z: The vector in the above equation.