pytorch/caffe2/utils/smart_tensor_printer.h
Jane Xu 71ca600af9 Renaming CAFFE2_API to TORCH_API (#49496)
Summary:
Since caffe2 and torch have been consolidated, CAFFE2_API should be merged with TORCH_API. Addresses a TODO.

Manually edited some references of the removed `CAFFE2_API`:
* `CONTRIBUTING.md`
* `caffe2/proto/CMakeLists.txt`
* `cmake/ProtoBuf.cmake`
* `c10/macros/Export.h`
* `torch/csrc/WindowsTorchApiMacro.h`

Pull Request resolved: https://github.com/pytorch/pytorch/pull/49496

Reviewed By: malfet, samestep

Differential Revision: D25600726

Pulled By: janeyx99

fbshipit-source-id: 7e068d959e397ac183c097d7e9a9afeca5ddd782
2020-12-18 10:54:50 -08:00

50 lines
1.4 KiB
C++

#pragma once
#include "caffe2/core/tensor.h"
namespace caffe2 {
// This is a wrapper around the TensorPrinter that doesn't require the user to
// explicit specify the type of the tensor while calling the Print() method.
// It also supports a convenience function with a default constructed printer as
// a static method.
class TORCH_API SmartTensorPrinter {
public:
// The proliferation of constructors is to give the feature parity with
// TensorPrinter
// yet not repeat the default arguments explicitly in case they change in the
// future.
SmartTensorPrinter() = default;
explicit SmartTensorPrinter(const std::string& tensor_name);
SmartTensorPrinter(
const std::string& tensor_name,
const std::string& file_name);
SmartTensorPrinter(
const std::string& tensor_name,
const std::string& file_name,
int limit);
void Print(const Tensor& tensor);
void PrintMeta(const Tensor& tensor) {
tensorPrinter_.PrintMeta(tensor);
}
// Uses a default constructed SmartTensorPrinter
static void PrintTensor(const Tensor& tensor);
// Uses a default constructed SmartTensorPrinter
void PrintTensorMeta(const Tensor& tensor) {
DefaultTensorPrinter().PrintMeta(tensor);
}
private:
// Returns a thread local default constructed TensorPrinter
static SmartTensorPrinter& DefaultTensorPrinter();
TensorPrinter tensorPrinter_;
};
}