A method for generating and processing a single instruction multiple data (SIMD) instruction and related equipment

By selecting matching information from the SIMD instruction model according to the cycle dimension length of the tensor calculation formula and generating SIMD instructions, the problem of low efficiency of brute force search in the existing technology is solved, and efficient SIMD instruction generation is achieved.

CN113391842BActive Publication Date: 2024-09-17HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202010177489.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-03-13
Publication Date
2024-09-17
Estimated Expiration
2040-03-13

AI Technical Summary

Technical Problem

When converting tensor calculation formulas into SIMD instructions, the existing technology relies on brute force search methods, resulting in a large parameter value space and low efficiency, making it difficult to quickly generate matching SIMD instructions.

Method used

By selecting the matching information from multiple sets of SIMD instruction model information according to the length of each loop dimension of the tensor calculation formula, and generating the corresponding SIMD instructions, whole block and tail block technology are used to deal with the problem that the length of the loop dimension is not divisible, and improve Generate efficiency.

Benefits of technology

Significantly improves the efficiency of the SIMD instruction generation process, reduces the number of searches, and increases the speed of the matching process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113391842B
    Figure CN113391842B
Patent Text Reader

Abstract

The embodiment of the present application discloses a method for generating and processing SIMD instructions and related equipment, which are used in the field of SIMD instruction generation in the chip field. The method may include: obtaining the length of each loop dimension of the first tensor calculation formula, selecting information of a second SIMD instruction model matching the first tensor calculation formula from multiple groups of information of the first SIMD instruction model according to the length of each loop dimension of the first tensor calculation formula, and generating the first SIMD instruction after the first tensor calculation formula is converted according to the length of at least one loop dimension of the first tensor calculation formula and the second SIMD instruction model. According to the length of each loop dimension of the tensor calculation formula, the information of the second SIMD instruction model is selected from the information of the multiple groups of the first SIMD instruction model, and then the first SIMD instruction after the first tensor calculation formula is converted is generated according to the second SIMD instruction model, which greatly improves the efficiency of the SIMD instruction generation process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence, and in particular to a method for generating and processing a single instruction multiple data (SIMD) instruction and related equipment. Background Art

[0002] Since the 1990s, major chip manufacturers have begun to integrate single instruction multiple data (SIMD) instruction extension technology into processors. SIMD instructions have a significant acceleration effect when dealing with computationally intensive problems with simple control flow and less data dependencies, and are widely used to accelerate computer programs such as image processing, video processing, and scientific computing.

[0003] At present, the process of converting the input tensor calculation formula into SIMD instructions mainly relies on brute force search. The brute force search method is to give each parameter in the SIMD instruction a limited value range, and for all parameters in the SIMD instruction, enumerate all possible parameter combinations within the parameter value range. For each parameter combination, it is necessary to convert the SIMD instruction under the parameter combination into the corresponding tensor calculation formula, and compare whether the input tensor calculation formula and the converted tensor calculation formula are equivalent. If they are equivalent, obtain the SIMD instruction under the parameter combination; if not, perform the above operation on the next parameter combination.

[0004] However, the value space of each parameter is large, and it takes a long time to obtain the SIMD instruction that matches an input tensor calculation formula through brute force search, which is inefficient. Summary of the invention

[0005] The embodiments of the present application provide a method for generating and processing a SIMD instruction and related equipment, which is used to select information of a second SIMD instruction model from multiple groups of information of first SIMD instruction models according to the length of each loop dimension of a tensor calculation formula, and then generate a first SIMD instruction after conversion of the first tensor calculation formula according to the second SIMD instruction model, thereby greatly improving the efficiency of the SIMD instruction generation process.

[0006] To solve the above technical problems, the present application provides the following technical solutions:

[0007] In the first aspect, the embodiment of the present application provides a method for processing SIMD instructions, which can be used in the field of SIMD instruction generation in the chip field, and the method includes: a SIMD instruction generation device obtains the length of each loop dimension of a first tensor calculation formula. Wherein, the tensor calculation formula includes a nested for loop or multiple for loops, and each for loop defines an operation formula to be executed by the for loop, and the operation formula includes a tensor and an operator. Of course, each for loop can also include a range of values ​​of coordinates in the tensor. A tensor is a multilinear mapping defined on the Cartesian product of a vector space and a dual space. The operator in the tensor calculation formula determines the operation type of the tensor calculation formula. The operation type of the first tensor calculation formula can specifically be addition or multiplication. The tensor calculation formula can be specifically expressed in the form of a for loop, and a tensor calculation formula can include multiple data objects. A loop dimension of the tensor calculation formula refers to a for loop in the tensor calculation formula. The length of a loop dimension in the tensor calculation formula refers to the upper limit of the value of the coordinates in a for loop of the tensor calculation formula, and a data object refers to a tensor in the tensor calculation formula. The SIMD instruction generation device obtains information of multiple groups of first SIMD instruction models. Wherein, each group of information of the first SIMD instruction model corresponds to at least one loop dimension of a tensor calculation formula, and each group of information of the first SIMD instruction model includes a first constraint condition, and the first constraint condition is used to indicate the constraint condition of the length of each loop dimension in at least one loop dimension. The SIMD instruction generation device selects the information of the second SIMD instruction model from the information of multiple groups of the first SIMD instruction model according to the first constraint condition and the length of each loop dimension of the first tensor calculation formula, and the information of the second instruction model matches the first tensor calculation formula, and the length of the loop dimension of the first tensor calculation formula satisfies the first constraint condition in the information of the second SIMD instruction model. The SIMD instruction generation device generates the parameter value of the second SIMD instruction model according to the length of at least one loop dimension of the first tensor calculation formula and the second SIMD instruction model, and brings the parameter value of the second SIMD instruction model into the second SIMD instruction model to generate the first SIMD instruction, and then the first SIMD instruction after the conversion of the first tensor calculation formula can be obtained. The second SIMD instruction model is used to generate the first SIMD instruction. The format of the first SIMD instruction model is the same as that of the first SIMD instruction. The difference is that the parameter values ​​of each parameter in the first SIMD instruction model have not been determined, while the parameter values ​​of each parameter in the SIMD instruction have been determined.In this implementation, through the aforementioned method, a specific implementation scheme for converting the first tensor calculation formula into SIMD instructions is realized; multiple groups of first SIMD instruction model information are generated in advance, and during the conversion process, a matching second SIMD instruction model is selected from the information of several groups of first SIMD instruction models based on the length of each loop dimension of the tensor calculation formula, thereby greatly improving the efficiency of the SIMD instruction generation process.

[0008] In a possible implementation of the first aspect, the information of each group of first SIMD instruction models also includes first indication information, where the first indication information is used to indicate the correspondence between K first parameters of a first SIMD instruction model and at least one loop dimension of a tensor calculation formula, K is an integer greater than or equal to 1, and the first parameter indicates the number of times an operation is repeatedly performed on a data object in a tensor calculation formula.

[0009] In a possible implementation of the first aspect, at least one loop dimension includes N loop dimensions, at least one group of information of the first SIMD instruction model includes information of multiple types of SIMD instruction models, and the value of N corresponding to the information of different types of SIMD instruction models is different, and N is an integer greater than or equal to 1. In this implementation, the information of at least one group of the first SIMD instruction model is divided into categories according to the number of loop dimensions corresponding to the information of the first SIMD instruction model, so as to facilitate the subsequent separate management of the information of different types of first SIMD instruction models and improve the management accuracy.

[0010] In a possible implementation of the first aspect, the first constraint condition is related to the type of chip that executes the converted first SIMD instruction, and the first constraint conditions of different types of chips may be different. In this implementation, the information set of the SIMD instruction model is generated based on a specific chip, and different chips will generate different SIMD instruction model information, which not only expands the application scenarios of this solution, but also improves the fit between the SIMD instruction model and the chip.

[0011] In a possible implementation of the first aspect, the SIMD instruction generation device generates a first SIMD instruction after the conversion of the first tensor calculation formula according to the length of at least one loop dimension of the first tensor calculation formula and the second SIMD instruction model, which may include: the SIMD instruction generation device generates multiple first SIMD instructions according to the length of at least one loop dimension of the first tensor calculation formula and the second SIMD instruction model. Specifically, the SIMD instruction generation device can generate parameter values ​​for the second SIMD instruction model according to the length of each loop dimension in the N loop dimensions of the first tensor calculation formula, the second SIMD instruction model and the coordinate linearization coefficient of the first tensor calculation formula, and bring the parameter values ​​of the second SIMD instruction model into the second SIMD instruction to obtain the first SIMD instruction. The aforementioned generated parameter values ​​include the parameter values ​​of each first parameter in the second SIMD instruction model, the parameter value of the destination address offset and the parameter value of the source address offset. The SIMD instruction generation device selects a SIMD instruction that meets the optimization target from among the multiple first SIMD instructions according to the cost function of each first SIMD instruction from among the multiple first SIMD instructions, and uses it as the first SIMD instruction after the first tensor calculation formula conversion, wherein the SIMD instruction that meets the optimization target is the SIMD instruction with the maximum or minimum function value of the cost function, and the cost function indicates the optimization target related to the first SIMD instruction. In this implementation, a cost function is generated in advance to assist in selecting the optimal SIMD instruction in the SIMD instruction conversion stage of the tensor calculation formula that executes the target operation type, and the cost function is generated based on the optimization target, which can meet the user's SIMD instruction optimization needs.

[0012] In a possible implementation of the first aspect, the optimization target indicated by the cost function includes at least one of the following: the minimum total number of SIMD instruction executions, the maximum total number of SIMD instruction executions, the minimum number of whole blocks and tail blocks in SIMD instructions, the maximum number of whole blocks and tail blocks in SIMD instructions, the maximum interval between whole blocks and tail blocks in SIMD instructions, the minimum interval between whole blocks and tail blocks in SIMD instructions, the minimum SIMD instruction scheduling delay, the maximum SIMD instruction scheduling delay, the minimum total execution time of SIMD instructions, the maximum calculation overhead of address offsets in SIMD instructions, and the minimum calculation overhead of address offsets in SIMD instructions. In this implementation, multiple scenarios of optimization targets are provided, which expands the application scenarios of this solution.

[0013] In a possible implementation of the first aspect, the independent variable of the cost function includes at least one of the following: the parameter value of the first parameter in the first SIMD instruction, the number of whole blocks in the first SIMD instruction, the number of tail blocks in the first SIMD instruction, the number of calculations of the address offset in the first SIMD instruction, the duration of executing a SIMD instruction, and the duration of switching from the process of executing a first SIMD instruction to the process of executing another first SIMD instruction. Further, the parameter value of the first parameter in the SIMD instruction may include the parameter value of the first parameter of the whole block part of the SIMD instruction and the parameter value of the first parameter of the tail block part of the SIMD instruction. In this implementation, the SIMD instruction cost function takes into account both the SIMD instruction parameters and the hardware parameters of the chip, so that the generated optimal SIMD instruction can give full play to the performance of the chip.

[0014] In a possible implementation of the first aspect, the SIMD instruction generation device generates a first SIMD instruction after the first tensor calculation formula is converted according to the length of at least one loop dimension of the first tensor calculation formula and the second SIMD instruction model, which may include: the SIMD instruction generation device obtains the first parameter corresponding to the first loop dimension of the first tensor calculation formula according to the first indication information in the information of the second SIMD instruction model. Wherein, the first loop dimension is a loop dimension of at least one loop dimension, and the length of the first loop dimension does not divide the value range of the corresponding first parameter. For the meaning that the length of the first loop dimension does not divide the value range of the corresponding first parameter, one or more first parameters in the SIMD instruction are used to implement the calculation of a first loop dimension, then the length of the first loop dimension does not divide one of the one or more first parameters, or the product of multiple parameters. For example, the aforementioned one or more first parameters include a fifth parameter and a sixth parameter, then the value range of the first parameter corresponding to the length of the first loop dimension does not divide the value range of the fifth parameter that the length of the first loop dimension does not divide the fifth parameter refers to the value range of the first loop dimension that the length of the first loop dimension does not divide the fifth parameter, or the value product of the fifth parameter and the sixth parameter that the length of the first loop dimension does not divide the fifth parameter. The SIMD instruction generating device generates the parameter value of the whole block part of the first SIMD instruction and the parameter value of the tail block part of the first SIMD instruction based on the length of the first loop dimension. Regarding the meaning of the whole block and the tail block, the whole block refers to the part in which the number of data in the SIMD instruction is equal to the preset number, and the tail block refers to the part in which the number of data in the SIMD instruction is less than the preset number. When the chip calculates the data in batches by calling the SIMD instruction, each batch can process a fixed number of data. If the number of data to be processed is not divisible by the aforementioned fixed number, a tail block will be set, the number of data in the tail block is less than the aforementioned fixed number, and the number of data in the whole block is equal to the aforementioned fixed number; if the number of data to be processed is divisible by the aforementioned fixed number, there is no tail block. In this implementation, through the technology of the whole block and the tail block, the problem of the value range of the first parameter corresponding to the length of the first loop dimension not being divisible by an integer can be solved, and the application scenario of this solution is expanded, thereby expanding the scope of application of this solution.

[0015] In a possible implementation of the first aspect, a SIMD instruction generation device generates a first SIMD instruction after conversion of a first tensor calculation formula according to the length of at least one loop dimension of the first tensor calculation formula and a second SIMD instruction model, which may include: the SIMD instruction generation device obtains a first parameter corresponding to a second loop dimension of the first tensor calculation formula according to first indication information in information of the second SIMD instruction model, wherein the second loop dimension is a loop dimension with the highest dimension among at least one loop dimension, and the length of the second loop dimension exceeds the upper limit of the corresponding first parameter; the SIMD instruction generation device generates a parameter value of a whole block portion of the first SIMD instruction based on the length of the second loop dimension. In this implementation, the value range of the length of the loop dimension in the constraint condition can be expanded through the technology of the whole block and the tail block, thereby expanding the applicable scope of this solution.

[0016] In a possible implementation of the first aspect, at least one group of information of the first SIMD instruction model includes information of the third SIMD instruction model, information of the fourth SIMD instruction model, and information of the fifth SIMD instruction model, the value of N corresponding to the information of the third SIMD instruction model is less than the value of N corresponding to the information of the fourth SIMD instruction model, the value of N corresponding to the information of the fourth SIMD instruction model is less than the value of N corresponding to the information of the fifth SIMD instruction model, and the N corresponding to the information of the fourth SIMD instruction model is greater than or equal to 2. The SIMD instruction generation device selects at least one group of information of the second SIMD instruction model from the information of the at least one group of first SIMD instruction model, including: the SIMD instruction generation device selects the information of the second SIMD instruction model from the information of the third SIMD instruction model; when the information of the second SIMD instruction model does not exist in the information of the fourth SIMD instruction model, the selection of the information of the second SIMD instruction model from the information of the fifth SIMD instruction model is terminated. Further, the SIMD instruction generation device first performs the selection operation of the information of the second SIMD instruction model on the information of the third SIMD instruction model, and then performs the selection operation of the information of the second SIMD instruction model on the information of the fourth SIMD instruction model. In this implementation, if there is no matching model in the low-dimensional model, there is no need to match the high-dimensional model, which can effectively reduce the number of matches and further improve the generation efficiency of SIMD instructions.

[0017] In a possible implementation of the first aspect, the method further includes: the SIMD instruction generation device obtains a second constraint condition, the second constraint condition is used to indicate the number of destination addresses in the first SIMD instruction model and the number of source addresses in the first SIMD instruction model. The SIMD instruction generation device obtains the number of destination addresses in the first tensor calculation formula and the number of source addresses in the first tensor calculation formula. The SIMD instruction generation device selects at least one group of information of the second SIMD instruction model from at least one group of information of the first SIMD instruction model, including: when the number of destination addresses in the first tensor calculation formula is the same as the number of destination addresses in the first SIMD instruction model, and the number of source addresses in the first tensor calculation formula is the same as the number of source addresses in the first SIMD instruction model, select at least one group of information of the second SIMD instruction model from at least one group of information of the first SIMD instruction model. The method also includes: when the number of destination addresses in the first tensor calculation formula is different from the number of destination addresses in the first SIMD instruction model, or the number of source addresses in the first tensor calculation formula is different from the number of source addresses in the first SIMD instruction model, output warning information. In this implementation, during the execution of the SIMD instruction automatic conversion operation, it will first be determined whether the number of destination addresses and the number of source addresses in the first tensor calculation formula meet the requirements for the number of destination addresses and the number of source addresses in the SIMD instruction model. Only when the constraints are met, the subsequent SIMD instruction model matching operation will be performed to improve the efficiency of the SIMD instruction automatic conversion process; in addition, if it is not met, an alarm message will be output in a timely manner to remind technical personnel to intervene in time.

[0018] In a possible implementation of the first aspect, the SIMD instruction generation device obtains information of at least one group of first SIMD instruction models, including: the SIMD instruction generation device obtains information of at least one group of first SIMD instruction models from the information set of the SIMD instruction model. Wherein, the information set of the SIMD instruction model includes at least one information subset of the SIMD instruction model, each information subset of the SIMD instruction model corresponds to a tensor calculation formula of an operation type, different information subsets of SIMD instruction models correspond to tensor calculation formulas of different operation types, and at least one group of information of the first SIMD instruction model belongs to the information subset of the SIMD instruction model corresponding to the operation type of the first tensor calculation formula. In this implementation, the information of the first SIMD instruction model is generated for a tensor calculation formula of a specific operation type, that is, the information of the SIMD instruction model corresponding to the tensor calculation formula of different operation types is different, so that the information of the first SIMD instruction model is more consistent with the tensor calculation formula of the operation type of the first tensor calculation formula, and it is beneficial to improve the efficiency of the SIMD instruction generation process.

[0019] In a possible implementation of the first aspect, the method includes: a SIMD instruction generation device obtains a first parameter value and a second parameter value corresponding to a first SIMD instruction model, wherein the first parameter value is K, which is used to indicate that the first SIMD instruction model includes K first parameters, K is an integer greater than or equal to 1, and the second parameter value indicates the value constraints of the K first parameters, and the first parameter reflects the number of times an operation is repeatedly performed on a data object in a tensor calculation formula matching the first SIMD instruction model. The SIMD instruction generation device generates information of the first SIMD instruction model based on the first parameter value and the second parameter value. Specifically, the SIMD instruction processing device generates first indication information included in the information of the first SIMD instruction model based on the first parameter; and generates a first constraint condition included in the information of the first SIMD instruction model based on the first indication information and the second parameter. In this implementation, the information set of the SIMD instruction model generated corresponding to the chip is used to indicate the SIMD instruction conversion operation for executing the tensor calculation formula; in addition, a plurality of groups of first SIMD instruction model information are generated in advance, and during the conversion process, a matching combination is first selected from a number of combinations based on the lengths of the N loop dimensions of the tensor calculation formula, which greatly reduces the difficulty of the SIMD instruction generation process and improves the efficiency of automatically generating SIMD instructions.

[0020] In a possible implementation of the first aspect, the method further includes: the SIMD instruction generation device obtains a third parameter value, and the third parameter value indicates the number constraint of the whole block in the first SIMD instruction model. The SIMD instruction generation device generates information of the first SIMD instruction model according to the first parameter value and the second parameter value, including: generating first indication information according to the first parameter value; generating a first constraint condition according to the first indication information, the second parameter value and the third parameter value. Among them, the first constraint condition includes a constraint condition on the length of the second loop dimension in the first SIMD instruction model, and the upper limit of the length of the second loop dimension can be extended by setting the whole block method. Further, the whole block method is set to the upper limit of the length of the second loop dimension of the product type. In this implementation method, the number constraint of the whole block in the SIMD instruction of the target type in the chip is obtained in advance, and combined with the number constraint of the whole block, a constraint condition for indicating the length of the loop dimension of the tensor calculation formula is generated. Through the technology of the whole block and the tail block, the value range of the length of the loop dimension in the constraint condition can be expanded, thereby expanding the applicable scope of this solution.

[0021] In a possible implementation of the first aspect, the method further includes: the SIMD instruction generation device obtains a fourth parameter value, and the fourth parameter value is used to indicate the number of destination addresses of the first SIMD instruction model and the number of source addresses of the first SIMD instruction model. The SIMD instruction generation device generates a second constraint condition based on the fourth parameter value, and the second constraint condition is used to indicate the number of destination addresses and the number of source addresses in the tensor calculation formula matching the first SIMD instruction model. In this implementation, the number of destination addresses and the number of source addresses in the SIMD instructions of the target type of the chip are obtained in advance, and then the second constraint condition is generated. The second constraint condition is used to indicate the number of destination addresses and the number of source addresses in the tensor calculation formula of the target operation type, so that the second constraint condition can be used to preliminarily determine whether the SIMD instruction model matches the tensor calculation formula to be converted, thereby avoiding the waste of computer resources, and is also conducive to improving the efficiency of the tensor calculation formula conversion stage.

[0022] In a possible implementation of the first aspect, the method further includes: the SIMD instruction generation device obtains a cost function corresponding to the first SIMD instruction. The cost function is used to select the optimal SIMD instruction by using the cost function in the SIMD instruction conversion operation of the tensor calculation formula of the target operation type executed by the SIMD instruction generation device.

[0023] In the second aspect, the embodiment of the present application provides a method for processing a SIMD instruction, which can be used in the field of SIMD instruction generation in the chip field. The method may include: a SIMD instruction processing device obtains a first parameter value and a second parameter value corresponding to a first SIMD instruction model. Wherein, the value of the first parameter value is K, which is used to indicate that the first SIMD instruction model includes K first parameters, K is an integer greater than or equal to 1, and the second parameter value indicates the value constraints of the K first parameters, and the first parameter reflects the number of repetitions of an operation on a data object in a tensor calculation formula matching the first SIMD instruction model. The SIMD instruction processing device generates information of the first SIMD instruction model according to the first parameter value and the second parameter value, wherein the information of a first SIMD instruction model corresponds to a first SIMD instruction model, and the information of the first SIMD instruction model includes a first indication information and a first constraint condition, the first indication information is used to indicate the correspondence between the K first parameters and at least one loop dimension of the tensor calculation formula matching the first SIMD instruction model, and the first constraint condition is used to indicate the constraint condition of the length of each loop dimension in at least one loop dimension.

[0024] In a possible implementation of the second aspect, the method further includes: the SIMD instruction processing device obtains a third parameter value, and the third parameter value indicates a quantity constraint of the entire block in the first SIMD instruction model. The SIMD instruction processing device generates information of the first SIMD instruction model according to the first parameter value and the second parameter value, including: generating first indication information according to the first parameter value; generating a first constraint condition according to the first indication information, the second parameter value, and the third parameter value.

[0025] In a possible implementation of the second aspect, the method also includes: the SIMD instruction processing device obtains a fourth parameter value, the fourth parameter value is used to indicate the number of destination addresses of the first SIMD instruction model and the number of source addresses of the first SIMD instruction model; based on the fourth parameter value, a second constraint condition is generated, and the second constraint condition is used to indicate the number of destination addresses and the number of source addresses in the tensor calculation formula matching the first SIMD instruction model.

[0026] In a possible implementation manner of the second aspect, the method also includes: a SIMD instruction processing device obtains a cost function corresponding to a first SIMD instruction model, wherein the cost function is used to screen out SIMD instructions that meet the optimization goal, and the SIMD instructions that meet the optimization goal are SIMD instructions with the largest or smallest function value of the cost function, and the independent variables of the cost function include at least one of the following: a parameter value of a first parameter in the first SIMD instruction, the number of whole blocks in the first SIMD instruction, the number of tail blocks in the first SIMD instruction, the number of calculation times of an address offset in the first SIMD instruction, the duration of executing a SIMD instruction, and the duration of switching from a process of executing a first SIMD instruction to a process of executing another first SIMD instruction.

[0027] In a possible implementation of the second aspect, the optimization objectives of the cost function include at least one of the following: minimum total number of SIMD instruction executions, maximum total number of SIMD instruction executions, minimum number of whole blocks and tail blocks in SIMD instructions, maximum number of whole blocks and tail blocks in SIMD instructions, maximum interval between whole blocks and tail blocks in SIMD instructions, minimum interval between whole blocks and tail blocks in SIMD instructions, minimum SIMD instruction scheduling delay, maximum SIMD instruction scheduling delay, minimum total execution time of SIMD instructions, maximum computational overhead of address offsets in SIMD instructions, and minimum computational overhead of address offsets in SIMD instructions.

[0028] In the second aspect of the present application, the specific implementation methods and beneficial effects of the SIMD instruction processing device executing the second aspect and each possible implementation method of the second aspect can be specifically referred to the first aspect. The SIMD instruction processing device can also execute various other possible implementation methods in the first aspect, which will not be repeated here.

[0029] In a third aspect, an embodiment of the present application provides a SIMD instruction generation device, which can be used in the field of SIMD instruction generation in the chip field, and the device includes: an acquisition module, used to obtain the length of each loop dimension of a first tensor calculation formula; the acquisition module is also used to obtain information of multiple groups of first single-instruction multiple-data SIMD instruction models, wherein the information of each group of first SIMD instruction models corresponds to at least one loop dimension of a tensor calculation formula, and the information of each group of first SIMD instruction models includes a first constraint condition, and the first constraint condition is used to indicate the constraint condition of the length of each loop dimension in at least one loop dimension; a selection module is used to select information of a second SIMD instruction model from the information of multiple groups of first SIMD instruction models according to the first constraint condition and the length of each loop dimension of the first tensor calculation formula, the information of the second instruction model matches the first tensor calculation formula, and the length of the loop dimension of the first tensor calculation formula satisfies the first constraint condition in the information of the second SIMD instruction model; a generation module is used to generate a first SIMD instruction after the conversion of the first tensor calculation formula according to the length of at least one loop dimension of the first tensor calculation formula and the second SIMD instruction model.

[0030] The constituent modules of the SIMD instruction generation device provided in the third aspect of the present application can also be used to execute the steps performed by the SIMD instruction generation device in various possible implementation methods of the first aspect. For details, please refer to the description in the first aspect and the various possible implementation methods in the first aspect, and will not be repeated here one by one.

[0031] In a fourth aspect, an embodiment of the present application provides a SIMD instruction processing device, which can be used in the field of SIMD instruction generation in the chip field, and the device includes: an acquisition module, used to obtain a first parameter value and a second parameter value corresponding to a first SIMD instruction model, wherein the value of the first parameter value is K, used to indicate that the first SIMD instruction model includes K first parameters, K is an integer greater than or equal to 1, and the second parameter value indicates the value constraints of the K first parameters, and the first parameter reflects the number of repetitions of an operation on a data object in a tensor calculation formula matching the first SIMD instruction model; a generation module, used to generate information of the first SIMD instruction model according to the first parameter value and the second parameter value, wherein the information of a first SIMD instruction model corresponds to a first SIMD instruction model, and the information of the first SIMD instruction model includes first indication information and first constraint conditions, the first indication information is used to indicate the correspondence between the K first parameters and at least one loop dimension of the tensor calculation formula matching the first SIMD instruction model, and the first constraint condition is used to indicate the constraint condition of the length of each loop dimension in at least one loop dimension.

[0032] The constituent modules of the SIMD instruction generation device provided in the fourth aspect of the present application can also be used to execute the steps performed by the SIMD instruction generation device in various possible implementation methods of the second aspect. For details, please refer to the description in the second aspect and the various possible implementation methods in the second aspect, and will not be repeated here one by one.

[0033] In a fifth aspect, an embodiment of the present application provides an execution device, comprising a processor, the processor being coupled to a memory; the memory being used to store programs; and the processor being used to execute the programs in the memory, so that the execution device executes the steps performed by the SIMD instruction generation device in each possible implementation method of the first aspect.

[0034] In a sixth aspect, an embodiment of the present application provides an execution device, comprising a processor coupled to a memory; the memory is used to store programs; and the processor is used to execute the programs in the memory, so that the execution device executes the steps performed by the SIMD instruction processing device in each possible implementation method of the second aspect.

[0035] In the seventh aspect, an embodiment of the present application provides a computer-readable storage medium, in which a computer program is stored. When the computer-readable storage medium is run on a computer, the computer executes the processing method of the SIMD instructions described in the first aspect above, or the computer executes the processing method of the SIMD instructions described in the second aspect above.

[0036] In an eighth aspect, an embodiment of the present application provides a computer program, which, when executed on a computer, enables the computer to execute the SIMD instruction processing method described in the first aspect above, or enables the computer to execute the SIMD instruction processing method described in the second aspect above.

[0037] In a ninth aspect, the present application provides a chip system, which includes a processor for supporting a terminal device or a communication device to implement the functions involved in the above aspects, for example, sending or processing the data and / or information involved in the above methods. In one possible design, the chip system also includes a memory, which is used to store program instructions and data necessary for the terminal device or the communication device. The chip system can be composed of a chip, or it can include a chip and other discrete devices. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] Figure 1 A system architecture diagram of a SIMD instruction processing system provided in an embodiment of the present application;

[0039] Figure 2 A flowchart of a method for processing SIMD instructions provided in an embodiment of the present application;

[0040] Figure 3 Another flowchart of a method for processing SIMD instructions provided in an embodiment of the present application;

[0041] Figure 4 A schematic diagram of the corresponding relationship between the first parameter and the loop dimension in the SIMD instruction processing method provided in an embodiment of the present application;

[0042] Figure 5 A flowchart of a method for generating a SIMD instruction provided in an embodiment of the present application;

[0043] Figure 6 A flowchart of another method for processing SIMD instructions provided in an embodiment of the present application;

[0044] Figure 7 A structural schematic diagram of a SIMD instruction generation device provided in an embodiment of the present application;

[0045] Figure 8 A structural schematic diagram of a SIMD instruction processing device provided in an embodiment of the present application;

[0046] Fig. 9 A schematic diagram of the structure of an execution device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0047] The embodiments of the present application provide a method for generating and processing a SIMD instruction and related equipment, which is used to select information of a second SIMD instruction model from multiple groups of information of first SIMD instruction models according to the length of each loop dimension of a tensor calculation formula, and then generate a first SIMD instruction after conversion of the first tensor calculation formula according to the second SIMD instruction model, thereby greatly improving the efficiency of the SIMD instruction generation process.

[0048] The embodiments of the present application are described below in conjunction with the accompanying drawings. Those skilled in the art will appreciate that, with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.

[0049] The terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and need not be used to describe a specific order or sequential order. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances, which is only to describe the distinction mode adopted by the objects of the same attributes when describing in the embodiments of the present application. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, so that the process, method, system, product or equipment comprising a series of units need not be limited to those units, but may include other units that are not clearly listed or inherent to these processes, methods, products or equipment.

[0050] It should be understood that the processing method of SIMD instructions provided in the embodiments of the present application can be applied to the development process of various types of chips. Among them, the aforementioned chip can be specifically manifested as a central processing unit (CPU), an AI chip or other types of chips. Further, AI chips include but are not limited to neural network processors (neural-network processing unit, NPU), graphics processing units (graphics processing unit, GPU), application specific integrated circuits (application specific integrated circuit, ASIC), field programmable gate arrays (field programmable gate array, FPGA), etc. In the development process of the aforementioned various chips, the generation method of SIMD instructions provided in the embodiments of the present application can be used to realize the automatic conversion of tensor calculation formulas to SIMD instructions.

[0051] First, see Figure 1 , Figure 1 A system architecture diagram of a SIMD instruction processing system provided in an embodiment of the present application, Figure 1 The SIMD instruction model processing device 100 and the SIMD instruction model generating device 200 are shown in the figure. The SIMD instruction model processing device 100 is used to generate a software package including information of multiple groups of first SIMD instruction models, and configure the software package in the SIMD instruction model generating device 200. When the SIMD instruction model generating device 200 needs to perform a conversion operation from a first tensor calculation formula to a SIMD instruction, the length of each loop dimension of the first tensor calculation formula is obtained, and the information of the second SIMD instruction model is selected from the information of multiple groups of first SIMD instruction models according to the length of each loop dimension of the first tensor calculation formula, and the information of the second instruction model is matched with the first tensor calculation formula, thereby generating a first SIMD instruction after the conversion of the first tensor calculation formula.

[0052] The SIMD instruction model processing device 100 and the SIMD instruction model generating device 200 may be integrated into the same device or located in different devices. When integrated into the same device, the SIMD instruction model processing device 100 may configure a software package including information of multiple groups of first SIMD instruction models on the SIMD instruction model generating device 200 through a bus. When located in different devices, the SIMD instruction model processing device 100 may configure the software package in the processing device of the SIMD instruction model through a wired network, a wireless network or a removable storage medium.

[0053] Furthermore, the SIMD instruction model processing device 100 and the SIMD instruction model generating device 200 can be both devices with communication functions, such as desktop computers, laptop computers, personal digital assistants (PDA), tablet computers, handheld devices, wearable devices, etc., which are not limited here. It should be understood that although Figure 1 FIG. 1 shows a SIMD instruction model processing device 100 and three SIMD instruction model generating devices 200, but Figure 1 This is only for facilitating the understanding of this solution and is not intended to limit the number of devices.

[0054] In order to facilitate understanding of the present solution, before introducing the processing method of the SIMD instruction provided in the embodiment of the present application, the following terms appearing in the embodiment of the present application are first introduced:

[0055] Tensor calculation formula: includes one for loop or multiple nested for loops. Each for loop defines the calculation formula that needs to be executed by the for loop. The calculation formula includes tensors and operators. Of course, each for loop can also include the value range of the coordinates in the tensor. Tensors are multiple linear mappings defined on the Cartesian product of vector space and dual space. The operators in the tensor calculation formula determine the calculation type of the tensor calculation formula. The calculation type of the first tensor calculation formula can be addition or multiplication.

[0056] Loop dimension: A tensor calculation formula can be specifically expressed in the form of a for loop. A tensor calculation formula can include multiple data objects. A loop dimension of a tensor calculation formula refers to a for loop in the tensor calculation formula.

[0057] Length of loop dimension: The length of a loop dimension in a tensor calculation formula refers to the upper limit of the coordinate values ​​in a for loop of the tensor calculation formula.

[0058] SIMD instruction model: The format of the SIMD instruction model is the same as that of the SIMD instruction. The difference is that the parameter values ​​of each parameter in the SIMD instruction model have not been determined, while the parameter values ​​of each parameter in the SIMD instruction have been determined.

[0059] Whole block and tail block: When the chip calculates data objects in batches by calling SIMD instructions, each batch can process a fixed number of data objects. If the number of data objects to be processed is not divisible by the aforementioned fixed number, a tail block will be set. The number of data objects in the tail block is less than the aforementioned fixed number, and the number of data objects in the whole block is equal to the aforementioned fixed number. If the number of data objects to be processed is divisible by the aforementioned fixed number, there will be no tail block.

[0060] The length of the first loop dimension is not evenly divisible by the value range of the corresponding first parameter: one or more first parameters in the SIMD instruction are used to implement calculations of a first loop dimension, the one or more first parameters include a fifth parameter and a sixth parameter, and the fifth parameter is sorted earlier in the one or more first parameters than the sixth parameter in the one or more first parameters. Then the length of the first loop dimension is not evenly divisible by the value range of the corresponding first parameter refers to the length of the first loop dimension is not evenly divisible by the value range of the fifth parameter, or the length of the first loop dimension is not evenly divisible by the product of the values ​​of the fifth parameter and the sixth parameter.

[0061] Next, the specific implementation of the embodiment of the present application is described. Figure 2 , Figure 2 A flow chart of a processing method for SIMD instructions provided in an embodiment of the present application. The scheme provided in an embodiment of the present application can be divided into a generation phase of information of a SIMD instruction model and a conversion phase of a tensor calculation formula. In the generation phase of information of a SIMD instruction model, a SIMD instruction processing device generates an information set of a SIMD instruction model, and the information set of a SIMD instruction model includes information of at least one first SIMD instruction model; in the conversion phase of a tensor calculation formula, after obtaining a first tensor calculation formula of an operation type of a first tensor calculation formula, the SIMD instruction generation device obtains a SIMD instruction model that matches the first tensor calculation formula according to the information of the first SIMD instruction model generated in advance, and then generates a SIMD instruction corresponding to the first tensor calculation formula. The following begins to describe the specific implementation process of the generation phase of information of a SIMD instruction model and the conversion phase of a tensor calculation formula in the processing method for SIMD instructions provided in an embodiment of the present application.

[0062] 1. The information generation stage of SIMD instruction model

[0063] In the present application, please refer to Figure 3 , Figure 3 A flowchart of a method for processing a single instruction multiple data SIMD instruction provided in an embodiment of the present application is provided. The method for processing a single instruction multiple data SIMD instruction provided in an embodiment of the present application may include:

[0064] 301. A SIMD instruction processing apparatus obtains a first parameter value and a second parameter value corresponding to a first SIMD instruction model.

[0065] In the embodiment of the present application, since the chip can support one or more types of SIMD instructions, the SIMD instruction processing device will select the target type of SIMD instructions from the aforementioned one or more types of SIMD instructions to generate the information of the first SIMD instruction model of the target type as the target of a generation operation. Among them, the specific manifestation of the chip can refer to the above description, which will not be repeated this time. The target type of SIMD instruction is a SIMD instruction among the one or more types of SIMD instructions supported by the chip. Each type of SIMD instruction corresponds to a tensor calculation formula of an operation type. The SIMD instruction formats of different types of SIMD instructions are different; when the target type of SIMD instruction is called by the chip, it is used to implement the operation of the tensor calculation formula of the target operation type. Further, the tensor calculation formula is a calculation formula including a tensor (tensor) and an operator. The tensor is a multilinear mapping defined on the Cartesian product of the vector space and the dual space. The zero-order tensor can be called a scalar, and the first-order tensor can be called a vector. The operator in the tensor calculation formula determines the operation type of the tensor calculation formula. The target operation type can be specifically addition, multiplication or other types of operation types.

[0066] To further understand the present solution, the SIMD instructions in the embodiment of the present application are shown by the following formula:

[0067] SIMD_OP([dst i ],[src j ],[repeat k ],[dstStride i,k ],[srcStride j,k ],[other z ]); (1)

[0068] Among them, OP stands for operator, [dst i ](i=0,1,…,I-1) represents the destination address set of the data object corresponding to the SIMD instruction, i is an integer greater than or equal to 0, [src j ](j=0,1,…,J-1) represents the source address set of the data object corresponding to the SIMD instruction, j is an integer greater than or equal to 0, [repeat k ](k=0, 1, ..., K-1) represents K first parameters in the embodiment of the present application, and the first parameter refers to repeat k The value of the first parameter reflects the chip's execution of repeat k The parameter is the number of times the operation is repeated on the data object. K is an integer greater than or equal to 1. The operations performed on the data object include reading, calculating, and writing. 0≤repeat k ≤Rk , (k=0,1,…,K-1), R k Represents repeat k The upper limit of R k The value of is determined by the chip. When executing the SIMD instruction shown in formula (1), the chip follows the formula ([0,repeat0],[0,repeat1],…,[0,repeat K-1 ]) to perform operations on data objects corresponding to SIMD instructions in the order of [dstStride i,k ](i=0,1,…,I-1;k=0,1,…,K-1) represents the chip executing a certain repeat k The parameter is the destination address dst corresponding to the data object i The address offset of [srcStride j,k ]+(j=0,1,…,J-1;k=0,1,…,K-1) represents the chip executing a certain repeat k The parameter is the source address src corresponding to the data object j The address offset of [other z ](z=0,1,…,Z-1) are other parameters, and z is an integer greater than or equal to 0. It should be understood that the above formula (1) is only an illustration for facilitating the understanding of SIMD instructions. In other implementations, the order of arrangement of the parameters in the SIMD instruction may be different from that in formula (1), or the parameters in the SIMD instruction may be added or deleted based on formula (1), which is not limited here.

[0069] The tensor calculation formula in the embodiment of the present application is shown by the following formula:

[0070] for(x0,x1,…,x H-1 )in(X0,X1,…,X H-1 ):

[0071] [D i (x0,x1,…,x H-1 )]=OP([S j (x0,x1,…,x H-1 )]) (2)

[0072] The tensor calculation formula can be specifically expressed in the form of a for loop. A loop dimension of the tensor calculation formula refers to the dimension where a coordinate of a data object in the tensor calculation formula in the for loop form is located. Formula (2) shows a tensor calculation formula including H loop dimensions, (x0, x1, ..., x H-1 ) represents the tensor D i and the tensor S j, where i = 0, 1, ..., I-1, and I is an integer greater than or equal to 0, and the value of I represents the number of destination addresses in the tensor calculation formula, j = 0, 1, ..., J-1, and J is an integer greater than or equal to 0, and the value of J represents the number of source addresses in the tensor calculation formula, OP represents the operator (also called the operation type), (X0, X1, ..., X H-1 ) includes H X θ , X θ =[0,E θ ],(θ=0,1,…,H-1),E θ Is a non-negative integer representing the length of the θth loop dimension of the tensor calculation formula, x θ ∈X θ , the length of a loop dimension in a tensor calculation formula is related to the value range of a data object in the tensor calculation formula.

[0073] An equivalent linear expression of the above formula (2) is as follows:

[0074]

[0075] in, Represents the tensor D i Coordinate linearization coefficient, x p represents (x0, x1, …, x H-1 ), Represents the tensor S j Coordinate linearization coefficient of .

[0076] Furthermore, a specific example of a tensor calculation formula is shown below:

[0077]

[0078] Wherein, formula (4) is a tensor calculation formula including 6 loop dimensions, that is, H=6, tensor D0, tensor S0 and tensor S1 all include (x0, x1, x2, x3, x4, x5), the number of destination addresses of the tensor calculation formula shown in formula (4) is 1, the number of source addresses is 2, the length E0 of the loop dimension where x0 is located is 16, the length E1 of the loop dimension where x1 is located is 4, the length E2 of the loop dimension where x2 is located is 6, the length E3 of the loop dimension where x3 is located is 4, the length E4 of the loop dimension where x4 is located is 6, and the length E5 of the loop dimension where x5 is located is 6. The value of is 1. The value of is 16. The value of is 48. The value is 304. The value of is 912. The value of is 5776. The value of is 1. The value of is 16. The value of is 48. The value is 304. The value of is 912. The value of is 5776. The value of is 1. The value of is 0. The value of is 16. The value of is 0. The value of is 96. The value of is 576. It should be understood that the examples of tensor calculation formulas in the above formulas (2), (3) and (4) are only for the convenience of understanding this solution and are not used to limit this solution.

[0079] The SIMD instruction processing device obtains the first parameter value and the second parameter value corresponding to the target type of SIMD instruction. The first parameter value is K, which is used to indicate that the target type of SIMD instruction includes K first parameters, and the target function refers to the repeat in the above formula (1). k The second parameter value is used to indicate the value constraints of the K first parameters in the chip. The second parameter value refers to the K R in the above formula (1). k The chip can implement the tensor calculation formula of the target operation type when executing the SIMD instruction of the target type. The K first parameters correspond to the N loop dimensions in the tensor calculation formula of the target operation type, and N is an integer less than or equal to K and greater than or equal to 1. Furthermore, the chip can implement the calculation of a loop dimension of the tensor calculation formula through a one-dimensional or multi-dimensional first parameter. It should be noted that the tensor calculation formula of the aforementioned target operation type may include H loop dimensions, and H is an integer greater than or equal to N.

[0080] Specifically, in one implementation, after understanding the specifications and performance of the chip, the user can learn the first parameter value and the second parameter value corresponding to the target type of SIMD instruction in the chip, and then the SIMD instruction processing device can receive the first parameter value and the second parameter value input by the user. More specifically, the display interface of the SIMD instruction processing device can directly display the input box of the first parameter value and the second parameter value, so that the user inputs the first parameter value and the second parameter value through the aforementioned input box. The SIMD instruction processing device can also receive a file containing the first parameter value and the second parameter value input by the user, so that the SIMD instruction processing device can extract the input box of the first parameter value and the second parameter value from the aforementioned file, and the aforementioned file can be specifically expressed as a text document, a table document, a program code or other format files, etc. In another implementation, the SIMD instruction processing device can also receive the SIMD instruction model of the target type in the chip input by the user, and the SIMD instruction processing device obtains the parameter value of the first parameter by parsing the aforementioned SIMD instruction model. The way in which the SIMD instruction processing device obtains the second parameter value is similar to that in the aforementioned implementation, and will not be repeated here.

[0081] Optionally, the SIMD instruction processing device obtains a third parameter value, and the third parameter value is used to indicate the number constraint of the whole block (Body) in the SIMD instruction of the target type. Among them, the SIMD instruction processing device can implement tensor calculation operations through SIMD instructions of the whole block part and the tail block (Tail) part. Furthermore, when the chip calculates data objects in batches by calling SIMD instructions, each batch can process a fixed number of data objects. If the number of data objects to be processed is not divisible by the aforementioned fixed number, a tail block will be set, and the number of data objects in the tail block is less than the aforementioned fixed number, and the number of data objects in the whole block is equal to the aforementioned fixed number; if the number of data objects to be processed is divisible by the aforementioned fixed number, there is no tail block. As an example, please refer to the following formula:

[0082] for(x N , x N+1 , ..., x H-1 )in(X N , X N+1 , ..., X H-1 ):

[0083]

[0084]

[0085]

[0086]

[0087]

[0088] The above formula shows that a set of SIMD instructions in equation (5) and equation (6) cooperate with the For-x loop to jointly realize the operation of H loop dimensions of the tensor calculation formula. The equation (5) in the above formula represents the whole block part in a set of SIMD instructions, and the equation (6) in the above formula represents the tail block part in a set of SIMD instructions. p Represents (x N , x N+1 , ..., x H-1 ), Represents the tensor D i Medium p The coordinate linearization coefficients of represent Any parameter in The number of K first parameters representing the entire block of a set of SIMD instructions, Head (k=0, 1, ..., K-1), where Repeat in SIMD instruction representing the target type in the chip k The upper limit of the number of parameter blocks, is an integer greater than or equal to 0, The destination address D represents the entire block of a group of SIMD instructions. i middle The address offset of Represents the tensor S j Medium p The coordinate linearization coefficients of The source address S represents the entire block of a group of SIMD instructions. j middle The address offset of represents the K first parameters of a whole block of SIMD instructions, The value of reflects the number of times the chip repeats the operation on the data object when executing the K first parameters of the entire block in a set of SIMD instructions. i,k ] indicates that the chip is executing a repeat k The parameter is the destination address dst corresponding to the data object i The address offset of |srcStride j,k |(j=0,1,...,J-1;k=0,1,...,K-1) represents the chip executing a certain repeat k The parameter is the source address src corresponding to the data object j The address offset of represent Any parameter in represents the number of K first parameters of the tail block portion of a group of SIMD instructions, Head (k=0, 1, ..., K-1), where Repeat in SIMD instruction representing the target type in the chip k The upper limit of the number of parameter tail blocks, The value of is 0 or 1. When there is no tail block, When it represents a tail block, Represents the destination address D of the tail block of a group of SIMD instructions i middle The address offset of Represents the source address S of the tail block of a group of SIMD instructions j middle The address offset of represents the K first parameters of the tail block part of a group of SIMD instructions, The value of reflects the number of repetitions of the operation performed on the data object by the chip when executing the K first parameters of the tail block part of a set of SIMD instructions. It should be understood that in other embodiments, the operation of the tensor calculation formula can be realized only by the whole block part and the tail block part of a set of SIMD instructions without the need for a For loop; or, the operation of the tensor calculation formula can be realized only by the whole block part without the need for the tail block part, etc. The above examples are only for the convenience of understanding the concepts of the whole block and the tail block, and are not used to limit this solution.

[0089] A group of SIMD instructions is used to implement the calculation of N loop dimensions of a tensor calculation formula. Correspondingly, the whole block part of the group of SIMD instructions includes N kinds of whole blocks, each whole block corresponds to one loop dimension in the N loop dimensions; the tail block part of the group of SIMD instructions includes N kinds of tail blocks, each tail block corresponds to one loop dimension in the N loop dimensions, and N is an integer greater than or equal to 1. The number constraint on the whole blocks in the target type of SIMD instructions included in the third parameter refers to the upper limit of the number of whole blocks corresponding to the second loop dimension in the N kinds of whole blocks. As an example, for example, the third parameter also includes the number constraint on the whole blocks in the target type of SIMD instructions, where the number constraint value of the whole block is 5, and a group of target type of SIMD instructions is used to implement the operation of 2 loop dimensions of the tensor calculation formula, then the upper limit of the number of whole blocks corresponding to the second loop dimension of the tensor calculation formula in the whole block part of the target type of SIMD instructions is 5. It should be understood that this example is only for the convenience of understanding this solution and is not used to limit this solution.

[0090] Specifically, similar to the way in which the SIMD instruction processing device obtains the second parameter, in one implementation, the SIMD instruction processing device may receive the third parameter value input by the user through an input box. In another implementation, the SIMD instruction processing device may receive a file containing the third parameter value input by the user.

[0091] Optionally, the SIMD instruction processing device obtains a fourth parameter value, and the fourth parameter value is used to indicate the number of destination addresses of the target type of SIMD instructions and the number of source addresses of the target type of SIMD instructions. The number of destination addresses of the target type of SIMD instructions is also the value of I in formula (1), and the number of source addresses of the target type of SIMD instructions is also the value of J in formula (1). As an example, for example, if a certain SIMD instruction includes dst0, src0 and src1, the number of destination addresses in the SIMD instruction is 1, and the number of source addresses is 2. It should be understood that the example here is only for the convenience of understanding this solution and is not used to limit this solution.

[0092] Specifically, similar to the way in which the SIMD instruction processing device obtains the first parameter. In one implementation, the SIMD instruction processing device may receive the fourth parameter value input by the user through an input box. In another implementation, the SIMD instruction processing device may receive a file containing the fourth parameter value input by the user. In another implementation, the SIMD instruction processing device may receive a SIMD instruction model of a target type in a chip input by the user, and extract the fourth parameter value therefrom.

[0093] 302. A SIMD instruction processing device generates information of a first SIMD instruction model.

[0094] In the embodiment of the present application, after executing step 301, the SIMD instruction processing device can generate at least one set of information of the first SIMD instruction model according to the parameters obtained in step 301. The information of the first SIMD instruction model is used to indicate the SIMD instruction conversion operation of the tensor calculation formula of the target operation type according to the information of the first SIMD instruction model. Each set of information of the first SIMD instruction model corresponds to a first SIMD instruction model, and the first SIMD instruction model is used to generate a SIMD instruction of the target type. The format of a first SIMD instruction model is the same as the format of the SIMD instruction of the target type, except that the parameter values ​​of each parameter in the first SIMD instruction model have not been determined, and the parameter values ​​of each parameter in the SIMD instruction have been determined. The information of each set of the first SIMD instruction model includes first indication information and first constraints, and a first indication information is used to indicate the correspondence between K first parameters included in a first SIMD instruction model and N loop dimensions of the tensor calculation formula matching the information of the first SIMD instruction model, and a first constraint condition is used to indicate the constraint condition of the length of the N loop dimensions of the tensor calculation formula matching the information of the first SIMD instruction model under the premise of the correspondence indicated by the first indication information.

[0095] Further, at least one group of information of the first SIMD instruction model includes information of multiple types of SIMD instruction models, and the values ​​of N corresponding to the information of different types of SIMD instruction models are different, and N is an integer greater than or equal to 1. In this implementation, the information of at least one group of the first SIMD instruction model is divided into categories according to the number of loop dimensions corresponding to the information of the first SIMD instruction model, so as to facilitate the subsequent management of the information of different types of first SIMD instruction models separately, thereby improving the management accuracy. The first constraint condition is related to the chip type, and the first constraint conditions of different types of chips may be different. In the embodiment of the present application, the information set of the SIMD instruction model is generated based on a certain specific chip, and different chips will generate different information of SIMD instruction models, which not only expands the application scenario of the present solution, but also improves the fit between the SIMD instruction model and the chip. Optionally, the information of the first SIMD instruction model may also include a third constraint condition, which is used to indicate the value constraint of the address offset in the SIMD instruction model under the premise of the corresponding relationship indicated by the first indication information.

[0096] Specifically, in one case, if only the first parameter and the second parameter are obtained in step 301, and the third parameter (i.e., the number constraint of the whole block in the target type of SIMD instruction) and the fourth parameter (i.e., the number of destination addresses and the number of source addresses of the target type of SIMD instruction) are not obtained, the SIMD instruction processing device may default the number of whole blocks to 1 and the number of tail blocks to 0. Step 302 may include: the SIMD instruction processing device generates the first indication information included in the information of the first SIMD instruction model according to the first parameter; the SIMD instruction processing device generates the first constraint condition included in the information of the first SIMD instruction model according to the first indication information and the second parameter.

[0097] More specifically, for the process of generating the first indication information, there are K repeats in the target type SIMD instruction of the target chip. k , repeat k The correspondence between the loop dimension of the tensor calculation formula of the target operation type can be one-to-one or many-to-one; and K repeats k The permutations and combinations can be made at will, and the value of N can be any value between 1 and K. After knowing the value of K, the SIMD instruction processing device can repeat K of the target type of SIMD instructions. k Perform permutations and combinations to generate up to K repeats k 2 between N cyclic dimensions K-1 There are at most 2 corresponding relationships. K-1 First indication information, each of which can indicate the generation of a first SIMD instruction model, that is, there can be at most 2 corresponding K-1 The first SIMD instruction model.

[0098] Furthermore, if K repeats of the target type SIMD instruction are used k represents a loop dimension of the target operation type (that is, the value of N is 1), then K repeats k There is a correspondence between 1 and 1 loop dimension. If K repeats are passed through the target type of SIMD instructions k Represents the K′ loop dimensions of the target operation type (that is, the value of N is K′), K′ is an integer greater than 1 and less than K, then K repeat k There are K′ cyclic dimensions. There are corresponding relationships, that is, A SIMD instruction model, a SIMD instruction processing device can generate the aforementioned If K repeats of the target type's SIMD instructions are used, k represents the K loop dimensions of the target operation type (that is, the value of N is K), then K repeat k There is a corresponding relationship between and the K loop dimensions. For example, if the value of K is 3, then K repeats k There can be four corresponding relationships between the N loop dimensions (that is, there are four first indication information). In the first corresponding relationship, the 3-dimensional repeat k Together they represent one cyclic dimension. In the second correspondence, the first two dimensions repeat k Used to represent 1 loop dimension, the next dimension is repeat k Used to represent 1 circular dimension. In the third correspondence, the previous dimension repeats k The first dimension is used to represent one loop dimension, and the second dimension is used to represent one loop dimension. In the fourth correspondence, the 3-dimensional repeat k Represent the three circulation dimensions respectively.

[0099] To more intuitively show the correspondence between the first parameter and the loop dimension, see Figure 4 , Figure 4 A schematic diagram of the correspondence between the first parameter and the loop dimension in the processing method of the SIMD instruction provided in the embodiment of the present application. Wherein, K′ refers to N values, representing K repeats in the target type of SIMD instruction k It is divided into K' groups, which are used to represent the K' loop dimensions of the tensor calculation formula of the target operation type. As shown in the figure, repeat0 and repeat1 are used to represent the first loop dimension of the K' loop dimensions of the tensor calculation formula of the target operation type, repeat2 to repeat6 are used to represent the second loop dimension of the K' loop dimensions of the tensor calculation formula of the target operation type, and repeat K-3 and repeat K-2 The K′-1th loop dimension of the K′ loop dimension of the tensor calculation formula used to represent the target operation type, repeat K-1 The K′th loop dimension of the K′ loop dimensions of the tensor calculation formula used to represent the target operation type, etc. Figure 4 The correspondence between the first parameter and the loop dimension is very intuitively shown. The correspondence between other loop dimensions in the K′ loop dimensions will not be described this time. It should be understood that Figure 4 The examples are only for facilitating the understanding of the concept of the first indication information and are not used to limit this solution.

[0100] In order to ensure that the corresponding relationship indicated by the first indication information is feasible, the SIMD instruction processing device also needs to generate the corresponding relationship with 2 K-1 The first indication information corresponds to 2 K-1 The first constraint condition. If K repeats in SIMD instructions k A loop dimension x in the tensor computation that represents the type of the target operation k , the loop dimension x k The length is E k , then it is necessary to satisfy This constraint, that is, the length of a loop dimension of the tensor calculation formula must be less than or equal to the upper limit of the product of the K first parameters. k represents K′ loop dimensions, where K′ is an integer greater than 1 and less than K. k There are K′ cyclic dimensions. The corresponding relationship mentioned above The sth kind of corresponding relationship In the corresponding relationship, for any loop dimension x in the tensor calculation formula of the target operation type k (0≤k<K′) The repeat parameter is used to represent it, that is, in, η represents 0 to Any value in Represents a summation expression middle The subscript of Need to meet (k = 0, ..., K'-1) This constraint condition. If K repeats in SIMD instructions k The K loop dimensions x in the tensor computation used to represent the target operation type k , that is, each dimension of the SIMD instruction is repeated k A loop dimension x in the tensor calculation formula used to represent the target operation type k , the loop dimension x k The length is E k , then it is necessary to satisfy E k ≤R k This constraint, that is, the length of the tensor calculation loop dimension must be less than or equal to repeat k In order to more intuitively understand the first constraint, the following table shows it:

[0101] Table 1

[0102]

[0103] Refer to Table 1 above. Table 1 more intuitively shows the specific presentation form of the first constraint condition under the premise of the corresponding relationship indicated by the first indication information. Since it has been described in detail in the text part before Table 1, it will not be described in detail here.

[0104] In another case, if the first parameter, the second parameter and the third parameter (that is, the number constraint of the whole block in the SIMD instruction of the target type in the chip) are obtained in step 301, the fourth parameter (that is, the number of destination addresses and the number of source addresses of the SIMD instruction of the target type) is not obtained. Step 302 may include: the SIMD instruction processing device generates a first indication information according to the first parameter value; the SIMD instruction processing device generates a first constraint condition according to the first indication information, the second parameter value and the third parameter value. In the embodiment of the present application, the number constraint of the whole block in the SIMD instruction of the target type in the chip is obtained in advance, and combined with the number constraint of the whole block, a constraint condition for indicating the length of the loop dimension of the tensor calculation formula is generated. Through the technology of the whole block and the tail block, the value range of the length of the loop dimension in the constraint condition can be expanded, thereby expanding the scope of applicability of the present solution.

[0105] Specifically, for the specific implementation method of the SIMD instruction processing device generating one or more first indication information according to the first parameter value, reference can be made to the description in the previous case, which will not be repeated here. The SIMD instruction processing device generates a first constraint condition according to the first indication information, the second parameter value and the third parameter value. Among them, the influence of the number of whole blocks in the three parameters on the first constraint condition. Let the number of whole blocks in the target type of SIMD instructions in the chip be in, represents the upper limit of the number of whole blocks of SIMD instructions of the target type in the chip, represents the constraint on the number of whole blocks in the target type of SIMD instructions in the third parameter, then the limit Rk in the first constraint will be relaxed to From the above formula, we can know that by setting the whole block as the product-type expansion of the first constraint condition R k The upper limit value of . Furthermore, the SIMD instruction of the target type is used to implement the calculation of N loop dimensions of the tensor calculation formula, and the upper limit of the constraint of the second loop dimension is relaxed through the whole block and tail block technology. As an example, for example, if the value of N is 2, the first constraint before the expansion is E0≤16×4, E1≤8, and the upper limit of the number of whole blocks is 5, then the first constraint after the expansion is E0≤16×4, E1≤8×5, that is, only the constraint corresponding to the Nth (that is, 2nd) loop dimension is expanded.

[0106] In another case, if the first parameter, the second parameter and the fourth parameter (i.e., the number of destination addresses and the number of source addresses of the target type of SIMD instruction) are obtained in step 301, and the third parameter (i.e., the number constraint of the whole block in the target type of SIMD instruction) is not obtained, the SIMD instruction processing device may default to the number of whole blocks being 1. Step 302 may include: the SIMD instruction processing device generates first indication information according to the first parameter value; generates a first constraint condition according to the first indication information and the second parameter information; generates a second constraint condition according to the fourth parameter value, wherein the information subset of the SIMD instruction model may include only one second constraint condition in the information subset of the entire SIMD instruction model, or may include the second constraint condition in the information of each group of the first SIMD instruction model. The second constraint condition is used to indicate the number of destination addresses in the tensor calculation formula of the target operation type and the number of source addresses in the tensor calculation formula of the target operation type. In an embodiment of the present application, the number of destination addresses and the number of source addresses in the SIMD instructions of the target type of the chip are obtained in advance, and then a second constraint condition is generated. The second constraint condition is used to indicate the number of destination addresses and the number of source addresses in the tensor calculation formula of the target operation type. Therefore, it is possible to preliminarily determine whether the SIMD instruction model matches the tensor calculation formula to be converted based on the second constraint condition, thereby avoiding waste of computer resources and also helping to improve the efficiency of the tensor calculation formula conversion stage.

[0107] Specifically, the specific implementation method for the SIMD instruction processing device to generate the first indication information according to the first parameter value, and the specific implementation method for the SIMD instruction processing device to generate the first constraint condition according to the first indication information and the second parameter information, can all be referred to the specific implementation method of the SIMD instruction processing device when only the first parameter and the second parameter are obtained in step 301, which will not be repeated here. For the specific implementation method for the SIMD instruction processing device to generate one or more second constraints according to the fourth parameter value, after obtaining the number of destination addresses and the number of source addresses of the target type of SIMD instructions, the SIMD instruction processing device can determine the number of destination addresses of the target type of SIMD instructions as the number of destination addresses in the tensor calculation formula of the target operation type in the second constraint condition, and determine the number of source addresses of the target type of SIMD instructions as the number of source addresses in the tensor calculation formula of the target operation type in the second constraint condition. As an example, if the number of destination addresses in the target type of SIMD instruction is 1 and the number of source addresses is 2, then the number of constrained destination addresses in the tensor calculation formula for the target operation type in the second constraint is limited to 1, and the number of constrained source addresses in the tensor calculation formula for the target operation type in the second constraint is limited to 2. It should be understood that the examples given here are only for the convenience of understanding this scheme and are not used to limit this scheme.

[0108] In another case, if the first parameter, the second parameter, the third parameter and the fourth parameter are obtained in step 301. Step 302 may include: the SIMD instruction processing device generates one or more first indication information according to the first parameter value; generates one or more first constraints according to the first indication information and the second parameter information; generates a second constraint according to the fourth parameter value. The specific implementation of the SIMD instruction processing device to perform the above steps can refer to the description in the above three cases, which will not be repeated here.

[0109] 303. The SIMD instruction processing device obtains a first parameter calculation rule.

[0110] In some embodiments of the present application, the SIMD instruction processing device may also generate one or more first parameter calculation rules corresponding to the information of the first SIMD instruction model. The first parameter calculation rule is used for the SIMD instruction generation device to generate the parameter values ​​of the first parameter, the address offset of the destination address, and the address offset of the source address in the SIMD instruction model according to the first parameter calculation rule. The number of first parameter calculation rules and the number of first constraints may be the same, and the first parameter calculation rule is used to indicate the parameter value calculation rules of the first parameter, the address offset of the destination address, and the address offset of the source address under the premise of the corresponding relationship indicated by the first indication information. Optionally, the first parameter calculation rule is also used to indicate the value-taking rule of the number of whole blocks in the SIMD instruction under the premise of the corresponding relationship indicated by the first indication information. In the whole block and tail block technology, the problem of non-divisibility is solved by the tail block in the SIMD instruction. If there is non-divisibility, the number of tail blocks is 1, and if there is no non-divisibility problem, the number of tail blocks is 0, so there is no value-taking rule for the number of tail blocks.

[0111] Furthermore, in one case, if the target type SIMD instruction does not use the whole block and tail block technology, the number of whole blocks defaults to 1, and the number of tail blocks defaults to 0. Combining equations (1), (3) and Table 1, let stride i,k =dstStride i,k , (i=0,1,...,I-1) and stride j+I,k =srcStride j,k , (j=0, 1, ..., J-1), that is, [stride l,k ], (l = 0, 1, ..., I + J-1) is used to represent all the offset (stride) parameters. (i=0, 1,...,I-1) and (j=0, 1, ..., J-1), that is (l = 0, 1, ..., I + J-1) is used to represent the coordinate linearization coefficients of all tensors and ensures that stride l,k and The variables l in are one-to-one corresponding. The following table shows the first parameter calculation rule.

[0112] Table 2

[0113]

[0114] Refer to Table 2 above. Since the meanings of all the letters in Table 2 have been introduced in formula (1), formula (3) and Table 1, they will not be repeated here. k A loop dimension x in the tensor computation that represents the type of the target operation k , then the first parameter calculation rule can be expressed as the row where the value of N in Table 2 is 1. If K repeats are performed k represents K′ loop dimensions, where K′ is an integer greater than 1 and less than K. k There are K′ cyclic dimensions. The corresponding relationship mentioned above The sth kind of corresponding relationship In the corresponding relationship, the first parameter calculation rule can be expressed as the row where the value of N in Table 2 is K′. k The K loop dimensions x in the tensor computation used to represent the target operation type k , that is, each dimension of the SIMD instruction is repeated k A loop dimension x in the tensor calculation formula used to represent the target operation type k , then the first parameter calculation rule can be expressed as the row where the value of N in the above Table 2 is K. It should be understood that the example in Table 2 is only for the convenience of understanding the concept of the first parameter calculation rule and is not used to limit this solution.

[0115] In another case, the whole block and tail block technology is used in the SIMD instruction of the target type, and the length of the first loop dimension and the value constraint of the first parameter corresponding to the first loop dimension determine that there is a non-divisible situation, and it is necessary to solve the non-divisible problem by setting the tail block in the whole block and tail block technology. Among them, the first loop dimension is any dimension of the N loop dimensions of the tensor calculation formula. Regarding the meaning of the value range of the corresponding first parameter that the length of the first loop dimension is not evenly divided, one or more first parameters in the SIMD instruction are used to implement the calculation of a first loop dimension, and the aforementioned one or more first parameters include a fifth parameter and a sixth parameter, and the fifth parameter is sorted in the aforementioned one or more first parameters. The sorting position of the fifth parameter in the aforementioned one or more first parameters is higher than the sorting position of the fifth parameter in the aforementioned one or more first parameters, then the length of the first loop dimension is not evenly divided by the value range of the corresponding first parameter refers to the length of the first loop dimension is not evenly divided by the value range of the fifth parameter, or the length of the first loop dimension is not evenly divided by the product of the values ​​of the fifth parameter and the sixth parameter. As an example, for example, a SIMD instruction of the target type is used to implement the operation of two loop dimensions (that is, the value of N is 2) of the tensor calculation formula, the first loop dimension is the first loop dimension of the two loop dimensions, the length of the first loop dimension is E0, and the first parameter corresponding to the first loop dimension includes repeat o , repeat1 and repeat2, according to the calculation rules in Table 2 above, we know that we need to use repeat0 and repeat1 in repeat0, repeat1 and repeat2 to represent the first loop dimension of the tensor calculation formula. Then the length of the first loop dimension and the value constraint of the first parameter corresponding to the first loop dimension determine that there is no integer divisibility, which means that the product of E2 and repeat0 and repeat1 is not divisible. As an example, in combination with the above example, if the product of E2 and repeat0 and repeat1 is not divisible, it can be solved by setting a tail block. and Multiply and E2 is represented by addition, that is, the setting of the tail block in the whole block and tail block technology solves the problem of non-divisibility by addition. It should be understood that the above examples are only for the convenience of understanding this solution and are not used to limit this solution. Correspondingly, the first parameter calculation rule can also include the following Table 3 in addition to Table 2. Table 3 is used to adjust some parameter values ​​obtained by Table 2. The parameter calculation rule shown in Table 3 is used to generate the parameter values ​​of the whole block part and the parameter values ​​of the tail block part of the SIMD instruction. Please refer to the following Table 3. Table 3 combines the above formula (1), formula (3), formula (5), formula (6), Table 1 and Table 2 to give examples of the explanations of the meanings of various letters.

[0116] Table 3

[0117]

[0118] Since the meanings of the letters in Table 3 have been introduced in Formula (1), Formula (3), Formula (5), Formula (6), Table 1 and Table 2, they are not repeated here.

[0119] In another case, if the whole block and tail block techniques are used in the target type's SIMD instructions, the third parameter places an upper limit on the number of whole blocks in the target type's SIMD instructions. When the length of the second loop dimension of the tensor calculation formula exceeds the upper limit of the product of the Nth whole block, the whole block and tail block technologies are simultaneously used to expand the upper limit of the value of the Nth whole block corresponding to the second loop dimension, and, in the case of the non-divisibility problem between the length of the first loop dimension and the value constraint of the first parameter corresponding to the first loop dimension, the first parameter calculation rule may include Table 4 in addition to Table 2. Table 4 is used to adjust some parameter values ​​obtained by Table 2. The parameter calculation rule shown in Table 4 is used to generate parameter values ​​of the whole block part and the tail block part of the SIMD instruction. Please refer to Table 4 below. Table 4 combines the explanations of the meanings of various letters in the above formulas (1), (3), (5), (6), Table 1 and Table 2 to give examples.

[0120] Table 4

[0121]

[0122] Since the meanings of the letters in Table 4 have been introduced in Formula (1), Formula (3), Formula (5), Formula (6), Table 1 and Table 2, they are not repeated here.

[0123] 304. The SIMD instruction processing device obtains a cost function corresponding to the first SIMD instruction model.

[0124] In some embodiments of the present application, the SIMD instruction processing device will obtain a cost function corresponding to the information of the first SIMD instruction model. The cost function is used to use the cost function to filter out the optimal SIMD instruction in the SIMD instruction conversion operation of the tensor calculation formula of the target operation type executed by the SIMD instruction generation device. Corresponding to the cost function can be one or more optimization objectives (i.e., the dependent variable of the cost function), the aforementioned optimization objectives include but are not limited to the minimum total number of SIMD instruction executions, the maximum total number of SIMD instruction executions, the minimum number of whole blocks and tail blocks in SIMD instructions, the maximum number of whole blocks and tail blocks in SIMD instructions, the maximum interval between whole blocks and tail blocks in SIMD instructions, the minimum interval between whole blocks and tail blocks in SIMD instructions, the minimum SIMD instruction scheduling delay, the maximum SIMD instruction scheduling delay, the minimum total execution time of SIMD instructions, the maximum computational overhead of address offsets in SIMD instructions, the minimum computational overhead of address offsets in SIMD instructions, the maximum value of the first parameter of one or several dimensions among the K first parameters of SIMD instructions, the minimum value of the first parameter of several dimensions among the K first parameters of SIMD instructions, dstStride i,k The parameter value is the smallest when i takes a certain value or several values, dstStride i,k The parameter value is the largest when i takes a certain value or several values, srcStride j,k The minimum value of the parameter and / or srcStride when j takes a certain value or several values j,k The parameter value is the maximum when the parameter j takes a certain value or several values, etc. It should be understood that the above examples of optimization targets are for the convenience of understanding this solution. In actual situations, there may be other types of optimization targets. The determination of specific optimization targets can be determined in combination with factors such as the hardware performance of the chip. In the embodiments of the present application, various situations of optimization targets are provided to expand the application scenarios of this solution.

[0125] The independent variables of the cost function include at least one of the following: the parameter value of the first parameter in the first SIMD instruction, the number of whole blocks in the first SIMD instruction, the number of tail blocks in the first SIMD instruction, the number of calculations of the address offset in the first SIMD instruction, the duration of executing a SIMD instruction, the duration of switching from the process of executing a first SIMD instruction to the process of executing another first SIMD instruction, and the duration of the chip executing different repeat parameters in the SIMD instruction. Further, the parameter value of the first parameter in the SIMD instruction may include the parameter value of the first parameter of the whole block part of the SIMD instruction and the parameter value of the first parameter of the tail block part of the SIMD instruction, and the number of whole blocks in the SIMD instruction may include the number of each type of whole blocks in the N types of whole blocks of the whole block part of the SIMD instruction. In the embodiment of the present application, a cost function is generated in advance to assist in selecting the optimal SIMD instruction in the SIMD instruction conversion stage of the tensor calculation formula of the target operation type. The cost function is generated based on the optimization target and can meet the user's SIMD instruction optimization requirements; the SIMD instruction cost function takes into account both the SIMD instruction parameters and the hardware parameters of the chip, so that the generated optimal SIMD instruction can give full play to the performance of the chip.

[0126] Specifically, in one implementation, step 304 may include: the SIMD instruction processing device may receive a cost function corresponding to the information of the first SIMD instruction model input by a technician in the field. That is, after knowing the user's optimization goal, the technician in the field may manually generate a cost function corresponding to the information of the first SIMD instruction model, and then input it into the SIMD instruction processing device. Furthermore, a cost function input box may be provided on the display interface of the SIMD instruction processing device to receive the cost function input by the user through the input box; the SIMD instruction processing device may also receive a file including a cost function, which includes but is not limited to a text document, a table, and a coding file.

[0127] In another implementation, step 304 may include: the SIMD instruction processing device may receive an optimization target input by a person skilled in the art, and generate a cost function corresponding to the information of the first SIMD instruction model according to the optimization target and the SIMD instruction model of the target type. The specific implementation of the SIMD instruction processing device receiving the optimization target is similar to the specific implementation of the SIMD instruction processing device receiving the cost function, which will not be described in detail here.

[0128] It should be noted that the execution order of step 303 and step 304 is not limited in the embodiment of the present application. Step 303 may be executed first, and then step 304; or step 304 may be executed first, and then step 303.

[0129] 305. The SIMD instruction processing device outputs information of the first SIMD instruction model.

[0130] In the embodiment of the present application, since the chip may include one or more types of SIMD instructions, the SIMD instruction processing device executes steps 301 to 304 once to generate information of a first SIMD instruction model corresponding to a type of SIMD instruction (that is, a set of SIMD instruction models), a first parameter calculation rule and a cost function. The SIMD instruction processing device executes steps 301 to 304 once for each of the one or more types of SIMD instructions of the chip, and then obtains information of one or more first SIMD instruction models corresponding to the one or more types of SIMD instructions, a first parameter calculation rule and a cost function, and then performs an output operation.

[0131] Specifically, steps 303 and 304 are optional steps. If steps 303 and 304 are performed, step 305 may include: the SIMD instruction processing device outputs the first indication information, the first constraint condition, the first parameter calculation rule and the cost function. If only step 304 is performed and step 303 is not performed, step 305 may include: the SIMD instruction processing device outputs the first indication information, the first constraint condition and the cost function. If only step 303 is performed and step 304 is not performed, step 305 may include: the SIMD instruction processing device outputs the first indication information, the first constraint condition and the first parameter calculation rule.

[0132] More specifically, for the output mode of the information of the first SIMD instruction model, the first parameter calculation rule and / or the cost function, the SIMD instruction processing device can directly display the information of the first SIMD instruction model, the first parameter calculation rule and / or the cost function in the display interface, and then the technicians in this field configure the information of the first SIMD instruction model, the first parameter calculation rule and / or the cost function in the SIMD instruction generation device. The SIMD instruction processing device can also package the information of the first SIMD instruction model, the first parameter calculation rule and / or the cost function into a file and output the file, and then the technicians in this field configure the information of the first SIMD instruction model, the first parameter calculation rule and / or the cost function in the SIMD instruction generation device. The SIMD instruction processing device can also directly send the information of the first SIMD instruction model, the first parameter calculation rule and / or the cost function to the SIMD instruction generation device through a wireless network or a wired network, etc., and the output mode of the SIMD instruction processing device is not limited at this time.

[0133] In an embodiment of the present application, a set of information about a SIMD instruction model generated corresponding to a chip is used to indicate a SIMD instruction conversion operation for executing a tensor calculation formula; in addition, a plurality of sets of information about a first SIMD instruction model are generated in advance, and during the conversion process, a matching combination is selected from a number of combinations based on the lengths of the N loop dimensions of the tensor calculation formula, thereby greatly reducing the difficulty of the SIMD instruction generation process and improving the efficiency of automatically generating SIMD instructions.

[0134] 2. Conversion stage of tensor calculation formula

[0135] In the present application, please refer to Figure 5 , Figure 5 A flow chart of a method for generating a SIMD instruction provided in an embodiment of the present application is provided. The method for processing a single instruction multiple data SIMD instruction provided in an embodiment of the present application may include:

[0136] 501. A SIMD instruction generation device obtains the length of each loop dimension of a first tensor calculation formula.

[0137] In the embodiment of the present application, during the conversion process from tensor calculation formula to SIMD instruction, after obtaining the first tensor calculation formula, the SIMD instruction generation device can obtain the lengths of the H loop dimensions of the first tensor calculation formula. The first tensor calculation formula includes a total of H loop dimensions. For the concepts of tensor calculation formula, loop dimensions, and the length of the loop dimensions of the tensor calculation formula, please refer to the above Figure 3 The description of step 201 in the corresponding embodiment will not be repeated here.

[0138] 502. The SIMD instruction generation device obtains the number of destination addresses in the first tensor calculation formula and the number of source addresses in the first tensor calculation formula.

[0139] In some embodiments of the present application, after obtaining the first tensor calculation formula, the SIMD instruction generation device can also obtain the number of destination addresses of the first tensor calculation formula and the number of source addresses in the first tensor calculation formula. For the concept of the number of destination addresses of the first tensor calculation formula and the concept of the number of source addresses in the first tensor calculation formula, please refer to the above Figure 3 The description of step 201 in the corresponding embodiment will not be repeated here.

[0140] 503. The SIMD instruction generation device obtains the operation type of the first tensor calculation formula.

[0141] In some embodiments of the present application, after obtaining the first tensor calculation formula, the SIMD instruction generation device can also obtain the operation type of the first tensor calculation formula of the first tensor calculation formula. For the concept of the operation type of the first tensor calculation formula of the first tensor calculation formula, refer to the above Figure 3 The description of step 201 in the corresponding embodiment will not be repeated here.

[0142] It should be noted that the execution order of step 501, step 502 and step 503 is not limited in the embodiment of the present application. Steps 501, 502 and 503 can be executed simultaneously, or they can be arranged in any order.

[0143] 504. The SIMD instruction generation device obtains information of multiple groups of first SIMD instruction models.

[0144] In the embodiment of the present application, step 503 is an optional step. If step 503 is executed, step 504 may include: the SIMD instruction generation device obtains multiple groups of information of the first SIMD instruction model from the information set of the SIMD instruction model. Specifically, the SIMD instruction generation device may be pre-configured with an information set of the SIMD instruction model, and the information set of the SIMD instruction model may include at least one information subset of the SIMD instruction model, each information subset of the SIMD instruction model corresponds to a tensor calculation formula of an operation type, and different information subsets of SIMD instruction models correspond to tensor calculation formulas of different operation types. The information subset of the SIMD instruction model to which the information of at least one group of the first SIMD instruction model belongs corresponds to the operation type of the first tensor calculation formula. After obtaining the operation type of the first tensor calculation formula, the SIMD instruction generation device can obtain the information of the first SIMD instruction model that matches the operation type of the first tensor calculation formula from the information set of the SIMD instruction model. Among them, the operation type of the first tensor calculation formula can be addition, multiplication or other operation types, etc. In an embodiment of the present application, the information of the first SIMD instruction model is generated for a tensor calculation formula of a specific operation type, that is, the information of the SIMD instruction model corresponding to the tensor calculation formulas of different operation types is different, so that the information of the first SIMD instruction model is more closely aligned with the tensor calculation formula of the operation type of the first tensor calculation formula, and is conducive to improving the efficiency of the SIMD instruction generation process.

[0145] If step 503 is not performed, the embodiment of the present application does not limit the execution order between steps 501 and 502 and step 504, and steps 501 and 502 may be performed first, and then step 504; or step 504 may be performed first, and then steps 501 and 502. Step 504 may include: the SIMD instruction generation device obtains multiple groups of first SIMD instruction model information from the storage medium, and determines the information of all first SIMD instruction models in the multiple groups of first SIMD instruction model information as the first SIMD instruction model information.

[0146] 505. The SIMD instruction generation device determines whether the number of destination addresses in the first tensor calculation formula is the same as the number of destination addresses in the first SIMD instruction model, and whether the number of source addresses in the first tensor calculation formula is the same as the number of source addresses in the first SIMD instruction model. If they are not the same, the process proceeds to step 506; if they are the same, the process proceeds to step 507.

[0147] In some embodiments of the present application, the information of the first SIMD instruction model may further include a second constraint, and the second constraint is used to indicate the number of destination addresses in the tensor calculation formula that matches the information of the first SIMD instruction model and the number of source addresses in the tensor calculation formula that matches the information of the first SIMD instruction model. After the SIMD instruction generation device obtains the number of destination addresses and the number of source addresses in the first tensor calculation formula through step 502, and obtains the second constraint from the information of the first SIMD instruction model, it can perform a judgment operation.

[0148] 506. The SIMD instruction generation device outputs warning information.

[0149] In some embodiments of the present application, when the number of destination addresses in the first tensor calculation formula is different from the number of destination addresses in the first SIMD instruction model, or when the number of source addresses in the first tensor calculation formula is different from the number of source addresses in the first SIMD instruction model, the SIMD instruction generation device outputs an alarm message; the aforementioned alarm message is used to inform the user that the SIMD instruction automatic conversion process has failed. Specifically, the aforementioned alarm message can be output in the form of a text box; it can also be output in the form of voice, or it can be output in the form of a flashing signal light, etc., and the output method of the alarm message is not limited at this time.

[0150] 507. The SIMD instruction generation device selects information of a second SIMD instruction model from multiple groups of information of first SIMD instruction models.

[0151] In the embodiment of the present application, steps 502, 505 and 506 are all optional steps. If step 502 is not performed, steps 505 and 506 do not need to be performed, and step 507 can be performed directly after step 504 is performed. If step 502 is performed, steps 505 and 506 need to be performed, and step 507 may include: the SIMD instruction generation device selects information of a second SIMD instruction model that matches the first tensor calculation formula according to the lengths of the H loop dimensions of the first tensor calculation formula, when the number of destination addresses in the first tensor calculation formula and the number of source addresses in the first tensor calculation formula meet the constraints of the second constraint condition. In an embodiment of the present application, during the execution of the SIMD instruction automatic conversion operation, it will first be determined whether the number of destination addresses and the number of source addresses in the first tensor calculation formula meet the requirements for the number of destination addresses and the number of source addresses in the SIMD instruction model. Only when the constraints are met will the subsequent SIMD instruction model matching operation be executed. If not, an alarm message will be output in a timely manner to improve the efficiency of the SIMD instruction automatic conversion process.

[0152] For details, see Figure 3 As described in step 202 in the corresponding embodiment, the information of the first SIMD instruction model includes multiple groups of information of the first SIMD instruction model, and the information of each group of SIMD instruction models includes first indication information and first constraints. The first constraints are used to indicate the constraints of the lengths of N loop dimensions of the tensor calculation formula that matches the information of the first SIMD instruction model under the premise of the corresponding relationship indicated by the first indication information, and N is an integer greater than or equal to 1 and less than or equal to H. After obtaining the information of the first SIMD instruction model, the SIMD instruction generation device obtains multiple first constraints therefrom. For specific presentation forms, please refer to Table 1 above. After obtaining the lengths of the H loop dimensions, the lengths of the H loop dimensions are matched with the multiple first constraints, so that at least one first constraint matching the first tensor calculation formula can be obtained. As an example, for example, E0 is obtained from the lengths of the H loop dimensions, and it is determined whether E0 satisfies As another example, if the value of N is K′, then k is any integer from 0 to K′-1, and the lengths of H cyclic dimensions are distributed to obtain E0, E1, ... to E K′ , and then judge E0, E1... to E K′Whether the corresponding first constraint condition is satisfied, no other examples are given this time. After selecting at least one first constraint condition matching the first tensor calculation formula from the information of the first SIMD instruction model according to the length of the H loop dimensions, at least one first indication information corresponding to the at least one first constraint condition matching is obtained, that is, the information of the second SIMD instruction model matching the first tensor calculation formula is selected, and the information of the second SIMD instruction model includes at least one set of information of the first SIMD instruction model.

[0153] More specifically, in one implementation, at least one set of information of the first SIMD instruction model includes information of the third SIMD instruction model, information of the fourth SIMD instruction model, and information of the fifth SIMD instruction model, the value of N corresponding to the information of the third SIMD instruction model is less than the value of N corresponding to the information of the fourth SIMD instruction model, the value of N corresponding to the information of the fourth SIMD instruction model is less than the value of N corresponding to the information of the fifth SIMD instruction model, and the N corresponding to the information of the fourth SIMD instruction model is greater than or equal to 2. Step 507 may include: the SIMD instruction generation device selects the information of the second SIMD instruction model from the information of the third SIMD instruction model; if the information of the second SIMD instruction model does not exist in the information of the fourth SIMD instruction model, the selection of the information of the second SIMD instruction model from the information of the fifth SIMD instruction model is terminated. Further, the SIMD instruction generation device first performs the selection operation of the information of the second SIMD instruction model on the information of the third SIMD instruction model, and then performs the selection operation of the information of the second SIMD instruction model on the information of the fourth SIMD instruction model. In the embodiment of the present application, if there is no matching model in the low-dimensional model, there is no need to match the high-dimensional model, which can effectively reduce the number of matches and further improve the generation efficiency of SIMD instructions.

[0154] In another implementation, the SIMD instruction generation device may adopt a random matching method to match each first constraint condition in multiple first constraints according to the lengths of H loop dimensions to obtain at least one first constraint condition that matches the first tensor calculation formula.

[0155] 508. The SIMD instruction generation device obtains a second SIMD instruction model corresponding to the information of the second SIMD instruction model.

[0156] In the embodiment of the present application, after the SIMD instruction generation device obtains the information of the second SIMD instruction model, since the information of the second SIMD instruction model includes at least one group of information of the first SIMD instruction model, each group of information of the first SIMD instruction model corresponds to a first SIMD instruction model. Then the SIMD instruction generation device obtains the second SIMD instruction model corresponding to the information of the second SIMD instruction model, wherein the second SIMD instruction model includes at least one first SIMD instruction model. Specifically, in one implementation, the information of the first SIMD instruction model may not include the first SIMD instruction model, and the SIMD instruction generation device generates the second SIMD instruction model according to the instruction format of the SIMD instruction of the target type of the chip and at least one first indication information included in the information of the second SIMD instruction model. In another implementation, the information of each group of the first SIMD instruction model also includes the first SIMD instruction model, then after the information of the second SIMD instruction model is obtained, at least one first SIMD instruction model is obtained from the information of at least one group of the first SIMD instruction model included in the information of the second SIMD instruction model, and all the obtained first SIMD instruction models are determined as the second SIMD instruction model.

[0157] 509. The SIMD instruction generating device generates parameter values ​​of a second SIMD instruction model.

[0158] In an embodiment of the present application, the SIMD instruction generation device can generate parameter values ​​for the second SIMD instruction model based on the lengths of the N loop dimensions of the first tensor calculation formula, the first indication information included in the information of the second SIMD instruction model, the first constraint condition included in the information of the second SIMD instruction model, and the coordinate linearization coefficient of the first tensor calculation formula. The parameter values ​​generated above include the parameter values ​​of the K first parameters, the parameter value of the destination address offset, and the parameter value of the source address offset. Optionally, the parameter values ​​generated above may also include the number of whole blocks and the number of tail blocks.

[0159] Specifically, the SIMD instruction generation device may be pre-configured with a first parameter calculation rule, so that after obtaining the length of the N loop dimensions of the first tensor calculation formula, the coordinate linearization coefficient of the first tensor calculation formula, and the second SIMD instruction model, the SIMD instruction generation device generates the model parameters of each SIMD instruction model included in the second SIMD instruction model according to the pre-configured first parameter calculation rule. The SIMD instruction generation device may also generate the first parameter calculation rule after obtaining the length of the N loop dimensions of the first tensor calculation formula, the coordinate linearization coefficient of the first tensor calculation formula, and the second SIMD instruction model, and then generate the model parameters of each SIMD instruction model included in the second SIMD instruction model according to the generated first parameter calculation rule.

[0160] More specifically, in one case, the target type SIMD instruction does not use the whole block and tail block technology, then the specific expression of the first parameter calculation rule can refer to the above Figure 3 Corresponding to Table 2 in the embodiment, the SIMD instruction generation device brings the acquired lengths of the N loop dimensions of the first tensor calculation formula and the coordinate linearization coefficient of the first tensor calculation formula into the parameter calculation rules shown in the above Table 2, thereby respectively obtaining the model parameters of each SIMD instruction model included in the second SIMD instruction model.

[0161] In another case, the whole block and tail block technology is used in the SIMD instruction of the target type, and step 509 may include: the SIMD instruction generation device obtains the first parameter corresponding to the first loop dimension of the first tensor calculation formula according to the first indication information in the information of the second SIMD instruction model, wherein the first loop dimension is a loop dimension of at least one loop dimension, and the length of the first loop dimension is not an integer division of the corresponding first parameter value range. The SIMD instruction generation device generates the parameter value of the whole block part of the first SIMD instruction and the parameter value of the tail block part of the first SIMD instruction based on the length of the first loop dimension. Since the length of the first loop dimension and the value constraints of the first parameter corresponding to the first loop dimension determine that there is a concept of non-divisibility, and the method of solving the non-divisibility by setting the tail block has been already described. Figure 3 In the embodiment of the present application, the technology of whole block and tail block is used to solve the problem of non-divisibility between the loop dimension and the first parameter, which expands the applicable situations of the solution and expands the applicable scope of the solution.

[0162] Specifically, for the parameter value generation process of any SIMD instruction model in the second SIMD instruction model, the SIMD instruction generation device can first perform a model parameter generation operation of the SIMD instruction model through the parameter calculation rules shown in Table 2. During the generation process, it can be determined whether the length of the first loop dimension and the value constraint of the first parameter corresponding to the first loop dimension have a problem of non-divisibility. If there is a problem of non-divisibility, the SIMD instruction generation device sets the tail block part of the SIMD again, adjusts some parameter values ​​of the whole block part of the SIMD instruction through the parameter calculation rules shown in Table 3, and generates parameter values ​​of the tail block part of the SIMD instruction.

[0163] In another case, the whole block and tail block technology is used in the SIMD instruction of the target type, and step 509 may include: the SIMD instruction generation device obtains the first parameter corresponding to the second loop dimension of the first tensor calculation formula according to the first indication information in the information of the second SIMD instruction model, wherein the second loop dimension is a loop dimension with the highest dimension in at least one loop dimension, and the length of the second loop dimension exceeds the upper limit of the corresponding first parameter. The SIMD instruction generation device generates the parameter value of the whole block part of the first SIMD instruction based on the length of the second loop dimension. In the embodiment of the present application, the whole block and tail block technology is used to solve the problem that the length of the Nth loop dimension is greater than the upper limit of the value of the first parameter corresponding to the second loop dimension, further expanding the applicable situations of the present solution and further expanding the applicable scope of the present solution.

[0164] Specifically, for the parameter value generation process of any SIMD instruction model in the second SIMD instruction model, the SIMD instruction generation device can first perform a model parameter generation operation of the SIMD instruction model through the parameter calculation rules shown in Table 2. During the generation process, it can be determined whether the length of the Nth loop dimension is greater than the upper limit of the value of the first parameter corresponding to the second loop dimension. When it is determined that the value exceeds the upper limit, the partial parameter values ​​of the entire block of the SIMD instruction are adjusted through the parameter calculation rules shown in Table 4.

[0165] In another case, the whole block and tail block technology is used in the SIMD instruction of the target type, and step 509 may include: the SIMD instruction generation device obtains the value constraint of the first parameter corresponding to the first loop dimension of the first tensor calculation formula according to the first indication information included in the information of the second SIMD instruction model. When the length of the Nth loop dimension is greater than the upper limit of the value of the first parameter corresponding to the second loop dimension and it is determined that there is non-divisibility according to the length of the first loop dimension and the value constraint of the first parameter corresponding to the first loop dimension, the parameter value of the whole block part of the target SIMD instruction and the parameter value of the tail block part of the target SIMD instruction are generated.

[0166] Specifically, for the parameter value generation process of any SIMD instruction model in the second SIMD instruction model, the SIMD instruction generation device can first perform a model parameter generation operation of the SIMD instruction model through the parameter calculation rules shown in Table 2. During the generation process, it can be determined whether the length of the Nth loop dimension is greater than the upper limit of the value of the first parameter corresponding to the second loop dimension, and whether the length of the first loop dimension and the value constraint of the first parameter corresponding to the first loop dimension are not divisible. In the case of determining that there is a problem of exceeding the upper limit of the value and there is a problem of not divisible, the parameter values ​​of the whole block part of the SIMD instruction are adjusted through the parameter calculation rules shown in Table 4, and the parameter values ​​of the tail block part of the SIMD instruction are generated.

[0167] 510. The SIMD instruction generation device substitutes the parameter value into the second SIMD instruction model to obtain a first SIMD instruction.

[0168] In an embodiment of the present application, the SIMD instruction generation device substitutes the parameter values ​​into each second SIMD instruction model included in at least one second SIMD instruction model to obtain one or more first SIMD instructions, and the number of SIMD instructions in the first SIMD instruction is consistent with the number of second SIMD instruction models.

[0169] 511. A SIMD instruction generating apparatus obtains a cost function corresponding to a first SIMD instruction, and generates a function value of the cost function for each group of target SIMD instructions in the first SIMD instruction.

[0170] In an embodiment of the present application, a SIMD instruction generation device may be pre-configured with a plurality of cost functions corresponding to the various types of SIMD instructions of the chip, and obtain a cost function corresponding to the first SIMD instruction of the chip, that is, obtain a cost function corresponding to the target type of SIMD instruction of the chip, wherein the cost function indicates an optimization target related to the first SIMD instruction. The SIMD instruction generation device generates a function value of the cost function for each first SIMD instruction in one or more first SIMD instructions based on the parameter value of the target SIMD instruction and the hardware performance parameters of the chip. Optionally, the function value of the cost function for each first SIMD instruction in multiple first SIMD instructions may be generated only when multiple first SIMD instructions are obtained through step 510. For a detailed introduction to the cost function, please refer to the above Figure 3 The step 204 in the corresponding embodiment will not be described in detail here.

[0171] 512. The SIMD instruction generation device selects a SIMD instruction that meets the optimization target in the first SIMD instructions, and uses it as the first SIMD instruction after the first tensor calculation formula is converted.

[0172] In the embodiment of the present application, after obtaining the function value of the cost function of each first SIMD instruction in one or more first SIMD instructions, the SIMD instruction generation device selects the SIMD instruction with the largest function value from the one or more first SIMD instructions, and uses it as the first SIMD instruction after the first tensor calculation formula is converted, or selects the SIMD instruction with the smallest function value from the one or more first SIMD instructions, and uses it as the first SIMD instruction after the first tensor calculation formula is converted. In the embodiment of the present application, the cost function is used to select the optimal SIMD instruction, which is conducive to improving the performance of the SIMD instruction execution process.

[0173] In an embodiment of the present application, a specific implementation scheme for converting a first tensor calculation formula into a SIMD instruction is implemented; multiple groups of first SIMD instruction model information are generated in advance, and during the conversion process, a matching second SIMD instruction model is selected from the multiple groups of first SIMD instruction model information based on the length of each loop dimension of the tensor calculation formula, thereby greatly improving the efficiency of the SIMD instruction generation process.

[0174] To further understand this program, please participate Figure 6 , Figure 6 A flowchart of a method for processing SIMD instructions provided in an embodiment of the present application is provided. Figure 6 In this example, the target chip is V chip. The optimization goal proposed by the user is to minimize the total time for V chip to execute SIMD instructions. The number of whole blocks of SIMD instructions cannot exceed 5, and the number of tail blocks cannot exceed 1. The input tensor calculation formula is as follows:

[0175]

[0176]

[0177] Subject to the above conditions, the SIMD instruction processing method provided in the embodiment of the present application may include:

[0178] 601. A SIMD instruction processing apparatus obtains a first parameter value, a second parameter value, a third parameter value, and a fourth parameter value of a target type of SIMD instruction in a V chip.

[0179] In this embodiment, referring to the above formula (7), it can be known that the target type of SIMD instruction is used to implement the tensor calculation formula with the operation type of addition. A person skilled in the art can refer to the ISA of the V chip and obtain that the target type of SIMD instruction device format for implementing the tensor calculation formula with the operation type of addition in the V chip is:

[0180] V_SIMD_OP(dst0,src0,src1,repeat1,repeat2,dstStride 0,1 , srcStride 0,1 , srcStride 1,1 ,dstStride 0,2 ,srcStride 0,2 ,srcStride 1,2 ); (8)

[0181] Those skilled in the art know that the first parameter value (ie, K) is 3, and the second parameter value includes R0, R1, and R2. The value of R0 is 16, the value of R1 is 8, and the value of R2 is 4. Due to the hardware performance requirements of the V chip, repeat0 is fixed to 16, and dstStride i,0 and srcStride j,0 The first parameter value, the second parameter value, the third parameter value, the fourth parameter value, and repeat0, dstStride, and dstStride are all fixed to 1, the upper limit of the number of whole blocks included in the third parameter value is 5, the number of destination addresses (i.e., I) included in the fourth parameter value is 1, and the number of source addresses (i.e., J) included in the fourth parameter value is 2. After knowing the above information, those skilled in the art can display the first parameter value, the second parameter value, the third parameter value, the fourth parameter value, and repeat0, dstStride, and dstStride through the display interface of the SIMD instruction device. i,0 and srcStride j,0 The value constraint is input into the SIMD instruction device, and correspondingly, the SIMD instruction device obtains the aforementioned information.

[0182] 602. The SIMD instruction processing device generates information of a first SIMD instruction model.

[0183] In this embodiment, after the SIMD instruction device learns that there are three first parameters in the SIMD instruction device, it can generate information of a first SIMD instruction model, wherein the information of the first SIMD instruction model includes four groups of information of the first SIMD instruction model, and each group of information of the SIMD instruction model includes a first indication information and a first constraint condition.

[0184] Specifically, the four first indication information are: (1) if the target type of SIMD instruction is used to implement a loop dimension of a tensor calculation formula, the three first parameters together correspond to a loop dimension of the tensor calculation formula; (2) if the target type of SIMD instruction is used to implement two loop dimensions of a tensor calculation formula, the first two first parameters of the three first parameters may correspond to a loop dimension of the tensor calculation formula, and the last first parameter may correspond to a loop dimension of the tensor calculation formula; (3) if the target type of SIMD instruction is used to implement two loop dimensions of a tensor calculation formula, the first first parameter of the three first parameters may correspond to a loop dimension of the tensor calculation formula, and the last two first parameters may correspond to a loop dimension of the tensor calculation formula; (4) if the target type of SIMD instruction is used to implement three loop dimensions of a tensor calculation formula, the three first parameters may correspond to the three loop dimensions of the tensor calculation formula respectively.

[0185] Correspondingly, the four first indication information correspond to four first constraint conditions respectively. Please refer to the following Table 5. The letters in Table 5 are combined with the above Figure 3 Corresponding to the description in the embodiment.

[0186] Table 5

[0187]

[0188] 603. The SIMD instruction processing device obtains a cost function corresponding to a target type of SIMD instruction in the V chip, and the optimization goal is to minimize the total time for the V chip to execute SIMD instructions.

[0189] In this embodiment, after knowing that the optimization goal set by the user for the V chip is to minimize the total execution time of SIMD instructions, the technical personnel in this field determines the cost function of the target type of SIMD instructions of the V chip when the optimization goal is to minimize the total execution time of SIMD instructions based on the unified model of the cost function of the target type of SIMD instructions of the V chip, and inputs it into the SIMD instruction processing device. Correspondingly, the SIMD instruction processing device receives the cost function corresponding to the target type of SIMD instructions in the V chip input by the technical personnel.

[0190] Combined with the above Figure 3 Corresponding to the definitions of the meanings of various letters in the embodiments, the unified model of the cost function of the target type of SIMD instructions of the V chip can be:

[0191]

[0192] in, represent The number of represent The number of represent The number of represent The number of t represents the switching time consumed by the V chip hardware to process the whole block of SIMD instructions and the tail block of SIMD instructions, c v Indicates the time consumed by the V chip hardware to call a SIMD instruction. Indicates the time consumed by the V chip hardware to execute SIMD instructions with different repeat parameters.

[0193] Combined with the above Figure 3 Corresponding to the definitions of the meanings of various letters in the embodiment, when the optimization goal is to minimize the total execution time of SIMD instructions, the cost function of the target type of SIMD instructions of the V chip can be:

[0194]

[0195] Among them, H represents the number of dimensions of the tensor calculation formula, E l Represents the length of the lth loop dimension in the tensor calculation formula. Since the meanings of other letters in formula (10) have been Figure 3 The corresponding embodiments and formula (9) have been described and will not be repeated here.

[0196] 604. The SIMD generation device obtains the number of destination addresses, the number of source addresses, the lengths of H loop dimensions, and the linear coordinate coefficients of the tensor of the first tensor calculation formula.

[0197] In this embodiment, after obtaining the first tensor calculation formula, the SIMD generation device can analyze and obtain the following parameters based on the first tensor calculation formula:

[0198] E0=16, E1=4, E2=6, E3=4, E4=3, E5=2, (11)

[0199] Tensor C,

[0200] Tensor S0,

[0201] Tensor S1,

[0202] 0P is addition, H = 6 (15)

[0203] The meaning of the above letters can be understood with the help of Figure 3 The description in the corresponding embodiment will not be repeated here.

[0204] 605. The SIMD generation device obtains a second SIMD instruction model that matches the first tensor calculation formula.

[0205] In this embodiment, the SIMD generation device determines whether E0 satisfies the first constraint condition corresponding to the first indication information (1) in Table 5. If the judgment result is satisfied, the SIMD instruction model corresponding to the first indication information (1) is determined as a SIMD instruction model in the second SIMD instruction model. The SIMD generation device determines whether E0 and E1 satisfy the first constraint condition corresponding to the first indication information (2) in Table 5. If the judgment result is satisfied, the SIMD instruction model corresponding to the first indication information (2) is determined as a SIMD instruction model in the second SIMD instruction model. The SIMD generation device determines whether E0 and E1 satisfy the first constraint condition corresponding to the first indication information (3) in Table 5. If the judgment result is satisfied, the SIMD instruction model corresponding to the first indication information (3) is determined as a SIMD instruction model in the second SIMD instruction model. The SIMD generation device determines whether E0, E1 and E2 satisfy the first constraint condition corresponding to the first indication information (4) in Table 5. If the judgment result is satisfied, the SIMD instruction model corresponding to the first indication information (4) is determined as a SIMD instruction model in the second SIMD instruction model. The SIMD generation device obtains four SIMD instruction models matching the first tensor calculation formula by executing the above operations.

[0206] 606. The SIMD generating device generates parameter values ​​of the second SIMD instruction model.

[0207] In this embodiment, the SIMD generation device may be pre-configured with parameter calculation rules. After obtaining the four SIMD instruction models included in the second SIMD instruction model, the lengths of the N loop dimensions of the calculation formula to be processed, and the linear coordinate coefficients in the first tensor calculation formula, the model parameters of the four SIMD instruction models included in the second SIMD instruction model are generated. Please refer to the following Table 6, which shows the parameter calculation rules for the first parameter and the address offset parameter. The meanings of the letters in Table 2 can be combined with the above Figure 3 Please understand the description in the corresponding embodiment and will not elaborate on it this time.

[0208] Table 6

[0209]

[0210] The SIMD generation device substitutes the acquired lengths of the N loop dimensions and the linear coordinate coefficients in the first tensor calculation formula into the above Table 6, and calculates the parameter values ​​of the first parameter and the address offset parameter as follows, please refer to Table 7.

[0211] Table 7

[0212]

[0213] The SIMD generation device discovers in the process of generating the parameter values ​​of the first parameter and the address offset parameter that: in the 3D SIMD instruction model, there is a problem of non-integer divisibility between the third loop dimension of the tensor calculation formula and the first parameter repeat2 corresponding to the second loop dimension of the first tensor calculation formula in the 3D SIMD instruction model, that is, repeat2=E2 cannot be realized in the 3D SIMD instruction model, and it is necessary to solve the problem of non-integer divisibility by setting a tail block in the whole block and tail block technology, and then the parameter values ​​of the whole block part of the 3D SIMD instruction model and the parameter values ​​of the tail block part of the SIMD instruction are generated as follows:

[0214]

[0215]

[0216] 607. The SIMD generating device brings the parameter values ​​of the second SIMD instruction model into the second SIMD instruction model to obtain four first SIMD instructions.

[0217] 608. The SIMD generating device generates function values ​​of cost functions of four first SIMD instructions, and selects a SIMD instruction with a maximum cost function value.

[0218] In this embodiment, the SIMD generation device can obtain the hardware performance parameters of the V chip, that is, c t 、c v and The value of can be automatically obtained by the SIMD generation device. After the SIMD generation device generates parameters of four SIMD instructions matching the first tensor calculation formula through step 606, the corresponding parameters are substituted into formula (10) to obtain the function values ​​of the cost functions of the four SIMD instructions included in the first SIMD instruction. For details, refer to the following Table 8.

[0219] Table 8

[0220]

[0221] In this embodiment, after obtaining the function values ​​of the cost functions of the four SIMD instructions matching the first tensor calculation formula, the SIMD generation device selects the SIMD instruction with the largest cost function value and determines it as the optimal SIMD instruction matching the first tensor calculation formula.

[0222] In order to have a more intuitive understanding of the beneficial effects brought by the embodiments of the present application, the following is combined with Table 9 and the above Figure 6 The corresponding embodiments further introduce the beneficial effects brought by the embodiments of the present application. The beneficial effects of Table 9 are based on the obtained Figure 6The display is based on the premise setting that the first tensor calculation formula in the embodiment matches the target type SIMD instruction. Please refer to the following Table 9.

[0223] Table 9

[0224] Embodiments of the present application Brute force search Number of searches 4 ≥589824(1×16×16×48×48)

[0225] Combined with the above Figure 6 It can be seen from the corresponding embodiments that the method provided in the embodiment of the present application performs a total of 4 search operations in order to obtain the first tensor calculation formula, while the current brute force search method needs to enumerate all parameter value combinations starting from 0. In order to identify a feasible SIMD instruction parameter combination, when the value of N is 1, 589824 search operations need to be performed. Obviously, compared with the current brute force search method, the SIMD instruction processing method provided in the embodiment of the present application greatly improves the efficiency of the SIMD instruction matching process.

[0226] exist Figures 1 to 6 On the basis of the corresponding embodiments, in order to better implement the above solutions of the embodiments of the present application, the following also provides related devices for implementing the above solutions. Figure 7 , Figure 7 A structural schematic diagram of a SIMD instruction generation device provided in an embodiment of the present application, the SIMD instruction generation device 700 includes: an acquisition module 701, a selection module 702 and a generation module 703. Among them, the acquisition module 701 is used to obtain the length of each loop dimension of the first tensor calculation formula; the acquisition module 701 is also used to obtain information of multiple groups of first single instruction multiple data SIMD instruction models, wherein each group of information of the first SIMD instruction model corresponds to at least one loop dimension of a tensor calculation formula, and each group of information of the first SIMD instruction model includes a first constraint condition, and the first constraint condition is used to indicate the constraint condition of the length of each loop dimension in at least one loop dimension; the selection module 702 is used to select the information of the second SIMD instruction model from the information of the multiple groups of first SIMD instruction models according to the first constraint condition and the length of each loop dimension of the first tensor calculation formula, the information of the second instruction model matches the first tensor calculation formula, and the length of the loop dimension of the first tensor calculation formula satisfies the first constraint condition in the information of the second SIMD instruction model; the generation module 703 is used to generate the first SIMD instruction after the first tensor calculation formula is converted according to the length of at least one loop dimension of the first tensor calculation formula and the second SIMD instruction model.

[0227] In an embodiment of the present application, a specific implementation scheme for converting a first tensor calculation formula into a SIMD instruction is implemented; multiple groups of first SIMD instruction model information are generated in advance, and during the conversion process, a matching second SIMD instruction model is selected from the multiple groups of first SIMD instruction model information based on the length of each loop dimension of the tensor calculation formula, thereby greatly improving the efficiency of the SIMD instruction generation process.

[0228] In one possible design, the information of each group of first SIMD instruction models also includes first indication information, where the first indication information is used to indicate the correspondence between K first parameters of a first SIMD instruction model and at least one loop dimension of a tensor calculation formula, where K is an integer greater than or equal to 1, and the first parameter indicates the number of times an operation is repeatedly performed on a data object in a tensor calculation formula.

[0229] In one possible design, at least one loop dimension includes N loop dimensions, and at least one group of information of the first SIMD instruction model includes information of multiple types of SIMD instruction models. The value of N corresponding to the information of different types of SIMD instruction models is different, and N is an integer greater than or equal to 1.

[0230] In an embodiment of the present application, information of at least one group of first SIMD instruction models is classified according to the number of loop dimensions corresponding to the information of the first SIMD instruction model, so as to facilitate the subsequent management of information of different types of first SIMD instruction models and improve management accuracy.

[0231] In a possible design, the first constraint condition is related to the type of chip that executes the converted first SIMD instruction.

[0232] In the embodiment of the present application, the information set of the SIMD instruction model is generated based on a specific chip, and different chips will generate different SIMD instruction model information, which not only expands the application scenarios of this solution, but also improves the fit between the SIMD instruction model and the chip.

[0233] In one possible design, the generation module 703 is specifically used to: generate multiple first SIMD instructions based on the length of at least one loop dimension of the first tensor calculation formula and the second SIMD instruction model; select the SIMD instruction that meets the optimization goal from the multiple first SIMD instructions based on the cost function of each first SIMD instruction in the multiple first SIMD instructions, and use it as the first SIMD instruction after the first tensor calculation formula is converted, wherein the SIMD instruction that meets the optimization goal is the SIMD instruction with the maximum or minimum function value of the cost function, and the cost function indicates the optimization goal related to the first SIMD instruction.

[0234] In an embodiment of the present application, a cost function is pre-generated to assist in selecting the optimal SIMD instruction in the SIMD instruction conversion stage of the tensor calculation formula that executes the target operation type. The cost function is generated based on the optimization target and can meet the user's SIMD instruction optimization needs.

[0235] In one possible design, the optimization objectives indicated by the cost function include at least one of the following: minimum total number of SIMD instruction executions, maximum total number of SIMD instruction executions, minimum number of whole blocks and tail blocks in SIMD instructions, maximum number of whole blocks and tail blocks in SIMD instructions, maximum interval between whole blocks and tail blocks in SIMD instructions, minimum interval between whole blocks and tail blocks in SIMD instructions, minimum SIMD instruction scheduling delay, maximum SIMD instruction scheduling delay, minimum total execution time of SIMD instructions, maximum computational overhead of address offsets in SIMD instructions, and minimum computational overhead of address offsets in SIMD instructions.

[0236] In the embodiments of the present application, multiple scenarios of optimization objectives are provided, which expands the application scenarios of the present solution.

[0237] In one possible design, the independent variables of the cost function include at least one of the following: the parameter value of the first parameter in the first SIMD instruction, the number of whole blocks in the first SIMD instruction, the number of tail blocks in the first SIMD instruction, the number of times the address offset is calculated in the first SIMD instruction, the duration of executing a SIMD instruction, and the duration of switching from the process of executing a first SIMD instruction to the process of executing another first SIMD instruction.

[0238] In the embodiment of the present application, the SIMD instruction cost function takes into account both SIMD instruction parameters and chip hardware parameters, so that the generated optimal SIMD instruction can better exert the performance of the chip.

[0239] In one possible design, the generation module 703 is specifically used to obtain a first parameter corresponding to a first loop dimension of a first tensor calculation formula according to first indication information in the information of a second SIMD instruction model, wherein the first loop dimension is a loop dimension of at least one loop dimension, and the length of the first loop dimension does not divide the value range of the corresponding first parameter; based on the length of the first loop dimension, generate a parameter value of a whole block part of the first SIMD instruction and a parameter value of a tail block part of the first SIMD instruction.

[0240] In the embodiment of the present application, the whole block and tail block technology can be used to solve the problem that the length of the first loop dimension does not divide the value range of the corresponding first parameter, expand the application scenario of the present solution, and thus expand the scope of applicability of the present solution.

[0241] In one possible design, the generation module 703 is specifically used to: obtain a first parameter corresponding to a second loop dimension of the first tensor calculation formula according to first indication information in the information of the second SIMD instruction model, wherein the second loop dimension is a loop dimension with the highest dimension among at least one loop dimension, and the length of the second loop dimension exceeds the upper limit of the value of the corresponding first parameter; based on the length of the second loop dimension, generate a parameter value of the entire block of the first SIMD instruction.

[0242] In the embodiment of the present application, the whole block and tail block technology can be used to expand the value range of the length of the loop dimension in the constraint condition, thereby expanding the applicability of the present solution.

[0243] In one possible design, at least one set of information of the first SIMD instruction model includes information of the third SIMD instruction model, information of the fourth SIMD instruction model, and information of the fifth SIMD instruction model, the value of N corresponding to the information of the third SIMD instruction model is less than the value of N corresponding to the information of the fourth SIMD instruction model, the value of N corresponding to the information of the fourth SIMD instruction model is less than the value of N corresponding to the information of the fifth SIMD instruction model, and the N corresponding to the information of the fourth SIMD instruction model is greater than or equal to 2. The selection module 702 is specifically used to select the information of the second SIMD instruction model from the information of the third SIMD instruction model; if the information of the second SIMD instruction model does not exist in the information of the fourth SIMD instruction model, the selection of the information of the second SIMD instruction model from the information of the fifth SIMD instruction model is terminated.

[0244] In the embodiment of the present application, if there is no matching model in the low-dimensional model, there is no need to match the high-dimensional model, which can effectively reduce the number of matches and further improve the generation efficiency of SIMD instructions.

[0245] In a possible design, the acquisition module 701 is further used to acquire a second constraint condition, where the second constraint condition is used to indicate the number of destination addresses in the first SIMD instruction model and the number of source addresses in the first SIMD instruction model;

[0246] The acquisition module 701 is further used to acquire the number of destination addresses in the first tensor calculation formula and the number of source addresses in the first tensor calculation formula;

[0247] The selection module 702 is specifically used to select at least one group of second SIMD instruction model information from at least one group of first SIMD instruction model information when the number of destination addresses in the first tensor calculation formula is the same as the number of destination addresses in the first SIMD instruction model, and the number of source addresses in the first tensor calculation formula is the same as the number of source addresses in the first SIMD instruction model.

[0248] In an embodiment of the present application, during the execution of the SIMD instruction automatic conversion operation, it will first be determined whether the number of destination addresses and the number of source addresses in the first tensor calculation formula meet the requirements for the number of destination addresses and the number of source addresses in the SIMD instruction model. Only when the constraints are met, the subsequent SIMD instruction model matching operation will be performed to improve the efficiency of the SIMD instruction automatic conversion process; in addition, if it is not met, an alarm message will be output in a timely manner to remind technical personnel to intervene in time.

[0249] In one possible design, the acquisition module 701 is specifically used to obtain at least one group of information of a first SIMD instruction model from an information set of a SIMD instruction model, wherein the information set of the SIMD instruction model includes at least one information subset of the SIMD instruction model, each information subset of the SIMD instruction model corresponds to a tensor calculation formula of an operation type, and the information subset of the SIMD instruction model to which the information of at least one group of the first SIMD instruction model belongs corresponds to the operation type of the first tensor calculation formula.

[0250] In an embodiment of the present application, the information of the first SIMD instruction model is generated for a tensor calculation formula of a specific operation type, that is, the information of the SIMD instruction model corresponding to the tensor calculation formulas of different operation types is different, so that the information of the first SIMD instruction model is more closely aligned with the tensor calculation formula of the operation type of the first tensor calculation formula, and is conducive to improving the efficiency of the SIMD instruction generation process.

[0251] It should be noted that the information interaction, execution process, etc. between the modules / units in the SIMD instruction generation device 700 are the same as those in the present application. Figure 5 and Figure 6 The corresponding method embodiments are based on the same concept. For specific contents, please refer to the description in the method embodiments shown above in this application, which will not be repeated here.

[0252] The present application also provides a SIMD instruction processing device, see Figure 8 , Figure 8A structural schematic diagram of a SIMD instruction processing device provided in an embodiment of the present application, the SIMD instruction processing device 800 includes: an acquisition module 801 and a generation module 802. The acquisition module 801 is used to acquire a first parameter value and a second parameter value corresponding to a first SIMD instruction model, wherein the value of the first parameter value is K, which is used to indicate that the first SIMD instruction model includes K first parameters, K is an integer greater than or equal to 1, and the second parameter value indicates the value constraints of the K first parameters, and the first parameter reflects the number of repetitions of an operation repeatedly performed on a data object in a tensor calculation formula matching the first SIMD instruction model; the generation module 802 is used to generate information of the first SIMD instruction model according to the first parameter value and the second parameter value, wherein the information of a first SIMD instruction model corresponds to a first SIMD instruction model, and the information of the first SIMD instruction model includes a first indication information and a first constraint condition, the first indication information is used to indicate the correspondence between the K first parameters and at least one loop dimension of the tensor calculation formula matching the first SIMD instruction model, and the first constraint condition is used to indicate the constraint condition of the length of each loop dimension in at least one loop dimension.

[0253] In a possible design, the acquisition module 801 is further used to acquire a third parameter value, where the third parameter value indicates the quantity constraint of the entire block in the first SIMD instruction model. The generation module 802 is specifically used to: generate first indication information according to the first parameter value; and generate a first constraint condition according to the first indication information, the second parameter value and the third parameter value.

[0254] In one possible design, the acquisition module 801 is also used to obtain a fourth parameter value, which is used to indicate the number of destination addresses of the first SIMD instruction model and the number of source addresses of the first SIMD instruction model; the generation module 802 is also used to generate a second constraint condition based on the fourth parameter value, and the second constraint condition is used to indicate the number of destination addresses and the number of source addresses in the tensor calculation formula that matches the first SIMD instruction model.

[0255] In one possible design, the acquisition module 801 is also used to obtain a cost function corresponding to the first SIMD instruction model, wherein the cost function is used to screen out SIMD instructions that meet the optimization goal, and the SIMD instructions that meet the optimization goal are SIMD instructions with the largest or smallest function value of the cost function, and the independent variables of the cost function include at least one of the following: the parameter value of the first parameter in the first SIMD instruction, the number of whole blocks in the first SIMD instruction, the number of tail blocks in the first SIMD instruction, the number of times the address offset is calculated in the first SIMD instruction, the duration of executing a SIMD instruction, and the duration of switching from the process of executing a first SIMD instruction to the process of executing another first SIMD instruction.

[0256] It should be noted that the information interaction, execution process, etc. between the modules / units in the SIMD instruction processing device 800 are the same as those in the present application. Figure 3 , Figure 4 and Figure 6 The corresponding method embodiments are based on the same concept. The specific implementation methods and beneficial effects brought about can be found in the description of the method embodiments shown in the previous description of this application, and will not be repeated here.

[0257] Next, an execution device provided by an embodiment of the present application is introduced. Fig. 9 , Fig. 9 A schematic diagram of the structure of an execution device provided in an embodiment of the present application, the execution device 900 can be specifically a desktop computer, a mobile phone, a tablet, a laptop computer, a smart wearable device or a radar data processing device, etc., which is not limited here. Among them, the execution device 900 can be deployed with Figure 3 and Figure 4 The SIMD instruction processing device described in the corresponding embodiment is used to implement Figure 8 The functions of the SIMD instruction processing device 800 in the corresponding embodiment. Alternatively, the execution device 900 may be deployed with Figure 5 The SIMD instruction generating device described in the corresponding embodiment is used to implement Figure 7 The function of the SIMD instruction generation device 700 in the corresponding embodiment. Specifically, the execution device 900 may have relatively large differences due to different configurations or performances, and may include one or more central processing units (CPU) 922 (for example, one or more processors) and a memory 932, and one or more storage media 930 (for example, one or more mass storage devices) storing application programs 942 or data 944. Among them, the memory 932 and the storage medium 930 can be short-term storage or permanent storage. The program stored in the storage medium 930 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the execution device. Furthermore, the central processing unit 922 can be configured to communicate with the storage medium 930 to execute a series of instruction operations in the storage medium 930 on the execution device 900.

[0258] The execution device 900 may also include one or more power supplies 926, one or more wired or wireless network interfaces 950, one or more input and output interfaces 958, and / or one or more operating systems 941, such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, etc.

[0259] In one embodiment of the present application, the central processor 922 is used to implement Figure 7 The function of the SIMD instruction generation device 700 in the corresponding embodiment. Specifically, the central processing unit 922 is used to obtain the length of each loop dimension of the first tensor calculation formula; obtain multiple groups of information of the first single instruction multiple data SIMD instruction model, wherein each group of information of the first SIMD instruction model corresponds to at least one loop dimension of a tensor calculation formula, and each group of information of the first SIMD instruction model includes a first constraint condition, and the first constraint condition is used to indicate the constraint condition of the length of each loop dimension in at least one loop dimension; according to the first constraint condition and the length of each loop dimension of the first tensor calculation formula, select the information of the second SIMD instruction model from the information of the multiple groups of the first SIMD instruction model, the information of the second instruction model matches the first tensor calculation formula, and the length of the loop dimension of the first tensor calculation formula satisfies the first constraint condition in the information of the second SIMD instruction model; according to the length of at least one loop dimension of the first tensor calculation formula and the second SIMD instruction model, generate the first SIMD instruction after the conversion of the first tensor calculation formula.

[0260] It should be noted that the CPU 922 can also be used to execute Figure 7 The specific manner in which the CPU 922 performs the above steps in the corresponding embodiment of the SIMD instruction generation device 700 is the same as that in the present application. Figure 5 The corresponding method embodiments are based on the same concept, and the technical effects they bring are the same as those in this application. Figure 5 The corresponding method embodiments are the same. For specific contents, please refer to the description in the method embodiments shown above in this application, which will not be repeated here.

[0261] In one embodiment of the present application, the central processor 922 is used to implement Figure 7The function of the SIMD instruction generation device 700 in the corresponding embodiment. Specifically, the central processing unit 922 is used to obtain a first parameter value and a second parameter value corresponding to the first SIMD instruction model, wherein the value of the first parameter value is K, which is used to indicate that the first SIMD instruction model includes K first parameters, K is an integer greater than or equal to 1, and the second parameter value indicates the value constraints of the K first parameters, and the first parameter reflects the number of repetitions of an operation repeatedly performed on a data object in a tensor calculation formula matching the first SIMD instruction model; according to the first parameter value and the second parameter value, the information of the first SIMD instruction model is generated, wherein the information of a first SIMD instruction model corresponds to a first SIMD instruction model, and the information of the first SIMD instruction model includes first indication information and first constraint conditions, the first indication information is used to indicate the corresponding relationship between the K first parameters and at least one loop dimension of the tensor calculation formula matching the first SIMD instruction model, and the first constraint condition is used to indicate the constraint condition of the length of each loop dimension in at least one loop dimension.

[0262] It should be noted that the CPU 922 can also be used to execute Figure 8 The specific manner in which the CPU 922 performs the above steps in the corresponding embodiment of the SIMD instruction processing device 800 is the same as that in the present application. Figure 3 and Figure 4 The corresponding method embodiments are based on the same concept, and the technical effects they bring are the same as those in this application. Figure 3 and Figure 4 The corresponding method embodiments are the same. For specific contents, please refer to the description in the method embodiments shown above in this application, which will not be repeated here.

[0263] The present application also provides a computer program product which, when executed on a computer, enables the computer to execute the above Figure 3 and Figure 4 The method described in the embodiment shown in the figure executes the steps executed by the device, or causes the computer to execute the above-mentioned Figure 5 The illustrated embodiment describes the steps performed by the device in the method.

[0264] The present application also provides a computer-readable storage medium in which a program for signal processing is stored. When the program is run on a computer, the computer executes the above-mentioned Figure 3 and Figure 4 The method described in the embodiment shown in the figure executes the steps executed by the device, or causes the computer to execute the above-mentioned Figure 5 The illustrated embodiment describes the steps performed by the device in the method.

[0265] The execution device, execution device, terminal device or communication device provided in the embodiment of the present application may be a chip, and the chip includes: a processing unit and a communication unit, the processing unit may be a processor, and the communication unit may be an input / output interface, a pin or a circuit, etc. The processing unit may execute the computer execution instructions stored in the storage unit, so that the chip in the execution device executes the above Figure 3 and Figure 4 The processing method of the SIMD instruction described in the embodiment shown in the figure, or, to enable the chip in the execution device to execute the above Figure 5 The method for generating SIMD instructions described in the illustrated embodiment. Optionally, the storage unit is a storage unit in the chip, such as a register, a cache, etc. The storage unit may also be a storage unit located outside the chip in the wireless access device, such as a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, a random access memory (RAM), etc.

[0266] The processor mentioned in any of the above places may be a general-purpose central processing unit, a microprocessor, an ASIC, or one or more integrated circuits for controlling the execution of the program of the above-mentioned first aspect method.

[0267] It should also be noted that the device embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed over multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. In addition, in the drawings of the device embodiments provided by the present application, the connection relationship between the modules indicates that there is a communication connection between them, which may be specifically implemented as one or more communication buses or signal lines.

[0268] Through the description of the above implementation mode, the technicians in the field can clearly understand that the present application can be implemented by means of software plus necessary general hardware, and of course, it can also be implemented by special hardware including application-specific integrated circuits, special CPUs, special memories, special components, etc. In general, all functions completed by computer programs can be easily implemented with corresponding hardware, and the specific hardware structure used to implement the same function can also be various, such as analog circuits, digital circuits or special circuits. However, for the present application, software program implementation is a better implementation mode in more cases. Based on such an understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a readable storage medium, such as a computer floppy disk, a U disk, a mobile hard disk, a ROM, a RAM, a disk or an optical disk, etc., including a number of instructions to enable a computer device (which can be a personal computer, an execution device, or a network device, etc.) to execute the methods described in each embodiment of the present application.

[0269] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.

[0270] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from a website site, a computer, an execution device, or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, execution device, or data center. The computer-readable storage medium may be any available medium that a computer can store or an execution device, data center, or other data storage device that includes one or more available media integration. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)), etc.

Claims

1. A method for generating a single instruction multiple data SIMD instruction, characterized in that: The method comprises: Get the length of each loop dimension in at least one loop dimension of the first tensor calculation formula; Acquire information of multiple groups of first single instruction multiple data (SIMD) instruction models, wherein the information of each group of first SIMD instruction models corresponds to at least one loop dimension of a tensor calculation formula, and the information of each group of first SIMD instruction models includes a first constraint condition, and the first constraint condition is used to indicate a constraint condition of a length of each loop dimension in the at least one loop dimension; Selecting information of a second SIMD instruction model from the plurality of groups of information of first SIMD instruction models according to the first constraint condition and the length of each loop dimension in at least one loop dimension of the first tensor calculation formula, wherein the length of the loop dimension of the first tensor calculation formula satisfies the first constraint condition in the information of the second SIMD instruction model; Generate a first SIMD instruction after converting the first tensor calculation formula according to the length of at least one loop dimension of the first tensor calculation formula and the second SIMD instruction model.

2. The method according to claim 1, characterized in that Each group of information of the first SIMD instruction model also includes first indication information, where the first indication information is used to indicate the correspondence between K first parameters of a first SIMD instruction model and at least one loop dimension of a tensor calculation formula, where K is an integer greater than or equal to 1, and the first parameter indicates the number of times an operation is repeatedly performed on a data object in a tensor calculation formula.

3. The method according to claim 2, characterized in that The number of loop dimensions is N, and the information of the at least one group of first SIMD instruction models includes information of multiple types of SIMD instruction models. The value of N corresponding to the information of different types of SIMD instruction models is different, and N is an integer greater than 1.

4. The method according to claim 2, characterized in that: The first constraint condition is related to a type of chip that executes the converted first SIMD instruction.

5. The method according to any one of claims 1 to 4, characterized in that: The generating, according to the length of at least one loop dimension of the first tensor calculation formula and the second SIMD instruction model, a first SIMD instruction after conversion of the first tensor calculation formula comprises: Generate a plurality of first SIMD instructions according to the length of at least one loop dimension of the first tensor calculation formula and the second SIMD instruction model; According to the cost function of each first SIMD instruction among the multiple first SIMD instructions, a SIMD instruction that meets the optimization target is selected from the multiple first SIMD instructions and used as the first SIMD instruction after the first tensor calculation formula is converted, wherein the cost function indicates the optimization target related to the first SIMD instruction.

6. The method according to claim 5, characterized in that The optimization objectives indicated by the cost function include at least one of the following: minimum total number of SIMD instruction executions, maximum total number of SIMD instruction executions, minimum number of whole blocks and tail blocks in SIMD instructions, maximum number of whole blocks and tail blocks in SIMD instructions, maximum interval between whole blocks and tail blocks in SIMD instructions, minimum interval between whole blocks and tail blocks in SIMD instructions, minimum SIMD instruction scheduling delay, maximum SIMD instruction scheduling delay, minimum total execution time of SIMD instructions, maximum calculation overhead of address offset in SIMD instructions, and minimum calculation overhead of address offset in SIMD instructions.

7. The method according to claim 5, characterized in that The independent variables of the cost function include at least one of the following: the parameter value of the first parameter in the first SIMD instruction, the number of whole blocks in the first SIMD instruction, the number of tail blocks in the first SIMD instruction, the number of times the address offset is calculated in the first SIMD instruction, the duration of executing a SIMD instruction, and the duration of switching from the process of executing a first SIMD instruction to the process of executing another first SIMD instruction.

8. The method according to claim 2, characterized in that: The generating, according to the length of at least one loop dimension of the first tensor calculation formula and the second SIMD instruction model, a first SIMD instruction after conversion of the first tensor calculation formula comprises: Acquire, according to the first indication information in the information of the second SIMD instruction model, a first parameter corresponding to a first loop dimension of the first tensor calculation formula, wherein the first loop dimension is one loop dimension of the at least one loop dimension, and a length of the first loop dimension does not divide a value range of the corresponding first parameter; Based on the length of the first loop dimension, a parameter value of a full block portion of the first SIMD instruction and a parameter value of a tail block portion of the first SIMD instruction are generated.

9. The method according to claim 2, characterized in that: The generating, according to the length of at least one loop dimension of the first tensor calculation formula and the second SIMD instruction model, a first SIMD instruction after conversion of the first tensor calculation formula comprises: Acquire, according to the first indication information in the information of the second SIMD instruction model, a first parameter corresponding to a second loop dimension of the first tensor calculation formula, wherein the second loop dimension is a loop dimension with the highest dimension among the at least one loop dimension, and a length of the second loop dimension exceeds an upper limit of a value of the corresponding first parameter; Based on the length of the second loop dimension, parameter values ​​for the entire block portion of the first SIMD instruction are generated.

10. The method according to claim 3, characterized in that The information of the at least one group of first SIMD instruction models includes information of a third SIMD instruction model, information of a fourth SIMD instruction model, and information of a fifth SIMD instruction model, a value of N corresponding to the information of the third SIMD instruction model is less than a value of N corresponding to the information of the fourth SIMD instruction model, a value of N corresponding to the information of the fourth SIMD instruction model is less than a value of N corresponding to the information of the fifth SIMD instruction model, and N corresponding to the information of the fourth SIMD instruction model is greater than or equal to 2; The selecting at least one set of information of the second SIMD instruction model from the at least one set of information of the first SIMD instruction model comprises: Selecting information of the second SIMD instruction model from information of the third SIMD instruction model; When the information of the second SIMD instruction model does not exist in the information of the fourth SIMD instruction model, the selection of the information of the second SIMD instruction model from the information of the fifth SIMD instruction model is abandoned.

11. The method according to any one of claims 1 to 4, characterized in that: The method further comprises: Obtaining a second constraint condition, where the second constraint condition is used to indicate the number of destination addresses in the first SIMD instruction model and the number of source addresses in the first SIMD instruction model; Obtaining the number of destination addresses in the first tensor calculation formula and the number of source addresses in the first tensor calculation formula; The selecting at least one set of information of the second SIMD instruction model from the at least one set of information of the first SIMD instruction model comprises: When the number of destination addresses in the first tensor calculation formula is the same as the number of destination addresses in the first SIMD instruction model, and the number of source addresses in the first tensor calculation formula is the same as the number of source addresses in the first SIMD instruction model, at least one group of second SIMD instruction model information is selected from the at least one group of first SIMD instruction model information.

12. The method according to any one of claims 1 to 4, characterized in that: The obtaining of information of at least one set of first SIMD instruction models includes: The information of the at least one group of first SIMD instruction models is obtained from the information set of SIMD instruction models, wherein the information set of the SIMD instruction models includes at least one information subset of the SIMD instruction models, each information subset of the SIMD instruction model corresponds to a tensor calculation formula of an operation type, and the information subset of the SIMD instruction model to which the information of the at least one group of first SIMD instruction models belongs corresponds to the operation type of the first tensor calculation formula.

13. A method for processing a single instruction multiple data (SIMD) instruction, characterized in that: The method comprises: Obtaining a first parameter value and a second parameter value corresponding to a first SIMD instruction model, wherein the value of the first parameter value is K, which is used to indicate that the first SIMD instruction model includes K first parameters, and K is an integer greater than or equal to 1, and the second parameter value indicates a value constraint of the K first parameters, and the first parameter reflects the number of times an operation is repeatedly performed on a data object in a tensor calculation formula matching the first SIMD instruction model; According to the first parameter value and the second parameter value, information of a first SIMD instruction model is generated, wherein the information of one first SIMD instruction model corresponds to one first SIMD instruction model, and the information of the first SIMD instruction model includes first indication information and a first constraint condition, the first indication information is used to indicate the correspondence between the K first parameters and at least one loop dimension of a tensor calculation formula matching the first SIMD instruction model, and the first constraint condition is used to indicate a constraint condition on the length of each loop dimension in the at least one loop dimension.

14. The method according to claim 13, characterized in that The method further comprises: Obtaining a third parameter value, wherein the third parameter value indicates a quantity constraint of an entire block in the first SIMD instruction model; The generating information of the first SIMD instruction model according to the first parameter value and the second parameter value includes: Generate the first indication information according to the first parameter value; The first constraint condition is generated according to the first indication information, the second parameter value and the third parameter value.

15. The method according to claim 13 or 14, characterized in that The method further comprises: Obtaining a fourth parameter value, where the fourth parameter value is used to indicate the number of destination addresses of the first SIMD instruction model and the number of source addresses of the first SIMD instruction model; A second constraint condition is generated according to the fourth parameter value, where the second constraint condition is used to indicate the number of destination addresses and the number of source addresses in a tensor calculation formula that matches the first SIMD instruction model.

16. The method according to claim 13 or 14, characterized in that The method further comprises: A cost function corresponding to the first SIMD instruction model is obtained, wherein the cost function is used to screen out SIMD instructions that meet the optimization goal, the SIMD instructions that meet the optimization goal are SIMD instructions with the largest or smallest function value of the cost function, and the independent variables of the cost function include at least one of the following: a parameter value of the first parameter in the first SIMD instruction, the number of whole blocks in the first SIMD instruction, the number of tail blocks in the first SIMD instruction, the number of calculation times of the address offset in the first SIMD instruction, the duration of executing a SIMD instruction, and the duration of switching from a process of executing a first SIMD instruction to a process of executing another first SIMD instruction.

17. A device for generating a single instruction multiple data (SIMD) instruction, characterized in that: The device comprises: An acquisition module, used to obtain the length of each loop dimension of the first tensor calculation formula; The acquisition module is further used to acquire information of multiple groups of first single instruction multiple data (SIMD) instruction models, wherein the information of each group of first SIMD instruction models corresponds to at least one loop dimension of a tensor calculation formula, and the information of each group of first SIMD instruction models includes a first constraint condition, and the first constraint condition is used to indicate a constraint condition of a length of each loop dimension in the at least one loop dimension; A selection module, configured to select information of a second SIMD instruction model from the plurality of groups of information of first SIMD instruction models according to the first constraint condition and the length of each loop dimension of the first tensor calculation formula, wherein the information of the second SIMD instruction model matches the first tensor calculation formula, and the length of the loop dimension of the first tensor calculation formula satisfies the first constraint condition in the information of the second SIMD instruction model; A generation module is used to generate a first SIMD instruction after converting the first tensor calculation formula according to the length of at least one loop dimension of the first tensor calculation formula and the second SIMD instruction model.

18. The device according to claim 17, characterized in that Each group of information of the first SIMD instruction model also includes first indication information, where the first indication information is used to indicate the correspondence between K first parameters of a first SIMD instruction model and at least one loop dimension of a tensor calculation formula, where K is an integer greater than or equal to 1, and the first parameter indicates the number of times an operation is repeatedly performed on a data object in a tensor calculation formula.

19. The device according to claim 18, characterized in that The at least one loop dimension includes N loop dimensions, and the information of the at least one group of first SIMD instruction models includes information of multiple types of SIMD instruction models. The value of N corresponding to the information of different types of SIMD instruction models is different, and N is an integer greater than or equal to 1.

20. The device according to any one of claims 17 to 19, characterized in that The generating module is specifically used for: Generate a plurality of first SIMD instructions according to the length of at least one loop dimension of the first tensor calculation formula and the second SIMD instruction model; According to the cost function of each first SIMD instruction among the multiple first SIMD instructions, a SIMD instruction that meets the optimization goal among the multiple first SIMD instructions is selected and used as the first SIMD instruction after the first tensor calculation formula is converted, wherein the SIMD instruction that meets the optimization goal is the SIMD instruction with the maximum or minimum function value of the cost function, and the cost function indicates the optimization goal related to the first SIMD instruction.

21. The device according to claim 18, characterized in that The generating module is specifically used for: Acquire, according to the first indication information in the information of the second SIMD instruction model, a first parameter corresponding to a first loop dimension of the first tensor calculation formula, wherein the first loop dimension is a loop dimension of the at least one loop dimension, and a length of the first loop dimension does not divide a value range of the corresponding first parameter; Based on the length of the first loop dimension, a parameter value of a full block portion of the first SIMD instruction and a parameter value of a tail block portion of the first SIMD instruction are generated.

22. The device according to claim 18, characterized in that The generating module is specifically used for: Acquire, according to the first indication information in the information of the second SIMD instruction model, a first parameter corresponding to a second loop dimension of the first tensor calculation formula, wherein the second loop dimension is a loop dimension with the highest dimension among the at least one loop dimension, and a length of the second loop dimension exceeds an upper limit of a value of the corresponding first parameter; Parameter values ​​for the entire block portion of the first SIMD instruction are generated based on the length of the second loop dimension.

23. The device according to claim 19, characterized in that The information of the at least one group of first SIMD instruction models includes information of a third SIMD instruction model, information of a fourth SIMD instruction model, and information of a fifth SIMD instruction model, a value of N corresponding to the information of the third SIMD instruction model is less than a value of N corresponding to the information of the fourth SIMD instruction model, a value of N corresponding to the information of the fourth SIMD instruction model is less than a value of N corresponding to the information of the fifth SIMD instruction model, and N corresponding to the information of the fourth SIMD instruction model is greater than or equal to 2; The selection module is specifically used for: Selecting information of the second SIMD instruction model from information of the third SIMD instruction model; When the information of the second SIMD instruction model does not exist in the information of the fourth SIMD instruction model, the selection of the information of the second SIMD instruction model from the information of the fifth SIMD instruction model is terminated.

24. The device according to any one of claims 17 to 19, characterized in that The acquisition module is further used to acquire a second constraint condition, where the second constraint condition is used to indicate the number of destination addresses in the first SIMD instruction model and the number of source addresses in the first SIMD instruction model; The acquisition module is further used to acquire the number of destination addresses in the first tensor calculation formula and the number of source addresses in the first tensor calculation formula; The selection module is specifically used to select at least one group of second SIMD instruction model information from the at least one group of first SIMD instruction model information when the number of destination addresses in the first tensor calculation formula is the same as the number of destination addresses in the first SIMD instruction model, and the number of source addresses in the first tensor calculation formula is the same as the number of source addresses in the first SIMD instruction model.

25. The device according to any one of claims 17 to 19, characterized in that The acquisition module is specifically used to acquire the information of the at least one group of first SIMD instruction models from the information set of the SIMD instruction model, wherein the information set of the SIMD instruction model includes at least one information subset of the SIMD instruction model, each information subset of the SIMD instruction model corresponds to a tensor calculation formula of an operation type, and the information subset of the SIMD instruction model to which the information of the at least one group of first SIMD instruction models belongs corresponds to the operation type of the first tensor calculation formula.

26. A processing device for a single instruction multiple data (SIMD) instruction, characterized in that: The device comprises: an acquisition module, configured to acquire a first parameter value and a second parameter value corresponding to a first SIMD instruction model, wherein the value of the first parameter value is K, indicating that the first SIMD instruction model includes K first parameters, and K is an integer greater than or equal to 1; the second parameter value indicates a value constraint of the K first parameters, and the first parameter reflects the number of repetitions of an operation repeatedly performed on a data object in a tensor calculation formula matching the first SIMD instruction model; A generation module is used to generate information of a first SIMD instruction model according to the first parameter value and the second parameter value, wherein the information of a first SIMD instruction model corresponds to a first SIMD instruction model, and the information of the first SIMD instruction model includes first indication information and a first constraint condition, the first indication information is used to indicate the correspondence between the K first parameters and at least one loop dimension of the tensor calculation formula matching the first SIMD instruction model, and the first constraint condition is used to indicate the constraint condition of the length of each loop dimension in the at least one loop dimension.

27. The device according to claim 26, characterized in that The acquisition module is further used to acquire a third parameter value, where the third parameter value indicates a quantity constraint of the entire block in the first SIMD instruction model; The generating module is specifically used for: Generate the first indication information according to the first parameter value; The first constraint condition is generated according to the first indication information, the second parameter value and the third parameter value.

28. The device according to claim 26 or 27, characterized in that The acquisition module is further used to acquire a fourth parameter value, where the fourth parameter value is used to indicate the number of destination addresses of the first SIMD instruction model and the number of source addresses of the first SIMD instruction model; The generation module is also used to generate a second constraint condition based on the fourth parameter value, where the second constraint condition is used to indicate the number of destination addresses and the number of source addresses in the tensor calculation formula that matches the first SIMD instruction model.

29. The device according to claim 26 or 27, characterized in that The acquisition module is further used to acquire a cost function corresponding to the first SIMD instruction model, wherein the cost function is used to screen out SIMD instructions that meet the optimization goal, and the SIMD instructions that meet the optimization goal are SIMD instructions with the largest or smallest function value of the cost function, and the independent variables of the cost function include at least one of the following: the parameter value of the first parameter in the first SIMD instruction, the number of whole blocks in the first SIMD instruction, the number of tail blocks in the first SIMD instruction, the number of calculation times of the address offset in the first SIMD instruction, the execution time of a SIMD instruction, and the execution time of switching from the process of executing a first SIMD instruction to the process of executing another first SIMD instruction.

30. A computer-readable storage medium, characterized in that: The invention comprises a program which, when being executed on a computer, causes the computer to execute the method according to any one of claims 1 to 12, or causes the computer to execute the method according to any one of claims 13 to 16.

31. An execution device, characterized in that: comprising a processor and a memory, the processor being coupled to the memory, The memory is used to store programs; The processor is used to execute the program in the memory so that the execution device executes the method according to any one of claims 1 to 12, or the execution device executes the method according to any one of claims 13 to 16.

32. A chip, wherein the chip is configured in an execution device so that the execution device implements the method according to any one of claims 1 to 12, or the execution device implements the method according to any one of claims 13 to 16.