GPU compiler testing method, device and storage medium
By automatically generating test programs and differential testing methods, the problems of low efficiency and low quality of GPU compiler testing are solved, efficient and accurate compiler testing is achieved, deep-seated problems are discovered, and the compiler security is ensured.
Patent Information
- Application Number
- CN202311788011.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-22
- Publication Date
- 2024-11-26
- Estimated Expiration
- 2043-12-22
AI Technical Summary
In the prior art, the testing efficiency of GPU compilers is low and the quality of test cases is not high, which makes it difficult to detect and discover compiler problems, affecting the normal operation of the program.
By obtaining the GPU's kernel function pool and probability state transfer table, the test program is automatically generated, the diversity test program is constructed using randomness, and the GPU compiler is tested using the differential testing method.
Improves the construction efficiency and quality of GPU compiler test programs, saves time and labor costs, and can discover deep compiler problems, ensures the safety and accuracy of the compiler.
Smart Images

Figure CN117785686B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of computer software testing, and in particular to a testing method, device and storage medium for a graphics processing unit (GPU) compiler. Background Art
[0002] A GPU compiler is a compiler that can compile code using the high concurrent computing power of the GPU. The GPU compiler can compile the target code for the calculation expression in a short time, which can speed up the program. The accuracy of the GPU compiler compilation results is the prerequisite for ensuring the normal operation of the program. If there is a problem with the compiler, the behavior of the generated executable program may be inconsistent with the semantics of the source program, causing unexpected errors in the program. This kind of error is not easy to detect and discover for application developers, and can easily lead to major online accidents. Therefore, the reliability of the GPU compiler is very critical, and systematic testing and quality assurance of the GPU compiler have also become crucial.
[0003] In the related art, test cases are usually used to test the GPU compiler. Specifically, the tester needs to manually write the test cases for testing the GPU compiler. The GPU compiler compiles the test cases and generates execution results, and uses the test tool to verify whether the execution results are consistent with the expected results.
[0004] However, in the above method, when testing the GPU compiler, the tester needs to write additional test cases, which results in low program building efficiency and low test case quality. Summary of the invention
[0005] In view of this, the present disclosure proposes a test method, device and storage medium for a GPU compiler. The technical solution includes:
[0006] According to one aspect of the present disclosure, a method for testing a GPU compiler is provided, the method comprising:
[0007] Acquire a kernel function pool and a probability state transition table of the GPU, wherein the kernel function pool includes a plurality of grammars, and the probability state transition table is used to indicate the probability of each of the plurality of grammars deriving other grammars;
[0008] Generate a test program for the GPU compiler according to the kernel function pool and the probability state transition table;
[0009] The GPU compiler is tested according to the test program.
[0010] In a possible implementation, generating a test program for the GPU compiler according to the kernel function pool and the probability state transition table includes:
[0011] Generate a kernel function of the GPU device end according to the probability state transfer table and the kernel function pool;
[0012] A test program of the GPU compiler is generated according to the kernel function of the GPU device end and the main function of the central processing unit (CPU) host end.
[0013] In another possible implementation, generating the kernel function of the GPU device end according to the probability state transition table and the kernel function pool includes:
[0014] The multiple grammars in the kernel function pool are randomly combined according to the probability state transition table to generate a kernel function on the GPU device side.
[0015] In another possible implementation, generating a test program for the GPU compiler according to the kernel function of the GPU device and the main function of the CPU host includes:
[0016] mutating the kernel function;
[0017] The main function is combined with the mutated kernel function, and the main function is combined with the non-mutated kernel function to obtain a test program for the GPU compiler.
[0018] In another possible implementation, mutating the kernel function includes:
[0019] A semantically equivalent variation is performed on the kernel function, where the semantically equivalent variation is used to indicate that dead code in the kernel function is deleted and / or dead code is added to the kernel function.
[0020] In another possible implementation, mutating the kernel function includes:
[0021] Determine an Abstract Syntax Code (AST) corresponding to the kernel function;
[0022] According to the probability state transition table, a subtree of the abstract syntax tree is randomly mutated.
[0023] In another possible implementation, before obtaining the kernel function pool and the probability state transition table of the GPU, the method further includes:
[0024] The probability state transition table is generated according to a test case set, wherein the test case set includes a plurality of test cases that have errors in historical tests.
[0025] In another possible implementation, the probability state transition table is used to indicate the correspondence between the first grammar, the second grammar and the state transition probability value, and the state transition probability value is the probability value of deriving the second grammar from the first grammar, and the second grammar is different from the first grammar.
[0026] In another possible implementation, before obtaining the kernel function pool and the probability state transition table of the GPU, the method further includes:
[0027] The kernel function pool of the GPU is generated according to preset rules, wherein the preset rules include context-free methods and / or Compute Unified Device Architecture (CUDA) language grammar rules.
[0028] In another possible implementation, the kernel function pool also includes multiple identifiers, which are used to indicate at least one of thread organization method, memory management model, function qualification identifier, data type, memory fence and thread synchronization, and atomic operation.
[0029] In another possible implementation, testing the GPU compiler according to the test program includes:
[0030] According to the test program, the GPU compiler is tested by using a differential test method.
[0031] According to another aspect of the present disclosure, a testing device for a GPU compiler is provided, the device comprising:
[0032] An acquisition module, used to acquire a kernel function pool and a probability state transition table of the GPU, wherein the kernel function pool includes a plurality of grammars, and the probability state transition table is used to indicate the probability of each of the plurality of grammars deriving other grammars;
[0033] A generating module, used for generating a test program of the GPU compiler according to the kernel function pool and the probability state transition table;
[0034] A testing module is used to test the GPU compiler according to the testing program.
[0035] In a possible implementation, the generating module is further used to:
[0036] Generate a kernel function of the GPU device end according to the probability state transfer table and the kernel function pool;
[0037] A test program for the GPU compiler is generated according to the kernel function of the GPU device end and the main function of the CPU host end.
[0038] In another possible implementation, the generating module is further used to:
[0039] The multiple grammars in the kernel function pool are randomly combined according to the probability state transition table to generate a kernel function on the GPU device side.
[0040] In another possible implementation, the generating module is further used to:
[0041] mutating the kernel function;
[0042] The main function is combined with the mutated kernel function, and the main function is combined with the non-mutated kernel function to obtain a test program for the GPU compiler.
[0043] In another possible implementation, the generating module is further used to:
[0044] A semantically equivalent variation is performed on the kernel function, where the semantically equivalent variation is used to indicate that dead code in the kernel function is deleted and / or dead code is added to the kernel function.
[0045] In another possible implementation, the generating module is further used to:
[0046] Determine an abstract syntax tree corresponding to the kernel function;
[0047] According to the probability state transition table, a subtree of the abstract syntax tree is randomly mutated.
[0048] In another possible implementation, the device further includes: a probability state transition table generating module, configured to:
[0049] The probability state transition table is generated according to a test case set, wherein the test case set includes a plurality of test cases that have errors in historical tests.
[0050] In another possible implementation, the probability state transition table is used to indicate the correspondence between the first grammar, the second grammar and the state transition probability value, and the state transition probability value is the probability value of deriving the second grammar from the first grammar, and the second grammar is different from the first grammar.
[0051] In another possible implementation, the device further includes: a kernel function pool generating module, configured to:
[0052] The kernel function pool of the GPU is generated according to preset rules, wherein the preset rules include context-free methods and / or CUDA language grammar rules.
[0053] In another possible implementation, the kernel function pool also includes multiple identifiers, which are used to indicate at least one of thread organization method, memory management model, function qualification identifier, data type, memory fence and thread synchronization, and atomic operation.
[0054] In another possible implementation, the test module is further used to:
[0055] According to the test program, the GPU compiler is tested by using a differential test method.
[0056] According to another aspect of the present disclosure, a computing device is provided, the computing device comprising: a processor; a memory for storing processor-executable instructions;
[0057] Wherein, the processor is configured to:
[0058] Acquire a kernel function pool and a probability state transition table of the GPU, wherein the kernel function pool includes a plurality of grammars, and the probability state transition table is used to indicate the probability of each of the plurality of grammars deriving other grammars;
[0059] Generate a test program for the GPU compiler according to the kernel function pool and the probability state transition table;
[0060] The GPU compiler is tested according to the test program.
[0061] According to another aspect of the present disclosure, a non-volatile computer-readable storage medium is provided, on which computer program instructions are stored. When the computer program instructions are executed by a processor, the method provided by the first aspect or any possible implementation manner of the first aspect is implemented.
[0062] The disclosed embodiment obtains a kernel function pool and a probability state transition table of a GPU, wherein the kernel function pool includes multiple grammars, and the probability state transition table is used to indicate the probability of each of the multiple grammars deriving other grammars; generates a test program for a GPU compiler according to the kernel function pool and the probability state transition table; and tests the GPU compiler according to the test program; thereby automatically generating the test program for the GPU compiler, improving the construction efficiency and quality of the test program for the GPU compiler, which not only saves time and labor costs, but also can utilize its randomness to construct more diverse programs, thereby discovering deep-seated compiler problems. BRIEF DESCRIPTION OF THE DRAWINGS
[0063] The accompanying drawings, which are incorporated in and constitute a part of the specification, illustrate exemplary embodiments, features, and aspects of the disclosure and, together with the description, serve to explain the principles of the disclosure.
[0064] Figure 1 A schematic diagram of the structure of a computing device provided by an exemplary embodiment of the present disclosure is shown.
[0065] Figure 2 A flowchart of a method for testing a GPU compiler provided by an exemplary embodiment of the present disclosure is shown.
[0066] Figure 3 A flowchart of a method for testing a GPU compiler provided by another exemplary embodiment of the present disclosure is shown.
[0067] Figure 4 A flow chart of a method for generating a kernel function provided by an exemplary embodiment of the present disclosure is shown.
[0068] Figure 5 A flow chart of a method for performing semantically equivalent mutation on a kernel function provided by an exemplary embodiment of the present disclosure is shown.
[0069] Figure 6 A flow chart of a method for randomly mutating a kernel function provided by an exemplary embodiment of the present disclosure is shown.
[0070] Figure 7 A flow chart of a method for generating a main function provided by an exemplary embodiment of the present disclosure is shown.
[0071] Figure 8 A flow chart of a differential test method provided by an exemplary embodiment of the present disclosure is shown.
[0072] Fig. 9 A schematic diagram showing a principle of a method for testing a GPU compiler provided by an exemplary embodiment of the present disclosure is shown.
[0073] Fig.10 A schematic diagram of the structure of a GPU compiler testing device provided by an exemplary embodiment of the present disclosure is shown.
[0074] Fig.11 The invention is a block diagram showing a device for testing a GPU compiler according to an exemplary embodiment.
[0075] Fig.12 The invention is a block diagram showing a device for testing a GPU compiler according to an exemplary embodiment. DETAILED DESCRIPTION
[0076] Various exemplary embodiments, features and aspects of the present disclosure will be described in detail below with reference to the accompanying drawings. The same reference numerals in the accompanying drawings represent elements with the same or similar functions. Although various aspects of the embodiments are shown in the accompanying drawings, the drawings are not necessarily drawn to scale unless otherwise specified.
[0077] The word “exemplary” is used exclusively herein to mean “serving as an example, example, or illustration.” Any embodiment described herein as “exemplary” is not necessarily to be construed as preferred or advantageous over other embodiments.
[0078] In addition, in order to better illustrate the present disclosure, numerous specific details are given in the following specific embodiments. It should be understood by those skilled in the art that the present disclosure can also be implemented without certain specific details. In some examples, methods, means, components and circuits well known to those skilled in the art are not described in detail in order to highlight the subject matter of the present disclosure.
[0079] With the development of artificial intelligence, various neural network models are becoming more and more complex. Complex calculations require strong computing power support, and the requirements for GPU performance are getting higher and higher. Therefore, compilers are becoming more and more important, and their quality assurance is indispensable.
[0080] Most of the current compiler testing technologies focus on functional testing and performance testing of built-in functions, which require manual construction. However, compilers are different from traditional software. Their test input is code in a high-level programming language, and their output is an executable program. Therefore, the scenarios involved are relatively complex. In addition, due to the constraints of grammatical and semantic correctness, it is difficult to construct test cases. Test cases rely on manual writing, so the construction of programs is inefficient. Moreover, the effectiveness and quality of manually generated programs cannot be compared with those of machines. In addition, the diversity of test programs also depends on the personal ability of engineers. Simply manually constructing test case programs cannot achieve ideal code diversity. Therefore, an automated method is imperative. Constructing test programs through automatic generation can not only save time and labor costs, but also use its randomness to construct more diverse programs to discover deep compiler problems. There is currently no good feasible solution for fuzz testing related to GPU compilers. How to develop efficient and accurate program automatic generation fuzz testing for GPU compilers? The relevant technology has not yet provided a reasonable and effective method.
[0081] The disclosed embodiment provides a testing method for a GPU compiler based on program automatic generation fuzzy testing. According to a constructed kernel function pool and a probability state transition table, a test program for the GPU compiler is automatically generated, thereby improving the construction efficiency and quality of the test program for the GPU compiler. This not only saves time and labor costs, but also can utilize its randomness to construct more diverse programs, thereby discovering deep-seated compiler problems.
[0082] First, the application scenarios involved in this disclosure are introduced. Figure 1 , which shows a schematic diagram of the structure of a computing device provided by an exemplary embodiment of the present disclosure.
[0083] The computing device includes a server and / or a terminal. The terminal includes a mobile terminal or a fixed terminal, such as a mobile phone, a tablet computer, a laptop computer, a desktop computer, etc. The server can be a server, or a server cluster composed of several servers, or a cloud computing service center.
[0084] The computing device includes a processor 10, a memory 20, and a communication interface 30. Those skilled in the art will appreciate that Figure 1 The structure shown in the figure does not constitute a limitation on the computing device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
[0085] The processor 10 is the control center of the computing device, and uses various interfaces and lines to connect various parts of the entire computing device. It executes various functions of the computing device and processes data by running or executing software programs and / or modules stored in the memory 20, and calling data stored in the memory 20, thereby controlling the computing device as a whole. The processor 10 can be implemented by a CPU or a GPU.
[0086] The memory 20 can be used to store software programs and modules. The processor 10 executes various functional applications and data processing by running the software programs and modules stored in the memory 20. The memory 20 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system 21, an acquisition module 22, a generation module 23, a test module 24, and an application 25 required for at least one function, etc.; the data storage area may store data created according to the use of the computing device, etc. The memory 20 may be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as a static random access memory (SRAM), an electrically erasable programmable read-only memory (EEPROM), an erasable programmable read-only memory (EPROM), a programmable read-only memory (PROM), a read-only memory (ROM), a magnetic memory, a flash memory, a magnetic disk or an optical disk. Accordingly, the memory 20 may further include a memory controller to provide the processor 10 with access to the memory 20 .
[0087] The processor 10 executes the following functions by running the acquisition module 22: acquiring the kernel function pool and the probability state transition table of the GPU, the kernel function pool includes multiple grammars, and the probability state transition table is used to indicate the probability of each of the multiple grammars deriving other grammars. The processor 10 executes the following functions by running the generation module 23: generating a test program for the GPU compiler according to the kernel function pool and the probability state transition table. The processor 10 executes the following functions by running the test module 24: testing the GPU compiler according to the test program.
[0088] The following describes the GPU compiler testing method provided by the embodiments of the present disclosure using several exemplary embodiments.
[0089] Please refer to Figure 2 , which shows a flowchart of a method for testing a GPU compiler provided by an exemplary embodiment of the present disclosure. In this embodiment, the method is used for Figure 1 The method is illustrated by using the computing device shown in FIG.
[0090] Step 201, obtaining a kernel function pool and a probability state transition table of a GPU, wherein the kernel function pool includes a plurality of grammars, and the probability state transition table is used to indicate the probability of each of the plurality of grammars deriving other grammars.
[0091] The computing device pre-builds a kernel function pool of the GPU, the kernel function pool includes multiple grammars; and pre-builds a probability state transition table, the probability state transition table is used to indicate the probability of each of the multiple grammars deriving other grammars.
[0092] The syntax includes functions, and the syntax may also include identifiers. Optionally, the kernel function pool includes multiple functions and multiple identifiers, which are supported by the CUDA language and follow CUDA syntax rules. The identifier may be a parameter of a function or a parameter of a variable.
[0093] Optionally, the identifier is used to indicate at least one of a thread organization method, a memory management model, a function-qualified identifier, a data type, a memory fence and thread synchronization, and an atomic operation.
[0094] The probability state transition table is used to indicate the probability of multiple grammars deriving other grammars. Optionally, the probability state transition table is used to indicate the corresponding relationship between the first grammar, the second grammar and the state transition probability value, and the state transition probability value is the probability value of the first grammar deriving the second grammar, and the second grammar is different from the first grammar.
[0095] It should be noted that the details of the construction method of the GPU kernel function pool and the probability state transition table can be referred to the relevant description in the following embodiments, which will not be introduced here.
[0096] Step 202: Generate a test program for the GPU compiler according to the kernel function pool and the probability state transition table.
[0097] Optionally, the computing device generates a kernel function on the GPU device side according to the probability state transfer table and the kernel function pool; and generates a test program for the GPU compiler according to the kernel function on the GPU device side and the main function on the CPU host side.
[0098] Optionally, the computing device calls a program generation tool to randomly generate a kernel function on the GPU device side. The program generation tool is used to randomly combine functions and identifiers in the kernel function pool according to the probability state transition table to generate a kernel function on the GPU device side. Schematically, a starting grammar is first determined, and then the next grammar is derived according to the probability state transition table until the entire sentence generation is completed. The generated multiple sentences constitute a kernel function.
[0099] Optionally, the computing device mutates the kernel function of the GPU device, mixes the main function of the CPU host with the mutated kernel function or the unmutated kernel function, and generates a test program for the GPU compiler. It should be noted that the details of the test program generation method can be referred to the relevant description in the following embodiment, which will not be introduced here.
[0100] Step 203: Test the GPU compiler according to the test program.
[0101] Optionally, the computing device performs a differential test on the GPU compiler according to the test program of the GPU compiler. It should be noted that the details of the test method can be referred to the relevant description in the following embodiment, which will not be introduced here.
[0102] In summary, the method provided by the embodiment of the present disclosure can generate a test program for the GPU compiler in an automatic manner according to the constructed kernel function pool and probability state transition table, thereby improving the construction efficiency and quality of the test program for the GPU compiler. It not only saves time and labor costs, but also can use its randomness to construct more diverse programs, thereby discovering deep-seated compiler problems.
[0103] In the related art, there is no good solution for fuzz testing of GPU compilers, whether it is generation type or mutation type. At present, the automatic generation type fuzz testing of programs mainly uses CSimit open source software, but CSimit open source software is limited to CPU architecture and only has relevant grammar function pools for C++, while the device-side kernel function of GPU is based on CUDA code. On the one hand, the embodiment of the present disclosure first needs to establish a diverse kernel function pool; on the other hand, the related art adopts a uniform random generation method, which is not targeted. The embodiment of the present disclosure uses test cases with errors in historical tests (including historical unit tests or system-level tests), analyzes the context of its grammar, and constructs a probabilistic state transition table to ensure the generation of high-quality test cases; on the other hand, there is no random mutation in mutation in the related art. The embodiment of the present disclosure randomly mutates the subtrees of the abstract syntax tree, which greatly improves the diversity of the test set while ensuring the validity of the grammatical semantics; on the other hand, in compiler testing, the embodiment of the present disclosure tests the GPU compiler by adopting a differential test method, and the number and version of compilers tested in large quantities are sufficient to ensure the security of the self-developed compiler.
[0104] Please refer to Figure 3 , which shows a flowchart of a method for testing a GPU compiler provided by another exemplary embodiment of the present disclosure. In this embodiment, the method is used for Figure 1 The method is illustrated by using the computing device shown in FIG.
[0105] Step 301 : Generate a kernel function pool of a GPU according to preset rules, where the preset rules include a context-free method and / or a CUDA language grammar rule.
[0106] The computing device generates a kernel function pool of the GPU according to a context-free method and / or CUDA language grammar rules. The kernel function pool of the GPU includes multiple grammars, such as multiple functions and multiple identifiers.
[0107] Optionally, the identifier is used to indicate at least one of a thread organization method, a memory management model, a function-qualified identifier, a data type, a memory fence and thread synchronization, and an atomic operation.
[0108] Optionally, the identifier indicating the thread organization method includes a grid, a thread block, and a thread. The grid is a two-dimensional array containing multiple thread blocks. Each thread block is also a two-dimensional array containing multiple threads, so each thread can execute the same code and can use different data when executing. And the three parameters can be configured by the user, and the three parameters actually used by the host side are passed to the device side to calculate the identity document (ID) index of each actual thread.
[0109] Optionally, the memory management model is divided into on-chip space and off-chip space according to the storage space of the GPU, including registers and shared memory on each Streaming Multiprocessor (SM) chip, and off-chip global memory, local memory, read-only constant cache, and read-only texture memory. In terms of memory access speed, from fast to slow, they are registers, shared memory, constant memory, texture memory, local memory, and global memory. In terms of the size of the storable space, it is inversely proportional to the memory access speed.
[0110] Optionally, the function qualifier includes a basic qualifier and a variable qualifier. The basic qualifier is used to indicate whether the function is run or called on the host side or on the device side, and the supported types are also consistent with CUDA; the variable qualifier is used to indicate the storage location of the variable on the device. Because the host side does not need this qualifier, the variable qualifier mainly includes the variable declaration on the device side, the choice of memory space, and some variable modification keywords.
[0111] Optionally, the data types include vector types and vector types. Common CUDA vectors and vectors are supported, and the data types and basic operations supported by different computing platforms are also different. The vector type includes at least one of unsigned integers, characters, short integers, long integers, single-precision floating point numbers, half-precision floating point numbers, and double-precision floating point numbers. The vector type supports a linear combination of at least two of the above same vector types.
[0112] Optionally, GPU computing is a parallel Single Instruction Multiple Threads (SIMT) architecture. The compiler has a synchronization point in the operation of random access to memory, so that all read and write operations before this point can be executed before the operation after this point can be started. Therefore, in order to ensure the correctness of the calculated data, each thread must involve memory fences and linear synchronization. The embodiments of the present disclosure support common primitives in CUDA.
[0113] Optionally, atomic operations are used to indicate that when a thread wants to perform "read, compute, write" operations on the same video memory variable in sequence, the entire operation must be executed coherently, and no other operations can be inserted in the middle. The support for atomic operations is also consistent with CUDA, supporting atomic addition, subtraction, exchange, increment, decrement, and, or, XOR, etc. of most data types. In addition, in actual work tests, from the perspective of generalization, the method provided in the embodiments of the present disclosure can also be applied to various GPU hardware environments.
[0114] Step 302: Generate a probability state transition table according to a test case set, where the test case set includes a plurality of test cases that have errors in historical tests.
[0115] The computing device obtains a test case set, namely, multiple test cases that have failed in historical tests, counts the logical rules generated by the programs of the multiple test cases that have failed, and generates a probability state transition table.
[0116] Optionally, multiple test cases that failed in historical testing include multiple test cases that have historically triggered program errors (English: bugs) during unit testing and system testing. Code statistics are performed on multiple test cases that failed in historical testing, and the respective probabilities that a certain syntax will generate the next different syntax are roughly calculated, so as to construct a probability state transition table. In this way, a test program can be randomly constructed according to the probability state transition table. Compared with the traditional method of using the same probability to generate a test program, it is more targeted, the generated test program is of better quality, and is more likely to trigger program errors.
[0117] Optionally, the probability state transition table is used to indicate the correspondence between the first grammar, the second grammar and the state transition probability value, and the state transition probability value is the probability value of deriving the second grammar from the first grammar, and the second grammar is different from the first grammar.
[0118] In an illustrative example, part of the probability state transition table is shown in Table 1. The probability value of grammar 1 deriving grammar 2 is 0.4, the probability value of grammar 1 deriving grammar 3 is 0.1, and the probability value of grammar 1 deriving grammar 4 is 0.5.
[0119] Table 1
[0120] First Grammar Second Grammar State transition probability value Syntax 1 Syntax 2 0.4 Syntax 1 Syntax 3 0.1 Syntax 1 Syntax 4 0.5
[0121] It should be noted that step 301 and step 302 may be performed in parallel, or step 301 may be performed first and then step 302, or step 302 may be performed first and then step 301, and the embodiments of the present disclosure are not limited to this.
[0122] Step 303: Generate a kernel function on the GPU device side according to the probability state transition table and the kernel function pool.
[0123] Optionally, the computing device calls a program generation tool to randomly generate a kernel function on the GPU device side, and the program generation tool is used to randomly combine various syntaxes of the kernel function pool using a probability state transition table to generate a kernel function on the GPU device side.
[0124] Optionally, the random combination includes a combination of at least two of variables, expressions, and operators. Optionally, the computing device displays an interactive interface, which is an interface provided to the user for selecting a combination method. The computing device receives the selected combination method through the interactive interface, and combines various syntaxes of the kernel function pool according to the selected combination method to obtain a kernel function, such as generating command line selection parameters for atomic operations separately, but of course, unified generation is still the main method.
[0125] Optionally, the computing device performs syntax and semantics checks on the generated kernel function, filters out syntactically and semantically incorrect codes, and thus generates a syntactically and semantically correct kernel function.
[0126] Optionally, the target parameter of the kernel function is a set value, and the target set parameter includes at least one of code length, code nesting depth, and parameter passing amount, so that a test code with controllable code length, code nesting depth, parameter passing amount, etc. can be generated while ensuring that the syntax and semantics are correct. The set value is set by default or is set by the user. The embodiments of the present disclosure are not limited to this.
[0127] In an illustrative example, the computing device generates a kernel function on the GPU device side according to the probability state transition table and the kernel function pool, including but not limited to the following steps: Figure 4As shown in the figure: the computing device builds a kernel function pool of the GPU, the kernel function pool includes multiple functions and multiple identifiers, and the multiple identifiers are used to indicate the thread organization method, memory management model, function qualification identifier, data type, memory fence and thread synchronization and atomic operation; builds a probability state transition table; generates a kernel function on the GPU device side according to the probability state transition table and the kernel function pool; performs syntax and semantic detection on the generated kernel function, filters out the code with syntax and semantic errors, and thus generates a kernel function with correct syntax and semantics.
[0128] Step 304: mutate the kernel function on the GPU device side.
[0129] Optionally, the kernel function on the GPU device side of the computing device is subjected to multiple mutations, including semantically equivalent mutations and / or random mutations of subtrees of the abstract syntax tree. The semantically equivalent mutations are used to indicate the deletion of dead code in the kernel function and / or the addition of dead code in the kernel function, while the random mutation of subtrees of the abstract syntax tree is a more random mutation, which requires the subsequent use of heuristic algorithms such as probabilistic state transition tables to ensure the semantic validity of the program. The two methods can start from different perspectives and can greatly improve the diversity of generated programs.
[0130] In a possible implementation, under the premise of semantic equivalence, the computing device performs semantic equivalence mutation on the kernel function, and the semantic equivalence mutation is used to indicate that dead code in the kernel function is deleted and / or dead code is added to the kernel function.
[0131] Among them, dead code is essentially a block in the program that cannot be executed. Adding or deleting dead code in the program will not change the logic and output of the program. Optionally, the computing device uses a static code analysis tool to analyze the kernel function to detect dead code and delete the dead code; and / or, randomly add dead code to the kernel function. Although dead code will affect the efficiency of the compiler and is often deleted, using it in testing can increase the diversity of the program.
[0132] In an illustrative example, the computing device performs semantic equivalent mutation on the kernel function, including but not limited to the following steps: Figure 5 As shown: the computing device obtains the kernel function; after obtaining the kernel function, the computing device performs dead code detection and determination on the kernel function, and when dead code is detected in the kernel function, the dead code is deleted; and / or, after obtaining the kernel function, the computing device adds dead code to the kernel function.
[0133] In another possible implementation, the computing device determines an abstract syntax tree corresponding to the kernel function; and randomly mutates a subtree of the abstract syntax tree according to a probability state transition table.
[0134] Optionally, the computing device extracts an abstract syntax tree according to the kernel function; randomly removes subtrees in the abstract syntax tree; randomly mutates the removed subtrees according to the probability state transition table; and re-adds the mutated subtree sequence to the original abstract syntax tree.
[0135] In an illustrative example, the computing device models a series of new fragment sequences using the hierarchical structure of the test case and the relationship between these structures, that is, the computing device randomly mutates the subtrees of the abstract syntax tree, including but not limited to the following steps: Figure 6 As shown: Step 601, obtain the kernel function. Step 602, generate the corresponding abstract syntax tree. Optionally, extract the corresponding abstract syntax tree according to the kernel function in the order of lexical analysis, syntax analysis, and semantic analysis. Step 603, standardize the abstract syntax tree and generate a triple sequence. Optionally, traverse each abstract syntax tree from the root node in pre-order, recursively generate a series of sequences with a depth of 1, and standardize the AST at the same time, change the variable name to a unified name, such as: A0, A1, etc.; change the function name to a unified name, such as: F1, F2, etc. The nodes of the tree in the AST can be represented by a triple (n0, e, n1), n0 represents the current node, e is the edge of the node, n1 is the successor node, and the leaf node has no successor node. It is also possible to use the extraction test case set to record its code logic, calculate the probability state transition table based on the frequency of the current node and the edge connecting to different successor nodes, and recursively generate the successor node until the terminal symbol is encountered. Step 604, randomly delete a subtree in the abstract syntax tree. Step 605, randomly mutate the deleted subtree according to the constructed probability state transition table. Generate each sequence one by one by performing a pre-order traversal of the subtree starting from the root node. Step 606, add the mutated subtree back to the original abstract syntax tree. Step 607, perform syntax and semantic checks on the mutated abstract syntax tree. Optionally, in order to ensure the syntax and semantic accuracy of the newly generated abstract syntax tree after mutation, relevant checks are performed according to preset grammar rules, so that other syntax errors such as unreferenced identifiers will not occur during compilation; for semantic errors, such as those caused by splicing two subtrees together, the preset rules used when the kernel function pool is generated can be used for semantic checking.
[0136] Step 305 , respectively mix the main function of the CPU host side with the mutated kernel function or the unmutated kernel function to generate a test program for the GPU compiler.
[0137] The computing device generates a main function of the CPU host side, combines the main function of the CPU host side with the mutated kernel function, and combines the main function with the non-mutated kernel function to obtain a test program of the GPU compiler.
[0138] In an illustrative example, the computing device generates a main function of the CPU host in a traditional manner, including but not limited to the following steps: Figure 7 As shown: Step 701, the computing device specifies the parameters for calling the kernel function, which are the parameters required by the application programming interface (API) for the CPU host to call the kernel function, including the thread block and number of threads passed to the GPU device. Step 702, initialize the CPU memory and GPU memory, that is, initialize the CPU memory and GPU memory according to the memory size required for the CPU host program to define the data. Optionally, use the runtime (English: runtime) API to allocate the CPU memory and GPU memory. Step 703, copy the data from the CPU host to the GPU device. Step 704, call the kernel function and start executing the code on the GPU device. Step 705, copy the result of the GPU device back to the CPU memory. Optionally, the CPU host process is blocked, and the result will be written to the CPU memory after the GPU device completes the calculation. Step 706, release the memory space of the CPU host and GPU device, and generate the main function of the CPU host. Next, the main function on the CPU host side and the kernel function on the GPU device side are combined in code, including the combination of the main function on the CPU host side and the mutated kernel function, and the combination of the main function on the CPU host side and the non-mutated kernel function. This forms a complete test program that can be directly compiled and executed.
[0139] Step 306: Test the GPU compiler using a differential test method according to the test program.
[0140] Optionally, the computing device tests the GPU compiler by differential testing according to the test program obtained by the combination, and outputs a program error result, where the program error result is used to indicate whether the GPU compiler is abnormal.
[0141] Among them, differential testing is to run the same program on different compilers or run the same program on the same compiler with different compilation options through a simple assumption. Compare the results of the compiled and run tests. If they are different, it means that an error has occurred. It is usually believed that most of the same results are correct outputs, and a few are incorrect outputs.
[0142] Optionally, the computing device uses a differential test method to determine whether the GPU compiler is abnormal by comparing the sum of hash values (English: hash) of global variables corresponding to different types of compilers, and comparing the sum of hash values of global variables corresponding to different levels of the same type of compiler, and comparing the sum of hash values of global variables corresponding to different versions of the same type of compiler. For example, different types of compilers include CUDA compilers and self-developed compilers, different levels of the same type of compiler include 4 compilation optimization levels of the self-developed compiler, and different versions of the same type of compiler include different submission (English: commit) versions of the self-developed compiler. This is not limited in the present disclosed embodiments.
[0143] Optionally, when a preset judgment condition is met, the GPU compiler is judged to be normal, and the preset judgment condition includes: the sum of hash values of global variables corresponding to different types of compilers are equal, and the sum of hash values of global variables corresponding to different levels of the same type of compiler are equal, and the sum of hash values of global variables corresponding to different versions of the same type of compiler are equal. When the preset judgment condition is not met, the GPU compiler is judged to be abnormal.
[0144] In an illustrative example, the computing device tests the GPU compiler using a differential test method according to a test program, including but not limited to the following steps: Figure 8As shown: Step 801, store all the combined test programs into a queue; Step 802, traverse the entire queue, read the test program pointed to by the head node of the queue, that is, the entire test process will complete the traversal of this queue, and then read the test program pointed to by the head node of the queue; Step 803, compile the test program and run it, that is, compile it based on different types of compilers (such as non-self-developed compilers and self-developed compilers), different optimization levels of the same type of compilers (such as 4 compilation optimization levels of self-developed compilers), and different versions of the same type of compilers (such as different commit versions of self-developed compilers), and then run the generated binary programs under their respective compilations. Step 804, calculate the sum of the hash values of global variables. The content output by the test program after compilation is the sum of the hash values of global variables. The sum of the hash values of global variables includes the sum of the hash values of global variables corresponding to different types of compilers, the sum of the hash values of global variables corresponding to different levels of the same type of compiler, and the sum of the hash values of global variables corresponding to different versions of the same type of compiler. Step 805, compare whether the sum of hash values is equal. In the verification phase of the last step, the sum of hash values is compared to determine whether the compiler triggers a program error, that is, compare whether the sum of hash values of global variables corresponding to different types of compilers are equal, and compare whether the sum of hash values of global variables corresponding to different levels of the same type of compiler are equal, and compare whether the sum of hash values of global variables corresponding to different versions of the same type of compiler are equal. Step 806, if the sum of hash values is equal and meets the preset judgment condition, read the next test program, start the test of the next test program in the queue, and cycle in sequence until the end of the queue. Step 807, if the sum of hash values is not equal and does not meet the preset judgment condition, collect error reports and determine that the test program is wrong. You can also use multiple compilers for testing, manually confirm which compiler compiles the program that is different from the other compilers, and then locate the location of the compiler's program error by analyzing the content of the test program with the error.
[0145] In an illustrative example, a schematic diagram of the principle of the GPU compiler testing method provided by the embodiment of the present disclosure is as follows: Fig. 9As shown in the figure: First, build the kernel function pool of the GPU, build a probability state transition table based on multiple test cases that have errors in historical tests, and generate the kernel function of the GPU device based on the probability state transition table and the kernel function pool. Perform semantic equivalent mutation on the kernel function of the GPU device and random mutation on the subtree of the abstract syntax tree, mix the main function of the CPU host with the kernel function after semantic equivalent mutation, mix the main function of the CPU host with the kernel function after random mutation, and mix the main function of the CPU host with the kernel function that has not been mutated, so as to generate a test program for the GPU compiler. The computing device tests the GPU compiler in a differential test manner according to the test program and outputs the program error results.
[0146] In summary, the embodiments of the present disclosure provide a testing method for a GPU compiler, which automatically generates a kernel function on the GPU device side according to a constructed kernel function pool and a probability state transition table, then performs multiple mutations on the generated kernel function, and performs code combination with the generated host-side main function, and finally detects potential problems of the compiler through differential testing to improve the security of the compiler.
[0147] On the one hand, by using the syntax-assisted method to build the kernel function pool, and by counting the code logic errors in the historical tests, the probability state transition table is generated, and then the kernel function is generated according to the state transition table, and the high-quality test program is quickly generated. This not only ensures the efficiency of the device-side program of the random batch GPU and the high quality of the use case, but also because the generated program is tested by syntax and semantics, the generated test program is also effective. On the other hand, the kernel function pool supports built-in function calls under multiple features, so that the randomly generated program also has strong diversity. On the other hand, under the condition of ensuring the correct syntax and semantics, the dead code of the generated GPU device-side program is deleted and added, and the subtree of the abstract syntax tree is randomly mutated based on the probability state transition table. This ensures the effectiveness and greatly improves the diversity of the program, so that the potential problems and risks of the compiler can be better and faster discovered, and the problems can be located in time and repair measures can be taken to improve the safety of the compiler. On the other hand, a large number of differential tests on the compiler from different angles can better discover the potential problems of the compiler, especially some deep-seated problems that cannot be discovered by test cases constructed by traditional methods.
[0148] The following is an apparatus embodiment of the present disclosure. For parts not described in detail in the apparatus embodiment, reference may be made to the technical details disclosed in the above method embodiment.
[0149] Please refer to Fig.10, which shows a schematic diagram of the structure of a test device for a GPU compiler provided by an exemplary embodiment of the present disclosure. The test device for the GPU compiler can be implemented as all or part of a computing device through software, hardware, or a combination of both. The device includes: an acquisition module 22, a generation module 23, and a test module 24.
[0150] An acquisition module 22 is used to acquire a kernel function pool and a probability state transition table of a GPU, wherein the kernel function pool includes a plurality of grammars, and the probability state transition table is used to indicate the probability of each of the plurality of grammars deriving other grammars;
[0151] A generating module 23, used for generating a test program of a GPU compiler according to the kernel function pool and the probability state transition table;
[0152] The testing module 24 is used to test the GPU compiler according to the testing program.
[0153] In a possible implementation, the generating module 23 is further configured to:
[0154] Generate the kernel function of the GPU device side according to the probability state transition table and the kernel function pool;
[0155] Generate a test program for the GPU compiler based on the kernel function on the GPU device side and the main function on the CPU host side.
[0156] In another possible implementation, the generating module 23 is further configured to:
[0157] Mutate the kernel function;
[0158] The main function is combined with the mutated kernel function, and the main function is combined with the non-mutated kernel function to obtain a test program for the GPU compiler.
[0159] In another possible implementation, the generating module 23 is further configured to:
[0160] A semantically equivalent mutation is performed on the kernel function, where the semantically equivalent mutation is used to indicate that dead code in the kernel function is deleted and / or dead code is added to the kernel function.
[0161] In another possible implementation, the generating module 23 is further configured to:
[0162] Determine the abstract syntax tree corresponding to the kernel function;
[0163] According to the probability state transition table, the subtrees of the abstract syntax tree are randomly mutated.
[0164] In another possible implementation, the device further includes: a probability state transition table generating module, configured to:
[0165] A probability state transition table is generated according to a test case set, where the test case set includes a plurality of test cases that have errors in historical tests.
[0166] In another possible implementation, the probability state transition table is used to indicate the correspondence between the first grammar, the second grammar and the state transition probability value, and the state transition probability value is the probability value of deriving the second grammar from the first grammar, and the second grammar is different from the first grammar.
[0167] In another possible implementation, the device further includes: a kernel function pool generating module, configured to:
[0168] A kernel function pool of a GPU is generated according to preset rules, wherein the preset rules include a context-free method and / or a CUDA language grammar rule.
[0169] In another possible implementation, the kernel function pool also includes multiple identifiers, which are used to indicate at least one of thread organization method, memory management model, function qualification identifier, data type, memory fence and thread synchronization, and atomic operation.
[0170] In another possible implementation, the testing module 24 is further configured to:
[0171] According to the test procedure, the GPU compiler is tested by differential testing.
[0172] It should be noted that the device provided in the above embodiment only uses the division of the above-mentioned functional modules as an example to implement its functions. In practical applications, the above-mentioned functions can be assigned to different functional modules according to actual needs, that is, the content structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0173] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0174] The embodiments of the present disclosure further provide a computing device, which includes: a processor; and a memory for storing instructions executable by the processor; wherein the processor is configured to: implement the steps executed by the computing device in the above-mentioned various method embodiments.
[0175] The embodiments of the present disclosure further provide a non-volatile computer-readable storage medium on which computer program instructions are stored. When the computer program instructions are executed by a processor, the methods in the above-mentioned various method embodiments are implemented.
[0176] Fig.111 is a block diagram of an apparatus 1100 for testing a GPU compiler according to an exemplary embodiment. For example, the apparatus 1100 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.
[0177] Reference Fig.11 , the device 1100 may include one or more of the following components: a processing component 1102 , a memory 1104 , a power component 1106 , a multimedia component 1108 , an audio component 1110 , an input / output (I / O) interface 1112 , a sensor component 1114 , and a communication component 1116 .
[0178] The processing component 1102 generally controls the overall operation of the device 1100, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 1102 may include one or more processors 1120 to execute instructions to perform all or part of the steps of the above-described method. In addition, the processing component 1102 may include one or more modules to facilitate interaction between the processing component 1102 and other components. For example, the processing component 1102 may include a multimedia module to facilitate interaction between the multimedia component 1108 and the processing component 1102.
[0179] The memory 1104 is configured to store various types of data to support the operation of the device 1100. Examples of such data include instructions for any application or method operating on the device 1100, contact data, phone book data, messages, pictures, videos, etc. The memory 1104 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0180] The power supply component 1106 provides power to the various components of the device 1100. The power supply component 1106 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the device 1100.
[0181] The multimedia component 1108 includes a screen that provides an output interface between the device 1100 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 1108 includes a front camera and / or a rear camera. When the device 1100 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
[0182] The audio component 1110 is configured to output and / or input audio signals. For example, the audio component 1110 includes a microphone (MIC), and when the device 1100 is in an operating mode, such as a call mode, a recording mode, and a speech recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 1104 or sent via the communication component 1116. In some embodiments, the audio component 1110 also includes a speaker for outputting audio signals.
[0183] I / O interface 1112 provides an interface between processing component 1102 and peripheral interface modules, which may be keyboards, click wheels, buttons, etc. These buttons may include but are not limited to: a home button, a volume button, a start button, and a lock button.
[0184] The sensor assembly 1114 includes one or more sensors for providing various aspects of the status assessment of the device 1100. For example, the sensor assembly 1114 can detect the open / closed state of the device 1100, the relative positioning of components, such as the display and keypad of the device 1100, the sensor assembly 1114 can also detect the position change of the device 1100 or a component of the device 1100, the presence or absence of user contact with the device 1100, the orientation or acceleration / deceleration of the device 1100, and the temperature change of the device 1100. The sensor assembly 1114 can include a proximity sensor configured to detect the presence of a nearby object without any physical contact. The sensor assembly 1114 can also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 1114 can also include an accelerometer, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0185] The communication component 1116 is configured to facilitate wired or wireless communication between the device 1100 and other devices. The device 1100 can access a wireless network based on a communication standard, such as WiFi, 2G or 3G, or a combination thereof. In an exemplary embodiment, the communication component 1116 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 1116 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0186] In an exemplary embodiment, the device 1100 can be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors or other electronic components to perform the above methods.
[0187] In an exemplary embodiment, a non-volatile computer-readable storage medium is also provided, such as a memory 1104 including computer program instructions, which can be executed by a processor 1120 of the device 1100 to perform the above method.
[0188] Fig.12 1 is a block diagram of a device 1200 for testing a GPU compiler according to an exemplary embodiment. For example, the device 1200 may be provided as a server. Fig.12 , the apparatus 1200 includes a processing component 1222, which further includes one or more processors, and a memory resource represented by a memory 1232 for storing instructions, such as an application, that can be executed by the processing component 1222. The application stored in the memory 1232 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 1222 is configured to execute the instructions to perform the above method.
[0189] The device 1200 may also include a power supply component 1226 configured to perform power management of the device 1200, a wired or wireless network interface 1250 configured to connect the device 1200 to a network, and an input / output (I / O) interface 1258. The device 1200 may operate based on an operating system stored in the memory 1232, such as Windows Server™, MacOS X™, Unix™, Linux™, FreeBSD™, or the like.
[0190] In an exemplary embodiment, a non-volatile computer-readable storage medium is also provided, such as a memory 1232 including computer program instructions, which can be executed by the processing component 1222 of the device 1200 to perform the above method.
[0191] The present disclosure may be a system, a method and / or a computer program product. The computer program product may include a computer-readable storage medium carrying computer-readable program instructions for causing a processor to implement various aspects of the present disclosure.
[0192] A computer-readable storage medium may be a tangible device that can hold and store instructions used by an instruction execution device. A computer-readable storage medium may be, for example, but not limited to, an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination of the foregoing. More specific examples of computer-readable storage media (a non-exhaustive list) include: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, such as a punch card or a raised structure in a groove on which instructions are stored, and any suitable combination of the foregoing. As used herein, a computer-readable storage medium is not to be interpreted as a transient signal per se, such as a radio wave or other freely propagating electromagnetic wave, an electromagnetic wave propagating through a waveguide or other transmission medium (e.g., a light pulse through a fiber optic cable), or an electrical signal transmitted through a wire.
[0193] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, optical fiber transmissions, wireless transmissions, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.
[0194] The computer program instructions for performing the operation of the present disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages, such as Smalltalk, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. Computer-readable program instructions may be executed completely on a user's computer, partially on a user's computer, as an independent software package, partially on a user's computer, partially on a remote computer, or completely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider to connect via the Internet). In some embodiments, an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA), or a programmable logic array (PLA), may be customized by utilizing the state information of the computer-readable program instructions, and the electronic circuit may execute the computer-readable program instructions, thereby realizing various aspects of the present disclosure.
[0195] Various aspects of the present disclosure are described herein with reference to the flowcharts and / or block diagrams of the methods, devices (systems) and computer program products according to the embodiments of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer-readable program instructions.
[0196] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the processor of the computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other equipment to work in a specific manner, so that the computer-readable medium storing the instructions includes a manufactured product, which includes instructions for implementing various aspects of the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0197] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operating steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0198] The flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system, method and computer program product according to multiple embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a part of a module, program segment or instruction, and a part of the module, program segment or instruction includes one or more executable instructions for realizing the specified logical function. In some alternative implementations, the function marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous square boxes can actually be executed substantially in parallel, and they can sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs the specified function or action, or can be implemented with a combination of special hardware and computer instructions.
[0199] The embodiments of the present disclosure have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or technical improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.
Claims
1. A method for testing a graphics processor GPU compiler, characterized in that: The method comprises: Acquire a kernel function pool and a probability state transition table of the GPU, wherein the kernel function pool includes a plurality of grammars, and the probability state transition table is used to indicate the probability of each of the plurality of grammars deriving other grammars; Generate a test program for the GPU compiler according to the kernel function pool and the probability state transition table; Testing the GPU compiler according to the test program; The step of generating a test program for the GPU compiler according to the kernel function pool and the probability state transition table comprises: Generate a kernel function of a GPU device end according to the probability state transfer table and the kernel function pool; A test program for the GPU compiler is generated according to the kernel function of the GPU device end and the main function of the central processing unit CPU host end.
2. The method according to claim 1, characterized in that The step of generating a kernel function of a GPU device according to the probability state transition table and the kernel function pool includes: The multiple grammars in the kernel function pool are randomly combined according to the probability state transition table to generate a kernel function on the GPU device side.
3. The method according to claim 1, characterized in that The step of generating a test program for the GPU compiler according to the kernel function of the GPU device end and the main function of the central processing unit CPU host end includes: mutating the kernel function; The main function is combined with the mutated kernel function, and the main function is combined with the non-mutated kernel function to obtain a test program for the GPU compiler.
4. The method according to claim 3, characterized in that The mutating the kernel function comprises: A semantically equivalent variation is performed on the kernel function, where the semantically equivalent variation is used to indicate that dead code in the kernel function is deleted and / or dead code is added to the kernel function.
5. The method according to claim 3, characterized in that: The mutating the kernel function comprises: Determine an abstract syntax tree corresponding to the kernel function; According to the probability state transition table, a subtree of the abstract syntax tree is randomly mutated.
6. The method according to any one of claims 1 to 5, characterized in that: Before obtaining the kernel function pool and the probability state transition table of the GPU, the method further includes: The probability state transition table is generated according to a test case set, wherein the test case set includes a plurality of test cases that have errors in historical tests.
7. The method according to any one of claims 1 to 5, characterized in that: The probability state transition table is used to indicate the correspondence between the first grammar, the second grammar and the state transition probability value, and the state transition probability value is the probability value of deriving the second grammar from the first grammar, and the second grammar is different from the first grammar.
8. The method according to any one of claims 1 to 5, characterized in that: Before obtaining the kernel function pool and the probability state transition table of the GPU, the method further includes: The kernel function pool of the GPU is generated according to preset rules, wherein the preset rules include a context-free method and / or a Compute Unified Device Architecture (CUDA) language grammar rule.
9. The method according to any one of claims 1 to 5, characterized in that: The testing of the GPU compiler according to the test program includes: According to the test program, the GPU compiler is tested by using a differential test method.
10. A GPU compiler testing device, characterized in that: The device comprises: An acquisition module, used to acquire a kernel function pool and a probability state transition table of the GPU, wherein the kernel function pool includes a plurality of grammars, and the probability state transition table is used to indicate the probability of each of the plurality of grammars deriving other grammars; A generating module, used for generating a test program of the GPU compiler according to the kernel function pool and the probability state transition table; A testing module, used for testing the GPU compiler according to the testing program; The generating module is further used for: Generate a kernel function of a GPU device end according to the probability state transfer table and the kernel function pool; A test program for the GPU compiler is generated according to the kernel function of the GPU device end and the main function of the central processing unit CPU host end.
11. A computing device, characterized in that: The computing device comprises: a processor; a memory for storing instructions executable by the processor; Wherein, the processor is configured to: Obtain a kernel function pool and a probability state transition table of a GPU, wherein the kernel function pool includes a plurality of grammars, and the probability state transition table is used to indicate the probability of each of the plurality of grammars deriving other grammars; Generate a test program for a GPU compiler according to the kernel function pool and the probability state transition table; Testing the GPU compiler according to the test program; The step of generating a test program for a GPU compiler according to the kernel function pool and the probability state transition table comprises: Generate a kernel function of a GPU device end according to the probability state transfer table and the kernel function pool; A test program for the GPU compiler is generated according to the kernel function of the GPU device end and the main function of the central processing unit CPU host end.
12. A non-volatile computer-readable storage medium having computer program instructions stored thereon, characterized in that: When the computer program instructions are executed by a processor, the method according to any one of claims 1 to 9 is implemented.
