LAMA
|
Alternative context to DefaultHostContext so that memory will be allocated on pinned memory that allows faster transfer to a certain CUDA device. More...
#include <CUDAHostContext.hpp>
Public Types | |
enum | HostContextType { DefaultHost, CUDAHost, OpenCLHost, PGAS, MaxHostContext } |
Due to more efficient transfers between Host and other contexts there might be different HOST contexts that will be distinguished by their type. More... | |
enum | ContextType { Host, CUDA, OpenCL, MaxContext } |
Enumeration type for the supported contexts. More... | |
Public Member Functions | |
virtual | ~CUDAHostContext () |
virtual void * | allocate (const size_t size) const |
virtual void | allocate (ContextData &contextData, const size_t size) const |
This method allocates memory and must be implemented by each Context. | |
virtual void | free (void *pointer, const size_t size) const |
This method free's allocated data allocated by this allocator. | |
virtual void | free (ContextData &contextData) const |
This method free's allocated data allocated by this allocator. | |
virtual void | memcpy (void *dst, const void *src, const size_t size) const |
Memory copy within the same context. | |
virtual std::auto_ptr< SyncToken > | memcpyAsync (void *dst, const void *src, const size_t size) const |
virtual bool | cancpy (const ContextData &dst, const ContextData &src) const |
Checks if this Context can copy from src to dst. | |
virtual void | memcpy (ContextData &dst, const ContextData &src, const size_t size) const |
Memory copy. | |
virtual std::auto_ptr< SyncToken > | memcpyAsync (ContextData &dst, const ContextData &src, const size_t size) const |
virtual HostContextType | getHostType () const |
virtual bool | canUseData (const Context &other) const |
This predicate returns true if one context can use data of another context. | |
virtual std::auto_ptr< SyncToken > | getSyncToken () const |
Providing implementation for Context::getSyncToken. | |
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 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 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. | |
Private Member Functions | |
LAMA_LOG_DECL_STATIC_LOGGER (logger) | |
CUDAHostContext (boost::shared_ptr< const CUDAContext > cudaContext) | |
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. | |
Private Attributes | |
boost::shared_ptr< const CUDAContext > | mCUDAContext |
Friends | |
class | CUDAHostContextManager |
Alternative context to DefaultHostContext so that memory will be allocated on pinned memory that allows faster transfer to a certain CUDA device.
As the CUDA Host memory will only allow faster transfer to a certain device and requires CUDA initialization, we will store also a shared pointer to the corresponding CUDA context.
enum lama::Context::ContextType [inherited] |
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.
enum lama::HostContext::HostContextType [inherited] |
lama::CUDAHostContext::~CUDAHostContext | ( | ) | [virtual] |
lama::CUDAHostContext::CUDAHostContext | ( | boost::shared_ptr< const CUDAContext > | cudaContext | ) | [private] |
References LAMA_THROWEXCEPTION, and mCUDAContext.
void * lama::CUDAHostContext::allocate | ( | const size_t | size | ) | const [virtual] |
References LAMA_CONTEXT_ACCESS, LAMA_CUDA_DRV_CALL, LAMA_REGION, and mCUDAContext.
Referenced by allocate().
void lama::CUDAHostContext::allocate | ( | ContextData & | contextData, |
const size_t | size | ||
) | const [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 |
Implements lama::Context.
References allocate(), lama::Context::ContextData::pointer, and lama::Context::ContextData::setPinned().
bool lama::CUDAHostContext::cancpy | ( | const ContextData & | dst, |
const ContextData & | src | ||
) | const [virtual] |
Checks if this Context can copy from src to dst.
[in] | dst | the dst ContextData |
[in] | src | the src ContextData |
Implements lama::Context.
References lama::Context::ContextData::context, and lama::Context::getType().
bool lama::HostContext::canUseData | ( | const Context & | other | ) | const [virtual, inherited] |
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 |
Implements lama::Context.
References lama::Context::getType(), and lama::Context::Host.
void lama::Context::disable | ( | const char * | file, |
int | line | ||
) | const [virtual, inherited] |
Disable computations in the context.
Reimplemented in lama::CUDAContext.
References lama::Context::mEnabled, lama::Context::mFile, and lama::Context::mLine.
void lama::Context::enable | ( | const char * | file, |
int | line | ||
) | const [virtual, inherited] |
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.
References lama::Context::mEnabled, lama::Context::mFile, and lama::Context::mLine.
void lama::CUDAHostContext::free | ( | void * | pointer, |
const size_t | size | ||
) | const [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.
Implements lama::Context.
References LAMA_CONTEXT_ACCESS, LAMA_CUDA_DRV_CALL, LAMA_REGION, and mCUDAContext.
Referenced by free().
void lama::CUDAHostContext::free | ( | ContextData & | contextData | ) | const [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.
Implements lama::Context.
References lama::Context::ContextData::context, free(), lama::Context::getType(), LAMA_ASSERT_EQUAL_ERROR, lama::Context::ContextData::pointer, and lama::Context::ContextData::size.
HostContext::HostContextType lama::CUDAHostContext::getHostType | ( | ) | const [virtual] |
Implements lama::HostContext.
References lama::HostContext::CUDAHost.
const LAMAInterface & lama::Context::getInterface | ( | ) | const [inherited] |
This method returns interface for a given context.
References lama::LAMAInterfaceRegistry::getInterface(), lama::LAMAInterfaceRegistry::getRegistry(), lama::Context::getType(), and LAMA_ASSERT_DEBUG.
std::auto_ptr< SyncToken > lama::HostContext::getSyncToken | ( | ) | const [virtual, inherited] |
Providing implementation for Context::getSyncToken.
Implements lama::Context.
ContextType lama::Context::getType | ( | ) | const [inline, inherited] |
Method to get the type of the context.
Referenced by lama::PGASContext::cancpy(), cancpy(), lama::HostContext::canUseData(), lama::CUDAContext::canUseData(), lama::PGASContext::free(), free(), lama::CUDAContext::free(), lama::Context::getInterface(), lama::PGASContext::memcpy(), memcpy(), lama::PGASContext::memcpyAsync(), and memcpyAsync().
lama::CUDAHostContext::LAMA_LOG_DECL_STATIC_LOGGER | ( | logger | ) | [private] |
Reimplemented from lama::Context.
void lama::CUDAHostContext::memcpy | ( | void * | dst, |
const void * | src, | ||
const size_t | size | ||
) | const [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
Implements lama::Context.
Referenced by memcpy().
void lama::CUDAHostContext::memcpy | ( | ContextData & | dst, |
const ContextData & | src, | ||
const size_t | size | ||
) | const [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
Implements lama::Context.
References lama::Context::ContextData::context, lama::Context::getType(), LAMA_ASSERT_ERROR, memcpy(), and lama::Context::ContextData::pointer.
std::auto_ptr< SyncToken > lama::CUDAHostContext::memcpyAsync | ( | void * | dst, |
const void * | src, | ||
const size_t | size | ||
) | const [virtual] |
Implements lama::Context.
References LAMA_CONTEXT_ACCESS, LAMA_CUDA_RT_CALL, and mCUDAContext.
Referenced by memcpyAsync().
std::auto_ptr< SyncToken > lama::CUDAHostContext::memcpyAsync | ( | ContextData & | dst, |
const ContextData & | src, | ||
const size_t | size | ||
) | const [virtual] |
Implements lama::Context.
References lama::Context::ContextData::context, lama::Context::getType(), LAMA_ASSERT_ERROR, memcpyAsync(), and lama::Context::ContextData::pointer.
bool lama::Context::operator!= | ( | const Context & | other | ) | const [inherited] |
The inequality operator is just the inverse to operator==.
References lama::Context::operator==().
bool lama::Context::operator== | ( | const Context & | other | ) | const [inherited] |
This predicate returns true if two contexts can use same data and have the same type.
References lama::Context::canUseData(), LAMA_ASSERT_EQUAL_DEBUG, and lama::Context::mContextType.
Referenced by lama::Context::operator!=().
void lama::CUDAHostContext::writeAt | ( | std::ostream & | stream | ) | const [private, 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 lama::HostContext.
References mCUDAContext.
friend class CUDAHostContextManager [friend] |
ContextType lama::Context::mContextType [protected, inherited] |
Referenced by lama::Context::Context(), lama::Context::operator==(), and lama::Context::~Context().
boost::shared_ptr<const CUDAContext> lama::CUDAHostContext::mCUDAContext [private] |
Referenced by allocate(), CUDAHostContext(), free(), memcpyAsync(), and writeAt().
bool lama::Context::mEnabled [mutable, protected, inherited] |
if true the context is currently accessed
Referenced by lama::Context::disable(), and lama::Context::enable().
const char* lama::Context::mFile [mutable, protected, inherited] |
File name where context has been enabled.
Referenced by lama::Context::disable(), and lama::Context::enable().
int lama::Context::mLine [mutable, protected, inherited] |
Line number where context has been enabled.
Referenced by lama::Context::disable(), and lama::Context::enable().