MCPcopy Create free account
hub / github.com/XiaoMi/mace / get_mem_size

Method get_mem_size

tools/python/micro/mem_computer.py:53–73  ·  view source on GitHub ↗
(self, op, output_shape)

Source from the content-addressed store, hash-verified

51 self.ref_counts[tensor_name] += 1
52
53 def get_mem_size(self, op, output_shape):
54 np_data_type = self.np_data_type
55 if len(op.output_type) > 0:
56 np_data_type = \
57 data_type_to_np_dt(op.output_type[0], self.np_data_type)
58 data_type_bytes = np.dtype(np_data_type).itemsize
59 if op.type == 'WinogradTransform' or op.type == 'GEMM':
60 mace_check(len(output_shape) == 4,
61 "WinogradTransform and GEMM only support 4-dim")
62 mem_size = output_shape[2] * output_shape[3] * output_shape[0] \
63 * int((output_shape[1] + 3) / 4) * 4
64 else:
65 dim_size = len(output_shape)
66 if dim_size > 0:
67 mem_size = int((output_shape[dim_size - 1] + 3) / 4) * 4
68 for i in range(dim_size - 1):
69 mem_size *= output_shape[i]
70 else:
71 print("the op %s's output dim size is 0" % op.type)
72 mem_size = 0
73 return mem_size * data_type_bytes
74
75 def remove_mem_block_by_name(self, mem_list, tensor_name):
76 return_mem_block = None

Callers 1

fake_newMethod · 0.95

Calls 3

data_type_to_np_dtFunction · 0.90
mace_checkFunction · 0.90
dtypeMethod · 0.80

Tested by

no test coverage detected