| 54 | class GeometryEyeLike : public GeometryComputer { |
| 55 | public: |
| 56 | virtual bool onCompute(const Op* op, const std::vector<Tensor*>& inputs, const std::vector<Tensor*>& outputs, |
| 57 | Context& context, CommandBuffer& res) const override { |
| 58 | int k = 0; |
| 59 | if (inputs.size() == 2) { |
| 60 | k = inputs[1]->host<int>()[0]; |
| 61 | } |
| 62 | auto shape = outputs[0]->shape(); |
| 63 | int row = shape[shape.size() - 2], col = shape[shape.size() - 1]; |
| 64 | int batch = (shape.size() == 3 ? shape[0] : 1); |
| 65 | |
| 66 | auto outputDes = TensorUtils::getDescribe(outputs[0]); |
| 67 | outputDes->memoryType = Tensor::InsideDescribe::MEMORY_VIRTUAL; |
| 68 | if (k >= col || k <= -row) { |
| 69 | outputDes->regions.clear(); |
| 70 | return true; |
| 71 | } |
| 72 | outputDes->regions.resize(1); |
| 73 | auto& reg = outputDes->regions[0]; |
| 74 | auto type = outputs[0]->getType(); |
| 75 | auto oneConst = context.allocConst(op, {}, type); |
| 76 | if (type == halide_type_of<float>()) { |
| 77 | oneConst->host<float>()[0] = 1.0; |
| 78 | } else { |
| 79 | oneConst->host<int>()[0] = 1; |
| 80 | } |
| 81 | reg.origin = oneConst.get(); |
| 82 | reg.src.stride[0] = reg.src.stride[1] = 0; |
| 83 | reg.dst.stride[0] = row * col; |
| 84 | reg.dst.stride[1] = col + 1; |
| 85 | reg.size[0] = batch; |
| 86 | if (k >= 0) { |
| 87 | reg.dst.offset = k; |
| 88 | reg.size[1] = ALIMIN(row, col - k); |
| 89 | } else { |
| 90 | reg.dst.offset = (-k) * col; |
| 91 | reg.size[1] = ALIMIN(row + k, col); |
| 92 | } |
| 93 | |
| 94 | return true; |
| 95 | } |
| 96 | }; |
| 97 | |
| 98 | static void _create() { |