MCPcopy Create free account
hub / github.com/alibaba/MNN / onCompute

Method onCompute

source/geometry/GeometryFill.cpp:56–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54class GeometryEyeLike : public GeometryComputer {
55public:
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
98static void _create() {

Callers

nothing calls this directly

Calls 7

shapeMethod · 0.80
allocConstMethod · 0.80
sizeMethod · 0.45
clearMethod · 0.45
resizeMethod · 0.45
getTypeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected