1 #include <caffe2/ideep/ideep_utils.h> 2 #include <caffe2/ideep/operators/operator_fallback_ideep.h> 3 #include "caffe2/operators/utility_ops.h" 4 #include "caffe2/operators/elementwise_add_op.h" 10 USE_IDEEP_DEF_ALIASES();
11 USE_IDEEP_OPERATOR_FUNCTIONS();
18 fallback_sum_(operator_def, ws),
19 fallback_add_(operator_def, ws) {}
22 bool RunOnDevice()
override {
23 itensor::dims input_dims;
24 bool fallback_to_cpu =
false;
25 vector<itensor> inputs_itensor;
30 for (
int i = 0; i < InputSize(); ++i) {
31 if (OperatorBase::InputBlob(i).template IsType<itensor>()) {
32 auto& tensor_ideep = Input(i);
33 if (input_dims.empty()) {
34 input_dims = tensor_ideep.get_dims();
35 }
else if (input_dims != tensor_ideep.get_dims()) {
36 fallback_to_cpu =
true;
39 inputs_itensor.emplace_back(tensor_ideep);
42 BlobIsTensorType(OperatorBase::InputBlob(i), CPU),
43 "Expect cpu tensor if not itensor");
44 fallback_to_cpu =
true;
49 if (!fallback_to_cpu) {
50 auto* Y = Output(OUTPUT);
51 if (InputSize() == 1) {
52 const auto& X = Input(INPUT0);
53 ideep::direct_copy::compute(X, *Y);
55 const vector<float> scales(InputSize(), 1.0);
56 ideep::sum::compute(scales, inputs_itensor, *Y);
61 if (InputSize() == 2) {
62 return fallback_add_.Run(0);
65 return fallback_sum_.Run(0);
The CPU Context, representing the bare minimum of what a Context class in Caffe2 should implement...
Workspace is a class that holds all the related objects created during runtime: (1) all blobs...
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
A templated class to allow one to wrap a CPU operator as an IDEEP operator.