MCPcopy Create free account
hub / github.com/MegEngine/MegCC / execute

Function execute

runtime/src/vm/reshape.c:27–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25}
26
27static TinyNNStatus execute(Instruction* inst, VM* vm) {
28 Tensor *input = inst->workload.reshape.inputs[0],
29 *shape_tensor = inst->workload.reshape.inputs[1],
30 *output = inst->workload.reshape.output;
31 output->layout = input->layout;
32 output->layout.nr_dim = shape_tensor->layout.dims[0];
33 uint32_t nr_elem = 1;
34 for (int i = 0; i < input->layout.nr_dim; ++i) {
35 nr_elem *= input->layout.dims[i];
36 }
37 int* tshape = shape_tensor->ptr;
38 int neg_axis = -1;
39 for (int i = 0; i < shape_tensor->layout.dims[0]; ++i) {
40 if (tshape[i] > 0) {
41 output->layout.dims[i] = tshape[i];
42 nr_elem = nr_elem / output->layout.dims[i];
43 } else {
44 TINYNN_ASSERT(tshape[i] == -1 && neg_axis == -1);
45 neg_axis = i;
46 }
47 }
48 if (neg_axis >= 0) {
49 output->layout.dims[neg_axis] = nr_elem;
50 }
51 force_layout_contiguous(&(output->layout));
52 output->ptr = input->ptr;
53 output->size = tensor_length_in_byte(output);
54 return TinyNN_SUCCESS;
55}
56
57static TinyNNStatus destruct(VM* vm, Instruction* inst) {
58 FREE(inst->workload.reshape.inputs);

Callers

nothing calls this directly

Calls 2

force_layout_contiguousFunction · 0.85
tensor_length_in_byteFunction · 0.85

Tested by

no test coverage detected