Caffe2 - C++ API
A deep learning, cross platform ML framework
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 Member Functions

 CPUContext (const DeviceOption &option)
 
void SwitchToDevice (int stream_id)
 
void SwitchToDevice ()
 
bool FinishDeviceComputation ()
 
std::mt19937 & 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 void * New (size_t nbytes)
 
static void Delete (void *data)
 

Protected Attributes

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

Static Protected Attributes

static 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 105 of file context.h.


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