Caffe2 - C++ API
A deep learning, cross platform ML framework
fbgemm_pack_op.h
1 #pragma once
2 
3 #include "caffe2/core/operator.h"
4 #include "caffe2/operators/conv_op.h"
5 #include "caffe2/quantization/server/conv_pool_dnnlowp_op_base.h"
6 #include "caffe2/quantization/server/fbgemm_pack_blob.h"
7 #include "caffe2/quantization/server/fully_connected_dnnlowp_op.h"
8 
9 namespace caffe2 {
10 
11 using FCFp32Op = FullyConnectedOp<CPUContext>;
12 
14  : public DNNLowPOp<std::uint8_t, FCFp32Op> {
15  public:
17  const OperatorDef& operator_def,
18  Workspace* ws);
19  USE_OPERATOR_FUNCTIONS(CPUContext);
20 
21  bool RunOnDevice() override;
22 
23  private:
24  int axis_w_;
25  bool quantize_channelwise_;
26  int nbits_in_non_outlier_; // only for DNNLOWP_ACC16
27 
28  INPUT_TAGS(FILTER, BIAS);
29 };
30 
32 
46  : public ConvPoolDNNLowPOpBase<std::uint8_t, ConvFp32Op> {
47  public:
48  USE_CONV_POOL_BASE_FUNCTIONS(CPUContext);
49  USE_CONV_POOL_DNNLOWP_OPERATOR_BASE_FUNCTIONS(std::uint8_t, ConvFp32Op);
50  ConvDNNLowPPackWeightOp(const OperatorDef& operator_def, Workspace* ws);
51 
52  bool RunOnDevice() override;
53 
54  private:
55  bool TakeDepthWise3x3FastPath_();
56  bool TakeDepthWise3x3x3FastPath_();
57  bool TakeGConvFastPath_();
58 
59  bool quantize_groupwise_;
60  int nbits_in_non_outlier_; // only for DNNLOWP_ACC16
61 
62  INPUT_TAGS(FILTER, BIAS);
63 };
64 
65 // Helper functions for packing weights that can be used by
66 // ConvDNNLowPAcc16PackWeightOp, ConvDNNLowPOp, and ConvDNNLowPAcc16Op
67 
68 template <typename T>
69 void QuantizeWeight(
70  const Blob& blob,
71  int kernel_dim,
72  int M,
73  vector<dnnlowp::TensorQuantizationParams>& qparams,
74  vector<typename std::make_signed<T>::type>& w_quantized,
76 
77 template <typename T>
78 void ComputeColumnOffsets(
79  int num_rows,
80  int num_cols,
81  const T* W,
82  const vector<dnnlowp::TensorQuantizationParams>& qparams,
83  vector<int32_t>& col_offsets);
84 
88 fbgemm::CompressedSparseColumn* ExtractOutlierMatrix(
89  int groups,
90  int kernel_dim,
91  int M,
92  int nbits_in_non_outlier,
93  vector<std::int8_t>& W_quantized);
94 
95 } // namespace caffe2
Blob is a general container that hosts a typed pointer.
Definition: blob.h:24
Definition: any.cpp:108
The CPU Context, representing the bare minimum of what a Context class in Caffe2 should implement...
Definition: context.h:40
Workspace is a class that holds all the related objects created during runtime: (1) all blobs...
Definition: workspace.h:47
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13
Pack a weight matrix that can be used by DNNLOWP Int8Conv operators.
A convenient base class for C2 operators with DNNLOWP engine.
Definition: dnnlowp_op.h:77