Model compiling method and apparatus, and device and storage medium

By analyzing the target calculation subgraph and thread task parallelism of the calculation graph of the machine learning model, the calculation tasks of memory access-intensive operators are rearranged, and an optimized execution instruction sequence is generated, which solves the problem of insufficient utilization of GPU resources and execution efficiency. low problem, achieving higher computing task parallelism and resource utilization.

WO2024222552A1PCT designated stage expired Publication Date: 2024-10-31CLOUD INTELLIGENCE ASSETS HOLDING (SINGAPORE) PTE LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2024/088380
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-04-25
Filing Date
2024-04-17
Publication Date
2024-10-31

AI Technical Summary

Technical Problem

In the existing technology, when a machine learning model is compiled on a GPU, there are problems such as high scheduling overhead for computing subgraph execution instructions in the CPU scheduling calculation graph and insufficient utilization of GPU resources, resulting in the inability to meet the performance requirements of users for computing tasks.

Method used

By obtaining the target calculation subgraph in the calculation graph of the model to be compiled, multiple sets of calculation tasks that need to be executed serially by the target thread are determined, and the sequence is rearranged according to the calculation dependencies of memory access-intensive operators to generate an execution instruction sequence. Improve thread parallelism and optimize the execution efficiency of executable program files.

Benefits of technology

It improves the execution efficiency and resource utilization of machine learning models on the GPU. By rearranging the order of memory-intensive operators in threads, the parallelism of computing tasks and instruction execution is improved, and resource scheduling overhead is reduced.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024088380_31102024_PF_FP_ABST
    Figure CN2024088380_31102024_PF_FP_ABST
Patent Text Reader

Abstract

Provided in the present application are a model compiling method and apparatus, and a device and a storage medium. The method comprises: acquiring, from a computation graph corresponding to a model to be compiled, a target computation sub-graph which includes a plurality of memory access intensive operators and corresponding data; according to a plurality of threads set in an actuator of the model and the computation task parallelism of each thread, determining a plurality of groups of computation tasks that a target thread needs to execute in series, wherein each computation task refers to a task of sequentially using the plurality of memory access intensive operators to perform computation on the corresponding data; for any group of computation tasks, according to the computation dependency relationship of the plurality of memory access intensive operators, performing sequential rearrangement on a plurality of computation tasks included in any group of computation tasks, such that different computation tasks corresponding to the same memory access intensive operator are arranged in parallel, so as to generate an execution instruction sequence corresponding to the target thread and any group of computation tasks; and on the basis of the execution instruction sequence corresponding to any group of computation tasks, determining that the actuator executes an executable program file of the model.
Need to check novelty before this filing date? Find Prior Art

Description

Model compilation method, device, equipment and storage medium

[0001] This application claims priority to the Chinese patent application filed with the China Patent Office on April 25, 2023, with application number 202310478439.4 and invention name “Model compilation method, device, equipment and storage medium”, the entire contents of which are incorporated by reference into this application. Technical Field

[0002] The present application relates to the field of artificial intelligence technology, and in particular to a model compilation method, apparatus, device, and storage medium. Background Art

[0003] Currently, machine learning is widely used in fields such as image processing, natural language processing, search, recommendation, and advertising. Machine learning computational tasks often require a certain amount of computing power and are often deployed on executors such as graphics processing units (GPUs).

[0004] During implementation, machine learning models, from high-level modeling to low-level deployment, require model compilation. This involves translating the high-level code language corresponding to the machine learning model into the low-level machine language supported by the underlying hardware. During model compilation, the high-level code language corresponding to the machine learning model is first converted into the computational representation of the model's corresponding computational graph. Optimization strategies are then applied to the computational graph to generate the final low-level machine language, such as the executable program running on the GPU. The optimization strategy applied to the computational graph determines the efficiency of the machine learning model's task execution.

[0005] In related technologies, when the model compilation results are running, there are often problems such as high scheduling overhead when the CPU schedules the execution instructions corresponding to each computational subgraph in the computational graph to the GPU and insufficient GPU resource utilization, which cannot meet the user's performance requirements for machine learning computing tasks.

[0006] Summary of the Invention

[0007] Embodiments of the present application provide a model compilation method, apparatus, device, and storage medium for improving the execution efficiency of a compiled executable program file when executed by an executor and the resource utilization of the executor.

[0008] In a first aspect, an embodiment of the present application provides a model compilation method, the method comprising: obtaining a target computation subgraph in a computation graph corresponding to a model to be compiled, the target computation subgraph comprising a plurality of memory-intensive operators and corresponding data, the target computation subgraph being a computation subgraph contained in the computation graph; determining a plurality of groups of computation tasks to be executed serially by a target thread according to a plurality of threads set in an executor of the model and the computation task parallelism of each thread, wherein each group of computation tasks comprises a plurality of computation tasks, each computation task refers to a task for calculating corresponding data in sequence using the plurality of memory-intensive operators, the computation task parallelism indicates the number of computation tasks that can be executed in parallel by each thread, and the target thread is Any one of a plurality of threads; for any group of computing tasks, according to the computing dependencies of the plurality of memory-intensive operators, sequentially rearrange the plurality of computing tasks included in the any group of computing tasks to obtain a plurality of rearranged computing tasks, wherein the rearrangement causes different computing tasks corresponding to the same memory-intensive operator to be arranged in parallel; according to the plurality of rearranged computing tasks, generate an execution instruction sequence corresponding to the target thread and the any group of computing tasks; according to the execution instruction sequence corresponding to the target thread and the any group of computing tasks, determine an executable program file for the executor to execute the model, wherein the executable program file contains execution instruction sequences corresponding to each of the plurality of computing subgraphs contained in the computing graph.

[0009] In a second aspect, an embodiment of the present application provides a model compilation device, the device comprising: an acquisition module for acquiring a target computational subgraph in a computational graph corresponding to a model to be compiled, the target computational subgraph comprising multiple memory-intensive operators and corresponding data, the target computational subgraph being a computational subgraph contained in the computational graph; a compilation module for determining, based on multiple threads set in an executor of the model and the computational task parallelism of each thread, a plurality of groups of computational tasks to be executed serially by a target thread, wherein each group of computational tasks comprises multiple computational tasks, each computational task refers to a task that sequentially uses the multiple memory-intensive operators to compute corresponding data, and the computational task parallelism indicates the number of computational tasks that can be executed in parallel by each thread, The target thread is any one of a plurality of threads; for any group of computing tasks, the plurality of computing tasks contained in the any group of computing tasks are sequentially rearranged according to the computing dependencies of the plurality of memory-intensive operators to obtain a plurality of rearranged computing tasks, wherein the rearrangement causes different computing tasks corresponding to the same memory-intensive operator to be arranged in parallel; based on the plurality of rearranged computing tasks, an execution instruction sequence corresponding to the target thread and the any group of computing tasks is generated; based on the execution instruction sequence corresponding to the target thread and the any group of computing tasks, an executable program file for the executor to execute the model is determined, wherein the executable program file contains execution instruction sequences corresponding to each of the plurality of computing subgraphs contained in the computing graph.

[0010] In a third aspect, an embodiment of the present application provides an electronic device comprising: a memory, a processor, and a communication interface; wherein the memory stores executable code, and when the executable code is executed by the processor, the processor executes the model compilation method as described in the first aspect.

[0011] In a fourth aspect, an embodiment of the present application provides a non-transitory machine-readable storage medium, on which executable code is stored. When the executable code is executed by a processor of an electronic device, the processor can at least implement the model compilation method described in the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] In order to more clearly illustrate the technical solutions in the embodiments of the present application, a brief introduction will be given below to the drawings required for use in the description of the embodiments. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0013] FIG1 is a flow chart of a model compilation method provided in an embodiment of the present application;

[0014] FIG2 is a schematic diagram of grouping computing tasks provided in an embodiment of the present application;

[0015] FIG3 is a flowchart of another model compilation method provided in an embodiment of the present application;

[0016] FIG4 is a schematic diagram of an execution scenario of an execution instruction sequence provided in an embodiment of the present application;

[0017] FIG5 is a flowchart of another model compilation method provided in an embodiment of the present application;

[0018] FIG6 is a flowchart of another model compilation method provided in an embodiment of the present application;

[0019] FIG7 is a schematic diagram of a computational subgraph provided in an embodiment of the present application;

[0020] FIG8 is a schematic diagram of the structure of a model compilation device provided in an embodiment of the present application;

[0021] FIG9 is a schematic structural diagram of an electronic device provided by this embodiment. DETAILED DESCRIPTION

[0022] To make the purpose, technical solutions, and advantages of the embodiments of this application more clear, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0023] The following describes some embodiments of the present application in detail with reference to the accompanying drawings. In the absence of conflicts between the embodiments, the following embodiments and features in the embodiments may be combined with each other.

[0024] In addition, the step sequence in the following method embodiments is only an example and not a strict limitation.

[0025] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in the embodiments of the present application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.

[0026] To facilitate understanding, several concepts involved in the embodiments of the present application are first described below.

[0027] Model compilation is the process of converting the machine learning algorithm corresponding to a machine learning model from its development form to its deployment form. The development form of a machine learning algorithm refers to source code written in a high-level programming language that approximates natural language and mathematical formulas, while the deployment form of a machine learning algorithm refers to program code that can be executed by the underlying machine. In simple terms, model compilation is the process of converting a high-level code language into a low-level machine language, with the goal of deploying a machine learning model in a specific hardware environment.

[0028] A computational graph is a tool that represents the computational logic and state of a machine learning model's inference process. A computational graph corresponding to a machine learning model consists of multiple computational subgraphs, each of which contains operators and corresponding data (usually represented as tensors). During model compilation, the computational graph is the intermediate representation (IR) used to convert high-level code into underlying machine language. By applying appropriate optimization strategies to the computational graph, the final compiled underlying machine language, or executable program file for the underlying hardware, is obtained.

[0029] In practical applications, the operators contained in the computational subgraph are divided into computationally intensive operators and memory-intensive operators based on the ratio of computational instructions and memory-access instructions corresponding to each operator in the executable program file. A computationally intensive operator refers to an operator whose ratio of computational instructions to memory-access instructions is greater than a set threshold, such as matrix multiplication, convolution, etc.; a memory-intensive operator refers to an operator whose ratio of computational instructions to memory-access instructions is less than or equal to a set threshold, such as element-wise calculation, reduce calculation, etc. The model compilation method in this embodiment is used to optimize the execution instruction compilation process related to memory-intensive operators. Simply put, in a computationally intensive operator, a certain data may be used repeatedly many times, such as in matrix multiplication, a certain point in the matrix will be subjected to multiple different multiplication calculations; in a memory-intensive operator, a certain data may be used only once, such as in the point-by-point addition calculation of two matrices, a point will be subjected to only one addition calculation.

[0030] FIG1 is a flow chart of a model compilation method provided in an embodiment of the present application. As shown in FIG1 , the method includes the following steps:

[0031] 101. Obtain a target computation subgraph in a computation graph corresponding to the model to be compiled. The target computation subgraph includes multiple memory-intensive operators and corresponding data. The target computation subgraph is a computation subgraph included in the computation graph corresponding to the model.

[0032] 102. Based on the multiple threads set in the executor of the model and the computing task parallelism of each thread, determine the multiple groups of computing tasks that the target thread needs to execute serially, where each group of computing tasks contains multiple computing tasks, each computing task refers to a task that uses multiple memory-intensive operators in sequence to calculate corresponding data, the computing task parallelism indicates the number of computing tasks that each thread can execute in parallel, and the target thread is any one of the multiple threads.

[0033] 103. For any group of computing tasks, according to the computing dependencies of multiple memory-intensive operators, the multiple computing tasks included in any group of computing tasks are sequentially rearranged to obtain multiple rearranged computing tasks, wherein the rearrangement allows different computing tasks corresponding to the same memory-intensive operator to be arranged in parallel.

[0034] 104. Generate an execution instruction sequence corresponding to a target thread and any group of computing tasks according to the rearranged plurality of computing tasks.

[0035] 105. Determine an executable program file of the executor execution model based on an execution instruction sequence corresponding to the target thread and any group of computing tasks. The executable program file includes an execution instruction sequence corresponding to each of the multiple computing subgraphs included in the computing graph.

[0036] In this embodiment, the model compilation method can be executed by a CPU, which is equipped with a compiler with corresponding model compilation capabilities. In one embodiment, the executor can be an accelerator such as a graphics processing unit (GPU). The following description uses the GPU as an example, but is not limited to this.

[0037] In practical applications, based on its limited on-chip storage space (including shared memory and registers), when executing the executable program file corresponding to the model, the GPU often suffers from resource usage conflicts between compute-intensive operators and memory-intensive operators in the computational subgraph, resulting in low running efficiency of the executable program corresponding to the model and insufficient GPU resource utilization.

[0038] Specifically, compute-intensive operators in a computational subgraph have data locality. To achieve higher data reuse efficiency, more on-chip storage space on the GPU is usually used to store data calculation results so that these calculation results can be accessed by multiple other computations. This characteristic inevitably results in only a small amount of on-chip storage space in the GPU being available for memory-intensive operators. It is understandable that the small amount of on-chip storage space in the GPU can only provide a small number of threads, while memory-intensive operators often require more threads to improve the efficiency of accessing the GPU's off-chip storage space. Therefore, in general, the resource usage conflict between compute-intensive operators and memory-intensive operators lies in the fact that the limited on-chip storage space of the GPU cannot simultaneously provide sufficient on-chip storage space for compute-intensive operators to store data calculation results, while also providing enough threads for memory-intensive operators to achieve a high degree of thread parallelism.

[0039] In order to solve at least one of the above technical problems, in this embodiment, by reordering the computing tasks corresponding to the memory-intensive operators in the thread, when the number of threads in the GPU remains unchanged, the overall parallelism of the computing tasks corresponding to the memory-intensive operators when the encoded executable program file is executed is higher, thereby effectively improving the running efficiency of the executable program corresponding to the model. Since the order of the computing tasks corresponding to the memory-intensive operators is rearranged, it is manifested as a reordering of the execution instruction sequence corresponding to the computing tasks in the executable program file corresponding to the model. Therefore, this solution can be understood as improving the parallelism of the execution instruction sequence of the computing tasks that each thread in the executable program file needs to execute, so that when the thread parallelism remains unchanged, the overall parallelism of the computing tasks when the executable program is executed is higher. The following is an expanded explanation of the model compilation method in this embodiment.

[0040] During model compilation, after the high-level code language corresponding to the model to be compiled is sent to the CPU, the compiler in the CPU can automatically generate the corresponding computation graph for the model according to preset rules. The computation graph corresponding to any model contains multiple different computation subgraphs. During specific implementation, the process by which the compiler in the CPU determines the execution instruction sequence corresponding to any computation subgraph is similar. This embodiment uses the target computation subgraph as an example to illustrate the determination of the execution instruction sequence corresponding to the computation subgraph. The target computation subgraph can be any of the multiple computation subgraphs contained in the computation graph corresponding to the model to be compiled.

[0041] It should be noted that, in this embodiment, there is no restriction on the order of generating the execution instruction sequence corresponding to the computation subgraph, and each computation subgraph can generate its corresponding execution instruction sequence independently.

[0042] In summary, when determining the compilation result (i.e., the instruction execution sequence) corresponding to the target computational subgraph, first determine the number of computational tasks corresponding to the target computational subgraph; then determine the multiple computational tasks that each thread needs to execute; then group the computational tasks assigned to each thread, and rearrange the order of the computational tasks in each group of computational tasks to obtain the execution instruction sequences corresponding to each rearranged group of computational tasks; finally, based on the execution instruction sequences corresponding to each group of computational tasks in each thread, determine the compilation result corresponding to the target computational subgraph.

[0043] To elaborate, the target computation subgraph contains multiple memory-intensive operators and corresponding data. In this embodiment, tasks that sequentially use multiple memory-intensive operators to compute the corresponding data are called computation tasks. For example, assuming the target computation subgraph contains the memory-intensive operators "+" and "-", the corresponding data are three matrices A, B, and C, each with 8*8 dimensions, and the corresponding computation logic is A+BC, then the target computation subgraph corresponds to 64 tasks, namely, computation task 1, computation task 2, ..., computation task 64.

[0044] Assuming that the compiled model's executable program file is executed by GPU-i after compilation, that is, the compiled model is to be deployed on GPU-i, then during compilation, the compiler on the CPU can obtain the corresponding configuration information of GPU-i, such as the number of threads on GPU-i that can be used to execute computing tasks corresponding to memory-intensive operators, thread identifiers, and the computing task parallelism of each thread. The computing task parallelism of a thread can be understood as the number of computing tasks that a thread can execute simultaneously. Based on the GPU-i configuration information, multiple groups of computing tasks that need to be executed serially by each thread on GPU-i can be determined.

[0045] For example, based on the aforementioned assumption about the target computation subgraph, if GPU-i has four threads: thread 1, thread 2, thread 3, and thread 4, the 64 computational tasks corresponding to the target computation subgraph can be evenly distributed across the four threads. For example, thread 1 is assigned to computational tasks 1-16, thread 2 is assigned to computational tasks 17-32, thread 3 is assigned to computational tasks 33-48, and thread 4 is assigned to computational tasks 49-64. In practical applications, a non-even distribution approach can also be adopted, assigning multiple computational tasks corresponding to the target computation subgraph to corresponding threads in GPU-i.

[0046] Afterwards, for any one of the four threads (referred to as a target thread), the 16 computing tasks in the target thread are grouped according to the parallelism of the computing tasks corresponding to the target thread. Figure 2 is a schematic diagram of a grouping of computing tasks provided in an embodiment of the present application. When the parallelism of the computing tasks of threads 1 to 4 is 2, the 16 computing tasks that threads 1 and 2 need to execute respectively are used as an example for illustration. As shown in Figure 2, the computing tasks 1-16 that thread 1 needs to execute and the computing tasks 17-32 that thread 2 need to execute are divided into 8 groups, and each group of computing tasks contains 2 computing tasks. When the parallelism of the computing tasks of threads 1 to 4 is 4, the 16 computing tasks that thread 3 needs to execute are used as an example for illustration. As shown in Figure 2, the computing tasks 33-48 that thread 3 needs to execute are divided into 4 groups, and each group of computing tasks contains 4 computing tasks. When the parallelism of the computing tasks of threads 1 to 4 is 8, the 16 computing tasks that thread 4 needs to execute are used as an example for illustration. As shown in Figure 2, the computing tasks 49-64 that thread 4 needs to execute are divided into 2 groups, and each group of computing tasks contains 8 computing tasks. Based on the computing task grouping situation shown in Figure 2, it can be seen that different computing task parallelisms correspond to different grouping results.

[0047] It should be noted that in this embodiment, the target thread executes the divided groups of computing tasks serially. When the target thread executes multiple computing tasks within the same group, it executes them in parallel. Serial execution means completing one computing task before executing the next; parallel execution means executing multiple computing tasks within the same group simultaneously.

[0048] In order to achieve efficient execution of multiple computing tasks in the same group of computing tasks, in this embodiment, for a group of computing tasks, the multiple computing tasks are reordered according to the computational dependency relationship between multiple memory-intensive operators. The computational dependency relationship can be understood as the execution order of the memory-intensive operators and the association relationship between the corresponding data. Taking A+BC as an example, the memory-intensive operator "-" is executed after the memory-intensive operator "+", and the memory-intensive operator "-" depends on the calculation result of "A+B" when calculating C. It is considered that there is a computational dependency relationship between the memory-intensive operator "-" and the memory-intensive operator "+".

[0049] It should be emphasized that the purpose of reordering the computing tasks in this embodiment is to arrange different computing tasks corresponding to the same memory-intensive operator in parallel. For example, assuming that there is a group of computing tasks in thread 1, the group of computing tasks includes two computing tasks, namely a1+b1-c1 and a2+b2-c2, where the calculation result of a1+b1 is d1 and the calculation result of a2+b2 is d2. When the order of these two tasks is reordered, the computing task "a1+b1" corresponding to the memory-intensive operator "+" is arranged in parallel with the computing task "a2+b2", and the computing task "d1-c1" corresponding to the memory-intensive operator "-" is arranged in parallel with the computing task "d2-c2".

[0050] For the two computing tasks in thread 1 above, the reordered execution instruction sequence can be "a1+b1 computing instruction, a2+b2 computing instruction, d1-c1 computing instruction, d2-c2 computing instruction." Because there's no computing dependency between a1+b1 and a2+b2, after sending the a1+b1 and a2+b2 computing instructions consecutively, both a1+b1 and a2+b2 can be executed, achieving parallel execution and improving execution efficiency.

[0051] It is understandable that if the computing tasks a1+b1-c1 and a2+b2-c2 are not reordered, their corresponding execution instruction sequence is "computational instruction for a1+b1, computational instruction for d1-c1, computational instruction for a2+b2, computational instruction for d2-c2." During actual execution, after sending the computational instruction for a1+b1, the computational instruction for d1 must be obtained before the computational instruction for d1-c1 can be sent. Similarly, the computational instructions for a1+b1 and d1-c1 are then sent. This approach results in time gaps between computational instructions. For example, after sending the computational instruction for a1+b1, there is a time gap while waiting for the computation of a1+b1 to complete and obtain d1. This prevents full utilization of the GPU-i's on-chip storage resources, resulting in resource waste and low computing efficiency.

[0052] From the perspective of the overall parallelism of the computing tasks when the executable program file is executed, thread 1, with a computing task parallelism of 2, can execute two computing tasks in parallel. If the computing task parallelism corresponding to each of the four threads in GPU-i is 2, then when GPU-i executes the executable program, the overall parallelism of the computing tasks is 2*4=8. Compared to the original situation where the overall parallelism of the computing tasks corresponding to the four threads is 4, when the execution instruction sequences generated by each group of computing tasks obtained by the method of this embodiment are executed, the computing instructions corresponding to the same memory-intensive operator can be executed concurrently, effectively improving the overall parallelism of the computing tasks and, in turn, the execution efficiency of the computing instructions is also improved.

[0053] Finally, according to the execution instruction sequence corresponding to the target thread and any group of computing tasks, the executable program file of the executor execution model is determined, wherein the executable program file contains the execution instruction sequence corresponding to each of the multiple computing subgraphs contained in the computing graph.

[0054] In this embodiment, by arranging in parallel the different computing tasks corresponding to the same memory-intensive operator in each group of computing tasks that the thread needs to execute, the resulting execution instruction sequence has a high degree of instruction parallelism. When the executable program file is finally generated, it can send and execute multiple execution instructions in parallel to simultaneously perform parallel calculations on different computing tasks corresponding to the same memory-intensive operator, thereby improving the running efficiency of the executable program file while keeping the number of threads in the executor unchanged.

[0055] The above embodiments provide a model compilation solution that improves the running efficiency of executable program files from the perspective of computing task parallelism. In practical applications, factors affecting the running efficiency of executable program files also include resource scheduling during instruction execution and instruction scheduling overhead. The following embodiments take these factors into consideration and provide alternative model compilation solutions.

[0056] FIG3 is a flow chart of another model compilation method provided in an embodiment of the present application. As shown in FIG3 , the method includes the following steps:

[0057] 301. Obtain a target computation subgraph in a computation graph corresponding to the model to be compiled, where the target computation subgraph includes multiple memory-intensive operators and corresponding data. The target computation subgraph is a computation subgraph included in the computation graph corresponding to the model.

[0058] 302. Based on the multiple threads set in the executor of the model and the computing task parallelism of each thread, determine the multiple groups of computing tasks that the target thread needs to execute serially, where each group of computing tasks contains multiple computing tasks, each computing task refers to a task that uses multiple memory-intensive operators in sequence to calculate corresponding data, the computing task parallelism indicates the number of computing tasks that each thread can execute in parallel, and the target thread is any one of the multiple threads.

[0059] 303. For any group of computing tasks, according to the computing dependencies of multiple memory-intensive operators, the multiple computing tasks included in any group of computing tasks are sequentially rearranged to obtain multiple rearranged computing tasks, wherein the rearrangement allows different computing tasks corresponding to the same memory-intensive operator to be arranged in parallel.

[0060] 304. Generate an execution instruction sequence corresponding to a target thread and any group of computing tasks according to the rearranged plurality of computing tasks.

[0061] 305. Insert a first data copy instruction before the execution instruction sequence corresponding to the target thread and any group of computing tasks. The first data copy instruction is used to copy the data corresponding to the next group of computing tasks of any group of computing tasks from the off-chip storage space of the executor to the first buffer of the on-chip storage space of the executor, so that the corresponding data can be read from the first buffer when executing the next group of computing tasks.

[0062] 306. Determine an executable program file of the executor execution model based on the execution instruction sequence corresponding to the target thread and any group of computing tasks and the first data copy instruction, wherein the executable program file includes the execution instruction sequence corresponding to each of the multiple computing subgraphs included in the computing graph.

[0063] The specific implementation process of steps 301 to 304 may refer to the aforementioned embodiment and will not be described in detail in this embodiment.

[0064] In this embodiment, the GPU is used as the executor. In practice, the GPU's memory space can be divided into on-chip memory and off-chip memory. On-chip memory, including shared memory and registers, refers to on-chip memory that can be shared within a thread block. Off-chip memory corresponds to the GPU's global memory (also known as main memory) and is visible to all threads globally.

[0065] In the executable program file corresponding to a GPU-executable model, the execution instruction sequence corresponding to a set of computing tasks typically includes instructions related to "read-compute-write." "Read" refers to reading the data corresponding to the computing task from the buffer or register in the on-chip storage space; "compute" refers to performing the calculation corresponding to the memory-intensive operator based on the data read from the buffer; and "write" refers to writing the calculation results to the register in the on-chip storage space.

[0066] Before executing the instruction sequence corresponding to any set of computing tasks, the GPU typically needs to copy the data corresponding to that set of computing tasks from off-chip storage to a buffer in on-chip storage. This allows the corresponding data to be read from the buffer when executing the instruction sequence corresponding to that set of computing tasks. In practical applications, the data copying time corresponding to each set of computing tasks affects the execution efficiency of the instruction sequence corresponding to each set of computing tasks. If the copying time is too long, it will take a long time to execute the instruction sequence corresponding to the computing task.

[0067] In this embodiment, in order to speed up the running efficiency of the executable program file, a "double buffering" mechanism is introduced. In layman's terms, two buffers are set in the on-chip storage space of the GPU. Through the setting of these two buffers, when executing the computing tasks of the current group in the target thread, the data corresponding to the next group of computing tasks can be copied from the off-chip storage space to the buffer of the on-chip storage space in advance, that is, the data copying process corresponding to the next group of computing tasks is pre-placed, so that when executing the next group of computing tasks, the corresponding data of each group of computing tasks can be read directly from the buffer of the on-chip storage space, without having to wait for the corresponding data of the next group of computing tasks to be copied from the off-chip storage space to the buffer of the on-chip storage space. Based on the setting of the double buffer, the waiting time when copying the data related to the computing task to the on-chip storage space can be saved, so that the running efficiency of executing instructions is higher.

[0068] Generally, the target thread needs to execute multiple groups of computing tasks serially. According to their corresponding execution order, the multiple groups of computing tasks can be divided into the first execution task (also called the first group of execution tasks) and the kth group of execution tasks, where k is an integer greater than 1.

[0069] When any of the other tasks in step 305 corresponds to the kth group of execution tasks, a first data copy instruction may be inserted directly before the execution instruction sequence corresponding to the kth group of execution tasks. The first data copy instruction is used to copy the data corresponding to the k+1th group of computing tasks from the GPU's off-chip storage space to a first buffer in the GPU's on-chip storage space, so that the corresponding data can be read from the first buffer when executing the k+1th group of computing tasks.

[0070] When any group of computing tasks in step 305 corresponds to the first group of computing tasks, a second data copy instruction is inserted before the first data copy instruction. The second data copy instruction is used to copy the data corresponding to the first group of computing tasks from the GPU's off-chip storage space to the second buffer of the GPU's on-chip storage space.

[0071] It should be noted that if each group of computing tasks contains multiple memory-intensive operators, when copying the corresponding data of each group of computing tasks to the buffer of the on-chip storage space, the data related to the same memory-intensive operator in the same group of computing tasks are copied to the buffer of the on-chip storage space in sequence according to the computing dependency relationship of the memory-intensive operators.

[0072] During the specific implementation process, the data corresponding to the k+1th group of computing tasks copied to the first buffer according to the first copy instruction is the data corresponding to the first memory-intensive operator in the k+1th group of computing tasks; the data corresponding to the 1st group of computing tasks copied to the second buffer according to the second copy instruction is the data corresponding to the first memory-intensive operator in the 1st group of computing tasks.

[0073] For data corresponding to a non-first memory-intensive operator, in one embodiment, its corresponding copy instruction can be similar to the copy instruction of the first memory-intensive operator and be pre-placed in the execution instruction sequence of the previous group of computing tasks, or in the execution instruction sequence of the current group of computing tasks. This embodiment does not impose any restrictions on this.

[0074] The following examples will more clearly illustrate the relationship between the copy instruction and the execution instruction sequence of a certain set of computing tasks. In the example, for greater clarity, the execution instruction sequence corresponding to a set of computing tasks is broken down into the corresponding read instructions, compute instructions, and write instructions.

[0075] Let's take thread 1, shown in Figure 2, as an example. As shown in Figure 2, thread 1 needs to serially execute the computational tasks in groups 1 through 8. Assume that group 1 includes two computational tasks: a1+b1-c1 and a2+b2-c2; group 2 includes two computational tasks: a3+b3-c3 and a4+b4-c4; and group 3 includes two computational tasks: a5+b5-c5 and a6+b6-c6. The computational result of a1+b1 is d1, the computational result of a2+b2 is d2, the computational result of a3+b3 is d3, the computational result of a4+b4 is d4, the computational result of a5+b5 is d5, and the computational result of a6+b6 is d6. Similarly, the two computational tasks contained in groups 4 through 8 are not further illustrated.

[0076] Assuming that the two buffers set in the GPU's on-chip storage space are buffer0 and buffer1, when the "double buffering" mechanism is introduced, the execution instruction sequences corresponding to group 1, group 2, and group 3 in thread 1 are:

[0077] The execution instruction sequence corresponding to group 1 in thread 1 is as follows: 1) a copy instruction to copy data a1, b1, a2, and b2 from the off-chip storage space to buffer0; 2) a copy instruction to copy data a3, b3, a4, and b4 from the off-chip storage space to buffer1; 3) a read instruction to read data a1, b1, a2, and b2 from buffer0; 4) a calculation instruction to calculate a1+b1, and a calculation instruction to calculate a2+b2; 5) a write instruction to write the calculation results d1 and d2 to the register; 6) a read instruction to read the calculation results d1 and d2 from the register; 7) a copy instruction to copy data c1 and c2 from the off-chip storage space to buffer0; 8) a read instruction to read c1 and c2 from buffer0; 9) a calculation instruction to calculate d1+c1, and a calculation instruction to calculate d2+c2; (10) a write instruction to write the calculation result to the off-chip storage space.

[0078] After the execution instruction sequence corresponding to group 1 in thread 1 is executed, buffer 0 is empty.

[0079] The execution instruction sequence corresponding to group 2 in thread 1 is as follows: 1) a copy instruction to copy data a5, b5, a6, and b6 from the off-chip storage space to buffer0; 2) a read instruction to read data a3, b3, a4, and b4 from buffer1; 3) a calculation instruction to calculate a3+b3, and a calculation instruction to calculate a4+b4; 4) a write instruction to write the calculation results d3 and d4 to the register; 5) a read instruction to read the calculation results d3 and d4 from the register; 6) a copy instruction to copy data c3 and c4 from the off-chip storage space to buffer1; 7) a read instruction to read c3 and c4 from buffer1; 8) a calculation instruction to calculate d3+c3, and a calculation instruction to calculate d4+c4; (9) a write instruction to write the calculation result to the off-chip storage space.

[0080] After the execution instruction sequence corresponding to group 2 in thread 1 is executed, buffer 1 is empty.

[0081] The execution instruction sequence for groups 3 through 7 in thread 1 is similar to the execution instruction sequence for group 2 and will not be repeated here. Since there is no subsequent group after group 8, the execution instruction sequence for group 8 does not include a copy instruction to copy the data corresponding to the first memory-intensive operator in the subsequent group to the buffer.

[0082] In addition, through the above examples, it can be found that the first buffer and the second buffer in this embodiment do not fixedly indicate a specific buffer, but are updated alternately. For example, the first buffer in the instruction sequence of group 1 indicates buffer1, and the first buffer in the instruction sequence of group 2 indicates buffer0.

[0083] Assuming that the time for copying the data corresponding to the first memory-intensive operator in each group of computing tasks to be executed by thread 1 from the off-chip storage space to the buffer of the on-chip storage space is t1, and the execution time of the execution instruction sequence corresponding to each group of computing tasks is t2, then Figure 4 can more clearly reflect the improvement of the running efficiency of the executable program file corresponding to the model by the "double buffering" mechanism in this embodiment.

[0084] Figure 4 is a schematic diagram of the execution of an execution instruction sequence provided by an embodiment of the present application. Figure 4 illustrates the time required to execute the instruction sequence corresponding to three groups of computing tasks. As shown in Figure 4, under the non-double buffering mechanism, since there is only one buffer, only one group of computing task-related data can be copied at a time. Therefore, for the next group of computing tasks, it can only wait for the execution instruction sequence of the previous group of computing tasks to be completed and the buffer to be free before the corresponding data copying can be performed. The time required to execute the instruction sequence corresponding to the three groups of computing tasks is 3*(t1+t2). Under the double buffering mechanism, while copying the data corresponding to the computing tasks of group 1, the data corresponding to the computing tasks of group 2 can also be copied. While executing the execution instruction sequence corresponding to group 2, the data corresponding to the computing tasks of group 3 can also be copied. The time required to execute the instruction sequence corresponding to the three groups of computing tasks is t1+3*t2, which is significantly less than the execution time under the non-double mechanism.

[0085] Therefore, in this embodiment, by introducing a double buffering mechanism, the calculation of different groups of computing tasks and the copying of data from the off-chip storage space to the on-chip storage space can be overlapped, effectively improving the memory access efficiency of memory-intensive operators and improving the running efficiency of the executable program file corresponding to the model.

[0086] FIG5 is a flowchart of another model compilation method provided in an embodiment of the present application. As shown in FIG5 , the method includes the following steps:

[0087] 501. Obtain a target computation subgraph in a computation graph corresponding to the model to be compiled, where the target computation subgraph includes multiple memory-intensive operators and corresponding data. The target computation subgraph is a computation subgraph included in the computation graph corresponding to the model.

[0088] 502. Based on the multiple threads set in the executor of the model and the computing task parallelism of each thread, determine the multiple groups of computing tasks that the target thread needs to execute serially, where each group of computing tasks contains multiple computing tasks, each computing task refers to a task that uses multiple memory-intensive operators in sequence to calculate corresponding data, the computing task parallelism indicates the number of computing tasks that each thread can execute in parallel, and the target thread is any one of the multiple threads.

[0089] 503. For any group of computing tasks, according to the computing dependencies of multiple memory-intensive operators, the multiple computing tasks included in any group of computing tasks are sequentially rearranged to obtain multiple rearranged computing tasks, wherein the rearrangement allows different computing tasks corresponding to the same memory-intensive operator to be arranged in parallel.

[0090] 504. Generate an execution instruction sequence corresponding to a target thread and any group of computing tasks according to the rearranged plurality of computing tasks.

[0091] 505. Determine the execution instruction sequence corresponding to the target computation subgraph based on the execution instruction sequences corresponding to the multiple groups of computation tasks executed by the multiple threads under the target computation subgraph; and determine the executable program file of the model by integrating the execution instruction sequences corresponding to the multiple computation subgraphs in the computation graph.

[0092] The specific implementation process of steps 501 to 504 may refer to the aforementioned embodiment and will not be described in detail in this embodiment.

[0093] In this embodiment, when generating the executable program file corresponding to the model, first, an execution instruction sequence corresponding to each group of computing tasks is generated; then, based on the execution instruction sequence corresponding to each group of computing tasks that the thread needs to execute, the execution instruction sequence corresponding to the thread is determined; then, based on the execution instruction sequence of each thread corresponding to the computing subgraph, the execution instruction sequence corresponding to the computing subgraph is determined; finally, the execution instruction sequence of each computing subgraph corresponding to the computing graph of the model is fused to generate the executable program file of the model.

[0094] Typically, after generating the executable file corresponding to the model, it is necessary to debug the executable file to obtain an executable file with better performance. It is understandable that directly debugging the executable file can be exponentially complex, making it impossible to complete the debugging and determine the executable file with better performance within a certain timeframe.

[0095] Since computational subgraphs are often independent of each other, in this embodiment, the execution instruction sequence corresponding to the computational subgraph is used as the basic debugging unit of the executable program file. By debugging the execution instruction sequence corresponding to each computational subgraph separately, the execution instruction sequence with better running performance corresponding to each computational subgraph is determined, and finally the execution instruction sequence with better running performance corresponding to each computational subgraph is merged into an executable program file.

[0096] During the specific implementation process, the parallelism of the computing tasks of each thread can be flexibly configured. Based on the introduction in the above embodiments, different parallelisms of computing tasks will have different computing task grouping results, and thus will also generate different execution instruction sequences.

[0097] Therefore, as a method of debugging an execution instruction sequence, we can first obtain multiple execution instruction sequences corresponding to the target computational subgraph under multiple degrees of parallelism of computing tasks; then, based on the running performance of the executor when executing multiple execution instruction sequences respectively, determine the target execution instruction sequence corresponding to the target computational subgraph; finally, fuse the target execution instruction sequences corresponding to multiple computational subgraphs to determine the executable program file of the model.

[0098] The performance of an executor when executing multiple execution instruction sequences can be measured by execution time. For example, the target computation subgraph corresponds to multiple execution instruction sequences under various computation task parallelisms: execution instruction sequence 1 and execution instruction sequence 2. The executor takes execution time T1 to execute execution instruction sequence 1, and takes execution time T2 to execute execution instruction sequence 2. If T1 > T2, execution instruction sequence 2 is determined to be the target execution instruction sequence corresponding to the target computation subgraph.

[0099] In this embodiment, the execution instruction sequence corresponding to the computational subgraph is used as the basic debugging unit. The execution instruction sequence that needs to be tested by the executor each time is small compared to all the execution instruction sequences corresponding to the executable program file. Therefore, the target execution instruction sequence corresponding to each computational subgraph can be determined in a short time, which not only obtains a feasible program file with better running performance, but also improves debugging efficiency.

[0100] FIG6 is a flowchart of another model compilation method provided in an embodiment of the present application. As shown in FIG6 , the method includes the following steps:

[0101] 601. Obtain a target computation subgraph in a computation graph corresponding to a model to be compiled, where the target computation subgraph includes multiple memory-intensive operators and corresponding data. The target computation subgraph is a computation subgraph included in the computation graph corresponding to the model.

[0102] 602. Based on the multiple threads set in the executor of the model and the computing task parallelism of each thread, determine the multiple groups of computing tasks that the target thread needs to execute serially, where each group of computing tasks contains multiple computing tasks, each computing task refers to a task that uses multiple memory-intensive operators in sequence to calculate corresponding data, the computing task parallelism indicates the number of computing tasks that each thread can execute in parallel, and the target thread is any one of the multiple threads.

[0103] 603. For any group of computing tasks, according to the computing dependencies of multiple memory-intensive operators, the multiple computing tasks included in any group of computing tasks are sequentially rearranged to obtain multiple rearranged computing tasks, wherein the rearrangement allows different computing tasks corresponding to the same memory-intensive operator to be arranged in parallel.

[0104] 604. Generate an execution instruction sequence corresponding to a target thread and any group of computing tasks according to the rearranged plurality of computing tasks.

[0105] 605. Determine an execution instruction sequence corresponding to the target computation subgraph according to execution instruction sequences corresponding to the multiple groups of computation tasks executed by the multiple threads under the target computation subgraph.

[0106] 606. Determine the distances of the multiple computational subgraphs to the initial computational subgraph respectively; group the multiple computational subgraphs according to the distances, wherein the distances corresponding to the computational subgraphs in the same group of computational subgraphs are the same; and insert a global synchronization instruction after the execution instruction sequence corresponding to each group of computational subgraphs to determine the executable program file of the model.

[0107] The specific implementation process of steps 601 to 605 can be referred to the aforementioned embodiment and will not be repeated in this embodiment.

[0108] Typically, after determining the execution instruction sequence corresponding to a computational subgraph, each corresponding execution instruction sequence is stored separately as a function, also known as a GPU kernel. When the GPU executes an executable program file, the CPU actually sends the GPU kernel corresponding to each computational subgraph to the GPU for execution.

[0109] The above-mentioned method of storing the GPU kernels corresponding to each computational subgraph separately, when the GPU executes the executable program file, the CPU must not only determine when to send the GPU kernel corresponding to which computational subgraph to the GPU for execution, but also frequently schedule the GPU kernels corresponding to each computational subgraph, which will generate a large non-computational overhead, that is, scheduling overhead. In addition, each computational subgraph corresponds to a different GPU kernel, and the global synchronization brought by the GPU kernel will also cause a certain amount of additional overhead. Global synchronization means that all execution instruction sequences corresponding to the GPU kernel are executed and no longer need to use on-chip storage space. In addition, since the CPU processing GPU tasks is usually busy due to tasks such as data processing, and the executable program file corresponding to the model corresponds to a large number of GPU kernels that need to be executed separately, the busy CPU will be unable to schedule these GPU kernels in a timely manner, resulting in a certain performance loss.

[0110] To solve at least one of the above technical problems, in this embodiment, after determining the execution instruction sequences corresponding to the multiple computational subgraphs contained in the model computation graph, the distances of the multiple computational subgraphs to the initial computational subgraph are first determined, where the initial computational subgraph is the computational subgraph corresponding to the input data of the computational subgraph, that is, the first computational subgraph of the computational subgraph; then, the multiple computational subgraphs are grouped according to the distance, and the computational subgraphs with the same corresponding distance are grouped into the same group; finally, a global synchronization instruction is inserted after the execution instruction sequence corresponding to each group of computational subgraphs to determine the executable program file of the model, where the executable program file of the model is a GPU kernel.

[0111] Figure 7 is a schematic diagram of a computational subgraph provided in an embodiment of the present application, and Figure 7 is used to illustrate the process of determining the executable program file of the model in this embodiment. As shown in Figure 7, it is assumed that the computational graph corresponding to the model to be compiled contains 6 computational subgraphs, namely computational subgraph A, computational subgraph B, computational subgraph C, computational subgraph D, computational subgraph E, and computational subgraph F (represented by A, B, C, D, E, and F in Figure 7), where computational subgraph A is the initial computational subgraph.

[0112] As shown in Figure 7, a computation subgraph may have more than one distance to the initial computation subgraph. Taking computation subgraph C as an example, when computation subgraph C follows the path "A→C", the corresponding distance to the initial computation subgraph is 1; when computation subgraph C follows the path "A→D→F→C", the corresponding distance to the initial computation subgraph is 3. To address this situation, in this embodiment, the distance from computation subgraph C to the initial computation subgraph is determined to be 3.

[0113] From this, we can determine that the distances from computation subgraphs A, B, C, D, E, and F to the initial computation subgraph (i.e., computation subgraph A) in Figure 7 are 0, 1, 3, 1, 4, and 2, respectively. Since the distances corresponding to computation subgraphs B and D are both 1, computation subgraphs B and D are grouped together, while computation subgraphs A, C, E, and F are each grouped separately.

[0114] Finally, a global synchronization instruction is inserted after the execution instruction sequence corresponding to the 5 groups of computational subgraphs to determine the executable program file of the model. Among them, the group corresponding to computational subgraph E is the last group, and you can choose to insert or not insert the global synchronization instruction after its corresponding execution instruction sequence. Since computational subgraph B and computational subgraph D belong to the same group, after inserting the global synchronization instruction after the group, it is equivalent to the execution instruction execution sequence corresponding to computational subgraph B and computational subgraph D, and a total of one global synchronization is required. In the case where each of the above computational subgraphs corresponds to a GPU kernel, the execution instruction execution sequence corresponding to computational subgraph B and computational subgraph D needs to be globally synchronized once. Therefore, the model compilation method in this embodiment can effectively reduce the number of global synchronizations, and the more computational subgraphs belonging to the same group, the more obvious this effect will be.

[0115] In this embodiment, the model's executable program file is a GPU kernel. Specifically, the execution instruction sequence and global synchronization instructions corresponding to each computational subgraph are stored as a function. This allows the CPU to send the model's corresponding GPU kernel to the GPU when executing the model's executable program file. The CPU does not need to determine when to send which GPU kernel to the GPU, nor does it need to frequently schedule GPU kernels. This effectively reduces non-computational overhead and the performance loss incurred by CPU scheduling GPU kernels. Furthermore, because the computational subgraphs are grouped and global synchronization instructions are inserted only after each group, the number of global synchronizations is reduced, improving computational efficiency and, consequently, the efficiency of the executable program file.

[0116] In practical applications, the model compilation solutions in the aforementioned embodiments can be combined with each other to achieve better model compilation effects.

[0117] In addition, it should be noted that, although the model compilation method provided in the aforementioned embodiments describes the execution instruction generation process for computing tasks related to memory-intensive operators, it does not mean that the complete executable program file corresponding to the model only contains execution instructions for computing tasks related to memory-intensive operators. The complete executable program file corresponding to the model also contains execution instructions for computing tasks related to computing-intensive operators.

[0118] The following describes in detail the model compilation device of one or more embodiments of the present application. Those skilled in the art will appreciate that these devices can be constructed by configuring commercially available hardware components through the steps taught in this solution.

[0119] FIG8 is a schematic structural diagram of a model compilation device provided in an embodiment of the present application. As shown in FIG8 , the device includes: an acquisition module 11 and a compilation module 12 .

[0120] The acquisition module 11 is used to obtain a target computation subgraph in a computation graph corresponding to the model to be compiled, wherein the target computation subgraph includes multiple memory-intensive operators and corresponding data, and the target computation subgraph is a computation subgraph included in the computation graph.

[0121] The compilation module 12 is used to determine multiple groups of computing tasks that the target thread needs to execute serially based on multiple threads set in the executor of the model and the computing task parallelism of each thread, wherein each group of computing tasks includes multiple computing tasks, each computing task refers to a task that sequentially uses the multiple memory-intensive operators to calculate corresponding data, the computing task parallelism indicates the number of computing tasks that each thread can execute in parallel, and the target thread is any one of the multiple threads; for any group of computing tasks, according to the computing dependencies of the multiple memory-intensive operators, the multiple computing tasks included in the any group of computing tasks are sequentially rearranged to obtain multiple rearranged computing tasks, wherein the rearrangement causes different computing tasks corresponding to the same memory-intensive operator to be arranged in parallel; based on the multiple rearranged computing tasks, an execution instruction sequence corresponding to the target thread and the any group of computing tasks is generated; based on the execution instruction sequence corresponding to the target thread and the any group of computing tasks, an executable program file for the executor to execute the model is determined, and the executable program file contains execution instruction sequences corresponding to each of the multiple computing subgraphs included in the computing graph.

[0122] In one embodiment, the compilation module 12 is further used to insert a first data copy instruction before the execution instruction sequence corresponding to the target thread and any one group of computing tasks. The first data copy instruction is used to copy the data corresponding to the next group of computing tasks of the any one group of computing tasks from the off-chip storage space of the executor to the first buffer of the on-chip storage space of the executor, so that the corresponding data is read from the first buffer when executing the next group of computing tasks.

[0123] In one embodiment, the compilation module 12 is specifically used to insert a second data copy instruction before the first data copy instruction if any one group of computing tasks is the first computing task among the multiple groups of computing tasks. The second data copy instruction is used to copy the data corresponding to the any one group of computing tasks from the off-chip storage space of the executor to the second buffer of the on-chip storage space of the executor.

[0124] Among them, the data corresponding to the next group of computing tasks copied to the first buffer is the data corresponding to the first memory-intensive operator in the next group of computing tasks; the data corresponding to any group of computing tasks copied to the second buffer is the data corresponding to the first memory-intensive operator in any group of computing tasks.

[0125] In one embodiment, the compilation module 12 is further specifically used to determine the execution instruction sequence corresponding to the target computing subgraph based on the execution instruction sequences corresponding to the multiple groups of computing tasks executed by the multiple threads under the target computing subgraph; and to fuse the execution instruction sequences corresponding to the multiple computing subgraphs in the computing graph to determine the executable program file of the model.

[0126] In one embodiment, the compilation module 12 is further specifically used to obtain multiple execution instruction sequences corresponding to the target computation subgraph under multiple computation task parallelisms; determine the target execution instruction sequence corresponding to the target computation subgraph based on the running performance of the executor when executing the multiple execution instruction sequences respectively; and fuse the target execution instruction sequences corresponding to the multiple computation subgraphs to determine the executable program file of the model.

[0127] In one embodiment, the compilation module 12 is further specifically used to respectively determine the distances between the multiple computational subgraphs and the initial computational subgraph; group the multiple computational subgraphs according to the distances, wherein the distances corresponding to the computational subgraphs in the same group of computational subgraphs are the same; and insert a global synchronization instruction after the execution instruction sequence corresponding to each group of computational subgraphs to determine the executable program file of the model.

[0128] In the model compilation solution provided in the embodiment of the present application, execution instructions are optimized and compiled for the computing tasks related to memory-intensive operators in the computation subgraph corresponding to the model. When compiling the model to be compiled, the multiple computation subgraphs contained in the computation graph corresponding to the model are compiled separately. The computation subgraphs can be divided into two categories: one is the computation subgraph corresponding to memory-intensive operators, and the other is the computation subgraph corresponding to computation-intensive operators. In the embodiment of the present application, compilation optimization is performed on the computation subgraph corresponding to the memory-intensive operators. Specifically, when compiling a target computation subgraph containing multiple memory-intensive operators and corresponding data, multiple computation tasks that each thread needs to execute are determined based on multiple threads set in the model's executor (such as a GPU) and the computation task parallelism of each thread. The multiple computation tasks that each thread needs to execute are then grouped to determine multiple groups of computation tasks that any one of the multiple threads (referred to as a target thread) needs to execute serially. Each group of computation tasks contains multiple computation tasks, each of which refers to a task that sequentially uses multiple memory-intensive operators to compute corresponding data. The computation task parallelism indicates the number of computation tasks that each thread can execute in parallel. Then, for any group of computation tasks in the target thread, the multiple computation tasks contained in any group of computation tasks are sequentially rearranged based on the computation dependencies of the multiple memory-intensive operators to obtain multiple rearranged computation tasks. Based on the multiple rearranged computation tasks, an execution instruction sequence corresponding to the target thread and any group of computation tasks is generated. The rearrangement is to arrange different computation tasks corresponding to the same memory-intensive operator in parallel. Finally, based on the execution instruction sequence corresponding to the target thread and any group of computing tasks, the executable program file of the executor to execute the model is determined, wherein the executable program file contains the execution instruction sequence corresponding to each of the multiple computing subgraphs contained in the computing graph, that is, the complete execution instructions of the model are contained in the executable program file, and the executable program file only needs to be provided to the executor once.

[0129] In this embodiment, by arranging in parallel the different computing tasks corresponding to the same memory-intensive operator in each group of computing tasks that the thread needs to execute, the resulting execution instruction sequence has a high degree of instruction parallelism. When the executable program file is finally generated, it can send and execute multiple execution instructions in parallel to simultaneously perform parallel calculations on different computing tasks corresponding to the same memory-intensive operator. This can improve the running efficiency of the executable program file while keeping the number of threads in the executor unchanged, and make full use of the resources of the executor.

[0130] The communication device shown in FIG8 can execute the various steps executed by the communication system in the aforementioned embodiment. For the parts not described in detail in this embodiment, reference can be made to the relevant description of the aforementioned embodiment and will not be repeated here.

[0131] In one possible design, the structure of the QR code recognition device shown in FIG8 can be implemented as an electronic device. As shown in FIG9 , the electronic device may include: a memory 21, a processor 22, and a communication interface 23. The memory 21 stores executable code. When the executable code is executed by the processor 22, the processor 22 can at least implement the model compilation method provided in the aforementioned embodiment.

[0132] In addition, an embodiment of the present application provides a non-transitory machine-readable storage medium, on which executable code is stored. When the executable code is executed by a processor of an electronic device, the processor can at least implement the model compilation method provided in the aforementioned embodiment.

[0133] The device embodiments described above are merely illustrative, wherein the network elements described as separate components may or may not be physically separate. Some or all of these modules may be selected based on actual needs to achieve the objectives of this embodiment. Persons of ordinary skill in the art can understand and implement these embodiments without inventive effort.

[0134] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by adding a necessary general hardware platform, and of course can also be implemented by a combination of hardware and software. Based on this understanding, the above technical solution, or the part that contributes to the prior art, can be embodied in the form of a computer product. The present application can take the form of a computer program product implemented on one or more computer storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer program code.

[0135] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims

1. A model compilation method, the method include: Obtain a target computation subgraph in a computation graph corresponding to a model to be compiled, wherein the target computation subgraph includes a plurality of memory-intensive operators and corresponding data, and the target computation subgraph is a computation subgraph included in the computation graph; According to the multiple threads set in the executor of the model and the computing task parallelism of each thread, determine multiple groups of computing tasks that the target thread needs to execute serially, wherein each group of computing tasks includes multiple computing tasks, each computing task refers to a task that sequentially uses the multiple memory-intensive operators to calculate corresponding data, the computing task parallelism indicates the number of computing tasks that each thread can execute in parallel, and the target thread is any one of the multiple threads; For any group of computing tasks, according to the computing dependencies of the multiple memory-intensive operators, multiple computing tasks included in the any group of computing tasks are sequentially rearranged to obtain multiple rearranged computing tasks, wherein the rearrangement enables different computing tasks corresponding to the same memory-intensive operator to be arranged in parallel; Generating, according to the rearranged plurality of computing tasks, an execution instruction sequence corresponding to the target thread and any one group of computing tasks; According to the execution instruction sequence corresponding to the target thread and any group of computing tasks, the executable program file for the executor to execute the model is determined, and the executable program file contains the execution instruction sequence corresponding to each of the multiple computing subgraphs included in the computing graph.

2. The method according to claim 1, further comprising: include: A first data copy instruction is inserted before the execution instruction sequence corresponding to the target thread and any one group of computing tasks, wherein the first data copy instruction is used to copy the data corresponding to the next group of computing tasks of the any one group of computing tasks from the off-chip storage space of the executor to the first buffer of the on-chip storage space of the executor, so that the corresponding data can be read from the first buffer when executing the next group of computing tasks.

3. The method according to claim 2, further comprising: include: If any one of the groups of computing tasks is the first computing task among the multiple groups of computing tasks, a second data copy instruction is inserted before the first data copy instruction, and the second data copy instruction is used to copy the data corresponding to any one of the groups of computing tasks from the off-chip storage space of the executor to the second buffer of the on-chip storage space of the executor.

4. According to the method described in claim 3, the data corresponding to the next group of computing tasks copied to the first buffer is the data corresponding to the first memory-intensive operator in the next group of computing tasks; the data corresponding to any group of computing tasks copied to the second buffer is the data corresponding to the first memory-intensive operator in any group of computing tasks.

5. The method according to any one of claims 1 to 4, wherein the executable program file for executing the model by the executor is determined according to the execution instruction sequence corresponding to the target thread and any one of the computing tasks. include: Determine the execution instruction sequence corresponding to the target computing subgraph according to the execution instruction sequences corresponding to the multiple groups of computing tasks respectively executed by the multiple threads under the target computing subgraph; The execution instruction sequences respectively corresponding to the multiple computational subgraphs in the computational graph are integrated to determine the executable program file of the model.

6. The method according to claim 5, further comprising: include: Obtain multiple execution instruction sequences corresponding to the target computing subgraph under multiple computing task parallelisms; Determine a target execution instruction sequence corresponding to the target computation subgraph according to the operating performance of the executor when executing the multiple execution instruction sequences respectively; The fusing of the execution instruction sequences respectively corresponding to the multiple computational subgraphs in the computational graph to determine the executable program file of the model includes: The target execution instruction sequences respectively corresponding to the multiple computational subgraphs are integrated to determine the executable program file of the model.

7. The method according to claim 5, wherein the execution instruction sequences corresponding to the plurality of computational subgraphs in the computational graph are integrated to determine the executable program file of the model. include: Determining respectively the distances of the plurality of computation subgraphs to the initial computation subgraph; Grouping the plurality of computation subgraphs according to the distances, wherein the distances corresponding to the computation subgraphs in the same group of computation subgraphs are the same; A global synchronization instruction is inserted after the execution instruction sequence corresponding to each group of computational subgraphs to determine the executable program file of the model.

8. A model compilation device, include: An acquisition module, used to acquire a target computation subgraph in a computation graph corresponding to a model to be compiled, wherein the target computation subgraph includes a plurality of memory-intensive operators and corresponding data, and the target computation subgraph is a computation subgraph included in the computation graph; A compilation module is used to determine multiple groups of computing tasks that need to be executed serially by a target thread according to multiple threads set in an executor of the model and the computing task parallelism of each thread, wherein each group of computing tasks includes multiple computing tasks, each computing task refers to a task that sequentially uses the multiple memory-intensive operators to calculate corresponding data, the computing task parallelism indicates the number of computing tasks that can be executed in parallel by each thread, and the target thread is any one of the multiple threads; for any group of computing tasks, according to the computing dependencies of the multiple memory-intensive operators, the multiple computing tasks included in the any group of computing tasks are sequentially rearranged to obtain multiple rearranged computing tasks, wherein the rearrangement causes different computing tasks corresponding to the same memory-intensive operator to be arranged in parallel; based on the multiple rearranged computing tasks, an execution instruction sequence corresponding to the target thread and the any group of computing tasks is generated; based on the execution instruction sequence corresponding to the target thread and the any group of computing tasks, an executable program file for the executor to execute the model is determined, and the executable program file contains execution instruction sequences corresponding to each of the multiple computing subgraphs contained in the computing graph.

9. An electronic device, include: A memory, a processor, and a communication interface; wherein the memory stores executable code, and when the executable code is executed by the processor, the processor executes the model compilation method according to any one of claims 1 to 7.

10. A non-transitory machine-readable storage medium having executable code stored thereon, and when the executable code is executed by a processor of an electronic device, the processor is caused to execute the model compilation method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Machine learning calculation optimization method and compiler

    CN114580653A

  • Deep learning compiler optimization method for CNN (Convolutional Neural Network) dedicated accelerator

    CN114995823A

  • Neural network model compiling method and device, electronic equipment and storage medium

    CN115829006A

  • Neural network reasoning pipeline multiplexing method based on batch processing

    CN115860066A

  • Model compiling method and device, equipment and storage medium

    CN116755702A