LAMA
|
This class is a common base class for all possible contexts. More...
#include <Context.hpp>
Data Structures | |
struct | ContextData |
Public Types | |
enum | ContextType { Host, CUDA, OpenCL, MaxContext } |
Enumeration type for the supported contexts. More... | |
Public Member Functions | |
virtual | ~Context () |
ContextType | getType () const |
Method to get the type of the context. | |
bool | operator== (const Context &other) const |
This predicate returns true if two contexts can use same data and have the same type. | |
bool | operator!= (const Context &other) const |
The inequality operator is just the inverse to operator==. | |
virtual bool | canUseData (const Context &other) const =0 |
This predicate returns true if one context can use data of another context. | |
virtual void | writeAt (std::ostream &stream) const |
This method writes info about the device in the output stream The method should be overwritten by base classes to give more specific information about the device that might be useful for logging. | |
virtual void | allocate (ContextData &contextData, const size_t size) const =0 |
This method allocates memory and must be implemented by each Context. | |
virtual void | free (void *pointer, const size_t size) const =0 |
This method free's allocated data allocated by this allocator. | |
virtual void | free (ContextData &contextData) const =0 |
This method free's allocated data allocated by this allocator. | |
virtual void | memcpy (void *dst, const void *src, const size_t size) const =0 |
Memory copy within the same context. | |
virtual std::auto_ptr< SyncToken > | memcpyAsync (void *dst, const void *src, const size_t size) const =0 |
virtual bool | cancpy (const ContextData &dst, const ContextData &src) const =0 |
Checks if this Context can copy from src to dst. | |
virtual void | memcpy (ContextData &dst, const ContextData &src, const size_t size) const =0 |
Memory copy. | |
virtual std::auto_ptr< SyncToken > | memcpyAsync (ContextData &dst, const ContextData &src, const size_t size) const =0 |
virtual std::auto_ptr< SyncToken > | getSyncToken () const =0 |
Getter routine for a new sync token that allows to asynchronous computations on the context. | |
virtual void | enable (const char *file, int line) const |
Enable computations in the context. | |
virtual void | disable (const char *file, int line) const |
Disable computations in the context. | |
class LAMAInterface & | getInterface () const |
This method returns interface for a given context. | |
Protected Member Functions | |
Context (ContextType type) | |
Default constructor, can only be called by base classes. | |
LAMA_LOG_DECL_STATIC_LOGGER (logger) | |
Protected Attributes | |
ContextType | mContextType |
bool | mEnabled |
if true the context is currently accessed | |
const char * | mFile |
File name where context has been enabled. | |
int | mLine |
Line number where context has been enabled. |
This class is a common base class for all possible contexts.
A context stands for a compute and data environment to run certain code.
Each context must provide routines to allocate and free data for the context as well as copy data in suitable memory locations accessible for the context.
Furthermore, each context should provide routines to transfer memory from the HOST to to the context and vice versa.
A copy constructor for a context is not provided.
Enumeration type for the supported contexts.
The type is used to select the appropriate code that will be used for the computations in the context.
The same context type does not imply that two different contexts can use the same data. Two CUDA contexts might allocate their own data where data must be transfered explicitly.
lama::Context::~Context | ( | ) | [virtual] |
References mContextType.
lama::Context::Context | ( | ContextType | type | ) | [protected] |
Default constructor, can only be called by base classes.
References mContextType.
virtual void lama::Context::allocate | ( | ContextData & | contextData, |
const size_t | size | ||
) | const [pure virtual] |
This method allocates memory and must be implemented by each Context.
[in] | size | is the number of bytes needed |
[out] | contextData | the ContextData the memory should be allocated for |
[in] | size | is the number of bytes needed |
Implemented in lama::CUDAContext, lama::DefaultHostContext, lama::CUDAHostContext, and lama::PGASContext.
virtual bool lama::Context::cancpy | ( | const ContextData & | dst, |
const ContextData & | src | ||
) | const [pure virtual] |
Checks if this Context can copy from src to dst.
[in] | dst | the dst ContextData |
[in] | src | the src ContextData |
Implemented in lama::CUDAContext, lama::DefaultHostContext, lama::CUDAHostContext, and lama::PGASContext.
virtual bool lama::Context::canUseData | ( | const Context & | other | ) | const [pure virtual] |
This predicate returns true if one context can use data of another context.
This pure routine must be implemented by base classes.
[in] | other | is the context against which the check is done |
Implemented in lama::CUDAContext, and lama::HostContext.
Referenced by operator==().
void lama::Context::disable | ( | const char * | file, |
int | line | ||
) | const [virtual] |
Disable computations in the context.
Reimplemented in lama::CUDAContext.
void lama::Context::enable | ( | const char * | file, |
int | line | ||
) | const [virtual] |
Enable computations in the context.
Operations on the context like allocation, deallocation of data, computations can only be done if the context is enabled.
Different threads can enable a context, but only one at a time.
Reimplemented in lama::CUDAContext.
virtual void lama::Context::free | ( | void * | pointer, |
const size_t | size | ||
) | const [pure virtual] |
This method free's allocated data allocated by this allocator.
[in] | pointer | is the pointer to the allocated data. |
[in] | size | is the number of bytes that have been allocated with pointer. |
The pointer must have been allocated by the same allocator with the given size.
Implemented in lama::CUDAContext, lama::DefaultHostContext, lama::CUDAHostContext, and lama::PGASContext.
Referenced by lama::Context::ContextData::~ContextData().
virtual void lama::Context::free | ( | ContextData & | contextData | ) | const [pure virtual] |
This method free's allocated data allocated by this allocator.
[in] | contextData | which holds the pointer to the allocated data. |
The pointer must have been allocated by the same allocator.
Implemented in lama::CUDAContext, lama::DefaultHostContext, lama::CUDAHostContext, and lama::PGASContext.
const LAMAInterface & lama::Context::getInterface | ( | ) | const |
This method returns interface for a given context.
References lama::LAMAInterfaceRegistry::getInterface(), lama::LAMAInterfaceRegistry::getRegistry(), getType(), and LAMA_ASSERT_DEBUG.
virtual std::auto_ptr<SyncToken> lama::Context::getSyncToken | ( | ) | const [pure virtual] |
Getter routine for a new sync token that allows to asynchronous computations on the context.
Implemented in lama::CUDAContext, and lama::HostContext.
ContextType lama::Context::getType | ( | ) | const [inline] |
Method to get the type of the context.
Referenced by lama::PGASContext::cancpy(), lama::CUDAHostContext::cancpy(), lama::HostContext::canUseData(), lama::CUDAContext::canUseData(), lama::PGASContext::free(), lama::CUDAHostContext::free(), lama::CUDAContext::free(), getInterface(), lama::PGASContext::memcpy(), lama::CUDAHostContext::memcpy(), lama::PGASContext::memcpyAsync(), and lama::CUDAHostContext::memcpyAsync().
lama::Context::LAMA_LOG_DECL_STATIC_LOGGER | ( | logger | ) | [protected] |
Reimplemented in lama::CUDAContext, lama::DefaultHostContext, lama::CUDAHostContext, and lama::PGASContext.
virtual void lama::Context::memcpy | ( | void * | dst, |
const void * | src, | ||
const size_t | size | ||
) | const [pure virtual] |
Memory copy within the same context.
param[in] dst pointer to the destination param[in] src pointer to the source param[in] size is the number of bytes to be copied.
This memory copies size values
Implemented in lama::CUDAContext, lama::DefaultHostContext, lama::CUDAHostContext, and lama::PGASContext.
virtual void lama::Context::memcpy | ( | ContextData & | dst, |
const ContextData & | src, | ||
const size_t | size | ||
) | const [pure virtual] |
Memory copy.
Copies the first size bytes from src->pointer to dst->pointer. the memory pointed to by src might be registered in a certain way to allow faster memory transfers. However the memory pointed to by src->pointer will not be altered by this function.
param[in] dst pointer to the destination param[in] src pointer to the source param[in] size is the number of bytes to be copied.
This memory copies size values
Implemented in lama::CUDAContext, lama::DefaultHostContext, lama::CUDAHostContext, and lama::PGASContext.
virtual std::auto_ptr<SyncToken> lama::Context::memcpyAsync | ( | void * | dst, |
const void * | src, | ||
const size_t | size | ||
) | const [pure virtual] |
Implemented in lama::CUDAContext, lama::DefaultHostContext, lama::CUDAHostContext, and lama::PGASContext.
virtual std::auto_ptr<SyncToken> lama::Context::memcpyAsync | ( | ContextData & | dst, |
const ContextData & | src, | ||
const size_t | size | ||
) | const [pure virtual] |
Implemented in lama::CUDAContext, lama::DefaultHostContext, lama::CUDAHostContext, and lama::PGASContext.
bool lama::Context::operator!= | ( | const Context & | other | ) | const |
The inequality operator is just the inverse to operator==.
References operator==().
bool lama::Context::operator== | ( | const Context & | other | ) | const |
This predicate returns true if two contexts can use same data and have the same type.
References canUseData(), LAMA_ASSERT_EQUAL_DEBUG, and mContextType.
Referenced by operator!=().
void lama::Context::writeAt | ( | std::ostream & | stream | ) | const [virtual] |
This method writes info about the device in the output stream The method should be overwritten by base classes to give more specific information about the device that might be useful for logging.
Reimplemented from Printable.
Reimplemented in lama::CUDAContext, lama::CUDAHostContext, lama::PGASContext, lama::HostContext, and lama::DefaultHostContext.
ContextType lama::Context::mContextType [protected] |
Referenced by Context(), operator==(), and ~Context().
bool lama::Context::mEnabled [mutable, protected] |
const char* lama::Context::mFile [mutable, protected] |
int lama::Context::mLine [mutable, protected] |