Skip to content
Search

Caffe:Develop

lastmod 2018-08-17created 2016-01-0816 edits

Contains source code analysis for Caffe development.

Blob

A wrapper class around #SyncedMemory that interacts with #Layer, #Net, and #Solver objects.

  • Header: include/caffe/blob.hpp
  • Source: src/caffe/blob.cpp

To understand this object, you first need to understand #SyncedMemory. Its characteristics are as follows.

  • A 4-dimensional array.
  • Stores data and is used for communication between modules.
  • Provides a memory interface so you don't have to worry about CPU/GPU synchronization and heterogeneous computation.
  • Models are stored with Google Protocol Buffers.
  • Large datasets are stored in LevelDB.

Member variables

protected:
shared_ptr<SyncedMemory> data_;
shared_ptr<SyncedMemory> diff_;
shared_ptr<SyncedMemory> shape_data_;
vector<int> shape_;
int count_;
int capacity_;

Layer

Its characteristics are as follows.

  • The building block of a network (#Net), taking one or more #Blobs as input and producing one or more #Blobs as output.
  • Has a Forward Pass and a Backward Pass, computes the gradients of the Layer parameters, and backpropagates (Back probagation) the error of the final output.
  • Provides Layers of types such as Convolution, Pooling, Inner products, Rectified linear, Logistic, Local response normalization, Element-wise operations, Losses like softmax and hinge.

Net

Solver

SyncedMemory

Manages memory allocation and synchronization between the host (CPU) and device (GPU).

  • Header: include/caffe/syncedmem.hpp
  • Source: src/caffe/syncedmem.cpp

Defines allocation/free operations for CPU memory and GPU memory.

Member variables

  • void* cpu_ptr_;: memory pointer for the CPU.
  • void* gpu_ptr_;: memory pointer for the GPU.
  • size_t size_;: allocated memory size.

util/math_functions

Mostly contains API wrappers for the GPU (CUDA), like the following.

inline void caffe_gpu_memset(const size_t N, const int alpha, void* X) {
#ifndef CPU_ONLY
    CUDA_CHECK(cudaMemset(X, alpha, N));  // NOLINT(caffe/alt_fn)
#else
    NO_GPU;
#endif
}

See also

Favorite site