| 14 | class GeometryStridedSlice : public GeometryComputer { |
| 15 | public: |
| 16 | virtual bool onCompute(const Op* op, const std::vector<Tensor*>& inputs, const std::vector<Tensor*>& outputs, |
| 17 | Context& context, CommandBuffer& res) const override { |
| 18 | Tensor* input = inputs[0]; |
| 19 | // input haven't realized |
| 20 | auto output = outputs[0]; |
| 21 | auto outputDes = TensorUtils::getDescribe(output); |
| 22 | outputDes->memoryType = Tensor::InsideDescribe::MEMORY_VIRTUAL; |
| 23 | outputDes->regions.clear(); |
| 24 | const int inputDim = input->buffer().dimensions; |
| 25 | auto parameter = op->main_as_StridedSliceParam(); |
| 26 | int32_t beginMask = parameter->beginMask(); |
| 27 | int32_t endMask = parameter->endMask(); |
| 28 | int32_t shrinkAxisMask = parameter->shrinkAxisMask(); |
| 29 | int32_t ellipsisMask = parameter->ellipsisMask(); |
| 30 | int32_t newAxisMask = parameter->newAxisMask(); |
| 31 | int32_t fromType = parameter->fromType(); |
| 32 | if (ellipsisMask && (ellipsisMask & (ellipsisMask - 1))) { |
| 33 | MNN_ERROR("only one non-zero bit is allowed in ellipsisMask\n"); |
| 34 | return false; |
| 35 | } |
| 36 | |
| 37 | MNN_ASSERT(inputs.size() >= 3 && inputs.size() <= 5); |
| 38 | Tensor *begin = inputs[1]; |
| 39 | Tensor *end = inputs[2]; |
| 40 | |
| 41 | int32_t strideSize = begin->length(0); |
| 42 | MNN_ASSERT(begin->buffer().dimensions == end->buffer().dimensions); |
| 43 | |
| 44 | int32_t inputShape[MNN_MAX_TENSOR_DIM] = { 0 }; |
| 45 | int32_t begins[MNN_MAX_TENSOR_DIM] = { 0 }; |
| 46 | int32_t ends[MNN_MAX_TENSOR_DIM] = { 0 }; |
| 47 | int32_t strides[MNN_MAX_TENSOR_DIM] = { 0 }; |
| 48 | int32_t axes[MNN_MAX_TENSOR_DIM] = { 0 }; |
| 49 | int32_t beginMasks[MNN_MAX_TENSOR_DIM] = { 0 }; |
| 50 | int32_t endMasks[MNN_MAX_TENSOR_DIM] = { 0 }; |
| 51 | int32_t shrinkAxisMasks[MNN_MAX_TENSOR_DIM] = { 0 }; |
| 52 | int32_t newAxisMasks[MNN_MAX_TENSOR_DIM] = { 0 }; |
| 53 | int32_t inputStride[MNN_MAX_TENSOR_DIM]; |
| 54 | |
| 55 | { |
| 56 | int stride = 1; |
| 57 | for (int i = input->buffer().dimensions - 1; i >= 0; --i) { |
| 58 | inputShape[i] = input->buffer().dim[i].extent; |
| 59 | inputStride[i] = stride; |
| 60 | stride *= inputShape[i]; |
| 61 | if (inputShape[i] == 0) { |
| 62 | return true; |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | for (int i = 0; i < inputDim; i++) { |
| 68 | inputShape[i] = input->length(i); |
| 69 | } |
| 70 | for (int i = 0; i < strideSize; i++) { |
| 71 | beginMasks[i] = beginMask & (1 << i); |
| 72 | } |
| 73 | for (int i = 0; i < strideSize; i++) { |
nothing calls this directly
no test coverage detected