Caffe2 - C++ API
A deep learning, cross platform ML framework
smart_tensor_printer.h
1 #pragma once
2 
3 #include "caffe2/core/tensor.h"
4 
5 namespace caffe2 {
6 
7 // This is a wrapper around the TensorPrinter that doesn't require the user to
8 // explicit specify the type of the tensor while calling the Print() method.
9 // It also supports a convenience function with a default constructed printer as
10 // a static method.
12  public:
13  // The proliferation of constructors is to give the feature parity with
14  // TensorPrinter
15  // yet not repeat the default arguments explicitly in case they change in the
16  // future.
17  SmartTensorPrinter() = default;
18 
19  explicit SmartTensorPrinter(const std::string& tensor_name);
20 
22  const std::string& tensor_name,
23  const std::string& file_name);
24 
26  const std::string& tensor_name,
27  const std::string& file_name,
28  int limit);
29 
30  void Print(const Tensor<CPUContext>& tensor);
31 
32  template <class Context>
33  void PrintMeta(const Tensor<Context>& tensor) {
34  tensorPrinter_.PrintMeta(tensor);
35  }
36 
37  // Uses a default constructed SmartTensorPrinter
38  static void PrintTensor(const Tensor<CPUContext>& tensor);
39 
40  // Uses a default constructed SmartTensorPrinter
41  template <class Context>
42  void PrintTensorMeta(const Tensor<Context>& tensor) {
43  DefaultTensorPrinter().PrintMeta(tensor);
44  }
45 
46  private:
47  // Returns a thread local default constructed TensorPrinter
48  static SmartTensorPrinter& DefaultTensorPrinter();
49 
50  TensorPrinter tensorPrinter_;
51 };
52 }
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...