1 #ifndef CAFFE2_OPERATORS_INT8_CHANNEL_SHUFFLE_OP_H_ 2 #define CAFFE2_OPERATORS_INT8_CHANNEL_SHUFFLE_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/conv_pool_op_base.h" 10 #include "caffe2/operators/quantized/int8_utils.h" 20 OPERATOR_NEEDS_FEATURE(
21 this->order_ == StorageOrder::NHWC,
22 "Int8ChannelShuffleOp only supports NHWC order");
26 if (this->qnnpackOperator_ !=
nullptr) {
27 qnnp_delete_operator(this->qnnpackOperator_);
28 this->qnnpackOperator_ =
nullptr;
32 bool RunOnDeviceWithOrderNHWC()
override {
33 const auto& X = Inputs()[0]->template Get<Int8TensorCPU>();
34 auto* Y = Outputs()[0]->template GetMutable<Int8TensorCPU>();
37 Y->zero_point = X.zero_point;
38 const int32_t Y_offset = this->
template GetSingleArgument<int>(
"Y_zero_point", 0);
39 const float Y_scale = this->
template GetSingleArgument<float>(
"Y_scale", 1.0f);
40 CHECK_EQ(Y_offset, X.zero_point);
41 CHECK_EQ(Y_scale, X.scale);
42 CHECK_GE(X.zero_point, std::numeric_limits<uint8_t>::min());
43 CHECK_LE(X.zero_point, std::numeric_limits<uint8_t>::max());
45 const auto C = X.t.dim32(3);
46 const auto G = this->group_;
47 CAFFE_ENFORCE(
C % G == 0,
"");
48 const auto B = X.t.numel() /
C;
52 if (this->qnnpackOperator_ ==
nullptr) {
53 const qnnp_status createStatus = qnnp_create_channel_shuffle_nc_x8(
57 &this->qnnpackOperator_);
59 createStatus == qnnp_status_success,
60 "failed to create QNNPACK channel shuffle operator");
61 CAFFE_ENFORCE(this->qnnpackOperator_ !=
nullptr);
64 const qnnp_status setupStatus = qnnp_setup_channel_shuffle_nc_x8(
65 this->qnnpackOperator_,
67 X.t.template data<uint8_t>(),
69 Y->t.template mutable_data<uint8_t>(),
72 setupStatus == qnnp_status_success,
73 "failed to setup QNNPACK channel shuffle operator");
76 const qnnp_status runStatus =
77 qnnp_run_operator(this->qnnpackOperator_,
nullptr );
79 pthreadpool_t threadpool =
80 reinterpret_cast<pthreadpool_t
>(ws_->GetThreadPool());
81 const qnnp_status runStatus =
82 qnnp_run_operator(this->qnnpackOperator_, threadpool);
85 runStatus == qnnp_status_success,
86 "failed to run QNNPACK channel shuffle operator");
94 qnnp_operator_t qnnpackOperator_{
nullptr};
101 #endif // CAFFE2_OPERATORS_INT8_CHANNEL_SHUFFLE_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 ...