Reduced branch sorting computation unit
By reorganizing execution items across and within wavefronts in SIMD processors based on control flow targets, the method addresses control flow divergence, enhancing parallel processing efficiency and reducing slowdowns in graphics and ray tracing tasks.
Patent Information
- Application Number
- JP2021570323
- Authority / Receiving Office
- JP · JP
- Patent Type
- Patents
- Current Assignee / Owner
- Priority Date
- 2019-06-28
- Filing Date
- 2020-05-07
- Publication Date
- 2024-11-05
- Estimated Expiration
- 2040-05-07
AI Technical Summary
Single instruction multiple data (SIMD) processors experience slowdowns due to serialized execution of different control flow paths resulting from divergent control flow depending on data, leading to inefficient parallel processing.
Reorganizing execution items across and within wavefronts of a workgroup by identifying control flow targets, sorting execution items based on these targets, and assigning them to minimize branching, using techniques such as intra-wavefront and inter-wavefront reorganization.
Reduces control flow branches, enhancing parallel processing efficiency by ensuring simultaneous execution of multiple instructions, thereby improving performance in graphics rendering and ray tracing operations.
Smart Images

Figure 0007577691000004 
Figure 0007577691000005 
Figure 0007577691000006
Abstract
Description
[Technical field]
[0001] (CROSS REFERENCE TO RELATED APPLICATIONS) This application claims the benefit of U.S. Patent Application No. 16 / 457,873, filed June 28, 2019, the contents of which are incorporated herein by reference. [Background technology]
[0002] Description of Related Art Single instruction multiple data (SIMD) processors achieve parallelism of execution by using a single control flow with multiple items of data. Because different threads of execution may have different values for the data on which the control flow depends, the control flows may diverge if the control flow depends on the data. In such a situation, the different control flow paths are serialized, resulting in a slowdown.
[0003] A more detailed understanding may be had from the following description, given by way of example in conjunction with the accompanying drawings, in which: [Brief description of the drawings]
[0004] [Figure 1] 1 is a block diagram of an example device capable of implementing one or more features of the present disclosure. [Diagram 2] 1 is a block diagram of an accelerated processing device illustrating additional details associated with executing processing tasks on the device, according to an example. [Diagram 3] FIG. 1 illustrates a ray tracing pipeline for rendering graphics using ray tracing techniques, according to one example. [Figure 4] FIG. 1 illustrates a diagram showing serialization resulting from branching control flows, according to an example. [Figure 5A] FIG. 1 illustrates a technique for reducing control flow divergence by reorganizing execution items across workgroup wavefronts, according to one example. [Figure 5B]FIG. 1 illustrates control flow branching that can occur without reorganization. [Figure 6A] FIG. 1 illustrates a technique for reducing control flow branching by reorganizing execution items within a wavefront, according to an example. [Figure 6B] FIG. 1 illustrates control flow branching that can occur without reorganization. [Figure 7] 1 is a flowchart of a method for reorganizing action items in an APD, according to an example. DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS
[0005] Described herein are techniques for reducing control flow divergence in single instruction multiple data processors. The method includes identifying control flow targets for different execution items at a point of diverging control flow, sorting the execution items based on the control flow targets, reordering the execution items based on the sorting, and executing with the reordered execution items after the point of diverging control flow.
[0006] 1 is a block diagram of an example device 100 capable of implementing one or more features of the present disclosure. Device 100 may include, for example, a computer, a gaming device, a handheld device, a set-top box, a television, a mobile phone, or a tablet computer. Device 100 includes a processor 102, a memory 104, a storage device 106, one or more input devices 108, and one or more output devices 110. Device 100 optionally includes an input driver 112 and an output driver 114. It should be understood that device 100 may include additional components not shown in FIG. 1.
[0007] In various alternatives, the processor 102 may include a central processing unit (CPU), a graphics processing unit (GPU), a CPU and a GPU located on the same die, or one or more processor cores, each of which may be a CPU or a GPU. In various alternatives, the memory 104 may be located on the same die as the processor 102 or may be separate from the processor 102. The memory 104 may include volatile or non-volatile memory (e.g., random access memory (RAM), dynamic RAM, cache).
[0008] The storage devices 106 include fixed or removable storage devices (e.g., hard disk drives, solid state drives, optical disks, flash drives). The input devices 108 include, but are not limited to, a keyboard, a keypad, a touch screen, a touch pad, a detector, a microphone, an accelerometer, a gyroscope, a biometric scanner, or a network connection (e.g., a wireless local area network card for transmitting and / or receiving wireless IEEE 802 signals). The output devices 110 include, but are not limited to, a display device 118, a speaker, a printer, a haptic feedback device, one or more lights, an antenna, or a network connection (e.g., a wireless local area network card for transmitting and / or receiving wireless IEEE 802 signals).
[0009] The input driver 112 communicates with the processor 102 and the input device 108, allowing the processor 102 to receive input from the input device 108. The output driver 114 communicates with the processor 102 and the output device 110, allowing the processor 102 to send output to the output device 110. It should be noted that the input driver 112 and the output driver 114 are optional components, and the device 100 operates similarly when the input driver 112 and the output driver 114 are not present. The output driver 114 includes an accelerated processing device (APD) 116 coupled to a display device 118. The APD 116 is configured to accept computational and graphics rendering commands from the processor 102, process these computational and graphics rendering commands, and provide pixel output to the display device 118 for display. As described further below, the APD 116 includes one or more parallel processing units configured to perform computations according to a single instruction multiple data (SIMD) paradigm. Thus, although various functions are described herein as being performed by or in conjunction with APD 116, in various alternative examples, the functions described as being performed by APD 116 may additionally or alternatively be performed by other computing devices having similar functionality that are not driven by a host processor (e.g., processor 102) and that are configured to provide (graphical) output to display device 118. For example, it is contemplated that any processing system that performs processing tasks according to the SIMD paradigm may be configured to perform the functions described herein.
[0010] FIG. 2 is a block diagram of device 100 illustrating additional details associated with the execution of processing tasks on APD 116, according to one example. Processor 102 maintains in system memory 104 one or more control logic modules for execution by processor 102. The control logic modules include operating system 120, drivers 122, and applications 126. These control logic modules control various functions of the operation of processor 102 and APD 116. For example, operating system 120 communicates directly with hardware and provides an interface to the hardware for other software to execute on processor 102. Drivers 122 control the operation of APD 116, for example, by providing an application programming interface (API) to software executing on processor 102 (e.g., applications 126) to access various functions of APD 116. In some embodiments, driver 122 includes a just-in-time compiler that compiles programs to be executed by processing components of APD 116 (such as SIMD units, described in more detail below). In other embodiments, a just-in-time compiler is not used to compile the programs, and a standard application compiler compiles the shader programs that run on the APD 116.
[0011] The APD 116 executes commands and programs for selected functions, such as graphics and non-graphics operations suitable for parallel and / or non-ordered processing. The APD 116 is used to perform graphics pipeline operations, such as pixel operations, geometry calculations, and rendering of images to a display device 118, based on commands received from the processor 102. The APD 116 also performs computational operations not related to or directly related to graphics operations, such as video-related operations, physics simulations, computational fluid dynamics, or other tasks, based on commands received from the processor 102. The APD 116 also performs computational operations related to ray tracing-based graphics rendering.
[0012] The APD 116 includes a computation unit 132 that includes one or more SIMD units 138 that execute operations at the request of the processor 102 in a parallel manner according to the SIMD paradigm. The SIMD paradigm allows multiple processing elements to share a single program control flow unit and program counter, thus executing the same program, but with different data. In one example, each SIMD unit 138 includes 16 lanes, each lane executing the same instruction simultaneously with the other lanes in the SIMD unit 138, but with different data. If not all lanes need to execute a given instruction, the lane is switched off by conditional execution control. Conditional execution control may be used to execute a program with branching control flow. More specifically, for programs with conditional branches or other instructions where the control flow is based on the calculations executed by the individual lanes, the conditional execution control of the lane corresponding to the control flow path that is not currently executed, and the serial execution of the different control flow paths allows arbitrary control flow. In an embodiment, each of the computation units 132 may have a local L1 cache. In an embodiment, multiple compute units 132 share an L2 cache.
[0013] The basic unit of execution in compute unit 132 is the work item. Each work item represents a single instantiation of a program that will be executed in parallel on a particular lane. Work items may be executed together as a "wave front" on a single SIMD processing unit 138. The SIMD nature of SIMD processing unit 138 means that multiple work items can execute in parallel at the same time. Work items executed together in this manner on a single SIMD unit are part of the same wave front. In some embodiments or modes of operation, SIMD unit 138 executes a wave front by simultaneously executing each of the work items of the wave front. In other embodiments or modes of operation, SIMD unit 138 executes different subsets of the work items in the wave front in parallel. In one example, a wave front includes 64 work items and SIMD unit 138 has 16 lanes (each lane is a unit of hardware sized to execute a single work item). In this example, SIMD unit 138 executes a wave front by simultaneously executing 16 work items four times.
[0014] One or more wavefronts are contained in a "workgroup," which includes a collection of work items designated to execute the same program. An application or other entity (host) requests that a shader program be executed by the accelerated processing device 116 and specifies the "size" (number of work items), and the command processor 136 generates one or more workgroups to perform the work. The number of workgroups, the number of wavefronts in each workgroup, and the number of work items in each wavefront are correlated to the size of the work requested by the host. In some embodiments, the host may specify the number of work items in each workgroup for a particular request to perform work, which specifies the number of workgroups to be generated by the command processor 136 to perform the work. As described above, the command processor 136 dispatches the workgroups to one or more compute units 132, which execute the appropriate number of wavefronts to complete the workgroup.
[0015] The parallelism provided by the computation units 132 is suitable for graphics-related operations such as pixel value calculations, vertex transformations, and other graphics operations. Thus, in some examples, a graphics pipeline 134, which accepts graphics processing commands from the processor 102, provides computation tasks to the computation units 132 for parallel execution.
[0016] In some embodiments, the accelerated processing device 116 implements ray tracing, which is a technique for rendering a 3D scene by testing for intersections between simulated rays and objects in the scene. Much of the work involved in ray tracing is performed by programmable shader programs executing on the SIMD units 138 in the compute units 132. Although some teachings presented herein are described in the context of ray tracing work performed on the APD 116, it should be understood that various teachings presented herein may be applied in workloads other than ray tracing workloads.
[0017] 3 illustrates a ray tracing pipeline 300 for rendering graphics using ray tracing techniques, according to an example. The ray tracing pipeline 300 provides an overview of the operations and entities involved in rendering a scene using ray tracing. The ray generation shader 302, the any hit shader 306, the closest hit shader 310, and the miss shader 312 are shader implementation stages that represent ray tracing pipeline stages whose functions are performed by shader programs executing in the SIMD unit 138. Any of the specific shader programs in each specific shader implementation stage are defined by application-provided code (i.e., code provided by the application developer that is precompiled by the application compiler and / or compiled by the driver 122). The ray tracing stage 304 performs ray intersection tests to determine whether a ray hits a triangle. The ray tracing stage 304 may be performed by shader programs executing in the SIMD units 138 or by fixed function hardware configured to perform ray intersection tests.
[0018] The various programmable shaders (ray generating shader 302, any hit shader 306, recently hit shader 310, miss shader 312) are implemented as shader programs that execute on the SIMD unit 138. The command processor 136 directs the execution of the ray tracing pipeline 300. In particular, the command processor 136 is a programmable unit that executes instructions that cause the various stages of the ray tracing pipeline 300 to execute on the APD 116. Further details are provided elsewhere herein.
[0019] The ray tracing pipeline 300 operates as follows: One or more compute units 132 execute a ray generation shader 302. The ray generation shader 302 requests the ray tracing stage 304 to perform one or more ray intersection tests. Each ray intersection test defines an origin and direction for a ray tracing operation, which determines whether a ray hits one or more triangles or whether the ray does not hit any triangles.
[0020] The ray tracing stage 304 identifies one or more triangles intersected by a ray for a ray intersection test, or determines that a ray does not hit any triangles (i.e., the ray "misses") if the triangle is not intersected by the ray up to a predetermined distance. The ray tracing stage 304 may be implemented in any technically feasible manner. In one example, the ray tracing stage 304 is implemented as a shader program executing on one or more compute units 132. In another example, the ray tracing stage 304 is implemented as fixed function hardware.
[0021] The ray tracing stage 304 triggers the execution of the recently hit shader 310 for the closest triangle to the ray's origin that was hit by the ray, or the miss shader if the triangle was not hit. A typical use for the recently hit shader 310 is to color a material based on the texture for the material. A typical use for the miss shader 312 is to color a pixel with a color set by a skybox. It should be understood that the shader programs defined for the recently hit shader 310 and the miss shader 312 may implement a wide range of techniques for coloring pixels and / or performing other operations.
[0022] A typical manner in which the ray generation shader 302 generates rays is through a technique called backward ray tracing. In backward ray tracing, rays are generated that have their origin at a point corresponding to the camera. The point at which the ray intersects a plane defined to correspond to the screen defines a pixel on the screen whose color is used to determine the ray. If the ray hits an object, the pixel is colored based on the recent hit shader 310. If the ray does not hit an object, the pixel is colored based on the miss shader 312. Multiple rays may be cast per pixel, and the final color of the pixel is determined by some combination (e.g., average) of the colors determined for each of the pixel's rays. Any particular ray generation shader 302 (or any other shader) may specify that for any hit between a ray and a triangle, the any hit shader 306 will be executed, even if such hit is not a recent hit.
[0023] The recently hit shader 310 and / or the miss shader 312 can spawn their own rays that are incident on the ray tracing pipeline 300 at the ray test points. These rays may be used for any purpose. One common use is to implement environmental lighting or environmental reflection. In one example, when the recently hit shader 310 is called, it spawns rays in various directions. For each object or light hit by the spawned ray, the recently hit shader 310 adds the lighting intensity and color at the hit location to the pixel corresponding to the recently hit shader 310 that spawned the ray. Although we have described several examples of how the various components of the ray tracing pipeline 300 can be used to render a scene, it should be understood that any of a wide range of techniques may be used instead.
[0024] It should be understood that any of the shader programs described for the recently hit shader stage 310, the miss shader stage 312, or the any hit shader stage 306 may implement any of the operations described elsewhere herein as being performed by a shader program described for the ray generation stage 302. For example, in addition to causing new rays to be provided to ray test points for testing the ray tracing stage 304, such shader programs may specify whether a miss or hit causes additional rays to be traced (starting again at the ray test points), which shader programs to execute for any such additional rays, how to combine color and / or luminosity values produced by such additional shader program executions, and any other operations performed by the ray generation shader 302.
[0025] Shader programs are launched as "kernels" on the APD 116. A kernel specifies a particular shader program (e.g., a stitched shader program) along with the number of work-items that will be executed as part of the kernel. The scheduler 136 breaks down kernels into work-groups and assigns the work-groups to one or more compute units 132 for execution. A kernel's work-groups begin execution, execute their instructions, and then terminate execution. The work-groups execute as one or more wavefronts within the compute units 132. The wavefronts execute on the SIMD units 138 as multiple work-items that execute simultaneously.
[0026] Each wavefront includes work items that execute simultaneously in a single instruction, multiple data (SIMD) manner. More specifically, SIMD unit 138 executes shader programs in a manner in which a single instruction pointer is used to control program execution for multiple work items, and thus multiple instructions can be executed simultaneously. In one example, four work items of a wavefront execute on a SIMD unit. Part of the execution control flow begins in the section shown in the following pseudocode: [Table 1]
[0027] The first instruction adds the value of r2 to the value of r3 and stores the result in r1. The second instruction adds the value of r1 to r5 and stores the result in r4. The third instruction stores the value of r4 at the address specified in r6. Lanes of a wavefront executing this pseudocode will execute simultaneously, such that multiple adds, multiplications, and stores are performed simultaneously, once per lane. "r1" through "r6" represent register names.
[0028] Control flow may branch across lanes in SIMD unit 138, and thus across work items in a wavefront. More specifically, some instructions modify the instruction pointer based on the value of a particular variable. In one example, a conditional branch is an instruction whose jump target is based on the result of evaluating a condition. In another example, a jump may target an address specified in a variable. When control flow branches in this manner, SIMD unit 138 serializes each of the possible paths that at least one lane will execute. The following example pseudocode illustrates a situation that may result in diverging control flow: [Table 2]
[0029] In Table 2, each lane executes the instruction add r1, r2, 5, which adds a value of 5 to r2 and stores the result in r1. The blz instruction is a conditional branch that is taken if the value of r1 is less than zero. If the value of r1 is greater than zero, the control flow goes through section 1, which contains several instructions and then a jump instruction to the "reconverge" label. Referring back to the conditional branch, if the value of r1 is less than zero, the control flow goes to label LESS_THAN_ZERO, and section 2 is executed. At label "RECONVERGE", the control flow reconverges.
[0030] If the first lane executing in the wavefront had a value of -10 stored in r2 when the first instruction shown was executed, then register r1 for that lane will store a value of -5 after that first instruction, which will cause the first lane to execute section 2 in "LESS_THAN_ZERO". If a second lane executing in the same wavefront had a value of 1 in r2 when the first instruction was executed, then register r1 for that lane will store a value of 6, which will cause that lane not to branch and execute section 1. Execution of sections 1 and 2 by different lanes is achieved by executing each section serially, and lanes not executing a particular section are switched off. More specifically, the branch causes SIMD unit 138 to execute section 1 on the second lane while the first lane is switched off, and then to execute section 2 on the first lane while the second lane is switched off, which reduces processing efficiency because multiple lanes that could otherwise be executing simultaneously are still serialized.
[0031] Another example of branching control flow is shown in Table 3. [Table 3]
[0032] In the example of Table 3, each lane performs a ray trace to detect triangle intersections. Each lane then identifies the material of the intersected triangle and stores the address of the material shader for the identified material in register r1. Each lane then jumps to the address stored in r1. Those addresses may be the various material shaders indicated ("MATERIAL_SHADER_1", "MATERIAL_SHADER_2", etc.). After performing the material shader, the lane jumps to "end_material_shaders". If each lane hits a triangle with a different material shader, each of those material shaders will be serialized, resulting in a slowdown equal to the number of lanes in the wavefront, representing the overall deparallelization. Note that the material shader is the section of code used for ray tracing that is executed to provide color for rays that intersect the triangle (e.g., in the recently hit shader stage) or that miss the triangle and are therefore colored by the skybox (e.g., in the miss stage).
[0033] In some examples, on a SIMD processor, a point where a branch instruction exists is a "branch point." A branch at a branch point points to one or more branch targets. A branch with a fixed target has a single branch target, while a branch with a variable target may have multiple branch targets. There are also reconvergence points, which are points where lanes that branched necessarily reconverge due to taking different branch paths. A sequence of instructions that starts at a branch target is referred to herein as a "taken path." A sequence of instructions that starts at an instruction immediately following a conditional branch (a "not-taken point") is referred to as a "not-taken path." Taken paths and not-taken paths are collectively referred to as "code paths." Each code path extends from a branch target or not-taken path to a reconvergence point or branch point. Essentially, each code path defines a sequence of instructions within which the combination of lanes executing that code path cannot change (changes occur due to branching or reconvergence).
[0034] To execute a sequence of instructions that includes a branch, the SIMD processor evaluates the branch instruction for each lane and, based on the results, sets a bit value in an execution bitmask for each code path reachable from the branch. Each bit in the bitmask is associated with one lane of the wavefront that is executed. A bit value of one in the bitmask (e.g., "1") indicates that the corresponding lane executes that code path. Any other bit value in the bitmask (e.g., "0") indicates that the corresponding lane does not execute that code path.
[0035] After determining the bit masks for the different code paths, the SIMD processor advances or modifies the instruction pointer as necessary until all code paths executed by at least one lane are actually executed. For code paths for which the bit mask indicates that the lane will not execute the code path, the SIMD processor modifies the instruction pointer to skip that code path. Generally, modifying the instruction pointer as necessary includes modifying the instruction pointer from the address of the last instruction of one code path executed by at least one lane to the address of another code path executed by at least one lane. Such modification may include simply incrementing the instruction pointer if the two code paths executed are laid out serially in memory, or may include a "true branch," meaning that the instruction pointer is modified in a manner other than simply incrementing the instruction pointer, by setting the instruction pointer to the address of the first instruction of the code path executed.
[0036] FIG. 4 illustrates the serialization resulting from branching control flows, according to an example. Table 400 shows several sections of code listed as "convergence section", "F1", "F2", "F3" and "F4". In the diagram, time progresses downwards. A mark "O" in a given box indicates that the lane executes the section of code in the given time section. In the convergence section, it is assumed that each of lanes 1-4 executes its section together. Thus, there is a mark "O" in each lane of the convergence section. Due to the outcome of the convergence section, it is determined that lane 1 executes F1 and does not execute F2, F3 or F4, lane 2 executes F2 and does not execute F1, F3 or F4, lane 3 executes F3 and does not execute F1, F2 or F4, and lane 4 executes F4 and does not execute F1, F2 or F3. Thus, the execution of the wavefront including lanes 1-4 is de-parallelized, since each of F1, F2, F3 and F4 executes in a different time section. More specifically, within a first time section, lane 1 performs function F1 while lanes 2-4 are switched off. Within a second time section, lane 2 performs function F2 while lanes 1, 3-4 are switched off. Within a third time section, lane 3 performs function F3 while lanes 1-2 and 4 are switched off. Within a fourth time section, lane 4 performs function F4 while lanes 1-3 are switched off.
[0037] To reduce control flow branching, the compute unit 132 reorganizes execution items at control flow branching points. In some embodiments, the term "execution item" refers to a work item. In other embodiments, the term "execution item" refers to a thread of execution that is finer-grained than a work item. More specifically, multiple logical threads may be executed within a single work item by executing such multiple logical threads serially. In such an example, each of the multiple logical threads is an execution item. Two techniques for reorganizing execution items at branching points include the compute unit 132 reorganizing execution items across different wavefronts of a workgroup and the compute unit 132 reorganizing execution items within a wavefront.
[0038] FIG. 5A illustrates a technique for reducing control flow branching by reorganizing execution items across a wavefront of a workgroup, according to an example. In this example, there is a one-to-one correspondence between work items and execution items, with each work item executing one execution item. In the scenario of FIG. 5A, a workgroup 502 includes two wavefronts: wavefront 1 504(1) and wavefront 2 504(2). A workgroup 502 is a collection of work items that execute together on a single compute unit 132. The work items of a workgroup 502 execute together as a wavefront. A wavefront includes work items that execute simultaneously on a SIMD unit 138, for example, as described with respect to FIG. 4. While it is possible for all of the work items of a wavefront to execute simultaneously on a SIMD unit 138, it is also possible for a wavefront to include a number of work items that is greater than the number of data lanes in the SIMD unit 138. Typically, such a wavefront includes a number of work items equal to an integer multiple of the number of data lanes in the SIMD unit 138. Execution of such a wavefront occurs by serially executing a subset of the work items of the wavefront. In one example, the wavefront includes 64 work items and SIMD unit 138 includes 16 data lanes. In this example, the wavefront executes by executing work items 1 through 16, then work items 17 through 32, then work items 33 through 48, then work items 49 through 64.
[0039] Different wavefronts of a single workgroup do not execute in the concurrent SIMD manner described herein, although such wavefronts may execute simultaneously on different SIMD units 138 of a single compute unit 132. However, one feature of workgroups is that the compute unit 132 supports synchronization between different workgroups. "Synchronization" refers to the ability for a wavefront to execute a barrier that suspends execution of all wavefronts involved in the barrier until some condition is met. Wavefronts within a workgroup also have the ability to communicate during execution via local memory in the compute unit 132.
[0040] In FIG. 5A, table 500 illustrates execution by workgroup 502. The illustrated workgroup 502 includes two wavefronts 504. Wavefront 1 504(1) includes work items 1-4, and wavefront 2 504(2) includes work items 5-8. Instruction pointers indicate the section of code each wavefront 504 executes at a given time. Time proceeds from top to bottom. Some of the entries in the table correspond to portions of code that may or may not be executed by a particular work item. Those portions include functions F1-F4 that are executed by one or more work items. The convergent portion is executed by all work items in wavefront 504. An "O" mark indicates that a particular work item executes one of those portions of code, and a blank rectangle indicates that a particular work item does not execute one of those portions of code.
[0041] In the convergence portion, each work item determines which of functions F1-F4 the work item will execute. The term "function" refers to the portion of the shader program executed by the workgroup 502. The barrier and reorganization stage executes after the convergence portion. The barrier and reorganization stage suspends execution of each wavefront 504 until the barrier and reorganization stage is completed for each wavefront 504 undergoing reorganization. Those wavefronts 504 include wavefront 1 504(1) and wavefront 2 504(2) in the example of FIG. 5A. The barrier and reorganization stage reorganizes work items across different wavefronts 504 based on the results of the convergence portion, which indicate which of functions F1-F4 the work item will execute. In general, the goal of the reorganization is to reduce branching for a wavefront by shuffling work items between wavefronts (in this example, the more total functions executed, the more branching there is). In general, reducing branching is achieved by reducing the number of control flow targets in at least one wavefront.
[0042] In the illustrated example, work items in both wavefront 1 504(1) and wavefront 2 504(2) execute all of functions F1-F4. This is considered a 4x branch because the compute units 132 executing those work items must serialize each of functions F1-F4. Reorganization reduces the total number of functions executing in the wavefront by grouping work items that branch to the same control flow target. Reorganization in this example results in wavefront 1 504(1) having work items designated to execute functions F1 and F2 and not execute functions F3 and F4, and wavefront 2 504(2) having work items designated to execute functions F3 and F4 and not execute functions F1 and F2. In particular, wavefront 1 504(1) includes work items 1, 2, 5, and 6, each of which is designated to execute either F1 or F2 and not F3 or F4, and wavefront 2 504(2) includes work items 3, 4, 7, and 8, each of which is designated to execute either F3 or F4 and not F1 or F2. This reorganization results in each wavefront 504 being twice as branched. The code executed by each wavefront 504 still includes functions that are not executed by certain work items, but this code is skipped, resulting in little or no execution time being spent on those functions for wavefronts 504 with work items that do not execute those functions.
[0043] Although a particular example sequence of instructions is shown, which involves determining a function to execute for each work item and executing the function by the work items, it should be understood that the technique described with respect to FIG. 5A may be applied to any sequence of instructions that results in diverging control flow. In either situation, the barrier and reorganization stage examines the total number of diverging control flow targets in the work group 502 and attempts to assign as few as possible to each wavefront 504. The control flow targets may be identified by the instruction pointer address targeted by the branch instruction, by determining whether a conditional branch is taken, or through any other technically feasible means. Assigning as few diverging control flow targets as possible to each wavefront 504 may be accomplished by sorting the wavefronts based on targets, dividing the sorted list by the number of work items in each wavefront 504, and assigning the divided work items to different wavefronts 504. Moving a work item from one wavefront 504 to another may be accomplished in any technically feasible manner, such as by modifying the list of work items assigned to each wavefront 504, by copying execution state data, such as register and flag values, from the location where the work item was previously executing to the location where the work item is being moved to, etc.
[0044] The barriers and reorganization stages may be implemented completely in software, for example by instructions inserted at run-time or by an offline compiler, or may be implemented with special hardware support. In one example, either or both of the destination of the execution items and the sorting by reorganization may be accomplished by fixed function hardware triggered by the execution of special instructions by each wavefront 504 of the workgroup 502.
[0045] Figure 5B illustrates the execution that would occur without the reorganization shown in Figure 5A. As noted above, each wavefront 502 includes work items that execute functions F1-F4. Thus, executing those functions without reorganization would result in four times branching, since each function would be executed in sequence.
[0046] FIG. 6A illustrates a technique for reducing control flow branching by reorganizing execution items within a wavefront, according to one example. In the illustrated example, each work item executes two execution items. More specifically, the shader programs executed by the wavefront are configured such that two instances (two execution items) of a particular workload are executed serially. Each execution item executed as part of a particular work item executes within a particular time slot. Of course, it should be noted that multiple different work items may be executed simultaneously. Thus, multiple work items may execute their slot 1 simultaneously, and then their slot 2 simultaneously. In a ray tracing example, each slot may correspond to a different ray. In this example, the shader program determines which triangles the ray intersects. The shader program executes a material shader based on the material of the intersected triangle. Because each slot of a work item corresponds to a different ray, it is possible to execute different material shaders in different slots of a single work item.
[0047] Sequential performance of two execution items allows for permutations to occur between slots, reducing branching. The example in FIG. 6A illustrates such permutations. In this example, four lanes of wavefront 602 execute each of two execution items. Lane 1 executes execution items 1 and 2, lane 2 executes execution items 3 and 4, lane 3 executes execution items 5 and 6, and lane 4 executes execution items 7 and 8. The lanes execute a convergence portion to identify which of functions F1, F2, F3, and F4 each execution item executes. Although not shown, the convergence portion may be executed once per execution item.
[0048] The result of the convergence part is shown, execution item 1 will execute function F1, execution item 2 will execute function F2, execution item 3 will execute function F2, execution item 4 will execute function F3, execution item 5 will execute function F1, execution item 6 will execute function F4, execution item 7 will execute function F3, and execution item 8 will execute function F4. In slot 1, there are a total of 3 functions executed, and in slot 2, there are a total of 3 functions executed. This means that in each slot, there is a branching factor of 3. In the reorganization stage, the computation unit 132 reorganizes the execution items across different lanes to reduce branching. In particular, the reorganization stage sorts the execution items by the targets of the execution items, splits the sorted execution items, and assigns the split and sorted execution items to slots. In the illustrated example, the sorted targets are F1 (Item1), F1 (Item5), F2 (Item3), F3 (Item4), F3 (Item7), F4 (Item6), and F4 (Item8). The reorganization stage assigns execution items executing functions F1 and F3 to slot 1, and assigns execution items executing functions F2 and F4 to slot 2. Slot 1 is executed, then slot 2 is executed, each resulting in two functions (a branching factor of 2). In particular, functions F1 through F4 are executed serially as shown. This sequence occurs twice, once per slot. In slot 1, items 1 and 5 execute function F1 simultaneously, and items 4 and 7 execute function F3 simultaneously. In slot 1, the lane does not execute functions F2 and F4, so those functions are skipped. In slot 2, items 2 and 3 execute F2 simultaneously, items 6 and 8 execute function F4 simultaneously, and functions F1 and F3 are skipped.
[0049] Although specific example instruction sequences are shown, in general, the intrawavefront technique is performed as follows: A compiler generates a shader program having two or more time slots, each time slot being a copy of a particular workload executed on a different execution item. At points of diverging control flow, the compiler inserts reorganization code to reorganize the execution items across time slots. The reorganization code sorts the execution items into execution item groups by control flow destination. The reorganization code attempts to assign as few groups as possible to each time slot. This reorganization reduces branching in at least one time slot, thereby reducing the total execution time.
[0050] The reordering stage may be implemented by software (by instructions inserted into the shader program by a runtime or offline compiler) or by at least partial hardware support. In one example, the shader program executes special instructions that cause the fixed function hardware to reorder the execution items across time slots as described.
[0051] It should be noted that although the functions in the time slots are shown to be executed serially within each time slot, each function can be repeated for each time slot. In one example, time slot 1 executes function 1, then time slot 2 executes function 1, then time slot 1 executes function 2, then time slot 2 executes function 2, etc. The teachings herein apply to any technique that executes multiple iterations of a particular section of a branching control flow. In various examples, a runtime or offline compiler translates the shader program such that multiple branches of the branching control flow section as described are executed.
[0052] Figure 6B illustrates the execution that occurs without the reordering of Figure 6A. In particular, because there are lanes in each time slot that perform three different functions, each time slot executes with three times branching, which is slow-down compared to the execution that occurs in Figure 6A.
[0053] 7 is a flowchart of a method 700 for reorganizing action items in an APD 116, according to one example. Although described with respect to the systems of FIGS. 1-6, it should be understood that any system configured to perform the steps of method 700 in any technically feasible order falls within the scope of this disclosure.
[0054] Method 700 begins at step 702, where the compute unit 132 identifies control flow targets for different execution items at a point of diverging control flow. As described elsewhere herein, two techniques for reorganizing execution items are disclosed. In a first technique, execution items are reorganized across time slots within a single wavefront. This first technique is referred to herein as the "intra-wavefront technique." In a second technique, execution items are reorganized across wavefronts of a wavegroup. This second technique is referred to herein as the "inter-wavefront technique." In either technique, the executing shader program reaches a point of diverging control flow, a point where different execution items execute different parts of the shader program due to having different branch targets (e.g., due to different condition outcomes or due to different address targets for a variable target jump instruction). In step 702, the different branch targets are identified for the different execution items. In some examples, the branch target for a particular execution item includes the address of a destination for that execution item. In another example, the branch target includes an indication of whether a conditional branch is taken (i.e., whether a condition is satisfied).
[0055] In one example, each execution item performs a ray tracing operation to identify the material of the triangle intersected by the ray. At this point, different execution items encounter different triangles with different materials and therefore execute different material shaders. Note that the different material shaders are inlined into the shader program being executed such that executing a particular material shader is accomplished by stopping execution of the current shader and jumping to the appropriate inline function rather than invoking the material shader. In other words, at least a portion of the ray tracing pipeline is implemented by a single "monolithic" shader program that includes shaders at different stages of the ray tracing pipeline, along with instructions for controlling execution flow between the different stages and moving data between the different stages.
[0056] In step 704, the computation unit 132 sorts the execution items based on the control flow target. In an example where the branching is based on a jump to a variable target, the control flow target is the target of the jump. In an example where the branching is based on a conditional branch, the control flow target is the result of the condition. Sorting based on the control flow target includes sorting the execution items such that execution items with the same control flow target are grouped together. The result of the sorting is data indicating a sorted order of the execution items. In this example, there are execution items 1-8 and they execute a conditional branch. Execution items 1, 3, 4, 7 take the branch and execution items 2, 5, 6, 8 do not take the branch. The data indicating the sorted order indicates that execution items 1, 3, 4, 7 are in a first group and execution items 2, 5, 6, 8 are in a second group.
[0057] In step 706, the computation unit 132 reorganizes the execution items based on the sorting operation. In an intra-wavefront technique where the execution items are reorganized across time slots, reorganizing the execution items includes assigning each group of sorted execution items to a particular time slot. In the above example, execution items 1, 3, 4, and 7 are assigned to a first time slot, and execution items 2, 5, 6, and 8 are assigned to a second time slot. As described elsewhere herein, a time slot is an iteration of a serially repeated portion of a shader program. More specifically, to enable reorganization of execution items within a wavefront, at least some portions of a shader program are configured to execute in two or more iterations, each iteration corresponding to a different time slot. Because branching relates to the number of different segments of code that are executed at a particular time, having multiple time slots allows for a reorganization of execution items across time slots such that more execution items with the same control flow target are executed within the same time slot. Of course, the number of execution items in each sorted group may not be identical to the number of execution items in the wavefront. However, in this scenario, even when more than one group is assigned to a particular time slot, sorting reduces branching and therefore reduces the total execution time.
[0058] In some embodiments, a compiler introduces a time slot structure to the shader program. One example of a compiler is a runtime compiler that executes, for example, as part of the driver 122. Another example of a compiler is an offline compiler that executes as part of an application compiler that compiles an application that triggers the execution of the shader program. The compiler introduces the time slot structure by having at least a portion of the shader program execute in two or more iterations, one iteration per time slot. In each iteration, a different execution item executes a portion of the shader program. Furthermore, since the purpose of the time slot is to enable a reduction in control flow branching resulting from different execution items taking different control flow paths, each iteration can choose any of the possible branch paths (even though each execution item can only take one such path). For example, if there is a variable jump that targets one of the possible segments of code and there are four different segments of code to be executed in a given portion of the shader program, then in each time slot, the execution item executes any of the possible segments of code. Branching control flows may still occur within a given time slot, and this is implemented by SIMD unit 138 serializing each of the different possible control flow paths, as is usual for branching control flows.
[0059] In the inter-wavefront technique, the reorganization of execution items occurs across wavefronts. More specifically, the data sorting described above is still used to group execution items. However, instead of reorganizing execution items across time slots in a single wavefront, groups are assigned together to a particular wavefront. In the above example, if each wavefront is four work items wide, execution items 1, 3, 4, and 7 are assigned to the first wavefront, and execution items 2, 5, 6, and 8 are assigned to the second wavefront. As with the intra-wavefront technique, multiple groups may be assigned to each wavefront, but still with reduced branching. In step 708, the shader program executes past the point of branching control flow with the reorganized execution items.
[0060] It should be understood that many variations are possible based on the disclosure herein. Although features and elements are described above in certain combinations, each feature or element may be used alone without other features and elements, or may be used in various combinations with or without other features and elements. In one example, the technique is described in the context of a SIMD processor, but the technique may also be used for a multiple instruction multiple data (MIMD) processor. In another example, although the sorting is described as being performed based on the code sections executed, it is possible to sort based on other criteria instead, such as the textures that the lanes fetch or the direction of the rays associated with the lanes. Sorting based on such criteria is not directly related to sorting based on which code sections are executed by the lanes. However, such sorting is more likely to group together lanes that have similar execution flows. For example, lanes with similar ray directions are likely to hit the same triangle and therefore execute the same material shader. Also, since fetching the same texture may indicate that the lanes execute the same shader (e.g., material shader), lanes that fetch the same texture may execute similar sequences of instructions.
[0061] The various functional units illustrated in the figures and described herein (including, but not limited to, the processor 102, the input driver 112, the input device 108, the output driver 114, the output device 110, the accelerated processing device 116, the scheduler 136, the graphics processing pipeline 134, the computation unit 132, the SIMD unit 138, the ray tracing pipeline 300, the ray generation shader 302, the ray tracing stage 304, the any hit shader 306, the miss shader 312, or the recent hit shader 310) may be implemented as a general purpose computer, processor, or processor core, or as a program, software, firmware stored on a non-transitory computer readable medium or another medium executable by the general purpose computer, processor, or processor core. The provided method may be implemented in a general purpose computer, processor, or processor core. Suitable processors include, by way of example, general purpose processors, special purpose processors, conventional processors, digital signal processors (DSPs), multiple microprocessors, one or more microprocessors associated with a DSP core, controllers, microcontrollers, application specific integrated circuits (ASICs), field programmable gate array (FPGA) circuits, other types of integrated circuits (ICs), and / or state machines. Such processors may be manufactured by configuring a manufacturing process using the results of processed hardware description language (HDL) instructions and other intermediate data including a netlist (such instructions may be stored on a computer readable medium). The result of such processing may be a mask work, which is used in a semiconductor manufacturing process to manufacture a processor embodying aspects of the embodiments.
[0062] The methods or flow charts provided herein may be implemented in a computer program, software, firmware embodied in a non-transitory computer-readable storage medium for execution by a general purpose computer or processor. Examples of non-transitory computer-readable storage media include, for example, read-only memory (ROM), random access memory (RAM), registers, cache memory, semiconductor memory devices, magnetic media such as internal hard disks and removable disks, magneto-optical media, optical media such as CD-ROM disks and digital versatile disks (DVDs).
Claims
1. 1. A method for reducing control flow branching in a single instruction multiple data processor, comprising: identifying control flow targets for different execution items of a wavefront having a plurality of time slots at a point of diverging control flows; sorting the execution items based on the identified control flow targets to generate a sorted group of execution items; reordering the execution items of the wavefront across the time slot based on the sorted groups of execution items such that in the time slot, more execution items have the same control flow target than would be the case if no reordering were performed; executing the wavefront after the point of diverging control flow. method.
2. identifying a control flow target of the different execution items includes identifying whether the different execution items take a branch; 2. The method of claim 1.
3. identifying a control flow target of the different execution item includes identifying a target address of a jump; 2. The method of claim 1.
4. Sorting the execution items includes grouping execution items having the same control flow target into the execution item group.
2. The method of claim 1.
5. 1. A device for reducing control flow branching in a single instruction multiple data (SIMD) processor, comprising: a memory configured to store a shader program; a SIMD processor configured to execute the shader program with a plurality of execution items; The SIMD processor comprises: identifying control flow targets for different execution items of a wavefront having a plurality of time slots at a point of diverging control flow; sorting the execution items based on the identified control flow targets to generate a sorted group of execution items; reordering the execution items of the wavefront across the time slot based on the sorted groups of execution items such that in the time slot, more execution items have the same control flow target than would be the case if no reordering were performed; executing the wavefront after the point of diverging control flow; [0023] device.
6. identifying a control flow target of the different execution items includes identifying whether the different execution items take a branch; The device of claim 5.
7. identifying a control flow target of the different execution item includes identifying a target address of a jump; The device of claim 5.
8. Sorting the execution items includes grouping the execution items having the same control flow target into the execution item group. The device of claim 5.
9. A computer-readable storage medium storing instructions, comprising: The instructions, when executed by a processor, identifying control flow targets for different execution items of a wavefront having a plurality of time slots at a point of diverging control flows; sorting the execution items based on the identified control flow targets to generate a sorted group of execution items; reordering the execution items of the wavefront across the time slot based on the sorted groups of execution items such that in the time slot, more execution items have the same control flow target than would be the case if no reordering were performed; executing the wavefront after the point of diverging control flow; causing a processor to reduce branching of control flow in a single instruction multiple data (SIMD) processor by A computer-readable storage medium.
Citation Information
Patent Citations
gpu divergence barrier
JP2016532180A
Method and System for Resolving Thread Divergences
US20130179662A1
Method for determining a distance by x-ray imaging, and x-ray device
US20140016743A1
Creating SIMD efficient code by transferring register state through common memory
US20140149710A1
GPU divergence barrier
US20150095914A1
