1 #ifndef CAFFE2_INT8_SIGMOID_OP_H_ 2 #define CAFFE2_INT8_SIGMOID_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" 20 if (this->qnnpackOperator_ !=
nullptr) {
21 qnnp_delete_operator(this->qnnpackOperator_);
22 this->qnnpackOperator_ =
nullptr;
26 bool RunOnDevice()
override {
27 const auto& X = Inputs()[0]->template Get<Int8TensorCPU>();
28 auto* Y = Outputs()[0]->template GetMutable<Int8TensorCPU>();
29 const int32_t Y_zero_point =
30 this->
template GetSingleArgument<int>(
"Y_zero_point", 0);
32 this->
template GetSingleArgument<float>(
"Y_scale", 1);
33 CHECK_EQ(Y_zero_point, 0);
34 CHECK_EQ(Y_scale, 1.0f / 256.0f);
41 const uint8_t X_zero_point = X.zero_point;
42 const float X_scale = X.scale;
45 Y->zero_point = Y_zero_point;
50 if (this->qnnpackOperator_ ==
nullptr) {
51 const qnnp_status createStatus = qnnp_create_sigmoid_nc_q8(
53 X_zero_point, X_scale,
54 static_cast<uint8_t>(Y_zero_point), Y_scale,
60 createStatus == qnnp_status_success,
61 "failed to create QNNPACK Sigmoid operator");
62 CAFFE_ENFORCE(this->qnnpackOperator_ !=
nullptr);
65 const qnnp_status setupStatus = qnnp_setup_sigmoid_nc_q8(
66 this->qnnpackOperator_,
68 X.t.template data<uint8_t>(),
70 Y->t.template mutable_data<uint8_t>(),
73 setupStatus == qnnp_status_success,
74 "failed to setup QNNPACK Sigmoid operator");
77 const qnnp_status runStatus =
78 qnnp_run_operator(this->qnnpackOperator_,
nullptr );
80 pthreadpool_t threadpool =
81 reinterpret_cast<pthreadpool_t
>(ws_->GetThreadPool());
82 const qnnp_status runStatus =
83 qnnp_run_operator(this->qnnpackOperator_, threadpool);
86 runStatus == qnnp_status_success,
87 "failed to run QNNPACK Sigmoid operator");
95 qnnp_operator_t qnnpackOperator_{
nullptr};
100 #endif // CAFFE2_INT8_SIGMOID_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 ...