Operator precision test method, apparatus, device, medium, and program product
By computing the reference operator and the operator under test in parallel within a graphics processor, the problem of inefficient operator accuracy testing in existing technologies is solved, resulting in more efficient, flexible, and accurate test results.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- GUOCHAO (XIAN) COMPUTING TECH CO LTD
- Filing Date
- 2026-03-18
- Publication Date
- 2026-07-10
AI Technical Summary
In existing operator precision testing methods, the central processing unit (CPU) is responsible for the scheduling and control logic of the entire computing task, resulting in low efficiency, underutilization of the computing power of the graphics processing unit (GPU), and problems with data migration and scheduling interaction.
By storing reference operators and operators under test in the graphics processor for parallel computation, accuracy testing is performed using the graphics processor, reducing data migration and scheduling interactions between the central processing unit and the graphics processor, and employing different test instructions to adapt to different hardware environments and task requirements.
This improves the efficiency of operator precision testing, fully utilizes the parallel computing capabilities of graphics processors, reduces memory redundancy and data migration, and enhances the flexibility and accuracy of testing.
Smart Images

Figure CN122364002A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence technology, and in particular to an operator accuracy testing method, apparatus, device, medium, and program product. Background Technology
[0002] The rapid development of artificial intelligence technology is inseparable from the widespread application of deep learning models. As the basic computational unit of deep learning models, the computational accuracy of operators directly affects the final performance and reliability of deep learning models. In fields with extremely high safety requirements, such as computer vision, natural language processing, and autonomous driving, operator accuracy deviations can lead to serious consequences. Therefore, operator accuracy testing has become an indispensable part of the artificial intelligence software development process.
[0003] Currently, operator precision testing primarily relies on the central processing unit (CPU) handling the scheduling and control logic of the entire computational task, while the graphics processing unit (GPU) handles large-scale parallel computing tasks. However, this method suffers from low efficiency. Summary of the Invention
[0004] Therefore, it is necessary to provide an operator accuracy testing method, apparatus, equipment, medium, and program product that can improve efficiency in addressing the above-mentioned technical problems.
[0005] In a first aspect, this application provides an operator precision testing method applied to a graphics processor, the method comprising:
[0006] Obtain the test instructions for the operator to be tested;
[0007] If the test instruction is the first test instruction, then the reference operator and the operator to be tested stored in the graphics processor are used to perform a precision test on the operator to be tested, and the precision test result is determined; the first test instruction is used to instruct the graphics processor to test the precision of the operator to be tested.
[0008] In the above embodiments, by obtaining the test instruction for the operator to be tested, and if the test instruction is the first test instruction, the reference operator and the operator to be tested stored in the graphics processor are used to perform a precision test on the operator to be tested, and the precision test result is determined. The first test instruction is used to instruct the graphics processor to test the precision of the operator to be tested. In this way, during the operator precision testing process, the graphics processor performs parallel calculations on the reference operator and the operator to be tested, realizing the precision test of the operator to be tested. This reduces data migration and scheduling interactions between the central processing unit and the graphics processor, resulting in higher efficiency in operator precision testing.
[0009] In one embodiment, a precision test is performed on the operator under test using a reference operator stored in the graphics processor and the operator under test, and the precision test result is determined, including:
[0010] Based on the parameter information of the operator to be tested and the available memory space of the graphics processor, the first storage space, the second storage space, and the third storage space are determined.
[0011] The test data is calculated using the operator to be tested, and the first calculation result is stored in the second storage space; the test data is stored in the first storage space.
[0012] The test data is calculated using a reference operator, and the second calculation result is stored in the third storage space;
[0013] Based on the comparison between the first calculation result stored in the second storage space and the second calculation result stored in the third storage space, the accuracy test result of the operator to be tested is determined.
[0014] In the above embodiments, by applying for a first storage space, a second storage space, and a third storage space in the graphics processor, the test data and calculation results are stored in the graphics processor. There is no need to store the test data and perform data migration through the central processing unit, which makes the operator precision test more efficient. At the same time, no additional memory is required in the central processing unit, avoiding data redundancy.
[0015] In one embodiment, the parameter information includes the input data size, output data size, and precision type. Based on the parameter information of the operator to be tested and the available memory space of the graphics processor, a first storage space, a second storage space, and a third storage space are determined, including:
[0016] Determine the amount of test data based on the scale and precision type of the input data;
[0017] The first storage space is determined based on the amount of test data and the available memory space;
[0018] The amount of data in the first calculation result is determined based on the output data size and precision type.
[0019] Based on the amount of data from the first calculation result, the first storage space, and the available memory space, the second and third storage spaces are determined.
[0020] In the above embodiments, storage space is allocated according to the parameter information of the operator to be tested and the available memory space of the graphics processor. The test data and calculation results are stored only in the graphics processor, without the need for data migration and backup in the central processing unit, thus reducing memory redundancy.
[0021] In one embodiment, if the test instruction is a second test instruction, the method further includes:
[0022] The test data is calculated using the operator to be tested to obtain a third calculation result, and the third calculation result is sent to the central processing unit (CPU) so that the CPU can determine the accuracy test result of the operator to be tested based on the third calculation result and the fourth calculation result. The fourth calculation result is obtained by the CPU using its own stored reference operator to calculate the test data. The second test instruction is used to instruct the graphics processor (GPU) and the CPU to cooperate in testing the accuracy of the operator to be tested.
[0023] In the above embodiments, different types of test instructions are supported. In the case of the second test instruction, the central processing unit and the graphics processing unit work together to perform accuracy testing on the operator under test, which can be applied to different hardware environments and task requirements, making operator accuracy testing more flexible.
[0024] In one embodiment, the accuracy test result of the operator to be tested is determined based on a data comparison between the first calculation result stored in the second storage space and the second calculation result stored in the third storage space, including:
[0025] Calculate the absolute error and relative error between each element in the first calculation result and the corresponding element in the second calculation result;
[0026] The accuracy test results of the operator to be tested are determined based on the absolute and relative errors corresponding to each element.
[0027] In the above embodiments, the parallel comparison of calculation results is performed by the graphics processor, eliminating the need to send the calculation results to the central processing unit for comparison, thus avoiding the data migration process and improving the efficiency of operator accuracy testing.
[0028] In one embodiment, the accuracy test result of the operator to be tested is determined based on the absolute error and relative error corresponding to each element, including:
[0029] The absolute and relative errors corresponding to each element are compared with the absolute error threshold and the relative error threshold, respectively.
[0030] If there are no elements whose absolute error exceeds the absolute error threshold and whose relative error exceeds the relative error threshold, then the accuracy test result of the operator to be tested is determined to be a pass.
[0031] In one embodiment, the method further includes:
[0032] If there are elements whose absolute error exceeds the absolute error threshold or whose relative error exceeds the relative error threshold, the position of the abnormal element and the corresponding absolute and relative errors will be output, and the accuracy test result of the operator to be tested will be determined as a test failure.
[0033] In the above embodiments, the accuracy of operator precision testing is improved by comparing the absolute and relative errors of each element.
[0034] In one embodiment, the method further includes:
[0035] Test data is generated randomly based on the parameter information;
[0036] The test data is stored in the first storage space.
[0037] In the above embodiments, test data is generated and stored by the graphics processor, eliminating the need for the central processing unit to send the test data to the graphics processor, thus avoiding the data migration process and improving the efficiency of operator accuracy testing.
[0038] Secondly, this application also provides an operator precision testing device, applied to a graphics processor, the device comprising:
[0039] The acquisition module is used to acquire the test instructions of the operator to be tested;
[0040] The testing module is used to perform a precision test on the operator under test using the reference operator and the operator under test stored in the graphics processor if the test instruction is the first test instruction, and to determine the precision test result; the first test instruction is used to instruct the graphics processor to test the precision of the operator under test.
[0041] Thirdly, this application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the operator precision testing method described in any of the first aspects above.
[0042] Fourthly, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the operator precision testing method described in any of the first aspects above.
[0043] Fifthly, this application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the operator precision testing method described in any of the first aspects above.
[0044] The aforementioned operator accuracy testing method, apparatus, device, medium, and program products are applied to a graphics processing unit (GPU). They acquire test instructions for the operator under test. If the test instruction is a first test instruction, the GPU utilizes a reference operator and the operator under test stored in the GPU to perform an accuracy test on the operator under test, determining the accuracy test result. The first test instruction instructs the GPU to test the accuracy of the operator under test. In this way, during the operator accuracy testing process, the GPU performs parallel computation on the reference operator and the operator under test, achieving accuracy testing of the operator under test. This reduces data migration and scheduling interactions between the CPU and the GPU, resulting in higher efficiency in operator accuracy testing. Attached Figure Description
[0045] To more clearly illustrate the technical solutions in the embodiments of this application or related technologies, the drawings used in the description of the embodiments of this application or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0046] Figure 1 This is a diagram illustrating the application environment of an operator accuracy testing method in one embodiment.
[0047] Figure 2 This is a flowchart illustrating an operator accuracy testing method in one embodiment;
[0048] Figure 3 This is a flowchart illustrating the operator accuracy testing method in another embodiment;
[0049] Figure 4 This is a schematic diagram of the memory space in a graphics processor in one embodiment;
[0050] Figure 5 This is a flowchart illustrating the steps for determining the first storage space, the second storage space, and the third storage space in one embodiment.
[0051] Figure 6 This is a flowchart illustrating the test data generation steps in one embodiment;
[0052] Figure 7 This is a flowchart illustrating the operator accuracy testing method in another embodiment;
[0053] Figure 8 This is a flowchart illustrating the operator accuracy testing method in another embodiment;
[0054] Figure 9 This is a structural block diagram of an operator accuracy testing device in one embodiment;
[0055] Figure 10 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0056] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0057] It should be noted that the terms "first," "second," etc., used in this application can be used to describe various elements, but these elements are not limited by these terms. These terms are only used to distinguish the first element from the second element. The terms "comprising" and "having," and any variations thereof, used in this application, are intended to cover non-exclusive inclusion. The term "multiple" used in this application refers to two or more. The term "and / or" used in this application refers to one of the embodiments, or any combination of multiple embodiments.
[0058] Currently, operator precision testing primarily relies on the central processing unit (CPU) to handle the scheduling and control logic of the entire computational task, while the graphics processing unit (GPU) handles large-scale parallel computing tasks. In existing technologies, the core logic of operator precision verification is entirely executed by the CPU. As the main processor, the CPU is responsible for the scheduling and control of the entire verification process, including memory management, data initialization, GPU kernel startup, data transfer, and result verification. This centralized control model can lead to severe performance bottlenecks; when processing a large number of operators or large-scale data, the CPU's processing power becomes a limiting factor for the overall system.
[0059] Meanwhile, the computing power of the graphics processing unit (GPU) is not fully utilized. As a coprocessor, the GPU is only responsible for executing kernel functions, and throughout the verification process, it frequently waits for the central processing unit (CPU) to complete data preparation and scheduling tasks. This design results in a waste of computing resources. Therefore, this operator accuracy testing method suffers from low efficiency.
[0060] In view of this, this application proposes an operator precision testing method applied to a graphics processing unit (GPU). The method involves acquiring a test instruction for the operator to be tested. If the test instruction is a first test instruction, the reference operator and the operator to be tested stored in the GPU are used to perform a precision test on the operator to be tested, and the precision test result is determined. The first test instruction instructs the GPU to test the precision of the operator to be tested. In this way, during the operator precision testing process, the GPU performs parallel computation on the reference operator and the operator to be tested, achieving precision testing of the operator to be tested. This reduces data migration and scheduling interactions between the CPU and the GPU, resulting in higher efficiency in operator precision testing.
[0061] The operator accuracy testing method provided in this application embodiment can be applied to, for example... Figure 1 In the application environment shown, the central processing unit 102 communicates with the graphics processing unit 104 via a network. The CPU (Central Processing Unit) and GPU (Graphics Processing Unit) form a CPU-GPU heterogeneous architecture. By tightly integrating the two processors, a powerful computing foundation can be provided for various computationally intensive applications.
[0062] In one exemplary embodiment, such as Figure 2 As shown, an operator accuracy testing method is provided, which is applied to... Figure 1 Taking the graphics processor in the image as an example, the explanation includes the following steps 201 to 202. Wherein:
[0063] Step 201: Obtain the test instructions for the operator to be tested.
[0064] The test instructions can be generated by the graphics processor after judging the operator to be tested, or generated by the central processing unit after judging the operator to be tested and sent to the graphics processor, or generated and sent to the graphics processor based on the selection input of the user interface.
[0065] For example, taking the generation of test instructions after the graphics processor judges the operator to be tested as an example, the graphics processor determines the amount of memory space required for operator accuracy testing based on the parameter information of the operator to be tested, including the sum of the memory space occupied by the test data and the memory space occupied by the test results. Based on the amount of memory space required for operator accuracy testing and the amount of available memory space of the graphics processor, the test instructions are generated.
[0066] Optionally, the test instructions may include a first test instruction and a second test instruction. The first test instruction may be generated when the memory space required for operator accuracy testing is less than the available memory space of the graphics processor, and is used to instruct the graphics processor to perform accuracy testing on the operator under test. The second test instruction may be generated when the memory space required for operator accuracy testing is greater than the available memory space of the graphics processor, and is used to instruct the CPU and graphics processor to cooperate in performing operator accuracy testing on the operator under test.
[0067] Step 202: If the test instruction is the first test instruction, then the reference operator and the operator to be tested stored in the graphics processor are used to perform an accuracy test on the operator to be tested, and the accuracy test result is determined.
[0068] The first test instruction instructs the graphics processor (GPU) to test the accuracy of the operator under test. The reference operator is a simple convolution kernel function implemented loop-by-loop. Its simple logic and ease of ensuring correctness make it a benchmark for accuracy comparison, used to determine the accuracy of the operator under test. The operator under test is the operator for which accuracy testing is required. The GPU performs parallel calculations on both the reference and test operators, compares their results, and determines the accuracy test result of the operator under test based on the comparison.
[0069] In the above embodiments, by obtaining the test instruction for the operator to be tested, and if the test instruction is the first test instruction, the reference operator and the operator to be tested stored in the graphics processor are used to perform a precision test on the operator to be tested, and the precision test result is determined. The first test instruction is used to instruct the graphics processor to test the precision of the operator to be tested. In this way, during the operator precision testing process, the graphics processor performs parallel calculations on the reference operator and the operator to be tested, realizing the precision test of the operator to be tested. This reduces data migration and scheduling interactions between the central processing unit and the graphics processor, resulting in higher efficiency in operator precision testing.
[0070] In the embodiments of this application, the steps of step 202, which involves performing operator precision testing within the graphics processor, are as follows: Figure 3 As shown, it may include:
[0071] Step 301: Determine the first storage space, the second storage space, and the third storage space based on the parameter information of the operator to be tested and the available memory space of the graphics processor.
[0072] The parameter information of the operator to be tested may include the input data information and output data information of the operator to be tested. Based on the input data information and output data information, the amount of memory space required for the operator to be tested during the operator accuracy test can be determined.
[0073] The available memory space of the graphics processor is obtained from the memory management module of the graphics processor. Memory is allocated in the available memory space. Based on the amount of memory space required for the accuracy test of the operator to be tested, the first storage space, the second storage space, and the third storage space are requested.
[0074] For example, the first storage space is used to store the test data of the operator to be tested, i.e., the input data. The size of the first storage space needs to be precisely calculated based on the parameter information of the operator to be tested, such as batch size, number of channels, height, width, etc., and data precision type, such as float32, int8, etc., to ensure that it can accommodate all input data, while reserving necessary memory alignment boundaries. The second storage space is used to store the calculation result data obtained by the operator to be tested. The size of the second storage space needs to be calculated based on the parameter information of the operator to be tested, such as output data information, to ensure that it can accommodate all output data, while reserving necessary memory alignment boundaries. The third storage space is used to store the calculation result data obtained by the reference operator. The size of the third storage space is the same as the size of the second storage space. It is understood that when allocating memory, priority is given to contiguous memory blocks of the graphics processor to improve data reading efficiency. Optionally, the first, second, and third storage spaces can be configured as follows: Figure 4 As shown.
[0075] Step 302: Calculate the test data using the operator to be tested, and store the first calculation result in the second storage space.
[0076] The test data is stored in the first storage space. The test data is also the input data. The first storage space is accessible to both the operator under test and the reference operator. The operator under test reads the test data, performs calculations, executes preset operations or transformations, and stores the first calculation result in the second storage space.
[0077] Step 303: Calculate the test data using the reference operator and store the second calculation result in the third storage space.
[0078] The reference operator reads the test data in the first storage space, performs calculations, executes preset operations or transformations, and stores the calculated second result in the third storage space.
[0079] Step 304: Determine the accuracy test result of the operator to be tested according to the data comparison result between the first calculation result stored in the second storage space and the second calculation result stored in the third storage space.
[0080] Exemplarily, read the first calculation result from the second storage space. The data format of the first calculation result may be a floating-point array, a tensor, or a multi-dimensional matrix, and the specific format depends on the input and output parameter information of the operator to be tested. At the same time, read the second calculation result from the third storage space. The data format of the second calculation result is the same as that of the first calculation result to enable comparison with the first calculation result, and determine the accuracy test result of the operator to be tested according to the comparison result.
[0081] Optionally, compare each element in the first calculation result with each element at the corresponding position in the second calculation result. When all elements in the first calculation result and the second calculation result are the same, determine that the comparison result of the first calculation result and the second calculation result is consistent. It can also be that when the error of all elements in the first calculation result and the second calculation result is less than a preset threshold, determine that the comparison result of the first calculation result and the second calculation result is consistent. When the comparison result is consistent, that is, the calculation accuracy of the operator to be tested is the same as that of the standard reference operator, determine that the accuracy test of the operator to be tested is qualified. If the comparison result of the first calculation result and the second calculation result is inconsistent, that is, the calculation accuracy of the operator to be tested is different from that of the reference operator, and there may be a calculation error in the operator to be tested, determine that the accuracy test of the operator to be tested is unqualified.
[0082] In the above embodiment, by applying for the first storage space, the second storage space, and the third storage space in the graphics processor, the test data and the calculation results are both stored in the graphics processor, and there is no need to store the test data through the central processing unit and perform data migration. The efficiency of the operator accuracy test is higher. At the same time, there is no additional memory occupation in the central processing unit, avoiding data redundancy.
[0083] In one embodiment, if the test instruction is the second test instruction, the method further includes: calculating a third calculation result by using the operator to be tested for the test data, and sending the third calculation result to the central processing unit so that the central processing unit determines the accuracy test result of the operator to be tested based on the third calculation result and the fourth calculation result; the fourth calculation result is obtained by the central processing unit calculating the test data by using the reference operator stored in itself; the second test instruction is used to instruct the graphics processor and the central processing unit to cooperate to test the accuracy of the operator to be tested.
[0084] For example, if the test instruction is the second test instruction, meaning that the memory space required for the operator accuracy test of the operator under test is greater than the available memory space of the graphics processor, then the central processing unit (CPU) and the graphics processor need to work together to perform the accuracy test on the operator under test. The graphics processor uses the operator under test to calculate the test data, obtains a third calculation result, and sends it to the CPU for comparison. The CPU uses a reference operator to calculate the test data, obtains a fourth calculation result, and compares the third calculation result with the fourth calculation result to determine the accuracy test result of the operator under test.
[0085] In the above embodiments, when the test instruction is the second test instruction, the operator accuracy test is performed in collaboration between the central processing unit and the graphics processing unit, thereby reducing the memory space occupied by the graphics processing unit.
[0086] Furthermore, by determining different types of test instructions based on the parameter information of the operator to be tested and the specifications of the graphics processor, and controlling different processors to perform operator accuracy tests according to different types of test instructions, the operator accuracy test becomes more flexible.
[0087] In one embodiment, the parameter information includes the input data size, output data size, and precision type. The steps for determining the first storage space, the second storage space, and the third storage space based on the parameter information of the operator under test and the available memory space of the graphics processor are as follows: Figure 5 As shown, it may include:
[0088] Step 501: Determine the amount of test data based on the scale and precision type of the input data.
[0089] The input data size can include the specifications of the input tensors, weights, and biases. Optionally, the data size of the test data, i.e. the number of bytes of the test data, can be determined by multiplying the sum of the input tensors, weights, and biases by the precision type. The size of the test data size can determine the amount of memory space required to store the test data.
[0090] Step 502: Determine the first storage space based on the amount of test data and the available memory space.
[0091] Based on the amount of test data and the available memory space of the graphics processor, allocate the first storage space for storing the test data.
[0092] Optionally, the process of generating test data is as follows: Figure 6 As shown, it may include:
[0093] Step 601: Generate test data randomly based on the parameter information.
[0094] Based on the parameter information of the operator to be tested, such as the input data size, random numbers are generated through a random initialization function as test data to simulate the real input tensor, weights, and biases, which are used for calculations of the operator to be tested and the reference operator.
[0095] Step 602: Store the test data in the first storage space.
[0096] The generated test data is stored in the first storage space, which can be called by the graphics processor when calculating the operator to be tested and the reference operator, so as to perform calculations based on the test data and obtain the corresponding calculation results.
[0097] In this way, test data is generated and stored by the graphics processor, eliminating the need for the central processing unit to send the test data to the graphics processor, thus avoiding the data migration process and improving the efficiency of operator accuracy testing.
[0098] Step 503: Determine the data volume of the first calculation result based on the output data size and precision type.
[0099] The size of the first calculation result, i.e., the number of bytes, is determined by multiplying the output data size and precision type. The amount of memory space required to store the first calculation result can then be determined based on this size.
[0100] Step 504: Determine the second and third storage spaces based on the data volume of the first calculation result, the first storage space, and the available memory space.
[0101] Excluding the memory allocated for the first storage space from the available memory space of the graphics processor, the second and third storage spaces are allocated from the remaining available memory space based on the amount of data from the first calculation result.
[0102] In the above embodiments, storage space is allocated according to the parameter information of the operator to be tested and the available memory space of the graphics processor. The test data and calculation results are stored only in the graphics processor, without the need for data migration and backup in the central processing unit, thus reducing memory redundancy.
[0103] In one embodiment, the accuracy test result of the operator to be tested is determined based on a comparison between the first calculation result stored in the second storage space and the second calculation result stored in the third storage space. Figure 7 As shown, it includes:
[0104] Step 701: Calculate the absolute error and relative error between each element in the first calculation result and the corresponding element in the second calculation result.
[0105] The graphics processor simultaneously calculates the absolute and relative errors between each element in the first calculation result and the corresponding element in the second calculation result using multiple threads. The number of threads can be set according to the processing power of the graphics processor to improve the comparison efficiency.
[0106] Step 702: Determine the accuracy test result of the operator to be tested based on the absolute error and relative error corresponding to each element.
[0107] For example, the absolute and relative errors corresponding to each element are compared with the absolute error threshold and the relative error threshold, respectively. This includes the following two cases:
[0108] In the first case, if there are no elements whose absolute error exceeds the absolute error threshold and whose relative error exceeds the relative error threshold, then the accuracy test result of the operator to be tested is determined to be a pass.
[0109] The absolute error threshold and relative error threshold are set according to the accuracy test requirements. If the absolute error of all elements is less than the absolute error threshold and the relative error is less than the relative error threshold, then the first calculation result and the second calculation result are determined to be consistent, that is, the accuracy test result of the operator to be tested is that the test is passed.
[0110] In the second case, if there are elements whose absolute error exceeds the absolute error threshold or whose relative error exceeds the relative error threshold, the position of the abnormal element and the corresponding absolute and relative errors will be output, and the accuracy test result of the operator to be tested will be determined as a test failure.
[0111] If the absolute error of an element exceeds the absolute error threshold, or the relative error exceeds the relative error threshold, then that element is identified as an anomaly. The location of the anomaly, along with its specific absolute and relative errors, is recorded. Furthermore, the inconsistency between the first and second calculation results indicates that the precision test result for the operator under test has failed. Simultaneously, the location of the anomaly and its corresponding absolute and relative errors are output for maintenance personnel to use for debugging based on this information.
[0112] In the above embodiments, the parallel comparison of calculation results is performed by the graphics processor, eliminating the need to send the calculation results to the central processing unit for comparison, thus avoiding the data migration process and improving the efficiency of operator accuracy testing.
[0113] In the embodiments of this application, such as Figure 8 As shown, an operator accuracy testing method is provided, including:
[0114] Step 801: Obtain the test instructions for the operator to be tested.
[0115] Step 802: If the test instruction is the first test instruction, determine the first storage space, the second storage space, and the third storage space based on the parameter information of the operator to be tested and the available memory space of the graphics processor.
[0116] Step 803: Randomly generate test data based on the parameter information. Store the test data in the first storage space.
[0117] Step 804: Calculate the test data using the operator to be tested, and store the first calculation result in the second storage space.
[0118] Step 805: Calculate the test data using the reference operator and store the second calculation result in the third storage space.
[0119] Step 806: Calculate the absolute error and relative error between each element in the first calculation result and the corresponding element in the second calculation result.
[0120] Step 807: Determine the accuracy test result of the operator to be tested based on the absolute and relative errors corresponding to each element.
[0121] Step 808: If the test instruction is the second test instruction, the test data is calculated using the operator to be tested to obtain the third calculation result, and the third calculation result is sent to the central processing unit so that the central processing unit can determine the accuracy test result of the operator to be tested based on the third calculation result and the fourth calculation result.
[0122] In the embodiments of this application, the operator accuracy test of the aforementioned operator to be tested can be applied to an operator accuracy testing tool. This tool can generate test instructions based on user selection or based on the parameter information of the operator to be tested, thereby determining whether the test should be performed collaboratively by the CPU and GPU, or solely by the GPU. In traditional collaborative testing, the CPU needs to migrate test data to the GPU, and after computation, the GPU migrates the computation results back to the CPU. However, for large-scale deep learning operators, the overhead of data migration often exceeds the actual computation time, limiting the efficiency of operator accuracy testing. Therefore, when the GPU's memory space meets the testing conditions of the operator to be tested, performing the test solely by the GPU can reduce the migration process of test data and computation results, improving the efficiency of operator accuracy testing.
[0123] For example, in deep learning models, the convolution operator is a core operator in computer vision tasks, and its computational accuracy is crucial. This embodiment uses a common convolution operation for illustration, with input data including:
[0124] Input data: [1,3,32,32] (format: [Batch,Channels,Height,Width]);
[0125] Weight: [64,3,3,3] (format: [OutputChannels,InputChannels,KernelH,KernelW]);
[0126] Bias:
[64] .
[0127] The output data size includes: [1,64,30,30].
[0128] Based on the parameter information of the operator to be tested and the available memory space of the graphics processor, a first storage space, a second storage space, and a third storage space are determined. The first storage space stores shared test data, randomly generated by the graphics processor, including input tensors, weights, and biases, with a size of (1*3*32*32+64*3*3*3+64)*sizeof(float) bytes, where sizeof(float) is the number of bytes in the float precision type. The second storage space stores the first calculation result of the operator to be tested, with a size of 1*64*30*30*sizeof(float) bytes. The third storage space stores the second calculation result of the reference operator, with the same size as the second storage space. The reference operator is a simple convolution kernel function implemented loop-by-loop; its logic is simple, and its correctness is easily guaranteed, serving as a benchmark for precision comparison of the operator to be tested.
[0129] Then, the graphics processor simultaneously launches two computation kernel functions to perform calculations in parallel based on the test data. After the calculations are completed, the first and second calculation results are compared in parallel. Each element of the two result tensors (a total of 1*64*30*30=57,600 elements) is traversed, and the absolute error and relative error of each element are calculated. The absolute error and relative error can be calculated according to the following formula:
[0130] Absolute error = abs(result_second calculation result[i] - result_first calculation result[i])
[0131] Relative error = abs(result_second calculation result[i] - result_first calculation result[i]) / (abs(result_first calculation result[i]) + 1e-7)
[0132] If there are no elements whose absolute error exceeds the absolute error threshold and whose relative error exceeds the relative error threshold, then the accuracy test result of the operator under test is determined to be a pass. If there are elements whose absolute error exceeds the absolute error threshold or whose relative error exceeds the relative error threshold, then the operator accuracy test tool outputs the position of the abnormal element and the corresponding absolute and relative errors, and determines that the accuracy test result of the operator under test is a fail.
[0133] In the above embodiments, under the first test instruction, all operator calculations and error comparisons are completed within the graphics processing unit (GPU), fully utilizing the GPU's parallel computing capabilities. This results in higher efficiency for operator accuracy testing during large-scale tensor error comparisons, improving the GPU's resource utilization efficiency. Furthermore, the tool supports different test instructions, making it suitable for various hardware environments and task requirements, thus providing greater flexibility in operator accuracy testing.
[0134] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages in other steps. It is understood that the steps in different embodiments can be freely combined as needed, and all non-contradictory solutions formed by such combinations are within the scope of protection of this application.
[0135] Based on the same inventive concept, this application also provides an operator accuracy testing device for implementing the operator accuracy testing method described above. The solution provided by this device is similar to the implementation described in the above method; therefore, the specific limitations in one or more operator accuracy testing device embodiments provided below can be found in the limitations of the operator accuracy testing method described above, and will not be repeated here.
[0136] In one exemplary embodiment, such as Figure 9 As shown, an operator precision testing device 900 is provided, applied to a graphics processor, including: an acquisition module 901 and a testing module 902, wherein:
[0137] Module 901 is used to acquire test instructions for the operator to be tested.
[0138] The test module 902 is used to perform an accuracy test on the operator to be tested using the reference operator and the operator to be tested stored in the graphics processor if the test instruction is the first test instruction, and to determine the accuracy test result; the first test instruction is used to instruct the graphics processor to test the accuracy of the operator to be tested.
[0139] In one embodiment, the testing module 902 is specifically used to determine a first storage space, a second storage space, and a third storage space based on the parameter information of the operator to be tested and the available memory space of the graphics processor; to perform calculations on the test data using the operator to be tested and store the first calculation result in the second storage space; to store the test data in the first storage space; to perform calculations on the test data using a reference operator and store the second calculation result in the third storage space; and to determine the accuracy test result of the operator to be tested based on the data comparison between the first calculation result stored in the second storage space and the second calculation result stored in the third storage space.
[0140] In one embodiment, the parameter information includes the input data size, the output data size, and the precision type. The test module 902 is specifically used to determine the data volume of the test data based on the input data size and the precision type; determine the first storage space based on the data volume of the test data and the available memory space; determine the data volume of the first calculation result based on the output data size and the precision type; and determine the second and third storage spaces based on the data volume of the first calculation result, the first storage space, and the available memory space.
[0141] In one embodiment, the device further includes a collaborative computing module for calculating a third calculation result on the test data using the operator to be tested, and sending the third calculation result to the central processing unit (CPU) so that the CPU determines the accuracy test result of the operator to be tested based on the third calculation result and the fourth calculation result; the fourth calculation result is obtained by the CPU using its own stored reference operator to calculate the test data; the second test instruction is used to instruct the graphics processor and the CPU to collaboratively test the accuracy of the operator to be tested.
[0142] In one embodiment, the test module 902 is specifically used to calculate the absolute error and relative error between each element in the first calculation result and the corresponding element in the second calculation result; and to determine the accuracy test result of the operator to be tested based on the absolute error and relative error corresponding to each element.
[0143] In one embodiment, the test module 902 is specifically used to compare the absolute error and relative error corresponding to each element with the absolute error threshold and the relative error threshold, respectively; if there is no element whose absolute error exceeds the absolute error threshold and whose relative error exceeds the relative error threshold, then the accuracy test result of the operator to be tested is determined to be a pass.
[0144] In one embodiment, the device further includes a determination module, configured to output the position of the abnormal element and the absolute and relative errors corresponding to the abnormal element if there is an element whose absolute error exceeds an absolute error threshold or whose relative error exceeds a relative error threshold, and determine that the accuracy test result of the operator to be tested is a test failure.
[0145] In one embodiment, the device further includes a generation module for randomly generating test data based on parameter information and storing the test data in a first storage space.
[0146] Each module in the aforementioned operator accuracy testing device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in the processor of a computer device in hardware form or independent of it, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0147] In one exemplary embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 10 As shown, the computer device includes a processor, memory, input / output interfaces, a communication interface, a display unit, and an input device. The processor, memory, and input / output interfaces are connected via a system bus, and the communication interface, display unit, and input device are also connected to the system bus via the input / output interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The input / output interfaces are used for exchanging information between the processor and external devices. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, mobile cellular networks, Near Field Communication (NFC), or other technologies. When the computer program is executed by the processor, it implements an operator accuracy testing method. The display unit is used to form a visually visible image and can be a display screen, a projection device, or a virtual reality imaging device. The display screen can be an LCD screen or an e-ink screen. The input device of the computer device can be a touch layer covering the display screen, or buttons, trackballs, or touchpads set on the casing of the computer device, or external keyboards, touchpads, or mice, etc.
[0148] Those skilled in the art will understand that Figure 10The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0149] In an exemplary embodiment, a computer device is provided, including a memory and a processor. The memory stores a computer program, and the processor executes the computer program to perform the following steps: obtaining a test instruction for an operator to be tested; if the test instruction is a first test instruction, then using a reference operator stored in a graphics processor and the operator to be tested to perform an accuracy test on the operator to be tested, and determining the accuracy test result; the first test instruction is used to instruct the graphics processor to test the accuracy of the operator to be tested.
[0150] In one embodiment, when the processor executes the computer program, it further performs the following steps: determining a first storage space, a second storage space, and a third storage space based on the parameter information of the operator to be tested and the available memory space of the graphics processor; calculating the test data using the operator to be tested and storing the first calculation result in the second storage space; storing the test data in the first storage space; calculating the test data using a reference operator and storing the second calculation result in the third storage space; and determining the accuracy test result of the operator to be tested based on the data comparison between the first calculation result stored in the second storage space and the second calculation result stored in the third storage space.
[0151] In one embodiment, the parameter information includes the input data size, the output data size, and the precision type. When the processor executes the computer program, it further implements the following steps: determining the data volume of the test data based on the input data size and the precision type; determining a first storage space based on the data volume of the test data and the available memory space; determining the data volume of the first calculation result based on the output data size and the precision type; and determining a second storage space and a third storage space based on the data volume of the first calculation result, the first storage space, and the available memory space.
[0152] In one embodiment, when the processor executes the computer program, it further performs the following steps: using the operator to be tested to calculate the test data to obtain a third calculation result, and sending the third calculation result to the central processing unit, so that the central processing unit determines the accuracy test result of the operator to be tested based on the third calculation result and the fourth calculation result; the fourth calculation result is obtained by the central processing unit using its own stored reference operator to calculate the test data; the second test instruction is used to instruct the graphics processor and the central processing unit to cooperate in testing the accuracy of the operator to be tested.
[0153] In one embodiment, when the processor executes the computer program, it further performs the following steps: calculating the absolute error and relative error between each element in the first calculation result and the corresponding element in the second calculation result; and determining the accuracy test result of the operator to be tested based on the absolute error and relative error corresponding to each element.
[0154] In one embodiment, when the processor executes the computer program, it further performs the following steps: comparing the absolute error and relative error corresponding to each element with the absolute error threshold and the relative error threshold, respectively; if there is no element whose absolute error exceeds the absolute error threshold and whose relative error exceeds the relative error threshold, then the accuracy test result of the operator to be tested is determined to be a pass.
[0155] In one embodiment, when the processor executes the computer program, it further implements the following steps: if there is an element whose absolute error exceeds the absolute error threshold or whose relative error exceeds the relative error threshold, the position of the abnormal element and the absolute and relative errors corresponding to the abnormal element are output, and the accuracy test result of the operator to be tested is determined to be a test failure.
[0156] In one embodiment, when the processor executes the computer program, it further performs the following steps: randomly generating test data based on parameter information; and storing the test data in a first storage space.
[0157] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, it performs the following steps: obtaining a test instruction for an operator to be tested; if the test instruction is a first test instruction, then using a reference operator and the operator to be tested stored in the graphics processor to perform an accuracy test on the operator to be tested, and determining the accuracy test result; the first test instruction is used to instruct the graphics processor to test the accuracy of the operator to be tested.
[0158] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: determining a first storage space, a second storage space, and a third storage space based on the parameter information of the operator to be tested and the available memory space of the graphics processor; calculating the test data using the operator to be tested and storing the first calculation result in the second storage space; storing the test data in the first storage space; calculating the test data using a reference operator and storing the second calculation result in the third storage space; and determining the accuracy test result of the operator to be tested based on the data comparison between the first calculation result stored in the second storage space and the second calculation result stored in the third storage space.
[0159] In one embodiment, the parameter information includes the input data size, the output data size, and the precision type. When the computer program is executed by the processor, it further implements the following steps: determining the data volume of the test data based on the input data size and the precision type; determining a first storage space based on the data volume of the test data and the available memory space; determining the data volume of the first calculation result based on the output data size and the precision type; and determining a second storage space and a third storage space based on the data volume of the first calculation result, the first storage space, and the available memory space.
[0160] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: using the operator to be tested to calculate the test data to obtain a third calculation result, and sending the third calculation result to the central processing unit, so that the central processing unit determines the accuracy test result of the operator to be tested based on the third calculation result and the fourth calculation result; the fourth calculation result is obtained by the central processing unit using its own stored reference operator to calculate the test data; the second test instruction is used to instruct the graphics processor and the central processing unit to cooperate in testing the accuracy of the operator to be tested.
[0161] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: calculating the absolute error and relative error between each element in the first calculation result and the corresponding element in the second calculation result; and determining the accuracy test result of the operator to be tested based on the absolute error and relative error corresponding to each element.
[0162] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: comparing the absolute error and relative error corresponding to each element with the absolute error threshold and the relative error threshold, respectively; if there is no element whose absolute error exceeds the absolute error threshold and whose relative error exceeds the relative error threshold, then the accuracy test result of the operator to be tested is determined to be a pass.
[0163] In one embodiment, when the computer program is executed by the processor, it further implements the following steps: if there is an element whose absolute error exceeds the absolute error threshold or whose relative error exceeds the relative error threshold, the position of the abnormal element and the absolute and relative errors corresponding to the abnormal element are output, and the accuracy test result of the operator to be tested is determined to be a test failure.
[0164] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: randomly generating test data based on parameter information; and storing the test data in a first storage space.
[0165] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps of any of the embodiments described above.
[0166] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of the relevant data must comply with relevant regulations.
[0167] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, artificial intelligence (AI) processors, etc., and are not limited to these.
[0168] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0169] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A method for testing operator accuracy, characterized in that, The method is applied to a graphics processor, and the method includes: Obtain the test instructions for the operator to be tested; If the test instruction is a first test instruction, then the reference operator stored in the graphics processor and the operator to be tested are used to perform an accuracy test on the operator to be tested, and the accuracy test result is determined; the first test instruction is used to instruct the graphics processor to test the accuracy of the operator to be tested.
2. The method according to claim 1, characterized in that, The step of performing an accuracy test on the operator under test using a reference operator stored in the graphics processor and the operator under test, and determining the accuracy test result, includes: Based on the parameter information of the operator to be tested and the available memory space of the graphics processor, the first storage space, the second storage space, and the third storage space are determined; The test data is calculated using the operator to be tested, and the first calculation result is stored in the second storage space; the test data is stored in the first storage space. The test data is calculated using a reference operator, and the second calculation result is stored in the third storage space; The accuracy test result of the operator to be tested is determined based on the data comparison between the first calculation result stored in the second storage space and the second calculation result stored in the third storage space.
3. The method according to claim 2, characterized in that, The parameter information includes the input data size, output data size, and precision type. Determining the first storage space, the second storage space, and the third storage space based on the parameter information of the operator to be tested and the available memory space of the graphics processor includes: The amount of test data is determined based on the input data size and the precision type. The first storage space is determined based on the amount of test data and the available memory space; The amount of data in the first calculation result is determined based on the output data size and the precision type. Based on the amount of data from the first calculation result, the first storage space, and the available memory space, the second storage space and the third storage space are determined.
4. The method according to claim 1, characterized in that, If the test instruction is a second test instruction, the method further includes: The test data is calculated using the operator to be tested to obtain a third calculation result, and the third calculation result is sent to the central processing unit (CPU) so that the CPU determines the accuracy test result of the operator to be tested based on the third calculation result and the fourth calculation result; the fourth calculation result is obtained by the CPU using its own stored reference operator to calculate the test data; the second test instruction is used to instruct the graphics processor (GPU) and the CPU to cooperate in testing the accuracy of the operator to be tested.
5. The method according to any one of claims 2 or 3, characterized in that, The step of determining the accuracy test result of the operator to be tested based on the data comparison results of the first calculation result stored in the second storage space and the second calculation result stored in the third storage space includes: Calculate the absolute error and relative error between each element in the first calculation result and the corresponding element in the second calculation result; The accuracy test result of the operator to be tested is determined based on the absolute and relative errors corresponding to each element.
6. The method according to claim 3, characterized in that, The step of determining the accuracy test result of the operator under test based on the absolute and relative errors corresponding to each element includes: The absolute and relative errors corresponding to each element are compared with the absolute error threshold and the relative error threshold, respectively. If there are no elements whose absolute error exceeds the absolute error threshold and whose relative error exceeds the relative error threshold, then the accuracy test result of the operator to be tested is determined to be a pass.
7. The method according to claim 6, characterized in that, The method further includes: If there are elements whose absolute error exceeds the absolute error threshold or whose relative error exceeds the relative error threshold, the position of the abnormal element and the corresponding absolute and relative errors are output, and the accuracy test result of the operator to be tested is determined to be a test failure.
8. The method according to claim 2, characterized in that, The method further includes: The test data is generated randomly based on the parameter information. The test data is stored in the first storage space.
9. An operator accuracy testing device, characterized in that, The device, applied to a graphics processor, includes: The acquisition module is used to acquire the test instructions of the operator to be tested; The testing module is configured to, if the test instruction is a first test instruction, perform an accuracy test on the operator to be tested using a reference operator stored in the graphics processor and the operator to be tested, and determine the accuracy test result; the first test instruction is used to instruct the graphics processor to test the accuracy of the operator to be tested.
10. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 8.
11. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 8.
12. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 8.