Automatic generation method and device of high-performance sparse tensor program

Through domain customized language and computational graph analysis, combined with reinforcement learning and heuristic algorithms, the design space is built to generate high-performance sparse tensor programs, solving the problems of high computational cost and difficult development in sparse tensor calculations, and achieving efficient sparse tensor program generation.

CN120406911APending Publication Date: 2025-08-01UNIV OF SCI & TECH OF CHINA
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510309128.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-13
Publication Date
2025-08-01

AI Technical Summary

Technical Problem

The existing sparse tensor computing has problems such as high computational cost, high development difficulty and low efficiency in high performance operator development. The existing hardware manufacturer's operator library cannot meet the development needs of new algorithms.

Method used

The sparse calculation operations are represented as sparse calculation descriptions using a domain custom language, and the design space is constructed through computational graph analysis and reinforcement learning and heuristic algorithms, the target primitive configuration is determined, and a high-performance sparse tensor program is generated.

Benefits of technology

The generation accuracy and efficiency of sparse tensor programs are improved, and the determination accuracy and efficiency of sparse calculation operators are significantly improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120406911A_ABST
    Figure CN120406911A_ABST
Patent Text Reader

Abstract

The invention discloses an automatic generation method and device for a high-performance sparse tensor program, and the method comprises the steps: representing a sparse calculation operation as a sparse calculation description based on a domain customization language, and further converting the sparse calculation description into a calculation graph; calculating features are obtained based on calculation graph analysis, a first design space is constructed based on the calculation features, and a target point is determined from all design points in the first design space so as to determine target primitive configuration based on the target point; based on the sparse tensor compiler and the target primitive configuration, a sparse compute operator is determined to generate a high performance sparse tensor program. Therefore, the sparse calculation operation can be converted into the calculation graph, the first design space and the second design space are constructed, the target primitive configuration is obtained by searching the second design space, the determination accuracy and efficiency of the sparse calculation operator are improved, and then the generation accuracy and efficiency of the high-performance sparse tensor program are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular, to a method for automatically generating a high-performance sparse tensor program. Background Art

[0002] Sparse tensor calculation plays an important role in modern deep learning and scientific computing, but its high computational cost leads to a strong demand for high-performance operators. However, developing high-performance operators is extremely difficult and cumbersome, and the existing operator libraries of hardware manufacturers cannot meet the development trend of new algorithms.

[0003] In the prior art, a sparse tensor compiler is used to simplify the development and optimization of operators. Developers only need to operate on the high-level tuning instructions provided by the compiler. However, the combination of tuning instructions and parameters still forms a huge design space. At the same time, the specific implementation of the program is also sensitive to the computational hardware platform. Deploying different sparse computations to different computing devices incurs exponential growth in human effort. Therefore, how to provide an automatic generation scheme for high-performance sparse tensor programs to improve the generation accuracy and efficiency of high-performance sparse tensor programs is particularly important. Summary of the Invention

[0004] The technical problem to be solved by the present invention is to provide a method and device for automatically generating a high-performance sparse tensor program, which can improve the generation accuracy and efficiency of the high-performance sparse tensor program.

[0005] To solve the above technical problem, a first aspect of the present invention discloses a method for automatically generating a high-performance sparse tensor program, the method comprising:

[0006] Representing the sparse computation operation input by the user as a sparse computation description corresponding to the sparse computation operation based on a domain-specific language;

[0007] Converting the sparse computation description into a computation graph corresponding to the sparse computation description based on the domain-specific language;

[0008] Analyzing a computation pattern corresponding to the sparse computation description based on the computation graph to obtain a computation feature corresponding to the sparse computation description;

[0009] Constructing a first design space corresponding to the sparse computation description based on the computation feature corresponding to the sparse computation description; the first design space includes a plurality of design points and neighbor relationships between the design points, and the design points are used to represent a combination configuration scheme of each loop scheduling primitive in the loop scheduling primitive set for optimizing the sparse computation description and each sparse format primitive in the sparse format primitive set;

[0010] Determine the target point corresponding to the sparse computation description from all the design points in the first design space;

[0011] Determine the target primitive configuration corresponding to the sparse computation description based on the target point;

[0012] Based on the sparse tensor compiler and the target primitive configuration, determine the sparse computation operator corresponding to the sparse computation operation, where the sparse computation operator is used for generating a high-performance sparse tensor program.

[0013] As an alternative implementation, in the first aspect of the present invention, the nodes of the computation graph represent tensor operation operations corresponding to sparse computation operations, and the edges of the computation graph represent tensors corresponding to sparse computation operations; the tensors include dense tensors and sparse tensors, and the tensors are combined with axes in several dimensions, where the axes are used to define the length and format attributes of the tensors.

[0014] As an alternative implementation, in the first aspect of the present invention, the determining the target point corresponding to the sparse computation description from all the design points in the first design space includes:

[0015] Perform a pruning operation on the first design space and regenerate the neighbor relationships of all the design points to obtain a second design space corresponding to the sparse computation description;

[0016] Based on reinforcement learning and a heuristic algorithm, search the second design space and determine the target point corresponding to the sparse computation description from all the design points.

[0017] As an alternative implementation, in the first aspect of the present invention, the axes include sparse-related axes and loop axes; the computation features include information on the sparse-related axes corresponding to the sparse computation description, information on the loop axes, and feature information corresponding to the tensors;

[0018] Moreover, the sparse format primitive is used to split and reorganize the axes and assign different sparse level attributes to the axes, and the loop scheduling primitive is used to perform splitting, reorganization, and parallelization operations on all the loop axes after the operation of the sparse format primitive on the axes.

[0019] As an alternative implementation, in the first aspect of the present invention, the heuristic algorithm includes a simulated annealing algorithm;

[0020] Moreover, the searching the second design space based on reinforcement learning and a heuristic algorithm and determining the target point corresponding to the sparse computation description from all the design points includes:

[0021] Generate a feature vector corresponding to each design point in the first design space;

[0022] Extract a batch of design points from the second design space as the initial search population, use reinforcement learning to navigate the change of the initial search population, and use the simulated annealing algorithm to determine the elimination and reproduction of the initial search population. After iterating several rounds or when the search converges, obtain the target search population; Based on the target search population, determine the target point corresponding to the sparse computation description; wherein, the feature vector corresponding to the design point is used to represent the state of reinforcement learning, the neighbor relationship between the design points is used to represent the action of reinforcement learning, and the Q value of the reinforcement learning is predicted based on a multi-layer perceptron;

[0023] In addition, the method further includes:

[0024] Run the sparse computation operator corresponding to the sparse computation operation on the target computing platform to obtain the measured program performance corresponding to the sparse computation operation; the measured program performance is used for the reinforcement learning process of navigating the change of the initial search population.

[0025] As an optional implementation manner, in the first aspect of the present invention, before analyzing the computation mode corresponding to the sparse computation description based on the computation graph to obtain the computation feature corresponding to the sparse computation description, the method further includes:

[0026] Divide the computation graph into several sub-computation graphs;

[0027] In addition, analyzing the computation mode corresponding to the sparse computation description based on the computation graph to obtain the computation feature corresponding to the sparse computation description includes:

[0028] Based on the sub-computation graphs divided from the computation graph, analyze the computation mode corresponding to the sparse computation description to obtain the computation feature corresponding to the sparse computation description.

[0029] As an optional implementation manner, in the first aspect of the present invention, the encoding to generate a feature vector corresponding to each design point in the first design space includes:

[0030] For each design point in the first design space, translate the strings in the corresponding loop scheduling primitive and its parameters, and the sparse format primitive and its parameters of the design point into numerical types based on the mapping table, and splice the combination of the loop scheduling primitive corresponding to the design point and the corresponding sparse format primitive into a numerical array type as the feature vector corresponding to the design point.

[0031] The second aspect of the present invention discloses an automatic generation device for a high-performance sparse tensor program, and the device includes:

[0032] A conversion module, configured to represent a sparse computing operation input by a user as a sparse computing description corresponding to the sparse computing operation based on a domain-specific language; and convert the sparse computing description into a computation graph corresponding to the sparse computing description based on the domain-specific language.

[0033] An analysis module, configured to analyze a computation pattern corresponding to the sparse computing description based on the computation graph to obtain a computation feature corresponding to the sparse computing description.

[0034] A construction module, configured to construct a first design space corresponding to the sparse computing description based on the computation feature corresponding to the sparse computing description; the first design space includes a plurality of design points and neighbor relationships between the design points, and the design points are used to represent a combination configuration scheme of each loop scheduling primitive in a set of loop scheduling primitives for optimizing the sparse computing description and each sparse format primitive in a set of sparse format primitives.

[0035] A determination module, configured to determine a target point corresponding to the sparse computing description from all the design points in the first design space; determine a target primitive configuration corresponding to the sparse computing description based on the target point; and determine a sparse computing operator corresponding to the sparse computing operation based on a sparse tensor compiler and the target primitive configuration, where the sparse computing operator is used for generating a high-performance sparse tensor program.

[0036] As an optional implementation manner, in the second aspect of the present invention, a node of the computation graph represents a tensor operation operation corresponding to a sparse computing operation, and an edge of the computation graph represents a tensor corresponding to the sparse computing operation; the tensor includes a dense tensor and a sparse tensor, and the tensor is combined by axes in several dimensions, and the axes are used to define the length and format attributes of the tensor.

[0037] As an optional implementation manner, in the second aspect of the present invention, the manner in which the determination module determines a target point corresponding to the sparse computing description from all the design points in the first design space specifically includes:

[0038] Performing a pruning operation on the first design space and regenerating neighbor relationships of all the design points to obtain a second design space corresponding to the sparse computing description.

[0039] Searching the second design space based on reinforcement learning and a heuristic algorithm to determine a target point corresponding to the sparse computing description from all the design points.

[0040] As an alternative implementation, in the second aspect of the present invention, the axis includes a sparsity-related axis and a loop axis; the computed features include information on the sparsity-related axis corresponding to the sparse computation description, information on the loop axis, and the feature information corresponding to the tensor;

[0041] Moreover, the sparse format primitive is used to split and recombine the axis and assign different sparse level attributes to the axis, and the loop scheduling primitive is used to perform splitting, recombination, and parallelization operations on all the loop axes after the operation of the sparse format primitive on the axis.

[0042] As an alternative implementation, in the second aspect of the present invention, the heuristic algorithm includes a simulated annealing algorithm;

[0043] Moreover, the determination module searches the second design space based on reinforcement learning and the heuristic algorithm, and determines the target point corresponding to the sparse computation description from all the design points. The specific method includes:

[0044] Encoding to generate a feature vector corresponding to each design point in the first design space;

[0045] Extracting a batch of design points from the second design space as the initial search population, using reinforcement learning to navigate the change of the initial search population, using the simulated annealing algorithm to determine the elimination and reproduction of the initial search population. After iterating several rounds or the search converges, a target search population is obtained; based on the target search population, the target point corresponding to the sparse computation description is determined; wherein, the feature vector corresponding to the design point is used to represent the state of reinforcement learning, the neighbor relationship between the design points is used to represent the action of reinforcement learning, and the Q value of reinforcement learning is predicted based on a multi-layer perceptron;

[0046] Moreover, the device further includes:

[0047] A measurement module, configured to run the sparse computation operator corresponding to the sparse computation operation on a target computing platform to obtain the measured program performance corresponding to the sparse computation operation; the measured program performance is used for the reinforcement learning process of navigating the change of the initial search population.

[0048] As an alternative implementation, in the second aspect of the present invention, the device further includes:

[0049] A partitioning module, configured to partition the computation graph into several sub-computation graphs before the analysis module analyzes the computation mode corresponding to the sparse computation description based on the computation graph to obtain the computed features corresponding to the sparse computation description;

[0050] Moreover, the analysis module analyzes the computation pattern corresponding to the sparse computation description based on the computation graph to obtain the computation features corresponding to the sparse computation description. The specific method includes:

[0051] Based on the sub-computation graphs divided from the computation graph, analyze the computation pattern corresponding to the sparse computation description to obtain the computation features corresponding to the sparse computation description.

[0052] As an alternative implementation, in the second aspect of the present invention, the determination module encodes and generates a feature vector corresponding to each design point in the first design space. The specific method includes:

[0053] For each design point in the first design space, translate the strings in the loop scheduling primitive and its parameters, and the sparse format primitive and its parameters corresponding to the design point into numerical types based on the mapping table, and splice the combination of the loop scheduling primitive and the corresponding sparse format primitive corresponding to the design point into a numerical array type as the feature vector corresponding to the design point.

[0054] The third aspect of the present invention discloses another automatic generation device for high-performance sparse tensor programs. The device includes:

[0055] A memory storing executable program code;

[0056] A processor coupled to the memory;

[0057] The processor calls the executable program code stored in the memory and executes the steps in the automatic generation method for high-performance sparse tensor programs disclosed in the first aspect of the present invention.

[0058] The fourth aspect of the present invention discloses a computer storage medium storing computer instructions, which are used to execute the steps in the automatic generation method for high-performance sparse tensor programs disclosed in the first aspect of the present invention when called.

[0059] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:

[0060] Based on a domain-specific language, the present invention represents sparse computing operations as sparse computing descriptions, and further converts the sparse computing descriptions into a computational graph; analyzes computational features based on the computational graph and constructs a first design space based on the computational features, determines a target point from all design points in the first design space to determine a target primitive configuration based on the target point; determines a sparse computing operator based on a sparse tensor compiler and the target primitive configuration to generate a high-performance sparse tensor program. It can be seen that the present invention can transform sparse computing operations into a computational graph and construct a first design space and a second design space, obtain the target primitive configuration by searching the second design space, which is beneficial to improving the determination accuracy and efficiency of the sparse computing operator, and further improving the generation accuracy and efficiency of the high-performance sparse tensor program. Description of the Drawings

[0061] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the following drawings are only some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on these drawings.

[0062] Figure 1 is a schematic flowchart of a method for automatically generating a high-performance sparse tensor program disclosed in an embodiment of the present invention;

[0063] Figure 2 is a schematic diagram of the use of a domain-specific language disclosed in an embodiment of the present invention;

[0064] Figure 3 is a schematic flowchart of the generation process of the first design space disclosed in an embodiment of the present invention;

[0065] Figure 4 is a schematic flowchart of an adaptive search based on reinforcement learning and simulated annealing algorithms disclosed in an embodiment of the present invention;

[0066] Figure 5 is a schematic structural diagram of an apparatus for automatically generating a high-performance sparse tensor program disclosed in an embodiment of the present invention;

[0067] Figure 6 is a schematic structural diagram of another apparatus for automatically generating a high-performance sparse tensor program disclosed in an embodiment of the present invention. Detailed Embodiments

[0068] To enable those skilled in the art to better understand the solution of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts belong to the scope of protection of the present invention.

[0069] The terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or terminal that includes a series of steps or units is not limited to the listed steps or units, but optionally further includes steps or units not listed, or optionally further includes other steps or units inherent to these processes, methods, products or terminals.

[0070] Referring to "embodiment" herein means that a specific feature, structure or characteristic described in connection with the embodiment can be included in at least one embodiment of the present invention. The phrase appears in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment mutually exclusive with other embodiments. Those skilled in the art explicitly and implicitly understand that the embodiments described herein can be combined with other embodiments.

[0071] The present invention discloses a method and device for automatically generating a high-performance sparse tensor program. Implementing the method described in the embodiments of the present invention can transform sparse computing operations into a computational graph and construct a first design space and a second design space. Obtaining a target primitive configuration by searching the second design space is beneficial to improving the determination accuracy and efficiency of sparse computing operators, and further improving the generation accuracy and efficiency of high-performance sparse tensor programs. The following will be described in detail respectively.

[0072] Embodiment 1

[0073] Please refer to Figure 1 , Figure 1 which is a schematic flowchart of a method for automatically generating a high-performance sparse tensor program disclosed in an embodiment of the present invention. Among them, Figure 1 the described method can be applied to a sparse tensor compiler. The compiler runs on a target computing device, and the method is applicable to any scenario for automatically generating high-performance sparse tensor programs, which is not limited in the embodiments of the present invention. As Figure 1 shown, the method for automatically generating a high-performance sparse tensor program includes the following operations:

[0074] 101. Represent the sparse computing operations input by the user as sparse computing descriptions corresponding to the sparse computing operations based on the domain-specific language.

[0075] In the embodiments of the present invention, sparse computing performs operations such as mathematics and operations on one or more input tensors including sparse tensors. The sparse computing is included in common deep learning models and scientific computing models, including speech recognition models, image detection models, large language models, and point cloud computing models, etc. Specifically, sparse computing is applied to the operators in the model. Among them, the sparse computing operation includes sparse computing and the sparse data input for sparse computing. The sparse data is the entire tensor elements and position information described in a certain format data structure.

[0076] In the embodiments of the present invention, the domain-specific language is dedicated to describing sparse tensor computing, and its functions include: defining tensor axes, including sparse format attributes, lengths, and identifiers; combining tensor axes to construct tensors and identifying sparse tensor notations; defining an operator library, including operators such as mathematical operations and tensor operations; forming a calculation based on the defined tensors and operators in the operator library and generating intermediate and output tensors. By providing the domain-specific language, various sparse computing expressions can be flexibly supported. The domain-specific language is the front end of the high-performance sparse tensor program automatic generation method provided in this application, and users can easily use the domain-specific language to implement high-performance sparse operators.

[0077] 102. Convert the sparse computing description into a computation graph corresponding to the sparse computing description based on the domain-specific language.

[0078] In the embodiments of the present invention, as Figure 2 shown is an example of the use of the domain-specific language, which illustrates the definition of the sparse matrix multiplication (SPMM) calculation. The user uses the domain-specific language in four parts including steps 310 to 340. In 310, the user operates the domain-specific language to first describe all the relevant axes of the sparse matrix multiplication input tensor, including the length, attributes, and identifiers of the axes. The axis variables with the same identifier correspond to the same loop traversal in the specific calculation of the multi-layer nested loop. Based on the axes defined in 310, tensors are formed. In 320, the left and right operands of the sparse matrix multiplication are defined, where the A matrix is a sparse matrix. 330 declares the specific calculation, where the basic primitive operators provided by the domain-specific language are used, and the final output result tensor C is obtained. The information of tensor C is deduced by the domain-specific language through the operand tensors and operators. 340 tunes and compiles the existing calculation to generate a computable object. The computable object is a completely encapsulated computing operator, and the statically compiled operator can be run therein.

[0079] 103. Analyze the computation pattern corresponding to the sparse computing description based on the computation graph to obtain the computation characteristics corresponding to the sparse computing description.

[0080] 104. Describe the corresponding computing characteristics based on sparse computing and construct the first design space corresponding to the sparse computing description;

[0081] In the embodiments of the present invention, the first design space includes several design points and the neighbor relationships between the design points. The design points are used to represent the combination configuration schemes of each loop scheduling primitive in the loop scheduling primitive set for optimizing the sparse computing description and each sparse format primitive in the sparse format primitive set;

[0082] In the embodiments of the present invention, it can be understood that the combination of the sparse format primitives explores all possible storage formats, and the loop scheduling primitives explore all possibilities of memory access optimization and parallelization optimization. The Cartesian product of the two explorations forms the first design space, covering almost all optimization possibilities.

[0083] In the embodiments of the present invention, it can be understood that the first design space establishes neighbor relationships to form an undirected fully connected graph, where the edges of the neighbor relationships are formed by complex primitive combination transformations, and the neighbor relationships represent that the primitive features and performance of adjacent points are positively correlated.

[0084] In the embodiments of the present invention, such as Figure 3The figure shows the generation flow chart of the first design space. First, within the domain-specific language, the sparse matrix multiplication is transformed into a computation graph represented by 411. This computation graph can be expanded into the three-layer nested loop and the innermost multiply-accumulate assignment statement shown in 410. 420 collects the feature information of the sparse computation based on the computation graph to analyze the computation pattern, records the node and edge information of the computation graph, records the sparse-related and non-sparse-related tensor information, records the non-zero elements and layout features of the sparse tensor, records the input operand types of the sparse computation, records the loop axis types for the expansion of the computation nodes, including the spatial axis and the reduction axis, as well as the axis order. Among them, the nested loop of the node contains the spatial loop and the reduction loop. The former is more suitable for loop parallelization operations due to the lack of data dependence, while the latter needs to consider the overhead of atomic operations during parallelization. The format of the sparse tensor reflects the mapping from storage access to the physical storage space and jointly affects the memory access overhead and load balancing with the loop access order. The axes of the sparse attributes have complex format metadata and are not suitable for loop parallelization and blocking. 430 automatically adds primitive configurations based on the computation pattern. 430 shows a way of adding primitives. It splits the i and j axes of the sparse tensor once, reorders the four axes formed after splitting, and then adds format attributes to the four axes. Among them, the three types of operations form a new storage format. Obviously, more formats can be combined by splitting the depth and there is an exponential growth; it splits and reorders the non-sparse axes, where the axes that do not affect the format reordering are not reordered; finally, it adds parallelization primitives to the determined axes, including parallelization, vectorization, and loop unrolling. 440 performs encoding mapping on the characters in the primitive configuration sequence, and finally 450 shows the feature vector formed by the primitive configuration sequence. The feature vector of 450 can identify a unique design point in the space. Based on the five operation steps from 410 to 450, the first design space is formed. Based on the first design space, the neighbor relationship of the points in the space can be established to facilitate wandering in the undirected fully connected graph during subsequent searches. Different from directly using the feature vector formed by 450 to construct the neighbor relationship edge through vector similarity, this application uses the parameter changes of the primitives in 430 to connect the two edges. Specifically, the recombination of the splitting factors, the permutation and combination scheme of the reordering, and the recombination of the parallelization primitive triples can all form transformation relationships. Obviously, the transformations between the design points retain most of the common features and have the characteristics of mostly similar performance, which is beneficial to capturing the correct search transformation direction during the search.

[0085] 105. Determine the target point corresponding to the sparse computation description from all the design points in the first design space;

[0086] 106. Determine the target primitive configuration corresponding to the sparse computation description based on the target point;

[0087] 107. Based on the sparse tensor compiler and the target primitive configuration, determine the sparse computing operator corresponding to the sparse computing operation, where the sparse computing operator is used for the generation of high-performance sparse tensor programs.

[0088] In the embodiments of the present invention, it can be understood that step 107 is to use the sparse tensor compiler for compilation based on the search-based optimal primitive configuration to obtain the final program, and output the completely encapsulated sparse computing operator.

[0089] Experiments show that when this method is deployed on the CPU computing platforms Intel E5-2620 v4 and AMD EPYC 7543, and three common sparse computations are selected, including sparse matrix multiplication (SPMM), sparse matrix-vector multiplication (SPMV), and sparse matrix-dense matrix multiplication (SDDMM), a batch of data is randomly selected from the SuiteSparse sparse matrix database as the input sparse data, and experimental comparisons are made with four state-of-the-art schemes, including the Intel Math Kernel Library (MKL), the manually optimized sparse operator scheme, the tensor program auto-tuning framework TVM, and WACO. The operators output by the method provided in this application can achieve an average performance improvement of 1.19 to 6.34 times.

[0090] It can be seen that the present invention can transform the sparse computing operation into a computation graph and construct the first design space and the second design space, and obtain the target primitive configuration by searching the second design space, which is beneficial to improving the determination accuracy and efficiency of the sparse computing operator, and further improving the generation accuracy and efficiency of high-performance sparse tensor programs.

[0091] In an optional embodiment, the nodes of the computation graph represent the tensor operation operations corresponding to the sparse computing operations, and the edges of the computation graph represent the tensors corresponding to the sparse computing operations; the tensors include dense tensors and sparse tensors, and the tensors are combined by axes of several dimensions, where the axes are used to define the length and format attributes of the tensors.

[0092] In this optional embodiment, it can be understood that the computation graph is composed of edges representing tensors and nodes representing basic operator operations, and is a directed acyclic graph, and the target sparse computing expression is formed by combining according to the flow topological order of the edges representing tensors. The basic operator is a code block that can be mapped to a tensor operation and operation composed of multi-layer nested loops and calculation assignment statements. The tensors and nodes carry attributes and store information; the operator nodes operate on the input tensors and infer the information of the output tensors.

[0093] It can be seen that this optional embodiment can determine the meanings represented by the nodes and variables of the computation graph and the presentation form of the tensors, which is beneficial to improving the determination accuracy of the computation graph, and further improving the determination accuracy of the first design space and the second design space, thereby improving the generation accuracy and efficiency of high-performance sparse tensor programs.

[0094] In another alternative embodiment, determining the target point corresponding to the sparse computation description from all the design points in the first design space in step 105 includes:

[0095] Performing a pruning operation on the first design space and regenerating the neighbor relationships of all the design points to obtain a second design space corresponding to the sparse computation description;

[0096] Based on reinforcement learning and a heuristic algorithm, searching the second design space to determine the target point corresponding to the sparse computation description from all the design points.

[0097] In this alternative embodiment, it can be understood that pruning is used to remove a large number of inefficient and invalid redundant points in the first design space. Among them, the two pieces of information, i.e., the axis order and the length, are determined after the format primitive reordering in the foregoing step 430. This information conflicts with the format attributes and forms a semantic error format. The current loop axis is prone to dependencies on the parent loop axis (the axis order is smaller than the current axis), and the dependencies have constraints on the format attributes of the axis; the position of the current loop axis determines whether the axis length can be non-1. The splitting depth of the two splitting primitives in the foregoing step 430 depends on the axis length, and the splitting factor needs to consider the minimum length constraint of the axis sorted later, such as i1, after splitting. The loop splitting primitive and the three parallelization primitives in the foregoing step 430 are only for non-compressed sparse formats to reduce the cost of accessing sparse axes. Limit the parameter ranges of the loop splitting factor and the parallelization primitives according to the hardware information. Among them, the number of applications of the splitting primitive represents the splitting depth, and the loop traversal cost grows exponentially with the depth. Therefore, exclude inefficient configurations by limiting the splitting depth; at the same time, limit the parameter ranges of the loop splitting factor and the parallelization primitives according to the hardware information; the combination of loop parallelization primitives can only be applied to axes with dense attributes and has an order requirement according to the parallelization primitive; there are a large number of semantic error storage formats in the formats formed by the combination of format primitives, and the multi-layer nested loop code based on the format attributes is inconsistent with the actual storage scheme, so the calculation result is incorrect or the program crashes. Further, the point relationships in the pruned second design space become sparser. In this application, a finite recursion rule is used during pruning to skip invalid points and establish neighbor relationships with other valid points.

[0098] It can be seen that this alternative embodiment can perform pruning on the first design space to obtain a second design space, search for the target point through reinforcement learning and a heuristic algorithm, which is beneficial to improving the determination accuracy of the target point, and further improving the determination accuracy and efficiency of the sparse computation operator, thereby improving the generation accuracy and efficiency of high-performance sparse tensor programs.

[0099] In yet another alternative embodiment, the axis includes a sparse-related axis and a loop axis; the computation features include the information of the sparse-related axis corresponding to the sparse computation description, the information of the loop axis, and the feature information corresponding to the tensor;

[0100] Further, the sparse format primitive is used to split and recombine axes and assign different sparse hierarchical attributes to the axes, and the loop scheduling primitive is used to perform splitting, recombination, and parallelization operations on all loop axes after the sparse format primitive operates on the axes.

[0101] In this optional embodiment, further, the calculation features specifically include sparse tensors and dense tensors; the axis attributes of each dimension in the sparse tensor, including sparse attributes and lengths; the axis order representing the tensor storage order; the features of the sparse tensor, reflecting the number of non-zero elements and the layout of non-zero elements, etc.; the tensor operator identifier to distinguish, such as left and right operands and output tensors; the sparse and dense related loop axes of the operator-expanded multi-layer nested loop; the spatial loop axes and reduction loop axes of the operator-expanded multi-layer nested loop; the axis order associated with the loop axes in the multi-layer nested loop. The calculation mode is associated with the calculation features and indicates the specific implementation details of the calculation. Based on this, the specific tuning primitive addition scheme can be analyzed.

[0102] Further, based on the foregoing definitions, determining the first design space based on the calculation features can be understood as follows: First, determine the primitives related to the sparse tensor storage format, split, reorder, and add sparse attributes to the axes related to the sparse tensor. Among them, the splitting and reordering of the axes form the storage access optimization of the block data, with better data locality. The reordering and attribute addition of the axes form different sparse data storage schemes, changing the data access efficiency; synchronize the operations on the sparse-related axes to the naive multi-layer nested loop to implement the access to the sparse tensor storage format; split and reorder the non-sparse-related axes to optimize the data locality of the dense tensor; apply the primitives of loop parallelization, loop unrolling, and loop vectorization to fully utilize the computing performance of the computing platform. Based on the addition rules of the tuning primitives, different primitive combinations and parameter combination schemes are formed. All the schemes form the first design space. The schemes represent points in the design space, and this space is design-complete and contains the optimal design of this tuning scheme.

[0103] It can be seen that this optional embodiment can further determine the information and uses included in the calculation features, the sparse format primitive, and the loop scheduling primitive. It is beneficial to improve the determination accuracy of the calculation and primitives, and further improve the determination accuracy and efficiency of the sparse calculation operator, thereby improving the generation accuracy and efficiency of the high-performance sparse tensor program.

[0104] In yet another optional embodiment, the heuristic algorithm includes a simulated annealing algorithm;

[0105] Further, based on reinforcement learning and heuristic algorithms, searching the second design space and determining the target point corresponding to the sparse calculation description from all design points may include:

[0106] The encoding generates a feature vector corresponding to each design point in the first design space;

[0107] Extract a batch of design points from the second design space as the initial search population, use reinforcement learning to navigate the change of the initial search population, and use the simulated annealing algorithm to determine the elimination and reproduction of the initial search population. After several rounds of iteration or search convergence, obtain the target search population; Based on the target search population, determine the target point corresponding to the sparse computation description; Among them, the feature vector corresponding to the design point is used to represent the state of reinforcement learning, the neighbor relationship between design points is used to represent the action of reinforcement learning, and the Q value of reinforcement learning is predicted based on a multi-layer perceptron;

[0108] Moreover, the method may further include:

[0109] Run the sparse computation operator corresponding to the sparse computation operation on the target computing platform to obtain the measured program performance corresponding to the sparse computation operation; The measured program performance is used for the reinforcement learning process of navigating the change of the initial search population.

[0110] In this optional embodiment, it can be understood that reinforcement learning and heuristic algorithms maintain the population explored and updated in multiple rounds and gradually converge to the globally optimal point. Among them, reinforcement learning serves as the navigator for population exploration, and the heuristic algorithm maintains the survival of the fittest of the population itself based on the simulated annealing algorithm. The search metric uses the actual test performance on the target computing platform.

[0111] In this optional embodiment, such as Figure 4The figure shows the adaptive search flow chart of the present invention's embodiment based on reinforcement learning and simulated annealing algorithm. Further, it can be understood that the algorithm inputs the upper limit of the search rounds, the population size of the search, and the hyperparameters related to reinforcement learning, and finally outputs the top k optimal points. In the initialization part, based on the second design space, the population is randomly initialized first. The memory data set D of reinforcement learning is set to be empty. The optimal metric E* of the simulated annealing algorithm is initialized as the optimal performance in the current initial population. This performance measures the primitive configuration represented by the design point and the actual measurement of the program on the target computing platform. In the T-round iterative search, each round of steps includes two parts. First, the population is propagated (moved in the design space) and eliminated (deciding whether the new point stays). Then, the training part of reinforcement learning is carried out. Reinforcement learning uses a multi-layer perceptron to predict the Q value. The input is the feature vector of the point in the design space, and the output is the Q value of each action. The action is mapped to the neighbor relationship in the design space. The training is implemented using a double network of a value network and a target network to prevent quickly falling into local optimality during the search process. For each point s in the current population, the optimal action a is predicted through the value network of reinforcement learning and this action is taken to obtain a new point s'. The performance of the primitive and the program represented by s' is obtained through the actual measurement on the target computing platform. It is determined by the simulated annealing algorithm whether the point s' can replace the point s. At the same time, the reward value that should be obtained by adopting this action a for the seen point s is calculated, and the above information is pieced together into a tuple and recorded in the memory data set D. In each search iteration, a sub-data set is randomly sampled from the memory data set D. For each data in it, the Q value estimated by the target network is used as the label for the loop value network, and the mean square error is used as the loss function to train the value network. After every fixed number of iterations, the weight parameters of the value network are copied to the target network, so that the estimated Q value and the training are more stable and not easily fall into local optimality. Finally, the optimal k primitive configurations are output after the search converges or reaches the target iteration number.

[0112] It can be seen that this optional embodiment can use reinforcement learning to navigate the changes in the initial search population, and use the simulated annealing algorithm to determine the elimination and reproduction of the initial search population. After several rounds of iteration or the search converges, the target search population is obtained, and the target point is further determined, which is beneficial to improving the determination accuracy of the target point, and then improving the determination accuracy and efficiency of the sparse computing operator, thereby improving the generation accuracy and efficiency of the high-performance sparse tensor program.

[0113] In another optional embodiment, before analyzing the computational pattern corresponding to the sparse computation description based on the computational graph in step 103 to obtain the computational characteristics corresponding to the sparse computation description, the method further includes:

[0114] Dividing the computational graph into several sub-computational graphs;

[0115] In addition, analyzing the computational pattern corresponding to the sparse computation description based on the computational graph in step 103 to obtain the computational characteristics corresponding to the sparse computation description may include:

[0116] Analyzing the computational pattern corresponding to the sparse computation description based on the sub-computational graphs divided from the computational graph to obtain the computational characteristics corresponding to the sparse computation description.

[0117] In this optional embodiment, it can be understood that the computational graph is divided into a set of sub-computational graphs with a consistent granularity. Each sub-computational graph represents a combination of multi-layer nested loops and computational assignment statements. The multi-layer nested loops correspond to the respective dimensional axes of the input tensors, and the axes with the same identifier in the input tensor set share the same loop; the loop associated with the sparse attribute axis only traverses the coordinate data structure of the non-zero elements compressed in this dimension; access the corresponding tensor coordinates in the nested loops according to the established computational rules of the operator, then extract the tensor elements for computation, and the assignment statement stores the computation result to the target coordinates of the temporary or output tensor.

[0118] It can be seen that this optional embodiment can divide the computational graph into sub-computational graphs and analyze the computational pattern based on the sub-computational graphs, which is beneficial to improving the determination accuracy of the computational characteristics, thereby improving the addition accuracy of the primitives, and thus improving the generation accuracy and efficiency of the high-performance sparse tensor program.

[0119] In another optional embodiment, encoding to generate a feature vector corresponding to each design point in the first design space may include:

[0120] For each design point in the first design space, translate the strings in the loop scheduling primitive and its parameters, and the sparse format primitive and its parameters corresponding to this design point into numerical types based on the mapping table, and splice the combination of the loop scheduling primitive and the corresponding sparse format primitive corresponding to this design point into a numerical array type as the feature vector corresponding to this design point.

[0121] In this optional embodiment, it can be understood that based on the primitive and parameter combination scheme represented by the points in the design space, the points are converted into feature vector representations. Among them, the strings representing the primitives and axes are converted into numbers through the feature mapping table, the numerical parameters are retained, all the numbers are arranged in the order of the primitive addition rules to form a number list, and then the list is converted into a feature vector. Each feature vector only represents a unique point in the design space.

[0122] It can be seen that this optional embodiment can transform the primitives and their parameters of the design points into corresponding types to form the feature vectors of the design points, which is beneficial to improving the determination accuracy of the feature vectors corresponding to the design points, thereby improving the determination accuracy of the target points, and thus improving the generation accuracy and efficiency of the high-performance sparse tensor program.

[0123] Embodiment 2

[0124] Please refer to Figure 5 , Figure 5 which is a schematic structural diagram of an automatic generation device for a high-performance sparse tensor program disclosed in an embodiment of the present invention. Among them, Figure 5 the described device can be applied to any scenario for automatically generating a high-performance sparse tensor program, and the embodiments of the present invention do not make any limitations. As Figure 5 shown, the automatic generation device for a high-performance sparse tensor program may include:

[0125] A conversion module 201, configured to represent the sparse computing operations input by a user as sparse computing descriptions corresponding to the sparse computing operations based on a domain-specific language; and convert the sparse computing descriptions into computation graphs corresponding to the sparse computing descriptions based on the domain-specific language;

[0126] An analysis module 202, configured to analyze the computation pattern corresponding to the sparse computing description based on the computation graph to obtain the computation features corresponding to the sparse computing description;

[0127] A construction module 203, configured to construct a first design space corresponding to the sparse computing description based on the computation features corresponding to the sparse computing description; the first design space includes a plurality of design points and the neighbor relationships between the design points, and the design points are used to represent the combination configuration schemes of each loop scheduling primitive in the set of loop scheduling primitives for optimizing the sparse computing description and each sparse format primitive in the set of sparse format primitives;

[0128] A determination module 204, configured to determine a target point corresponding to the sparse computing description from all the design points in the first design space; determine a target primitive configuration corresponding to the sparse computing description based on the target point; and determine a sparse computing operator corresponding to the sparse computing operation based on the sparse tensor compiler and the target primitive configuration, where the sparse computing operator is used for generating a high-performance sparse tensor program.

[0129] It can be seen that implementing the device described in the embodiments of the present invention can transform sparse computing operations into computation graphs and construct the first design space and the second design space, and obtain the target primitive configuration by searching the second design space, which is beneficial to improving the determination accuracy and efficiency of the sparse computing operator, and further improving the generation accuracy and efficiency of the high-performance sparse tensor program.

[0130] In an alternative embodiment, the nodes of the computation graph represent tensor operation operations corresponding to the sparse computing operations, and the edges of the computation graph represent tensors corresponding to the sparse computing operations; the tensors include dense tensors and sparse tensors, and the tensors are combined with axes in several dimensions, and the axes are used to define the length and format attributes of the tensors.

[0131] It can be seen that implementing this optional embodiment can determine the meanings represented by the nodes and variables of the computational graph, as well as the presentation form of tensors, which is conducive to improving the determination accuracy of the computational graph, and further improving the determination accuracy of the first design space and the second design space, thereby improving the generation accuracy and efficiency of high-performance sparse tensor programs.

[0132] In another optional embodiment, the determination module 204 determines the target point corresponding to the sparse computation description from all the design points in the first design space. The specific method includes:

[0133] Performing a pruning operation on the first design space and regenerating the neighbor relationships of all design points to obtain a second design space corresponding to the sparse computation description;

[0134] Based on reinforcement learning and heuristic algorithms, search the second design space to determine the target point corresponding to the sparse computation description from all design points.

[0135] It can be seen that implementing this optional embodiment can perform pruning on the first design space to obtain a second design space, and search for the target point through reinforcement learning and heuristic algorithms, which is conducive to improving the determination accuracy of the target point, and further improving the determination accuracy and efficiency of sparse computation operators, thereby improving the generation accuracy and efficiency of high-performance sparse tensor programs.

[0136] In yet another optional embodiment, the axes include sparse-related axes and loop axes; the computational characteristics include the information of the sparse-related axes corresponding to the sparse computation description, the information of the loop axes, and the characteristic information corresponding to the tensors;

[0137] And, the sparse format primitive is used to split and recombine the axes and assign different sparse level attributes to the axes, and the loop scheduling primitive is used to perform splitting, recombination, and parallelization operations on all loop axes after the operation of the sparse format primitive on the axes.

[0138] It can be seen that implementing this optional embodiment can further determine the information and uses included in the computational characteristics, sparse format primitives, and loop scheduling primitives. It is conducive to improving the determination accuracy of computations and primitives, and further improving the determination accuracy and efficiency of sparse computation operators, thereby improving the generation accuracy and efficiency of high-performance sparse tensor programs.

[0139] In yet another optional embodiment, the heuristic algorithm includes a simulated annealing algorithm;

[0140] And, the determination module 204 searches the second design space based on reinforcement learning and heuristic algorithms to determine the target point corresponding to the sparse computation description from all design points. The specific method includes:

[0141] Encoding to generate a feature vector corresponding to each design point in the first design space;

[0142] Extract a batch of design points from the second design space as the initial search population, use reinforcement learning to navigate the changes of the initial search population, and use the simulated annealing algorithm to determine the elimination and reproduction of the initial search population. When iterating for several rounds or the search converges, obtain the target search population; based on the target search population, determine the target points corresponding to the sparse computation description; among them, the feature vector corresponding to the design point is used to represent the state of reinforcement learning, the neighbor relationship between design points is used to represent the actions of reinforcement learning, and the Q value of reinforcement learning is predicted based on a multi-layer perceptron;

[0143] Moreover, the device further includes:

[0144] An actual measurement module, configured to run the sparse computation operator corresponding to the sparse computation operation on the target computing platform to obtain the actual program performance corresponding to the sparse computation operation; the actual program performance is used for the reinforcement learning process of navigating the changes of the initial search population.

[0145] It can be seen that implementing this optional embodiment can use reinforcement learning to navigate the changes of the initial search population, use the simulated annealing algorithm to determine the elimination and reproduction of the initial search population. When iterating for several rounds or the search converges, obtain the target search population, and further determine the target points, which is beneficial to improving the determination accuracy of the target points, and then improving the determination accuracy and efficiency of the sparse computation operator, thereby improving the generation accuracy and efficiency of the high-performance sparse tensor program.

[0146] In another optional embodiment, the device may further include:

[0147] A partitioning module, configured to partition the computation graph into several sub-computation graphs before the analysis module 202 analyzes the computation pattern corresponding to the sparse computation description based on the computation graph to obtain the computation characteristics corresponding to the sparse computation description;

[0148] Moreover, the analysis module 202 analyzes the computation pattern corresponding to the sparse computation description based on the computation graph to obtain the computation characteristics corresponding to the sparse computation description. The specific method includes:

[0149] Based on the sub-computation graphs partitioned from the computation graph, analyze the computation pattern corresponding to the sparse computation description to obtain the computation characteristics corresponding to the sparse computation description.

[0150] In another optional embodiment, the specific method for the determination module 204 to encode and generate the feature vector corresponding to each design point in the first design space includes:

[0151] For each design point in the first design space, translate the strings in the loop scheduling primitive and its parameters, and the sparse format primitive and its parameters corresponding to the design point into numerical types based on the mapping table, and concatenate the combination of the loop scheduling primitive and the corresponding sparse format primitive corresponding to the design point into a numerical array type as the feature vector corresponding to the design point.

[0152] It can be seen that implementing this optional embodiment can divide the computational graph into sub-computational graphs and analyze the computational pattern based on the sub-computational graphs, which is beneficial to improving the determination accuracy of computational features, thereby improving the addition accuracy of primitives, and thus improving the generation accuracy and efficiency of high-performance sparse tensor programs.

[0153] Embodiment III

[0154] Please refer to Figure 6 , Figure 6 which is a schematic structural diagram of another automatic generation device for high-performance sparse tensor programs disclosed in the embodiments of the present invention. As Figure 6 shown, the automatic generation device for high-performance sparse tensor programs may include:

[0155] A memory 501 storing executable program code;

[0156] A processor 502 coupled to the memory 501;

[0157] The processor 502 calls the executable program code stored in the memory 501 and executes the steps in the method for automatically generating high-performance sparse tensor programs described in Embodiment I of the present invention.

[0158] Embodiment IV

[0159] The embodiments of the present invention disclose a computer storage medium storing computer instructions, which are used to execute the steps in the method for automatically generating high-performance sparse tensor programs described in Embodiment I of the present invention when the computer instructions are called.

[0160] Embodiment V

[0161] The embodiments of the present invention disclose a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer program is operable to cause a computer to execute the steps in the method for automatically generating high-performance sparse tensor programs described in Embodiment I.

[0162] The system embodiments described above are merely illustrative. The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed to multiple network modules. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art can understand and implement it without creative work.

[0163] Through the specific descriptions of the above embodiments, those skilled in the art can clearly understand that each implementation manner can be realized by means of software plus a necessary general hardware platform, and of course, it can also be realized by hardware. Based on such an understanding, the essence of the above technical solution, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, and the storage medium includes read-only memory (ROM), random access memory (RAM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), one-time programmable read-only memory (OTPROM), electrically-erasable programmable read-only memory (EEPROM), compact disc read-only memory (CD-ROM) or other optical disc memories, magnetic disk memories, tape memories, or any other computer-readable medium capable of carrying or storing data.

[0164] Finally, it should be noted that: what is disclosed in an automatic generation method and device for a high-performance sparse tensor program disclosed in the embodiments of the present invention is only the preferred embodiments of the present invention, only for explaining the technical solutions of the present invention, rather than limiting it; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements on some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. An automatic generation method for a high-performance sparse tensor program, characterized in that, The method includes: Representing the sparse computing operations input by the user as sparse computing descriptions corresponding to the sparse computing operations based on a domain-specific language; Converting the sparse computing descriptions into computing graphs corresponding to the sparse computing descriptions based on the domain-specific language; Analyzing the computing patterns corresponding to the sparse computing descriptions based on the computing graphs to obtain the computing features corresponding to the sparse computing descriptions; Constructing a first design space corresponding to the sparse computing descriptions based on the computing features corresponding to the sparse computing descriptions; the first design space contains a number of design points and the neighbor relationships between the design points, and the design points are used to represent the combined configuration schemes of each loop scheduling primitive in the loop scheduling primitive set for optimizing the sparse computing descriptions and each sparse format primitive in the sparse format primitive set; Determining a target point corresponding to the sparse computing descriptions from all the design points in the first design space; Determining a target primitive configuration corresponding to the sparse computing descriptions based on the target point; Determining a sparse computing operator corresponding to the sparse computing operations based on a sparse tensor compiler and the target primitive configuration, and the sparse computing operator is used for generating a high-performance sparse tensor program.

2. The automatic generation method of the high-performance sparse tensor program according to claim 1, characterized in that The nodes of the computing graph represent the tensor operation operations corresponding to the sparse computing operations, and the edges of the computing graph represent the tensors corresponding to the sparse computing operations; the tensors include dense tensors and sparse tensors, and the tensors are combined with axes in several dimensions, and the axes are used to define the length and format attributes of the tensors.

3. The automatic generation method of the high-performance sparse tensor program according to claim 1, wherein The determining a target point corresponding to the sparse computing descriptions from all the design points in the first design space includes: Performing a pruning operation on the first design space and regenerating the neighbor relationships of all the design points to obtain a second design space corresponding to the sparse computing descriptions; Searching the second design space based on reinforcement learning and a heuristic algorithm to determine a target point corresponding to the sparse computing descriptions from all the design points.

4. The automatic generation method of the high-performance sparse tensor program according to claim 2, wherein The axes include sparse-related axes and loop axes; the computing features include the information of the sparse-related axes corresponding to the sparse computing descriptions, the information of the loop axes, and the feature information corresponding to the tensors; In addition, the sparse format primitive is used to split and recombine the axes and assign different sparse level attributes to the axes, and the loop scheduling primitive is used to perform all the splitting, recombination, and parallelization operations of the loop axes after the operation of the sparse format primitive on the axes.

5. The automatic generation method of the high-performance sparse tensor program according to claim 3, characterized in that, The heuristic algorithm includes a simulated annealing algorithm; In addition, the searching the second design space based on reinforcement learning and a heuristic algorithm to determine a target point corresponding to the sparse computing descriptions from all the design points includes: Encoding and generating a feature vector corresponding to each design point in the first design space; Extract a batch of design points from the second design space as the initial search population, navigate the change of the initial search population with reinforcement learning, and determine the elimination and reproduction of the initial search population with the simulated annealing algorithm. When several rounds of iteration or search convergence are reached, obtain the target search population; based on the target search population, determine the target point corresponding to the sparse calculation description; wherein, the feature vector corresponding to the design point is used to represent the state of reinforcement learning, the neighbor relationship between the design points is used to represent the action of reinforcement learning, and the Q value of reinforcement learning is predicted based on a multi-layer perceptron; Moreover, the method further includes: Run the sparse calculation operator corresponding to the sparse calculation operation on the target calculation platform to obtain the measured program performance corresponding to the sparse calculation operation; the measured program performance is used for the reinforcement learning process of navigating the change of the initial search population.

6. The automatic generation method of the high-performance sparse tensor program according to claim 1, wherein Before analyzing the calculation pattern corresponding to the sparse calculation description based on the calculation graph to obtain the calculation features corresponding to the sparse calculation description, the method further includes: Divide the calculation graph into several sub-calculation graphs; Moreover, analyzing the calculation pattern corresponding to the sparse calculation description based on the calculation graph to obtain the calculation features corresponding to the sparse calculation description includes: Based on the sub-calculation graphs divided from the calculation graph, analyze the calculation pattern corresponding to the sparse calculation description to obtain the calculation features corresponding to the sparse calculation description.

7. The automatic generation method of the high-performance sparse tensor program according to claim 5, characterized in that, The encoding to generate the feature vector corresponding to each design point in the first design space includes: For each design point in the first design space, translate the strings in the loop scheduling primitive and its parameters, and the sparse format primitive and its parameters corresponding to the design point into numerical types based on the mapping table, and splice the combination of the loop scheduling primitive corresponding to the design point and the corresponding sparse format primitive into a numerical array type as the feature vector corresponding to the design point.

8. A high-performance sparse tensor program automatic generation device, characterized in that: The device includes: A conversion module, configured to represent the sparse calculation operation input by the user as the sparse calculation description corresponding to the sparse calculation operation based on the domain-specific language; and convert the sparse calculation description into the calculation graph corresponding to the sparse calculation description based on the domain-specific language; An analysis module, configured to analyze the calculation pattern corresponding to the sparse calculation description based on the calculation graph to obtain the calculation features corresponding to the sparse calculation description; A construction module, configured to construct the first design space corresponding to the sparse calculation description based on the calculation features corresponding to the sparse calculation description; the first design space includes several design points and the neighbor relationship between the design points, and the design points are used to represent the combined configuration scheme of each loop scheduling primitive in the set of loop scheduling primitives for optimizing the sparse calculation description and each sparse format primitive in the set of sparse format primitives; A determination module, configured to determine a target point corresponding to the sparse computation description from all the design points in the first design space; determine a target primitive configuration corresponding to the sparse computation description based on the target point; and determine a sparse computation operator corresponding to the sparse computation operation based on a sparse tensor compiler and the target primitive configuration, where the sparse computation operator is used for generating a high-performance sparse tensor program.

9. An automatic generation device for a high-performance sparse tensor program, characterized in that, The apparatus includes: A memory storing executable program code; A processor coupled to the memory; The processor invokes the executable program code stored in the memory and executes the steps in the method for automatically generating a high-performance sparse tensor program according to any one of claims 1-7.

10. A computer storage medium, characterized in that The computer storage medium stores computer instructions, which, when invoked, execute the steps in the method for automatically generating a high-performance sparse tensor program according to any one of claims 1-7.

Citation Information

Cited By

  • Sparse accelerator customization method and related device

    CN121072625A