30 #include "caffe2/core/common.h"
31 #include "caffe2/utils/math.h"
35 template <
typename T,
class Context,
class Engine = DefaultEngine>
36 class TcOp :
public Operator<Context> {
38 TcOp(
const OperatorDef& operator_def, Workspace* ws)
39 : caffe2::Operator<Context>(operator_def, ws),
40 tc_(OperatorBase::GetSingleArgument<std::string>(
"tcDef",
"ERROR")),
42 OperatorBase::GetSingleArgument<std::string>(
"tcName",
"ERROR")),
46 OperatorBase::GetSingleArgument<std::string>(
"tcGradDef",
"ERROR");
48 OperatorBase::GetSingleArgument<std::string>(
"tcGradName",
"ERROR");
49 profile_ = OperatorBase::GetSingleArgument<bool>(
"profile",
false);
50 ArgumentHelper args(operator_def);
51 if (args.HasArgument(
"mappingOptions")) {
53 args.GetSingleArgument<std::string>(
"mappingOptions",
"ERROR"));
58 if (args.HasArgument(
"gradMappingOptions")) {
60 args.GetSingleArgument<std::string>(
"gradMappingOptions",
"ERROR"));
84 for (
int i = 0; i < tensorInfo.size(); ++i) {
85 auto info = tensorInfo[i];
86 std::vector<int64_t> shape(info->shape, info->shape + info->ndim);
87 Output(i)->Resize(shape);
89 Output(i)->template mutable_data<T>();
99 std::vector<::tc::dlutils::DLTensorUPtr> inTensorUPtrs;
100 std::vector<const DLTensor*> inputDLTensors;
101 for (
int idx = 0; idx < this->InputSize(); ++idx) {
102 auto dims = this->Input(idx).dims();
103 inTensorUPtrs.emplace_back(
105 inputDLTensors.push_back(inTensorUPtrs.back().get());
113 std::vector<::tc::dlutils::DLTensorUPtr> outTensorUPtrs;
114 std::vector<DLTensor*> outputDLTensors;
115 for (
int i = 0; i < OutputSize(); ++i) {
117 outputDLTensors.push_back(outTensorUPtrs.back().get());
142 using GradientMakerBase::GradientMakerBase;
145 ArgumentHelper args(Def());
146 CHECK(
false) <<
"NYI gradient";
tc::MappingOptions mappingOptions_
Definition: tc_op.h:133
Definition: execution_engine.h:34
bool profile_
Definition: tc_op.h:132
USE_OPERATOR_CONTEXT_FUNCTIONS
Definition: tc_op.h:68
std::string gradTc_
Definition: tc_op.h:129
std::string gradTcName_
Definition: tc_op.h:131
virtual void setupNaiveMappingOptions()
Definition: tc_op.h:76
std::string tc_
Definition: tc_op.h:128
~TcOp() override
Definition: tc_op.h:70
std::string tcName_
Definition: tc_op.h:130
void prepareOutputs(const std::vector< const DLTensor * > tensorInfo)
Definition: tc_op.h:83
std::unique_ptr< tc::ExecutionEngine > executionEngine_
Definition: tc_op.h:137
std::vector< OperatorDef > GetGradientDefs() override
Definition: tc_op.h:144
tc::dlutils::DLTensorUPtr makeConstDLTensor(const caffe2::Tensor< C2Context > &tensor, const vector< TIndex > &shapeOverride={})
Definition: dlpack_c2.h:61
Definition: mapping_options.h:336
virtual bool RunOnDevice() override
Definition: tc_op.h:93
tc::dlutils::DLTensorUPtr makeDLTensor(caffe2::Tensor< C2Context > *tensor)
Definition: dlpack_c2.h:88
TcOp(const OperatorDef &operator_def, Workspace *ws)
Definition: tc_op.h:38
virtual void setupDefaultGradMappingOptions()
Definition: tc_op.h:81
tc::MappingOptions gradMappingOptions_
Definition: tc_op.h:134