GPU driving performance analysis method
The GPU driver performance analysis method addresses system limitations by using a high-precision timestamp API in GPU memory, ensuring accurate data collection and analysis, and reducing system impact, thereby enhancing efficiency.
Patent Information
- Application Number
- CN202410767149.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-14
- Publication Date
- 2024-12-17
- Estimated Expiration
- 2044-06-14
AI Technical Summary
Existing GPU driver performance analysis tools like Gprof and Perf are limited by system environment, consume significant system memory, and suffer from inaccurate timestamps, especially in high-load or low-memory embedded systems.
A GPU driver performance analysis method using a high-precision timestamp API inserted at function entry and exit points, storing data in GPU memory, and saving to file systems when conditions are met, without relying on the operating system.
Accurate performance data collection and analysis are achieved, reducing system impact and enabling precise bottleneck identification, improving technician efficiency.
Smart Images

Figure CN119149358A_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 update of GPU chip technology, GPU chips have powerful computing and graphics rendering capabilities and have been 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 currently commonly used:
[0004] (1) Use the Gprof performance analysis tool to analyze the "flat profile" generated when the GPU application is running to obtain the number of calls, call time, call relationship, etc. of each function in the GPU driver;
[0005] (2) Use the Perf performance analysis tool to sample GPU applications, record 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] In the specific implementation process of GPU driver performance analysis, it was found that the analysis method based on Gprof and Perf performance analysis tools has at least the following technical problems:
[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, needs to consume a large amount of system memory, and the accuracy of the timestamp needs to be improved. Summary of the invention
[0011] In view of 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, design a high-precision timestamp API, insert the high-precision timestamp API into the function entry position, function return or exit position of each tested function of the GPU application program, and generate a GPU driver tested object;
[0015] S3, loading and running the GPU application to dynamically collect the performance data of the object under test, where the performance data is obtained through an inserted 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, and saving 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] Based on the above technical solution, the present invention can also make the following improvements.
[0020] Optionally, the S2 designs a high-precision timestamp API based on C language embedded assembly, including:
[0021] Use C language embedded assembly method to read the value of CNTFRQ register and the value of 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, where 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 display memory area.
[0025] Optionally, the performance data in the GPU video 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 video memory area meets the saving condition, pausing the GPU application and saving the performance data in the GPU video memory area to the file system includes:
[0027] When the performance data fills up the memory space of the GPU video memory area, pausing the GPU application and saving the performance data in the GPU video memory area to the first file system;
[0028] When the GPU application includes multiple scenes, each time a GPU application of a scene is loaded and run, the GPU application of the scene is paused, 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, 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 result 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 shortest 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, count the time required for each function under test to run, including:
[0034] The CPU counter value at the entrance 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;
[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 timing counter.
[0036] Optionally, the step of 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 timing counter includes:
[0037]
[0038] Among them, t is the time required for the function under test to run, in milliseconds, and tick 2 The CPU counter value when the function returns or exits, tick 1 is the CPU counter value at the function entry, and freq is the frequency of the CPU timer counter.
[0039] The present invention provides a GPU driver performance analysis method, which designs a high-precision timestamp API that does not rely on an operating system. After the CPU is powered on, the timestamps of each function entry position and function return or exit position can be accurately collected to improve the code execution efficiency, and the calculated timestamp information can be accurate to nanoseconds. The present invention stores the collected GPU driver performance information in the video memory, 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 demand, and the GPU driver bottleneck position can be accurately located to improve the work efficiency of technicians. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Figure 1 A flow chart of a GPU driver performance analysis method provided by the present invention;
[0041] Figure 2 It is a schematic diagram of the performance data storage method in the GPU video memory area;
[0042] Figure 3 A schematic diagram showing the time required for the function under test to run;
[0043] Figure 4 The figure is a flowchart of a GPU driver performance analysis method according to an embodiment. 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 in the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention. 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 subject to the constraints of the sequence of steps and / or the structural composition mode, but must be based on the ability of ordinary technicians in this field to achieve. When the combination of technical solutions is contradictory or cannot be achieved, it should be considered 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 does not support the installation of performance analysis tools such as perf and Gprof, or the system memory is too small to meet the needs of running performance analysis tools such as perf and Gprof. Running performance analysis tools such as perf and Gprof in an embedded environment will affect the system itself, and the timestamp information obtained will have large errors, resulting in inaccurate analysis results.
[0046] The present invention proposes a GPU driver performance analysis method based on high-precision timestamp, aiming to solve the technical problem that the 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 into the function entry position, function return or exit position of each tested function of the GPU application program, and generates a GPU driver tested object.
[0051] It is understandable that the C language embedded assembly method is used to read the value of the CNTFRQ register and the value of the CNTPCT register to design a high-precision timestamp API. As needed, the high-precision timestamp API is inserted into each tested function that needs to be analyzed in the GPU application. Specifically, according to the needs, the high-precision timestamp API can be inserted into all tested functions in the GPU application, and the high-precision timestamp API can also be inserted into the tested function that needs to be analyzed.
[0052] A high-precision timestamp API is inserted at the function entry position and the 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 program, dynamically collecting the performance data of the object under test, wherein the performance data is obtained by inserting a high-precision timestamp API.
[0054] It is understandable that after S2 inserts the high-precision timestamp API at different positions of each tested function of the GPU application, it loads and runs the GPU application and collects the performance data of the tested object in real time, wherein the performance data is obtained by inserting the high-precision timestamp API at different positions of the function. The performance data generated for each tested function includes 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.
[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 GPU application program 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 stored in the GPU display memory area A, and each performance data is stored in the corresponding address of the GPU display memory area.
[0057] When the performance data of the object under test is stored in the GPU memory area, when the performance data in the GPU memory area meets the saving condition, it is necessary to suspend the running of the GPU application, and then transfer the performance data in the GPU memory area to the file system. The saving condition of the performance data in the GPU memory area can be adjusted according to the size of the performance data, the scene of the GPU application, the running time, etc.
[0058] Among them, in the first case: 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, and the performance data corresponding to the GPU applications of 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 video memory area, and the performance data in the GPU video 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 is understandable 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 driver under test is collected, the performance data in each file system is analyzed, wherein a binary tree-based sorting and searching algorithm is used to count the number of executions of each function under test and the time required for each operation, and the total execution time, average running time, maximum running time and shortest running time of each function under test are analyzed and calculated. The functions under test are sorted according to the total execution time, and the data performance analysis results of each function under test are saved in the file system result_data_1.
[0065] The time required for each run of the tested function is counted, including:
[0066] The CPU counter value at the function entry of the tested function is collected by inserting a high-precision timestamp API at the function entry position of the tested function, 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 tested function; the time required for the tested function 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 time required for the function under test to run is calculated as:
[0068]
[0069] Among them, t is the time required for the function under test to run, in milliseconds, and tick 2 The CPU counter value when the function returns or exits, tick 1 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 after the analysis is completed, store the analysis result data in another file system. Then repeat the above steps to process the performance data in the file systems such as 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 save the performance analysis results.
[0071] The present invention is implemented in a specific way in 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) Use C language embedded assembly to 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 object under test;
[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 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; obtain the number of executions, average execution time, maximum execution time, and minimum execution time of the object under test based on the binary tree sorting and searching algorithm; 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 assembly language is used to read the CPU's timer frequency and counter value, which can improve the code execution efficiency, 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, 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 emphasis, and for parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0086] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, 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 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 flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, 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 generate 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 flowchart and / or block diagram. 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 capable of directing a computer or other programmable data processing device to operate 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 A 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 operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0090] Although the preferred embodiments of the present invention have been described, those skilled in the art may make other 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 can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.
Claims
1. A GPU driver performance analysis method, It is characterized in that include: S1, open up a GPU memory area; S2, based on the C language embedded assembly method, design a high-precision timestamp API, insert the high-precision timestamp API at the function entry position, function return or exit position of each tested function of the GPU application program, and generate a GPU driver tested object; S3, loading and running the GPU application to dynamically collect the performance data of the object under test, where the performance data is obtained through an inserted 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, and saving 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.
2. The GPU driver performance analysis method according to claim 1, It is characterized in that The S2 is based on the C language embedded assembly method to design a high-precision timestamp API, including: Use C language embedded assembly method to read the value of CNTFRQ register and the value of CNTPCT register to design a high-precision timestamp API.
3. The GPU driver performance analysis method according to claim 1, It is 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 display memory area.
4. The GPU driver performance analysis method according to claim 1, It is characterized in that 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.
5. The GPU driver performance analysis method according to claim 4, It is characterized in that In S4, when the performance data in the GPU video memory area meets the saving condition, pausing the GPU application and saving the performance data in the GPU video memory area to the file system includes: When the performance data fills up the memory space of the GPU video memory area, pausing the GPU application and saving the performance data in the GPU video memory area to the first file system; When the GPU application includes multiple scenes, each time a GPU application of a scene is loaded and run, the GPU application of the scene is paused, 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, 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.
6. The GPU driver performance analysis method according to claim 1, It is characterized in that 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 shortest 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.
7. The GPU driver performance analysis method according to claim 6, It is characterized in that Statistics on the running time of each tested function, including: The CPU counter value at the entrance 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.
8. The GPU driver performance analysis method according to claim 7, It is characterized in that The step 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 timing counter includes: Among them, t is the time required for the function under test to run, in milliseconds, and tick 2 The CPU counter value when the function returns or exits, tick 1 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
CPU + GPU heterogeneous parallel optimization method in gas dynamic theory unified algorithm
CN111858066A
Accurate timestamp or export counter value generation on complex CPU
CN116635833A
Continuous performance analysis method and device based on eBPF, electronic equipment and storage medium
CN117240695A
Heads-up-display software development tool for analyzing and optimizing computer software
US7950003B1
Cited By
Performance analysis method and device, electronic equipment and storage medium
CN121807669A
