Alsvinn  0.5.3
The fast FVM simulator with UQ support
Public Member Functions | Protected Attributes | List of all members
alsfvm::memory::Memory< T > Class Template Referenceabstract

#include <alsfvm/memory/Memory.hpp>

Inheritance diagram for alsfvm::memory::Memory< T >:
alsfvm::memory::MemoryBase alsfvm::cuda::CudaMemory< T > alsfvm::memory::HostMemory< T >

Public Member Functions

 Memory (size_t nx, size_t ny, size_t nz)
 Memory constructs new memory. More...
 
virtual ~Memory ()
 
virtual size_t getSize () const
 
virtual size_t getSizeX () const
 
virtual size_t getSizeY () const
 
virtual size_t getSizeZ () const
 
virtual std::shared_ptr< Memory< T > > makeInstance () const =0
 Clones the memory area, but does not copy the content More...
 
virtual void copyFrom (const Memory< T > &other)=0
 Copies the contents of the other memory area into this one. More...
 
virtual size_t getExtentXInBytes () const
 
virtual size_t getExtentYInBytes () const
 
virtual bool isOnHost () const =0
 
T * data ()
 
const T * data () const
 
T & operator[] (size_t i)
 
operator[] (size_t i) const
 
operator() (int x, int y, int z) const
 
T & operator() (int x, int y, int z)
 
virtual T * getPointer ()=0
 
virtual const T * getPointer () const =0
 
virtual void copyToHost (T *bufferPointer, size_t bufferLength) const =0
 
virtual void copyFromHost (const T *bufferPointer, size_t bufferLength)=0
 
virtual void operator+= (const Memory< T > &other)=0
 
virtual void operator*= (const Memory< T > &other)=0
 
virtual void operator-= (const Memory< T > &other)=0
 
virtual void operator/= (const Memory< T > &other)=0
 
virtual void operator+= (real scalar)=0
 
virtual void operator*= (real scalar)=0
 
virtual void operator-= (real scalar)=0
 
virtual void operator/= (real scalar)=0
 
virtual void makeZero ()=0
 makeZero sets every element to zero (0) More...
 
virtual void copyInternalCells (size_t startX, size_t endX, size_t startY, size_t endY, size_t startZ, size_t endZ, T *output, size_t outputSize)=0
 copyInternalCells copies the internal cells into the memory area This is ideal for removing ghost cells before outputing the solution. More...
 
View< T > getView ()
 getView gets the view to the memory More...
 
View< const T > getView () const
 getView gets the view to the memory (const version) More...
 
virtual void addLinearCombination (T a1, T a2, const Memory< T > &v2, T a3, const Memory< T > &v3, T a4, const Memory< T > &v4, T a5, const Memory< T > &v5)=0
 
virtual void addPower (const Memory< T > &other, double power)=0
 
virtual void addPower (const Memory< T > &other, double power, double factor)=0
 
virtual void subtractPower (const Memory< T > &other, double power)=0
 
virtual std::shared_ptr< Memory< T > > getHostMemory ()=0
 Copies the data to host if it is on GPU, otherwise makes a copy. More...
 
virtual const std::shared_ptr< const Memory< T > > getHostMemory () const =0
 
virtual real getTotalVariation (int p, const ivec3 &start, const ivec3 &end) const =0
 
virtual real getTotalVariation (int direction, int p, const ivec3 &start, const ivec3 &end) const =0
 
- Public Member Functions inherited from alsfvm::memory::MemoryBase
 MemoryBase ()
 
virtual ~MemoryBase ()
 

Protected Attributes

const size_t nx
 
const size_t ny
 
const size_t nz
 

Detailed Description

template<class T>
class alsfvm::memory::Memory< T >

Class to hold data. Do note that this is an abstract interface, look at the other concrete implementations to use this.

Constructor & Destructor Documentation

◆ Memory()

template<class T >
alsfvm::memory::Memory< T >::Memory ( size_t  nx,
size_t  ny,
size_t  nz 
)

Memory constructs new memory.

Parameters
nxthe number of cells in x direction
nythe number of cells in y direction
nzthe number of cells in z direction

◆ ~Memory()

template<class T>
virtual alsfvm::memory::Memory< T >::~Memory ( )
inlinevirtual

Member Function Documentation

◆ addLinearCombination()

template<class T>
virtual void alsfvm::memory::Memory< T >::addLinearCombination ( a1,
a2,
const Memory< T > &  v2,
a3,
const Memory< T > &  v3,
a4,
const Memory< T > &  v4,
a5,
const Memory< T > &  v5 
)
pure virtual

Adds the memory with coefficients to this memory area Here we compute the sum

\[ v_1^{\mathrm{new}}=a_1v_1+a_2v_2+a_3v_3+a_4v_4+a_5v_5+a_6v_6\]

where $v_1$ is the volume being operated on.

Implemented in alsfvm::memory::HostMemory< T >, and alsfvm::cuda::CudaMemory< T >.

◆ addPower() [1/2]

template<class T>
virtual void alsfvm::memory::Memory< T >::addPower ( const Memory< T > &  other,
double  power 
)
pure virtual

Adds a power of the other memory area to this memory area, ie

\[this += pow(other, power)\]

Parameters
otherthe other memory area to the the power of
powerthe power to use

Implemented in alsfvm::memory::HostMemory< T >, and alsfvm::cuda::CudaMemory< T >.

◆ addPower() [2/2]

template<class T>
virtual void alsfvm::memory::Memory< T >::addPower ( const Memory< T > &  other,
double  power,
double  factor 
)
pure virtual

Adds a power of the other memory area to this memory area, ie

\[this += factor*pow(other, power)\]

Parameters
otherthe other memory area to the the power of
powerthe power to use
factorthe factor to multiply

Implemented in alsfvm::memory::HostMemory< T >, and alsfvm::cuda::CudaMemory< T >.

◆ copyFrom()

template<class T>
virtual void alsfvm::memory::Memory< T >::copyFrom ( const Memory< T > &  other)
pure virtual

Copies the contents of the other memory area into this one.

Implemented in alsfvm::memory::HostMemory< T >, and alsfvm::cuda::CudaMemory< T >.

◆ copyFromHost()

template<class T>
virtual void alsfvm::memory::Memory< T >::copyFromHost ( const T *  bufferPointer,
size_t  bufferLength 
)
pure virtual

Copies the memory from the buffer (assumed to be on Host/CPU)

Note
bufferLength must be at least getSize()
Parameters
bufferPointerthe buffer to write to
bufferLengththe size of the buffer (in number of T's)

Implemented in alsfvm::memory::HostMemory< T >, and alsfvm::cuda::CudaMemory< T >.

◆ copyInternalCells()

template<class T>
virtual void alsfvm::memory::Memory< T >::copyInternalCells ( size_t  startX,
size_t  endX,
size_t  startY,
size_t  endY,
size_t  startZ,
size_t  endZ,
T *  output,
size_t  outputSize 
)
pure virtual

copyInternalCells copies the internal cells into the memory area This is ideal for removing ghost cells before outputing the solution.

Parameters
startXstart index (inclusive) for x direction
endXend index (exclusive) for x direction
startYstart index (inclusive) for y direction
endYend index (exclusive) for y direction
startZstart index (inclusive) for z direction
endZend index (exclusive) for z direction
outputthe output buffer
outputSizemust be at least the size of the written memory

This is essentially equivalent to doing

size_t numberOfZ = endZ-startZ;
size_t numberOfY = endY-startY;
size_t numberOfX = endX-startX;
for(size_t z = startZ; z < endZ; z++) {
for(size_t y = startY; y < endY; y++) {
for(size_t x = startX; x < endX; x++) {
size_t indexIn = z * nx * ny + y * nx + x;
size_t indexOut = (z-startZ) * numberOfX * numberOfY
+ (y - startY) * numberOfY + (x - startX);
output[indexOut] = data[indexIn];
}
}
}

Implemented in alsfvm::memory::HostMemory< T >, and alsfvm::cuda::CudaMemory< T >.

◆ copyToHost()

template<class T>
virtual void alsfvm::memory::Memory< T >::copyToHost ( T *  bufferPointer,
size_t  bufferLength 
) const
pure virtual

Copies the memory to the given buffer

Note
bufferLength must be at least getSize()
Parameters
bufferPointerthe buffer to write to
bufferLengththe size of the buffer (in number of T's)

Implemented in alsfvm::memory::HostMemory< T >, and alsfvm::cuda::CudaMemory< T >.

◆ data() [1/2]

template<class T>
T* alsfvm::memory::Memory< T >::data ( )
inline

◆ data() [2/2]

template<class T>
const T* alsfvm::memory::Memory< T >::data ( ) const
inline

◆ getExtentXInBytes()

template<class T >
size_t alsfvm::memory::Memory< T >::getExtentXInBytes ( ) const
virtual
Returns
the size (in bytes) of the memory in X direction.
Note
use this for indexing
const size_t extentX = memory.getExtentXInBytes();
const size_t extentY = memory.getExtentYInBytes();
size_t indexByte = i*extentX*ExtentY+j*extentX+k;

◆ getExtentYInBytes()

template<class T >
size_t alsfvm::memory::Memory< T >::getExtentYInBytes ( ) const
virtual
Returns
the size (in bytes) of the memory in Y direction.
Note
use this for indexing
const size_t extentX = memory.getExtentXInBytes();
const size_t extentY = memory.getExtentYInBytes();
size_t indexByte = i*extentX*ExtentY+j*extentX+k;

◆ getHostMemory() [1/2]

template<class T>
virtual std::shared_ptr<Memory<T> > alsfvm::memory::Memory< T >::getHostMemory ( )
pure virtual

Copies the data to host if it is on GPU, otherwise makes a copy.

Implemented in alsfvm::memory::HostMemory< T >, and alsfvm::cuda::CudaMemory< T >.

◆ getHostMemory() [2/2]

template<class T>
virtual const std::shared_ptr<const Memory<T> > alsfvm::memory::Memory< T >::getHostMemory ( ) const
pure virtual

Copies the data to host if it is on GPU, otherwise makes a copy Const version

Implemented in alsfvm::memory::HostMemory< T >, and alsfvm::cuda::CudaMemory< T >.

◆ getPointer() [1/2]

template<class T>
virtual T* alsfvm::memory::Memory< T >::getPointer ( )
pure virtual

Gets the pointer to the data (need not be on the host!)

Note
If this is an OpenCL implementation, the pointer will be useless! If you want to use the OpenCL memory, you should first cast to OpenCL memory, then get the OpenCL buffer pointer.

Implemented in alsfvm::memory::HostMemory< T >, and alsfvm::cuda::CudaMemory< T >.

◆ getPointer() [2/2]

template<class T>
virtual const T* alsfvm::memory::Memory< T >::getPointer ( ) const
pure virtual

Gets the pointer to the data (need not be on the host!)

Note
If this is an OpenCL implementation, the pointer will be useless! If you want to use the OpenCL memory, you should first cast to OpenCL memory, then get the OpenCL buffer pointer.

Implemented in alsfvm::memory::HostMemory< T >, and alsfvm::cuda::CudaMemory< T >.

◆ getSize()

template<class T >
size_t alsfvm::memory::Memory< T >::getSize ( ) const
virtual
Returns
the size (in number of T) of the memory

◆ getSizeX()

template<class T >
size_t alsfvm::memory::Memory< T >::getSizeX ( ) const
virtual
Returns
the size (in number of T) of the memory in X diretion

◆ getSizeY()

template<class T >
size_t alsfvm::memory::Memory< T >::getSizeY ( ) const
virtual
Returns
the size (in number of T) of the memory in Y diretion

◆ getSizeZ()

template<class T >
size_t alsfvm::memory::Memory< T >::getSizeZ ( ) const
virtual
Returns
the size (in number of T) of the memory in Z diretion

◆ getTotalVariation() [1/2]

template<class T>
virtual real alsfvm::memory::Memory< T >::getTotalVariation ( int  p,
const ivec3 start,
const ivec3 end 
) const
pure virtual

Computes the total variation, given here as

\[\sum_{i,j,k} \sqrt(\sum_{n=1}^d|u_{(i,j,k)}-u_{(i,j,k)-e_n}|^2)^p.\]

Note
This function gives no performance guarantees
Parameters
pthe exponent p
startthe index to start at (inclusive)
endthe maximum index (exclusive)

Implemented in alsfvm::memory::HostMemory< T >, and alsfvm::cuda::CudaMemory< T >.

◆ getTotalVariation() [2/2]

template<class T>
virtual real alsfvm::memory::Memory< T >::getTotalVariation ( int  direction,
int  p,
const ivec3 start,
const ivec3 end 
) const
pure virtual

$

\[\sum_{i,j,k} |u_{(i,j,k)}-u_{(i,j,k)-e_n}|^p.\]

Note
This function gives no performance guarantees
Parameters
pthe exponent p
directionthe direction (between 0 and 2 inclusive)
startthe index to start at (inclusive)
endthe maximum index (exclusive)

Implemented in alsfvm::memory::HostMemory< T >, and alsfvm::cuda::CudaMemory< T >.

◆ getView() [1/2]

template<class T >
View< T > alsfvm::memory::Memory< T >::getView ( )

getView gets the view to the memory

Returns
the view

◆ getView() [2/2]

template<class T >
View< const T > alsfvm::memory::Memory< T >::getView ( ) const

getView gets the view to the memory (const version)

Returns
the view

◆ isOnHost()

template<class T>
virtual bool alsfvm::memory::Memory< T >::isOnHost ( ) const
pure virtual

Checks if the memory area is on the host (CPU) or on some device, if the latter, one needs to copy to host before reading it.

Returns
true if the memory is on host, false otherwise

Implemented in alsfvm::cuda::CudaMemory< T >, and alsfvm::memory::HostMemory< T >.

◆ makeInstance()

template<class T>
virtual std::shared_ptr<Memory<T> > alsfvm::memory::Memory< T >::makeInstance ( ) const
pure virtual

Clones the memory area, but does not copy the content

Implemented in alsfvm::memory::HostMemory< T >, and alsfvm::cuda::CudaMemory< T >.

◆ makeZero()

template<class T>
virtual void alsfvm::memory::Memory< T >::makeZero ( )
pure virtual

makeZero sets every element to zero (0)

Implemented in alsfvm::memory::HostMemory< T >, and alsfvm::cuda::CudaMemory< T >.

◆ operator()() [1/2]

template<class T>
T alsfvm::memory::Memory< T >::operator() ( int  x,
int  y,
int  z 
) const
inline

◆ operator()() [2/2]

template<class T>
T& alsfvm::memory::Memory< T >::operator() ( int  x,
int  y,
int  z 
)
inline

◆ operator*=() [1/2]

template<class T>
virtual void alsfvm::memory::Memory< T >::operator*= ( const Memory< T > &  other)
pure virtual

Mutliplies the other memory area to this one

Parameters
otherthe memory area to multiply from

Implemented in alsfvm::memory::HostMemory< T >, and alsfvm::cuda::CudaMemory< T >.

◆ operator*=() [2/2]

template<class T>
virtual void alsfvm::memory::Memory< T >::operator*= ( real  scalar)
pure virtual

Multiplies the scalar to each component

Parameters
scalarthe scalar to multiply

Implemented in alsfvm::memory::HostMemory< T >, and alsfvm::cuda::CudaMemory< T >.

◆ operator+=() [1/2]

template<class T>
virtual void alsfvm::memory::Memory< T >::operator+= ( const Memory< T > &  other)
pure virtual

Adds the other memory area to this one

Parameters
otherthe memory area to add from

Implemented in alsfvm::memory::HostMemory< T >, and alsfvm::cuda::CudaMemory< T >.

◆ operator+=() [2/2]

template<class T>
virtual void alsfvm::memory::Memory< T >::operator+= ( real  scalar)
pure virtual

Adds the scalar to each component

Parameters
scalarthe scalar to add

Implemented in alsfvm::memory::HostMemory< T >, and alsfvm::cuda::CudaMemory< T >.

◆ operator-=() [1/2]

template<class T>
virtual void alsfvm::memory::Memory< T >::operator-= ( const Memory< T > &  other)
pure virtual

Subtracts the other memory area to this one

Parameters
otherthe memory area to subtract from

Implemented in alsfvm::memory::HostMemory< T >, and alsfvm::cuda::CudaMemory< T >.

◆ operator-=() [2/2]

template<class T>
virtual void alsfvm::memory::Memory< T >::operator-= ( real  scalar)
pure virtual

Subtracts the scalar from each component

Parameters
scalarthe scalar to subtract

Implemented in alsfvm::memory::HostMemory< T >, and alsfvm::cuda::CudaMemory< T >.

◆ operator/=() [1/2]

template<class T>
virtual void alsfvm::memory::Memory< T >::operator/= ( const Memory< T > &  other)
pure virtual

Divides the other memory area to this one

Parameters
otherthe memory area to divide from

Implemented in alsfvm::memory::HostMemory< T >, and alsfvm::cuda::CudaMemory< T >.

◆ operator/=() [2/2]

template<class T>
virtual void alsfvm::memory::Memory< T >::operator/= ( real  scalar)
pure virtual

Divides the each component by the scalar

Parameters
scalarthe scalar to divide

Implemented in alsfvm::memory::HostMemory< T >, and alsfvm::cuda::CudaMemory< T >.

◆ operator[]() [1/2]

template<class T>
T& alsfvm::memory::Memory< T >::operator[] ( size_t  i)
inline

◆ operator[]() [2/2]

template<class T>
T alsfvm::memory::Memory< T >::operator[] ( size_t  i) const
inline

◆ subtractPower()

template<class T>
virtual void alsfvm::memory::Memory< T >::subtractPower ( const Memory< T > &  other,
double  power 
)
pure virtual

Subtracts a power of the other memory area to this memory area, ie

\[this -= pow(other, power)\]

Parameters
otherthe other memory area to the the power of
powerthe power to use

Implemented in alsfvm::memory::HostMemory< T >, and alsfvm::cuda::CudaMemory< T >.

Member Data Documentation

◆ nx

template<class T>
const size_t alsfvm::memory::Memory< T >::nx
protected

◆ ny

template<class T>
const size_t alsfvm::memory::Memory< T >::ny
protected

◆ nz

template<class T>
const size_t alsfvm::memory::Memory< T >::nz
protected

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