Data processing method and related device

By adapting the target template to different buffer numbers and preload optimization, the template expansion problem caused by multi-buffer technology is solved, efficient data processing deployment and compilation are achieved, and the performance of the processor architecture is improved.

CN120803454APending Publication Date: 2025-10-17HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410430400.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-04-10
Publication Date
2025-10-17

AI Technical Summary

Technical Problem

Traditional processor architectures cannot meet the growing performance demands. Multi-buffer technology leads to template expansion, resulting in excessive deployment storage, which affects client-side deployment efficiency.

Method used

The target template is used to adapt to multi-buffer optimization with different buffer numbers. The compiler assigns the first and second variables to achieve compatibility with different buffer numbers and preload optimization for the same template, reducing storage overhead and compilation time.

Benefits of technology

It reduces storage overhead during deployment, improves client-side deployment efficiency, shortens compilation time, and optimizes data processing pipeline efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120803454A_ABST
    Figure CN120803454A_ABST
Patent Text Reader

Abstract

The invention discloses a data processing method. In the method, in a scene of optimizing a plurality of buffer regions, when a source code is compiled, a compiler can directly assign a first variable in a compilation template (namely a target template in the embodiment of the invention) as a numerical value of the number of buffers needing to be started and optimized, that is, the target template can be a template adaptive to different numbers of buffers, so that the number of the buffers required to be started and optimized is increased, and the number of the buffers required to be started and optimized is increased. After the first variable is assigned, the intermediate representation IR of the source code can be obtained, and the machine code is obtained according to the IR, so that the storage overhead during deployment can be reduced, and the deployment efficiency can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of artificial intelligence (AI), and in particular to a data processing method and related apparatus. BACKGROUND

[0002] With the rapid development of artificial intelligence technology, the traditional processor architecture has been unable to meet the growing performance requirements. The industry accelerates key operators on specific hardware chips based on AI compilation frameworks such as Tvm and Halide, which can realize the construction of high-performance neural network models.

[0003] The multi-buffer technology (also known as n-buffer technology) is widely used to improve the pipeline efficiency of the entire data flow. The multi-buffer technology can reduce the memory access latency of data transfer and calculation, thereby accelerating data execution. The multi-buffer technology needs to expand the original cache size. When optimizing the performance of a single operator, the developer will selectively use n-buffer optimization according to the use case scenario or resource consumption. In this way, optimization for different buffer quantities will derive a series of different templates. Through combination, as shown in Figure 1 , it will cause the problem of template expansion. In the binary release process, each template needs to correspond to a bin file, resulting in a large release package file and large deployment storage, which in turn affects the efficiency of customer-side deployment. SUMMARY

[0004] The present application provides a data processing method and related apparatus, which can reduce the storage overhead during deployment and improve the deployment efficiency.

[0005] The first aspect of the present application provides a data processing method. In the scenario of optimizing a plurality of cache areas buffer, when the source code is compiled, the compiler can directly assign the first variable in the compilation template (that is, the target template in the embodiment of the present application) to the value of the buffer quantity that needs to be optimized. That is, the target template can be a template adapted to different buffer quantities. After assigning the first variable, the intermediate representation (IR) of the source code can be obtained, and the machine code can be obtained according to the IR.

[0006] In the prior art, different buffer quantity multi-buffer optimization corresponds to different templates, which causes excessive storage overhead and reduces deployment efficiency. In the embodiment of the present application, the buffer optimization of different buffer quantities can share the same template. The template (that is, the target template in the embodiment of the present application) can be adapted to multi-buffer optimization of different buffer quantities. Specifically, the template can include a variable (that is, the first variable in the embodiment of the present application) related to the buffer quantity of the enabled multi-buffer optimization. During compilation, for the same template, only the variable in the template needs to be assigned based on the buffer quantity of the enabled multi-buffer optimization, so that the corresponding intermediate representation (IR) can be obtained. Since the buffer optimization of different buffer quantities can share the same template, the storage overhead during deployment can be reduced. During the binary publishing process, a single template only needs to correspond to one bin file. Compared with multiple templates, the single template has a smaller publishing package file, which can improve the efficiency of customer-side deployment. In addition, the multi-template form is time-consuming during compilation, which is not conducive to online compilation of the model. The single template of the embodiment of the present application can reduce the compilation time.

[0007] During compilation, the compiler can compile the source code based on the preset template to obtain machine code. The template can include the execution relationship of the operations in the source code, such as whether they can be parallel, the sequence constraint, and the like. Specifically, the template can include the relationship between the use of each buffer, such as the storage space of each buffer, the sequence constraint, waiting relationship, and whether they can be parallel between different buffers.

[0008] In a possible implementation, the first variable is a variable related to the buffer quantity in the target template.

[0009] In a possible implementation, the target template includes: a first cache space used by a first operation, the first cache space being represented by a start address and an address offset; the first operation is an operation within a loop count in a loop operation, the start address being represented by first information, and the first information being a relationship between the loop count in which the first operation is located and the first variable.

[0010] In a possible implementation, the target template further includes a plurality of candidate start addresses; and the first information is specifically a remainder result of the loop count in which the first operation is located and the first variable, and different candidate start addresses correspond to different remainder results.

[0011] In the embodiment of the present application, the operation is often a loop operation, for example, for Figure 7As shown, when the loop count is 0, 2, 4, 6, 8, etc. even number, the operation uses the cache A0, when the loop count is 1, 3, 5, 7, 9, etc. odd number, the operation uses the cache A1, thus, when the loop count is even number, the starting address of the cache used by the operation is the starting address of A0, when the loop count is odd number, the starting address of the cache used by the operation is the starting address of A1. For another example, when the loop count is 0, 2, 4, 6, 8, etc. even number, the operation uses the cache B0, when the loop count is 1, 3, 5, 7, 9, etc. odd number, the operation uses the cache B1, thus, when the loop count is even number, the starting address of the cache used by the operation is the starting address of B0, when the loop count is odd number, the starting address of the cache used by the operation is the starting address of B1.

[0012] In a possible implementation, the target template comprises: a first execution constraint between the second operation and the third operation; the first execution constraint indicates whether to execute in parallel, the second operation and the third operation belong to operations of different loop counts in a loop operation, and the execution order constraint is represented by a relationship between second information and third information, the second information is a relationship between a loop count where the second operation is located and the first variable, and the third information is a relationship between a loop count where the third operation is located and the first variable.

[0013] In a possible implementation, the second information is specifically a remainder result of the loop count where the second operation is located and a quantity, and the third information is specifically a remainder result of the loop count where the third operation is located and the quantity; when the second information and the third information are the same, the first execution constraint indicates that the second operation and the third operation do not execute in parallel.

[0014] In addition to the multi-buffer optimization, a preload technique (advance loading technique, that is, to perform reading and moving of data of a subsequent loop count in advance) is also applied to improve the pipeline efficiency of the entire data flow, and the proload technique can load the associated data in advance.

[0015] In addition to being compatible with buffer optimization of different buffer quantities, the target template in the embodiment of the present application can also be compatible with enabling or not enabling preload optimization. Similarly to the above, a variable (that is, the second variable in the embodiment of the present application) related to whether to enable the preload optimization can also be set in the target template. Based on the assignment to the variable, the IR obtained based on the template can be IR of enabling the proload optimization or IR of not enabling the proload optimization.

[0016] In a possible implementation, the second indication information can be acquired, and the second indication information is used to indicate whether to start a preload optimization; the target template is further adapted to start or not to start the preload optimization, the target template includes a second variable related to whether to start the preload optimization, and the compiler is further configured to assign the second variable in the target template based on whether to start the preload optimization, to obtain the intermediate representation IR of the source code.

[0017] In the above manner, one template can represent the functions of n buffers and preload at the same time, so that a common template is realized at the operator side, and storage overhead and coding time overhead are further reduced.

[0018] In a possible implementation, when the second indication information indicates that the preload is started, the second variable in the target template is assigned a first preset value, and when the second variable is the first preset value, the IR indicates that the first code and the second code are executed, the first code indicates data required by an operation with a loop count of 0, and the second code indicates data required by an operation with a loop count of j+1, where j is a current loop count.

[0019] In a possible implementation, when the second indication information indicates that the preload is not started, the second variable in the target template is assigned a second preset value, and when the second variable is the second preset value, the IR indicates that the third code is executed, the third code indicates data required by an operation with a loop count of j, where j is a current loop count.

[0020] In a second aspect, the present application provides a data processing apparatus, applied to a scenario of optimizing a plurality of buffers, and the apparatus comprises:

[0021] The obtaining module is configured to obtain a source code and first indication information, and the first indication information is used to indicate a number of buffers to be started for optimization.

[0022] The processing module is configured to assign a first variable in a target template based on the source code and the first indication information by using a compiler to obtain an intermediate representation IR of the source code, and obtain machine code based on the IR.

[0023] In a possible implementation, the target template is a template adapted to different numbers of buffers.

[0024] In a possible implementation, the first variable is a variable in the target template related to the number of buffers.

[0025] In a possible implementation, the target template comprises:

[0026] The first cache space used by the first operation is represented by a start address and an address offset; the first operation is an operation in a loop count in a loop operation; the start address is represented by the first information; and the first information is a relationship between the loop count in which the first operation is located and the first variable.

[0027] In a possible implementation, the target template further includes a plurality of candidate start addresses; and the first information is specifically a remainder result of the loop count in which the first operation is located and the first variable; and different candidate start addresses correspond to different remainder results.

[0028] In a possible implementation, the target template includes:

[0029] A first execution constraint between the second operation and the third operation; the first execution constraint indicates whether the second operation and the third operation are executed in parallel; the second operation and the third operation belong to operations in different loop counts in a loop operation; and the execution order constraint is represented by a relationship between the second information and the third information; the second information is a relationship between the loop count in which the second operation is located and the first variable; and the third information is a relationship between the loop count in which the third operation is located and the first variable.

[0030] In a possible implementation, the second information is specifically a remainder result of the loop count in which the second operation is located and the number;

[0031] The third information is specifically a remainder result of the loop count in which the third operation is located and the number;

[0032] When the second information and the third information are the same, the first execution constraint indicates that the second operation and the third operation are not executed in parallel.

[0033] In a possible implementation, the obtaining module is further configured to:

[0034] Obtain second indication information, the second indication information being used to indicate whether to start a preload optimization; and

[0035] The target template is further adapted to start or not start the preload optimization; the target template includes a second variable related to whether to start the preload optimization; and the compiler is further configured to assign the second variable in the target template based on whether to start the preload optimization, to obtain the intermediate representation IR of the source code.

[0036] In a possible implementation, when the second indication information indicates that the preloading is enabled, the second variable in the target template is assigned a first preset value, and when the second variable is the first preset value, the IR indicates execution of a first code and a second code, the first code indicates data required for an operation with a loop count of 0, and the second code indicates data required for an operation with a loop count of j+1, where j is a current loop count.

[0037] In a possible implementation, when the second indication information indicates that the preloading is not enabled, the second variable in the target template is assigned a second preset value, and when the second variable is the second preset value, the IR indicates execution of a third code, the third code indicates data required for an operation with a loop count of j, where j is a current loop count.

[0038] The third aspect of the present application provides a data processing apparatus, which can include a processor, the processor and a memory are coupled, and the memory stores program instructions, when the program instructions stored in the memory are executed by the processor, the method of the first aspect or any implementation manner of the first aspect is implemented. For the processor to execute the steps in each possible implementation manner of the first aspect, specific details can be referred to the first aspect, which will not be repeated here.

[0039] The fourth aspect of the present application provides a computer readable storage medium, the computer readable storage medium stores a computer program, when the computer program is run on a computer, the computer executes the method of any implementation manner of the first aspect.

[0040] The fifth aspect of the present application provides a circuit system, the circuit system includes a processing circuit, the processing circuit is configured to execute the method of any implementation manner of the first aspect.

[0041] The sixth aspect of the present application provides a computer program product, when the computer program product is run on a computer, the computer executes the method of any implementation manner of the first aspect.

[0042] The seventh aspect of the present application provides a chip system, the chip system includes a processor, and is used for supporting a server or a threshold value obtaining apparatus to implement functions involved in any implementation manner of the first aspect, for example, sending or processing data and / or information involved in the method. In a possible design, the chip system further includes a memory, the memory is used for saving necessary program instructions and data of the server or the communication device. The chip system can be composed of a chip, or can include the chip and other discrete devices.

[0043] The beneficial effects of the second aspect to the seventh aspect can be referred to the introduction of the first aspect, which will not be repeated here. BRIEF DESCRIPTION OF DRAWINGS

[0044] Figure 1 A multi-buffer optimization schematic diagram provided for an embodiment of the present application;

[0045] Figure 2 A system architecture schematic diagram provided for an embodiment of the present application;

[0046] Figure 3 A data processing method flow schematic diagram provided for an embodiment of the present application;

[0047] Figure 4 And Figure 5 A data execution synchronization schematic diagram provided for an embodiment of the present application;

[0048] Figure 6 And Figure 7 A storage space schematic diagram provided for an embodiment of the present application;

[0049] Figure 8 A data processing device structure schematic diagram provided for an embodiment of the present application;

[0050] Figure 9 A structure schematic diagram of an execution device provided for an embodiment of the present application;

[0051] Figure 10 A chip structure schematic diagram provided for an embodiment of the present application;

[0052] Figure 11 A computer readable storage medium structure schematic diagram provided for an embodiment of the present application. DETAILED DESCRIPTION

[0053] In order to make the purpose, technical scheme and advantages of the present application clearer, the embodiments of the present application are described below with reference to the drawings. Obviously, the described embodiments are only a part of the embodiments of the present application, not all the embodiments. Those skilled in the art can know that with the appearance of new application scenarios, the technical scheme provided by the embodiments of the present application is also applicable to similar technical problems.

[0054] The terms "first", "second", and the like in the description and in the claims of the present application and above-described drawings are used to distinguish between similar objects and are not necessarily used to describe a particular sequential or chronological order. It will be understood that the descriptions used herein of the description can be interchanged, where appropriate, to enable the embodiments to be carried out in other than the order illustrated or described herein. Furthermore, the terms "comprise" and "include", and variations thereof, are intended to cover non-exclusive inclusions, such that processes, methods, systems, products, or devices that comprise, include, or are otherwise including a list of steps or modules are not necessarily limited to those steps or modules that are explicitly listed, but can include additional steps or modules not expressly listed or inherent to such processes, methods, products, or devices. The naming or numbering of steps appearing in the present application does not mean that the steps in the method flow must be executed in the time / logical order indicated by the naming or numbering, and the named or numbered steps in the flow can be executed in a different order according to the technical purpose to be achieved, as long as the same or similar technical effects can be achieved. The division of units appearing in the present application is a logical division, and in actual application, there can be another division manner, for example, multiple units can be combined or integrated into another system, or some features can be ignored or not executed, in addition, the coupling or direct coupling or communication connection between the units shown or discussed can be through some interface, the indirect coupling or communication connection between the units can be electrical or other similar forms, which are not limited in the present application. In addition, the units or sub-units described as separate components can or can not be physically separated, can or can not be physical units, or can be distributed in multiple circuit units, and part or all of the units can be selected according to actual needs to achieve the purpose of the present application.

[0055] With the rapid development of artificial intelligence technology, the traditional processor architecture has been unable to meet the growing performance demand. The industry accelerates key operators on specific hardware chips based on AI compilation frameworks such as Tvm and Halide, which can realize the construction of high-performance neural network models.

[0056] The multi-buffer technology (also known as n-buffer technology) is widely used to improve the pipeline efficiency of the entire data stream. The multi-buffer technology can reduce the memory access latency of data transfer and calculation, thereby accelerating data execution. The multi-buffer technology needs to expand the original cache size. When optimizing the performance of a single operator, the developer will selectively use n-buffer optimization according to the use case scenario or resource consumption. In this way, different templates will be derived for optimization of different buffer quantities. Through combination, such as Figure 1As shown, the template expansion problem will occur. In the binary release process, each template needs to correspond to a bin file, resulting in a large release package file and a large deployment storage, which further affects the efficiency of the customer side deployment.

[0057] The system architecture and application scenarios of the embodiments of the present application will be introduced below. Please refer to Figure 2 , Figure 2 is a schematic diagram of a system architecture 300 in the embodiments of the present application.

[0058] As shown in Figure 2 , the compiling device 320 compiles the source program 350 to obtain the program compilation result 301. The source program 350 is the program (first program or second program) in the embodiments of the present application, which can be a program for multi-dimensional data operation in different scenarios, including image processing, speech recognition, scientific computing, or physical modeling, etc. The compiling device 320 can be any device containing a compiler (such as GCC or LLVM compiler, etc.).

[0059] The compiling process of the compiling device 320 on the source program 350 will be described in detail below based on the embodiment shown in Figure 2 .

[0060] The program compilation result 301 obtained by using the compiling device 320 can be applied to different systems or devices, such as the execution device 310 shown in Figure 2 , which can be a terminal such as a mobile terminal, a tablet computer, a notebook computer, an augmented reality (AR) / virtual reality (VR), a vehicle-mounted terminal, etc., and can also be a server or a cloud, etc. Figure 2 In the embodiment, the execution device 310 is configured with an input / output (I / O) interface 312 for data interaction with external devices.

[0061] The execution device 310 can receive data in the database 330 or input by the client device 340, and use the computing module 311 to execute the related computing process in the program compilation result 301 to obtain the corresponding processing result.

[0062] Finally, the I / O interface 312 returns the processing result (for example, image processing result or speech recognition result, etc.) to the client device 340 to provide to the user.

[0063] It is worth noting that the compiling device 320 can compile source programs for different purposes or different tasks to obtain corresponding program compilation results 301, and then the execution device 310 is used to execute the related computing processes in the program compilation results 301 to obtain the processing results required for different purposes or different tasks.

[0064] In the case shown in Figure 2 , the user can manually give the input data, which can be operated through the interface provided by the I / O interface 312. In another case, the client device 340 can automatically send the input data to the I / O interface 312, and if the user's authorization is required to automatically send the input data to the client device 340, the user can set the corresponding permission in the client device 340. The user can view the results output by the execution device 310 in the client device 340, and the specific presentation form can be a specific way such as display, sound, action, etc.

[0065] It is worth noting that, Figure 2 The system architecture provided by the embodiment of the present application is only a schematic diagram, and the positional relationship between the devices, devices, modules and the like shown in the figure does not constitute any limitation. For example, in Figure 2 , the compiling device 320 is an external device relative to the execution device 310, and in other cases, the compiling device 320 can be placed in the execution device 310. The execution device 310 is an external device relative to the client device 340, and in other cases, the execution device 310 and the client device 340 can be the same device.

[0066] It should be understood that the compiling method in the embodiment of the present application can be applied to scenarios that require multi-dimensional data operation in the fields of artificial intelligence (such as image processing or speech recognition, etc.), scientific computing, physical modeling, etc. First, the image data to be processed is obtained, and the image data to be processed is defined in a high-level language (such as C, C++ or Python programming language, etc.) to obtain a multi-dimensional data program representation 420 (i.e. the source program in Figure 2 ).

[0067] The compiling method in the embodiment of the present application is executed by the compiling device 320 to obtain a program compilation result (i.e. the program compilation result 301 in Figure 2 ). The program compilation result is optimized and instruction mapping, etc. to obtain a hardware machine language executable on hardware (such as CPU or GPU, etc.).

[0068] The hardware machine language is run by the execution device 310 to perform corresponding multi-dimensional data operation to obtain an image processing result.

[0069] It should be understood that in Figure 3In the embodiment, the compiling device 320 is an external device relative to the executing device 310. In other cases, the compiling device 320 can also be placed in the executing device 310.

[0070] The above describes the system architecture used by the method provided in this embodiment. The following will describe in detail the specific execution process of the method provided in this embodiment in conjunction with the accompanying drawings.

[0071] See also Figure 3 , Figure 3 This is a flow chart of a data processing method provided in an embodiment of the present application. Figure 1 As shown, the data processing method includes the following steps 301-302.

[0072] Step 301: Obtain source code and first indication information, where the first indication information is used to indicate the number of buffers to enable optimization.

[0073] In an embodiment of the present application, the source code to be compiled can be obtained, wherein the source code can be a code written using an application editing interface of a high-level editing language. Exemplarily, the high-level programming language can be a domain specific language (DSL), and the DSL language can be: Halide, GraphIt, Spatial, or other customized domain specific languages. Among them, Halide is suitable for vector and tensor operations, GraphIt is suitable for the field of graph computing, Spatial is suitable for the field of programmable hardware, and customized domain specific languages ​​are suitable for corresponding customized fields.

[0074] Reference Figure 6 , buffers of different colors (represented as shared_mem in the figure) represent the caches needed for different operations. For example, shared_memA is the cache used when reading and moving data that needs to be operated on, shared_memB is the cache used when performing operations on the read data, and shared_memC is the cache used when moving the results of the operations. When double buffer optimization is not enabled, shared_memA, shared_memB, and shared_memC need to be used in sequence to perform data reading and moving, operations, and result moving in sequence. When double buffer optimization is enabled and shared_memA, shared_memB, and shared_memC are split, shared_memA includes two parts. When using the second part of shared_memA for reading and moving, shared_memB can be used in parallel for data operations, and so on, thereby accelerating the overall operation process.

[0075] When compiling the source code, whether to enable the multi-buffer optimization and the number of buffers of the enabled multi-buffer optimization can be selected. When compiling, the compiler can compile the source code based on a preset template to obtain machine code, and the template can include execution relationships of operations in the source code, such as whether to be parallel, a sequence constraint, and the like. Specifically, in the template, a relationship between the buffers can be included, such as a storage space of each buffer, a sequence constraint, a waiting relationship, and whether to be parallel between different buffers. In the prior art, different multi-buffer optimizations of different numbers of buffers correspond to different templates, which can cause excessive storage overhead and reduce deployment efficiency. In the embodiment of the present application, the buffer optimization of different numbers of buffers can share the same template, and the template (that is, the target template in the embodiment of the present application) can be adapted to multi-buffer optimization of different numbers of buffers. Specifically, the template can include a variable (that is, the first variable in the embodiment of the present application) related to the number of buffers of the enabled multi-buffer optimization. When compiling, for the same template, only the variable in the template needs to be assigned based on the number of buffers of the enabled multi-buffer optimization, so that the corresponding intermediate representation (IR) can be obtained. Since the buffer optimization of different numbers of buffers can share the same template, the storage overhead during deployment can be reduced. In the binary release process, a single template only needs to correspond to a bin file. Compared with multiple templates, the single template has a smaller release package file, which can improve the efficiency of customer-side deployment. In addition, the multi-template form consumes a lot of time during compilation, which is not conducive to online compilation of the model. The single template in the embodiment of the present application can reduce the compilation time.

[0076] It should be understood that the number of buffers of the enabled multi-buffer optimization in the embodiment of the present application can be the split number of the cache used for each operation. For example, the split number for shared_memA can be 2, the split number for shared_memB can be 1 (that is, not split), and the split number for shared_memC can be 2.

[0077] In a possible implementation, the number of buffers of the enabled multi-buffer optimization indicated in the first indication information can be specified by a user (or a provider of the source code, which can be a user or a device) or determined by the compilation system itself, for example, based on the current running environment. The embodiment of the present application does not limit this.

[0078] At step 302, the first variable in the target template is assigned a value by the compiler according to the source code and the first indication information to obtain an intermediate representation (IR) of the source code, and machine code is obtained according to the IR.

[0079] In a possible implementation, the source code can be compiled by a compiler calling a target template according to the source code and the first indication information to obtain machine code. The target template is a template for multi-buffer optimization adapted to different buffer numbers, and the target template includes a first variable related to the buffer number of the multi-buffer optimization. The compiler is configured to assign a value to the first variable in the target template based on the buffer number, to obtain an intermediate representation (IR) of the source code, and to obtain machine code according to the IR.

[0080] Next, the first variable and how the template adapts to multi-buffer optimization of different buffer numbers through the first variable are introduced.

[0081] In multi-buffer optimization of different buffer numbers, the buffer space allocated to each operation can be different. For example, refer to Figure 6 , Figure 7 In the case of FIG. 6, multi-buffer optimization is not enabled, and the starting address of the buffer B is the starting address of the buffer A plus the address offset of the buffer A, refer to Figure 7 , Figure 7 In the case of FIG. 7, double buffer optimization is enabled, and the starting address of the buffer A1 is the starting address of the buffer A0 plus the address offset of the buffer A0, and the starting address of the buffer B is the starting address of the buffer A1 plus the address offset of the buffer A1.

[0082] Therefore, the starting address of each buffer can be specified in the template, and the starting address of the buffer is related to the buffer number. For example, the allocation of the storage space of different buffers on the shared memory is essentially affected by each other. For example, whether the buffer A is enabled for double buffer determines the starting address of the buffer B, as shown in FIG. 8. Therefore, when the actual operator compute does not perceive the value of n of the nbuffer, the memory size also needs to be dynamically allocated. Random n buffers: Figure 7

[0083] shared_mem A=ALL_LOOP%N==0?A[0]:(ALL_LOOP%N==1?A[1]:...);

[0084] ​shared_mem B=A+(ALL_LOOP%N==0?B[0]:(ALL_LOOP%N==1?B[1]:...));

[0085] Taking the first operation as an example, in a possible implementation, the target template includes: a first cache space used by the first operation, the first cache space is represented by a starting address and an address offset; the first operation is an operation within a loop count in a loop operation, the starting address is represented by first information, and the first information is the relationship between the loop count in which the first operation is located and the first variable.

[0086] In a possible implementation, the target template further includes multiple candidate start addresses; the first information is specifically a modulo result of a loop count of the first operation and the first variable, and different candidate start addresses correspond to different modulo results.

[0087] Among them, the operation is often a loop operation, for example, Figure 7 As shown, when the loop count is an even number such as 0, 2, 4, 6, 8, the cache used by the operation is A0, and when the loop count is an odd number such as 1, 3, 5, 7, 9, the cache used by the operation is A1. Therefore, when the loop count is an even number, the starting address of the cache used by the operation is the starting address of A0, and when the loop count is an odd number, the starting address of the cache used by the operation is the starting address of A1. For another example, for Figure 4 As shown, when the loop count is an even number such as 0, 2, 4, 6, 8, the cache used by the operation is B0, and when the loop count is an odd number such as 1, 3, 5, 7, 9, the cache used by the operation is B1. Therefore, when the loop count is an even number, the starting address of the cache used by the operation is the starting address of B0, and when the loop count is an odd number, the starting address of the cache used by the operation is the starting address of B1.

[0088] For example, the target template may be:

[0089] #nbuffer

[0090] for jm

[0091] wait(comsumer_pipe,mode=j%N)

[0092] producer_instr(shared_mem A[j%N]+address offset)

[0093] set(producer_pipe,mode=j%N)

[0094] wait(producer_pipe,mode=j%N)

[0095] comsumer_instr(shared_mem A[j % N] + offset)

[0096] set(comsumer_pipe, mode = j % N)

[0097] Wherein, the producer can be a process of data reading and carrying operation, the address used by the operation is shared_mem A[j % N] + offset, % represents the remainder, j is the current loop count, N is the number of buffers opened for multi-buffer optimization, when j is even, the cache start address used by the operation is shared_mem A[0], when j is odd, the cache start address used by the operation is shared_mem A[1].

[0098] In a possible implementation, the target template comprises: a first execution constraint between a second operation and a third operation; the first execution constraint indicates whether to execute in parallel, the second operation and the third operation belong to operations of different loop counts in a loop operation, and the execution order constraint is represented by a relationship between second information and third information, the second information is a relationship between a loop count where the second operation is located and a first variable, and the third information is a relationship between a loop count where the third operation is located and the first variable.

[0099] In a possible implementation, the second information is specifically a remainder result of a number and a loop count where the second operation is located; the third information is specifically a remainder result of the number and a loop count where the third operation is located; and when the second information and the third information are the same, the first execution constraint indicates that the second operation and the third operation are not executed in parallel.

[0100] The multi-buffer optimization can accelerate the data processing process mainly because some operations are executed in parallel. The concept of inter-instruction synchronization and "lock" of the operations is similar, controls the execution logic between data, and determines the actual data flow arrangement. For example, Figure 5 and Figure 4 As shown, Figure 5 is the execution order of single buffer data, sch[A_ub].nbuffer(1) is the execution order of double buffer data. The mode represents a synchronization mode, and the synchronization instructions of set and wait are matched and associated through the mode value. Here, in order to better enable nbuffer to be parallel, it is necessary to dynamically allocate and generate a synchronization mode:

[0101] mode = (ALL_LOOP % N)

[0102] Wherein, the synchronization mode of single buffer is mode=0, and the synchronization mode of double buffer is mode=loop_count%2, wherein loop_count represents the current loop count.

[0103] For example, the target template can be:

[0104] #nbuffer

[0105] for j m

[0106] wait(comsumer_pipe,mode=j%N)

[0107] producer_instr(shared_mem A[j%N]+offset)

[0108] set(producer_pipe,mode=j%N)

[0109] wait(producer_pipe,mode=j%N)

[0110] comsumer_instr(shared_mem A[j%N]+address offset)

[0111] set(comsumer_pipe,mode=j%N)

[0112] Wherein, the order of the codes represents the order of execution, and the wait indicates that the same mode of set before needs to be executed before the code can be executed, and the code does not need to wait for the execution of the set of different mode before to be executed, that is, the code can be executed in parallel.

[0113] In addition to the multi-buffer optimization, the preload technology (advance loading technology, that is, the advance execution of the reading and moving of the data of the subsequent loop count) is also applied to improve the flow efficiency of the entire data flow, and the proload technology can advance the loading of the associated data.

[0114] In addition to being compatible with buffer optimization of different buffer numbers, the target template in the embodiments of the present application can also be compatible with the preload optimization being enabled or not. Similar to the above, a variable (that is, the second variable in the embodiments of the present application) related to whether the preload optimization is enabled or not can also be set in the target template. Based on the assignment of the variable, the IR obtained based on the template can be the IR of the proload optimization being enabled or not.

[0115] In one possible implementation, second indication information can be obtained, and the second indication information is used to indicate whether to enable preload optimization; wherein, the target template is also adapted to enable or not enable preload optimization, and the target template includes a second variable related to whether to enable preload optimization, and the compiler is further used to assign a value to the second variable in the target template based on whether to enable preload optimization, to obtain an intermediate representation IR of the source code.

[0116] Through the above method, a template can be used to represent both nbuffer and preload, thereby implementing a common template on the operator side, further reducing storage overhead and encoding time overhead.

[0117] In one possible implementation, when the second indication information indicates to turn on preload, the second variable in the target template is assigned a first preset value, and when the second variable is the first preset value, the IR indicates to execute the first code and the second code, the first code indicates to load the data required for the operation with a loop count of 0, and the second code indicates to preload the data required for the operation with a loop count of j+1, where j is the current loop count.

[0118] In one possible implementation, when the second indication information indicates that preload is not enabled, the second variable in the target template is assigned a second preset value, and when the second variable is the second preset value, the IR indicates the execution of a third code, and the third code indicates the loading of data required for an operation with a loop count of j, where j is the current loop count.

[0119] Among them, when preload optimization is turned on, the data reading and moving operation with a loop count of 0 can be executed first, and then the data reading and moving operation with a loop count of 1 can be executed. That is, the data calculation operation with a loop count of 0 is not executed, but the data loading of the next loop count is performed in advance (when it is not turned on, the data calculation operation with a loop count of 0 is executed here).

[0120] For example, the target template may be:

[0121]

[0122]

[0123] Wherein, when the preload optimization is turned on, the data carrying operation with the loop count of 0 is performed first, and when the loop count is not the last one (j

[0124] For example, the target template can be:

[0125]

[0126]

[0127] Next, the data processing method of the embodiment of the application will be introduced in combination with several specific examples.

[0128] For example, the current input specification has image matrices of 10*10, 100*100 and 1000*1000, the small matrix 10*10 can be satisfied by using hardware resources, and the single_buffer performance can achieve the best. The image matrix of 100*100 needs double_buffer performance to achieve the best. The data amount of the image matrix of 1000*1000 is larger, and the preload optimization is needed to obtain the best performance. Therefore, for the above scenarios, the operator front-end Compute is expressed as follows:

[0129] (I) 10*10 specification single_buffer:

[0130] sch[A_ub].nbuffer(2)

[0131] The generated IR is as follows:

[0132]

[0133] (II) 100*100 specification double_buffer:

[0134] Figure 8

[0135] The generated IR is as follows:

[0136]

[0137] (III) 1000*1000 specification double_buffer and preload:

[0138]

[0139] The generated IR is as follows:

[0140]

[0141] Due to different scenes, multiple templates may appear in the pursuit of extreme performance.

[0142] The application utilizes dynamic synchronization and memory code generation to realize the function of representing single, double, etc. nbuffer and preload at the same time, and to realize common templates at the operator side.

[0143] The operator front end Compute is as follows:

[0144]

[0145] The finally generated IR is as follows:

[0146]

[0147] The above describes the method provided by the embodiments of the application in detail, and next, the device provided by the embodiments of the application for executing the above method will be introduced.

[0148] Please refer to Figure 8 , Figure 8 The structural schematic diagram of a data processing apparatus provided by the embodiments of the application is shown in FIG. 1. Figure 9 As shown in the figure, the data processing apparatus comprises: an acquisition module 1001 configured to acquire source code and first indication information, the first indication information being used to indicate the number of buffers opened for optimization;

[0149] a processing module 1002 configured to assign values to first variables in a target template through a compiler to obtain an intermediate representation (IR) of the source code according to the source code and the first indication information, and to obtain machine code according to the IR.

[0150] In a possible implementation, the target template is a template adapted to different buffer numbers.

[0151] In a possible implementation, the first variable is a variable in the target template related to the buffer number.

[0152] In a possible implementation, the target template comprises:

[0153] The first cache space used by the first operation, the first cache space being represented by a start address and an address offset; the first operation being an operation within a loop count in a loop operation, the start address being represented by first information, and the first information being a relationship between the loop count in which the first operation is located and the first variable.

[0154] In a possible implementation, the target template further includes a plurality of candidate start addresses; the first information is specifically a remainder result of a loop count where the first operation is located and the first variable, and different candidate start addresses correspond to different remainder results.

[0155] In a possible implementation, the target template includes:

[0156] a first execution constraint between the second operation and the third operation; the first execution constraint indicates whether the second operation and the third operation are executed in parallel, the second operation and the third operation belong to operations of different loop counts in a loop operation, and the execution order constraint is represented by a relationship between second information and third information, the second information is a relationship between a loop count where the second operation is located and the first variable, and the third information is a relationship between a loop count where the third operation is located and the first variable.

[0157] In a possible implementation, the second information is specifically a remainder result of a loop count where the second operation is located and the number;

[0158] the third information is specifically a remainder result of a loop count where the third operation is located and the number;

[0159] When the second information and the third information are the same, the first execution constraint indicates that the second operation and the third operation are not executed in parallel.

[0160] In a possible implementation, the obtaining module 1001 is further configured to:

[0161] obtain second indication information, the second indication information being used to indicate whether to start a preload optimization; and

[0162] The target template is further adapted to start or not to start the preload optimization, the target template includes a second variable related to whether to start the preload optimization, and the compiler is further configured to assign the second variable in the target template based on whether to start the preload optimization, to obtain the intermediate representation IR of the source code.

[0163] In a possible implementation, when the second indication information indicates to start the preload, the second variable in the target template is assigned a first preset value, and when the second variable is the first preset value, the IR indicates to execute a first code and a second code, the first code indicates to load data required by an operation with a loop count of 0, and the second code indicates to preload data required by an operation with a loop count of j+1, j being a current loop count.

[0164] In a possible implementation, when the second indication information indicates that the preloading is not started, the second variable in the target template is assigned a second preset value, and when the second variable is the second preset value, the IR instructs to execute third code, and the third code indicates data required by an operation with a loop count of j, where j is a current loop count.

[0165] Please refer to Figure 9 , Figure 9 A structural diagram of an execution device provided by an embodiment of the present application is shown in FIG. 1. The execution device 1100 can be a server, a personal computer, a smart phone, or the like, and is not limited herein. Specifically, the execution device 1100 includes a receiver 1101, a transmitter 1102, a processor 1103, and a memory 1104 (wherein the number of processors 1103 in the execution device 1100 can be one or more, and one processor is taken as an example in the present embodiment), wherein the processor 1103 can include an application processor 11031 and a communication processor 11032. In some embodiments of the present application, the receiver 1101, the transmitter 1102, the processor 1103, and the memory 1104 can be connected through a bus or other means. Figure 10

[0166] The memory 1104 can include a read-only memory and a random access memory, and provide the processor 1103 with instructions and data. A part of the memory 1104 can also include a non-volatile random access memory (NVRAM). The memory 1104 stores processor and operation instructions, executable modules or data structures, or subsets thereof, or expanded sets thereof, wherein the operation instructions can include various operation instructions for implementing various operations.

[0167] The processor 1103 controls the operation of the execution device. In a specific application, various components of the execution device are coupled together through a bus system, wherein the bus system can include a data bus, a power supply bus, a control bus, and a state signal bus, etc. in addition to the data bus. However, for the sake of clarity, all kinds of buses are referred to as a bus system in the figure.

[0168] ​The method disclosed in the embodiments of the present application can be applied to the processor 1103 or implemented by the processor 1103. The processor 1103 can be an integrated circuit chip having a signal processing capability. In the implementation process, the steps of the above method can be completed by hardware integrated logic circuits in the processor 1103 or by instructions in the form of software. The processor 1103 described above can be a general processor, a digital signal processor (DSP), a microprocessor or a microcontroller, and can further include an application specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component.

[0169] The processor 1103 can implement or execute the methods, steps and logic block diagrams disclosed in the embodiments of the present application. The general processor can be a microprocessor or the processor can also be any conventional processor or the like. The steps of the method disclosed in combination with the embodiments of the present application can be directly embodied as a hardware code processor for execution, or a combination of hardware and software modules in the code processor for execution. The software module can be located in a random memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register or the like mature storage medium in the art. The storage medium is located in the memory 1104, and the processor 1103 reads the information in the memory 1104 and combines the hardware to complete the steps of the above method.

[0170] The receiver 1101 can be used to receive input digital or character information, and to generate signal input related to the relevant settings and function control of the execution device. The transmitter 1102 can be used to output digital or character information through the first interface; the transmitter 1102 can also be used to send instructions to the disk group through the first interface to modify the data in the disk group; the transmitter 1102 can also include a display device such as a display screen.

[0171] The electronic device provided in the embodiments of the present application can be a chip, which includes a processing unit, for example, a processor, and a communication unit, for example, an input / output interface, a pin, or a circuit, etc. The processing unit can execute computer execution instructions stored in a storage unit, so as to enable the chip in the execution device to execute the model structure determination method described in the above embodiments, or so as to enable the chip in the training device to execute the model structure determination method described in the above embodiments. Alternatively, the storage unit is a storage unit in the chip, such as a register, a cache, etc., and the storage unit can also be a storage unit outside the chip in the wireless access device, such as a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, a random access memory (RAM), etc.

[0172] Specifically, refer to Figure 10 , Figure 11 A structural schematic diagram of the chip provided in the embodiments of the present application is shown in FIG. 12. The chip can be a neural network processor NPU 1200, which is mounted on a host CPU (Host CPU) as a coprocessor and is assigned tasks by the Host CPU. The core part of the NPU is an operation circuit 1203, which extracts matrix data in a memory and performs multiplication operation under the control of a controller 1204.

[0173] In some implementations, the operation circuit 1203 internally includes a plurality of processing units (PEs). In some implementations, the operation circuit 1203 is a two-dimensional systolic array. The operation circuit 1203 can also be a one-dimensional systolic array or other electronic circuits capable of performing mathematical operations such as multiplication and addition. In some implementations, the operation circuit 1203 is a general matrix processor.

[0174] For example, it is assumed that there are an input matrix A, a weight matrix B, and an output matrix C. The operation circuit takes corresponding data of the matrix B from the weight memory 1202 and buffers the data on each PE in the operation circuit. The operation circuit takes the matrix A data from the input memory 1201 and performs matrix operation with the matrix B, and the partial result or final result of the obtained matrix is saved in an accumulator 1208.

[0175] The unified memory 1206 is used to store input data and output data. The weight data is transferred to the weight memory 1202 through a direct memory access controller (DMAC) 1205. The input data is also transferred to the unified memory 1206 through the DMAC.

[0176] BIU for Bus Interface Unit, i.e., Bus Interface Unit 1210, is used for the interaction between AXI bus and DMAC and instruction fetch buffer (IFB) 1209.

[0177] Bus Interface Unit 1210 (BIU) is used for instruction fetch buffer 1209 to fetch instructions from external memory, and also used for input matrix A or original data of weight matrix B fetched from external memory by memory access controller 1205.

[0178] DMAC is mainly used to transfer input data in external memory DDR to unified memory 1206, or to transfer weight data to weight memory 1202, or to transfer input data to input memory 1201.

[0179] Vector calculation unit 1207 includes a plurality of operation processing units, which further process the output of operation circuit 1203 as needed, such as vector multiplication, vector addition, exponential operation, logarithmic operation, size comparison, etc. It is mainly used for non-convolutional / full connection layer network calculation in neural network, such as batch normalization (Batch Normalization), pixel-level summation, upsampling of feature plane, etc.

[0180] In some implementations, vector calculation unit 1207 can store the processed output vector to unified memory 1206. For example, vector calculation unit 1207 can apply a linear function; or, a nonlinear function to the output of operation circuit 1203, such as linear interpolation on the feature plane extracted by the convolutional layer, and further, for example, a vector of accumulated values to generate activation values. In some implementations, vector calculation unit 1207 generates normalized values, pixel-level summation values, or both. In some implementations, the processed output vector can be used as activation input to operation circuit 1203, for example, for use in subsequent layers in the neural network.

[0181] Controller 1204 is connected to instruction fetch buffer 1209, which is used to store instructions used by controller 1204.

[0182] Unified memory 1206, input memory 1201, weight memory 1202, and instruction fetch buffer 1209 are all on-chip memories. The external memory is private to the NPU hardware architecture.

[0183] The processor mentioned in any of the above can be a general central processing unit, a microprocessor, an ASIC, or one or more integrated circuits for controlling the execution of the above programs.

[0184] Reference can be made to Figure 11 , Figure 3 A structural schematic diagram of a computer readable storage medium provided by an embodiment of the present application is provided. The present application also provides a computer readable storage medium, in some embodiments, the above Figure 11 The disclosed method can be implemented as computer program instructions encoded on a computer readable storage medium in a machine-readable format, or on other non-transitory media or articles of manufacture.

[0185] Figure 3 A conceptual partial view of an example computer readable storage medium arranged in accordance with at least some embodiments presented herein is schematically depicted, the example computer readable storage medium including a computer program for executing a computer process on a computing device.

[0186] In one embodiment, the computer readable storage medium 1300 is provided using a signal bearing medium 1301. The signal bearing medium 1301 can include one or more program instructions 1302, which when executed by one or more processors can provide the functionality or some of the functionality described above with respect to ​ the above described functionality or partial functionality.

[0187] In some examples, the signal bearing medium 1301 can comprise a computer readable medium 1303, such as, but not limited to, a hard disk drive, a compact disk (CD), a digital video disk (DVD), a digital tape, memory, ROM, RAM, etc.

[0188] In some implementations, the signal bearing medium 1301 can comprise a computer recordable medium 1304, such as, but not limited to, memory, a read / write (R / W) CD, a R / W DVD, etc. In some implementations, the signal bearing medium 1301 can comprise a communication medium 1305, such as, but not limited to, a digital and / or an analog communication medium (e.g., a fiber optic cable, a waveguide, a wired communication link, a wireless communication link, etc.). Thus, for example, the signal bearing medium 1301 can be conveyed by a wireless form of the communication medium 1305 (e.g., a wireless communication medium complying with the IEEE 802.11 standard or other transmission protocol).

[0189] The one or more program instructions 1302 can be, for example, computer-executable instructions or logic-implementing instructions. In some examples, a computing device of a computing device can be configured to provide various operations, functions, or actions in response to program instructions 1302 being communicated to the computing device through one or more of computer-readable medium 1303, computer-recordable medium 1304, and / or communication medium 1305.

[0190] It should be noted that the apparatus embodiments described above are merely exemplary, and units described as separate components can or can not be physically separate, and components shown as units can or can not be physical units, i.e., can be located in one place, or can be distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the embodiment. In addition, the connection relationship between the modules in the apparatus embodiments provided in the present application indicates that there is a communication connection between them, which can be implemented as one or more communication buses or signal lines.

[0191] From the above description of the embodiments, those skilled in the art can clearly understand that the present application can be implemented by means of software and necessary general hardware, and of course can also be implemented by special hardware including special integrated circuits, special CPUs, special memories, special components, etc. Generally, functions completed by computer programs can be easily implemented by corresponding hardware, and specific hardware structures for implementing the same function can also be various, such as analog circuits, digital circuits or special circuits. However, for the present application, software program implementation is a better embodiment. Based on this understanding, the technical solutions of the present application can be embodied in the form of a software product, which is stored in a readable storage medium, such as a computer's floppy disk, U disk, mobile hard disk, ROM, RAM, magnetic disk or optical disk, etc., including a plurality of instructions for causing a computer device (which can be a personal computer, a training device, or a network device, etc.) to execute the methods of various embodiments of the present application.

[0192] In the above embodiments, all or part can be implemented by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in the form of a computer program product in whole or in part.

[0193] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on the computer, the processes or functions according to the embodiments of the present application are generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions can be transmitted from one website site, computer, training device or data center to another website site, computer, training device or data center through wired (for example, coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (for example, infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that the computer can store or be integrated into a training device, data center, etc. data storage device including one or more available media sets. The available media can be a magnetic medium (for example, a floppy disk, a hard disk, a magnetic tape), an optical medium (for example, a DVD), or a semiconductor medium (for example, a solid state disk (SSD)), etc.

Claims

1. A data processing method, applied to a scenario of optimizing multiple buffers, is characterized in that: The method comprises: Obtain source code and first indication information, where the first indication information is used to indicate the number of buffers to enable optimization; According to the source code and the first indication information, a compiler assigns a value to a first variable in a target template to obtain an intermediate representation IR of the source code, and obtains a machine code according to the IR.

2. The method according to claim 1, characterized in that The target template is a template adapted to different buffer quantities.

3. The method according to claim 1 or 2, characterized in that The first variable is a variable in the target template that is related to the buffer quantity.

4. The method according to claim 1, wherein The method is applied to a scenario where multiple buffers are optimized.

5. The method according to any one of claims 1 to 4, characterized in that: The target template includes: A first cache space used by a first operation, the first cache space being represented by a starting address and an address offset; the first operation being an operation within a loop count in a loop operation, the starting address being represented by first information, and the first information being a relationship between the loop count in which the first operation is located and the first variable.

6. The method according to claim 5, characterized in that The target template further includes a plurality of candidate starting addresses; the first information is specifically a modulo result of a loop count where the first operation is located and the first variable, and different candidate starting addresses correspond to different modulo results.

7. The method according to any one of claims 1 to 6, characterized in that: The target template includes: A first execution constraint between a second operation and a third operation; the first execution constraint indicates whether to execute in parallel, the second operation and the third operation belong to operations with different loop counts in a loop operation, and the execution order constraint is represented by a relationship between second information and third information, the second information being a relationship between the loop count where the second operation is located and the first variable, and the third information being a relationship between the loop count where the third operation is located and the first variable.

8. The method according to claim 7, characterized in that The second information is specifically a modulo result of a loop count of the second operation and the quantity; The third information is specifically a modulo result of the loop count of the third operation and the quantity; When the second information and the third information are the same, the first execution constraint indicates that the second operation and the third operation are not executed in parallel.

9. The method according to any one of claims 1 to 8, characterized in that: The method further comprises: Obtain second indication information, where the second indication information is used to indicate whether to enable preload optimization; wherein, The target template is also adapted to enable or disable preload optimization, and the target template includes a second variable related to whether preload optimization is enabled. The compiler is also used to assign a value to the second variable in the target template based on whether preload optimization is enabled to obtain an intermediate representation IR of the source code.

10. The method according to claim 9, characterized in that When the second indication information indicates to turn on preload, the second variable in the target template is assigned a first preset value, and when the second variable is the first preset value, the IR indicates the execution of a first code and a second code, wherein the first code indicates loading data required for an operation with a loop count of 0, and the second code indicates preloading data required for an operation with a loop count of j+1, where j is the current loop count.

11. The method according to claim 10, characterized in that When the second indication information indicates that preload is not enabled, the second variable in the target template is assigned a second preset value, and when the second variable is the second preset value, the IR indicates the execution of a third code, and the third code indicates the loading of data required for an operation with a loop count of j, where j is the current loop count.

12. A data processing device, used in a scenario of optimizing multiple buffers, characterized in that: The device comprises: An acquisition module, configured to acquire source code and first indication information, wherein the first indication information is used to indicate the number of buffers for which optimization is enabled; A processing module is configured to assign a value to a first variable in a target template through a compiler according to the source code and the first indication information to obtain an intermediate representation IR of the source code, and obtain a machine code according to the IR.

13. The device according to claim 12, characterized in that The target template is a template adapted to different buffer quantities.

14. The device according to claim 12 or 13, characterized in that The first variable is a variable in the target template that is related to the buffer quantity.

15. The device according to any one of claims 12 to 14, characterized in that The target template includes: A first cache space used by a first operation, the first cache space being represented by a starting address and an address offset; the first operation being an operation within a loop count in a loop operation, the starting address being represented by first information, and the first information being a relationship between the loop count in which the first operation is located and the first variable.

16. The device according to claim 15, characterized in that The target template further includes a plurality of candidate starting addresses; the first information is specifically a modulo result of a loop count where the first operation is located and the first variable, and different candidate starting addresses correspond to different modulo results.

17. The device according to any one of claims 12 to 16, characterized in that The target template includes: A first execution constraint between a second operation and a third operation; the first execution constraint indicates whether to execute in parallel, the second operation and the third operation belong to operations with different loop counts in a loop operation, and the execution order constraint is represented by a relationship between second information and third information, the second information being a relationship between the loop count where the second operation is located and the first variable, and the third information being a relationship between the loop count where the third operation is located and the first variable.

18. The device according to claim 17, characterized in that The second information is specifically a modulo result of a loop count of the second operation and the quantity; The third information is specifically a modulo result of the loop count of the third operation and the quantity; When the second information and the third information are the same, the first execution constraint indicates that the second operation and the third operation are not executed in parallel.

19. The device according to any one of claims 12 to 18, characterized in that The acquisition module is further used to: Obtain second indication information, where the second indication information is used to indicate whether to enable preload optimization; wherein, The target template is also adapted to enable or disable preload optimization, and the target template includes a second variable related to whether preload optimization is enabled. The compiler is also used to assign a value to the second variable in the target template based on whether preload optimization is enabled to obtain an intermediate representation IR of the source code.

20. The device according to claim 19, characterized in that When the second indication information indicates to turn on preload, the second variable in the target template is assigned a first preset value, and when the second variable is the first preset value, the IR indicates the execution of a first code and a second code, wherein the first code indicates loading data required for an operation with a loop count of 0, and the second code indicates preloading data required for an operation with a loop count of j+1, where j is the current loop count.

21. The device according to claim 20, characterized in that When the second indication information indicates that preload is not enabled, the second variable in the target template is assigned a second preset value, and when the second variable is the second preset value, the IR indicates the execution of a third code, and the third code indicates the loading of data required for an operation with a loop count of j, where j is the current loop count.

22. A data processing device, characterized in that: The device comprises a memory and a processor; the memory stores codes, the processor is configured to execute the codes, and when the codes are executed, the device executes the method according to any one of claims 1 to 11.

23. A computer storage medium, characterized in that The computer storage medium stores instructions, which, when executed by a computer, cause the computer to implement the method according to any one of claims 1 to 11.

24. A computer program product, characterized in that The computer program product stores instructions, which, when executed by a computer, cause the computer to implement the method according to any one of claims 1 to 11.