Task execution method, device, apparatus, storage medium, and computer program product
By caching the executed operator sequences in heterogeneous computing devices and searching for consistent or prefixed sequences, task execution instructions are sent directly to the second processor, solving the problems of computation graph compilation time and code migration difficulty, and achieving improved task execution efficiency and efficient resource utilization.
Patent Information
- Application Number
- CN202510679645.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-23
- Publication Date
- 2026-11-24
AI Technical Summary
In heterogeneous computing devices, the compilation of computation graphs takes a long time during the repeated execution of tasks, resulting in accelerator waiting states, wasted computing power, and difficulty in code migration, which affects task execution efficiency and increases labor costs.
By caching the executed operator sequences, and using the cache space to find matching operator sequences or operator sequences with the same prefix, task execution instructions are sent directly to the second processor, reducing the number of times the computation graph is sent and the compilation process, thereby improving task execution efficiency.
This reduces the number of operator deployments and compilation time, lowers development difficulty and manpower costs, improves task execution efficiency, and makes full use of the accelerator's computing resources.
Smart Images

Figure CN123157345A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a task execution method, apparatus, device, storage medium, and computer program product. Background Technology
[0002] Currently, many tasks are performed by heterogeneous computing devices, which typically include a central processing unit (CPU) and one or more accelerators such as a neural network processing unit (NPU) and a graphics processing unit (GPU). Taking a heterogeneous computing device consisting of a CPU and an NPU as an example, the CPU is responsible for interacting with the user to obtain tasks, preprocessing the tasks, and then sending them to the NPU, which is responsible for executing the tasks.
[0003] During task preprocessing, the CPU determines the computation graph (including the operators required to complete the task) based on the task information, compiles the computation graph, and sends the compiled computation graph to the NPU. The NPU executes the task according to the received computation graph, returns the task execution result to the CPU, and the CPU displays the task execution result to the user.
[0004] Many tasks in various scenarios need to be executed repeatedly, such as model training and generation. For the same task, in related technologies, the CPU needs to compile and distribute the computation graph each time it executes the task. However, the compilation of the computation graph is usually time-consuming, impacting task execution efficiency. Furthermore, during the compilation process, the accelerator is in a waiting state, resulting in significant waste of its computing power. In addition, related technologies require both the CPU and the accelerator to support graph compilation functionality, but developing such code is complex; for example, it requires migrating the graph compilation code corresponding to the computation graph to the software framework of other accelerators, a migration process that demands substantial code modifications. Summary of the Invention
[0005] This application provides a task execution method, apparatus, device, storage medium, and computer program product, which can improve task execution efficiency and reduce development difficulty and labor costs. The technical solution is as follows:
[0006] In a first aspect, a task execution method is provided, the method being applied to a first processor, the method comprising:
[0007] A target computation graph for the target task is determined, the target computation graph representing a sequence of target operators, the sequence of target operators including operators required to complete the target task; if a first operator sequence consistent with the target operator sequence exists in the cache space, a task execution instruction is sent to the second processor; wherein, the task execution instruction instructs the second processor to retrieve the first operator sequence from the cache space and execute the operators in the first operator sequence to obtain the execution result of the target task.
[0008] In other words, after determining the target computation graph of the target task, if the first processor has a first operator sequence in its cache that matches the target operator sequence, then the first processor can skip the process of sending down the target computation graph. For target tasks that need to be executed repeatedly, the technical solution of this application can reduce the number of operator sending operations and reduce the time spent on sending operations, thereby reducing the waiting time of the second processor and effectively improving task execution efficiency. Furthermore, this technical solution does not require graph compilation, thus eliminating the need for extensive code modifications to support graph compilation functionality, thereby reducing labor costs and development difficulty, making it easier to implement and more practical.
[0009] The first processor and the second processor can be two processors in a heterogeneous computing device.
[0010] In one possible implementation, the cache space further includes a first parameter segment corresponding to the first operator sequence. The first parameter segment stores parameters required to execute the operators in the first operator sequence. The target computation graph further represents target parameters, including parameters required to execute the operators in the target computation graph. Based on this, before sending the task execution instruction to the second processor, the method further includes: updating the parameters in the first parameter segment according to the target parameters. The second processor is then used to execute the operators in the first operator sequence according to the parameters in the first parameter segment. That is, for a task that requires parameter updates, after the first processor updates the parameters, it can instruct the second processor to execute the task according to the updated parameters.
[0011] There are two ways to find an operator sequence that matches the target operator sequence from the cache space.
[0012] In the first implementation, after determining the target computation graph of the target task, the method further includes: searching for an operator sequence in the cache space that is the same as the target operator sequence; if an operator sequence that is the same as the target operator sequence is found, determining that there exists a first operator sequence in the cache space that is consistent with the target operator sequence.
[0013] In other words, the first operator sequence must be exactly the same as the target operator sequence. After finding an operator sequence that is exactly the same as the target operator sequence, the first processor sends the task execution instruction to the second processor. It should be understood that in this implementation, "consistent with the target operator sequence" means "identical to the target operator sequence".
[0014] In the second implementation, after determining the target computation graph of the target task, the method further includes: searching for an operator sequence in the cache space whose prefix is the same as the target prefix, wherein the target prefix includes the first N operators in the target operator sequence, and N is less than the total number of operators in the target operator sequence and is a positive integer; if an operator sequence whose prefix is the same as the target prefix is found, it is determined that there exists a first operator sequence in the cache space that is consistent with the target operator sequence.
[0015] In other words, without comparing the complete operator sequence, as long as the first operator sequence with the same prefix is found, the first processor can send the task execution instruction to the second processor. It should be understood that in this implementation, "consistent with the target operator sequence" means "having the same prefix as the target operator sequence".
[0016] In one possible implementation, after finding an operator sequence whose prefix is the same as the target prefix, the method further includes: if a difference is detected between a first subsequence and a target subsequence, sending an execution interrupt instruction to a second processor, wherein the first subsequence is an operator sequence in the first operator sequence excluding the target prefix, and the target subsequence is an operator sequence in the target operator sequence excluding the target prefix, and the execution interrupt instruction instructs the second processor to interrupt the execution operation on the operators in the first operator sequence.
[0017] That is, although the first operator sequence and the target operator sequence have the same prefix, if the remaining operators are different, then the execution result obtained by the second processor from executing the first operator sequence is not the execution result of the target task. If the second processor continues to execute the first operator sequence, it will get an incorrect execution result. Therefore, it is necessary to interrupt the second processor's execution operation on the operators in the first operator sequence in time.
[0018] In one possible implementation, after sending the execution interrupt instruction to the second processor, the method further includes: sending the target computation graph to the second processor to instruct the second processor to execute operators in the target computation graph.
[0019] In other words, since the first operator sequence in the cache space is actually different from the target operator sequence, the first processor needs to perform a computation graph distribution operation so that the second processor can correctly execute the target task.
[0020] The above describes two implementations for finding an operator sequence in the cache that matches the target operator sequence. The first implementation ensures that the second processor correctly executes the target task, preventing interruptions to the second processor's execution of the first operator sequence (described in detail later). The second implementation, as an execution prediction method, improves search efficiency, thereby improving task execution efficiency. In rare cases, it may require interrupting the second processor's execution of the first operator sequence, but the probability is low, so the impact on overall performance is minimal and negligible.
[0021] The above describes the processing flow of the first processor when an operator sequence identical to the target operator sequence exists in the cache space. In one possible implementation, the method further includes: if no operator sequence identical to the target operator sequence exists in the cache space, then sending the target computation graph to the second processor to instruct the second processor to execute the operators in the target computation graph.
[0022] In one possible implementation, the target computation graph further characterizes target parameters, which include parameters required to execute operators in the target computation graph; the step of sending the target computation graph to the second processor to instruct the second processor to execute operators in the target computation graph includes: sending the target operator sequence and target parameters to the second processor to instruct the second processor to execute operators in the target operator sequence according to the target parameters.
[0023] In one possible implementation, the first processor is a CPU.
[0024] In one possible implementation, the second processor is an NPU or a GPU.
[0025] Secondly, a task execution method is provided, the method being applied to a second processor, the method comprising:
[0026] Receive a task execution instruction sent by a first processor; based on the task execution instruction, obtain a first operator sequence from the cache space; execute the operators in the first operator sequence to obtain the execution result of the target task.
[0027] In other words, the cache space can be used to cache operator sequences. Based on this, after receiving the task execution instruction, the second processor can retrieve the corresponding first operator sequence from the cache space based on the instruction, thus eliminating the need for the first processor to issue the target computation graph of the target task. That is, the first processor can skip the issuance of the target computation graph. For target tasks that need to be executed repeatedly, the technical solution of this application can reduce the number of operator issuances, thereby reducing the time consumed by the issuance operation, reducing the waiting time of the second processor, and effectively improving task execution efficiency. Furthermore, this technical solution does not require graph compilation, thus eliminating the need for extensive code modifications to support graph compilation functionality, thereby reducing labor costs and development difficulty, making it easier to implement and more practical.
[0028] In one possible implementation, the cache space further includes a first parameter segment corresponding to the first operator sequence, the first parameter segment being used to store parameters required for executing the operators in the first operator sequence; the execution of the operators in the first operator sequence includes: executing the operators in the first operator sequence according to the parameters in the first parameter segment.
[0029] In one possible implementation, the method further includes: during the execution of operators in the first operator sequence, if an execution interrupt instruction sent by the first processor is received, the execution operation of the operators in the first operator sequence is interrupted.
[0030] In one possible implementation, after receiving the execution interrupt instruction sent by the first processor, the method further includes: receiving a target computation graph issued by the first processor, executing operators in the target computation graph to obtain the execution result of the target task; caching the operators in the target computation graph in the cache space, wherein the operators in the target computation graph are arranged in the cache space according to the operator execution order to form a target operator sequence.
[0031] In other words, the second processor can cache the sequence of executed operators according to the order of operator execution, thereby reducing the number of subsequent operations that the first processor needs to send to the corresponding operators.
[0032] In one possible implementation, the target computation graph represents the target operator sequence and target parameters, the target parameters including parameters required to execute the operators in the target computation graph; receiving the target computation graph issued by the first processor and executing the operators in the target computation graph includes: receiving the target operator sequence and the target parameters issued by the first processor, and executing the operators in the target operator sequence according to the target parameters; after receiving the target parameters, the method further includes: setting a target parameter segment corresponding to the target operator sequence in the cache space, the target parameter segment being used to store the parameters required to execute the target operator sequence.
[0033] In one possible implementation, the first processor is a CPU.
[0034] In one possible implementation, the second processor is an NPU or, in another, a GPU.
[0035] Thirdly, a task execution apparatus is provided, which has the function of implementing the task execution method behavior described in the first aspect. The task execution apparatus includes one or more modules for implementing the task execution method provided in the first aspect.
[0036] That is, a task execution device is provided, the device being included in a first processor, the device comprising:
[0037] The first determining module is used to determine the target computation graph of the target task, wherein the target computation graph represents a sequence of target operators, and the sequence of target operators includes the operators required to complete the target task;
[0038] A first sending module is configured to send a task execution instruction to a second processor if a first operator sequence identical to the target operator sequence exists in the cache space; wherein the task execution instruction instructs the second processor to retrieve the first operator sequence from the cache space and execute the operators in the first operator sequence to obtain the execution result of the target task.
[0039] In one possible implementation, the cache space further includes a first parameter segment corresponding to the first operator sequence, the first parameter segment being used to store parameters required to execute the operators in the first operator sequence, and the target computation graph further characterizing target parameters, the target parameters including parameters required to execute the operators in the target computation graph; the apparatus further includes:
[0040] The parameter update module is used to update the parameters in the first parameter segment according to the target parameters before sending the task execution instruction to the second processor. The second processor is used to execute the operators in the first operator sequence according to the parameters in the first parameter segment.
[0041] In one possible implementation, the device further includes:
[0042] The first search module is used to search for an operator sequence that is the same as the target operator sequence from the cache space after the target computation graph of the target task is determined;
[0043] The second determining module is used to determine, when an operator sequence identical to the target operator sequence is found, that a first operator sequence identical to the target operator sequence exists in the cache space.
[0044] In one possible implementation, the device further includes:
[0045] The second search module is used to search for an operator sequence with the same prefix as the target prefix from the cache space after the target computation graph of the target task is determined. The target prefix includes the first N operators in the target operator sequence, where N is less than the total number of operators in the target operator sequence and is a positive integer.
[0046] The third determining module is used to determine, when an operator sequence with the same prefix as the target prefix is found, that there exists a first operator sequence in the cache space that is consistent with the target operator sequence.
[0047] In one possible implementation, the device further includes:
[0048] The second sending module is configured to send an execution interrupt instruction to the second processor after finding an operator sequence whose prefix is the same as the target prefix, and if it detects that the first subsequence is different from the target subsequence. The first subsequence is the operator sequence in the first operator sequence excluding the target prefix, and the target subsequence is the operator sequence in the target operator sequence excluding the target prefix. The execution interrupt instruction instructs the second processor to interrupt the execution operation of the operators in the first operator sequence.
[0049] In one possible implementation, the device further includes:
[0050] The third sending module is used to send the target computation graph to the second processor after sending an execution interrupt instruction to the second processor, so as to instruct the second processor to execute the operators in the target computation graph.
[0051] In one possible implementation, the device further includes:
[0052] The fourth sending module is used to send the target computation graph to the second processor if there is no operator sequence in the cache space that matches the target operator sequence, so as to instruct the second processor to execute the operator in the target computation graph.
[0053] In one possible implementation, the target computation graph further characterizes target parameters, which include parameters required to execute operators in the target computation graph;
[0054] The fourth sending module is specifically used for:
[0055] The target operator sequence and target parameters are sent to the second processor to instruct the second processor to execute the operators in the target operator sequence according to the target parameters.
[0056] In one possible implementation, the first processor is a CPU.
[0057] In one possible implementation, the second processor is an NPU or a GPU.
[0058] Fourthly, a task execution apparatus is provided, which has the function of implementing the task execution method behavior described in the second aspect above. The task execution apparatus includes one or more modules for implementing the task execution method provided in the second aspect above.
[0059] That is, a task execution device is provided, the device being included in a second processor, the device comprising:
[0060] The first receiving module is used to receive task execution instructions sent by the first processor;
[0061] The acquisition module is used to acquire the first operator sequence from the cache space based on the task execution instruction;
[0062] The execution module is used to execute the operators in the first operator sequence to obtain the execution result of the target task.
[0063] In one possible implementation, the cache space further includes a first parameter segment corresponding to the first operator sequence, the first parameter segment being used to store parameters required to execute the operators in the first operator sequence;
[0064] The execution module is specifically used for:
[0065] The operators in the first operator sequence are executed according to the parameters in the first parameter segment.
[0066] In one possible implementation, the device further includes:
[0067] An execution interrupt module is used to interrupt the execution of operators in the first operator sequence if an execution interrupt instruction sent by the first processor is received during the execution of operators in the first operator sequence.
[0068] In one possible implementation, the device further includes:
[0069] The second receiving module is used to receive the target computation graph sent by the first processor;
[0070] The execution module is further configured to execute operators in the target computation graph to obtain the execution result of the target task;
[0071] A caching module is used to cache the operators in the target computation graph in the cache space, wherein the operators in the target computation graph are arranged in the cache space according to the operator execution order to form a target operator sequence.
[0072] In one possible implementation, the target computation graph represents the target operator sequence and target parameters, the target parameters including parameters required to execute the operators in the target computation graph;
[0073] The second receiving module is specifically used to: receive the target operator sequence and the target parameters sent by the first processor;
[0074] The execution module is specifically used to: execute the operators in the target operator sequence according to the target parameters;
[0075] The device further includes:
[0076] The setting module is used to set the target parameter segment corresponding to the target operator sequence in the cache space, and the target parameter segment is used to store the parameters required to execute the target operator sequence.
[0077] In one possible implementation, the first processor is a CPU.
[0078] In one possible implementation, the second processor is an NPU or a GPU.
[0079] Fifthly, a heterogeneous computing device is provided, the heterogeneous computing device including a first processor and a second processor;
[0080] The first processor is used to execute the steps of the task execution method described in the first aspect above;
[0081] The second processor is used to execute the steps of the task execution method described in the second aspect above.
[0082] A sixth aspect provides a computer device comprising a processor and a memory, the memory being configured to store a program for executing the task execution method provided in the first and / or second aspects, and to store data relating to implementing the task execution method provided in the first and / or second aspects. The processor is configured to execute the program stored in the memory.
[0083] In one possible implementation, the computer device may further include a communication bus for establishing a connection between the processor and the memory.
[0084] In a seventh aspect, a computer-readable storage medium is provided, wherein instructions are stored therein, which, when executed on a computer, cause the computer to perform the task execution method described in the first or second aspect above.
[0085] Eighthly, a computer program product containing instructions is provided, which, when run on a computer, causes the computer to perform the task execution method described in the first or second aspect above.
[0086] The technical effects achieved by the third to eighth aspects mentioned above are similar to those achieved by the corresponding technical means in the first and second aspects, and will not be repeated here. Attached Figure Description
[0087] Figure 1 This is a schematic diagram of a task execution method in related technologies;
[0088] Figure 2 This is a schematic diagram of the structure of a computer device provided in an embodiment of this application;
[0089] Figure 3 This is a flowchart of a task execution method provided in an embodiment of this application;
[0090] Figure 4 This is a flowchart of another task execution method provided in an embodiment of this application;
[0091] Figure 5 This is a hardware and software system architecture diagram of a heterogeneous computing device provided in an embodiment of this application;
[0092] Figure 6 This is a flowchart of yet another task execution method provided in the embodiments of this application;
[0093] Figure 7 This is a flowchart of yet another task execution method provided in the embodiments of this application;
[0094] Figure 8 This is a flowchart of yet another task execution method provided in the embodiments of this application;
[0095] Figure 9 This is a schematic diagram of the structure of a task execution device provided in an embodiment of this application;
[0096] Figure 10 This is a schematic diagram of another task execution device provided in an embodiment of this application;
[0097] Figure 11 This is a schematic diagram of the structure of another task execution device provided in the embodiments of this application;
[0098] Figure 12 This is a schematic diagram of the structure of another task execution device provided in the embodiments of this application. Detailed Implementation
[0099] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the implementation methods of this application will be further described in detail below with reference to the accompanying drawings.
[0100] To facilitate understanding, some terms involved in the embodiments of this application will be explained first.
[0101] Heterogeneous computing devices: also known as heterogeneous acceleration devices or heterogeneous accelerators, typically include one or more CPUs and one or more accelerators (also known as dedicated processors, such as NPUs, GPUs, etc.).
[0102] Heterogeneous computing system: includes multiple heterogeneous computing devices, or may include a single heterogeneous computing device.
[0103] Operator dispatch: The process by which the CPU dispatches operators to the NPU. An operator is a computational operation required to complete a task.
[0104] Computational graph: Also known as a data flow graph, it represents a sequence of operators and parameters. The sequence of operators includes the operators required to complete a task. Each operator sequence also corresponds to a parameter. Parameters include the data carried by the connecting edges of the operators (also called operator nodes or computation nodes) in the computational graph, used for operator processing or fed back by the operators. In other words, parameters include the necessary parameters for executing the operators in the computational graph.
[0105] Operator segment: also known as operator memory segment, is a memory segment used to store operators (which can be binary executable programs).
[0106] Parameter segment: also known as the parameter memory segment, is used to store the parameters required to execute the operator.
[0107] Next, the application scenarios and implementation environment of the embodiments of this application will be introduced.
[0108] This application relates to the field of operator execution acceleration in heterogeneous computing systems. Currently, when computing tasks (hereinafter referred to as tasks) are executed in heterogeneous computing systems, there is a problem of not being able to fully utilize the computing power of heterogeneous computing devices. The problem mainly stems from insufficient coordination and scheduling between different processors, resulting in the underutilization of the computing power of heterogeneous computing devices. To fully utilize the computing power of heterogeneous computing devices, related technologies generally start with graph scheduling, reducing the scheduling overhead and shortening the scheduling sequence between different processors.
[0109] Figure 1 This is a schematic diagram of a task execution method in related technologies. Related technologies are as follows... Figure 1As shown in (a), taking a task's computation graph comprising four sequential operators (A, B, C, D) as an example, the CPU sequentially issues these four operators one by one. This operator issuance method can be called single-operator issuance mode. Each time an operator is issued, the GPU immediately executes that operator. Figure 1 As can be seen from the time represented by the length of the square block, the time it takes for the GPU to execute an operator is usually less than the time it takes for the CPU to issue an operator. Therefore, there are gaps (also known as bubbles) in the process of the GPU executing these four operators. During these gaps, the GPU needs to wait for the operators to be issued, and the GPU's computing resources are not fully utilized. Furthermore, many tasks in many scenarios need to be executed repeatedly. Each time a task is executed, the CPU needs to issue multiple operators for that task to the GPU sequentially. Thus, there will be many unused gaps on the GPU side.
[0110] Related technologies, such as Figure 1 As shown in (b), taking a task's computation graph consisting of four sequential operators (A, B, C, D) as an example, the CPU uses graph optimization to compile and distribute the entire computation graph, rather than distributing it operator by operator, thus requiring only one distribution. After the computation graph is distributed, the GPU executes the operators in the computation graph in batches without any gaps, fully utilizing the GPU's computing resources.
[0111] Depend on Figure 1 It is evident that, compared to related technology one, related technology two, through graph compilation and whole-graph distribution, reduces gaps on the accelerator side, saves task execution time, and improves task execution efficiency. However, a long graph compilation time is required before the computation graph is distributed, meaning graph compilation is time-consuming. During graph compilation, the accelerator remains in a waiting state, resulting in some waste of accelerator computing power. Furthermore, related technology two requires both the CPU and the accelerator to support graph compilation-related functions, and the code development for graph compilation-related functions is quite difficult. For example, it requires migrating the graph compilation code corresponding to the computation graph to the software framework of other accelerators, and the migration process requires a significant amount of code modification. Therefore, related technology two is difficult to develop, requires explicit code modification, increases manpower costs, and the cost of migrating the graph compilation code corresponding to the computation graph across different accelerator software frameworks is very high.
[0112] Furthermore, in related technologies one and two, for tasks that need to be executed repeatedly, the CPU performs the same process each time the task is executed, such as needing to perform a distribution operation (or graph compilation and distribution operation). These are repetitive operations, which waste time and thus affect execution efficiency.
[0113] Based on this, embodiments of this application provide a task execution method that does not require graph compilation, thereby avoiding the problems of graph compilation. Furthermore, it can cache the sequence of executed operators, thereby reducing the number of operator issuances and saving operator issuance time, thus improving task execution efficiency.
[0114] The task execution method provided in this application can be applied to heterogeneous computing devices. The steps of the method are executed by a first processor (such as a CPU) and a second processor (such as an NPU or GPU) in the heterogeneous computing device. This application does not limit the physical location of the first and second processors. The first and second processors can be located in a single computer device, which is a heterogeneous computing device. Alternatively, the first and second processors can be located in two separate computer devices, where some or all of the devices in these two computer devices constitute a heterogeneous computing device.
[0115] Figure 2 This is a schematic diagram of the structure of a computer device provided in an embodiment of this application. In some embodiments, the computer device may also be referred to as a computing device. In some embodiments, the computer device is a heterogeneous computing device, which includes one or more processors 201, a communication bus 202, a memory 203, and one or more communication interfaces 204.
[0116] The processor 201 may be a CPU, NPU, GPU, network processor (NP), microprocessor, or one or more integrated circuits for implementing the solutions of this application, such as application-specific integrated circuits (ASICs), programmable logic devices (PLDs), or combinations thereof. In some embodiments, the PLD may be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), generic array logic (GAL), or any combination thereof.
[0117] The communication bus 202 is used to transmit information between the aforementioned components. In some embodiments, the communication bus 202 is divided into an address bus, a data bus, a control bus, etc. For ease of illustration, Figure 2 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.
[0118] The memory 203 may be a read-only memory (ROM), random access memory (RAM), electrically erasable programmable read-only memory (EEPROM), optical disc (including compact disc read-only memory (CD-ROM), compressed optical disc, laser disc, digital versatile optical disc, Blu-ray disc, etc.), magnetic disk storage medium, or other magnetic storage device, or any other medium capable of carrying or storing desired program code in the form of instructions or data structures and accessible by a computer, but not limited thereto. The memory 203 exists independently and is connected to the processor 201 via the communication bus 202, or the memory 203 is integrated with the processor 201.
[0119] Communication interface 204 uses any transceiver-like device for communicating with other devices or communication networks. Communication interface 204 includes a wired communication interface and / or a wireless communication interface. The wired communication interface may be, for example, an Ethernet interface. The Ethernet interface can be an optical interface, an electrical interface, or a combination thereof. The wireless communication interface may be a wireless local area network (WLAN) interface, a cellular network communication interface, or a combination thereof.
[0120] In some embodiments, the computer device includes multiple processors, such as Figure 2 The processors 201 and 205 shown are illustrated. Each of these processors is either a single-core processor or a multi-core processor. Here, a processor refers to one or more devices, circuits, and / or processing cores used to process data (such as computer program instructions).
[0121] As an example, processor 201 includes two CPUs, such as Figure 2 As shown, CPU0 and CPU1, processor 205 includes two NPUs, such as Figure 2 The NPU0 and NPU1 are shown.
[0122] As one embodiment, the computer device also includes an output device 206 and an input device 207. The output device 206 communicates with the processor 201 and can display information in various ways. For example, the output device 206 may be a liquid crystal display (LCD), a light-emitting diode (LED) display device, a cathode ray tube (CRT) display device, or a projector. The input device 207 communicates with the processor 201 and can receive user input in various ways. For example, the input device 207 may be a mouse, keyboard, touchscreen device, or sensing device.
[0123] In some embodiments, memory 203 is used to store program code 210 for executing the scheme of this application, and processor 201 and / or processor 205 are capable of executing the program code 210 stored in memory 203. The program code includes one or more software modules, and the computer device can implement the following through processor 201 and / or processor 205 and the program code 210 in memory 203. Figure 3 The task execution method provided in the embodiment.
[0124] The business scenarios and implementation environments described in the embodiments of this application are for the purpose of more clearly illustrating the technical solutions of the embodiments of this application, and do not constitute a limitation on the technical solutions provided in the embodiments of this application. As those skilled in the art will know, with the evolution of computing architecture and the emergence of new business scenarios, the technical solutions provided in the embodiments of this application are also applicable to similar technical problems.
[0125] Next, the task execution method provided in the embodiments of this application will be described.
[0126] Figure 3 This is a flowchart illustrating a task execution method provided in an embodiment of this application. The method is applied to a first processor in a heterogeneous computing device, which further includes a second processor. The heterogeneous computing device can be... Figure 2 The computer device shown. The first processor can be a CPU, and the second processor can be an NPU or GPU, etc. This also applies to existing and future processors. Please refer to [reference needed]. Figure 3 The method includes the following steps.
[0127] Step 301: The first processor determines the target computation graph of the target task. The target computation graph represents the target operator sequence, which includes the operators required to complete the target task.
[0128] The target task is the task that needs to be executed currently, and it can be a recurring task. The embodiments of this application can improve the execution efficiency of tasks that need to be executed repeatedly and make full use of the computing resources of the second processor. Of course, since tasks may be random and diverse, in some cases, the task that needs to be executed currently (i.e., the target task) may only need to be executed once.
[0129] The target task can be a user-triggered task or a system-generated task; this application embodiment does not limit this. The target task can be a training task of a deep learning model (such as a matrix calculation task), or an inference task, such as a generation task. The target task can also be other possible tasks; this application embodiment does not limit this.
[0130] The first processor can acquire task information of the target task and determine the target computation graph of the target task based on the task information. There are various ways to determine the target computation graph, and the embodiments of this application do not limit this.
[0131] The target computation graph represents the target operator sequence, which includes the operators required to complete the target task. The first processor can determine the target operator sequence represented by the target computation graph.
[0132] As an example, the operators in the target operator sequence are arranged in the order of operator execution. For a target computation graph, the execution order of the multiple operators it includes can be one or more, so the target operator sequence may have one or more.
[0133] In one possible implementation, the target computation graph also represents target parameters, which include parameters required to execute operators in the target computation graph. For target tasks that need to be executed repeatedly, the target parameters may be different each time they are executed, or they may be the same; this application does not limit this.
[0134] In the embodiments of this application, the first processor may be a CPU or other possible processor, and there is no limitation thereto.
[0135] Step 301 can be completed in user space. For example, the first processor, at the application layer in user space, generates the target computation graph based on the program code of the target task.
[0136] Step 302: If a first operator sequence that matches the target operator sequence exists in the cache space, the first processor sends a task execution instruction to the second processor; wherein, the task execution instruction instructs the second processor to retrieve the first operator sequence from the cache space and execute the operators in the first operator sequence to obtain the execution result of the target task.
[0137] As can be seen from the above, the embodiments of this application reduce the number of operator issuances by caching the sequence of executed operators. Based on this, the embodiments of this application provide a cache space for caching the sequence of executed operators.
[0138] After determining the target operator sequence, the first processor can search for an operator sequence that matches the target operator sequence in the cache space. If a first operator sequence that matches the target operator sequence exists in the cache space, the first processor sends a task execution instruction to the second processor, that is, skips the operator distribution operation.
[0139] Among them, finding an operator sequence that matches the target operator sequence from the cache space includes at least the following two implementation methods.
[0140] In the first implementation, the first processor searches for an operator sequence in the cache space that is the same as the target operator sequence. If an operator sequence that is the same as the target operator sequence is found, it is determined that there is a first operator sequence in the cache space that is consistent with the target operator sequence.
[0141] In other words, the first operator sequence must be exactly the same as the target operator sequence. After finding an operator sequence that is exactly the same as the target operator sequence, the first processor sends the task execution instruction to the second processor. It should be understood that in this implementation, "consistent with the target operator sequence" means "identical to the target operator sequence".
[0142] If there is one target operator sequence, the first processor simply compares this target operator sequence with the operator sequences in the cache space. In this case, if a first operator sequence exists, then there is one first operator sequence.
[0143] When there are multiple target operator sequences, the first processor may need to compare some or all of these target operator sequences with the operator sequences in the cache space. For example, it may compare them sequentially, ending the search when a first operator sequence identical to one of the target operator sequences is found; in this case, there is one first operator sequence. Alternatively, it may compare them in parallel, ending the search when a first operator sequence identical to one or more of the target operator sequences is found; in this case, there is one first operator sequence, or multiple candidate first operator sequences. When there are multiple candidate first operator sequences, the first processor may randomly or according to other rules select one as the found first operator sequence.
[0144] In the second implementation, the first processor searches for an operator sequence in the cache space whose prefix is the same as the target prefix. The target prefix includes the first N operators in the target operator sequence, where N is less than the total number of operators in the target operator sequence and is a positive integer. If an operator sequence whose prefix is the same as the target prefix is found, it is determined that there is a first operator sequence in the cache space that is consistent with the target operator sequence.
[0145] In other words, without comparing the complete operator sequence, as long as the first operator sequence with the same prefix is found, the first processor can send the task execution instruction to the second processor. It should be understood that in this implementation, "consistent with the target operator sequence" means "having the same prefix as the target operator sequence".
[0146] If there is one target operator sequence, the first processor simply compares the target prefix of this target operator sequence with the prefix of the operator sequence in the cache space. In this case, if a first operator sequence exists, then there is one first operator sequence.
[0147] When there are multiple target operator sequences, the first processor may need to compare the target prefixes of some or all of the target operator sequences with the prefixes of the operator sequences in the cache space. For example, it may compare them sequentially with the target prefixes of these multiple target operator sequences. The search ends when a first operator sequence with the same prefix as the target prefix of one of the target operator sequences is found. In this case, there is one first operator sequence. Alternatively, it may compare them in parallel with the target prefixes of these multiple target operator sequences. The search ends when a first operator sequence with the same prefix as the target prefix of one or more of the target operator sequences is found. In this case, there is one first operator sequence, or there may be multiple candidate first operator sequences. When there are multiple candidate first operator sequences, the first processor may randomly or according to other rules select one first operator sequence as the found first operator sequence.
[0148] The second implementation method can be achieved through prefix matching, which will not be discussed in detail.
[0149] The number N of operators included in the target prefix can be flexibly set according to the actual situation, and this application embodiment does not limit it. For example, N can be set to a fixed value, or N can be set to P% of the length of the target operator sequence.
[0150] The above describes two implementations for finding an operator sequence in the cache that matches the target operator sequence. The first implementation ensures that the second processor correctly executes the target task, preventing interruptions to the second processor's execution of the first operator sequence (described in detail later). The second implementation, as an execution prediction method, improves search efficiency, thereby improving task execution efficiency. In rare cases, it may require interrupting the second processor's execution of the first operator sequence, but the probability is low, so the impact on overall performance is minimal and negligible.
[0151] As mentioned above, the target operator sequence also corresponds to target parameters. Accordingly, the cache space can cache not only the operator sequence itself but also the parameters corresponding to the operator sequence. Based on this, the cache space can also include a first parameter segment corresponding to the first operator sequence, which stores the parameters required to execute the operators in the first operator sequence. Therefore, if a first operator sequence identical to the target operator sequence exists in the cache space, the first processor can update the parameters in the first parameter segment according to the target parameters, and the second processor can then execute the operators in the first operator sequence according to the parameters in the first parameter segment.
[0152] In one possible implementation, each operator sequence in the cache space corresponds to a sequence identifier (referred to as identifier), different operator sequences correspond to different identifiers, and the task execution instruction can carry the identifier of the first operator sequence.
[0153] In one possible implementation, each parameter segment in the cache space corresponds to a parameter segment identifier (referred to as identifier), and different parameter segments correspond to different identifiers. The task execution instruction can carry the identifier of the first parameter segment.
[0154] That is, the task execution instruction can carry the identifier of the first operator sequence and / or the identifier of the first parameter segment.
[0155] After the first processor sends a task execution instruction to the second processor, the second processor can retrieve the first operator sequence from the cache space based on the task execution instruction and execute the operators in the first operator sequence to obtain the execution result of the target task.
[0156] For example, the second processor can obtain the first operator sequence from the cache space and execute the operators in the first operator sequence according to the parameters of the first parameter segment corresponding to the first operator sequence in the cache space.
[0157] If the first operator sequence is the same as the target operator sequence, the second processor can execute the operators in the first operator sequence to obtain the execution result of the target task.
[0158] When the first operator sequence is an operator sequence whose prefix is the same as the target prefix, during the process of the first processor sending the task execution instruction and the second processor executing the operators in the first operator sequence, the first processor can continue to detect whether there is a difference between the first subsequence and the target subsequence. The first subsequence is the operator sequence in the first operator sequence excluding the target prefix, and the target subsequence is the operator sequence in the target operator sequence excluding the target prefix.
[0159] If a difference is detected between the first subsequence and the target subsequence, the first processor sends an execution interrupt instruction to the second processor. This instruction instructs the second processor to interrupt the execution of the operators in the first operator sequence. In other words, although the first operator sequence and the target operator sequence share the same prefix, the remaining operators differ. Therefore, the execution result obtained by the second processor from executing the first operator sequence is not the result of the target task. Continuing to execute the first operator sequence would result in an incorrect execution result; therefore, it is necessary to promptly interrupt the second processor's execution of the operators in the first operator sequence.
[0160] After sending an execution interrupt instruction to the second processor, the first processor sends the target computation graph to the second processor, instructing the second processor to execute the operators in the target computation graph. That is, since the first operator sequence in the cache space is actually different from the target operator sequence, it can be basically determined that the target operator sequence has not been executed. Therefore, the first processor needs to perform a computation graph sending operation so that the second processor can correctly execute the target task.
[0161] The above describes the processing flow of the first processor when an operator sequence matching the target operator sequence exists in the cache space. If no operator sequence matching the target operator sequence exists in the cache space, the first processor sends the target computation graph to the second processor, instructing the second processor to execute the operators in the target computation graph. That is, if it has been determined during the search process that the target operator sequence has not been executed, then the first processor needs to perform a computation graph sending operation to ensure that the second processor correctly executes the target task.
[0162] In this embodiment, the process of the first processor sending a target computation graph to the second processor to instruct the second processor to execute the operators in the target computation graph is as follows: the first processor sends a target operator sequence and target parameters to the second processor to instruct the second processor to execute the operators in the target operator sequence according to the target parameters. The specific implementation of the first processor sending the target computation graph can also refer to related technologies, and this embodiment does not limit it.
[0163] As an example, the first processor can sequentially send the operators in the target operator sequence to the second processor. When sending each operator, the corresponding parameters of the target operator are also sent to the second processor to instruct the second processor to execute the operator according to the parameters corresponding to the operator.
[0164] In summary, in this embodiment, after determining the target computation graph of the target task, if the cache space contains a first operator sequence that matches the target operator sequence, the first processor can skip the distribution operation of the target computation graph. For target tasks that need to be executed repeatedly, the technical solution of this embodiment can greatly reduce the time spent on the distribution operation, thereby reducing the waiting time of the second processor and effectively improving task execution efficiency. Furthermore, the technical solution of this embodiment does not require graph compilation, thus eliminating the need for extensive code modifications to support graph compilation functionality, thereby reducing labor costs, making it easier to implement, and more practical.
[0165] Figure 4 This is a flowchart of another task execution method provided in an embodiment of this application. The method is applied to a second processor in a heterogeneous computing device, which also includes a first processor. The heterogeneous computing device can be... Figure 2 The computer device shown. The first processor can be a CPU, and the second processor can be an NPU or GPU, etc., and this also applies to existing and future processors. The first processor can be... Figure 3 The first processor in the embodiment is, that is, Figure 3 Examples and Figure 4 The examples can be used in combination. Figure 3 The content of the embodiments applies to Figure 4 Example, Figure 4 The content of the embodiments also applies to Figure 3 Example. Please refer to the following: Figure 4 The method includes the following steps.
[0166] Step 401: The second processor receives the task execution instruction sent by the first processor.
[0167] Specifically, the task execution instruction instructs the second processor to retrieve the first operator sequence from the cache space and execute the operators in the first operator sequence to obtain the execution result of the target task.
[0168] The task execution command can be Figure 3 The task execution instructions in the embodiment, the timing of the first processor sending the task execution instructions, and the timing of the second processor receiving the task execution instructions can be referred to... Figure 4 The details of the embodiments will not be repeated here.
[0169] Step 402: The second processor executes instructions based on the task and retrieves the first operator sequence from the cache space.
[0170] In one possible implementation, the task execution instructions may carry an identifier of the first operator sequence. The second processor may then retrieve the first operator sequence from the cache space based on the identifier of the first operator sequence.
[0171] The identifier of the first operator sequence can be the memory address of the first operator sequence, and the second processor can directly obtain the first operator sequence from the cache space based on the memory address of the first operator sequence.
[0172] Alternatively, the identifier of the first operator sequence may be another identifier that has a mapping relationship with the memory address of the first operator sequence. The second processor may determine the memory address of the first operator sequence from the mapping relationship based on the identifier of the first operator sequence, and then obtain the first operator sequence from the cache space based on the memory address of the first operator sequence.
[0173] Alternatively, the identifier of the first operator sequence can be any other identifier, without limitation, as long as the first operator sequence can be retrieved from the cache space based on the identifier.
[0174] Depend on Figure 4 As can be seen from the embodiments, the cache space may further include a first parameter segment corresponding to the first operator sequence, which is used to store the parameters required to execute the operators in the first operator sequence. Based on this, the second processor may also obtain the parameters of the first parameter segment from the cache space based on the task execution instructions.
[0175] As an example, the task execution instruction can carry the identifier of the first parameter segment, and the second processor can retrieve the parameters of the first parameter segment from the cache space based on the identifier of the first parameter segment.
[0176] The identifier of the first parameter segment can be the memory address of the first parameter segment. The second processor can directly obtain the parameters in the first parameter segment from the cache space based on the memory address of the first parameter segment.
[0177] Alternatively, the identifier of the first parameter segment may be another identifier that has a mapping relationship with the memory address of the first parameter segment. The second processor may determine the memory address of the first parameter segment from the mapping relationship based on the identifier of the first parameter segment, and then obtain the parameters in the first parameter segment from the cache space based on the memory address of the first parameter segment.
[0178] Alternatively, the identifier for the first parameter segment can be any other identifier, without limitation, as long as the parameters in the first parameter segment can be retrieved from the cache space based on this identifier.
[0179] As another example, the task execution instruction carries the identifier of the first operator sequence but not the identifier of the first parameter segment. The second processor can determine the identifier of the first parameter segment from the mapping relationship between the operator sequence and the parameter segment based on the identifier of the first operator sequence, and then obtain the parameter in the first parameter segment from the cache space based on the identifier of the first parameter segment.
[0180] In another possible implementation, the task execution instruction carries the identifier of the first parameter segment but not the identifier of the first operator sequence. The second processor can determine the identifier of the first operator sequence from the mapping relationship between the operator sequence and the parameter segment based on the identifier of the first parameter segment, and then obtain the first operator sequence from the cache space based on the identifier of the first operator sequence.
[0181] It should be understood that the second processor can retrieve all operators in the first operator sequence in batches from the cache space, and then execute all operators in the first operator sequence in batches through step 503, so that there are no gaps in the execution of the first operator sequence.
[0182] Step 403: The second processor executes the operators in the first operator sequence to obtain the execution result of the target task.
[0183] After obtaining the first operator sequence, the second processor can execute the first operator sequence.
[0184] In this embodiment of the application, the second processor can execute the operators in the first operator sequence according to the parameters in the first parameter segment.
[0185] During the execution of operators in the first operator sequence, if an execution interrupt instruction is received from the first processor, the second processor will interrupt the execution of operators in the first operator sequence. For details, please refer to [link to implementation details]. Figure 4 The details of the embodiments will not be repeated here.
[0186] After receiving the execution interrupt instruction sent by the first processor, the second processor can also receive the target computation graph sent by the first processor, execute the operators in the target computation graph to obtain the execution result of the target task, and can also cache the operators in the target computation graph in the cache space. The operators in the target computation graph are arranged in the cache space according to the operator execution order to form the target operator sequence.
[0187] See Figure 4In this embodiment, the interrupt instruction is sent to the second processor when the first processor detects a difference between the first subsequence and the target subsequence. The first subsequence is the operator sequence in the first operator sequence excluding the target prefix, and the target subsequence is the operator sequence in the target operator sequence excluding the target prefix. Therefore, since the distribution operation of the target computation graph is performed for the first time, the second processor needs to cache the target operator sequence so that the first processor can skip subsequent distribution operations related to the target task.
[0188] The second processor can cache the operators in the target computation graph sequentially according to the execution order of the operators in the target computation graph, thereby caching the target operator sequence in the cache space.
[0189] In this embodiment, the target computation graph represents a target operator sequence and target parameters. The target parameters include parameters required to execute the operators in the target computation graph. Accordingly, the second processor receives the target computation graph from the first processor, and the process of executing the operators in the target computation graph includes: receiving the target operator sequence and target parameters from the first processor, and executing the operators in the target operator sequence according to the target parameters. Furthermore, after receiving the target parameters, the second processor can also set a target parameter segment corresponding to the target operator sequence in the cache space. The target parameter segment is used to store the parameters required to execute the target operator sequence.
[0190] Setting a parameter segment in the cache space can be viewed as a shadow mapping of setting the target parameter in the cache space.
[0191] In summary, in this embodiment, the cache space can be used to cache operator sequences. Therefore, after receiving the task execution instruction, the second processor can retrieve the corresponding first operator sequence from the cache space, thus eliminating the need for the first processor to issue the target computation graph of the target task; that is, the first processor can skip the issuance operation of the target computation graph. For target tasks that need to be executed repeatedly, the technical solution of this embodiment can greatly reduce the time spent on the issuance operation, thereby reducing the waiting time of the second processor and effectively improving task execution efficiency. Furthermore, the technical solution of this embodiment does not require graph compilation, thus eliminating the need for extensive code modifications to support graph compilation functionality, thereby reducing labor costs, making it easier to implement, and more practical.
[0192] To facilitate understanding of the technical solution of the task execution method provided in the above embodiments, the following will be combined with... Figures 5 to 8 Taking the first processor as the CPU and the second processor as the NPU as an example, the task execution method is explained by way of example.
[0193] Figure 5 This is a hardware and software system architecture diagram of a heterogeneous computing device provided in an embodiment of this application. See also... Figure 5 The hardware in this system architecture includes a CPU and an NPU, while the software includes CPU-side user applications, runtime (abbreviated as RT in the diagram), application programming interface (API), driver, driver API, heterogeneous computing units, operator sequence caching module, and operator sequence execution module. The functions of the hardware and software modules are as follows.
[0194] 1. User applications are programs developed by users to perform computational tasks, such as deep learning programs developed based on the Mindspore / PyTorch framework, which are used to generate computational tasks (referred to as tasks).
[0195] 2. runtime is the dynamic library that the Mindspore / pytorch framework depends on, and it is generally used to provide development interfaces for heterogeneous computing devices.
[0196] 3. The driver is the bridge for communication between the CPU and the NPU. It exists on both sides of the CPU. The driver on the CPU side is used to send the CPU's instructions (such as task execution instructions) to the NPU through the driver API. The driver on the NPU side is used to send the NPU's execution results back to the CPU.
[0197] 4. Heterogeneous computing units refer to the physical hardware that actually executes the operators related to the task. For example, a heterogeneous computing unit in an NPU can be an artificial intelligence (AI) core. An NPU typically includes multiple AI cores.
[0198] 5. Operator sequence caching module, used to cache operator sequences executed by heterogeneous computing units over a period of time.
[0199] 6. Operator sequence execution module, which is used to directly send a sequence of operators cached by the operator sequence caching module to the heterogeneous computing unit for execution.
[0200] The operator sequence caching module is a software module. Its cache space can be located in the CPU or the NPU; this embodiment does not limit this. The operator sequence execution module is also a software module. Both the operator sequence caching module and the operator sequence execution module can belong to the CPU or the NPU, or one can belong to the CPU and the other to the NPU. They only need to be able to cooperate with the driver to execute the task execution method provided in this embodiment.
[0201] Figure 5 The logic between the hardware and software shown is as follows.
[0202] Users develop user applications using frameworks such as Mindspore / PyTorch, which rely on the corresponding runtime dynamic libraries of the NPU. When a user triggers a heterogeneous computing device to run their application, the application transforms its computational tasks into a final computation graph (including operator sequences and parameters) through the runtime. The runtime passes the operators in the computation graph to the driver via the runtime API. The driver packages the operators into sub-computational tasks that need to be executed, including the executable code segment and the parameter segment. The driver places the sub-computational tasks into the NPU's hardware execution queue. The heterogeneous computing unit sequentially retrieves the sub-computational tasks from the hardware execution queue and performs the actual computational operations, i.e., executes the corresponding operators. The operator sequence caching module caches operator sequences executed over a period of time. The operator sequence execution module executes a specific operator sequence (e.g., the first operator sequence) cached by the operator sequence caching module according to the CPU's task execution instructions.
[0203] It should be understood that the operations of the runtime passing operators in the computation graph to the driver, the driver wrapping them and placing the sub-computation tasks into the NPU's hardware execution queue, and the heterogeneous computing units sequentially retrieving sub-computation tasks from the hardware execution queue, do not exist in the cache space of the computation. Figure 1 This is performed under the condition of a consistent operator sequence. The computation exists in the cache space. Figure 1 In the case of a consistent operator sequence, these operations are unnecessary. Instead, the operator sequence execution module is directly triggered by the driver to retrieve the relevant computation from the cache space. Figure 1 The driver loads the obtained operator sequence into the NPU's hardware execution queue for execution by heterogeneous computing units.
[0204] Figure 6 This is a flowchart of yet another task execution method provided in an embodiment of this application. See also... Figure 6 In this method, when the CPU first obtains a computation graph (such as a target computation graph), if the cache space does not contain an operator sequence that matches the operator sequence represented by the computation graph, then the computation graph is distributed according to the normal process, for example, according to... Figure 5 One implementation involves placing the computation graph into the NPU's hardware execution queue. The NPU then executes the operators in the hardware execution queue according to a standard process to obtain the execution results of the corresponding tasks. The NPU can also identify operator segments and parameter segments in the computation graph, caching the operators in the parameter segment according to the operator execution order. This allows the cache space to store the operator sequence for the corresponding task (e.g., the target operator sequence) and set the corresponding parameter segment in the cache space so that the CPU can subsequently store the parameters required to execute the operator sequence in the parameter segment.
[0205] See also Figure 6 If the CPU retrieves the computation graph again, and a sequence of operators matching the operator sequence represented by the computation graph exists in the cache, the CPU can skip the delivery process, update the parameters in the parameter segment corresponding to the operator sequence in the cache, and send a task execution instruction (not shown in the diagram) to the NPU. The NPU, based on this instruction, directly executes the cached operator sequence in sequence to obtain the execution result of the corresponding task. If no sequence of operators matching the operator sequence represented by the computation graph exists in the cache, the CPU delivers the computation graph according to the normal process.
[0206] The CPU can determine whether a sequence of operators in the cache exists that matches the operator sequence represented by the computation graph by prefix matching, or by comparing the complete sequence. For specific implementation details, please refer to [link to relevant documentation]. Figure 4 The specific implementation will not be detailed here. In the case of prefix matching, if the CPU detects that the operator sequence is actually different from the cache (e.g., the first subsequence differs from the target subsequence), the CPU can send an execution interrupt instruction to the NPU to interrupt the NPU's execution, and then issue the computation graph according to the normal process.
[0207] The methods described above, comparing complete sequences and prefix matching, are two different approaches with different implementations, such as differences in code implementation. These will be illustrated below.
[0208] In the scheme that compares the complete sequence (referred to as the cached execution scheme), users can explicitly define three semantics: record, replay, and update, to respectively implement the three processes of operator sequence caching, computation graph repetition, and parameter segment update. Relevant code examples are shown below.
[0209] record_start(id) / / record_start is the start marker of the operator sequence that needs to be cached, and id should be the identifier of the operator sequence.
[0210] matmul(A,B) / / Operator and corresponding parameters ...
[0212] record_end(id) / / record_end is the end marker of the operator sequence that needs to be cached.
[0213] replay(id, N-1, update) / / replay is a flag for repeated execution, N-1 is the number of times it needs to be executed after the first execution, and update means that the parameter segment needs to be updated.
[0214] As can be seen from this code example, users only need to add three semantics to the code to implement the cache execution scheme. The amount of code modification is very small and easy to implement.
[0215] Figure 7 This is a flowchart of yet another task execution method provided in an embodiment of this application. (In conjunction with...) Figure 7 The cache execution scheme will be explained again.
[0216] First, we introduce the operator sequence caching process, which can utilize... Figure 5 The operator sequence caching module implementation is shown.
[0217] See Figure 7 The host operating system (Host OS) is the software operating system on the CPU side, on which business applications (such as user applications) run. These business applications depend on their corresponding runtimes and drivers. The business applications generate a computation graph of computing tasks, such as... Figure 7 The section from "Start" to "End" on the far left. This computational task is typically executed multiple times. Upon the first execution of this task, the record semantics are invoked, indicating that the sequence of operators to be executed needs to be cached. At runtime, based on the dependencies between operators in the computation graph, each operator is assigned to its corresponding hardware submit queue (SQ). Figure 7 The diagram shows three hardware submission queues: SQ1, SQ2, and SQ3. At the driver level, each operator in each hardware submission queue requires an operator dispatch operation, with a total dispatch count of, for example: Figure 7The diagram shows N iterations. When each operator is issued, it can "ring a hardware doorbell" on the device operating system (e.g., the NPU's OS). Upon receiving the hardware doorbell, the NPU places the corresponding operator into a hardware execution queue (also called a task scheduler) to await scheduling. The AI cores in the NPU receive tasks from the hardware execution queue and execute the corresponding operators. The operator sequence cache module records the operators actually executed by each AI core in the NPU. If the NPU has multiple AI cores, the operators executed by these cores are arranged in the order of execution into an operator sequence. The cache also records the execution entity corresponding to each operator in this sequence; the execution entity refers to the AI core that actually executes the corresponding operator. During subsequent executions of this operator sequence, each operator in the sequence is scheduled to be executed on its corresponding execution entity. It should be understood that there can be multiple hardware submission queues, and these multiple hardware submission queues are actually executed in an interleaved manner. The actual execution sequence of the operators cannot be known in advance, but is known after the NPU has finished executing the task. Based on this, the operator sequence is cached according to the operator execution order after the NPU has finished executing the task or during the execution process.
[0218] The implementation methods and corresponding processes of hardware submission queues, hardware execution queues, and hardware doorbells can be found in relevant technologies, and will not be discussed in detail here.
[0219] Next, we introduce the process of executing the cached operator sequence, which can utilize... Figure 5 The operator sequence execution module shown is implemented.
[0220] In this process, the operator sequence caching module already caches operator sequences. During non-first executions of an operator graph, the replay semantics are invoked. This semantics accepts a parameter, which is the identifier (id) of a cached operator sequence. After invoking the replay semantics, the operator sequence execution module directly retrieves the corresponding operator sequence from the cache space according to the id and instructs the NPU's AI core to execute it. Alternatively, after invoking the replay semantics, the CPU retrieves the corresponding operator sequence from the cache space according to the id and allocates it to a hardware submission queue. The CPU-side driver then taps the NPU's hardware doorbell to send all the operators in the hardware submission queue to the NPU's hardware execution queue at once. The NPU's AI core executes the operators in the hardware execution queue in sequence. In this way, only one operator sending operation is required, which consumes very little time.
[0221] In the process of executing an operator graph for the first time, if it is necessary to update the parameters, a parameter update process needs to be added, and then the operator in the operator graph is executed according to the updated parameters.
[0222] As an example, see Figure 8 , Figure 8 The process of first acquiring and distributing the computation graph, caching the operator sequence, and setting the corresponding parameter segments in the middle Figure 6 , Figure 7 The implementation examples are similar and will not be repeated here. Figure 8 In this embodiment, when the computation graph is subsequently acquired, if an operator sequence matching the prefix of the computation graph exists in the cache space, the cached operator sequence is determined to be used. The CPU can request an operator sequence structure, copy the operator sequence matching the prefix from the cache space into the operator sequence structure, and place the operator sequence structure into a hardware submission queue all at once. The update semantics are invoked to update the parameters in the parameter segment, and the operators in the operator sequence structure are batch-distributed to the NPU through the hardware submission queue. If a subsequent operator sequence (such as the first subsequence and the target subsequence) is detected to be inconsistent, the CPU interrupts the current execution of the NPU and proceeds with the normal distribution process. If a subsequent operator sequence is detected to be consistent, the CPU waits for the NPU to complete execution and obtains the execution result.
[0223] In the prefix matching approach (referred to as the predictive execution approach), the operator sequence caching, computation graph repetition, and parameter segment updates can be achieved without requiring users to explicitly call the record, replay, and update semantics. The predictive execution approach requires less development work and is simpler to implement; it only requires enabling a switch (also known as a feature switch) during runtime.
[0224] To implement predictive execution schemes and ensure their reliability, given the significant time interval between the execution times of the current sub-task and the previous task, the CPU / NPU (e.g., its driver layer) can use this time interval to determine the boundaries of the operator sequence. That is, the execution intervals between multiple operators in the current sub-task are typically small, as these operators are issued and executed concurrently. Conversely, the execution interval between the first operator of the current sub-task and the last operator of the previous task is typically larger. Therefore, a time interval threshold can be set. If the time interval between two sequentially executed operators is detected to exceed this threshold, the CPU / NPU can treat the former operator as the last operator of the previous task and the latter operator as the first operator of the current sub-task, thus determining the operator sequence of the previous task and the first operator of the current sub-task's operator sequence. This process continues, allowing the CPU / NPU to determine the operator sequence for each executed task.
[0225] In summary, in this embodiment, the cache space can be used to cache operator sequences. Therefore, after receiving the task execution instruction, the second processor can retrieve the corresponding first operator sequence from the cache space, thus eliminating the need for the first processor to issue the target computation graph of the target task; that is, the first processor can skip the issuance operation of the target computation graph. For target tasks that need to be executed repeatedly, the technical solution of this embodiment can greatly reduce the time spent on the issuance operation, thereby reducing the waiting time of the second processor and effectively improving task execution efficiency. Furthermore, the technical solution of this embodiment does not require graph compilation, thus eliminating the need for extensive code modifications to support graph compilation functionality, thereby reducing labor costs, making it easier to implement, and more practical.
[0226] Figure 9 This is a schematic diagram of the structure of a task execution device provided in an embodiment of this application. The task execution device 900 can be implemented by software, hardware, or a combination of both as part or all of a computer device. The computer device can be... Figure 2 The computer device shown. In this embodiment, the task execution device 900 is included in a first processor, which may be a processor in a heterogeneous computing device. The heterogeneous computing device may also include a second processor. See also Figure 9 The task execution device 900 includes a first determining module 901 and a first sending module 902.
[0227] The first determining module 901 is used to determine the target computation graph of the target task. The target computation graph represents the target operator sequence, which includes the operators required to complete the target task.
[0228] The first sending module 902 is used to send a task execution instruction to the second processor if a first operator sequence that is consistent with the target operator sequence exists in the cache space; wherein the task execution instruction instructs the second processor to obtain the first operator sequence from the cache space and execute the operators in the first operator sequence to obtain the execution result of the target task.
[0229] In one possible implementation, the cache space also includes a first parameter segment corresponding to the first operator sequence. This first parameter segment stores the parameters required to execute the operators in the first operator sequence. The target computation graph also represents target parameters, which include the parameters required to execute the operators in the target computation graph. See also... Figure 10 The task execution device 900 also includes:
[0230] The parameter update module 903 is used to update the parameters in the first parameter segment according to the target parameters before sending the task execution instruction to the second processor. The second processor is used to execute the operators in the first operator sequence according to the parameters in the first parameter segment.
[0231] In one possible implementation, the task execution device 900 further includes:
[0232] The first search module is used to search for the operator sequence that is the same as the target operator sequence from the cache space after the target computation graph of the target task is determined;
[0233] The second determining module is used to determine, when an operator sequence identical to the target operator sequence is found, that a first operator sequence identical to the target operator sequence exists in the cache space.
[0234] In one possible implementation, the task execution device 900 further includes:
[0235] The second search module is used to search for the operator sequence with the same prefix as the target prefix from the cache space after the target computation graph of the target task is determined. The target prefix includes the first N operators in the target operator sequence, where N is less than the total number of operators in the target operator sequence and is a positive integer.
[0236] The third determining module is used to determine, when an operator sequence with the same prefix as the target prefix is found, whether there is a first operator sequence in the cache space that is consistent with the target operator sequence.
[0237] In one possible implementation, the task execution device 900 further includes:
[0238] The second sending module is used to send an execution interrupt instruction to the second processor after finding an operator sequence whose prefix is the same as the target prefix and detecting that the first subsequence is different from the target subsequence. The first subsequence is the operator sequence in the first operator sequence excluding the target prefix, and the target subsequence is the operator sequence in the target operator sequence excluding the target prefix. The execution interrupt instruction instructs the second processor to interrupt the execution operation of the operators in the first operator sequence.
[0239] In one possible implementation, the task execution device 900 further includes:
[0240] The third sending module is used to send the target computation graph to the second processor after sending the execution interrupt instruction to the second processor, so as to instruct the second processor to execute the operators in the target computation graph.
[0241] In one possible implementation, the task execution device 900 further includes:
[0242] The fourth sending module is used to send the target computation graph to the second processor if there is no operator sequence in the buffer space that matches the target operator sequence, so as to instruct the second processor to execute the operator in the target computation graph.
[0243] In one possible implementation, the target computation graph also characterizes target parameters, which include parameters required to execute operators in the target computation graph;
[0244] The fourth sending module is specifically used for:
[0245] The target operator sequence and target parameters are sent to the second processor to instruct the second processor to execute the operators in the target operator sequence according to the target parameters.
[0246] In one possible implementation, the first processor is a CPU.
[0247] In one possible implementation, the second processor is an NPU or a GPU.
[0248] In this embodiment, after determining the target computation graph of the target task, if the cache space contains a first operator sequence that matches the target operator sequence, the first processor can skip the distribution operation of the target computation graph. For target tasks that need to be executed repeatedly, the technical solution of this embodiment can greatly reduce the time spent on the distribution operation, thereby reducing the waiting time of the second processor and effectively improving the task execution efficiency. Furthermore, the technical solution of this embodiment does not require graph compilation, thus eliminating the need for extensive code modifications to support graph compilation functionality, thereby reducing labor costs, making it easier to implement, and more practical.
[0249] It should be noted that the task execution device 900 provided in the above embodiments is only illustrated by the division of the above functional modules when executing tasks. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the task execution device 900 provided in the above embodiments and the task execution method embodiments belong to the same concept, and the specific implementation process can be found in the method embodiments, which will not be repeated here.
[0250] Figure 11 This is a schematic diagram of another task execution device provided in this application embodiment. The task execution device 1100 can be implemented as part or all of a computer device by software, hardware, or a combination of both. The computer device can be... Figure 2 The computer device shown. In this embodiment, the task execution device 1100 is included in a second processor, which may be a processor in a heterogeneous computing device. The heterogeneous computing device may also include a first processor. See also Figure 11 The task execution device 1100 includes: a first receiving module 1101, an acquisition module 1102, and an execution module 1103.
[0251] The first receiving module 1101 is used to receive task execution instructions sent by the first processor;
[0252] The acquisition module 1102 is used to acquire the first operator sequence from the cache space based on the task execution instructions;
[0253] The execution module 1103 is used to execute the operators in the first operator sequence to obtain the execution result of the target task.
[0254] In one possible implementation, the cache space also includes a first parameter segment corresponding to the first operator sequence, which is used to store the parameters required to execute the operators in the first operator sequence;
[0255] Execution module 1103 is specifically used for:
[0256] The operators in the first operator sequence are executed according to the parameters in the first parameter segment.
[0257] In one possible implementation, the task execution device 1100 further includes:
[0258] The execution interrupt module is used to interrupt the execution of operators in the first operator sequence if an execution interrupt instruction sent by the first processor is received during the execution of operators in the first operator sequence.
[0259] In one possible implementation, see Figure 12 The task execution device 1100 also includes:
[0260] The second receiving module 1104 is used to receive the target calculation map sent by the first processor;
[0261] The execution module 1103 is also used to execute operators in the target computation graph to obtain the execution result of the target task;
[0262] The caching module 1105 is used to cache operators in the target computation graph in the cache space. The operators in the target computation graph are arranged in the cache space according to the order of operator execution to form a target operator sequence.
[0263] In one possible implementation, the target computation graph represents the target operator sequence and target parameters, including the parameters required to execute the operators in the target computation graph;
[0264] The second receiving module 1104 is specifically used for: receiving the target operator sequence and target parameters sent by the first processor;
[0265] Execution module 1103 is specifically used to: execute the operators in the target operator sequence according to the target parameters;
[0266] The task execution device 1100 also includes:
[0267] The configuration module is used to set the target parameter segment corresponding to the target operator sequence in the cache space. The target parameter segment is used to store the parameters required to execute the target operator sequence.
[0268] In one possible implementation, the first processor is a CPU.
[0269] In one possible implementation, the second processor is an NPU or a GPU.
[0270] In this embodiment, the cache space can be used to cache operator sequences. After receiving the task execution instruction, the second processor can retrieve the corresponding first operator sequence from the cache space, thus eliminating the need for the first processor to issue the target computation graph of the target task; that is, the first processor can skip the issuance operation of the target computation graph. For target tasks that need to be executed repeatedly, the technical solution of this embodiment can greatly reduce the time spent on the issuance operation, thereby reducing the waiting time of the second processor and effectively improving task execution efficiency. Furthermore, the technical solution of this embodiment does not require graph compilation, thus eliminating the need for extensive code modifications to support graph compilation functionality, thereby reducing labor costs, making it easier to implement, and more practical.
[0271] It should be noted that the task execution device 1100 provided in the above embodiments is only illustrated by the division of the above functional modules when performing tasks. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the task execution device 1100 provided in the above embodiments and the task execution method embodiments belong to the same concept, and the specific implementation process can be found in the method embodiments, which will not be repeated here.
[0272] This application also provides a computer-readable storage medium storing instructions that, when run on a computer, cause the computer to perform the steps of the task execution method shown in the above-described method embodiments.
[0273] This application also provides a computer program product containing instructions that, when run on a computer, causes the computer to perform the steps of the task execution method shown in the above method embodiments.
[0274] This application also provides a computer program that, when run on a computer, causes the computer to perform the steps of the task execution method shown in the above-described method embodiments.
[0275] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product. The computer program product includes one or more computer instructions. When the computer instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium accessible to a computer, or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., digital versatile disc (DVD)), or a semiconductor medium (e.g., solid state disk (SSD)). It is worth noting that the computer-readable storage medium mentioned in the embodiments of this application can be a non-volatile storage medium; in other words, it can be a non-transient storage medium.
[0276] It should be understood that "at least one" as mentioned herein refers to one or more, and "multiple" refers to two or more. In the description of the embodiments of this application, unless otherwise stated, " / " means "or," for example, A / B can mean A or B; "and / or" in this document is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. In addition, in order to clearly describe the technical solutions of the embodiments of this application, the terms "first," "second," etc., are used in the embodiments of this application to distinguish identical or similar items with substantially the same function and effect. Those skilled in the art will understand that the terms "first," "second," etc., do not limit the quantity or execution order, and the terms "first," "second," etc., are not necessarily different.
[0277] It should be noted that the information (including but not limited to user device information, user personal information, etc.), data (including but not limited to data used for analysis, data stored, data displayed, etc.) and signals involved in the embodiments of this application are all authorized by the user or fully authorized by all parties, and the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions.
[0278] The above descriptions are embodiments provided in this application and are not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A task execution method, characterized in that, The method is applied to a first processor, and the method includes: A target computation graph for the target task is determined, wherein the target computation graph represents a sequence of target operators, and the sequence of target operators includes the operators required to complete the target task; If a first operator sequence that matches the target operator sequence exists in the cache space, a task execution instruction is sent to the second processor; wherein the task execution instruction instructs the second processor to retrieve the first operator sequence from the cache space and execute the operators in the first operator sequence to obtain the execution result of the target task.
2. The method as described in claim 1, characterized in that, The cache space also includes a first parameter segment corresponding to the first operator sequence. The first parameter segment is used to store the parameters required to execute the operators in the first operator sequence. The target computation graph also represents target parameters, which include the parameters required to execute the operators in the target computation graph. Before sending the task execution instruction to the second processor, the method further includes: The parameters in the first parameter segment are updated according to the target parameters, and the second processor is used to execute the operators in the first operator sequence according to the parameters in the first parameter segment.
3. The method as described in claim 1 or 2, characterized in that, After determining the target computation graph for the target task, the method further includes: Search the cache space for an operator sequence that is identical to the target operator sequence; If an operator sequence identical to the target operator sequence is found, it is determined that a first operator sequence identical to the target operator sequence exists in the cache space.
4. The method as described in claim 1 or 2, characterized in that, After determining the target computation graph for the target task, the method further includes: Find the operator sequence in the cache space whose prefix is the same as the target prefix, wherein the target prefix includes the first N operators in the target operator sequence, and N is less than the total number of operators in the target operator sequence and is a positive integer; If an operator sequence with the same prefix as the target prefix is found, it is determined that a first operator sequence consistent with the target operator sequence exists in the cache space.
5. The method as described in claim 4, characterized in that, After finding an operator sequence whose prefix is the same as the target prefix, the method further includes: If a difference is detected between the first subsequence and the target subsequence, an execution interrupt instruction is sent to the second processor. The first subsequence is the operator sequence in the first operator sequence excluding the target prefix, and the target subsequence is the operator sequence in the target operator sequence excluding the target prefix. The execution interrupt instruction instructs the second processor to interrupt the execution operation of the operators in the first operator sequence.
6. The method as described in claim 5, characterized in that, After sending the execution interrupt instruction to the second processor, the method further includes: The target computation graph is sent to the second processor to instruct the second processor to execute the operators in the target computation graph.
7. The method according to any one of claims 1-6, characterized in that, The method further includes: If there is no operator sequence in the cache space that matches the target operator sequence, the target computation graph is sent to the second processor to instruct the second processor to execute the operators in the target computation graph.
8. The method as described in claim 6 or 7, characterized in that, The target computation graph also characterizes target parameters, which include parameters required to execute operators in the target computation graph; The step of sending the target computation graph to the second processor to instruct the second processor to execute the operators in the target computation graph includes: The target operator sequence and target parameters are sent to the second processor to instruct the second processor to execute the operators in the target operator sequence according to the target parameters.
9. The method according to any one of claims 1-8, characterized in that, The first processor is a central processing unit (CPU).
10. The method according to any one of claims 1-9, characterized in that, The second processor is a neural network processor (NPU) or a graphics processing unit (GPU).
11. A task execution method, characterized in that, The method is applied to a second processor, and the method includes: Receive task execution instructions sent by the first processor; Based on the task execution instructions, obtain the first operator sequence from the cache space; Execute the operators in the first operator sequence to obtain the execution result of the target task.
12. The method as described in claim 11, characterized in that, The cache space also includes a first parameter segment corresponding to the first operator sequence, the first parameter segment being used to store the parameters required to execute the operators in the first operator sequence; The execution of the operators in the first operator sequence includes: The operators in the first operator sequence are executed according to the parameters in the first parameter segment.
13. The method as described in claim 11 or 12, characterized in that, The method further includes: If an execution interrupt instruction is received from the first processor during the execution of the operators in the first operator sequence, the execution of the operators in the first operator sequence is interrupted.
14. The method as described in claim 13, characterized in that, After receiving the execution interrupt instruction sent by the first processor, the method further includes: Receive the target computation graph sent by the first processor, execute the operators in the target computation graph, and obtain the execution result of the target task; The operators in the target computation graph are cached in the cache space, and the operators in the target computation graph are arranged in the cache space according to the operator execution order to form a target operator sequence.
15. The method as described in claim 14, characterized in that, The target computation graph represents the target operator sequence and target parameters, the target parameters including parameters required to execute the operators in the target computation graph; The step of receiving the target computation graph sent by the first processor and executing the operators in the target computation graph includes: Receive the target operator sequence and the target parameters sent by the first processor, and execute the operators in the target operator sequence according to the target parameters; After receiving the target parameter, the method further includes: A target parameter segment corresponding to the target operator sequence is set in the cache space. The target parameter segment is used to store the parameters required to execute the target operator sequence.
16. The method according to any one of claims 11-15, characterized in that, The first processor is a central processing unit (CPU).
17. The method according to any one of claims 11-16, characterized in that, The second processor is a neural network processor (NPU) or a graphics processing unit (GPU).
18. A task execution device, characterized in that, The device is included in a first processor, and the device includes: The first determining module is used to determine the target computation graph of the target task, wherein the target computation graph represents a sequence of target operators, and the sequence of target operators includes the operators required to complete the target task; A first sending module is configured to send a task execution instruction to a second processor if a first operator sequence identical to the target operator sequence exists in the cache space; wherein the task execution instruction instructs the second processor to retrieve the first operator sequence from the cache space and execute the operators in the first operator sequence to obtain the execution result of the target task.
19. The apparatus as claimed in claim 18, characterized in that, The cache space also includes a first parameter segment corresponding to the first operator sequence. The first parameter segment is used to store the parameters required to execute the operators in the first operator sequence. The target computation graph also represents target parameters, which include the parameters required to execute the operators in the target computation graph. The device further includes: The parameter update module is used to update the parameters in the first parameter segment according to the target parameters before sending the task execution instruction to the second processor. The second processor is used to execute the operators in the first operator sequence according to the parameters in the first parameter segment.
20. The apparatus as claimed in claim 18 or 19, characterized in that, The device further includes: The first search module is used to search for an operator sequence that is the same as the target operator sequence from the cache space after the target computation graph of the target task is determined; The second determining module is used to determine, when an operator sequence identical to the target operator sequence is found, that a first operator sequence identical to the target operator sequence exists in the cache space.
21. The apparatus as claimed in claim 18 or 19, characterized in that, The device further includes: The second search module is used to search for an operator sequence with the same prefix as the target prefix from the cache space after the target computation graph of the target task is determined. The target prefix includes the first N operators in the target operator sequence, where N is less than the total number of operators in the target operator sequence and is a positive integer. The third determining module is used to determine, when an operator sequence with the same prefix as the target prefix is found, that there exists a first operator sequence in the cache space that is consistent with the target operator sequence.
22. The apparatus as claimed in claim 21, characterized in that, The device further includes: The second sending module is configured to send an execution interrupt instruction to the second processor after finding an operator sequence whose prefix is the same as the target prefix, and if it detects that the first subsequence is different from the target subsequence. The first subsequence is the operator sequence in the first operator sequence excluding the target prefix, and the target subsequence is the operator sequence in the target operator sequence excluding the target prefix. The execution interrupt instruction instructs the second processor to interrupt the execution operation of the operators in the first operator sequence.
23. The apparatus as claimed in claim 22, characterized in that, The device further includes: The third sending module is used to send the target computation graph to the second processor after sending an execution interrupt instruction to the second processor, so as to instruct the second processor to execute the operators in the target computation graph.
24. The apparatus according to any one of claims 18-23, characterized in that, The device further includes: The fourth sending module is used to send the target computation graph to the second processor if there is no operator sequence in the cache space that matches the target operator sequence, so as to instruct the second processor to execute the operator in the target computation graph.
25. The apparatus as claimed in claim 23 or 24, characterized in that, The target computation graph also characterizes target parameters, which include parameters required to execute operators in the target computation graph; The fourth sending module is specifically used for: The target operator sequence and target parameters are sent to the second processor to instruct the second processor to execute the operators in the target operator sequence according to the target parameters.
26. The apparatus according to any one of claims 18-25, characterized in that, The first processor is a central processing unit (CPU).
27. The apparatus according to any one of claims 18-26, characterized in that, The second processor is a neural network processor (NPU) or a graphics processing unit (GPU).
28. A task execution device, characterized in that, The device is included in a second processor, and the device includes: The first receiving module is used to receive task execution instructions sent by the first processor; The acquisition module is used to acquire the first operator sequence from the cache space based on the task execution instruction; The execution module is used to execute the operators in the first operator sequence to obtain the execution result of the target task.
29. The apparatus as claimed in claim 28, characterized in that, The cache space also includes a first parameter segment corresponding to the first operator sequence, the first parameter segment being used to store the parameters required to execute the operators in the first operator sequence; The execution module is specifically used for: The operators in the first operator sequence are executed according to the parameters in the first parameter segment.
30. The apparatus as claimed in claim 28 or 29, characterized in that, The device further includes: An execution interrupt module is used to interrupt the execution of operators in the first operator sequence if an execution interrupt instruction sent by the first processor is received during the execution of operators in the first operator sequence.
31. The apparatus as claimed in claim 30, characterized in that, The device further includes: The second receiving module is used to receive the target computation graph sent by the first processor; The execution module is further configured to execute operators in the target computation graph to obtain the execution result of the target task; A caching module is used to cache the operators in the target computation graph in the cache space, wherein the operators in the target computation graph are arranged in the cache space according to the operator execution order to form a target operator sequence.
32. The apparatus as claimed in claim 31, characterized in that, The target computation graph represents the target operator sequence and target parameters, the target parameters including parameters required to execute the operators in the target computation graph; The second receiving module is specifically used to: receive the target operator sequence and the target parameters sent by the first processor; The execution module is specifically used to: execute the operators in the target operator sequence according to the target parameters; The device further includes: The setting module is used to set the target parameter segment corresponding to the target operator sequence in the cache space, and the target parameter segment is used to store the parameters required to execute the target operator sequence.
33. The apparatus according to any one of claims 28-32, characterized in that, The first processor is a central processing unit (CPU).
34. The apparatus according to any one of claims 28-33, characterized in that, The second processor is a neural network processor (NPU) or a graphics processing unit (GPU).
35. A heterogeneous computing device, characterized in that, The heterogeneous computing device includes a first processor and a second processor; The first processor is configured to perform the steps of the method according to any one of claims 1-10; The second processor is used to perform the steps of the method according to any one of claims 11-17.
36. A computer-readable storage medium, characterized in that, The storage medium stores a computer program, which, when executed by a processor, implements the method described in any one of claims 1-10, or the method described in any one of claims 11-17.
37. A computer program product, characterized in that, The computer program product stores computer instructions, which, when executed by a processor, implement the method described in any one of claims 1-10, or the method described in any one of claims 11-17.
