A GPU driver performance analysis method
By inserting a high-precision timestamp API into GPU applications and storing performance data in the video memory area, the problems of existing tools occupying system resources and inaccurate timestamps in low-memory environments are solved, and efficient and accurate GPU driver performance analysis is achieved.
Patent Information
- Application Number
- CN202410767149.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-14
- Publication Date
- 2025-09-26
- Estimated Expiration
- 2044-06-14
AI Technical Summary
Existing GPU driver performance analysis tools occupy large system resources in low-memory embedded environments, have insufficient timestamp accuracy, and cannot perform accurate performance analysis on platforms that do not rely on an operating system.
A high-precision timestamp API is designed. Timestamps are inserted at the function entry and exit locations of GPU applications through C language inline assembly. Performance data is collected and stored in the GPU memory area. It is then saved to the file system in stages for analysis.
It achieves high-precision performance analysis on a platform that does not rely on an operating system, reduces system memory usage, accurately locates GPU driver bottlenecks, and improves analysis efficiency.
Smart Images

Figure CN119149358B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of GPU performance analysis, and more specifically, to a GPU driver performance analysis method. Background Art
[0002] With the continuous advancement of GPU chip technology, GPU chips have powerful computing and graphics rendering capabilities and are widely used in aerospace, artificial intelligence, industrial automation and other fields. GPU driver performance plays a key role in the reliability, stability, and event response time of time-sensitive business scenarios.
[0003] When analyzing GPU driver performance, the following methods are commonly used:
[0004] (1) Using the Gprof performance analysis tool, by analyzing the "flat profile" generated when the GPU application is running, the number of calls, call time, call relationship, etc. of each function in the GPU driver can be obtained;
[0005] (2) Using the Perf performance analysis tool, you can sample GPU applications, record the sampled data, and generate a flame graph. By analyzing the top-level display of the flame graph, you can intuitively view the performance status of the GPU driver function.
[0006] During the implementation of GPU driver performance analysis, we found that the analysis method based on Gprof and Perf performance analysis tools has at least the following technical issues:
[0007] (1) Grof and Perf performance analysis tools are mainly used in UNIX and UNIX-like systems and require system support;
[0008] (2) Grof and Perf performance analysis tools usually read the timer or counter provided by the operating system to generate timestamps. In high-load systems or when there is a delay in timestamp generation, the accuracy of timestamps will be affected.
[0009] (3) The Grof and Perf performance analysis tools need to store a large amount of function call stacks and timing information in memory, which will have a significant impact on the system in a low-memory embedded environment.
[0010] It can be seen that the existing technology is limited by the system environment of the target platform, consumes a large amount of system memory, and the accuracy of the timestamp needs to be improved. Summary of the Invention
[0011] In response to the technical problems existing in the prior art, the present invention provides a GPU driver performance analysis method, which aims to help technicians optimize GPU performance and improve overall system performance and user experience by providing more accurate performance analysis data.
[0012] The present invention provides a GPU driver performance analysis method, comprising:
[0013] S1, open up a GPU memory area;
[0014] S2, based on the C language embedded assembly method, designs a high-precision timestamp API. It inserts the high-precision timestamp API at the function entry, function return or exit position of each function under test in the GPU application program to generate the GPU driver under test object.
[0015] S3, loading and running the GPU application to dynamically collect the performance data of the object under test, the performance data is obtained through the insertion of a high-precision timestamp API;
[0016] S4, storing the performance data of the object under test in the GPU memory area, and when the performance data in the GPU memory area meets the saving condition, pausing the GPU application and saving the performance data in the GPU memory area to the first file system;
[0017] S5, repeatedly executing S3 and S4 multiple times to save the collected performance data of the measured object into multiple first file systems;
[0018] S6, closing the GPU application, analyzing the performance data in each first file system, and saving the data analysis results to the corresponding second file system.
[0019] On the basis of the above technical solution, the present invention can also make the following improvements.
[0020] Optionally, the S2 is based on C language embedded assembly mode to design a high-precision timestamp API, including:
[0021] Use C language embedded assembly to read the values of the CNTFRQ register and the CNTPCT register to design a high-precision timestamp API.
[0022] Optionally, S3 loads and runs a GPU application to dynamically collect performance data of the object under test. The performance data is obtained by inserting a high-precision timestamp API, including:
[0023] Load and run the GPU application, and use the function name of each tested function, the CPU counter value at the function entry position, and the CPU counter value when the function returns or exits to generate performance data for each tested function;
[0024] The performance data of each tested function is stored in the GPU memory area.
[0025] Optionally, the performance data in the GPU memory area meets the storage condition and is adjusted according to the size of the performance data, the scenario of the GPU application and the running time of the GPU application.
[0026] Optionally, in S4, when the performance data in the GPU memory area meets the saving condition, pausing the GPU application and saving the performance data in the GPU memory area to the file system includes:
[0027] When the performance data fills up the memory space of the GPU display memory area, pausing the GPU application and saving the performance data in the GPU display memory area to the first file system;
[0028] When the GPU application includes multiple scenes, each time a GPU application for a scene is loaded and run, the GPU application for the scene is paused, performance data of the scene is stored in the GPU display memory area, and the performance data in the GPU display memory area is saved to a first file system, and performance data corresponding to GPU applications of different scenes are stored in different first file systems;
[0029] When the GPU application running time reaches the set running time, the GPU application is suspended, the performance data is stored in the GPU display memory area, and the performance data in the GPU display memory area is saved in a first file system.
[0030] Optionally, the step S6 of closing the GPU application, analyzing the performance data in each first file system, and saving the data analysis results to the corresponding second file system includes:
[0031] Analyze the performance data in each first file system, count the number of executions of each tested function and the time required for the execution of each tested function, and analyze and calculate the total execution time, average execution time, maximum execution time, and minimum execution time of each tested function;
[0032] The tested functions are sorted according to the total execution time, and the performance data analysis results of each tested function are saved in the corresponding second file system.
[0033] Optionally, calculate the execution time of each function under test, including:
[0034] The CPU counter value at the entry of the function under test is collected by inserting a high-precision timestamp API into the function entry position of the function under test, and the CPU counter value when the function returns or exits is collected by inserting a high-precision timestamp API into the function return or exit position of the function under test;
[0035] The time required for the function under test to run is calculated based on the CPU counter value at the function entry, the CPU counter value when the function returns or exits, and the frequency of the CPU timer counter.
[0036] Optionally, calculating the time required for the function under test to run according to the CPU counter value at the function entry, the CPU counter value when the function returns or exits, and the frequency of the CPU timer counter includes:
[0037]
[0038] Where t is the time required for the function under test to run, in milliseconds, tick2 is the CPU counter value when the function returns or exits, tick1 is the CPU counter value at the function entry, and freq is the frequency of the CPU timer counter.
[0039] This invention provides a GPU driver performance analysis method with a designed high-precision timestamp API that is independent of the operating system. After the CPU is powered on, it accurately collects timestamps for each function entry point and function return or exit point, improving code execution efficiency. The calculated timestamp information can be accurate to the nanosecond level. The method stores the collected GPU driver performance information in video memory, eliminating system memory usage and minimizing the impact on the GPU driver and the system itself. During performance data collection, the method can collect and analyze GPU driver performance data in stages, as needed, to accurately locate GPU driver bottlenecks and improve technicians' work efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Figure 1 A flowchart of a GPU driver performance analysis method provided by the present invention;
[0041] Figure 2 This is a schematic diagram of how performance data is stored in the GPU memory area;
[0042] Figure 3 A schematic diagram of the time required to run the function under test;
[0043] Figure 4 A flowchart of a GPU driver performance analysis method according to an embodiment is shown. DETAILED DESCRIPTION
[0044] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention. In addition, the technical features in the various embodiments or single embodiments provided by the present invention can be arbitrarily combined with each other to form a feasible technical solution. This combination is not restricted by the sequence of steps and / or structural composition mode, but must be based on the ability of ordinary technicians in this field to implement it. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such a combination of technical solutions does not exist and is not within the scope of protection required by the present invention.
[0045] In some embedded application scenarios, the target system may not support the installation of performance analysis tools such as perf and Gprof, or the system memory may be too small to meet the requirements for running performance analysis tools such as perf and Gprof. Running performance analysis tools such as perf and Gprof in an embedded environment may affect the system itself, resulting in large errors in the obtained timestamp information and inaccurate analysis results.
[0046] The present invention proposes a GPU driver performance analysis method based on high-precision timestamps, aiming to solve the technical problem that GPU driver performance cannot be analyzed in the above application scenarios.
[0047] Figure 1 A flow chart of a GPU driver performance analysis method provided by the present invention is as follows: Figure 1 As shown, the method includes:
[0048] S1, open up a GPU memory area.
[0049] Among them, a GPU memory area A with a size of 50M Byte can be opened to store performance data later.
[0050] S2, based on the C language embedded assembly method, designs a high-precision timestamp API, inserts the high-precision timestamp API at the function entry position, function return or exit position of each tested function of the GPU application, and generates a GPU driver test object.
[0051] It can be understood that a high-precision timestamp API is designed using C language inline assembly to read the values of the CNTFRQ register and the CNTPCT register. As needed, the high-precision timestamp API is inserted into each function under test in the GPU application that requires analysis. Specifically, as needed, the high-precision timestamp API can be inserted into all functions under test in the GPU application, or into the functions under test that require analysis.
[0052] A high-precision timestamp API is inserted at the function entry position and function return or exit position of each tested function that needs to be analyzed in the GPU application program to generate the entire GPU driver tested body.
[0053] S3, loading and running the GPU application, dynamically collecting the performance data of the object under test, and the performance data is obtained by inserting a high-precision timestamp API.
[0054] It is understood that after S2 inserts a high-precision timestamp API at different locations in each function under test in the GPU application, it loads and runs the GPU application and collects performance data of the object under test in real time. The performance data is obtained by inserting the high-precision timestamp API at different locations in the function. The performance data generated for each function under test includes the function name, the CPU counter value at the function entry location, and the CPU counter value when the function returns or exits.
[0055] S4, storing the performance data of the object under test in the GPU memory area, and when the performance data in the GPU memory area meets the saving condition, pausing the running of the GPU application and saving the performance data in the GPU memory area to the first file system.
[0056] It is understandable that the performance data of each tested function is stored in the GPU memory area. Figure 2 The storage method shown is to store the data in GPU memory area A, and each performance data is stored in the corresponding address of the GPU memory area.
[0057] When storing the performance data of the subject under test in the GPU memory area, if the performance data in the GPU memory area meets the storage conditions, the GPU application needs to be suspended, and then the performance data in the GPU memory area is transferred and stored in the file system. The storage conditions of the performance data in the GPU memory area can be adjusted based on the size of the performance data, the scenario of the GPU application, the runtime, etc.
[0058] Among them, the first situation: when the performance data fills up the memory space of the GPU display memory area, the GPU application is suspended and the performance data in the GPU display memory area is saved in the first file system.
[0059] The second situation: When the GPU application includes multiple scenes, each time a GPU application for a scene is loaded and run, the GPU application for the scene is paused, the performance data of the scene is stored in the GPU video memory area, and the performance data in the GPU video memory area is saved to a first file system. The performance data corresponding to GPU applications for different scenes are stored in different first file systems.
[0060] The third situation: when the GPU application running time reaches the set running time, the GPU application is suspended, the performance data is stored in the GPU display memory area, and the performance data in the GPU display memory area is saved to a first file system.
[0061] S5, repeatedly executing S3 and S4 multiple times, and saving the collected performance data of the measured object into multiple first file systems.
[0062] It can be understood that after the performance data saving conditions in GPU memory area A are met, the GPU application is paused and the performance collection data in GPU memory area A is saved to the file system perf_date_1; the GPU application is continued to be executed multiple times to collect the performance data of each executed GPU program, and the performance data of each collected GPU program is stored in the file system perf_date_2, perf_date_3...perf_date_n.
[0063] S6, closing the GPU application, analyzing the performance data in each first file system, and saving the data analysis results to the corresponding second file system.
[0064] It is understandable that after the performance data of the GPU-driven test object is collected, the performance data in each file system is analyzed. Among them, based on the binary tree sorting and search algorithm, the number of executions of each tested function and the time required for each operation are counted, and the total execution time, average running time, maximum running time and shortest running time of each tested function are analyzed and calculated. The tested functions are sorted according to the total execution time, and the data performance analysis results of each tested function are saved to the file system result_data_1.
[0065] The time required for each execution of the tested function is counted, including:
[0066] The CPU counter value at the function entry of the function under test is collected by inserting a high-precision timestamp API at the function entry position of the function under test, and the CPU counter value when the function returns or exits is collected by inserting a high-precision timestamp API at the function return or exit position of the function under test; the time required for the function under test to run is calculated based on the CPU counter value at the function entry, the CPU counter value when the function returns or exits, and the frequency of the CPU timing counter.
[0067] See also Figure 3 , the calculation method for the running time of the tested function is:
[0068]
[0069] Where t is the time required for the function under test to run, in milliseconds, tick2 is the CPU counter value when the function returns or exits, tick1 is the CPU counter value at the function entry, and freq is the frequency of the CPU timer counter.
[0070] Analyze the performance data in each system file and store the analysis results in another file system. Repeat the above steps to process the performance data in the file systems perf_date_2, perf_date_3, ..., perf_date_n, and finally generate files such as result_data_2, result_data_3, ..., result_data_n to store the performance analysis results.
[0071] The present invention is implemented in a specific embodiment of the development environment of FT2000 / 4 in VxWorks6.9, and its specific flow chart is as follows: Figure 4 As shown:
[0072] (1) Open up a 50M Byte GPU memory area A0;
[0073] (2) Using C language embedded assembly, read the values of the CNTFRQ register (timer frequency value) and the CNTPCT register (physical counter) to design a high-precision timestamp API;
[0074] (3) Insert the API function __GL_HEADER() at the entry of the GPU driver function being analyzed and insert the API function __GL_FOOTER() before the function returns to form the tested object;
[0075] (4) Loading the GPU application, collecting the performance data of the object under test, and saving it to the GPU memory area A0. When A0 is full, pausing the GPU application, and saving the data in the GPU memory area A0 to the file system;
[0076] (5) Repeat the data collection 10 times and generate perf_data_1, perf_data_2…perf_data_10 files in the file system;
[0077] (6) Open the perf_data_1 file in the file system and calculate the execution time of the object under test; based on the binary tree sorting search algorithm, obtain the number of executions, average execution time, maximum execution time, and minimum execution time of the object under test; intelligently sort the total execution time of the object under test and save the data analysis results to the file system result_data_1;
[0078] (7) After repeating the analysis 10 times, result_data_2…result_data_n files are generated in the file system in sequence;
[0079] The specific content of the data analysis results is shown in Table 1 below. The GPU driver can be optimized based on the analysis results.
[0080] Table 1 Data analysis results
[0081]
[0082] The GPU driver performance analysis method provided by the present invention has the following beneficial effects:
[0083] (1) The high-precision API designed by the present invention does not rely on the operating system. After the CPU is powered on, the CPU timer frequency and counter value are read using assembly language, which can improve the efficiency of code execution and the calculated timestamp information can be accurate to the nanosecond level.
[0084] (3) The present invention stores the collected performance information of the GPU driver in the video memory, which does not occupy the system memory and reduces the impact on the GPU driver and the system itself. When collecting performance data, the performance data of the GPU driver can be collected and analyzed in stages according to needs, and the bottleneck position of the GPU driver can be accurately located, thereby improving the work efficiency of technicians.
[0085] It should be noted that, in the above embodiments, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant description of other embodiments.
[0086] It will be understood by those skilled in the art that embodiments of the present invention may be provided as methods, systems, or computer program products. Thus, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0087] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowcharts and / or block diagrams, as well as combinations of processes and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded computer, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowcharts and / or block diagrams. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0088] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0089] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0090] Although the preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention.
[0091] Obviously, those skilled in the art may make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if such changes and modifications fall within the scope of the claims and their equivalents, the present invention is intended to include such changes and modifications.
Claims
1. A GPU driver performance analysis method, characterized in that: include: S1, open up a GPU memory area; S2, based on the C language embedded assembly method, designs a high-precision timestamp API. It inserts the high-precision timestamp API at the function entry, function return or exit position of each function under test in the GPU application program to generate the GPU driver under test object. S3, loading and running the GPU application to dynamically collect the performance data of the object under test, the performance data is obtained through the insertion of a high-precision timestamp API; S4, storing the performance data of the object under test in the GPU memory area, and when the performance data in the GPU memory area meets the saving condition, pausing the GPU application and saving the performance data in the GPU memory area to the first file system; S5, repeatedly executing S3 and S4 multiple times to save the collected performance data of the measured object into multiple first file systems; S6, closing the GPU application, analyzing the performance data in each first file system, and saving the data analysis results to the corresponding second file system; The S2 is based on the C language embedded assembly method to design a high-precision timestamp API, including: Use C language embedded assembly to read the values of the CNTFRQ register and the CNTPCT register to design a high-precision timestamp API.
2. The GPU driver performance analysis method according to claim 1, characterized in that: S3 loads and runs the GPU application to dynamically collect the performance data of the object under test. The performance data is obtained by inserting a high-precision timestamp API, including: Load and run the GPU application, and use the function name of each tested function, the CPU counter value at the function entry position, and the CPU counter value when the function returns or exits to generate performance data for each tested function; The performance data of each tested function is stored in the GPU memory area.
3. The GPU driver performance analysis method according to claim 1, wherein: The performance data in the GPU display memory area meets the storage conditions and is adjusted according to the size of the performance data, the scenario of the GPU application and the running time of the GPU application.
4. The GPU driver performance analysis method according to claim 3, characterized in that: In S4, when the performance data in the GPU display memory area meets the saving condition, pausing the GPU application and saving the performance data in the GPU display memory area to the file system includes: When the performance data fills up the memory space of the GPU display memory area, pausing the GPU application and saving the performance data in the GPU display memory area to the first file system; When the GPU application includes multiple scenes, each time a GPU application for a scene is loaded and run, the GPU application for the scene is paused, performance data of the scene is stored in the GPU display memory area, and the performance data in the GPU display memory area is saved to a first file system, and performance data corresponding to GPU applications of different scenes are stored in different first file systems; When the GPU application running time reaches the set running time, the GPU application is suspended, the performance data is stored in the GPU display memory area, and the performance data in the GPU display memory area is saved in a first file system.
5. The GPU driver performance analysis method according to claim 1, wherein: The step S6, closing the GPU application, analyzing the performance data in each first file system, and saving the data analysis results to the corresponding second file system, includes: Analyze the performance data in each first file system, count the number of executions of each tested function and the time required for the execution of each tested function, and analyze and calculate the total execution time, average execution time, maximum execution time, and minimum execution time of each tested function; The tested functions are sorted according to the total execution time, and the performance data analysis results of each tested function are saved in the corresponding second file system.
6. The GPU driver performance analysis method according to claim 5, characterized in that: Statistics on the running time of each tested function, including: The CPU counter value at the entry of the function under test is collected by inserting a high-precision timestamp API into the function entry position of the function under test, and the CPU counter value when the function returns or exits is collected by inserting a high-precision timestamp API into the function return or exit position of the function under test; The time required for the function under test to run is calculated based on the CPU counter value at the function entry, the CPU counter value when the function returns or exits, and the frequency of the CPU timer counter.
7. The GPU driver performance analysis method according to claim 6, characterized in that: The method of calculating the time required for the function to be tested to run according to the CPU counter value at the function entry, the CPU counter value when the function returns or exits, and the frequency of the CPU timer counter includes: Where t is the time required for the function under test to run, in milliseconds, tick2 is the CPU counter value when the function returns or exits, tick1 is the CPU counter value at the function entry, and freq is the frequency of the CPU timer counter.
Citation Information
Patent Citations
Application performance analysis system and method
CN111611158A
Accurate timestamp or export counter value generation on complex CPU
CN116635833A