1 #ifndef CAFFE2_OPERATORS_INT8_ADD_OP_H_ 2 #define CAFFE2_OPERATORS_INT8_ADD_OP_H_ 6 #include "caffe2/core/context.h" 7 #include "caffe2/core/operator.h" 8 #include "caffe2/core/tensor_int8.h" 9 #include "caffe2/operators/quantized/int8_utils.h" 15 template <Activation Ac>
22 if (this->qnnpackOperator_ !=
nullptr) {
23 qnnp_delete_operator(this->qnnpackOperator_);
24 this->qnnpackOperator_ =
nullptr;
28 bool RunOnDevice()
override {
29 CAFFE_ENFORCE_EQ(Inputs().size(), 2);
30 const auto&
A = Inputs()[0]->template Get<Int8TensorCPU>();
31 const auto&
B = Inputs()[1]->template Get<Int8TensorCPU>();
32 auto* Y = Outputs()[0]->template GetMutable<Int8TensorCPU>();
37 "inputs must have the same shape (broadcast semantics is not supported)");
44 const uint8_t A_zero_point =
A.zero_point;
45 const uint8_t B_zero_point = B.zero_point;
46 const float A_scale =
A.scale;
47 const float B_scale = B.scale;
49 const int32_t Y_zero_point =
50 this->
template GetSingleArgument<int>(
"Y_zero_point", 0);
52 this->
template GetSingleArgument<float>(
"Y_scale", 1);
54 Y->zero_point = Y_zero_point;
59 pthreadpool_t threadpool =
60 reinterpret_cast<pthreadpool_t
>(ws_->GetThreadPool());
62 if (this->qnnpackOperator_ ==
nullptr) {
63 const qnnp_status createStatus = qnnp_create_add_nc_q8(
65 A_zero_point, A_scale,
66 B_zero_point, B_scale,
67 static_cast<uint8_t>(Y_zero_point), Y_scale,
68 activationLimits(Y_scale, Y_zero_point, Ac).first,
69 activationLimits(Y_scale, Y_zero_point, Ac).second,
73 createStatus == qnnp_status_success,
74 "failed to create QNNPACK add operator");
75 CAFFE_ENFORCE(this->qnnpackOperator_ !=
nullptr);
78 const qnnp_status setupStatus = qnnp_setup_add_nc_q8(
79 this->qnnpackOperator_,
81 A.t.template data<uint8_t>(),
83 B.t.template data<uint8_t>(),
85 Y->t.template mutable_data<uint8_t>(),
88 setupStatus == qnnp_status_success,
89 "failed to setup QNNPACK add operator");
92 const qnnp_status runStatus =
93 qnnp_run_operator(this->qnnpackOperator_,
nullptr );
95 const qnnp_status runStatus =
96 qnnp_run_operator(this->qnnpackOperator_, threadpool);
99 runStatus == qnnp_status_success,
100 "failed to run QNNPACK add operator");
108 qnnp_operator_t qnnpackOperator_{
nullptr};
115 #endif // CAFFE2_OPERATORS_INT8_ADD_OP_H_
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 ...