Kernel execution method and device, electronic equipment and storage medium
By adding a trigger signal at the end of the first core and starting the second core during its execution, using the trigger signal to trigger the execution of the second core at the end of the first core, the problem of inefficient sequential execution between multiple cores is solved. , which improves the kernel execution efficiency and reduces the technical threshold, and is suitable for scenarios with unknown dependencies.
Patent Information
- Application Number
- CN202411020498.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-26
- Publication Date
- 2024-10-18
AI Technical Summary
In the field of computer technology, the sequential execution of multiple cores results in a long overall execution time and low overall execution efficiency. Especially in the case of unknown dependencies, it is difficult for existing technology to effectively eliminate the time interval between cores, limiting Improves the efficiency of kernel execution.
By adding a first trigger signal at the end of the first core, starting and suspending the second core during the startup and execution of the first core, and using the trigger signal to trigger the execution of the second core at the end of the execution of the first core, thereby Eliminate the time interval between cores without unknown dependencies and improve overall execution efficiency.
It effectively eliminates the time interval between kernels, improves the overall efficiency of kernel execution, and achieves efficient execution without the need for users to manually modify the kernel code. It expands the application scope of efficient kernel execution and is compatible with Eager Mode and Programmatic Dependent Launch mechanisms.
Smart Images

Figure CN118796271A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a kernel execution method, device, electronic device and storage medium. Background Art
[0002] A data stream is a sequence of commands executed in order and is often used to manage concurrent operations in the kernel.
[0003] Currently, there is usually a dependency relationship between multiple kernels in the same data stream, which is specifically reflected in that the latter kernel depends on the data generated by the execution of the previous kernel. Therefore, multiple kernels need to be executed one by one in sequence, that is, the latter kernel will not be launched until the previous kernel is executed. As a result, the overall execution time of multiple kernels is longer and the overall execution efficiency is lower. Summary of the invention
[0004] The present invention provides a kernel execution method, device, electronic device and storage medium, which are used to solve the defect of low overall efficiency of sequential execution of multiple kernels in the related art.
[0005] The present invention provides a kernel execution method, comprising: Starting and executing a first kernel, and in the process of starting and executing the first kernel, starting and suspending a second kernel, wherein the first kernel is a kernel having a first trigger signal added to the end of a first original kernel, and the first original kernel does not contain the first trigger signal; When the execution of the first kernel ends, the execution of the second kernel is triggered based on the first trigger signal.
[0006] A kernel execution method provided according to the present invention also includes: In the process of executing the second kernel, starting and suspending the third kernel, wherein the second kernel is a kernel having a second trigger signal added to the end of the second original kernel, and the second original kernel does not contain the second trigger signal; When the execution of the second kernel ends, the execution of the third kernel is triggered based on the second trigger signal.
[0007] According to a kernel execution method provided by the present invention, the second kernel includes a first part and a second part, and the first part and the second part are obtained by splitting based on a wait instruction in the second kernel; The starting and suspending of the second kernel comprises: Starting the second kernel and executing the first part of the second kernel; After the first part is executed, suspending the second kernel; The triggering the second kernel to execute based on the first trigger signal includes: The second part is triggered to execute based on the first trigger signal.
[0008] According to a kernel execution method provided by the present invention, the second kernel is a kernel with a wait instruction added at the beginning of the second original kernel, and the second original kernel does not contain the wait instruction.
[0009] According to a kernel execution method provided by the present invention, the first part is independent of data generated by the execution of the first kernel.
[0010] According to a kernel execution method provided by the present invention, the number of kernels started simultaneously is less than or equal to two.
[0011] The present invention also provides a kernel execution device, comprising: a first execution unit, configured to start and execute a first kernel, and start and suspend a second kernel during the process of starting and executing the first kernel, wherein the first kernel is a kernel having a first trigger signal added to the end of a first original kernel, and the first original kernel does not contain the first trigger signal; The second execution unit is configured to trigger the execution of the second kernel based on the first trigger signal when the execution of the first kernel ends.
[0012] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, any one of the kernel execution methods described above is implemented.
[0013] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the kernel execution method described in any one of the above is implemented.
[0014] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the kernel execution method described above is implemented.
[0015] The kernel execution method, device, electronic device and storage medium provided by the present invention only need to add a first trigger signal at the end of the first original kernel, and start and suspend the second kernel during the startup and execution of the first kernel, so that the second kernel execution can be triggered by the first trigger signal when the first kernel execution ends. Therefore, under the premise of unknown whether there is a dependency relationship between the first kernel and the second kernel, the time interval between the first kernel and the second kernel can be effectively eliminated, thereby improving the overall efficiency of the kernel execution. In this process, there is no need for the user to manually modify the internal code of the kernel, which reduces the technical threshold of high-efficiency kernel execution and expands the application scope of high-efficiency kernel execution. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the technical solutions in the present invention or related technologies, the following briefly introduces the drawings required for use in the embodiments or related technical descriptions. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0017] Figure 1 It is one of the kernel execution timeline diagrams in the related art.
[0018] Figure 2 This is the second schematic diagram of the kernel execution timeline in the related art.
[0019] Figure 3 It is a flowchart diagram of the kernel execution method provided by the present invention.
[0020] Figure 4 It is a schematic diagram of the kernel execution timeline provided by the present invention.
[0021] Figure 5 It is a structural schematic diagram of the kernel execution device provided by the present invention.
[0022] Figure 6 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0023] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0024] At present, there is usually a dependency relationship between multiple kernels in the same data stream, which is specifically reflected in that the latter kernel depends on the data generated by the execution of the previous kernel. Therefore, multiple kernels need to be executed one by one in sequence, that is, the next kernel can only be sent to the processing unit for execution after the previous kernel is executed.
[0025] Figure 1 It is one of the kernel execution timeline diagrams in the related art, such as Figure 1 As shown in the figure, kernels in the same data stream are executed one by one in sequence by default, that is, the second kernel needs to be started after the first kernel is finished. Since the kernel startup takes a long time, there will be a time interval between the two kernels, which prolongs the overall execution time and leads to low overall execution efficiency. Since the kernel is usually run at the AI chip, the overall execution efficiency of the kernel is reduced, which will lead to the inability to fully utilize the computing resources of the AI chip. It is understandable that in Figure 1 In , the interval between the first kernel and the second kernel indicates the time it takes for the second kernel to start after the first kernel ends.
[0026] To address this problem, the Programmatic Dependent Launch mechanism is used in the Compute Unified Device Architecture (CUDA) to achieve asynchronous launch of kernels on the same data stream, thereby eliminating the latency caused by kernel launch and preprocessing. Here, the Programmatic Dependent Launch mechanism specifically means that when this mechanism is enabled, the second kernel that has a dependency on the previous kernel on the same data stream is allowed to launch before the previous kernel.
[0027] For example, Figure 2 This is the second schematic diagram of the kernel execution timeline in the related technology, such as Figure 2 As shown in the figure, under the Programmatic Dependent Launch mechanism, if the user knows that a part of the second kernel can be executed in advance, and the time point of the advance execution is in the first kernel, then the user can add a startup synchronization mechanism between the kernels. Thus, all threads in the first kernel execute the synchronization instructions of the synchronization mechanism, which can trigger the second kernel to start executing, execute the part that can be executed in advance, and then wait for the first kernel to end before continuing to execute the instructions in the second kernel.
[0028] It is understandable that, based on the Programmatic Dependent Launch mechanism, the first kernel and the second kernel have a portion of parallel execution process, and the kernel execution efficiency is improved.
[0029] However, the implementation of the Programmatic Dependent Launch mechanism requires user participation to modify the kernel code to add a synchronization mechanism between the front and back kernels. Specifically, the user is required to add a trigger signal sending mechanism in the front kernel and a wait instruction in the back kernel, so that the back kernel starts executing after waiting for the trigger signal, thereby ensuring the normal flow of data. It can be understood that the trigger signal here is the signal used to trigger the execution of the back kernel.
[0030] Eager Mode (dynamic graph mode) is a mode for implementing kernel instant execution. In Eager Mode, since the kernel is executed immediately, it is unknown whether there is a dependency between the previous and next kernels. In this case, the user obviously cannot manually modify the code of the previous and next kernels, resulting in the kernel execution in Eager Mode not being able to experience the advantages of the Programmatic Dependent Launch mechanism, and the interval between kernels cannot be eliminated.
[0031] For example, in Figure 2 In the process, since it is impossible to know whether there is a dependency relationship between the second kernel and other kernels, the second kernel and other kernels cannot apply the Programmatic Dependent Launch mechanism when they are executed, and there is still a time interval between the second kernel and other kernels. It is understandable that in Figure 2 In , the interval between the second kernel and other kernels indicates the time it takes for other kernels to start after the second kernel ends.
[0032] Therefore, the current Programmatic Dependent Launch mechanism is only applicable to the situation where there is a clear dependency relationship between the front and back kernels and the user can participate in modifying the internal code of the kernel. The application of the Programmatic Dependent Launch mechanism is restricted and has limited effect on improving the overall execution efficiency of the kernel.
[0033] In view of the above problems, an embodiment of the present invention provides a kernel execution method. Figure 3 is a flowchart of the kernel execution method provided by the present invention, such as Figure 3As shown, the method can be applied to artificial intelligence chips, for example, can be applied to graphics processing units (GPU), general-purpose computing on graphics processing units (GPGPU), etc. The method includes: Step 310, start and execute the first kernel, and in the process of starting and executing the first kernel, start and suspend the second kernel, the first kernel is a kernel that adds a first trigger signal at the end of the first original kernel, and the first original kernel does not contain the first trigger signal.
[0034] Specifically, the first kernel and the second kernel are two kernels executed one after the other when there are multiple kernels in the same data stream. It can be understood that in the embodiment of the present invention, the first kernel is the kernel executed first, and the second kernel is the kernel executed later.
[0035] The command processor (CP) can successively send the first kernel and the second kernel in the same data stream to the processing unit for execution, and no event can be inserted between the sending of the first kernel and the second kernel to interfere with or interrupt the continuous sending of the first kernel and the second kernel. Here, the command processor is a unit module on the artificial intelligence chip for processing commands. The processing unit can be a programmable multiprocessor, such as a streaming processing cluster (SPC).
[0036] In the case that it is unknown whether there is a dependency relationship between the first kernel and the second kernel, in order to make the execution of the first kernel and the second kernel adapt to the Programmatic Dependent Launch mechanism and thus improve the overall efficiency of kernel execution, settings may be made in advance for the first kernel.
[0037] Here, the setting for the first kernel may be implemented by a compiler or a driver.
[0038] Assume that it is unknown whether there is a dependency between the first kernel and the second kernel, and the user has not manually added a trigger signal in the first kernel, that is, there is no trigger signal in the unset first kernel. In this case, the unset first kernel can be recorded as the first original kernel. It is understandable that if the first original kernel is directly executed as the first kernel, the execution of the first kernel and the second kernel cannot adapt to the Programmatic Dependent Launch mechanism, and the second kernel will be started after the first kernel is executed, resulting in the inability to eliminate the time interval between the first kernel and the second kernel.
[0039] Therefore, for the first original kernel, a first trigger signal can be added at the end of the first original kernel, and the first original kernel with the first trigger signal added at the end is used as the first kernel that has been set. Here, the first trigger signal is a trigger signal set in the first kernel, and the first trigger signal is used to trigger the second kernel that is executed after the first kernel to start executing. It can be understood that adding the first trigger signal at the end means that the first trigger signal is sent when the first kernel is executed to trigger the second kernel to start executing. In this way, even if there is a dependency relationship between the first kernel and the second kernel, the second kernel can obtain the data obtained by the execution of the first kernel during execution, thereby ensuring that the second kernel can be executed smoothly.
[0040] By adding the first trigger signal at the end of the first original kernel, the first kernel includes the first trigger signal that can trigger the execution of the second kernel, so that the execution of the first kernel and the second kernel can adapt to the ProgrammaticDependent Launch mechanism to achieve the purpose of improving the overall efficiency of kernel execution.
[0041] In a specific implementation, the first kernel may be started and executed, that is, the first kernel is started, and after the first kernel is started, the first kernel is executed.
[0042] And, during the process of starting and executing the first kernel, the second kernel is started and suspended, that is, the second kernel is started, and after the second kernel is started, the second kernel is suspended. Here, suspending the second kernel means placing the second kernel in a state where it is neither executed nor terminated, that is, placing the second kernel in a waiting state. In this case, the second kernel can be triggered by the first trigger signal, and immediately resumes execution after being triggered by the first trigger signal.
[0043] It is understandable that during the process of starting and executing the first kernel, the second kernel is also started. That is, the start of the second kernel reuses the time of starting and executing the first kernel, so after the first kernel is executed, the second kernel does not need to spend time to start, which can greatly reduce the time interval between the first kernel and the second kernel.
[0044] Furthermore, during the process of starting and executing the first kernel, the second kernel is suspended after starting. That is, under the premise of not knowing whether there is a dependency relationship between the first kernel and the second kernel, the second kernel is not executed during the execution of the first kernel, which can avoid the problem of execution failure caused by the inability of the second kernel to obtain the data obtained by the execution of the first kernel during execution.
[0045] Step 320: When the execution of the first kernel ends, trigger the execution of the second kernel based on the first trigger signal.
[0046] Specifically, when the first kernel is finished executing, the first trigger signal added at the end of the first kernel is sent, so that the suspended second kernel can be triggered by the first trigger signal, and under the triggering of the first trigger signal, the suspended second kernel is transferred from the waiting state to the execution state, and the second kernel resumes execution.
[0047] It can be understood that since the startup of the second kernel has been completed during the startup and execution of the first kernel, the second kernel does not need to be started again after the execution of the first kernel is completed, and can immediately enter the execution state from the waiting state. The time interval between the first kernel and the second kernel is compressed and close to zero, and the overall execution efficiency of the kernel is improved.
[0048] In the method provided in the embodiment of the present invention, it is only necessary to add a first trigger signal at the end of the first original kernel, and to start and suspend the second kernel during the startup and execution of the first kernel, so that the second kernel can be triggered to execute by the first trigger signal when the execution of the first kernel ends. In this way, the time interval between the first kernel and the second kernel can be effectively eliminated without knowing whether there is a dependency relationship between the first kernel and the second kernel, thereby improving the overall efficiency of kernel execution. In this process, there is no need for the user to manually modify the internal code of the kernel, thereby lowering the technical threshold for high-efficiency kernel execution and expanding the application scope of high-efficiency kernel execution.
[0049] Furthermore, the method provided by the embodiment of the present invention can improve the overall efficiency of kernel execution under the premise of unknown whether there is a dependency relationship between the first kernel and the second kernel, so it is compatible with Eager Mode. Furthermore, even if there is no trigger signal in the first original kernel, the first kernel can still be obtained by adding the first trigger signal at the end of the first original kernel to achieve default sending of the trigger signal, which is compatible with Programmatic Dependent Launch.
[0050] Based on the above embodiment, the method further includes: In the process of executing the second kernel, starting and suspending the third kernel, wherein the second kernel is a kernel having a second trigger signal added to the end of the second original kernel, and the second original kernel does not contain the second trigger signal; When the execution of the second kernel ends, the execution of the third kernel is triggered based on the second trigger signal.
[0051] Specifically, the third kernel, the first kernel, and the second kernel are in the same data flow, and the third kernel is a kernel executed after the second kernel.
[0052] In the case that it is unknown whether there is a dependency between the second kernel and the third kernel, in order to make the execution of the second kernel and the third kernel also adapt to the Programmatic Dependent Launch mechanism, thereby improving the overall efficiency of kernel execution, settings may be made in advance for the second kernel.
[0053] Similarly, the setting for the second kernel may also be implemented by a compiler or a driver.
[0054] Assume that it is unknown whether there is a dependency between the second kernel and the third kernel, and the user has not manually added a trigger signal in the second kernel, that is, there is no trigger signal in the unset second kernel. In this case, the unset second kernel can be recorded as the second original kernel. It can be understood that if the second original kernel is directly executed as the second kernel, the execution of the second kernel and the third kernel cannot adapt to the Programmatic Dependent Launch mechanism, and the third kernel will be started after the second kernel is executed, resulting in the time interval between the second kernel and the third kernel cannot be eliminated.
[0055] Therefore, for the second original kernel, a second trigger signal can be added at the end of the second original kernel, and the second original kernel with the second trigger signal added at the end is used as the second kernel that has been set. Here, the second trigger signal is a trigger signal set in the second kernel, and the second trigger signal is used to trigger the third kernel executed after the second kernel to start executing. It can be understood that adding the second trigger signal at the end means that the second trigger signal is sent when the second kernel is executed to trigger the third kernel to start executing. In this way, even if there is a dependency relationship between the second kernel and the third kernel, the third kernel can obtain the data obtained by the execution of the second kernel during execution, thereby ensuring that the third kernel can be executed smoothly.
[0056] By adding a second trigger signal at the end of the second original kernel, the second kernel contains a second trigger signal that can trigger the execution of the third kernel, so that the execution of the second kernel and the third kernel can adapt to the ProgrammaticDependent Launch mechanism to achieve the purpose of improving the overall efficiency of kernel execution.
[0057] In a specific implementation, during the execution of the second kernel, the third kernel is started and suspended, that is, the third kernel is started, and after the third kernel is started, the third kernel is suspended. Here, suspending the third kernel means placing the third kernel in a state where it is neither executed nor terminated, that is, placing the third kernel in a waiting state. In this case, the third kernel can be triggered by the second trigger signal, and immediately resumes execution after being triggered by the second trigger signal.
[0058] It can be understood that during the execution of the second kernel, the first kernel has been executed. At this time, only the second kernel is executed in the data flow. During this process, the third kernel is started and suspended, that is, only the third kernel is suspended in the data flow. Therefore, the second trigger signal issued when the second kernel is executed can only trigger the execution of the third kernel, avoiding the timing problem of kernel execution caused by multiple kernels being suspended and waiting for trigger signals.
[0059] Moreover, during the execution of the second kernel, the third kernel is also started. That is, the startup of the third kernel reuses the execution time of the second kernel, so after the execution of the second kernel is completed, the third kernel does not need to consume time to start, which can greatly reduce the time interval between the second kernel and the third kernel.
[0060] Furthermore, during the execution of the second kernel, the third kernel is suspended after startup. That is, under the premise of not knowing whether there is a dependency relationship between the second kernel and the third kernel, the third kernel is not executed during the execution of the second kernel, which can avoid the problem of execution failure caused by the third kernel being unable to obtain the data obtained by the execution of the second kernel during execution.
[0061] When the second kernel finishes executing, the second trigger signal added at the end of the second kernel is sent. Thus, the suspended third kernel can be triggered by the second trigger signal, and under the triggering of the second trigger signal, the suspended third kernel switches from the waiting state to the execution state, and the third kernel resumes execution.
[0062] It can be understood that since the startup of the third kernel has been completed during the execution of the second kernel, the third kernel does not need to be started again after the execution of the second kernel is completed, and can immediately enter the execution state from the waiting state. The time interval between the second kernel and the third kernel is compressed and close to zero, and the overall execution efficiency of the kernel is improved.
[0063] In the method provided by the embodiment of the present invention, for two kernels executed successively in the same data stream, a trigger signal is added at the end of the earlier kernel, and for the later kernel, it is started and suspended during the execution of the earlier kernel, and is triggered to execute when the earlier kernel finishes execution, thereby eliminating the time interval between the two kernels executed successively.
[0064] In particular, for the case where there are more than two kernels in the same data stream, for the second kernel that is executed after the first kernel and before the third kernel, the second kernel is started and suspended during the startup and execution of the first kernel, and is executed under the trigger of the first trigger signal when the first kernel is executed. At the end of the execution, the third kernel is triggered to execute by the second trigger signal at the end, thereby compressing the time interval between the first kernel and the second kernel, and between the second kernel and the third kernel.
[0065] Based on any of the above embodiments, the second kernel includes a first part and a second part, and the first part and the second part are split based on the wait instruction in the second kernel.
[0066] Specifically, a waiting instruction may be set in the second kernel. The waiting instruction here is used to instruct the second kernel to suspend and wait for the first trigger signal. Thus, based on the waiting instruction in the second kernel, the second kernel may be split into two parts, namely, a first part and a second part.
[0067] It is understandable that the first part refers to the part of the second core arranged before the wait instruction, and the first part includes the wait instruction. The second part refers to the part of the second core arranged after the wait instruction, and the second part does not include the wait instruction.
[0068] Accordingly, in step 310, starting and suspending the second kernel includes: Starting the second kernel and executing the first part of the second kernel; After the first part is executed, the second kernel is suspended.
[0069] Specifically, in the process of starting and executing the first kernel, the second kernel can be started, and after the second kernel is started, the various instructions in the second kernel are executed sequentially until the waiting instruction is executed. Under the instruction of the waiting instruction, the second kernel is suspended and enters a waiting state, and begins to wait for the first trigger signal, that is, waits for the execution of the first kernel to end.
[0070] In step 320, triggering the second kernel to execute based on the first trigger signal includes: The second part is triggered to execute based on the first trigger signal.
[0071] Specifically, a first trigger signal is provided at the end of the first kernel, and the first trigger signal can be sent when the first kernel is finished executing. Accordingly, the suspended second kernel, that is, the second kernel in the waiting state waits for the first trigger signal, and can be triggered by the first trigger signal to switch from the waiting state to the execution state, and the second kernel continues to execute. And because the second kernel splits the first part and the second part based on the waiting instruction, it can be understood that the first part has been executed before the second kernel is suspended, and thus, when the second kernel switches from the waiting state to the execution state, the second part can be directly executed.
[0072] Based on any of the above embodiments, the second kernel is a kernel having a wait instruction added at the beginning of the second original kernel, and the second original kernel does not include the wait instruction.
[0073] Specifically, in the case where the dependency between the first kernel and the second kernel is known, the user can modify the code of the second kernel by adding a wait instruction in the second kernel, thereby dividing the second kernel into a first part that can be executed first without waiting for the first kernel to be completed, and a second part that needs to wait for the first kernel to be completed before execution can begin.
[0074] In the case where the dependency relationship between the first kernel and the second kernel is unknown and it is impossible to distinguish from the second kernel the part that can be executed first without waiting for the first kernel to be completed and the part that needs to wait for the first kernel to be completed before being executed, the second kernel usually does not include a wait instruction. In the embodiment of the present invention, the second kernel that has not yet been added with a wait instruction can be recorded as the second original kernel.
[0075] In this case, in order to ensure that the second kernel is suspended after startup and waits for the first kernel to be executed before execution, a waiting instruction can be added at the beginning of the second original kernel, and the second original kernel with the waiting instruction added at the beginning is used as the second kernel during actual execution. It can be understood that the second kernel with the waiting instruction added at the beginning can use the waiting instruction as the first part and all the codes after the waiting instruction as the second part.
[0076] Thus, during the process of starting and executing the first kernel, the second kernel can be started synchronously, and after the second kernel is started, the waiting instruction at the beginning of the second kernel can be executed, thereby suspending the second kernel and continuously waiting until the first kernel is executed and the first trigger signal is issued, and under the triggering of the first trigger signal, the second kernel starts to execute the part after the waiting instruction. In this way, even if there is a dependency relationship between the first kernel and the second kernel, the data obtained by the execution of the first kernel can be obtained when the second kernel is executed, thereby avoiding the risk of execution failure.
[0077] Based on any of the above embodiments, the first part is independent of data generated by the execution of the first kernel.
[0078] Specifically, since the first part of the second kernel is executed before the first kernel is executed, the first part of the second kernel cannot completely obtain the data generated by the execution of the first kernel when executing. In order to ensure the reliability of the execution of the first part of the second kernel, when dividing the first part and the second part of the second kernel, it is necessary to ensure that the first part is independent of the data generated by the execution of the first kernel. Accordingly, the second part of the second kernel executed after the first kernel is executed can be related to or unrelated to the data generated by the execution of the first kernel, and the embodiment of the present invention does not specifically limit this.
[0079] It can be understood that when it is determined that there is a dependency between the first kernel and the second kernel, the part of the second kernel that is not related to the data generated by the execution of the first kernel can be taken as the first part, and the part of the second kernel that is related to the data generated by the execution of the first kernel can be taken as the second part.
[0080] When it is unknown whether there is a dependency between the first kernel and the second kernel, a wait instruction can be set at the beginning of the second kernel, thereby taking the wait instruction itself as the first part and the entire part after the wait instruction as the second part, thereby ensuring that the first part is independent of the data generated by the execution of the first kernel, thereby ensuring the reliability of the execution of the second kernel.
[0081] Based on any of the above embodiments, the number of cores started simultaneously is less than or equal to two.
[0082] Specifically, in a data stream, the number of cores started simultaneously is ensured to be no more than two, so that under the Programmatic Dependent Launch mechanism, if one core is executing, there is at most one core that is suspended and waiting for a trigger signal. In this way, the timing problem of core execution caused by multiple cores being suspended and waiting for a trigger signal can be avoided.
[0083] In a specific implementation, for a data stream, the first executed kernel and the second executed kernel can be started at the same time, and in the process of executing the first kernel, in order to avoid the situation that other kernels except the second kernel are suspended waiting for a trigger signal, other kernels are not started. The third kernel is allowed to start only when the first kernel is finished executing. At this time, the kernels started in the data stream include the second kernel and the third kernel, and in the process of executing the second kernel, in order to avoid the situation that other kernels except the third kernel are suspended waiting for a trigger signal, other kernels are not started. The fourth kernel is allowed to start only when the second kernel is finished executing. And so on, to ensure that the number of kernels started simultaneously in a data stream does not exceed two, thereby ensuring the timing of kernel execution.
[0084] For example, Figure 4 It is a schematic diagram of the kernel execution timeline provided by the present invention, such as Figure 4 As shown, kernels A, B, C, and D are four kernels executed sequentially in the same data flow.
[0085] Among them, kernel A and kernel B are two kernels that are synchronized by pre-modifying the kernel code by the user under the Programmatic Dependent Launch mechanism, that is, there is a trigger signal in kernel A and a wait instruction in kernel B. Therefore, under the Programmatic Dependent Launch mechanism, kernel A and kernel B can be executed sequentially, and kernel B can execute the part after the wait instruction after kernel A sends a trigger signal.
[0086] In addition, it is unknown whether there is a dependency relationship between kernel B and kernel C, and between kernel C and kernel D, so there is no trigger signal in kernel B and kernel C, and there is no wait instruction in kernel C and kernel D. In view of this situation, the compiler or driver can directly add a trigger signal at the end of kernel B and kernel C, and add a wait instruction at the beginning of kernel C and kernel D.
[0087] Thus, when kernel A finishes executing, kernel B continues to execute, and kernel C starts at the same time. After starting, the wait instruction at the beginning of kernel C is executed, and kernel C hangs. It can be understood that in Figure 4In the example, the end time of kernel B execution is basically the same as the start time of kernel C execution, that is, there is basically no interval between the execution of kernel B and kernel C. The reason is that kernel C starts to start during the execution of kernel B. Therefore, when kernel B finishes executing, the trigger signal at the end of kernel B is sent, and kernel C starts to execute under the trigger of the trigger signal. The execution of kernel B and kernel C is basically seamless. At the same time, kernel D starts, and after the startup is completed, the waiting instruction at the beginning of kernel D is executed, and kernel D is suspended. It can be understood that in Figure 4 In the example, the end time of kernel C execution is basically the same as the start time of kernel D execution, that is, there is basically no interval between the execution of kernel C and kernel D, because kernel D starts to start during the execution of kernel C. Therefore, when kernel C finishes executing, the trigger signal at the end of kernel C is sent, and kernel D starts to execute under the trigger of the trigger signal, and the execution of kernel C and kernel D is basically seamless.
[0088] The kernel execution device provided by the present invention is described below. The kernel execution device described below and the kernel execution method described above can be referenced to each other.
[0089] Figure 5 Schematic diagram of the structure of the kernel execution device provided by the present invention. Figure 5 As shown, the device comprises: A first execution unit 510 is configured to start and execute a first kernel, and in the process of starting and executing the first kernel, start and suspend a second kernel, wherein the first kernel is a kernel having a first trigger signal added to the end of a first original kernel, and the first original kernel does not contain the first trigger signal; The second execution unit 520 is configured to trigger the execution of the second kernel based on the first trigger signal when the execution of the first kernel ends.
[0090] The device provided by the embodiment of the present invention only needs to add a first trigger signal at the end of the first original kernel, and start and suspend the second kernel during the startup and execution of the first kernel, so that the second kernel execution can be triggered by the first trigger signal when the first kernel execution ends. Therefore, under the premise of unknown whether there is a dependency relationship between the first kernel and the second kernel, the time interval between the first kernel and the second kernel can be effectively eliminated, thereby improving the overall efficiency of kernel execution. In this process, there is no need for the user to manually modify the internal code of the kernel, which reduces the technical threshold of high-efficiency kernel execution and expands the application scope of high-efficiency kernel execution.
[0091] Furthermore, the device provided by the embodiment of the present invention can improve the overall efficiency of kernel execution under the premise of unknown whether there is a dependency relationship between the first kernel and the second kernel, so it is compatible with Eager Mode. Furthermore, even if there is no trigger signal in the first original kernel, the first kernel can still be obtained by adding the first trigger signal at the end of the first original kernel to achieve default sending of the trigger signal, which is compatible with Programmatic Dependent Launch.
[0092] Based on any of the above embodiments, the device further includes a third execution unit, configured to: In the process of executing the second kernel, starting and suspending the third kernel, wherein the second kernel is a kernel having a second trigger signal added to the end of the second original kernel, and the second original kernel does not contain the second trigger signal; When the execution of the second kernel ends, the execution of the third kernel is triggered based on the second trigger signal.
[0093] Based on any of the above embodiments, the second kernel includes a first part and a second part, and the first part and the second part are obtained by splitting based on a wait instruction in the second kernel; The first execution unit is specifically used for: Starting the second kernel and executing the first part of the second kernel; After the first part is executed, suspending the second kernel; The second execution unit is specifically used for: The second part is triggered to execute based on the first trigger signal.
[0094] Based on any of the above embodiments, the second kernel is a kernel having a wait instruction added at the beginning of the second original kernel, and the second original kernel does not include the wait instruction.
[0095] Based on any of the above embodiments, the first part is independent of data generated by the execution of the first kernel.
[0096] Based on any of the above embodiments, the number of cores started simultaneously is less than or equal to two.
[0097] Figure 6 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 6As shown, the electronic device may include: a processor (processor) 610, a communication interface (Communications Interface) 620, a memory (memory) 630 and a communication bus 640, wherein the processor 610, the communication interface 620, and the memory 630 communicate with each other through the communication bus 640. The processor 610 may call the logic instructions in the memory 630 to execute the kernel execution method, which includes: Starting and executing a first kernel, and in the process of starting and executing the first kernel, starting and suspending a second kernel, wherein the first kernel is a kernel having a first trigger signal added to the end of a first original kernel, and the first original kernel does not contain the first trigger signal; When the execution of the first kernel ends, the execution of the second kernel is triggered based on the first trigger signal.
[0098] In addition, the logic instructions in the above-mentioned memory 630 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the present invention, or the part that contributes to the relevant technology or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0099] On the other hand, the present invention further provides a computer program product, the computer program product comprising a computer program, the computer program may be stored on a non-transitory computer-readable storage medium, and when the computer program is executed by a processor, the computer can execute the kernel execution method provided by the above methods, the method comprising: Starting and executing a first kernel, and in the process of starting and executing the first kernel, starting and suspending a second kernel, wherein the first kernel is a kernel having a first trigger signal added to the end of a first original kernel, and the first original kernel does not contain the first trigger signal; When the execution of the first kernel ends, the execution of the second kernel is triggered based on the first trigger signal.
[0100] In another aspect, the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the kernel execution method provided by the above methods is implemented, and the method includes: Starting and executing a first kernel, and in the process of starting and executing the first kernel, starting and suspending a second kernel, wherein the first kernel is a kernel having a first trigger signal added to the end of a first original kernel, and the first original kernel does not contain the first trigger signal; When the execution of the first kernel ends, the execution of the second kernel is triggered based on the first trigger signal.
[0101] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0102] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the relevant technology can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiment.
[0103] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A kernel execution method, characterized in that: include: Starting and executing a first kernel, and in the process of starting and executing the first kernel, starting and suspending a second kernel, wherein the first kernel is a kernel having a first trigger signal added to the end of a first original kernel, and the first original kernel does not contain the first trigger signal; When the execution of the first kernel ends, the execution of the second kernel is triggered based on the first trigger signal.
2. The kernel execution method according to claim 1, characterized in that: Also includes: In the process of executing the second kernel, starting and suspending the third kernel, wherein the second kernel is a kernel having a second trigger signal added to the end of the second original kernel, and the second original kernel does not contain the second trigger signal; When the execution of the second kernel ends, the execution of the third kernel is triggered based on the second trigger signal.
3. The kernel execution method according to claim 1, characterized in that: The second kernel includes a first part and a second part, wherein the first part and the second part are obtained by splitting based on a wait instruction in the second kernel; The starting and suspending of the second kernel comprises: Starting the second kernel and executing the first part of the second kernel; After the first part is executed, suspending the second kernel; The triggering the second kernel to execute based on the first trigger signal includes: The second part is triggered to execute based on the first trigger signal.
4. The kernel execution method according to claim 3, characterized in that: The second kernel is a kernel having a wait instruction added to the beginning of the second original kernel, and the second original kernel does not include the wait instruction.
5. The kernel execution method according to claim 3, characterized in that: The first portion is independent of data generated by execution of the first kernel.
6. The kernel execution method according to any one of claims 1 to 5, characterized in that: The number of cores started simultaneously is less than or equal to two.
7. A kernel execution device, characterized in that: include: a first execution unit, configured to start and execute a first kernel, and start and suspend a second kernel during the process of starting and executing the first kernel, wherein the first kernel is a kernel having a first trigger signal added to the end of a first original kernel, and the first original kernel does not contain the first trigger signal; The second execution unit is configured to trigger the execution of the second kernel based on the first trigger signal when the execution of the first kernel ends.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the kernel execution method according to any one of claims 1 to 6 is implemented.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the kernel execution method according to any one of claims 1 to 6 is implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the kernel execution method according to any one of claims 1 to 6 is implemented.
