# US 2023/0409289 A1 · Data processing apparatus and method

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

- Number: US 2023/0409289 A1
- Document ID: US20230409289A1
- Status: Published application
- Kind: A1
- Application number: 18/330,201
- Filed: 2023-06-06
- Published: 2023-12-21
- Earliest claimed: 2020-12-07
- Assignees: Huawei Technologies Co., Ltd.
- Applicants: Huawei Technologies Co., Ltd.
- Inventors: Long Wang; Zongyan Cao; Baicheng Yan; Yibin Wang; Zhe Wang
- Web page: https://patentgrep.com/patent/US20230409289A1

## CPC

- G06F 8/30: Creation or generation of source code
- G06F 8/76: Adapting program code to run in a different environment; Porting
- G06F 8/443: {Optimisation}
- G06F 8/447: {Target code generation}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

A data processing apparatus and method are provided. The method includes: performing multi-level IR decomposition on original application code, extracting more abundant computation and data flow features to obtain an initial computational graph, and performing graph transformation processing on the initial computational graph to obtain a target computational graph, allowing an application corresponding to original application code to run in different systems and implement performance portability.

## Claims

### Claim 1

A data processing apparatus comprising:
a memory storing executable instructions; and
a processor coupled to the memory and configured to execute the executable instructions to:
obtain original application code;
decompose the original application code into a plurality of levels of intermediate representations (IRs), and determine an initial computational graph based on the plurality of levels of IRs;
perform graph transformation processing on the initial computational graph for at least once to obtain a target computational graph;
generate target application code based on the target computational graph; and
output the target application code to a target device.

### Claim 2 (depends on 1)

The apparatus according to claim 1, wherein the processor is further configured to:
perform graph transformation processing on the initial computational graph for at least once, to obtain a graph-transformed computational graph, wherein the graph-transformed computational graph comprises an original parameter; and
perform parameter transformation processing on the original parameter in code corresponding to the graph-transformed computational graph, to obtain the target computational graph.

### Claim 3 (depends on 2)

The apparatus according to claim 2, wherein the processor is further configured to:
perform, based on hardware information of the target device, parameter transformation processing on the original parameter in the code corresponding to the graph-transformed computational graph, to obtain the target computational graph.

### Claim 4 (depends on 1)

The apparatus according to claim 1, wherein a multi-level IR decomposition comprises a first-level IR decomposition, a second-level IR decomposition, and a third-level IR decomposition;
the processor is further configured to:
determine a first IR based on the original application code, wherein the first IR comprises a plurality of operators;
construct a second IR based on the first IR, wherein the second IR comprises a structured pattern corresponding to the plurality of operators; and
determine, based on the second IR, a data-centric (DC) primitive corresponding to the structured pattern, wherein the DC primitive is used to construct the initial computational graph.

### Claim 5 (depends on 4)

The apparatus according to claim 4, wherein the processor is further configured to:
construct the second IR based on the first IR and hardware information of the target device.

### Claim 6 (depends on 1)

The apparatus according to claim 1, wherein the processor is further configured to:
decompose the initial computational graph to obtain a plurality of subgraphs; and
perform graph transformation processing on the plurality of subgraphs based on a preset subgraph transformation library for at least once, to obtain the target computational graph.

### Claim 7 (depends on 6)

The apparatus according to claim 6, wherein the processor is further configured to:
based on the preset subgraph transformation library and a first parameter, perform graph transformation processing on the plurality of subgraphs for at least once, to obtain the target computational graph, wherein the first parameter comprises at least one of the following: a quantity of transformation times, a transformation duration, data movement overheads, and a cache miss rate.

### Claim 8 (depends on 6)

The apparatus according to claim 6, wherein
the processor is further configured to:
obtain subgraph transformation update information; and
update the preset subgraph transformation library based on the subgraph transformation update information.

### Claim 9 (depends on 1)

The apparatus according to claim 1, wherein the original application code comprises at least one of the following: a mathematical equation operator, geometric discrete abstraction, a typical data structure, and a DC primitive.

### Claim 10 (depends on 4)

The apparatus according to claim 4, wherein the operator comprises at least one of the following: mathematical equation-based operator decomposition, geometric discrete abstraction, and a basic data type.

### Claim 11 (depends on 4)

The apparatus according to claim 4, wherein the structured pattern comprises at least one of the following: a Stencil pattern, a Reduce pattern, and a Package pattern.

### Claim 12 (depends on 4)

The apparatus according to claim 4, wherein the initial computational graph comprises at least one of the following: data, data movement, a computation task, and loop mapping.

### Claim 13

A data processing method applied to a data processing apparatus, the method comprising:
obtaining original application code;
decomposing the original application code into a plurality of levels of intermediate representations (IRs, and determining an initial computational graph based on the plurality of levels of IRs;
performing graph transformation processing on the initial computational graph for at least once to obtain a target computational graph;
generating target application code based on the target computational graph; and
outputting the target application code to a target device.

### Claim 14 (depends on 13)

The method according to claim 13, wherein the performing the graph transformation processing on the initial computational graph for at least once to obtain the target computational graph comprises:
performing graph transformation processing on the initial computational graph for at least once, to obtain a graph-transformed computational graph, wherein the graph-transformed computational graph comprises an original parameter; and
performing parameter transformation processing on the original parameter in code corresponding to the graph-transformed computational graph, to obtain the target computational graph.

### Claim 15 (depends on 14)

The method according to claim 14, wherein the performing the parameter transformation processing on the original parameter in code corresponding to the graph-transformed computational graph, to obtain the target computational graph comprises:
performing, based on hardware information of the target device, parameter transformation processing on the original parameter in the code corresponding to the graph-transformed computational graph, to obtain the target computational graph.

### Claim 16 (depends on 13)

The method according to claim 13, wherein the decomposing the original application code into the plurality of levels of IRs comprises:
determining a first IR based on the original application code, wherein the first IR comprises a plurality of operators;
constructing a second IR based on the first IR, wherein the second IR comprises a structured pattern corresponding to the plurality of operators; and
determining, based on the second IR, a data-centric (DC) primitive corresponding to the structured pattern, wherein the DC primitive is used to construct the initial computational graph.

### Claim 17 (depends on 16)

The method according to claim 16, wherein the constructing the second IR based on the first IR comprises:
constructing the second IR based on the first IR and the hardware information of the target device.

### Claim 18 (depends on 13)

The method according to claim 13, wherein the performing the graph transformation processing on the initial computational graph for at least once to obtain the target computational graph comprises:
decomposing the initial computational graph to obtain a plurality of subgraphs; and
performing graph transformation processing on the plurality of subgraphs based on a preset subgraph transformation library for at least once, to obtain the target computational graph.

### Claim 19 (depends on 18)

The method according to claim 18, wherein the performing the graph transformation processing on the plurality of subgraphs based on the preset subgraph transformation library for at least once, to obtain the target computational graph comprises:
based on the preset subgraph transformation library and a first parameter, performing graph transformation processing on the plurality of subgraphs for at least once, to obtain the target computational graph, wherein the first parameter comprises at least one of the following: a quantity of transformation times, a transformation duration, data movement overheads, and a cache miss rate.

### Claim 20 (depends on 18)

The method according to claim 18, further comprising:
obtaining subgraph transformation update information;
updating the preset subgraph transformation library based on the subgraph transformation update information.
