Caffe2 - C++ API
A deep learning, cross platform ML framework
smart_tensor_printer.h
1 
17 #pragma once
18 
19 #include "caffe2/core/tensor.h"
20 
21 namespace caffe2 {
22 
23 // This is a wrapper around the TensorPrinter that doesn't require the user to
24 // explicit specify the type of the tensor while calling the Print() method.
25 // It also supports a convenience function with a default constructed printer as
26 // a static method.
28  public:
29  // The proliferation of constructors is to give the feature parity with
30  // TensorPrinter
31  // yet not repeat the default arguments explicitly in case they change in the
32  // future.
33  SmartTensorPrinter() = default;
34 
35  explicit SmartTensorPrinter(const std::string& tensor_name);
36 
38  const std::string& tensor_name,
39  const std::string& file_name);
40 
42  const std::string& tensor_name,
43  const std::string& file_name,
44  int limit);
45 
46  void Print(const Tensor<CPUContext>& tensor);
47 
48  template <class Context>
49  void PrintMeta(const Tensor<Context>& tensor) {
50  tensorPrinter_.PrintMeta(tensor);
51  }
52 
53  // Uses a default constructed SmartTensorPrinter
54  static void PrintTensor(const Tensor<CPUContext>& tensor);
55 
56  // Uses a default constructed SmartTensorPrinter
57  template <class Context>
58  void PrintTensorMeta(const Tensor<Context>& tensor) {
59  DefaultTensorPrinter().PrintMeta(tensor);
60  }
61 
62  private:
63  // Returns a thread local default constructed TensorPrinter
64  static SmartTensorPrinter& DefaultTensorPrinter();
65 
66  TensorPrinter tensorPrinter_;
67 };
68 }
Copyright (c) 2016-present, Facebook, Inc.