1 #ifndef CAFFE2_OPERATORS_INT8_SLICE_OP_H_ 2 #define CAFFE2_OPERATORS_INT8_SLICE_OP_H_ 4 #include "caffe2/core/context.h" 5 #include "caffe2/core/operator.h" 6 #include "caffe2/core/tensor_int8.h" 7 #include "caffe2/operators/quantized/int8_utils.h" 8 #include "caffe2/operators/slice_op.h" 16 template <
class... Args>
19 bool RunOnDevice()
override {
20 if (InputSize() > 1) {
23 return DoRunWithType<int64_t>();
27 template <
typename SIndex>
28 bool DoRunWithType() {
29 if (InputSize() > 1) {
30 ReinitializeAndCopyFrom(&starts_host_, at::dtype<SIndex>().device(CPU),
Input(1));
31 ReinitializeAndCopyFrom(&ends_host_, at::dtype<SIndex>().device(CPU),
Input(2));
33 if (!statically_inited_) {
36 CAFFE_ENFORCE_EQ(starts_.size(), ends_.size());
39 &starts_host_, {
static_cast<int64_t
>(starts_.size())}, at::dtype<SIndex>().device(CPU));
41 &ends_host_, {
static_cast<int64_t
>(ends_.size())}, at::dtype<SIndex>().device(CPU));
44 starts_host_.template mutable_data<SIndex>(),
46 sizeof(SIndex) * starts_.size());
48 ends_host_.template mutable_data<SIndex>(),
50 sizeof(SIndex) * ends_.size());
51 statically_inited_ =
true;
57 int32_t Y_offset = this->
template GetSingleArgument<int>(
"Y_zero_point", 0);
58 auto Y_scale = this->
template GetSingleArgument<float>(
"Y_scale", 1);
59 CHECK_EQ(Y_offset, X.zero_point);
60 CHECK_EQ(Y_scale, X.scale);
62 Y->zero_point = Y_offset;
64 return SliceImpl<SIndex, CPUContext>(
65 &Y->t, X.t, starts_host_, ends_host_, &context_);
73 #endif // CAFFE2_OPERATORS_INT8_SLICE_OP_H_ void ReinitializeTensor(Tensor *tensor, at::IntArrayRef dims, at::TensorOptions options)
Reinitialize a Tensor to given dims and options if necessary, note that this will not do anything if ...
const Tensor & Input(int idx, DeviceType type=CPUContext::GetDeviceType())
Retrieve a non-owning reference to the input at position 'idx' for this operator. ...
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
bool HasArgument(const string &name) const
Checks if the operator has an argument of the given name.