Caffe2 - C++ API
A deep learning, cross platform ML framework
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | Static Protected Attributes
caffe2::CPUContext Class Referencefinal

The CPU Context, representing the bare minimum of what a Context class in Caffe2 should implement. More...

#include <context.h>

Public Types

typedef std::mt19937 rand_gen_type
 

Public Member Functions

 CPUContext (const DeviceOption &option)
 
void SwitchToDevice (int)
 
void SwitchToDevice ()
 
void WaitEvent (const Event &ev)
 
void Record (Event *ev, const char *err_msg=nullptr) const
 
void FinishDeviceComputation ()
 
rand_gen_type & RandGenerator ()
 
template<class SrcContext , class DstContext >
void CopyBytes (size_t nbytes, const void *src, void *dst)
 
template<typename T , class SrcContext , class DstContext >
void Copy (size_t n, const T *src, T *dst)
 
template<class SrcContext , class DstContext >
void CopyItems (const TypeMeta &meta, size_t n, const void *src, void *dst)
 
template<>
void CopyBytes (size_t nbytes, const void *src, void *dst)
 
template<>
void CopyBytes (size_t nbytes, const void *src, void *dst)
 
template<>
void CopyBytes (size_t nbytes, const void *src, void *dst)
 

Static Public Member Functions

static std::pair< void *, MemoryDeleter > New (size_t nbytes)
 
static bool HasAsyncPartDefault ()
 
static bool SupportsAsyncScheduling ()
 
static bool IsStreamFree (const DeviceOption &, int)
 

Protected Attributes

int random_seed_ {1701}
 
std::unique_ptr< rand_gen_type > random_generator_
 

Static Protected Attributes

static CAFFE2_API MemoryAllocationReporter reporter_
 

Detailed Description

The CPU Context, representing the bare minimum of what a Context class in Caffe2 should implement.

See operator.h, especially Operator<Context>, for how Context are used in actual operator implementations that are associated with specific devices. In general, the Context class is passed in as a template argument, and the operator can use the functions defined in the context to execute whatever computation it has.

A Context defines all the necessities to run an operator on a specific device. Specific Context classes have the freedom to choose what functions it implements, but there are a few functions that you should consider implementing if you want to write your own context class:

We intentionally did not create a base class for the various possible Context classes there might be, since they are intended to be specified during compile time using templates rather than via polymorphism. You should also not have classes derived from existing context classes.

Definition at line 66 of file context.h.


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