1 #ifndef CAFFE2_OPERATORS_INT8_LEAKY_RELU_OP_H_ 2 #define CAFFE2_OPERATORS_INT8_LEAKY_RELU_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" 19 const float alpha = this->
template GetSingleArgument<float>(
"alpha", 0.01);
20 CAFFE_ENFORCE_GT(alpha, 0.0);
21 CAFFE_ENFORCE_LT(alpha, 1.0);
26 if (this->qnnpackOperator_ !=
nullptr) {
27 qnnp_delete_operator(this->qnnpackOperator_);
28 this->qnnpackOperator_ =
nullptr;
32 bool RunOnDevice()
override {
33 const auto& X = Inputs()[0]->template Get<Int8TensorCPU>();
34 auto* Y = Outputs()[0]->template GetMutable<Int8TensorCPU>();
35 const int32_t Y_zero_point =
36 this->
template GetSingleArgument<int>(
"Y_zero_point", 0);
38 this->
template GetSingleArgument<float>(
"Y_scale", 1);
39 CHECK_GE(Y_zero_point, std::numeric_limits<uint8_t>::min());
40 CHECK_LE(Y_zero_point, std::numeric_limits<uint8_t>::max());
47 const uint8_t X_zero_point = X.zero_point;
48 const float X_scale = X.scale;
51 Y->zero_point = Y_zero_point;
56 if (this->qnnpackOperator_ ==
nullptr) {
57 const qnnp_status createStatus = qnnp_create_leaky_relu_nc_q8(
60 static_cast<uint8_t>(X_zero_point), X_scale,
61 static_cast<uint8_t>(Y_zero_point), Y_scale,
67 createStatus == qnnp_status_success,
68 "failed to create QNNPACK Leaky ReLU operator");
69 CAFFE_ENFORCE(this->qnnpackOperator_ !=
nullptr);
72 const qnnp_status setupStatus = qnnp_setup_leaky_relu_nc_q8(
73 this->qnnpackOperator_,
75 X.t.template data<uint8_t>(),
77 Y->t.template mutable_data<uint8_t>(),
80 setupStatus == qnnp_status_success,
81 "failed to setup QNNPACK Leaky ReLU operator");
84 const qnnp_status runStatus =
85 qnnp_run_operator(this->qnnpackOperator_,
nullptr );
87 pthreadpool_t threadpool =
88 reinterpret_cast<pthreadpool_t
>(ws_->GetThreadPool());
89 const qnnp_status runStatus =
90 qnnp_run_operator(this->qnnpackOperator_, threadpool);
93 runStatus == qnnp_status_success,
94 "failed to run QNNPACK Leaky ReLU operator");
103 qnnp_operator_t qnnpackOperator_{
nullptr};
110 #endif // CAFFE2_OPERATORS_INT8_LEAKY_RELU_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 ...