Caffe2 - C++ API
A deep learning, cross platform ML framework
ulp.h
1 #pragma once
2 
3 #include "caffe2/core/operator.h"
4 #include "caffe2/core/tensor.h"
5 
6 namespace caffe2 {
7 
8 constexpr size_t k2b1bXBits = 2;
9 
10 struct ConvArgs {
11  int stride_w{1};
12  int stride_h{1};
13  int pad_l{0};
14  int pad_t{0};
15  int pad_b{0};
16  int pad_r{0};
17 };
18 
19 using ParallelFor = std::function<void(size_t, std::function<void(size_t)>)>;
20 
21 struct QConvState {
22  std::vector<std::unique_ptr<TensorCPU>> XQs;
23  std::vector<std::unique_ptr<TensorCPU>> YQs;
24  std::unique_ptr<TensorCPU> WQ;
25  // architecture-dependent whether packing is used.
26  std::unique_ptr<TensorCPU> WQPacked;
27  std::unique_ptr<TensorCPU> WQN;
28  std::unique_ptr<TensorCPU> WQL1Norm;
29  // Useful for e.g. incomplete tiles
30  std::unique_ptr<TensorCPU> scratch;
31  std::unique_ptr<TensorCPU> scratchColBuffer;
32 
33  std::unique_ptr<TensorCPU> bias;
34 
35  ParallelFor parallelFor{nullptr};
36 };
37 
38 void uniformQuantize2b1b(const TensorCPU& X,
39  const std::vector<std::unique_ptr<TensorCPU>>& XQ,
40  float offset,
41  float inter_center_distance);
42 
43 void qpad_zero(const ConvArgs& args, const TensorCPU& X, TensorCPU* Y);
44 
45 inline size_t divRoundUp(size_t x, size_t d) { return (x + d - 1) / d; }
46 
47 void signQuantize(const TensorCPU& X, TensorCPU* XQ);
48 void filterNormalization11(const TensorCPU& WQ, TensorCPU* WQN);
49 void filterNormalizationL1(const TensorCPU& W, TensorCPU* WL1);
50 std::unique_ptr<QConvState> create2b1bConvState(Workspace* ws,
51  const TensorCPU& W,
52  const TensorCPU* b);
53 void run2b1bConvGeneric(QConvState* state, const ConvArgs& args, const TensorCPU& X, TensorCPU* Y);
54 void qconv(
55  const ConvArgs& args, const TensorCPU& X, const TensorCPU& W, const TensorCPU* b, TensorCPU* Y);
56 void qim2col(const ConvArgs& args, const TensorCPU& XQ, const TensorCPU& WQ, TensorCPU* XQcol);
57 
58 void run2b1bUnification(QConvState* state,
59  size_t N,
60  size_t C,
61  const float* WQNVdata,
62  const float* YQs0Vdata,
63  const float* YQs1Vdata,
64  size_t YQstride,
65  float* Ydata,
66  size_t Ystride,
67  const float* bias);
68 
69 } // namespace caffe2
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
Definition: static.cpp:64