fml  0.1-0
Fused Matrix Library
fml::gpuvec< T > Class Template Reference

Vector class for data held on a single GPU. More...

#include <gpuvec.hh>

Inheritance diagram for fml::gpuvec< T >:
fml::univec< T >

Public Member Functions

 gpuvec (std::shared_ptr< card > gpu)
 
 gpuvec (std::shared_ptr< card > gpu, len_t size)
 
 gpuvec (std::shared_ptr< card > gpu, T *data, len_t size, bool free_on_destruct=false)
 
 gpuvec (const gpuvec &x)
 
void resize (len_t size)
 Resize the internal object storage. More...
 
void resize (std::shared_ptr< card > gpu, len_t size)
 
void inherit (std::shared_ptr< card > gpu)
 
void inherit (std::shared_ptr< card > gpu, T *data, len_t size, bool free_on_destruct=false)
 
gpuvec< T > dupe () const
 Duplicate the object in a deep copy.
 
void print (uint8_t ndigits=4, bool add_final_blank=true) const
 Copy data from a CPU object to another. More...
 
void info () const
 Print some brief information about the object.
 
void fill_zero ()
 Set all values to zero.
 
void fill_val (const T v)
 Set all values to input value. More...
 
void fill_linspace ()
 Set values to linearly spaced numbers. More...
 
void fill_linspace (const T start, const T stop)
 
void scale (const T s)
 Multiply all values by the input value. More...
 
void pow (const T p)
 Raise every value of the vector to the given power. More...
 
void rev ()
 Reverse the vector.
 
sum () const
 Sum the vector.
 
max () const
 Maximum value of the vector.
 
min () const
 Minimum value of the vector.
 
get (const len_t i) const
 Get the specified value. More...
 
void set (const len_t i, const T v)
 Set the storage at the specified index with the provided value. More...
 
bool operator== (const gpuvec< T > &x) const
 See if the two objects are the same. More...
 
bool operator!= (const gpuvec< T > &x) const
 See if the two objects are not the same. Uses same internal logic as the == method. More...
 
gpuvec< T > & operator= (const gpuvec< T > &x)
 Operator that sets the LHS to a shallow copy of the input. Desctruction of the LHS object will not result in the internal array storage being freed. More...
 
std::shared_ptr< cardget_card () const
 
dim3 get_blockdim () const
 
dim3 get_griddim () const
 
- Public Member Functions inherited from fml::univec< T >
len_t size () const
 Number of elements in the vector.
 
T * data_ptr ()
 Pointer to the internal array.
 
T * data_ptr () const
 

Protected Attributes

std::shared_ptr< cardc
 
- Protected Attributes inherited from fml::univec< T >
len_t _size
 
T * data
 
bool free_data
 

Additional Inherited Members

- Protected Member Functions inherited from fml::univec< T >
bool should_free () const
 
void check_index (const len_t i) const
 
void printval (const T val, uint8_t ndigits) const
 
void printval (const int val, uint8_t ndigits) const
 

Detailed Description

template<typename T>
class fml::gpuvec< T >

Vector class for data held on a single GPU.

Template Parameters
Tshould be 'int', '__half', 'float' or 'double'.

Member Function Documentation

◆ fill_linspace()

template<typename T >
void fml::gpuvec< T >::fill_linspace

Set values to linearly spaced numbers.

Parameters
[in]start,stopBeginning/ending numbers. If not supplied, the vector will be filled with whole numbers from 1 to the total number of elements.

◆ fill_val()

template<typename T >
void fml::gpuvec< T >::fill_val ( const T  v)

Set all values to input value.

Parameters
[in]vValue to set all data values to.

◆ get()

template<typename T >
T fml::gpuvec< T >::get ( const len_t  i) const

Get the specified value.

Parameters
[in]iThe index of the desired value, 0-indexed.

Exceptions
If indices are out of bounds, the method will throw a runtime_error exception.

◆ operator!=()

template<typename T >
bool fml::gpuvec< T >::operator!= ( const gpuvec< T > &  x) const

See if the two objects are not the same. Uses same internal logic as the == method.

Parameters
[in]Comparisonobject.

◆ operator=()

template<typename T >
fml::gpuvec< T > & fml::gpuvec< T >::operator= ( const gpuvec< T > &  x)

Operator that sets the LHS to a shallow copy of the input. Desctruction of the LHS object will not result in the internal array storage being freed.

Parameters
[in]xSetter value.

◆ operator==()

template<typename T >
bool fml::gpuvec< T >::operator== ( const gpuvec< T > &  x) const

See if the two objects are the same.

Parameters
[in]Comparisonobject.
Returns
If the sizes mismatch, then false is necessarily returned. Next, if the pointer to the internal storage arrays match, then true is necessarily returned. Otherwise the objects are compared value by value.

◆ pow()

template<typename T >
void fml::gpuvec< T >::pow ( const T  p)

Raise every value of the vector to the given power.

Parameters
[in]pPower.

◆ print()

template<typename REAL >
void fml::gpuvec< REAL >::print ( uint8_t  ndigits = 4,
bool  add_final_blank = true 
) const

Copy data from a CPU object to another.

Parameters
[in]ndigitsNumber of decimal digits to print.
[in]add_final_blankShould a final blank line be printed?

◆ resize()

template<typename T >
void fml::gpuvec< T >::resize ( len_t  size)

Resize the internal object storage.

Parameters
[in]sizeLength of the vector needed.

Memory Allocations
Resizing triggers a re-allocation.

Exceptions
If the reallocation fails, a bad_alloc exception will be thrown. If the input values are invalid, a runtime_error exception will be thrown.

◆ scale()

template<typename T >
void fml::gpuvec< T >::scale ( const T  s)

Multiply all values by the input value.

Parameters
[in]sScaling value.

◆ set()

template<typename T >
void fml::gpuvec< T >::set ( const len_t  i,
const T  v 
)

Set the storage at the specified index with the provided value.

Parameters
[in]iThe index of the desired value, 0-indexed.
[in]vSetter value.

Exceptions
If indices are out of bounds, the method will throw a runtime_error exception.


The documentation for this class was generated from the following file: