Device, method and medium for reducing the precision of calculations used in shader programs

By automatically identifying and rewriting shader program calculations that can reduce accuracy in the compiler of computer devices, the problem of improving graphics shader performance is solved, and the performance improvement and power saving effect is achieved.

CN113924547BActive Publication Date: 2025-06-06MICROSOFT TECHNOLOGY LICENSING LLC
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202080040930.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Priority Date
2019-06-03
Filing Date
2020-04-17
Publication Date
2025-06-06
Estimated Expiration
2040-04-17

AI Technical Summary

Technical Problem

The prior art is difficult to effectively improve the performance of graphics shaders, especially when the shader program is used in games, resulting in an increase in power consumption of computer devices.

Method used

By implementing an automated process in a compiler of a computer device, identifying situations where the calculations in a shader program can reduce accuracy and have acceptable accuracy losses and rewrite it to half precision to generate edited program code.

Benefits of technology

Improves the performance of graphics processing, especially the performance of shader programs, reduces power consumption of computer devices while maintaining image quality.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113924547B_ABST
    Figure CN113924547B_ABST
Patent Text Reader

Abstract

Methods and apparatus for reducing the precision of calculations used in shader programs may include receiving program code for a shader program for use with a graphics processing unit (GPU) that supports half-precision storage and arithmetic in the shader program. The method and apparatus may include performing at least one pass on the program code to select an operation set within the program code to reduce the precision of multiple calculations used by the operation set, and for each of the multiple calculations, evaluating a risk of precision loss for reducing the precision to half precision. The method and apparatus may include generating edited program code by rewriting the calculation to half precision in response to the risk of precision loss being below a precision loss threshold.
Need to check novelty before this filing date? Find Prior Art

Description

Background Art

[0001] The present disclosure relates to graphics processing on a computer device, and more particularly to a device and method for compiling shader program code.

[0002] Games often use tens of thousands of graphics shader programs within the game to generate the appropriate level of color and / or special effects for the in-game images. Developers attempting to improve the performance of shader programs may encounter difficulties due to the large number of shader programs in games. The processing and / or performance of the graphics shaders may determine the performance of the game and / or the power consumption of the computer device.

[0003] Therefore, there is a need in the art to improve the performance of graphics shaders. Summary of the invention

[0004] A simplified overview of one or more implementations of the present disclosure is presented below in order to provide a basic understanding of such implementations. This content is not an extensive overview of all contemplated implementations, and is neither intended to identify key or essential elements of all implementations nor to delineate the scope of any or all implementations. Its sole purpose is to present some concepts of one or more implementations of the present disclosure in a simplified form as a prelude to a more detailed description presented later.

[0005] An example implementation relates to a computer device. The computer device may include: a graphics processing unit (GPU) that supports half-precision storage and arithmetic in shader programs; a memory that stores data and instructions; at least one processor configured to communicate with the memory; a compiler that communicates with the memory and the at least one processor, wherein the compiler is operable to: receive program code for a shader program for use with the GPU; perform at least one pass on the program code to select an operation set within the program code to reduce the precision of multiple calculations used by the operation set; for each of the multiple calculations, assess a risk of precision loss for reducing the precision of the calculation to half precision; in response to the risk of precision loss being below a precision loss threshold, generate edited program code by rewriting the calculation to half precision; and in response to the risk of precision loss being above the precision loss threshold, provide a notification with a warning for possible precision loss.

[0006] Another example implementation relates to a method for reducing the precision of calculations used in a shader program. The method may include, at a compiler on a computer device, receiving program code for a shader program for use with a graphics processing unit (GPU) that supports half-precision storage and arithmetic in the shader program. The method may include performing at least one pass on the program code to select an operation set within the program code to reduce the precision of multiple calculations used by the operation set. The method may include, for each of the multiple calculations, assessing the risk of precision loss of reducing the precision of the calculation to half precision. The method may include, in response to the risk of precision loss being below a precision loss threshold, generating edited program code by rewriting the calculation to half precision. The method may include, in response to the risk of precision loss being above a precision loss threshold, providing a notification with a precision loss warning.

[0007] Another example implementation relates to a computer-readable medium storing instructions that can be executed by a computer device. The computer-readable medium may include at least one instruction for causing a computer device to receive a program code for a shader program for use with a graphics processing unit (GPU) that supports half-precision storage and arithmetic in the shader program. The computer-readable medium may include at least one instruction for causing a computer device to perform at least one pass on the program code to select an operation set within the program code to reduce the precision of multiple calculations used by the operation set. The computer-readable medium may include at least one instruction for causing a computer device to evaluate the risk of precision loss of reducing the precision of the calculation to half precision for each calculation in a plurality of calculations. The computer-readable medium may include at least one instruction for causing a computer device to generate an edited program code by rewriting the calculation to half precision in response to the risk of precision loss being lower than a precision loss threshold. The computer-readable medium may include at least one instruction for causing a computer device to provide a notification with a precision loss warning in response to the risk of precision loss being higher than a precision loss threshold.

[0008] Additional advantages and novel features associated with the implementation of the present disclosure will be set forth in part in the following description and in part will become more apparent to those skilled in the art upon examination of the following or learning of the following through practice thereof. BRIEF DESCRIPTION OF THE DRAWINGS

[0009] In the attached picture:

[0010] Figure 1 is a schematic block diagram of an example computer device according to an implementation of the present disclosure;

[0011] Figure 2 is an example of an expression tree with an operation set according to an implementation of the present disclosure;

[0012] Figure 3 is a flow chart of an example method for reducing the precision of calculations used in a shader program according to an implementation of the present disclosure;

[0013] Figure 4 is a flowchart of an example method for evaluating lower precision for calculations used in a shader program according to an implementation of the present disclosure; and

[0014] Figure 5 is a schematic block diagram of an example device according to an implementation of the present disclosure. DETAILED DESCRIPTION

[0015] The present disclosure relates to a device and method for using a compiler to help reduce the precision of calculations used in shader programs used with graphics hardware such as a graphics processing unit (GPU). Computer devices executing game applications typically use tens of thousands of shader programs within the game to generate appropriate levels of color and / or special effects for images within the game. For example, a shader program can operate on data stored in a computer digital format such as a single-precision floating point format, which occupies 32 bits of computer memory. Modern graphics hardware supports half-precision storage and / or arithmetic in shader programs, where half-precision refers to a binary floating point computer digital format that occupies 16 bits of computer memory. Using half-precision storage and / or arithmetic in shader programs provides benefits to the performance of shader programs due to the increase in the number of shader programs in operation, the improvement of the throughput of arithmetic calculations, and / or the acceleration of memory access.

[0016] However, not all calculations used in shader programs can tolerate reduced precision and / or range formats without reducing image quality in the output (e.g., a rendered target in a game or application). In addition, due to the conversion from single precision to half precision and back, it may be difficult to predict the cost of adding half precision to a shader program. Furthermore, given the large number of shaders in a game (e.g., tens of thousands of shaders), the work involved in manually converting a shader program to use half precision may be impractical. Thus, identifying the calculations within a shader program that can tolerate reduced precision, range, and / or manually editing the shader can result in a significant amount of work for shader program developers.

[0017] The apparatus and method of the present disclosure can provide an automated process within the compiler to identify calculations in a shader program, where precision can be reduced and / or precision loss can be acceptable. For example, the compiler can build a dependent chain from outputs in a shader program known to use half precision (e.g., outputs to a rendering target or any other output marked as half in a shader). In addition, the compiler can build a dependent chain from inputs in a shader program known to use half precision. For example, the input layout of a vertex shader can specify an R16G16B16A16_FLOAT format, which is known to use half precision. After identifying the output and the corresponding dependent chain, the compiler can evaluate the result expression and can attempt to reduce the precision of any other instructions in the intermediate value, function parameter, memory load, and / or output dependent chain, while monitoring instructions that may be sensitive to precision. Instructions that may be sensitive to precision and / or precision changes may include, but are not limited to, trigonometric function instructions or transcendental instructions. For example, when the calculated value may exceed the expected range and / or exceed the precision limit when the precision is reduced, these instructions may be sensitive to precision and / or precision changes.

[0018] In addition, the compiler can weight the cost of the conversion operation and / or the benefits of any power consumption brought by the conversion operation to determine whether the precision can be reduced and / or under what circumstances the precision loss can be accepted. For example, the compiler can weight the runtime cost of the conversion (for example, the time and / or power consumed by performing the conversion) for the benefits of the conversion to determine whether the precision can be reduced. In addition, the power consumption benefits to the computer device can outweigh the precision loss that can be caused by reducing the calculation accuracy. Like this, the compiler can determine that the precision loss can be acceptable, and the calculation accuracy can be reduced to benefit from the power consumption saving when using half-precision calculation. For the expression chain part with lower risk of precision loss, the compiler can generate the edited program code by rewriting the expression using half-precision arithmetic. The compiler can also provide a change report, and the change report carries the information about the changes made to the shader program.

[0019] The device and method of the present disclosure may also receive user input to turn off or on analysis of specific instructions within the shader program for evaluating whether precision can be reduced for the identified instructions. In this way, the device and method may provide a language-level mechanism to the user to control the turning off or on of analysis of specific instructions within the program code in a more fine-grained manner.

[0020] The apparatus and method may also provide a user with a tool used during the development of a shader program that helps the user quantify the precision loss caused by reducing the precision of selected calculations in the edited program code for the shader program. For example, the tool may allow the user to open a game and / or a trace of the game so that the user can run the edited program code at a lower precision and assess whether the image quality output due to the lower precision is acceptable for use with the game. The tool may also provide the user with additional information and / or an explanation of the precision loss that may occur in the game output.

[0021] By reducing the precision of a portion of instructions within a shader program, typically by increasing the number of shader programs in operation, increasing the throughput of arithmetic calculations, and accelerating memory access, the performance of graphics processing can be improved, and in particular the performance of shader programs can be improved. Thus, by identifying instruction sets and / or operation sets within a shader program in which precision can be reduced, and / or automatically reducing the precision in the identified instruction sets, the described methods and apparatus can improve the performance of graphics processing and shader programs.

[0022] Reference now Figure 1 , which illustrates an example computer device 102 for reducing the precision of calculations 24 used in shader programs 12. The computer device 102 may include multiple applications 10 executed or processed by a processor 54 and / or system memory 56 of the computer device 102. A user may have developed program code 14 for one or more shader programs 12 within the application 10, which may cause the processor 54 to be executed by a graphics processing unit (GPU) 44 to render an image to be displayed. In addition, the computer device 102 or another computing device may have automatically generated program code 14 for one or more shader programs 12. For example, the application 10 may cause the GPU 44 to use tens of thousands of shaders associated with the program code 14 for executing the shader program 12 within the application 10 to generate an appropriate level of color and / or special effects for an image associated with running the application 10, such as for a game. Therefore, the GPU 44 may execute the shader program code 14 and render an output 46, which may include one or more rendered images 47 for presentation on a display 48.

[0023] In addition, the GPU 44 may support half precision in data storage and / or calculations or arithmetic in one or more portions of the program code of the shader program 12. For example, the present disclosure enables one or more portions of the program code 14, such as portions associated with storage and / or arithmetic and originally in single precision format, to be replaced with corresponding one or more portions of the edited program code 34 that use half precision 38 in storage and / or arithmetic. By using half precision storage and / or arithmetic, the performance of the shader program 12 with the edited program code 34 may be improved. For example, the number of shader programs 12 running in the GPU 44 may be increased. In addition, the throughput of the remaining, unedited portions of the program code 14 in the GPU 44 may also be improved, such as arithmetic calculations 24 in single precision 26 used in the shader program 12, because memory accesses of the GPU 44 may be accelerated.

[0024] Computer device 102 may include any mobile or fixed computer device that can be connected to a network. For example, computer device 102 may be a computer device such as a desktop computer or a laptop computer or a tablet computer, an Internet of Things (IoT) device, a cellular phone, a gaming device, a mixed reality or virtual reality device, a music device, a television, a navigation system, a camera, a personal digital assistant (PDA) or a handheld device, or any other computer device having wired and / or wireless connection capabilities to one or more other devices.

[0025] The computer device 102 may include an operating system 110 executed by a processor 54 and / or a memory 56. The memory 56 of the computer device 102 may be configured to store data and / or computer executable instructions that define and / or are associated with the operating system 110, and the processor 54 may execute such data and / or instructions to instantiate the operating system 110. Examples of the memory 56 may include, but are not limited to, types of memory that may be used by a computer, such as random access memory (RAM), read-only memory (ROM), tape, disk, optical disk, volatile memory, non-volatile memory, and any combination thereof. Examples of the processor 54 may include, but are not limited to, any of the processors specifically programmed as described herein, including a controller, a microcontroller, an application specific integrated circuit (ASIC), a field programmable gate array (FPGA), a system on a chip (SoC), or other programmable logic or state machine.

[0026] The operating system 110 may include a compiler 16 that may be used to verify and / or improve the program code 14. In addition, the compiler 16 may be used to port the program code 14 to half-precision 38 arithmetic by safely reducing the precision of operations within the shader program 12 from single-precision 26 to half-precision 38 arithmetic. The compiler 16 may also be used to verify whether a potential change to lower precision is worthwhile before modifying the program code 14 with lower precision. In one aspect, a user of the computer device 102 may load the program code 14 into the compiler 16 using the user interface 50. In another aspect, the application 10 may automatically transfer the program code 14 to the compiler 16.

[0027] The compiler 16 may have a reduced precision manager 20 operable to perform one or more passes 18 on the program code 14 to automatically search for reduced precision opportunities in the program code 14. The reduced precision manager 20 may identify a set of operations 22 within the program code 14 that may tolerate lower precision and / or range. The set of operations 22 may include a plurality of calculations 24 (up to n, where n is an integer) that are currently being performed in single precision 26.

[0028] The reduced precision manager 20 may analyze the structure of the program code 14 and / or shader program 12 and / or hardware parameters 45 of the GPU 44 to determine whether the operation set 22 can tolerate lower precision and / or range. The hardware parameters 45 of the GPU 44 may include, but are not limited to, the power consumption of the GPU 44, whether the GPU 44 supports half-precision 38, and / or the performance of the GPU 44. In addition, the reduced precision manager 20 may use a previously defined list of operations that support half-precision 38 to determine the operation set 22 that can tolerate lower precision and / or range. For example, operations such as, but not limited to, reading from images and / or textures, reading from buffers, low-precision inputs from vertices (e.g., 8 or 10-bit precision color inputs), and / or outputs to render targets may be known to operate in half-precision 38. In addition, precision-sensitive operations (e.g., trigonometric instructions or transcendental instructions) known to the reduced precision manager 20 may not be included in the operation set 22.

[0029] The precision reduction manager 20 may include an evaluation component 28 that may determine whether to reduce the precision of a computation 24 within an operation set 22. The evaluation component 28 may evaluate a result expression of the operation set 22 and may attempt to reduce the precision of intermediate data, function parameters, memory loads, and / or any other computation 24, while being mindful of the cost (e.g., time and / or power consumption) of computations 24 and / or weighted conversion operations that may be precision sensitive. Thus, the evaluation component 28 may identify possible results when a computation 24 is reduced to half precision 38.

[0030] The evaluation component 28 may attach range and precision information to each computation 24 in the operation set 22, and may track the range and precision information through the operation set 22. For example, the operation set 22 may be an expression tree having a chain of computations 24 that may be executed in a specified order. The evaluation component 28 may compare the range and / or precision information of each computation 24 to the expected range 35 and / or precision bounds 37 of the values ​​on the computation path. For each computation 24 on the computation path, the evaluation component 28 may score the possible loss against the expected range 35 and / or precision bounds 37. The evaluation component 28 may use the comparison of the range and precision information to the expected range 35 and / or precision bounds 37 to determine the risk 31 of precision loss.

[0031] For example, evaluation component 28 can receive a range x=7000 of values ​​for computation 24. Evaluation component 28 can determine that range x=7000 is within expected range 35 for computation 24 (e.g., the range is within the range of half-precision values). In another example, evaluation component 28 can receive a range x=70000. Evaluation component 28 can determine that range x=70000 exceeds expected range 35 for computation 24 (e.g., the range is outside the range of half-precision values), and can set precision loss risk 31 in response to determining that the range exceeds expected range 35.

[0032] For each computation 24 of the set of operations 22, the evaluation component 28 may determine a risk of precision loss 31 and may compare the risk of precision loss to a precision loss threshold 33. The precision loss threshold 33 may identify whether the computation 24 supports half-precision 38 and / or whether the computation 24 may be sensitive to half-precision 38. For example, if the computation 24 cannot work with lower precision (e.g., raising a value to a power), the risk of precision loss 31 may be higher than the precision loss threshold 33. Furthermore, if the GPU 44 does not support lower precision, the risk of precision loss 31 may be higher than the precision loss threshold 33. If the computation 24 supports lower precision and / or if the GPU 44 supports lower precision, the risk of precision loss 31 may be lower than the precision loss threshold 33.

[0033] When precision loss risk 31 is above precision loss threshold 33, evaluation component 28 may generate notification 32 with a warning indicating that computation 24 may not support half precision 38. Compiler 16 may communicate notification 32 to user interface 50 so that a user may use this information when editing program code 14.

[0034] The evaluation component 28 may also consider the power consumption benefit from the conversion operation when determining whether the precision may be reduced and / or whether the loss of precision is acceptable for the set of operations 22. The power consumption benefit to the computer device 102 that may occur when using half precision 38 in the calculation 24 may outweigh the loss of precision that may result from reducing the precision of the calculation 24. For example, the evaluation component 28 may determine that the risk of loss of precision 31 is above the precision loss threshold 33, but may determine that the lost precision may be acceptable in order to obtain the benefit of power consumption savings to the computer device 102 when using half precision 38 in the calculation 24. Thus, in response to determining that the power consumption benefit outweighs the loss of precision, the evaluation component 28 may modify the risk of loss of precision 31. In addition, the evaluation component 28 may send a notification 32 to the computer device 102 by using half precision 38 in the calculation 24, the notification 32 having information about the potential power consumption benefit and / or information about the potential loss of precision using half precision 38.

[0035] When the risk of loss of precision 31 is below the loss of precision threshold 33, the evaluation component 28 may identify that the computation 36 supports half precision 38. In this manner, the evaluation component 28 may perform an iterative process to determine whether to reduce the precision of the computation 24 within the set of operations 22.

[0036] In one aspect, the reduced precision manager 20 can automatically generate edited program code 34 by rewriting the precision of the identified calculations 36 with half precision 38. The reduced precision manager 20 can also generate a report 40 with information about the changes made to the precision. For example, the report 40 can include the identified calculations 36 and / or the set of operations 22. The report 40 can also include an explanation of the change in precision and / or the decision not to reduce precision. In another aspect, the report 40 can include the identified calculations 36 with half precision 38, and the report 40 can be transmitted to a user interface 50 for a user to review and / or modify the program code 14 in response to the information provided in the report 40.

[0037] The compiler 16 may transmit the edited program code to the GPU 44 for processing. The GPU 44 may execute the edited program code 34 using half precision 38 for the identified calculation 36 to generate output 46 for presentation on the display 48. By using half precision 38 in the identified calculation 36, the throughput of the identified calculation 36 used in the shader program 12 in the GPU 44 may be improved, and memory access of the GPU 44 may also be accelerated.

[0038] In addition, the compiler 16 may transmit the edited program code 34 and / or the report 40 to the user interface 50 for display. In one aspect, the user may use the information in the report 40 to further edit the program code 14 and / or the edited program code 34 and create a revised program code 52. For example, the user may change the precision of the calculations 36 identified in the program code 14. In addition, the user may choose to change a portion of the identified calculations to half precision 38. In this way, the user may use the provided information as a guide to reduce the precision within the shader program 12.

[0039] The user may also identify one or more calculations 24 in which the precision within the shader program code 14 may be reduced, and transmit the calculations 24 to the compiler 16 for evaluation. For example, the user may insert one or more mechanisms at the language level to identify such calculations 24, such as, but not limited to, attributes and / or annotations provided by the source code user. The evaluation component 28 may evaluate whether the precision of the calculations 24 may be reduced, and may provide a notification 32 to the user, with a warning about the possible loss of precision. The user may change the precision of the calculations 24 in response to information received from the compiler 16, and a revised program code 52 may be generated. As discussed above with respect to the program code 14, the revised program code 52 may be transmitted to the compiler 16 for further evaluation.

[0040] In addition, the user can use the user interface 50 to open the application 10 or a trace of the application 10, and can use the application 10 to run the edited program code 34 received from the compiler 16 to verify whether the quality of the output 46 is acceptable. For example, the image quality of the rendered image 47 can be compared with the quality threshold 30 to determine whether the quality of the rendered image 47 is acceptable. When there is little loss in the image quality of the rendered image 47, the quality of the rendered image 47 can be acceptable. In this way, the shader program 12 can tolerate reduced precision without reducing the image quality in the output 46.

[0041] When image quality is lost, the user can revise the edited program code 34 and generate revised program code 52 to change the amount of lower precision used in the shader program 12. In addition, when image quality is lost, the user can make adjustments to the analysis performed by the compiler 16. For example, by annotating chains of calculations with attributes in the shader program code 14, the user can remove specific instructions from the search performed by the compiler 16 so that the compiler does not identify these instructions as tolerant to lower precision. In addition, the user can turn off the channel 18 that performs a search to identify a set of operations 22 in which precision can be reduced.

[0042] In this way, users may be able to safely and quickly port shader programs 12 to half-precision 38 arithmetic. Furthermore, by having the compiler 1614 automatically identify the operation sets 22 in which precision may be reduced and / or automatically edit the program code 14 to include half-precision 38, a large number of users may be able to improve the performance of shader programs 12. In this way, the performance improvement of shader programs 12 may be scalable so that more shader programs 12 may be able to use the lower precision supported by the hardware.

[0043] Reference now Figure 2 , illustrates an example expression tree 200 with an operation set 22. The expression tree 200 may include the operation set 22 having a chain of calculations 202, 204, 210, 212 to be performed in a specified order. For example, the chain of calculations may start with calculation 202 and proceed in order until the expression tree 200 ends with calculation 212.

[0044] Evaluation Component 28 ( Figure 1 ) may attach range and precision information to each calculation 202, 204, 210, 212 in the expression tree 200 to determine whether any of the calculations 202, 204, 210, 212 may be reduced to half precision 38. The evaluation component 28 may start at the bottom of the expression tree 200 (e.g., calculation 212) and process the chain of calculations up to the beginning of the expression tree 200 (e.g., calculation 202). The evaluation component 28 may track the range and precision information through the expression tree 200 to determine whether the calculations 202, 204, 210, 212 may be reduced to half precision 38.

[0045] The evaluation component 28 can compare the range and / or precision information of each calculation 202, 204, 210, 212 to the expected range 35 and / or precision bounds 37 of the values ​​on the calculation path. For each calculation 202, 204, 210, 212 on the calculation path, the evaluation component 28 can score the possible loss against the expected range 35 and / or precision bounds 37. The evaluation component 28 can use the comparison of the range and precision information to the expected range 35 and / or precision bounds 37 to determine the risk 31 of precision loss.

[0046] At 212, for the operation set 22 in the expression tree 200, the evaluation component 28 may know that Z is output with half precision 38. For example, in response to knowing how the hardware works and / or how the shader works for the operation set 22 in the expression tree 200, the evaluation component 28 may know that the output of Z is always in the range of 0 to 1 and the precision of Z has half precision 38. For example, the operation set 22 in the expression tree 200 may be used to output color, and the evaluation component 28 may know that the color output is performed with half precision 38.

[0047] At calculation 210, in response to calculation 210 being reduced to half precision 38, evaluation component 28 can determine that expected range 35 of Y can be between -0.5 and 0.5 and precision bound 37 can remain the same. Thus, evaluation component 28 can determine that calculation 210 can be reduced to half precision 38 because the output of Z can remain in the range of 0 to 1, while expected range 35 of Y is between -0.5 and 0.5 and precision remains the same.

[0048] At calculation 204, in response to calculation 204 being reduced to half precision 38, evaluation component 28 can determine that the expected range of X can be between -1 and 1 and the precision limit 37 can remain the same. Evaluation component 28 can determine that calculation 204 can be reduced to half precision 38 because the output of Z can remain in the range of 0 to 1, while the expected range 35 of X is between -1 and 1 and the precision remains the same.

[0049] In this way, the evaluation component 28 may determine to reduce the precision of all the calculations 202 , 204 , 210 , 212 in the expression tree 200 .

[0050] In an alternative example, at calculation 204, in response to calculation 204 being reduced to half precision 38, evaluation component 28 can determine that the expected range of X can be between -1 and 1, but the precision becomes 0.3333. Evaluation component 28 can determine that the precision 0.3333 is outside precision bound 37, and because the precision exceeds precision bound 37, calculation 204 can not be reduced to half precision 38. Evaluation component 28 can determine to reduce the precision of calculations 210, 212 while maintaining calculation 204 in single precision.

[0051] Thus, evaluation component 28 may reduce the precision of all calculations in expression tree 200. Additionally, evaluation component 28 may reduce a portion of the calculations in expression tree 200 to a lower precision while maintaining other calculations in expression tree 200 at single precision. Evaluation component 28 may also determine that no calculations in expression tree 200 will use a lower precision and may maintain all calculations in expression tree 200 at single precision.

[0052] Reference now Figure 3 , computer device 102 ( Figure 1 ) can use the example method 300 to reduce the Figure 1 ) used in the calculation 24( Figure 1 ) accuracy. The actions of method 300 can be referred to below Figure 1 The architecture of the

[0053] At 302, method 300 may include receiving program code for a shader program for use with a GPU. For example, compiler 16 may receive program code 14 for use with GPU 44 of shader program 12, GPU 44 supporting half-precision 38 storage and / or arithmetic in shader program 12. A user of computer device 102 may load program code 14 into compiler 16 using user interface 50. Additionally, application 10 may automatically transmit program code 14 to compiler 16.

[0054] At 304, the method 300 may include executing at least one pass on the program code to select an operation set to reduce the precision of the plurality of computations. The compiler 16 may have a precision reduction manager 20 that is operable to execute one or more passes 18 on the program code 14 to automatically search for opportunities for precision reduction in the program code 14. The precision reduction manager 20 may identify an operation set 22 within the program code 14 that may tolerate lower precision and / or range. For example, a precision loss threshold 33 may determine an error value range of an expected range 35 and / or precision bound 37. When the error value range of the operation set 22 is below the precision loss threshold 33, the operation set 22 may be identified as tolerant to lower precision. The operation set 22 may include a plurality of computations 24 currently being executed in single precision 26. Additionally, the operation set 22 may include a plurality of computations 24 that are executed in a specified order. For example, the operation set 22 may be an expression tree having a chain of computations 24 to be executed in order.

[0055] The reduced precision manager 20 may analyze the structure of the shader program 12, such as the control flow of the shader program 12 and / or the hardware parameters 45 of the GPU 44, to determine whether the set of operations 22 can tolerate lower precision and / or range. In addition, the reduced precision manager 20 may use a previously defined list of operations that support half precision 38 to determine the set of operations 22 that can tolerate lower precision and / or range. For example, operations such as, but not limited to, reading from an image and / or texture, reading from a buffer, low-precision inputs from vertices (e.g., 8 or 10-bit precision color inputs), and / or inputs to a render target may be known to operate in half precision 38. In addition, operations known to the reduced precision manager 20 to be precision sensitive (e.g., trigonometric instructions or transcendental instructions) may not be included in the set of operations 22. In this way, the search performed by the reduced precision manager 20 may be a guided and / or intelligent search trained by prior knowledge of the hardware and / or operations used by the shader program 12.

[0056] At 306, the method 300 may include determining, for each of the plurality of calculations, whether the risk of loss of precision is below a loss of precision threshold. The precision reduction manager 20 may include an evaluation component 28 that determines whether to reduce the precision of the calculations 24 within the operation set 22 by evaluating the result expression of the operation set 22. The evaluation component 28 may attempt to reduce the precision of intermediate data, function parameters, memory loads, and / or any other calculations 24 while monitoring the calculations 24 that may be sensitive to the cost of precision and / or weighted conversion operations. For example, the values ​​of the calculations 24 may be compared to an expected range 35 (e.g., a minimum and maximum value of the value) and / or a precision bound 37 (e.g., a number of bits of the value). In response to these values ​​being outside the expected range 35 and / or the precision bound 37, the calculations 24 may be considered to be sensitive to precision. Thus, when the calculations 24 are reduced to half precision 38, the evaluation component 28 may identify possible results and / or a risk of loss of precision 31.

[0057] For each computation 24 of the set of operations 22, the evaluation component 28 may determine a risk of loss of precision 31 and may compare the risk of loss of precision to a precision loss threshold 33. The precision loss threshold 33 may identify whether the computation 24 supports half precision 38 and / or whether the computation 24 may be sensitive to half precision 38. In this way, the evaluation component 28 may perform an iterative process to determine whether to reduce the precision of the computations 24 within the set of operations 22.

[0058] Evaluation component 28 may also consider power consumption benefits from the conversion operation when determining whether precision may be reduced and / or under what circumstances a loss of precision is acceptable for set of operations 22. Power consumption benefits to computer device 102 that may occur when using half precision 38 in calculations 24 may outweigh the loss of precision that may occur from reducing the precision of calculations 24.

[0059] For example, for a value of a computation 24 within an expression tree, the evaluation component 28 may receive a range x=70000. The evaluation component 28 may determine that the range x=70000 exceeds the expected range 35 of the computation 24 (e.g., the range is outside the range for half-precision values) and may determine that the risk of loss of precision 31 is above the loss of precision threshold 33. However, when using half-precision 38 in the computation 24, the evaluation component 28 may determine that the lost precision may be acceptable to obtain a benefit of power consumption savings for the computer device 102. The evaluation component 28 may modify the risk of loss of precision 31 in response to determining that the power consumption benefit outweighs the loss of precision.

[0060] At 308, method 300 may include providing a notification with a possible precision loss warning when the precision loss risk 31 is above the precision loss threshold. When the precision loss risk 31 is above the precision loss threshold 33, evaluation component 28 may generate a notification 32 with a warning indicating that computation 24 may not support half-precision 38. For example, if computation 24 cannot work with lower precision (e.g., raising a value to a power), the precision loss risk 31 may be above the precision loss threshold 33. Additionally, if GPU 44 does not support lower precision, the precision loss risk 31 may be above the precision loss threshold 33. Additionally, notification 32 may include: information about potential power consumption benefits to computer device 102 by using half-precision 38 in computation 24; and / or information about potential precision loss using half-precision 38. Compiler 16 may transmit notification 32 to user interface 50 so that the user can use the information when editing program code 14.

[0061] At 310, method 300 may include generating edited program code by rewriting the computation to half precision when the risk of precision loss is below a precision loss threshold. When the risk of precision loss 31 is below the precision loss threshold 33, evaluation component 28 may identify that computation 36 supports half precision 38. If computation 24 supports lower precision and / or if GPU 44 supports lower precision, risk of precision loss 31 may be below precision loss threshold 33.

[0062] The precision reduction manager 20 may automatically generate edited program code 34 by rewriting the precision of the identified calculations 36 with half precision 38. The precision reduction manager 20 may also generate a report 40 with information about the changes made to the precision. For example, the report 40 may include the identified calculations 36 and / or the set of operations 22. The report 40 may also include an explanation of the changes made to the precision and / or the decision not to reduce the precision. On the other hand, the report 40 may include the calculations 36 identified for half precision 38, and the report 40 may be transmitted to a user interface 50 for a user to review and / or modify the program code 14 in response to the information provided in the report 40.

[0063] At 312, method 300 may include providing the edited program code. Compiler 16 may transmit the edited program code to GPU 44 for processing. GPU 44 may execute edited program code 34 using half precision 38 for identified calculations 36 to generate output 46 for presentation on display 48. By using half precision 38 in identified calculations 36, throughput capabilities of identified calculations 36 used in shader program 12 in GPU 44 may be improved, and memory accesses of GPU 44 may be accelerated.

[0064] The method 300 may be used to safely reduce the precision of operations within a shader program 12 from single precision 26 to half precision 38 , thereby improving the performance of the shader program 12 .

[0065] Reference now Figure 4 , the method 400 may be performed by the computer device 102 ( Figure 1 ) is used to evaluate the shader program 12 ( Figure 1 ) used in the calculation 24( Figure 1 ) with lower precision. The actions of method 400 can be referred to below Figure 1 The architecture of the

[0066] At 402, method 400 may include receiving, from a compiler, edited program code for a shader program for computing using half precision. Compiler 16 may transmit edited program code 34 to user interface 50 for display.

[0067] At 404, method 400 may optionally include receiving a report identifying changes to calculations using half precision. In one aspect, the user may use the information in report 40 to further edit program code 14 and / or edited program code 34 and create revised program code 52. For example, the user may change the precision of identified calculations 36 in program code 14. Additionally, the user may choose to change a portion of the identified calculations to half precision 38. In this way, the user may use the provided information as a guide to reduce precision within shader program 12.

[0068] At 406 , method 400 may include executing the edited program code using the application. A user may open application 10 or a trace of application 10 using user interface 50 and may run the edited program code 34 received from compiler 16 using application 10 .

[0069] At 408, method 400 may include determining whether the output quality of the application is within a quality threshold. The image quality of output 46 may be evaluated to determine whether shader program 12 can tolerate reduced precision without reducing the image quality of output 46. For example, the image quality of rendered image 47 may be compared to quality threshold 30 to determine whether the quality of rendered image 47 is within the quality threshold. When there is little loss in the image quality of rendered image 47, the quality of rendered image 47 may be below the quality threshold. In this way, shader program 12 may tolerate reduced precision without reducing the image quality in output 46, and at 310, method 300 may end.

[0070] The quality of rendered image 47 may be above the quality threshold when there is a loss in image quality of rendered image 47. Thus, shader program 12 may not tolerate reduced precision and further revisions and / or changes may be made to shader program 12 without reducing image quality in output 46.

[0071] At 412, method 400 may optionally include revising the edited program code. When image quality is lost, the user may revise the edited program code 34 and generate a revised program code 52 that changes the amount of lower precision used in the shader program 12. The revised program code 52 may be transmitted to the compiler 16 for further evaluation and / or modification.

[0072] At 414, method 400 may optionally include adjusting the analysis performed by the compiler. In addition, when image quality is lost, the user may adjust the analysis performed by compiler 16. For example, the user may remove specific instructions from the search performed by compiler 16 so that the compiler may not identify the instructions as tolerant to lower precision. In addition, the user may turn off channel 18, which performs a search to identify an operation set 22 in which precision can be reduced.

[0073] At 416, the method 400 may optionally include adding or removing a calculation path from the analysis performed by the compiler. The user may also identify one or more calculations 24 in which precision may be reduced within the shader program code 14, and transmit the calculations 24 to the compiler 16 for evaluation. The evaluation component 28 may evaluate whether precision may be reduced for the calculations 24, and may provide a notification 32 to the user with a warning about possible precision loss. The user may change the precision of the calculations 24 in response to information received from the compiler 16, 14, and may generate a revised program code 52. The revised program code 52 may be transmitted to the compiler 16 for further evaluation and / or modification.

[0074] Method 400 can provide a user with an interactive process for reducing precision in a shader program. In addition, method 400 can provide the user with more details and / or information for use in making a decision to reduce precision in a shader program. In this way, the user can more easily quantify the loss of precision when developing a shader program.

[0075] Reference now Figure 5 ,and Figure 1In contrast, the example computer 500, which may be configured as a computer device 102, includes additional component details depending on the implementation. In one example, the computer 500 may include processing functionality associated with one or more components and functions described herein. The processor 54 may include a single or multiple groups of processors or a multi-core processor. In addition, the processor 54 may be implemented as an integrated processing system and / or a distributed processing system.

[0076] The computer 500 may also include a memory 56, such as for storing local versions of applications executed by the processor 54. The memory 56 may include any type of memory that can be used by a computer, such as random access memory (RAM), read-only memory (ROM), tape, magnetic disk, optical disk, volatile memory, non-volatile memory, and any combination thereof. Additionally, the processor 54 may include and execute an operating system 110 ( Figure 1 ).

[0077] In addition, the computer 500 may include a communication component 58 that provides for establishing and maintaining communications with one or more parties using the hardware, software, and services described herein. The communication component 58 may facilitate communications between components on the computer device 102, and between the computer device 102 and external devices, such as devices across a communication network and / or devices serially or locally connected to the computer device 102. For example, the communication component 58 may include one or more buses, and may also include transmit and receive chain components associated with a transmitter and a receiver, respectively, that are operable to interface with external devices.

[0078] Additionally, the computer 500 may include a data repository 60, which may be any suitable combination of hardware and / or software that provides mass storage of information, databases, and programs employed in conjunction with the implementations described herein. For example, the data repository 60 may be a data storage device for the application 10, the GPU 44, the compiler 16, and / or the display 48.

[0079] The computer 500 may also include a user interface component 50 that is operable to receive input from a user of the computer device 102 and also operable to generate output for presentation to the user. The user interface component 50 may include one or more input devices, including but not limited to a keyboard, a numeric keypad, a mouse, a display 48 (e.g., which may be a touch-sensitive display), navigation keys, function keys, a microphone, a voice recognition component, any other mechanism capable of receiving input from a user, or any combination thereof. In addition, the user interface component 50 may include one or more output devices, including but not limited to a display, a speaker, a tactile feedback mechanism, a printer, any other mechanism capable of presenting output to a user, or any combination thereof.

[0080] In implementation, user interface component 50 may transmit and / or receive messages corresponding to the operation of application 10, GPU 44, compiler 16, and / or display 48. In addition, processor 54 executes application 10, GPU 44, compiler 16, and / or display 48, and memory 56 or data storage repository 60 may store them.

[0081] As used in this application, the terms "component", "system", etc. are intended to include entities related to computers, such as but not limited to hardware, firmware, a combination of hardware and software, software, or software being executed. For example, a component can be, but not limited to, a process, a processor, an object, an executable file, an execution thread, a program, and / or a computer running on a processor. For example, both applications and computer devices running on a computer device can be components. One or more components can reside in a process and / or an execution thread, and a component can be located on a computer and / or distributed between two or more computers. In addition, these components can be executed from various computer-readable media having various data structures stored thereon. Components can communicate by means of local and / or remote processes, such as data from a component interacting with another component in a local system or a distributed system, and / or can communicate across networks, such as communicating by means of signals across the Internet with other systems.

[0082] Furthermore, the term "or" is intended to mean an inclusive "or" rather than an exclusive "or". That is, unless specified otherwise or clear from the context, the phrase "X employs A or B" is intended to mean any of the natural inclusive permutations. That is, the phrase "X employs A or B" is satisfied by any of the following: X employs A; X employs B; or X employs A and B. In addition, the articles "a" and "an" used in this application and the appended claims should generally be construed to mean "one or more" unless specified otherwise or clear from the context to be directed to a singular form.

[0083] Various implementations or features may have been presented in terms of systems that may include several devices, components, modules, etc. It should be understood and appreciated that the various systems may include additional devices, components, modules, etc. and / or may not include all of the devices, components, modules, etc. discussed in conjunction with the figures. Combinations of these methods may also be used.

[0084] Various illustrative logic, logic blocks, and actions of the methods described in conjunction with the embodiments disclosed herein may be implemented or performed with a general purpose processor, a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic device, discrete gate or transistor logic, discrete hardware components, or any combination thereof designed to perform the functions described herein, specifically programmed. A general purpose processor may be a microprocessor, but in an alternative, the processor may be any conventional processor, controller, microcontroller, or state machine. The processor may also be implemented as a combination of computer devices, for example, a combination of a DSP and a microprocessor, a plurality of microprocessors, one or more microprocessors coupled to a DSP, or any other such configuration. Additionally, at least one processor may include one or more components operable to perform one or more of the above steps and / or actions.

[0085] In addition, the steps and / or actions of the method or algorithm described in conjunction with the implementation disclosed herein may be directly embodied in hardware, in a software module executed by a processor, or in a combination of the two. The software module may reside in a RAM memory, a flash memory, a ROM memory, an EPROM memory, an EEPROM memory, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art. An exemplary storage medium may be coupled to a processor so that the processor can read information from the storage medium and write information to the storage medium. Alternatively, the storage medium may be integrated with the processor. In addition, in some implementations, the processor and the storage medium may reside in an ASIC. Additionally, the ASIC may reside in a user terminal. Alternatively, the processor and the storage medium may reside in a user terminal as discrete components. In addition, in some implementations, the steps and / or actions of the method or algorithm may reside on a machine-readable medium and / or a computer-readable medium as one of a code set and / or an instruction set or any combination thereof, which may be incorporated into a computer program product.

[0086] In one or more implementations, the functions described may be implemented in hardware, software, firmware, or any combination thereof. If implemented in software, these functions may be stored or transmitted as one or more instructions or codes on a computer-readable medium. Computer-readable media include computer storage media and communication media, including any media that facilitates the transfer of computer programs from one place to another. Storage media may be any available media that a computer can access. As an example and not limitation, such computer-readable media may include RAM, ROM, EEPROM, CD-ROM or other optical disk storage devices, disk storage devices or other magnetic storage devices, or any other medium that can be used to store desired program codes in the form of instructions or data structures and can be accessed by a computer. Disks and optical disks used herein include compact disks (CDs), laser optical disks, optical disks, digital versatile disks (DVDs), floppy disks, and blue-ray disks, wherein disks typically reproduce data magnetically, and optical disks typically reproduce data optically with lasers. The above combination should also be included in the scope of computer-readable media.

[0087] Although the implementation of the present disclosure has been described in conjunction with its examples, it will be appreciated by those skilled in the art that variations and modifications may be made to the above implementations without departing from the scope thereof. Other implementations will be apparent to those skilled in the art from consideration of the specification or through practice, according to the examples disclosed herein.

Claims

1. A computer device, include: Graphics Processing Unit (GPU) supporting half-precision storage and arithmetic in shader programs; Memory for storing data and instructions; at least one processor configured to communicate with the memory; a compiler in communication with the memory and the at least one processor, wherein the compiler is operable to: receiving program code for a shader program for use with the GPU; performing at least one pass on the program code to automatically analyze the structure of the program code, and in response to the analysis identifying an operation set as supporting half precision, selecting the operation set within the program code to reduce the precision of a plurality of computations used by the operation set, wherein the analysis is a trained search that uses the following for identifying the operation set as supporting half precision: a combination of hardware information and a list of previously defined operations that support half precision and a list of previously defined operations that are sensitive to reduced precision; For each computation of the plurality of computations, assessing a risk of loss of precision of reducing the precision for the computation to half precision; In response to the risk of precision loss being below a precision loss threshold, generating edited program code by rewriting the calculation to the half precision; In response to the risk of loss of accuracy being above the loss of accuracy threshold, providing a notification with a warning for a possible loss of accuracy; as well as A report is generated having information about changes made to precision in the edited program code, wherein the report identifies one or more calculations in the edited program in which the precision is reduced and provides information for decisions to maintain the precision for other calculations in the edited program code. 2 . The computer device of claim 1 , wherein the precision loss threshold identifies whether the calculation supports the half precision. 3 . The computer device of claim 1 , wherein the set of operations is selected in response to being previously identified as supporting half precision or in response to user input. 4 . The computer device of claim 1 , wherein hardware parameters of the GPU are used by the compiler to evaluate the risk of precision loss. 5 . The computer device of claim 1 , wherein the risk of precision loss is higher than the precision loss threshold if the calculation does not support the half precision. The computer device according to claim 1 , wherein, in a case where the calculation supports the half precision, the risk of precision loss is lower than the precision loss threshold.

7. The computer device of claim 1, wherein the compiler is further operable to perform an iterative process to determine whether to reduce the precision of the plurality of computations within the set of operations.

8. The computer device of claim 1, wherein the report identifies changes made to the precision of the calculation and provides an explanation of the changes made.

9. The computer device of claim 1, wherein the compiler is further operable to: providing the compiled program code to the GPU for processing into output to be presented on a display; and The notification is provided to a user interface on the display.

10. A method for reducing the precision of calculations used in a shader program, include: receiving, at a compiler on a computer device, program code for a shader program for use with a graphics processing unit (GPU), the GPU supporting half-precision storage and arithmetic in the shader program; performing at least one pass on the program code to automatically analyze the structure of the program code, and in response to the analysis identifying an operation set as supporting half precision, selecting the operation set within the program code to reduce the precision of a plurality of computations used by the operation set, wherein the analysis is a trained search that uses the following for identifying the operation set as supporting half precision: a combination of hardware information and a list of previously defined operations that support half precision and a list of previously defined operations that are sensitive to reduced precision; For each computation of the plurality of computations, assessing a risk of loss of precision of reducing the precision for the computation to half precision; In response to the risk of precision loss being below a precision loss threshold, generating edited program code by rewriting the calculation to the half precision; In response to the risk of loss of accuracy being greater than the loss of accuracy threshold, providing a notification with a warning for loss of accuracy; as well as A report is generated having information about changes made to precision in the edited program code, wherein the report identifies one or more calculations in the edited program in which the precision is reduced and provides information for decisions to maintain the precision for other calculations in the edited program code. The method of claim 10 , wherein the precision loss threshold identifies whether the calculation supports the half precision. 12 . The method of claim 10 , wherein the set of operations is selected in response to being previously identified as supporting half precision or in response to user input.

13. The method of claim 10, wherein hardware parameters of the GPU are used by the compiler to evaluate the risk of precision loss. The method of claim 10 , wherein the risk of precision loss is higher than the precision loss threshold if the calculation does not support the half precision. The method according to claim 10 , wherein, in a case where the calculation supports the half precision, the risk of precision loss is lower than the precision loss threshold.

16. The method according to claim 10, further comprising: include: An iterative process is performed to determine whether to reduce the precision of the plurality of calculations within the set of operations.

17. The method of claim 10, wherein the report identifies changes made to the precision of the calculation and provides an explanation for the changes made.

18. The method according to claim 10, wherein the method further comprises include: A level of analysis of the program code is adjusted in response to user input.

19. The method according to claim 10, wherein the method further comprises include: providing the compiled program code to the GPU for processing into output to be presented on a display; as well as The notification is provided to a user interface on the display.

20. A non-transitory computer readable medium storing instructions executable by a computer device, the instructions include: at least one instruction for causing the computer device to receive program code for a shader program for use with a graphics processing unit (GPU), the GPU supporting half-precision storage and arithmetic in the shader program; at least one instruction for causing the computer device to perform at least one pass on the program code to automatically analyze the structure of the program code and, in response to the analysis identifying an operation set as supporting half precision, select the operation set within the program code to reduce the precision of a plurality of computations used by the operation set, wherein the analysis is a trained search, the trained search using the following for identifying the operation set as supporting half precision: a combination of hardware information and a list of previously defined operations that support half precision and a list of previously defined operations that are sensitive to reduced precision; at least one instruction for causing the computer device to evaluate, for each of the plurality of computations, a risk of loss of precision of reducing the precision of the computation to half precision; at least one instruction for causing the computer device to generate edited program code by rewriting the calculation to the half precision in response to the risk of loss of precision being below a loss of precision threshold; at least one instruction for causing the computer device to provide a notification with a warning for loss of precision in response to the risk of loss of precision being above the loss of precision threshold; as well as At least one instruction for causing the computer device to generate a report having information about changes made to precision in the edited program code, wherein the report identifies one or more calculations in the edited program in which the precision is reduced and provides information for decisions to maintain the precision for other calculations in the edited program code.

Citation Information

Patent Citations

  • Method and apparatus for generating resource efficient computer program code

    CN103493015A

  • Method and apparatus for generation of programmable shader configuration information from state-based control information and program instructions

    US20040012597A1