Computer-implemented method, hardware accelerator, and storage medium
By using an adaptive graph-to-stream mapping algorithm, kernels in the computation graph are divided into bands, and kernels are mapped to different streams for concurrent execution based on resource usage and dependencies. This solves the load imbalance problem in GPU multi-stream scheduling and improves GPU utilization efficiency and computing performance.
Patent Information
- Application Number
- CN202211576827.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-07
- Publication Date
- 2026-11-24
- Estimated Expiration
- 2042-12-07
AI Technical Summary
How to adaptively schedule multi-stream workloads in a graphics processing unit (GPU) to improve its utilization efficiency and overall computing performance, especially in deep learning tasks, reduce kernel startup overhead, and improve parallel processing efficiency.
By dividing the kernels in the computation graph into bands and mapping them to different streams for concurrent execution based on kernel resource usage and dependencies, an adaptive graph-to-stream mapping algorithm is used to insert synchronous kernels to maintain dependencies and periodically adjust the stream load to balance the workload.
It improves GPU utilization efficiency, enhances overall computing performance, reduces kernel startup overhead, and enables more efficient parallel processing.
Smart Images

Figure CN115964164B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a method for processing images using a graphics processing unit (GPU), and more particularly to a computer-implemented method, hardware accelerator, and storage medium capable of adapting a job scheduler to balance streaming workloads in the processor. Background Technology
[0002] Using dedicated processors such as Graphics Processing Units (GPUs) for deep learning (DL) has become standard practice. Recent DL frameworks have improved inference and training speeds by offloading the computationally intensive portions of their DL workloads to GPUs or other similar dedicated processors. On the GPU side, this is known as kernel launch. Kernel launch can involve the host CPU scheduling kernels onto the GPU. Launch overhead can become problematic when there are many kernels and their duration is short. Recent commercial GPUs offer a way to reduce this overhead by representing kernels as a computation graph and launching the computation graph as a single operation onto the GPU, rather than having the host CPU launch kernels one by one. On GPUs, multistreaming (such as HyperQ™) is a mechanism for enabling concurrent kernel execution. How kernels in the computation graph are mapped to multistreams in the GPU is crucial to GPU utilization efficiency and overall computational performance.
[0003] Therefore, how to adapt the job scheduler to balance the workload of multiple streams in the processor, improve the utilization efficiency of the GPU, and enhance the overall computing performance is one of the problems that needs to be solved. Summary of the Invention
[0004] Embodiments of the present invention provide a computer-implemented method, hardware accelerator, and storage medium. By having kernels mapped to the same stream executed sequentially by the GPU, and kernels mapped to different streams executed concurrently by the GPU, the utilization efficiency of the GPU can be improved, and the overall computing performance can be enhanced.
[0005] A computer-implemented method according to one embodiment of the present invention includes receiving a computation graph for a graphics processing unit, the computation graph including multiple nodes and multiple edges, the multiple nodes representing multiple kernels to be executed by the graphics processing unit, and the multiple edges representing execution dependencies between the multiple kernels; performing one or more band partitions on the computation graph to determine multiple bands of the multiple kernels, each band including one or more kernels that can be executed simultaneously on the graphics processing unit; obtaining a kernel resource table including resource usage of each kernel; mapping the multiple kernels into multiple streams according to the multiple bands and the kernel resource table; and executing the multiple streams on the graphics processing unit; wherein kernels mapped to the same stream are executed sequentially by the graphics processing unit, while kernels mapped to different streams are executed simultaneously by the graphics processing unit.
[0006] The above method, wherein the step of mapping the multiple kernels into multiple streams according to the multiple bands and the kernel resource table further includes: for one or more kernels from the same band among the multiple bands, determining one or more kernels whose resource usage is greater than a threshold; assigning the determined one or more kernels to the same stream; and assigning other kernels in the same band to multiple streams in a cyclical manner.
[0007] The method described above, wherein the step of obtaining a kernel resource table including the usage of each kernel resource further includes: obtaining the kernel resource table from a compiler that compiles multiple kernels.
[0008] The method described above, wherein the step of performing one or more band partitions on the computation graph to determine multiple bands of the multiple kernels further includes: performing a breadth-first search on the computation graph to determine the depth of each of the multiple nodes in the computation graph; and determining one or more kernels from the same depth as a band.
[0009] The above method, wherein the step of performing a breadth-first search on the computation graph to determine the depth of each of the plurality of nodes in the computation graph further includes: when a node appears on multiple paths in the computation graph, determining, based on the breadth-first search, multiple depths corresponding to the node on the multiple paths respectively; and determining the maximum depth among the multiple depths as the depth of the node.
[0010] The above method, wherein the plurality of streams includes a computing unified device architecture stream.
[0011] The above method further includes: inserting one or more synchronized kernels into one or more streams to maintain the correctness of execution dependencies between kernels.
[0012] The method described above, wherein the step of inserting one or more synchronous kernels into one or more streams further comprises: when the kernel preceding the first stream depends on the execution of the kernel preceding the second stream, inserting a synchronous kernel before the kernel preceding the first stream, so that the graphics processing unit executes the kernel preceding the first stream only when the kernel preceding the second stream is executed.
[0013] The method described above further includes: periodically detecting load imbalances among the plurality of streams; and remapping a kernel from one stream to another to balance the load across the plurality of streams.
[0014] In the above method, the computation graph is executed by the graphics processing unit for multiple iterations, and the remapping of the kernel from one stream to another affects the execution of the current iteration of the computation graph, rather than future iterations.
[0015] The method described above, wherein the step of executing the plurality of streams on the graphics processing unit further includes: retrieving kernels from the heads of the plurality of streams; and allocating the retrieved kernels to the plurality of stream multiprocessors for parallel processing.
[0016] The method described above, wherein the step of retrieving the kernel from the head of the plurality of streams further includes: retrieving the kernel from the head of the plurality of streams in a cyclic manner.
[0017] A hardware accelerator according to one embodiment of the present invention includes: a graph partitioning module for receiving a computation graph for a graphics processing unit (GPU), the computation graph including multiple nodes and multiple edges, the multiple nodes representing multiple kernels to be executed by the GPU, the multiple edges representing execution dependencies between the multiple kernels, performing one or more band partitioning on the computation graph to determine multiple bands of the multiple kernels, each band including one or more kernels that can be executed simultaneously on the GPU; a kernel resource table acquisition module for acquiring a kernel resource table including the resource usage of each kernel; a kernel stream mapping module for mapping the multiple kernels into multiple streams according to the multiple bands and the kernel resource table; and a global scheduling module for allocating kernels in the multiple streams to multiple stream multiprocessors for parallel processing.
[0018] In the aforementioned hardware accelerator, the kernel resource table acquisition module is further configured to obtain the kernel resource table from the compiler that compiles the plurality of kernels.
[0019] In the aforementioned hardware accelerator, the graph wave partitioning module is further configured to perform a breadth-first search on the computation graph to determine the depth of each of the plurality of nodes in the computation graph; and to determine one or more kernels from the same depth as a waveband.
[0020] The aforementioned hardware accelerator, wherein the plurality of streams includes a computing unified device architecture stream.
[0021] The aforementioned hardware accelerator further includes: a synchronous kernel insertion module for inserting a synchronous kernel before the kernel preceding the first stream when the kernel preceding the first stream depends on the execution of the kernel preceding the second stream, so that the graphics processing unit executes the kernel preceding the first stream only when the kernel preceding the second stream is executed.
[0022] The aforementioned hardware accelerator further includes: a kernel remapping module for periodically detecting load imbalances among the plurality of streams; and remapping a kernel from one stream to another to balance the load in the plurality of streams.
[0023] In the aforementioned hardware accelerator, the computation graph is executed by the graphics processing unit for multiple iterations, and the remapping of the kernel from one stream to another affects the execution of the current iteration of the computation graph, rather than future iterations.
[0024] A storage medium according to one embodiment of the present invention is used to store a computer program, wherein the computer program is used to execute any of the computer-implemented methods as described in claims 1-12.
[0025] These and other features of the disclosed systems, methods, and hardware devices, as well as the methods of operation and functions of the associated structural elements, and the combination of component and manufacturing economics, will become more apparent from the following description and the appended claims with reference to the accompanying drawings, wherein similar reference numerals denote corresponding portions in the drawings. However, it should be understood that the drawings are for illustration and description only and are not intended to be limiting of the invention.
[0026] The present invention will be described in detail below with reference to the accompanying drawings and specific embodiments, but this is not intended to limit the present invention. Attached Figure Description
[0027] Figure 1 This is an exemplary workflow for scheduling computing tasks on a GPU according to an embodiment of the present invention.
[0028] Figure 2A This is a schematic diagram of the band division of a calculation graph according to an embodiment of the present invention.
[0029] Figure 2B This is a schematic diagram of graph-to-stream mapping of a GPU according to an embodiment of the present invention.
[0030] Figure 3 This is a schematic diagram comparing the performance of different graph-to-stream scheduling methods according to some embodiments of the present invention.
[0031] Figure 4A This is a flowchart illustrating a computer-implemented method according to an embodiment of the present invention.
[0032] Figure 4B This is a schematic diagram of the structure of a hardware accelerator according to an embodiment of the present invention.
[0033] Figure 5 This is a schematic diagram of the hardware environment for implementing a computer-based method according to an embodiment of the present invention. Detailed Implementation
[0034] The structural and working principles of the present invention will be described in detail below with reference to the accompanying drawings:
[0035] The present invention is provided to enable those skilled in the art to make and use the embodiments, and is provided in the context of specific applications and their requirements. Various modifications to the disclosed embodiments will be apparent to those skilled in the art, and the general principles defined herein can be applied to other embodiments and applications without departing from the spirit and scope of this specification. Therefore, this specification is not limited to the illustrated embodiments, but should be accorded the broadest scope consistent with the principles and features disclosed herein.
[0036] The performance of GPU architectures continues to improve with each new generation. Modern GPUs are so fast that in many meaningful cases, the time taken for each GPU operation (such as a kernel or memory copy) is now measured in microseconds. However, submitting each operation to the GPU incurs overhead, which is becoming increasingly important in more and more situations.
[0037] Real-world applications perform a large number of GPU operations: the typical pattern involves many iterations (or time steps), with multiple operations at each step. For example, simulations of molecular systems iterate over multiple time steps, where the position of each molecule is updated at each step based on the forces exerted by other molecules. For simulation techniques that accurately model such systems, each time step typically requires multiple algorithmic stages corresponding to multiple GPU operations. If each of these operations were launched separately to the GPU and completed quickly, the overhead could accumulate, leading to a significant overall performance degradation.
[0038] To address these issues, commercial GPU products have incorporated computation graphs to allow jobs / kernels to be defined as graphs rather than single operations. Figure 1 As described herein. It is understood that GPUs are used for illustrative purposes, and in this disclosure, unless otherwise stated, processors equivalent to GPUs or processors that provide parallel processing (e.g., dedicated processors, neural processors, etc.) may also be used.
[0039] Figure 1 This is an exemplary workflow for scheduling computing tasks on a GPU according to an embodiment of the present invention. Figure 1 As shown, Figure 1 The workflow described provides a mechanism to represent multiple GPU cores as a computation graph 120 and initiate the computation graph with a single CPU operation, thereby reducing overhead. In the context of the GPU, a kernel refers to a function executed on the GPU. The computation graph 120 includes multiple nodes representing kernels and multiple edges representing dependencies between kernels. A first kernel that depends on a second kernel (e.g., represented by an arrow from the second kernel pointing to a node of the first kernel) can be executed after the second kernel is executed.
[0040] However, reducing startup overhead is only the first step in optimizing the overall computing performance of a GPU. The next step is to fully exploit the parallelism within the GPU. It is well known that GPUs have the powerful ability to run thousands of threads simultaneously. For example, multi-streaming mechanisms can be used in GPUs to achieve concurrent kernel execution. If resources (GPU computing power and / or memory space) are sufficient, kernels from different streams can run concurrently, while kernels within a single stream are executed sequentially in a FIFO (First-In, First-Out) order.
[0041] There are two approaches to utilizing GPU capabilities: (1) fully utilizing GPU kernels within a single GPU stream 140, and (2) running multiple GPU tasks concurrently using multiple GPU streams 142. The single-stream approach maintains sufficient intra-kernel parallelism for each kernel so that each kernel can fully utilize the GPU's computational power. However, depending on the kernel implementation and the size of the tensors computed in each kernel, intra-kernel parallelism may be insufficient, potentially leading to serialized execution of all kernels and resulting in low utilization. In contrast, the multi-stream approach better guarantees full utilization of GPU computational power in most cases. Figure 1 As shown, using two streams, 142-1 and 142-2, to execute tasks B and C in parallel can improve overall computational efficiency.
[0042] Existing implementations of multi-streaming schemes involve manually assigning kernels to different streams in a round-robin fashion. These methods are inefficient because, considering dependencies and resource consumption, they require programmer effort to carefully map the kernel graph to multiple streams (e.g., not automatically), and the graph stream mapping is static and not adaptive (e.g., the performance of the currently computed graph may be affected when a new kernel is submitted to the GPU).
[0043] To overcome the aforementioned technical deficiencies of existing implementations, this invention describes an automatic and adaptive graph-to-stream mapping when scheduling GPU kernels to maximize parallel processing within the GPU.
[0044] To better understand the present invention, exemplary definitions of the following terms are provided.
[0045] Stream: It can refer to a sequence of device operations (such as kernel startup) processed sequentially by a GPU device.
[0046] Work queue: This refers to the hardware on the GPU that sequentially queues kernel startup commands from a stream. The kernel scheduler selects a command from a work queue and initiates computation on the GPU. The work queue can also refer to the hardware that implements the streaming mechanism.
[0047] Streaming multiprocessor (SM): This likely refers to the basic computational unit that executes a block of threads. It may include the hardware resources for execution, such as execution units, registers, L1 cache / shared memory, etc. Multiple blocks of threads can reside on the same SM.
[0048] Stream processor (SP): It can refer to a basic computing unit that executes a warp.
[0049] warp: It can refer to a group of threads (e.g., 32 threads), which is the basic unit of execution and scheduling.
[0050] Thread block: It can refer to a programming abstraction that represents a group of threads that can execute concurrently on a single SM and share the same L1 / shared memory.
[0051] Figure 2A This is a schematic diagram of band partitioning of a computation graph according to an embodiment of the present invention. Note that two kernels can be processed in parallel when (1) there are no dependencies between them and (2) there are sufficient resources to execute both kernels simultaneously. This computation graph partitioning step aims to identify kernels that may be executed concurrently across multiple streams from the perspective of kernel dependencies. These kernels in the computation graph can be divided into multiple bands. Kernels in each band are independent of each other and can be executed concurrently on the GPU. A kernel in a given band (denoted as band (i+1)) may depend on kernels in any preceding band, and therefore may not be executed before band i is executed.
[0052] by Figure 2ATaking computation graph 210 as an example, K2 and K5 depend on the execution of K1, K3 and K6 depend on the execution of K2, K6 depends on the execution of K2 and K5, and K4 depends on the execution of K1 and K3. To partition the computation graph, a breadth-first search (BFS) algorithm, such as K1, can be executed from the root node to determine the depth of each node among multiple nodes in the computation graph. Nodes with the same depth can be partitioned into the same band. Here, the "depth" of a node can refer to the distance between the root node and the node. For example, BFS of K1 can determine that the depth of K1 is 0, the depth of K2 and K5 is 1, the depth of K3 and K6 is 2, and the depth of K4 is 3. Based on the node depth, band partitioning 220 can partition K1 into band 220-1, K2 and K5 into band 220-2, K3 and K6 into band 220-3, and K4 into band 220-4.
[0053] In some embodiments, a computation graph may have a node that exists in multiple paths from the root node, meaning that the corresponding kernel depends on multiple preceding kernels. The BFS algorithm can compute multiple depths for that node using different paths, and these depths may differ. In these cases, the maximum of the multiple depths can be chosen as the node's depth for band division. For example, according to BFS, the depth of K4 in computation graph 210 can be 1 (using the path from K1 to K4) or 3 (using the path from K1, K2, K3 to K4), with depth 3 being used as the final depth of K4.
[0054] After graph 210 is divided into bands, kernels are partitioned based on dependencies, with kernels from the same band being independent. However, as mentioned above, whether two kernels can execute simultaneously depends on their resource requirements. This means that two independent kernels may not be able to execute concurrently on the GPU due to insufficient resources. Here, resources may include one or more factors: the number of thread blocks, the number of threads, the number of registers, the size of shared memory, etc. Therefore, when mapping kernels to multiple streams, the graph-to-stream mapping also needs to consider the kernel's resource usage to achieve optimal concurrency.
[0055] Figure 2B This is a schematic diagram of graph-to-stream mapping in a GPU according to an embodiment of the present invention. (Combined with...) Figure 2A , 2B As shown, in Figure 2B In the example shown, computation graph 210 is mapped into three streams, which are then dispatched for processing in the GPU using various functions (typically denoted as modules). Although the modules are described as internal GPU modules (e.g., front-end interfaces), some of these modules may be implemented in a job scheduler or accelerator external to the GPU. In some embodiments, these modules may be implemented by one or more corresponding circuits.
[0056] In some embodiments, the graph-to-flow mapping can begin by dividing the computation graph 210 into multiple bands 220-1, 220-2, 220-3, and 220-4 using a graph wave partitioning module. The graph wave partitioning module can perform a breadth-first search (BFS) on the computation graph 210 to partition the nodes (kernels) in the computation graph into multiple bands 220-1, 220-2, 220-3, and 220-4, where kernels within the same wave are independent of each other and can be executed concurrently. The partitioning process can be similar to... Figure 2A The exemplary implementation described herein.
[0057] In some embodiments, the graph-to-flow mapping can determine the kernel resource usage of each of the plurality of kernels represented by computation graph 210. Some exemplary resources may include the number of thread blocks, the number of threads, the number of registers, the size of shared memory, etc. In some embodiments, the resource usage of each kernel can be obtained from the compiler at compile time. In some embodiments, kernel resource usage can be stored in a kernel resource table.
[0058] In some embodiments, the band partitioning and kernel resource table output from the wave partitioning module can be fed into the kernel stream mapping module to allocate the kernel band partitioning to available streams. In some cases, a stream can refer to a Compute Unified Device Architecture (CUDA) stream. Kernels within the same stream are allocated to the SM in a first-in-first-out manner for sequential execution, while kernels from different streams can be allocated to the SM for concurrent execution. In some implementations, allocation includes an iterative process that executes the following two rules: (1) allocating kernels from the same wave to different streams in a round-robin manner, and (2) allocating the most resource-intensive kernels from the same wave to the same stream.
[0059] A fundamental principle behind rule (1) is that kernels from the same wave are independent of each other and can therefore be executed concurrently. Assigning them to different streams allows the GPU to execute these independent kernels concurrently. A fundamental principle behind rule (2) is that even if the most resource-intensive kernels from the same wave are independent of each other, the GPU may not be able to execute them simultaneously due to resource constraints. Therefore, assigning them to different streams not only fails to achieve concurrent execution but also introduces serialization between these streams, which effectively delays other kernels assigned to these streams. For these reasons, rule (2) is implemented to assign these resource-intensive kernels to the same stream and allow the GPU to execute them serially (because kernels in the same stream will be executed in a FIFO manner) without preventing the execution of other kernels assigned to other streams (e.g., available streams other than the one assigned to the resource-intensive kernel).
[0060] An exemplary implementation of the iterative process might include: sorting kernels within the same band based on resource usage, identifying kernels on the GPU whose resource usage exceeds available resources, assigning the identified kernels to the same stream, and cyclically assigning the remaining kernels to available streams. Available resources on the GPU can be predetermined as a threshold. In some embodiments, resource usage can be a weighted sum of different types of resource demands, and the threshold can be learned through experimentation or domain knowledge.
[0061] The iterative process described above handles intra-wavelength flow mapping; the focus now shifts to inter-wavelength flow mapping. A sequence of multiple bands represents data dependencies; therefore, the kernel for band (i+1) might not be executed before the kernel for band i. Thus, in some embodiments, the synchronization insertion module can be configured to insert a synchronization kernel S into one or more streams to maintain the correctness of kernel dependencies between streams. Specifically, when the kernel at the head of a first stream depends on the kernel executed at the head of a second stream, a synchronization kernel can be inserted before the kernel at the head of the first stream so that the GPU executes the kernel at the top of the first stream only when the kernel at the top of the second stream is executed. Here, the "head" of a stream refers to the first kernel in the stream. For example, as... Figure 2B As shown, K2 and K5 should not be executed before K1. Assigning K1 to stream W1 and then directly assigning K2 and K5 to streams W2 and W3 might cause the GPU to execute K1, K2, and K5 simultaneously (e.g., drawing the first kernel from all available streams for parallel processing). To maintain dependencies, a synchronization kernel S (e.g., a virtual kernel) can be inserted between streams W2 and W3 before K2 and K5 so that the GPU executes K1 before K2 or K5. Similarly, a synchronization kernel S can be inserted between K1 and K6 before assigning K6 to stream W1 so that K6 does not execute before K2 and K5.
[0062] In some cases, the kernel allocation process described above and / or the real-time execution of kernels may lead to workload imbalances among multiple streams. During real-time execution, kernels with other workloads may also be allocated to streams. For example, kernels X1 and X2 may be allocated to streams 1, 2, and 3 along with K1-K6 of the current computation graph 210. The allocation of X1 and X2 may also cause workload imbalances. To mitigate these imbalances, a kernel remapping module can be configured to periodically detect load imbalances among multiple streams and remap kernels from one stream to another to balance the load across the streams. Figure 2BAs shown, K1′ is initially assigned to stream W1 and then remapped to stream W2 to balance the workload. Here, K1-K6 can refer to the kernels executed in the first iteration of the workload (e.g., in GPU workloads, some workloads may include the same set of kernels executing in multiple iterations), while K1′ refers to the first kernel of the workload executed in the second iteration. K1′ may initially be assigned to stream W1 because its corresponding previous iteration's K1 was previously assigned to stream W1. However, the kernel remapping module can detect that, in the current case, K1′ can be assigned to stream W2 to balance the load. The remapping (e.g., K1′ from stream 1 to stream 2) may only affect the current iteration and not future iterations. That is, the iteration of K″ (the first kernel of the workload that will be executed in the third phase) may still initially be assigned to stream W1, but is subject to the remapping by the kernel remapping module for load balancing purposes.
[0063] After the graph-to-stream mapping is complete, or while the graph-to-stream mapping is in progress, the GPU's global scheduling module can begin fetching kernels from the heads of multiple streams and sending the fetched kernels to multiple stream multiprocessors (SMs) for parallel execution. In some embodiments, the global scheduling module can fetch kernels from the heads of multiple streams in a cyclical manner. When the global scheduling module detects that it cannot execute a fetched kernel due to insufficient resources, it pauses execution until the kernel has finished executing, and then fetches more kernels from other streams.
[0064] Figure 3 This is a schematic diagram comparing the performance of different graph-to-stream scheduling methods according to some embodiments of the present invention. Figure 3 In the example shown, computation graph 340, with multiple kernels K1-K9 and multiple dependent edges, is used as an example workload for graph-to-stream scheduling to three streams (S1-S3). Besides the kernels within computation graph 340, other workloads (e.g., Figure 3 Additional kernels X1 and X2 (not shown in other computation graphs) also need to be scheduled into the three streams. Graphs 310, 320, and 330 illustrate how kernels are mapped into the streams. It is assumed that the runtime of each kernel is the same or similar, so the width of each bar in the graphs (representing the execution of the corresponding kernel) is the same or similar.
[0065] Figure 310 illustrates a single-stream scheduling method where all kernels are assigned to the same stream. This scheduling method can work well when kernels are interdependent and need to be executed sequentially. However, when kernels may execute concurrently, the single-stream scheduling method can lead to low GPU utilization.
[0066] Chart 320 illustrates Figure 2AThe graph-to-flow scheduling with band partitioning is illustrated in Figure 340. Specifically, the kernels in Figure 340 are partitioned into waves using an algorithm like BFS, where kernels with the same depth (e.g., the depth from the root node in Figure 340) are grouped into the same waveband. Kernels within each waveband are independent of each other; a kernel in the (i+1)th waveband may not be executed until a kernel in the ith waveband is executed, where i is an integer, i >= 1 (assuming the root node K1 is partitioned into the first waveband). The graph-to-flow mapping in Figure 320 can iterate over the waves sequentially, arranging the kernels in each waveband into available flows in a round-robin fashion. For example, assuming K1 is in wave W1, and K2, K5, K8, and K9 are in wave W2, K1 is mapped to flow S1, K2 is mapped to flow S2, K5 is mapped to flow S3, K8 is mapped back to flow S1 (round-robin), and K9 is mapped to flow S2. In computation graph 340, we further assume that K2 and K5 are resource-intensive tasks, and K2 cannot be executed by the GPU simultaneously. Since this scheduling method does not consider kernel resource consumption, K2 and K5 are mapped to two different streams simply because they originate from the same stream. This is different from graph 330.
[0067] Figure 330 illustrates a graph-to-flow scheduling method, in which Figure 2A The band division shown and Figure 2B The kernel resource table used in the illustrated embodiment. Besides using algorithms such as BFS to divide the kernels in computational diagram 340 into bands, the resource usage of each kernel is also considered during scheduling. For example... Figure 2B The global scheduling module can iterate through bands sequentially and map kernels to streams using the following two rules: (1) assigning kernels from the same band to different streams in a cyclical manner, and (2) assigning the most resource-intensive kernels from the same band to the same stream. When conflicts exist, rule (2) takes precedence over rule (1). Figure 3 In the example shown, since both K2 and K5 are resource-intensive, they are mapped to the same flow (flow S2) shown in Figure 330 according to rule (2). This allows other independent kernels from the same band to execute concurrently more quickly. For example, K8 in Figure 330 is now mapped to flow S3, which can execute immediately after K2 and concurrently with K5.
[0068] from Figure 3 The comparison shows that the scheduling shown in Chart 330 is more efficient than that shown in Charts 310 and 320. In other words, Figure 2A The band division shown is as follows: Figure 2B The automatic adaptive graph-to-flow scheduling method using kernel resource tables in the illustrated embodiment offers technical improvements over other scheduling methods.
[0069] Figure 4A This is a flowchart illustrating a computer-implemented method according to an embodiment of the present invention. Figure 4B This is a schematic diagram of the structure of a hardware accelerator according to an embodiment of the present invention. Figure 5 This is a schematic diagram of the hardware environment for implementing a computer-based method according to an embodiment of the present invention. The computer-based method 400 of the present invention can be implemented by... Figure 4B The hardware accelerator shown or Figure 5 Implemented in the hardware environment shown. Exemplary steps of method 400 are as follows: Figure 4A The steps shown will be used to illustrate this.
[0070] Step S410 includes receiving a computation graph for a graphics processing unit (GPU), the computation graph including (1) multiple nodes representing multiple cores for GPU execution and (2) multiple edges representing execution dependencies between the multiple cores.
[0071] Step S420 includes performing band partitioning on the computation graph to determine bands of a plurality of cores, each band including cores that can be executed concurrently on the GPU. In some embodiments, performing band partitioning on the computation graph to determine the cores of the plurality of bands includes: performing breadth-first search (BFS) on the computation graph to determine the depth of each node of the plurality of nodes in the computation graph; and determining the kernels from the same depth as the kernels of the bands. In some embodiments, performing BFS on the computation graph to determine the depth of each of the plurality of nodes may include: when a node appears on more than one path from the root node in the computation graph, determining more than one depth of the node corresponding to each of the more than one path based on BFS; and determining the maximum depth of the more than one depth as the depth of the node.
[0072] Step S430 includes obtaining a kernel resource table containing the resource usage of each kernel. In some embodiments, obtaining the kernel resource table containing the resource usage of each kernel represented in the computation graph includes obtaining the kernel resource table from a compiler that compiles multiple kernels.
[0073] Step S440 includes mapping multiple kernels to multiple streams based on multiple bands and a kernel resource table. In some embodiments, mapping multiple kernels to multiple streams based on multiple bands and a kernel resource table includes: for kernels from the same band in multiple bands, identifying one or more kernels whose resource usage is greater than a threshold; assigning one or more identified kernels to the same stream; and assigning other kernels from the same band to multiple streams in a cyclical manner. In some embodiments, the multiple streams include Compute Unified Device Architecture (CUDA) streams.
[0074] Step S450 includes executing multiple streams on the GPU, wherein kernels mapped to the same stream are executed sequentially by the GPU, and kernels mapped to different streams are executed concurrently by the GPU. In some embodiments, executing multiple streams on the GPU includes: retrieving kernels from the heads of the multiple streams; and allocating the retrieved kernels to multiple stream multiprocessors (SMs) for parallel execution. In some embodiments, retrieving kernels from the heads of the multiple streams includes: retrieving kernels from the heads of the multiple streams in a round-robin manner.
[0075] In some embodiments, method 400 may further include inserting a synchronization kernel into one or more streams to maintain kernel dependency correctness between kernels. In some embodiments, the step of inserting a synchronization kernel includes: inserting a synchronization kernel before the kernel of the first stream header when the kernel of the first stream header depends on the execution of the kernel of the second stream header, so that the GPU executes the kernel of the first stream header only when the kernel of the second stream header is executed.
[0076] In some embodiments, method 400 may further include periodically detecting load imbalances among multiple flows; and remapping kernels from one flow to another to balance the load among the multiple flows. In some embodiments, the computation graph is being executed by the GPU for multiple iterations, and remapping kernels from one flow to another only affects the current iteration of the computation graph and does not affect future iterations.
[0077] Figure 4B This is a schematic diagram of the structure of a hardware accelerator according to an embodiment of the present invention. Figure 4B The components shown in hardware accelerator 480 are for illustrative purposes only. Depending on the implementation, the hardware accelerator may include more, fewer, or alternative components. In some embodiments, the hardware accelerator may refer to the front end of the GPU or an accelerator coupled to the GPU.
[0078] Specifically, such as Figure 4B As shown, the hardware accelerator 480 of the present invention includes a graph wave partitioning module 482, a kernel resource table acquisition module 484, a kernel stream mapping module 486, and a global scheduling module 487. The graph wave partitioning module 482 can be configured to receive a computation graph of the GPU, the computation graph including (1) multiple nodes representing multiple kernels to be executed by the GPU and (2) multiple edges representing execution dependencies between multiple kernels; and to perform wave partitioning on the computation graph to determine kernels of multiple wavebands, each waveband including kernels executed concurrently on the GPU. The kernel resource table acquisition module 484 can be configured to acquire a kernel resource table containing the resource usage of each kernel. The kernel stream mapping module 486 can be configured to map multiple kernels into multiple streams based on multiple wavebands and the kernel resource table. The global scheduling module 487 can be configured to schedule the mapped kernels in the multiple streams to multiple stream multiprocessors (SMs) for parallel processing.
[0079] In some embodiments, the hardware accelerator 480 may further include a synchronous kernel insertion module configured to insert a synchronous kernel before the kernel of the first stream header when the kernel of the first stream header depends on the execution of the kernel of the second stream header, so that the GPU executes the kernel of the first stream header only when the kernel of the second stream header is executed.
[0080] In some embodiments, the hardware accelerator 480 may further include a kernel remapping module configured to: periodically detect load imbalances between multiple streams; and remap the kernel from one stream to another to balance the load between the multiple streams.
[0081] Figure 5 This is a schematic diagram of the hardware environment for implementing a computer-based method according to an embodiment of the present invention. Figure 5 As shown, Figure 5 The hardware device 500 in the text describes the internal structure of the scheduler 520 and the GPU front-end (or GPU accelerator) 530, as well as the data and instruction flow between the scheduler 520, the GPU front-end 530 and the external memory 510.
[0082] like Figure 5 As shown, the scheduler 520 may include multiple processors 522 and a cache 521 shared by the multiple processors 520. Each processor 522 may include an instruction fetch unit (IFU) 525, an instruction decode unit (IDU) 526, an instruction send unit (ITU) 527, and an instruction execution unit (IEU) 528.
[0083] In some embodiments, the IFU 525 can fetch instructions or data to be executed from the memory 510 to the register set 524. After obtaining the instructions or data, the scheduler 520 enters the instruction decoding stage. The IDU 526 decodes the fetched instructions according to a predetermined instruction format to determine operand fetch information, wherein the operands are necessary to execute the fetched instructions. In some embodiments, the operand fetch information may include immediate data, registers, or pointers or addresses to other software / hardware that provide the operands.
[0084] In some embodiments, ITU 527 can be configured between IDU 526 and IEU 528 for instruction scheduling and management. It can efficiently distribute instructions to different IEU 528s for parallel processing.
[0085] In some embodiments, after ITU 527 assigns an instruction to an IEU 528, the IEU 528 can execute the instruction. However, if the IEU 528 determines that the instruction should be executed by the GPU front-end 530, it can forward the instruction to the appropriate GPU front-end 530 for execution. For example, if the instruction points to a GNN computation based on the input graph, the IEU 528 can send the instruction to the GPU front-end 530 via bus channel 531 so that the GPU front-end 530 can execute the instruction.
[0086] In some embodiments, the GPU front end 530 may include multiple stream multiprocessors (SMs) 536. Figure 5 Four SMs 536 are shown, but those skilled in the art will understand that the GPU front end 530 may also include other numbers of SMs 536, command processor 537, direct memory access (DMA) interface 535, and bus channel 531.
[0087] Bus channel 531 may include channels through which instructions / data enter and leave the GPU front-end 530. DMA interface 535 may refer to a function provided by some computer bus architecture that allows devices to directly read data from and / or write data to memory 510. This contrasts with a method where all data transfers between devices must pass through scheduler 520. Figure 5 The architecture described in the document greatly improves the efficiency of data access. For example, the core of the GPU front-end 530 can directly access memory 510 and read the parameters of the neural network model (e.g., the weights of each node in the graph) and / or input data.
[0088] Command processor 537 can be configured to distribute instructions sent by scheduler 520 to GPU front-end 530 via IEU 528 to SM 536 for execution. After instructions to be executed enter GPU front-end 530 from bus channel 531, they can be cached in command processor 537, and command processor 537 can select SM 536 and distribute instructions to SM 536 for execution. In addition, command processor 537 can also be responsible for synchronization operations between SM 536.
[0089] The present invention also provides a storage medium for storing a computer program for executing any of the computer-implemented methods described above.
[0090] Each process, method, and algorithm described in the preceding sections can be embodied in a code module executed by one or more computer systems or computer processors (including computer hardware) and can be fully or partially automated by them. These processes and algorithms can be implemented, partially or entirely, in application-specific circuitry.
[0091] When the functions disclosed in this invention are implemented as software functional units and sold or used as independent products, they can be stored in a processor-executable, non-volatile, computer-readable storage medium. Specific technical solutions (all or part) disclosed herein, or aspects that contribute to the prior art, can be embodied in the form of a software product. The software product can be stored in a storage medium containing multiple instructions to cause a computing device (which may be a personal computer, server, network device, etc.) to perform all or part of the steps of the methods of the embodiments of this application. The storage medium may include a flash drive, portable hard disk drive, ROM, RAM, magnetic disk, optical disk, another medium that can be used to store program code, or any combination thereof.
[0092] Specific embodiments further provide a system including a processor and a non-transitory computer-readable storage medium storing processor-executable instructions to cause the system to perform operations corresponding to the steps in any of the methods of the above embodiments. Specific embodiments also provide a non-transitory computer-readable storage medium configured with instructions executable by one or more processors to cause one or more processors to perform operations corresponding to the steps in any of the methods of the above embodiments.
[0093] The embodiments disclosed herein can be implemented through a cloud platform, server, or group of servers (collectively referred to as the "service system") that interacts with a client. The client can be a terminal device or a client registered by a user on the platform, wherein the terminal device can be a mobile terminal, a personal computer (PC), or any device on which the platform application can be installed.
[0094] The various features and processes described above can be used independently or combined in various ways. All possible combinations and sub-combinations are intended to fall within the scope of this disclosure. Furthermore, certain method or process modules may be omitted in some embodiments. The methods and processes described herein are not limited to any particular order, and the associated blocks or states may be executed in other suitable orders. For example, the described blocks or states may be executed in a non-specifically disclosed order, or multiple blocks or states may be combined into a single block or state. Example blocks or states may be executed sequentially, simultaneously, or otherwise. Blocks or states may be added to or removed from the disclosed exemplary embodiments. The configuration of the exemplary systems and components described herein may differ from that described. For example, elements may be added, removed, or rearranged compared to the disclosed exemplary embodiments.
[0095] The various operations of the example methods described herein can be performed at least partially by an algorithm. This algorithm may include program code or instructions stored in memory (e.g., the aforementioned non-transitory computer-readable storage medium). Such an algorithm may include a machine learning algorithm. In some embodiments, the machine learning algorithm may not be explicitly programmed into the computer to perform the function, but may learn from training data to generate a predictive model that performs the function.
[0096] The various operations of the example methods described herein can be performed, at least in part, by one or more processors configured either temporarily (e.g., by software) or permanently to perform the relevant operations. Whether temporary or permanent, these processors can constitute the engine of a processor implementation that runs to perform one or more of the operations or functions described herein.
[0097] The methods described herein can be implemented at least in part by a processor, with one or more specific processors as examples of hardware. For example, at least some operations of a method can be performed by one or more processors or an engine implemented by a processor. Furthermore, one or more processors can also run in a “cloud computing” environment or as “Software as a Service” (SaaS) to support the performance of the relevant operations. For example, at least some operations can be performed by a set of computers (e.g., machines including processors) that can be accessed via a network (e.g., the Internet) and one or more suitable interfaces (e.g., application programming interfaces (APIs)).
[0098] The performance of certain operations can be distributed across processors, residing not only within a single machine but also deployed across multiple machines. In some exemplary embodiments, the processor or processor-implemented engine may reside in a single geographic location (e.g., in a home environment, office environment, or server farm). In other exemplary embodiments, the processor or processor-implemented engine may be distributed across multiple geographic locations.
[0099] In this specification, multiple instances can implement components, operations, or structures described as single instances. Although individual operations of one or more methods are described and illustrated as separate operations, one or more separate operations can be performed concurrently, and there is no requirement that these operations must be performed in the order described. Structures and functionalities presented as independent components in the example configurations can be implemented as composite structures or components. Similarly, structures and functionalities presented as single components can be implemented as separate components. These and other variations, modifications, additions, and improvements are all within the scope of this document.
[0100] While an overview of the subject matter has been described with reference to specific example embodiments, various modifications and alterations may be made to these embodiments without departing from the broader scope of embodiments of this disclosure. Throughout this document, for convenience only, the term "invention" may be used individually or collectively to refer to these embodiments of the subject matter, and if more than one is disclosed, it is not intended to voluntarily limit the scope of this application to any single disclosure or concept.
[0101] The embodiments illustrated herein have been described in sufficient detail to enable those skilled in the art to practice the disclosed teachings. Other embodiments may be used and derived therefrom to make structural and logical substitutions and changes without departing from the scope of the invention. Therefore, the detailed description is not intended to be limiting, and the scope of the various embodiments is defined only by the appended claims and all their equivalents to which those claims are entitled.
[0102] Any process descriptions, elements, or blocks in the flowcharts described herein and / or in the accompanying drawings should be understood to represent modules, segments, or code segments, including one or more executable instructions for implementing specific logical functions or steps in the process. Alternative implementations are included within the scope of the embodiments described herein, in which elements or functions may be removed from or executed out of order, depending on the functionality involved, including execution substantially simultaneously or in reverse order, as understood by those skilled in the art.
[0103] Here, "or" is inclusive, not exclusive, unless explicitly stated or indicated by the context. Therefore, "A, B, or C" here means "A, B, A and B, A and C, B and C, or A, B, and C," unless explicitly stated or indicated by the context. Furthermore, "and" is both common and individual, unless explicitly indicated or indicated by the context. Therefore, "A and B" here means "A and B, common or individual," unless explicitly stated or indicated by the context. Additionally, multiple instances of the resources, operations, or structures described herein may be provided as a single instance. Furthermore, the boundaries between various resources, operations, engines, and data stores are somewhat arbitrary, and specific operations are described within the context of a particular illustrative configuration. The allocation of other functionalities is conceivable and may fall within the scope of various embodiments of this disclosure. Generally, structures and functionalities presented as separate resources in the example configuration may be implemented as combined structures or resources. Similarly, structures and functionalities presented as single resources may be implemented as separate resources. These and other variations, modifications, additions, and improvements are all within the scope of embodiments of this disclosure represented by the appended claims. Therefore, this specification and accompanying drawings should be viewed in an illustrative rather than restrictive sense.
[0104] The terms “comprising” or “including” are used to indicate the presence of a subsequently declared feature, but do not preclude the addition of other features. Conditional language, such as “may” or “may,” unless specifically stated or otherwise understood in the context in which they are used, is generally intended to express that certain embodiments include certain features, elements, and / or steps, while other embodiments do not. Therefore, such conditional language generally does not imply that a feature, element, and / or step is necessary in any way for one or more embodiments, or that one or more embodiments must include logic for determining whether such features, elements, and / or steps are included or performed in any particular embodiment, with or without user input or prompting.
[0105] Of course, the present invention may have other various embodiments. Without departing from the spirit and essence of the present invention, those skilled in the art can make various corresponding changes and modifications according to the present invention, but these corresponding changes and modifications should all fall within the protection scope of the appended claims.
Claims
1. A computer-implemented method, characterized in that, include: The system receives a computation graph for a graphics processing unit, the computation graph including multiple nodes and multiple edges, the multiple nodes representing multiple kernels to be executed by the graphics processing unit, and the multiple edges representing the execution dependencies between the multiple kernels; One or more band divisions are performed on the computation graph to determine multiple bands of the multiple kernels, each band including one or more kernels that can be executed simultaneously on the graphics processing unit; Retrieve the kernel resource table, which includes the usage information for each kernel resource; The multiple kernels are mapped into multiple streams based on the multiple bands and the kernel resource table, wherein kernels in the same stream include resource-intensive kernels from the same band, and the resource-intensive kernels represent kernels whose kernel resource usage exceeds the available resources on the graphics processing unit; and The plurality of streams are executed on the graphics processing unit; in Kernels mapped to the same stream are executed sequentially by the graphics processing unit, while kernels mapped to different streams are executed simultaneously by the graphics processing unit.
2. The method according to claim 1, characterized in that, The step of mapping the multiple kernels into multiple streams based on the multiple bands and the kernel resource table further includes: For one or more cores from the same band among the multiple bands, identify one or more cores whose resource usage is greater than a threshold; Assign the identified one or more kernels to the same stream; and Other kernels in the same band are distributed to multiple streams in a cyclic manner.
3. The method according to claim 1, characterized in that, The steps of obtaining a kernel resource table that includes the usage of each kernel resource further include: The kernel resource table is obtained from a compiler that compiles multiple kernels.
4. The method according to claim 1, characterized in that, The step of performing one or more band divisions on the computation graph to determine multiple bands of the multiple kernels further includes: Perform a breadth-first search on the computation graph to determine the depth of each of the plurality of nodes in the computation graph; and Identify one or more nuclei from the same depth as a band.
5. The method according to claim 4, characterized in that, The step of performing a breadth-first search on the computation graph to determine the depth of each of the plurality of nodes in the computation graph further includes: When a node appears on multiple paths in the computation graph, based on the breadth-first search, the node is determined to correspond to multiple depths on each of the multiple paths; and The maximum depth among the plurality of depths is determined as the depth of the node.
6. The method according to claim 1, characterized in that, The multiple streams include a computing unified device architecture stream.
7. The method according to claim 1, characterized in that, Further includes: Insert one or more synchronized kernels into one or more streams to maintain the correctness of execution dependencies between kernels.
8. The method according to claim 7, characterized in that, The step of inserting one or more synchronization kernels into one or more streams further includes: When the kernel preceding the first stream depends on the execution of the kernel preceding the second stream, a synchronization kernel is inserted before the kernel preceding the first stream, so that the graphics processing unit executes the kernel preceding the first stream only when the kernel preceding the second stream is executed.
9. The method according to claim 1, characterized in that, Further includes: Periodically detect load imbalances among the multiple streams; as well as A kernel is remapped from one stream to another to balance the load across the multiple streams.
10. The method according to claim 9, characterized in that, The computation graph is subjected to multiple iterations by the graphics processing unit, and The kernel's remapping from one stream to another affects the execution of the current iteration of the computation graph, not future iterations.
11. The method according to claim 1, characterized in that, The step of executing the plurality of streams on the graphics processing unit further includes: Retrieve the kernel from the header of the multiple streams; and The retrieved kernels are distributed to multiple streaming multiprocessors for parallel processing.
12. The method according to claim 11, characterized in that, The step of retrieving the kernel from the headers of the plurality of streams further includes: The kernel is taken from the head of the multiple streams in a cyclic manner.
13. A hardware accelerator, characterized in that, include: A wave partitioning module is used to receive a computation graph for a graphics processing unit. The computation graph includes multiple nodes and multiple edges. The multiple nodes represent multiple kernels to be executed by the graphics processing unit, and the multiple edges represent the execution dependencies between the multiple kernels. One or more wave partitions are performed on the computation graph to determine multiple wavebands of the multiple kernels. Each waveband includes one or more kernels that can be executed simultaneously on the graphics processing unit. A kernel resource table acquisition module is used to acquire a kernel resource table that includes the usage information of each kernel resource; A kernel stream mapping module is used to map the multiple kernels into multiple streams according to the multiple bands and the kernel resource table, wherein the kernels in the same stream include resource-intensive kernels from the same band, and the resource-intensive kernels represent kernels whose kernel resource usage exceeds the available resources on the graphics processing unit; as well as A global scheduling module is used to allocate kernels from the multiple streams to multiple stream multiprocessors for parallel processing.
14. The hardware accelerator according to claim 13, characterized in that, The kernel resource table acquisition module is also used to obtain the kernel resource table from the compiler that compiles the plurality of kernels.
15. The hardware accelerator according to claim 13, characterized in that, The graph wave partitioning module is also used to perform a breadth-first search on the computation graph to determine the depth of each of the plurality of nodes in the computation graph; and to determine one or more kernels from the same depth as a waveband.
16. The hardware accelerator according to claim 13, characterized in that, The multiple streams include a unified device architecture stream for computing.
17. The hardware accelerator according to claim 13, characterized in that, Further includes: A synchronous kernel insertion module is provided for inserting a synchronous kernel before the kernel preceding the first stream when the kernel preceding the first stream depends on the execution of the kernel preceding the second stream, so that the graphics processing unit executes the kernel preceding the first stream only when the kernel preceding the second stream is executed.
18. The hardware accelerator according to claim 13, characterized in that, Further includes: A kernel remapping module is used to periodically detect load imbalances among the multiple streams; as well as A kernel is remapped from one stream to another to balance the load across the multiple streams.
19. The hardware accelerator according to claim 18, characterized in that, The computation graph is subjected to multiple iterations by the graphics processing unit, and The kernel's remapping from one stream to another affects the execution of the current iteration of the computation graph, not future iterations.
20. A storage medium for storing computer programs, characterized in that: The computer program is used to perform any of the computer-implemented methods as described in claims 1-12.
Citation Information
Patent Citations
Placement and scheduling of radio signal processing dataflow operations
CN111247513A
