Caffe2 - C++ API
A deep learning, cross platform ML framework
Namespaces | Data Structures | Typedefs | Enumerations | Functions | Variables
caffe2 Namespace Reference

Simple registry implementation in Caffe2 that uses static variables to register object creators during program initialization time. More...

Namespaces

 enforce_detail
 Rich logging messages.
 
 gpu_single_thread
 Code for special net type that uses one executor -thread per GPU.
 

Data Structures

class  ArgumentHelper
 A helper class to index into arguments. More...
 
class  AsyncDAGNet
 
class  AvgExportedStat
 
class  Blob
 Blob is a general container that hosts a typed pointer. More...
 
class  BlobDeserializerBase
 BlobDeserializerBase is an abstract class that deserializes a blob from a BlobProto or a TensorProto. More...
 
class  BlobSerializerBase
 BlobSerializerBase is an abstract class that serializes a blob to a string. More...
 
class  BlobsQueue
 
struct  BlobStatGetter
 
struct  BlobStatRegistry
 
class  Caffe2FlagParser
 
struct  CompiledExecutionStep
 
struct  CPUAllocator
 
class  CPUContext
 The CPU Context, representing the bare minimum of what a Context class in Caffe2 should implement. More...
 
class  CUDAContext
 
class  CudaRTCFunction
 
class  cudnnFilterDescWrapper
 
class  CuDNNHandles
 CuDNNHandles wraps around cudnnHandle_t so they can be properly destructed when threads exit. More...
 
class  CuDNNState
 
class  cudnnTensorDescWrapper
 cudnnTensorDescWrapper is the placeholder that wraps around a cudnnTensorDescriptor_t, allowing us to do descriptor change as-needed during runtime. More...
 
class  cudnnTypeWrapper
 cudnnTypeWrapper is a wrapper class that allows us to refer to the cudnn type in a template function. More...
 
class  cudnnTypeWrapper< double >
 
class  cudnnTypeWrapper< float >
 
class  cudnnTypeWrapper< float16 >
 
struct  CuDNNWorkspace
 CuDNNWorkspace is a wrapper around a raw cuda pointer that holds the cudnn scratch space. More...
 
class  CuDNNWrapper
 CuDNNWrapper is a class that wraps the cudnn handles and cudnn workspaces. More...
 
class  DAGNet
 
class  DAGNetBase
 
struct  DefaultCPUAllocator
 
class  DefaultEngine
 
class  DetailedExportedStat
 
class  DeviceGuard
 
struct  DeviceTypeRegisterer
 
struct  DispatchHelper
 
struct  DispatchHelper< FixedValues< FirstVal, Values... >, ExtraArgs... >
 
struct  DispatchHelper< FixedValues<>, ExtraArgs... >
 
class  ElementwiseRTCOp
 A GPU operator that can generate limited elementwise operations. More...
 
class  EnforceNotMet
 
class  ExportedStat
 
struct  ExportedStatValue
 
class  FixedDivisor
 
class  FixedDivisor< int32_t >
 
struct  FixedValues
 
struct  GenericTensorImplementation
 
class  GradientMakerBase
 
struct  GradientNotImplementedYet
 A helper class to indicate that the gradient mechanism is not ready. More...
 
struct  GradientOpsMeta
 A struct that holds the gradient operators and related gradient maps. More...
 
struct  GradientWrapper
 
class  InitRegisterer
 
class  LoggerVoidify
 
class  MaxPoolGradientRTCOp
 
class  MaxPoolRTCOp
 
class  MemoryAllocationReporter
 
class  MessageLogger
 
class  MKLContext
 The MKL Context, which is largely the same as the CPUContext. More...
 
class  MPICommonWorldWrapper
 A simple wrapper over an MPI common world. More...
 
class  MPIDataTypeWrapper
 
class  NetBase
 
class  NoGradient
 A helper class to indicate that the operator does not need gradient computation. More...
 
class  Operator
 
class  OperatorBase
 
class  OpSchema
 A class to record the schema of an op. More...
 
class  OpSchemaRegistry
 A registry to hold all the operator schemas. More...
 
struct  PinnedCPUAllocator
 An allocator that does the CPU memory allocation with pinned memory. More...
 
class  Predictor
 
class  QTensor
 
class  QTensorDeserializer
 
class  QTensorSerializer
 
class  Registerer
 
class  Registry
 A template class that allows one to register classes by keys. More...
 
class  ScopeGuardImpl
 
class  ScopeGuardImplBase
 ScopeGuard is a general implementation of the "Initialization is Resource Acquisition" idiom. More...
 
class  SignalHandler
 
class  SimpleNet
 
class  SimpleQueue
 
class  SkipIndices
 
class  SkipIndices<>
 
struct  Stat
 
class  StatRegistry
 Holds a map of atomic counters keyed by name. More...
 
class  StatValue
 
struct  StopOnSignal
 
class  StringDeserializer
 StringDeserializer is the deserializer for Strings. More...
 
class  StringSerializer
 StringSerializer is the serializer for String. More...
 
class  Tensor
 Tensor is the basic class in Caffe2 that stores a contiguous memory with its shape information. More...
 
class  TensorDeserializer
 TensorDeserializer is the deserializer for Tensors. More...
 
class  TensorPrinter
 
class  TensorSerializer
 TensorSerializer is the serializer for Tensors. More...
 
struct  TensorTypes
 
struct  TensorTypes2
 
class  ThreadLocalCUDAObjects
 A struct to host thread-local cuda objects. More...
 
struct  ThrowInTheTowelIfGradientIsCalled
 A helper class to indicate that the operator should have no gradient. More...
 
class  Timer
 A simple timer object for measuring time. More...
 
class  TypeMeta
 TypeMeta is a thin class that allows us to store the type of a container such as a blob, or the data type of a tensor, with a unique run-time id. More...
 
struct  TypeNameRegisterer
 
class  UnsupportedOperatorFeature
 
class  Workspace
 Workspace is a class that holds all the related objects created during runtime: (1) all blobs, and (2) all instantiated networks. More...
 
class  ZmqContext
 
class  ZmqMessage
 
class  ZmqSocket
 

Typedefs

typedef int64_t TIndex
 
template<typename Key , typename Value >
using CaffeMap = std::map< Key, Value >
 
typedef Tensor< CUDAContextTensorCUDA
 
typedef Registry< std::string, OperatorBase, const OperatorDef &, Workspace * > *(* RegistryFunction) ()
 
typedef ScopeGuardImplBase && ScopeGuard
 This is largely unneeded if you just use auto for your guards.
 
using ExportedStatList = std::vector< ExportedStatValue >
 Holds names and values of counters exported from a StatRegistry.
 
using ExportedStatMap = std::unordered_map< std::string, int64_t >
 
typedef Tensor< CPUContextTensorCPU
 
typedef TypeMeta(* TypeCall) (void *)
 
typedef vector< TIndex >(* ShapeCall) (void *, bool &shares_data, size_t &capacity)
 
typedef intptr_t CaffeTypeId
 
template<typename T >
using EigenMatrixMap = Eigen::Map< Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > >
 
template<typename T >
using EigenArrayMap = Eigen::Map< Eigen::Array< T, Eigen::Dynamic, Eigen::Dynamic > >
 
template<typename T >
using EigenVectorMap = Eigen::Map< Eigen::Matrix< T, Eigen::Dynamic, 1 > >
 
template<typename T >
using EigenVectorArrayMap = Eigen::Map< Eigen::Array< T, Eigen::Dynamic, 1 > >
 
template<typename T >
using ConstEigenMatrixMap = Eigen::Map< const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > >
 
template<typename T >
using ConstEigenArrayMap = Eigen::Map< const Eigen::Array< T, Eigen::Dynamic, Eigen::Dynamic > >
 
template<typename T >
using ConstEigenVectorMap = Eigen::Map< const Eigen::Matrix< T, Eigen::Dynamic, 1 > >
 
template<typename T >
using ConstEigenVectorArrayMap = Eigen::Map< const Eigen::Array< T, Eigen::Dynamic, 1 > >
 

Enumerations

enum  CudaMemoryPoolType { NONE = 0, CNMEM = 1, CUB = 2 }
 
enum  StorageOrder { UNKNOWN = 0, NHWC = 1, NCHW = 2 }
 

Functions

void ConvertToRawDataset (const string &input_db_name, const string &output_db_name)
 
void ReadImage (std::ifstream *file, int *label, char *buffer)
 
void WriteToDB (const string &filename, const int num_items, const int &offset, db::DB *db)
 
void ConvertCIFAR ()
 
void ConvertImageDataset (const string &input_folder, const string &list_filename, const string &output_db_name, const bool shuffle)
 
uint32_t swap_endian (uint32_t val)
 
void convert_dataset (const char *image_filename, const char *label_filename, const char *db_path, const int data_limit)
 
void run ()
 
void swap (Blob &lhs, Blob &rhs)
 
 CAFFE_DEFINE_TYPED_REGISTRY (BlobSerializerRegistry, CaffeTypeId, BlobSerializerBase)
 
 CAFFE_DEFINE_REGISTRY (BlobDeserializerRegistry, BlobDeserializerBase)
 
 CAFFE_DECLARE_TYPED_REGISTRY (BlobSerializerRegistry, CaffeTypeId, BlobSerializerBase)
 
unique_ptr< BlobSerializerBaseCreateSerializer (CaffeTypeId id)
 
 CAFFE_DECLARE_REGISTRY (BlobDeserializerRegistry, BlobDeserializerBase)
 
unique_ptr< BlobDeserializerBaseCreateDeserializer (const string &type)
 
template<typename T , typename... Args>
std::enable_if<!std::is_array< T >::value, std::unique_ptr< T > >::type make_unique (Args &&... args)
 
template<typename T >
std::enable_if< std::is_array< T >::value, std::unique_ptr< T > >::type make_unique (const size_t n)
 
template<typename T , typename... Args>
std::enable_if< std::extent< T >::value !=0, std::unique_ptr< T > >::type make_unique (Args &&...)=delete
 
template<typename Dst , typename Src >
Dst dynamic_cast_if_rtti (Src ptr)
 
size_t cudnnCompiledVersion ()
 
size_t cudnnRuntimeVersion ()
 
void CheckCuDNNVersions ()
 
cudnnTensorFormat_t GetCudnnTensorFormat (const StorageOrder &order)
 A wrapper function to convert the Caffe storage order to cudnn storage order enum values.
 
int NumCudaDevices ()
 Returns the number of devices.
 
void SetDefaultGPUID (const int deviceid)
 Sets the default GPU id for Caffe2. More...
 
int GetDefaultGPUID ()
 Gets the default GPU id for Caffe2.
 
int GetCurrentGPUID ()
 Gets the current GPU id. More...
 
int GetGPUIDForPointer (const void *ptr)
 Gets the GPU id that the current pointer is located at.
 
const cudaDeviceProp & GetDeviceProperty (const int device)
 Gets the device property for the given device.
 
void DeviceQuery (const int deviceid)
 Runs a device query function and prints out the results to LOG(INFO).
 
bool GetCudaPeerAccessPattern (vector< vector< bool > > *pattern)
 Return a peer access pattern by returning a matrix (in the format of a nested vector) of boolean values specifying whether peer access is possible. More...
 
const char * cublasGetErrorString (cublasStatus_t error)
 Return a human readable cublas error string.
 
const char * curandGetErrorString (curandStatus_t error)
 Return a human readable curand error string.
 
int CudaVersion ()
 A runtime function to report the cuda version that Caffe2 is built with.
 
bool HasCudaGPU ()
 Check if the current running session has a cuda gpu present. More...
 
int CAFFE_GET_BLOCKS (const int N)
 Compute the number of blocks needed to run N threads.
 
CPUAllocatorGetCPUAllocator ()
 
void SetCPUAllocator (CPUAllocator *alloc)
 
CudaMemoryPoolType GetCudaMemoryPoolType ()
 Gets the current memory pool type used by Caffe2. More...
 
 CAFFE_KNOWN_TYPE (db::DBReader)
 
 CAFFE_KNOWN_TYPE (db::Cursor)
 
 CAFFE_DEFINE_REGISTRY (Caffe2FlagsRegistry, Caffe2FlagParser, const string &)
 
void SetUsageMessage (const string &str)
 Sets the usage message when a commandline tool is called with "--help".
 
const char * UsageMessage ()
 Returns the usage message for the commandline tool set by SetUsageMessage.
 
bool ParseCaffeCommandLineFlags (int *pargc, char ***pargv)
 Parses the commandline flags. More...
 
bool CommandLineFlagsHasBeenParsed ()
 Checks if the commandline flags has already been passed.
 
 CAFFE_DECLARE_REGISTRY (Caffe2FlagsRegistry, Caffe2FlagParser, const string &)
 
bool GlobalInit (int *pargc, char ***argv)
 Initialize the global environment of caffe2. More...
 
std::string StripBasename (const std::string &full_path)
 
size_t ReplaceAll (string &s, const char *from, const char *to)
 
void SetStackTraceFetcher (std::function< string(void)> fetcher)
 
void SetOperatorLogger (std::function< void(const OperatorDef &)> tracer)
 
std::function< void(const OperatorDef &)> GetOperatorLogger ()
 
bool InitCaffeLogging (int *argc, char **argv)
 
constexpr bool IsUsingGoogleLogging ()
 
void MakeStringInternal (std::stringstream &ss)
 
template<typename T >
void MakeStringInternal (std::stringstream &ss, const T &t)
 
template<typename T , typename... Args>
void MakeStringInternal (std::stringstream &ss, const T &t, const Args &... args)
 
template<typename... Args>
string MakeString (const Args &... args)
 
template<>
string MakeString (const string &str)
 
string MakeString (const char *c_str)
 
template<class Container >
string Join (const string &delimiter, const Container &v)
 
template<class T >
void LogMessageFatal (const char *file, int line, const T &message)
 
template<typename T >
T & CheckNotNullCommon (const char *file, int line, const char *names, T &t)
 
template<typename T >
T * CheckNotNull (const char *file, int line, const char *names, T *t)
 
template<typename T >
T & CheckNotNull (const char *file, int line, const char *names, T &t)
 
template<class First , class Second >
std::ostream & operator<< (std::ostream &out, const std::pair< First, Second > &p)
 
template<class Iter >
void PrintSequence (std::ostream &ss, Iter begin, Iter end)
 
 CAFFE_DEFINE_REGISTRY (NetRegistry, NetBase, const NetDef &, Workspace *)
 
unique_ptr< NetBaseCreateNet (const NetDef &net_def, Workspace *ws)
 Creates a network, accessing / creating blobs in the given workspace. More...
 
 CAFFE_DECLARE_REGISTRY (NetRegistry, NetBase, const NetDef &, Workspace *)
 
 REGISTER_NET (async_dag, AsyncDAGNet)
 
unique_ptr< OperatorBaseCreateOperator (const OperatorDef &operator_def, Workspace *ws)
 
std::map< int32_t, OperatorRegistry * > * gDeviceTypeRegistry ()
 
 CAFFE_DEFINE_REGISTRY (CPUOperatorRegistry, OperatorBase, const OperatorDef &, Workspace *)
 
 CAFFE_REGISTER_DEVICE_TYPE (DeviceType::CPU, CPUOperatorRegistry)
 
 CAFFE_DEFINE_REGISTRY (CUDAOperatorRegistry, OperatorBase, const OperatorDef &, Workspace *)
 
 CAFFE_REGISTER_DEVICE_TYPE (DeviceType::CUDA, CUDAOperatorRegistry)
 
 CAFFE_DEFINE_REGISTRY (GradientRegistry, GradientMakerBase, const OperatorDef &, const vector< GradientWrapper > &)
 
GradientOpsMeta GetGradientForOp (const OperatorDef &def, const vector< GradientWrapper > &g_output)
 Gets the GradientOpsMeta for the given operator def.
 
TensorShapes InferBlobShapesAndTypesFromWorkspace (Workspace *ws, const vector< std::unique_ptr< NetDef >> &nets)
 
TensorShapes InferBlobShapesAndTypesFromMap (const CaffeMap< std::string, std::vector< TIndex >> &blob_dimensions, const vector< std::unique_ptr< NetDef >> &nets)
 
 CAFFE2_DEFINE_TENSOR_TYPES_DISPATCHER (TensorTypes, DoRunWithType, DoRunWithOtherType) CAFFE2_DEFINE_TENSOR_TYPES_DISPATCHER(TensorTypes2
 
 CAFFE_DECLARE_REGISTRY (CPUOperatorRegistry, OperatorBase, const OperatorDef &, Workspace *)
 
 CAFFE_DECLARE_REGISTRY (CUDAOperatorRegistry, OperatorBase, const OperatorDef &, Workspace *)
 
 CAFFE_DECLARE_REGISTRY (GradientRegistry, GradientMakerBase, const OperatorDef &, const vector< GradientWrapper > &)
 
std::ostream & operator<< (std::ostream &out, const OpSchema &schema)
 
TensorShape CreateTensorShape (vector< int > dims, ::caffe2::TensorProto_DataType dt)
 
vector< TIndex > GetDimsVector (const TensorShape &shape)
 
 CAFFE_KNOWN_TYPE (QTensor< CPUContext >)
 
template<typename FunctionType >
ScopeGuardImpl< typename std::decay< FunctionType >::type > MakeGuard (FunctionType &&fn) noexcept(std::is_nothrow_constructible< typename std::decay< FunctionType >::type, FunctionType >::value)
 
ExportedStatMap toMap (const ExportedStatList &stats)
 
 CAFFE_KNOWN_TYPE (Tensor< CPUContext >)
 
TypeCall GetTypeCallFunction (CaffeTypeId id)
 
void RegisterTypeCallFunction (CaffeTypeId id, TypeCall c)
 
ShapeCall GetShapeCallFunction (CaffeTypeId id)
 
void RegisterShapeCallFunction (CaffeTypeId id, ShapeCall c)
 
vector< TIndex > ToVectorTIndex (const std::vector< int > &src)
 A utility function to convert vector<int> to vector<TIndex>.
 
TIndex size_from_dim_ (int k, vector< TIndex > dims)
 Return product of all dimensions starting from K.
 
TIndex size_to_dim_ (int k, vector< TIndex > dims)
 
int canonical_axis_index_ (int axis_index, int ndims)
 
template<class Context >
TypeMeta GetTensorType (void *c)
 
template<class Context >
vector< TIndex > GetTensorShape (void *c, bool &shares_data, size_t &capacity)
 
std::map< CaffeTypeId, string > & gTypeNames ()
 
std::set< string > & gRegisteredTypeNames ()
 
string Demangle (const char *name)
 
string GetExceptionString (const std::exception &e)
 
 CAFFE_KNOWN_TYPE (float)
 
 CAFFE_KNOWN_TYPE (int)
 
 CAFFE_KNOWN_TYPE (std::string)
 
 CAFFE_KNOWN_TYPE (bool)
 
 CAFFE_KNOWN_TYPE (uint8_t)
 
 CAFFE_KNOWN_TYPE (int8_t)
 
 CAFFE_KNOWN_TYPE (uint16_t)
 
 CAFFE_KNOWN_TYPE (int16_t)
 
 CAFFE_KNOWN_TYPE (int64_t)
 
 CAFFE_KNOWN_TYPE (float16)
 
 CAFFE_KNOWN_TYPE (double)
 
 CAFFE_KNOWN_TYPE (char)
 
 CAFFE_KNOWN_TYPE (std::unique_ptr< std::mutex >)
 
 CAFFE_KNOWN_TYPE (std::unique_ptr< std::atomic< bool >>)
 
 CAFFE_KNOWN_TYPE (std::vector< int64_t >)
 
 CAFFE_KNOWN_TYPE (std::vector< unsigned long >)
 
TensorProto::DataType TypeMetaToDataType (const TypeMeta &meta)
 
const TypeMetaDataTypeToTypeMeta (const TensorProto::DataType &dt)
 
StorageOrder StringToStorageOrder (const string &str)
 
constexpr char NameScopeSeparator ()
 
struct CAFFE2_ALIGNED (2) __f16
 
string GetUniqueName ()
 
template<typename T_IN , typename T_OUT , class Context >
bool TransformOnGPU (Tensor< Context > &X, Tensor< Context > *Y, T_OUT mean, T_OUT std, Context *context)
 
 CAFFE_KNOWN_TYPE (MPICommonWorldWrapper)
 
std::mutex & MPIMutex ()
 
MPI_Comm GlobalMPIComm ()
 Gets the global MPI communicator used by Caffe2. More...
 
void SetGlobalMPIComm (MPI_Comm new_comm)
 Sets the global MPI communicator. More...
 
int MPICommSize (MPI_Comm comm)
 A helper function to return the size of the given communicator.
 
int MPICommRank (MPI_Comm comm)
 A helper function to return the rank of the given communicator.
 
void MPISetupPeers (const int replicas, const string &role, const string &job_path)
 A function used to perform peer setup so one does not need to use mpirun / mpiexec to run the binary. More...
 
void CheckInitializedMPI ()
 
 CAFFE_DECLARE_REGISTRY (MKLOperatorRegistry, OperatorBase, const OperatorDef &, Workspace *)
 
void MurmurHash3_x86_32 (const void *key, int len, uint32_t seed, void *out)
 
void MurmurHash3_x86_128 (const void *key, const int len, uint32_t seed, void *out)
 
void MurmurHash3_x64_128 (const void *key, const int len, const uint32_t seed, void *out)
 
std::string DeviceTypeName (const int32_t &d)
 
bool ReadStringFromFile (const char *filename, string *str)
 
bool WriteStringToFile (const string &str, const char *filename)
 
bool ReadProtoFromTextFile (const char *filename, Message *proto)
 
void WriteProtoToTextFile (const Message &proto, const char *filename)
 
bool ReadProtoFromBinaryFile (const char *filename, MessageLite *proto)
 
void WriteProtoToBinaryFile (const MessageLite &proto, const char *filename)
 
template<>
Argument MakeArgument (const string &name, const MessageLite &value)
 
const Argument & GetArgument (const OperatorDef &def, const string &name)
 
bool GetFlagArgument (const OperatorDef &def, const string &name, bool def_value)
 
Argument * GetMutableArgument (const string &name, const bool create_if_missing, OperatorDef *def)
 
bool ReadProtoFromBinaryFile (const string filename, MessageLite *proto)
 
void WriteProtoToBinaryFile (const MessageLite &proto, const string &filename)
 
string ProtoDebugString (const Message &proto)
 
bool ReadProtoFromTextFile (const string filename, Message *proto)
 
void WriteProtoToTextFile (const Message &proto, const string &filename)
 
bool ReadProtoFromFile (const char *filename, Message *proto)
 
bool ReadProtoFromFile (const string &filename, Message *proto)
 
template<class IterableInputs , class IterableOutputs , class IterableArgs >
OperatorDef CreateOperatorDef (const string &type, const string &name, const IterableInputs &inputs, const IterableOutputs &outputs, const IterableArgs &args, const DeviceOption &device_option, const string &engine)
 
template<class IterableInputs , class IterableOutputs , class IterableArgs >
OperatorDef CreateOperatorDef (const string &type, const string &name, const IterableInputs &inputs, const IterableOutputs &outputs, const IterableArgs &args)
 
template<class IterableInputs , class IterableOutputs >
OperatorDef CreateOperatorDef (const string &type, const string &name, const IterableInputs &inputs, const IterableOutputs &outputs)
 
bool HasArgument (const OperatorDef &def, const string &name)
 
template<typename T >
Argument MakeArgument (const string &name, const T &value)
 
template<typename T >
void AddArgument (const string &name, const T &value, OperatorDef *def)
 
std::vector< std::string > split (char separator, const std::string &string)
 
size_t editDistance (const std::string &s1, const std::string &s2, size_t max_distance)
 
int32_t editDistanceHelper (const char *s1, size_t s1_len, const char *s2, size_t s2_len, std::vector< size_t > &current, std::vector< size_t > &previous, std::vector< size_t > &previous1, size_t max_distance)
 

Variables

DoRunWithOtherType2 typedef Registry< std::string, OperatorBase, const OperatorDef &, Workspace * > OperatorRegistry
 
const int kCIFARSize = 32
 
const int kCIFARImageNBytes = kCIFARSize * kCIFARSize * 3
 
const int kCIFAR10BatchSize = 10000
 
const int kCIFAR10TestDataSize = 10000
 
const int kCIFAR10TrainBatches = 5
 
const int kCIFAR100TrainDataSize = 50000
 
const int kCIFAR100TestDataSize = 10000
 
constexpr auto kTensorBlobType = "Tensor"
 
constexpr auto kChunkIdSeparator = "#%"
 
constexpr int kDefaultChunkSize = -1
 
constexpr int kNoChunking = 0
 
constexpr int CAFFE_CUDA_NUM_THREADS = 512
 
constexpr int CAFFE_MAXIMUM_NUM_BLOCKS = 4096
 
constexpr size_t gCaffe2Alignment = 32
 
std::function< void(const OperatorDef &)> GetOperatorLogger ()
 
 DoRunWithType2
 
constexpr int kCannotComputeNumOutputs = -1
 
constexpr auto kQTensorBlobQType = "QTensor"
 
constexpr int k_limit_default_ = 1000
 
 float16
 

Detailed Description

Simple registry implementation in Caffe2 that uses static variables to register object creators during program initialization time.

Copyright (c) 2016, NVIDIA CORPORATION, All rights reserved.

Copyright 2016 Facebook.

Author
Tudor Bosman (tudor.[email protected][email protected].[email protected].com)

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Function Documentation

◆ CreateNet()

unique_ptr< NetBase > caffe2::CreateNet ( const NetDef &  net_def,
Workspace ws 
)

Creates a network, accessing / creating blobs in the given workspace.

Note that this is different from Workspace::CreateNet. The latter adds the created net object to the workspace's net map, while this function returns a standalone net object.

Definition at line 66 of file net.cc.

◆ GetCudaMemoryPoolType()

CudaMemoryPoolType caffe2::GetCudaMemoryPoolType ( )

Gets the current memory pool type used by Caffe2.

The memory pool is set up during caffe2's global initialization time.

◆ GetCudaPeerAccessPattern()

bool caffe2::GetCudaPeerAccessPattern ( vector< vector< bool > > *  pattern)

Return a peer access pattern by returning a matrix (in the format of a nested vector) of boolean values specifying whether peer access is possible.

This function returns false if anything wrong happens during the query of the GPU access pattern.

Definition at line 159 of file common_gpu.cc.

◆ GetCurrentGPUID()

int caffe2::GetCurrentGPUID ( )

Gets the current GPU id.

This is a simple wrapper around cudaGetDevice().

Definition at line 93 of file common_gpu.cc.

◆ GlobalInit()

bool caffe2::GlobalInit ( int *  pargc,
char ***  argv 
)

Initialize the global environment of caffe2.

Caffe2 uses a registration pattern for initialization functions. Custom initialization functions should take the signature bool (func)(int, char***) where the pointers to argc and argv are passed in. Caffe2 then runs the initialization in three phases: (1) Functions registered with REGISTER_CAFFE2_EARLY_INIT_FUNCTION. Note that since it is possible the logger is not initialized yet, any logging in such early init functions may not be printed correctly. (2) Parses Caffe-specific commandline flags, and initializes caffe logging. (3) Functions registered with REGISTER_CAFFE2_INIT_FUNCTION. If there is something wrong at each stage, the function returns false. If the global initialization has already been run, the function returns false as well.

Definition at line 15 of file init.cc.

◆ GlobalMPIComm()

MPI_Comm caffe2::GlobalMPIComm ( )

Gets the global MPI communicator used by Caffe2.

In default, this is MPI_COMM_WORLD unless you call SetGlobalMPIComm().

Definition at line 20 of file mpi_common.cc.

◆ HasCudaGPU()

bool caffe2::HasCudaGPU ( )
inline

Check if the current running session has a cuda gpu present.

Note that this is different from having caffe2 built with cuda. Building Caffe2 with cuda only guarantees that this function exists. If there are no cuda gpus present in the machine, or there are hardware configuration problems like an insufficient driver, this function will still return false, meaning that there is no usable GPU present.

Definition at line 64 of file common_gpu.h.

◆ MPISetupPeers()

void caffe2::MPISetupPeers ( const int  replicas,
const string &  role,
const string &  job_path 
)

A function used to perform peer setup so one does not need to use mpirun / mpiexec to run the binary.

Note that if you use mpirun or mpiexec to set up the common world, do not use this function - MPI_Init would have already set that up.

This also assumes that you have a common path (like NFS) that multiple instances can read from.

Inputs: replicas (int): the number of replicas that mpi will run with. role (string): the role of this process, "server" or "client". job_path (string): a file name that the server will write its port into and the clients will read the server's port from.

Definition at line 94 of file mpi_common.cc.

◆ ParseCaffeCommandLineFlags()

bool caffe2::ParseCaffeCommandLineFlags ( int *  pargc,
char ***  pargv 
)

Parses the commandline flags.

This command parses all the commandline arguments passed in via pargc and argv. Once it is finished, partc and argv will contain the remaining commandline args that caffe2 does not deal with. Note that following convention, argv[0] contains the binary name and is not parsed.

Definition at line 55 of file flags.cc.

◆ SetDefaultGPUID()

void caffe2::SetDefaultGPUID ( const int  deviceid)

Sets the default GPU id for Caffe2.

If an operator is set to run on Cuda GPU but no gpu id is given, we will use the default gpu id to run the operator. Before this function is explicitly called, GPU 0 will be the default GPU id.

Definition at line 80 of file common_gpu.cc.

◆ SetGlobalMPIComm()

void caffe2::SetGlobalMPIComm ( MPI_Comm  new_comm)

Sets the global MPI communicator.

Caffe2 takes over the ownership of the passed in communicator.

Definition at line 24 of file mpi_common.cc.