# US 12,602,178 B2 · Determining target calculation models that need memory allocation

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 12,602,178 B2
- Document ID: US12602178B2
- Status: Granted
- Kind: B2
- Application number: 17/385,106
- Filed: 2021-07-26
- Published: 2022-02-03
- Granted: 2026-04-14
- Earliest claimed: 2020-07-31
- Assignees: Sigmastar Technology Ltd.
- Applicants: SigmaStar Technology Ltd.
- Inventors: Xiaolong Liu
- Web page: https://patentgrep.com/patent/US12602178B2

## CPC

- G06F 3/0631: {by allocating resources to storage systems}
- G06N 3/063: using electronic means
- G06F 3/0604: {Improving or facilitating administration, e.g. storage management}
- G06F 3/0673: {Single storage device}
- G06F 9/5016: {the resource being the memory}
- G06N 3/045: Combinations of networks
- G06N 3/0464: Convolutional networks [CNN, ConvNet]
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)
- G06N: COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS

## Abstract

The present application discloses a memory allocation method, including: determining a plurality of target calculation models that need memory allocation; determining a target tensor of each of the target calculation models which a memory occupancy is needed during a calculation process; determining, according to lifecycles of the target tensors, a target memory space occupied by each of the target calculation models during the calculation process; and determining, according to the target memory spaces occupied by the target calculation models, a total memory space occupied by the target calculation models. Thus, an electronic apparatus is not required to allocate memory spaces for all the tensors, achieving the object of reducing the memory space occupied by calculation models.

## Claims

### Claim 1

A memory allocation method, applied to an electronic apparatus, the method comprising:
determining a plurality of target calculation models that need memory allocation;
determining a target tensor of each of the target calculation models which a memory occupancy is needed during a calculation process;
determining, according to lifecycles of the target tensors, a target memory space occupied by each of the target calculation models during the calculation process; and
determining, according to the target memory spaces occupied by the target calculation models, a total memory space occupied by the target calculation models during the calculation process; and
allocating, according to the total memory space, a portion of memory of the electronic apparatus to execute the target calculation models,
wherein the determining a target tensor of each of the target calculation models which a memory occupancy is needed during a calculation process comprises:
performing a topology analysis on each of the target calculation models to obtain a topology of operators in each of the target calculation models;
sorting depth priorities of the operators in each of the target calculation models according to the topology to obtain sorting information;
grouping each of the target calculation models into a plurality of operator sets according to the sorting information of each of the target calculation models; and
determining the target tensor of the operator sets included in each of the target calculation models which the memory occupancy is needed during the calculation process;
wherein, the operator sets comprise at least one predetermined type of operator, and a shape of an input tensor and a shape of an output tensor of the predetermined type of operator are different.

### Claim 2 (depends on 1)

The memory allocation method according to claim 1, wherein the total memory space occupied by the target calculation models during the calculation process is determined according to a largest of the target memory spaces occupied by the target calculation models.

### Claim 3 (depends on 1)

The memory allocation method according to claim 1, wherein the grouping each of the target calculation models into the plurality of operator sets according to the sorting information of each of the target calculation models comprises:
grouping, according to the sorting information of each of the target calculation models and that a first operator of the operator set is the predetermined type of operator, the predetermined type of operator and a non-predetermined type of operator connected to the predetermined type of operator into a same operator set.

### Claim 4 (depends on 3)

The memory allocation method according to claim 3, wherein the determining the target tensor of the operator sets included in each of the target calculation models which the memory occupancy is needed during the calculation process comprises:
determining an input tensor and an output tensor of the operator sets included in each of the target calculation models as the target tensor.

### Claim 5 (depends on 1)

The memory allocation method according to claim 1, further comprising:
allocating the total memory space to the target calculation models, wherein each of the target calculation models repeatedly uses a memory region.

### Claim 6 (depends on 1)

The memory allocation method according to claim 1, further comprising:
during the calculation process of each of the target calculation models, carrying a non-target tensor in each operator set included therein by a predetermined buffer.

### Claim 7 (depends on 5)

The memory allocation method according to claim 5, further comprising, during the calculation process of each of the target calculation models, when a non-occupied memory space in the total memory space is sufficient for occupancy by the target tensor but a largest empty block in the non-occupied memory space is insufficient for occupancy of the target tensor, performing a memory organization operation on the non-occupied memory space.

### Claim 8

An electronic apparatus, comprising a processor and a memory, the memory having a computer program stored therein, wherein when the computer program executed by the processor it performs a memory allocation method, the memory allocation method comprises:
determining a plurality of target calculation models that need memory allocation;
determining a target tensor of each of the target calculation models which a memory occupancy is needed during a calculation process;
determining, according to lifecycles of the target tensors, a target memory space occupied by each of the target calculation models during the calculation process;
determining, according to the target memory spaces occupied by the target calculation models, a total memory space occupied by the target calculation models during the calculation process; and
allocating, according to the total memory space, a portion of memory of the electronic apparatus to execute the target calculation models,
wherein the determining a target tensor of each of the target calculation models which a memory occupancy is needed during a calculation process comprises:
performing a topology analysis on each of the target calculation models to obtain a topology of operators in each of the target calculation models;
sorting depth priorities of the operators in each of the target calculation models according to the topology to obtain sorting information;
grouping each of the target calculation models into a plurality of operator sets according to the sorting information of each of the target calculation models; and
determining the target tensor of the operator sets included in each of the target calculation models which the memory occupancy is needed during the calculation process;
wherein, the operator sets comprise at least one predetermined type of operator, and a shape of an input tensor and a shape of an output tensor of the predetermined type of operator are different.

### Claim 9

A memory allocation method, applied to an electronic apparatus, the method comprising:
determining a plurality of target calculation models that need memory allocation;
determining a target tensor of each of the target calculation models which a memory occupancy is needed during a calculation process;
determining, according to lifecycles of the target tensors, a target memory space occupied by each of the target calculation models during the calculation process;
determining, according to the target memory spaces occupied by the target calculation models, a total memory space occupied by the target calculation models during the calculation process; and
allocating, according to the total memory space, a portion of memory of the electronic apparatus to execute the target calculation models,
wherein the determining, according to the lifecycles of the target tensors, the target memory space occupied by each of the target calculation models during the calculation process comprises:
pre-allocating, according to the lifecycles of the target tensors and constraints that a target tensor in a living state occupies a memory space and a memory space for a target tensor in a non-living state is released, the memory space to each of the target calculation models; and
determining the memory space pre-allocated to each of the target calculation models as the target memory space of the memory occupied by each of the target calculation models during the calculation process.

### Claim 10 (depends on 9)

The memory allocation method according to claim 9, wherein the pre-allocating the memory space to each of the target calculation models comprises:
when the target tensor is switched from the non-living state to the living state, if the released memory space is sufficient for occupancy by the target tensor, pre-allocating the memory space from the released memory space to the target tensor.

### Claim 11 (depends on 10)

The memory allocation method according to claim 10, further comprising:
if the released memory space is insufficient for occupancy by the target tensor, pre-allocating a new memory space to the target tensor.

### Claim 12 (depends on 9)

The memory allocation method according to claim 9, wherein the pre-allocating the memory space of each of the target calculation models further comprises:
determining a target tensor pair of an input/output relationship existing in the target tensor of each of the target calculation models, wherein the target tensor pair comprises an input target tensor and an output target tensor; and
for each target tensor pair, if the input target tensor therein is not used again after being inputted, pre-allocating the same memory space to the target tensor pair.
