Caffe2 - C++ API
A deep learning, cross platform ML framework
broadcast.cc
1 #include "caffe2/utils/math/broadcast.h"
2 
3 #include "caffe2/core/context.h"
4 #include "caffe2/utils/eigen_utils.h"
5 
6 namespace caffe2 {
7 namespace math {
8 
9 #define CAFFE2_SPECIALIZED_AFFINE_CHANNEL(T) \
10  template <> \
11  C10_EXPORT void AffineChannel<T, CPUContext, StorageOrder::NCHW>( \
12  const int N, \
13  const int C, \
14  const int HxW, \
15  const T* X, \
16  const T* scale, \
17  const T* bias, \
18  T* Y, \
19  CPUContext* /* context */) { \
20  ConstEigenVectorArrayMap<T> scale_arr(scale, C); \
21  ConstEigenVectorArrayMap<T> bias_arr(bias, C); \
22  const int stride = C * HxW; \
23  const T* X_ptr = X; \
24  T* Y_ptr = Y; \
25  for (int i = 0; i < N; ++i) { \
26  EigenArrayMap<T>(Y_ptr, HxW, C) = \
27  (ConstEigenArrayMap<T>(X_ptr, HxW, C).rowwise() * \
28  scale_arr.transpose()) \
29  .rowwise() + \
30  bias_arr.transpose(); \
31  X_ptr += stride; \
32  Y_ptr += stride; \
33  } \
34  } \
35  template <> \
36  C10_EXPORT void AffineChannel<T, CPUContext, StorageOrder::NHWC>( \
37  const int N, \
38  const int C, \
39  const int HxW, \
40  const T* X, \
41  const T* scale, \
42  const T* bias, \
43  T* Y, \
44  CPUContext* /* context */) { \
45  EigenArrayMap<T>(Y, C, N * HxW) = \
46  (ConstEigenArrayMap<T>(X, C, N * HxW).colwise() * \
47  ConstEigenVectorArrayMap<T>(scale, C)) \
48  .colwise() + \
49  ConstEigenVectorArrayMap<T>(bias, C); \
50  }
51 CAFFE2_SPECIALIZED_AFFINE_CHANNEL(float)
52 #undef CAFFE2_SPECIALIZED_AFFINE_CHANNEL
53 
54 } // namespace math
55 } // namespace caffe2
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13