# US 2025/0147740 A1 · Method of Compiling Neural Network Model, Compiler, and Storage Medium

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

- Number: US 2025/0147740 A1
- Document ID: US20250147740A1
- Status: Published application
- Kind: A1
- Application number: 18/823,421
- Filed: 2024-09-03
- Published: 2025-05-08
- Earliest claimed: 2023-11-08
- Assignees: Verisilicon Microelectronics (Beijing) Co., Ltd.; VeriSilicon Microelectronics (Shanghai) Co., Ltd.; VeriSilicon Microelectronics (Nanjing) Co., Ltd.; Verisilicon Technology (Shanghai) Co., Ltd.; Verisilicon Microelectronics (Hainan) Co., Ltd.; Verisilicon Microelectronics (Chengdu) Co., Ltd.
- Applicants: VeriSilicon Microelectronics (Beijing) Co., Ltd.; VeriSilicon Microelectronics (Shanghai) Co., Ltd.; Verisilicon Microelectronics (Nanjing) Co., Ltd.; Verisilicon Technology (Shanghai) Co., Ltd.; Verisilicon Microelectronics (Hainan) Co., Ltd.; Verisilicon Microelectronics (Chengdu) Co., Ltd.
- Inventors: Yang Zhang
- Web page: https://patentgrep.com/patent/US20250147740A1

## CPC

- G06F 8/41: Compilation
- Y02D 10/00: Energy efficient computing, e.g. low power processors, power management or thermal management
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)
- Y02D: CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE

## Abstract

Provided are a method of compiling a neural network model, a compiler, and a computer-readable storage medium. The method of compiling a neural network model includes reading a target neural network model and obtaining the target accelerator info; generating a first directed graph corresponding to the target neural network by using operation elements as nodes and dependencies between the operation elements as edges, wherein the operation elements include operation types and accompanying parameters of the operation types; revising the first directed graph based on a software and hardware information supported by the target accelerator to generate a second directed graph; and generating a compilation result of the target neural network model based on the second directed graph.

## Claims

### Claim 1

A method of compiling a neural network model, comprising:
reading a target neural network model and obtaining a target accelerator info;
generating a first directed graph corresponding to the target neural network by using operation elements as nodes and dependencies between the operation elements as edges,
wherein the operation elements comprise operation types and accompanying parameters of the operation types;
revising the first directed graph based on a software and hardware information supported by the target accelerator to generate a second directed graph; and
generating a compilation result of the target neural network model based on the second directed graph.

### Claim 2 (depends on 1)

The method of compiling a neural network model according to claim 1, wherein before the step of revising the first directed graph based on a software and hardware information supported by the target accelerator, the method of compiling a neural network model further comprises:
optimizing the first directed graph;
the step of revising the first directed graph based on a software and hardware information supported by the target accelerator comprises:
revising the optimized first directed graph based on the software and hardware information supported by the target accelerator; and
the step of optimizing the first directed graph comprises: obtaining a first subgraph and a second subgraph from the first directed graph, wherein the first subgraph and the second subgraph are identical, and wherein both the first subgraph and the second subgraph are comprised of the nodes and edges; and
converting the first subgraph and the second subgraph into subgraph nodes.

### Claim 3 (depends on 2)

The method of compiling a neural network model according to claim 2, wherein the step of optimizing the first directed graph further comprises:
obtaining an extended API for the target accelerator, wherein the extended API comprises multiple target functions; and
associating the nodes and the target functions having the same functionalities.

### Claim 4 (depends on 3)

The method of compiling a neural network model according to claim 3, wherein the step of associating the nodes and the target functions having the same functionalities comprises:
any of splitting a single node that can achieve multiple functions,
merging multiple nodes that can achieve a single function, and
splitting a single node that can achieve multiple functions and merging multiple nodes that can achieve a single function, so as to obtain new nodes; and
associating the new nodes and the target functions having the same functionalities.

### Claim 5 (depends on 2)

The method of compiling a neural network model according to claim 2, wherein the step of optimizing the first directed graph further comprises:
converting a precision of the accompanying parameters in each node.

### Claim 6 (depends on 1)

The method of compiling a neural network model according to claim 1, wherein the step of revising the first directed graph based on a software and hardware information supported by the target accelerator comprises:
obtaining a supported storage format of the target accelerator; and
modifying a data format of the accompanying parameters to the storage format.

### Claim 7 (depends on 1)

The method of compiling a neural network model according to claim 1, wherein the step of revising the first directed graph based on a software and hardware information supported by the target accelerator comprises:
obtaining an operation type merging program supported by the target accelerator; and
merging the nodes according to the operation type merging program.

### Claim 8 (depends on 1)

The method of compiling a neural network model according to claim 1, wherein the step of generating a compilation result of the target neural network model based on the second directed graph comprises any of:
generating a C language code as the compilation result according to an order of the nodes in the second directed graph,
generating a binary model file as the compilation result based on the order of the nodes in the second directed graph and,
generating both the C language code and the binary model file as the compilation result according to the order of the nodes in the second directed graph.

### Claim 9

A compiler of a neural network model, comprising:
an input module, wherein the input module is configured for reading a target neural network model and obtaining the target accelerator info;
a conversion module, wherein the conversion module is configured for generating a first directed graph corresponding to the target neural network by using operation elements as nodes and dependencies between the operation elements as edges, wherein the operation elements comprise operation types and accompanying parameters of the operation types;
a revision module, wherein the revision module is configured for revising the first directed graph based on a software and hardware information supported by the target accelerator to generate a second directed graph; and
a compilation module, wherein the compilation module is configured for generating a compilation result of the target neural network model based on the second directed graph.

### Claim 10 (depends on 1)

A non-transitory computer-readable storage medium, storing a computer program, wherein the computer program is executed by a processor to implement the method of compiling a neural network model according to claim 1.

### Claim 11 (depends on 10)

The computer-readable storage medium according to claim 10, wherein before the step of revising the first directed graph based on a software and hardware information supported by the target accelerator, the method of compiling a neural network model further comprises:
optimizing the first directed graph;
the step of revising the first directed graph based on a software and hardware information supported by the target accelerator comprises:
revising the optimized first directed graph based on the software and hardware information supported by the target accelerator; and
the step of optimizing the first directed graph comprises: obtaining a first subgraph and a second subgraph from the first directed graph, wherein the first subgraph and the second subgraph are identical, and wherein both the first subgraph and the second subgraph are comprised of the multiple nodes and edges; and
converting the first subgraph and the second subgraph into subgraph nodes.

### Claim 12 (depends on 11)

The computer-readable storage medium according to claim 11, wherein the step of optimizing the first directed graph further comprises:
obtaining an extended API for the target accelerator, wherein the extended API comprises multiple target functions; and
associating the nodes and the target functions having the same functionalities.

### Claim 13 (depends on 12)

The computer-readable storage medium according to claim 12, wherein the step of associating the nodes and the target functions having the same functionalities comprises:
any of splitting a single node that can achieve multiple functions,
merging multiple nodes that can achieve a single function, and
splitting a single node that can achieve multiple functions and merging multiple nodes that can achieve a single function, so to obtain new nodes; and
associating the new nodes and the target functions having the same functionalities.

### Claim 14 (depends on 11)

The computer-readable storage medium according to claim 11, wherein the step of optimizing the first directed graph further comprises:
converting a precision of the accompanying parameters in each node.

### Claim 15 (depends on 10)

The computer-readable storage medium according to claim 10, wherein the step of revising the first directed graph based on a software and hardware information supported by the target accelerator comprises:
obtaining a supported storage format of the target accelerator; and
modifying a data format of the accompanying parameters to the storage format.

### Claim 16 (depends on 10)

The computer-readable storage medium according to claim 10, wherein the step of revising the first directed graph based on a software and hardware information supported by the target accelerator comprises:
obtaining an operation type merging program supported by the target accelerator; and
merging the nodes according to the operation type merging program.

### Claim 17 (depends on 10)

The computer-readable storage medium according to claim 10, wherein the step of generating a compilation result of the target neural network model based on the second directed graph comprises any of:
generating a C language code as the compilation result according to an order of the nodes in the second directed graph,
generating a binary model file as the compilation result based on the order of the nodes in the second directed graph and,
generating both the C language code and the binary model file as the compilation result according to the order of the nodes in the second directed graph.

### Claim 18 (depends on 9)

The compiler of a neural network model according to claim 9, wherein before the step of revising the first directed graph based on a software and hardware information supported by the target accelerator, the method of compiling a neural network model further comprises:
optimizing the first directed graph;
the step of revising the first directed graph based on a software and hardware information supported by the target accelerator comprises:
revising the optimized first directed graph based on the software and hardware information supported by the target accelerator; and
the step of optimizing the first directed graph comprises: obtaining completely identical first subgraph and second subgraph from the first directed graph, wherein both the first subgraph and the second subgraph comprise the multiple nodes and edges; and
converting the first subgraph and the second subgraph into subgraph nodes.

### Claim 19 (depends on 18)

The compiler of a neural network model according to claim 18, wherein the step of optimizing the first directed graph further comprises:
obtaining an extended API for the target accelerator, wherein the extended API comprises multiple target functions; and
associating the nodes and the target functions having the same functionalities.

### Claim 20 (depends on 19)

The compiler of a neural network model according to claim 19, wherein the step of associating the nodes and the target functions having the same functionalities comprises:
any of splitting a single node that can achieve multiple functions,
merging multiple nodes that can achieve a single function, and
splitting a single node that can achieve multiple functions and merging multiple nodes that can achieve a single function, so to obtain new nodes; and
associating the new nodes and the target functions having the same functionalities.
