Caffe2 - C++ API
A deep learning, cross platform ML framework
ulp.h
1 
17 #pragma once
18 
19 #include "caffe2/core/operator.h"
20 #include "caffe2/core/tensor.h"
21 
22 namespace caffe2 {
23 
24 constexpr size_t k2b1bXBits = 2;
25 
26 struct ConvArgs {
27  int stride_w{1};
28  int stride_h{1};
29  int pad_l{0};
30  int pad_t{0};
31  int pad_b{0};
32  int pad_r{0};
33 };
34 
35 using ParallelFor = std::function<void(size_t, std::function<void(size_t)>)>;
36 
37 struct QConvState {
38  std::vector<std::unique_ptr<TensorCPU>> XQs;
39  std::vector<std::unique_ptr<TensorCPU>> YQs;
40  std::unique_ptr<TensorCPU> WQ;
41  // architecture-dependent whether packing is used.
42  std::unique_ptr<TensorCPU> WQPacked;
43  std::unique_ptr<TensorCPU> WQN;
44  std::unique_ptr<TensorCPU> WQL1Norm;
45  // Useful for e.g. incomplete tiles
46  std::unique_ptr<TensorCPU> scratch;
47  std::unique_ptr<TensorCPU> scratchColBuffer;
48 
49  std::unique_ptr<TensorCPU> bias;
50 
51  ParallelFor parallelFor{nullptr};
52 };
53 
54 void uniformQuantize2b1b(const TensorCPU& X,
55  const std::vector<std::unique_ptr<TensorCPU>>& XQ,
56  float offset,
57  float inter_center_distance);
58 
59 void qpad_zero(const ConvArgs& args, const TensorCPU& X, TensorCPU* Y);
60 
61 inline size_t divRoundUp(size_t x, size_t d) { return (x + d - 1) / d; }
62 
63 void signQuantize(const TensorCPU& X, TensorCPU* XQ);
64 void filterNormalization11(const TensorCPU& WQ, TensorCPU* WQN);
65 void filterNormalizationL1(const TensorCPU& W, TensorCPU* WL1);
66 std::unique_ptr<QConvState> create2b1bConvState(Workspace* ws,
67  const TensorCPU& W,
68  const TensorCPU* b);
69 void run2b1bConvGeneric(QConvState* state, const ConvArgs& args, const TensorCPU& X, TensorCPU* Y);
70 void qconv(
71  const ConvArgs& args, const TensorCPU& X, const TensorCPU& W, const TensorCPU* b, TensorCPU* Y);
72 void qim2col(const ConvArgs& args, const TensorCPU& XQ, const TensorCPU& WQ, TensorCPU* XQcol);
73 
74 void run2b1bUnification(QConvState* state,
75  size_t N,
76  size_t C,
77  const float* WQNVdata,
78  const float* YQs0Vdata,
79  const float* YQs1Vdata,
80  size_t YQstride,
81  float* Ydata,
82  size_t Ystride,
83  const float* bias);
84 
85 } // namespace caffe2
Workspace is a class that holds all the related objects created during runtime: (1) all blobs...
Definition: workspace.h:63
Copyright (c) 2016-present, Facebook, Inc.