3 #include "caffe2/core/context.h" 4 #include "caffe2/core/operator.h" 5 #include "caffe2/utils/cast.h" 6 #include "caffe2/utils/conversions.h" 7 #include "caffe2/utils/math.h" 8 #include "caffe2/core/logging.h" 9 #include "caffe2/core/types.h" 13 template <
class Context>
16 USE_OPERATOR_CONTEXT_FUNCTIONS;
21 TensorProto_DataType to = cast::GetCastDataType(helper,
"to");
22 TensorProto_DataType from = cast::GetCastDataType(helper,
"from_type");
27 bool RunOnDevice()
override {
28 return (this->*body_)();
32 void SetBody(TensorProto_DataType to);
34 template <
typename DstType>
35 bool DoRunWithDstType();
37 template <
typename DstType,
typename SrcType>
38 bool DoRunWithType() {
39 auto& input =
Input(0);
40 auto* output = Output(0);
41 output->ResizeLike(input);
42 const auto* data = input.template data<SrcType>();
43 auto* out = output->template mutable_data<DstType>();
44 auto N = input.size();
45 for (int64_t i = 0; i < N; ++i) {
46 out[i] =
static_cast<DstType
>(data[i]);
A helper class to index into arguments.
Workspace is a class that holds all the related objects created during runtime: (1) all blobs...
const Tensor & Input(int idx, DeviceType type=Context::GetDeviceType())
Retrieve a non-owning reference to the input at position 'idx' for this operator. ...
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...