Template calculation program block size prediction method and system based on LCE machine learning
The LCE machine learning-based method for block size prediction in template calculations addresses the complexity of determining optimal block sizes by synthesizing training data and optimizing calculation rate, enhancing performance and efficiency.
Patent Information
- Application Number
- CN202411258149.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-09
- Publication Date
- 2024-12-06
AI Technical Summary
The challenge of determining optimal block size for template calculations in single time steps is difficult due to the complexity of factors affecting performance, making existing methods time-consuming and requiring professional knowledge, and machine learning-based approaches often suffer from unpredictable results due to hyperparameters and neural network complexity.
A method and system using LCE machine learning to predict block size by synthesizing training data, extracting overall and fine-grained features, and employing grid search and cross-validation to optimize block size selection, focusing on calculation rate rather than direct block size prediction.
Enables fast and accurate block size selection for single time step template calculations, improving program parallelism and data locality, and achieving efficient template calculation performance.
Smart Images

Figure CN119089205A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of high performance computing, and in particular relates to a method and system for predicting the block size of a template computing program based on LCE machine learning. Background Art
[0002] Stencil computation is a very important computing mode, and its basic feature is to traverse the spatial grid in a loop, read the values of the grid points in the adjacent area of each point during the traversal, and update each point in the spatial grid with a fixed computing mode (or template). Stencil computation can be simply divided into Jacobi type and Gauss-Seidel type according to the different iteration methods. The Gauss-Seidel type reads and writes on the same array, and is highly dependent on the execution order, which limits the optimization of its locality and parallelism. Therefore, the iteration method of stencil computation optimized by the present invention is Jacobi type.
[0003] As the development speed of Moore's Law slows down, computing platforms that only use traditional multi-core architectures can no longer meet the computing performance requirements in the field of scientific computing. Multi-core architectures with powerful computing capabilities, such as GPUs, provide a strong guarantee for the acceleration of computing-intensive applications. However, unlike traditional multi-core architectures, GPUs are composed of thousands of streaming processors (SPs) and a small number of control units, which require the CPU to control and call.
[0004] With the advancement of CPU hardware and the proposal and development of new architectures such as GPU, the performance of hardware has been continuously improved, and the scale of the system has been continuously expanded, providing powerful computing power. However, in the actual application running process, the computing power used often cannot even reach 50% of the theoretical peak value. Therefore, the code quality of the application itself has become the main bottleneck restricting the improvement of computing efficiency in high-performance computing systems. The performance hotspots of most scientific computing programs are often concentrated in the nested loop code part. Loop optimization, as a very effective program performance optimization method, includes loop unrolling, loop skew, loop blocking and other technologies. Among them, loop blocking, as a memory access optimization technology, effectively improves the locality of the program by changing the execution order of the loop. After the loop blocking technology divides the iteration space of the template calculation into different blocks, they can be assigned to different computing cores (generally assigned to different blocks in CUDA) for calculation. It can be executed in parallel under the premise of satisfying data dependencies, further improving the computing performance of the template calculation.
[0005] However, for loop blocking technology, different blocking algorithms adopt different blocking ideas, and different computing platform architectures will also affect the actual performance of the nested loop program after actual blocking. In addition, the choice of block size will also have an important impact on the performance of the code after blocking, and is often affected by multiple factors such as the characteristics of the program itself and the size of the problem, making it difficult to quickly obtain the best block size. Template calculations can be divided into single time steps without cross-iteration dependencies and multi-time step template calculations with cross-iteration dependencies according to whether they contain time steps. Since single-time step template calculations do not have cross-iteration dependencies, they can be directly optimized using rectangular blocks, so it is necessary to focus on the selection of block size.
[0006] Since there are many factors that affect the performance of the program after segmentation, the existing segmentation size selection based on static analysis methods and empirical search often requires corresponding professional knowledge and is relatively time-consuming. The segmentation size selection method based on machine learning can quickly complete online prediction and obtain a better segmentation size after completing offline training on a specific platform. However, the existing segmentation size selection research based on machine learning often predicts the segmentation size based on a neural network model. However, the number of neural network layers, the number of neurons and the numerous hyperparameters in the training process will have a great impact on the final model prediction results, and it is difficult to form a theoretical basis. Summary of the invention
[0007] The technical problem to be solved by the present invention is to provide a template calculation program block size prediction method and system based on LCE machine learning in response to the deficiencies in the above-mentioned prior art, which is used to solve the technical problem that the block size is difficult to determine after the rectangular blocking method is used for template calculation in a single time step, and to efficiently solve the optimal cyclic block size.
[0008] The present invention adopts the following technical solutions:
[0009] The template calculation program block size prediction method based on LCE machine learning is characterized by comprising the following steps:
[0010] S1. For single time step template calculation, generate training data by artificially synthesizing template calculation programs with different feature values;
[0011] S2, limiting and collecting the training data obtained in step S1 in combination with the characteristics of actual applications, hardware platform resources, and GPU parallel features;
[0012] S3, using the training data obtained in step S2 as the training set of the template calculation program for predicting the block size of the TSS_LCE model, and the template calculation program as the test set to pre-train the TSS_LCE model, and select the optimal TSS_LCE model parameters through grid search method and five-fold cross validation;
[0013] S4, extracting overall features and fine-grained features from the template calculation program as input to the machine learning model;
[0014] S5. The machine learning model uses the calculation rate of the template calculation program as the output of the TSS_LCE model, and performs corresponding preprocessing operations on the TSS_LCE model output to obtain the optimal block size.
[0015] Preferably, the overall features include:
[0016] A set of problem size vectors of the form (N, M, L) of the upper limit size of the loop layer from the outside to the inside;
[0017] A set of grid number vectors of the form (I, O) of the template calculation input grid and output grid numbers, and the number of data P that the template calculation needs to access in a single iteration;
[0018] Fine-grained features include:
[0019] Such as the average value of the access distance of all layers of all input grids (avg_di, avg_dj, avg_dk) and the maximum value of the access distance of all layers of all input grids (max_di, max_dj, max_dk);
[0020] The size of the recurrent chunks is taken as a set of features as input to the model.
[0021] Preferably, in step S2, for a set of (N, M, L) vectors, the calculation rate S is:
[0022]
[0023] Among them, SUM is the total number of iterations, time is the execution time of the program, and N, M, and L represent the upper limit of the vector loop layer respectively.
[0024] Preferably, the post-processing of step S3 is specifically as follows:
[0025] Traverse all the block sizes of the prediction space and predict the calculation rate of the program after the block;
[0026] Group the problems according to their size, find the best computing rate in each group, and obtain the corresponding index;
[0027] According to the obtained index, the corresponding feature vector is obtained in reverse order, and the corresponding block size is extracted, that is, the optimal block size under each problem scale is obtained.
[0028] Preferably, in step S4, the calculation kernel includes the number of grids, the memory access distance of each input array, and the total number of points.
[0029] Preferably, the training data is generated by using a template calculation program with different artificially synthesized feature values as follows:
[0030] Generate the number of points for each input array based on the total number of points;
[0031] Generate a satisfying subscript for each input array according to the memory access distance and store it in the collection;
[0032] Store each set into the kernel and finally output it according to the format.
[0033] Preferably, in step S5, limiting the feature vector of the generated template calculation kernel includes:
[0034] Limit the number of grids to 2 to 12;
[0035] The total number of points is limited to 7 to 200, and the number of points accessed by each array is limited to less than 30;
[0036] The average memory access distance and maximum memory access distance of each layer are limited to less than 10.
[0037] Preferably, the number of input and output grids ranges from 2 to 12, the single-layer maximum value of the problem scale is set to 512, the single-layer minimum value and the value interval are set to 128, so the optional values of the single-layer problem scale are (128, 256, 384, 512) four, and a total of 64 optional combinations are included for the complete problem; the maximum memory access distance of each layer is 0 to 10; the total number of points is 7 to 200; for the block size, the single-layer minimum value and the value interval are set to 4, the maximum value is 64, and a total of 110 block combinations are included.
[0038] Preferably, in step S6, the mean square error MSE is specifically:
[0039]
[0040] Where n is the number of samples, y i is the true value, is the predicted value.
[0041] In a second aspect, an embodiment of the present invention provides a template calculation program block size prediction system based on LCE machine learning, comprising:
[0042] The data module generates training data for single time step template calculation by artificially synthesizing template calculation programs with different feature values;
[0043] The processing module restricts and collects the training data obtained by the data module based on the characteristics of the actual application, hardware platform resources, and GPU parallel characteristics;
[0044] The module is selected, and the training data obtained by the processing module is used as the training set of the template calculation program to predict the block size of the TSS_LCE model. The template calculation program is used as the test set to pre-train the TSS_LCE model, and the optimal TSS_LCE model parameters are selected through the grid search method and five-fold cross validation;
[0045] The extraction module extracts the overall features and fine-grained features of the template calculation program as the input of the machine learning model;
[0046] In the prediction module, the machine learning model uses the calculation rate of the template calculation program as the output of the TSS_LCE model, and performs corresponding preprocessing operations on the TSS_LCE model output to obtain the optimal block size.
[0047] Compared with the prior art, the present invention has at least the following beneficial effects:
[0048] The block size prediction method of template calculation program based on LCE machine learning, because the template calculation of a single time step does not have cross-time step dependencies, there is no need to design a complex block strategy. Only simple rectangular blocks are needed to change the iterative execution order and improve locality. Therefore, the optimization of single time step template calculation is mainly carried out from the perspective of block size selection. However, due to the many factors that affect the performance of the program after block partitioning, the block size selection based on static analysis methods and empirical search methods often requires corresponding professional knowledge and is relatively time-consuming. The block size selection method based on machine learning can quickly complete online prediction after offline training on a specific platform to obtain a better block size. Block size selection based on machine learning is essentially a task of regression prediction. Therefore, from the perspective of regression prediction, this paper selects the latest ensemble learning method LCE as the basis to build a block size selection model.
[0049] Further, in order to establish a more accurate block size model, the present invention extracts features from two granularities of the template computing program to obtain its overall features and fine-grained features. At the same time, in order to make the model more robust, the block size is not directly predicted, but is also used as a set of features. The overall features of the template computing program mainly refer to the three groups of features of the problem scale, the number of grids and the total number of points. The problem scale is selected as a general feature value. The problem scale is a directly related feature in the block size selection model. It can be expressed as a set of vectors in the form of (N, M, L), indicating the upper limit of the loop layer from outside to inside. For the same template computing program, its optimal block size will be different under different problem scales. More importantly, the problem scale will directly affect the number of thread blocks called by the program after the block. The relationship between the problem scale and the performance obtained by the optimal block size is not linear, so it is difficult to construct a prediction model of the block size according to the change of the problem scale in practical applications. Therefore, the model proposed by the present invention uses the problem scale as a feature value to obtain better prediction accuracy. Secondly, the number of grids is selected as a general eigenvalue. The number of grids refers to the number of input grids (i.e., read arrays) and output grids (i.e., write arrays) of template calculations, which can be represented as a set of vectors in the form of (I, O). They will directly affect the read and write mode of template calculations and the mode of data access, thereby affecting the execution performance of the program, so they are introduced as eigenvalues. Finally, the total number of points is selected as a general eigenvalue. The total number of points refers to the number of data that the template calculation needs to access in a single iteration, which can be represented as P. The total number of points reflects the overall number of single memory accesses, so it is introduced into the feature to enhance the accuracy of the model.
[0050] The fine-grained features of template calculation mainly refer to the locality features of each layer of loops; data locality is very important for the block size selection model and directly affects the performance that can be obtained by the block; the locality feature values selected by the present invention are composed of the locality feature values of multidimensional loops, which mainly refer to the memory access distance of each layer in a single iteration, which describes the distance of the data that the template calculation program needs to read in at each layer in a single iteration. Introducing the locality feature values of each layer of loops can enable the model to learn the laws related to locality and make it more accurate. In addition, since there may be more than one template calculation input grid, the locality feature values of different input grids may be completely different, so the locality feature values selected in this paper will be described from the overall perspective and the individual perspective. The overall perspective is described by the average memory access distance, that is, the average value of the memory access distance of all input grids (calculated separately for each layer), while the individual perspective is described by the maximum memory access distance, that is, the maximum value of the memory access distance of each layer of all input grids. In addition, in order to improve the robustness of the model and simplify the model, this paper does not directly perform multi-output regression prediction on the block size, but adds it as a set of features to the feature vector.
[0051] Furthermore, compared to the execution time, the calculation rates of different problem sizes are relatively more concentrated, which shows that for the block size selection model under different problem sizes, selecting the calculation rate as the output of the model is more stable than the execution time. Therefore, the block size selection model proposed in the present invention does not directly predict the block size but predicts the calculation rate of the template calculation program of different block sizes, so it is necessary to perform corresponding post-processing on the model output to obtain the optimal block size.
[0052] Furthermore, for the template calculation program of a single time step, it is mainly a three-layer spatial dimensional nested loop program, and different template calculations mainly differ in the statements executed in their loops. There are three core features: the first is the number of grids, which determines the number of input arrays and output arrays; the second is the memory access distance of each input array, which determines the possible subscript range of each input array; the third is the total number of points, which determines the total number of operations of the template calculation.
[0053] Furthermore, in order to achieve a better prediction effect, the block size selection model based on the machine learning method requires a large amount of data with different eigenvalues as training samples. Although there are a large number of template calculation programs in practice, the eigenvectors of these template calculation programs are not widely distributed, and it is difficult to obtain a huge number of eigenvalues with different values, which makes the generalization of the block size selection model insufficient. Therefore, the present invention generates training data for single time step template calculation by artificially synthesizing template calculation programs with different eigenvalues.
[0054] Furthermore, the artificially synthesized template calculation program is highly random. If it is not restricted, too many programs may be generated, which is too different from the actual template calculation program. Therefore, in order to better meet the characteristics of template calculation in actual applications, it is necessary to impose certain restrictions on the feature vectors of the generated template calculation kernel. There are three main restrictions: first, the number of grids is limited to 2-12; second, the total number of points is limited to 7-200, and the number of points accessed by each array is limited to less than 30; third, the average memory access distance and maximum memory access distance of each layer are limited to less than 10. Considering the resources of the hardware platform and the parallel characteristics of the GPU, it is necessary to restrict the combination of problem scale and block size. First, for the problem scale, considering the limitation of storage resources, the maximum value of the single layer of the problem scale is set to 512, and since there is no need to block for a too small problem scale, the minimum value of the single layer and the value interval are set to 128. As for the selection of block size, according to the parallel characteristics of GPU, the single-layer minimum value and value interval are set to 4, and the maximum value depends on the area of the entire block, and its area needs to be less than 1024, thus 110 block combinations can be obtained.
[0055] It can be understood that the beneficial effects of the second aspect mentioned above can be found in the relevant description of the first aspect mentioned above, and will not be repeated here.
[0056] In summary, the present invention realizes the problem of single-time-step Jacobi-type template calculation on GPU architecture, and provides users with a fast solution to the block size selection strategy, which can improve program parallelism and data locality and achieve improved template calculation efficiency.
[0057] The technical solution of the present invention is further described in detail below through the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0058] Figure 1 This is the overall architecture diagram of the TSS_LCE model proposed in the present invention to predict the optimal block;
[0059] Figure 2 This is a comparison chart of the prediction effects of various machine learning algorithms and LCE algorithm;
[0060] Figure 3 The performance comparison chart of the samples extracted from the actual application, where (a) is case 1, (b) is case 2, (c) is case 3, (d) is case 4, and (e) is case 5;
[0061] Figure 4 This is a performance comparison chart of artificially synthesized complex samples;
[0062] Figure 5 This is a performance comparison chart of the TSS_LCE model on the random problem scale;
[0063] Figure 6 This is a performance comparison chart of the TSS_LCE model and the ARTEMIS automatic optimization framework;
[0064] Figure 7 A schematic diagram of a computer device provided by an embodiment of the present invention;
[0065] Figure 8 The block diagram of a chip provided according to an embodiment of the present invention. DETAILED DESCRIPTION
[0066] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0067] In the description of the present invention, it should be understood that the terms “include” and “comprises” indicate the presence of described features, wholes, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or collections thereof.
[0068] It should also be understood that the terms used in the present specification are only for the purpose of describing specific embodiments and are not intended to limit the present invention. As used in the present specification and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.
[0069] It should be further understood that the term "and / or" used in the present specification and the appended claims refers to any combination of one or more of the associated listed items and all possible combinations, and includes these combinations. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in the present invention generally indicates that the associated objects are in an "or" relationship.
[0070] It should be understood that, although the terms first, second, third, etc. may be used to describe preset ranges, etc. in the embodiments of the present invention, these preset ranges should not be limited to these terms. These terms are only used to distinguish preset ranges from each other. For example, without departing from the scope of the embodiments of the present invention, the first preset range may also be referred to as the second preset range, and similarly, the second preset range may also be referred to as the first preset range.
[0071] The word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrases "if it is determined" or "if (stated condition or event) is detected" may be interpreted as "when it is determined" or "in response to determining" or "when detecting (stated condition or event)" or "in response to detecting (stated condition or event)", depending on the context.
[0072] Various structural schematic diagrams of the embodiments disclosed in the present invention are shown in the accompanying drawings. These figures are not drawn to scale, and some details are magnified and some details may be omitted for the purpose of clear expression. The shapes of various regions and layers shown in the figures and the relative sizes and positional relationships therebetween are only exemplary, and may deviate in practice due to manufacturing tolerances or technical limitations, and those skilled in the art may additionally design regions / layers with different shapes, sizes, and relative positions according to actual needs.
[0073] The present invention provides a template calculation program block size prediction method based on LCE machine learning. First, the model input is composed of the overall features and fine-grained features extracted from the template calculation and the block size combination generated by the prediction space; in addition, the model output is the calculation rate obtained by the model prediction; finally, the post-processing part uses the prediction space and screening to obtain the optimal calculation rate to obtain the final optimal block size. The present invention provides users with a fast solution to the block size selection strategy under the problem of single-time-step Jacobi template calculation on the GPU architecture, which can improve program parallelism and data locality and achieve the improvement of template calculation efficiency.
[0074] See also Figure 1 The present invention provides a template calculation program block size prediction method based on LCE machine learning, comprising the following steps:
[0075] S1, extracting features from the template calculation program;
[0076] The template calculation program is feature extracted from two granularities, namely, overall features and fine-grained features. Taking the three-dimensional template calculation of a single time step as an example, the overall features mainly include: a set of problem scale vectors such as the upper limit size of the loop layer from outside to inside (N, M, L), a set of grid number vectors such as the number of input grids and output grids of the template calculation (I, O), and the number of data P that the template calculation needs to access in a single iteration; fine-grained features, namely the locality features of each layer loop, include:
[0077] Such as the average value of the memory access distance of all layers of all input grids (avg_di, avg_dj, avg_dk) and the maximum value of the memory access distance of all layers of all input grids (max_di, max_dj, max_dk); in addition, in order to further improve the robustness of the model, the size of the loop block is used as a set of features as the input of the model.
[0078] S2, using the calculation rate of the template calculation program as the output of the block size selection model (TSS_LCE model);
[0079] The block size selection model proposed in the present invention does not directly use the block size as the output of the model, but uses the performance of the program as the prediction result; the execution time is the most direct performance expression of the template calculation program, and the discrete coefficient is introduced to compare the fluctuation of the block size and the program performance according to formula (1).
[0080]
[0081] Among them, s represents the standard deviation of the data, Represents the average of the data.
[0082] However, for optimal block prediction under variable problem scale, different problem scales will cause significant changes in the execution time of the program.
[0083] Specifically, in order to reduce the impact of the problem scale on performance prediction, the present invention converts the execution time of the program into a calculation rate, that is, the number of iterations that can be executed per unit time S; the calculation rate of the program is calculated according to formula (2), which is as follows:
[0084]
[0085] Among them, SUM is the total number of iterations, which is calculated by the problem size, and time is the execution time of the program, which can be measured by related functions.
[0086] S3, post-processing;
[0087] According to the result obtained in step S2, the model output needs to be preprocessed accordingly to obtain the optimal block size. Since step S1 uses the block size as a feature vector, the optional different block sizes constitute a prediction space, and the post-processing process is carried out in the selected prediction space. The specific steps of post-processing are as follows:
[0088] S301, traverse all block sizes of the prediction space and predict the calculation rate of the program after the block division;
[0089] S302, grouping according to different problem sizes, finding the best computing rate in each group, and obtaining its index;
[0090] S303 , reversely obtain the corresponding feature vector according to the obtained index, and extract the corresponding block size therefrom, so as to obtain the optimal block size under each problem scale.
[0091] S4, artificial synthesis template calculation kernel;
[0092] The block size based on machine learning methods requires a large amount of data with different feature values as training samples to achieve a good prediction effect; the artificial synthesis method only needs to synthesize the template calculation kernel according to the features. The core features mainly include:
[0093] The number of grids, the access distance of each input array, and the total number of points.
[0094] The present invention mainly focuses on single time step template calculation, and the specific steps of using the template calculation program with different artificial synthetic feature values to generate training data are as follows:
[0095] S401, generating the number of points of each input array according to the total number of points;
[0096] S402, generating a satisfying subscript for each input array according to the memory access distance, and storing it in a set;
[0097] S403, storing each set into the kernel, and finally outputting it according to the format.
[0098] S5, training data set collection;
[0099] The artificially synthesized template calculation program is highly random. In order to better meet the characteristics of template calculation in practical applications, it is necessary to impose certain restrictions on the feature vectors of the generated template calculation kernel. The main restrictions are as follows:
[0100] First, limit the number of grids to 2 to 12;
[0101] Second, the total number of points is limited to 7 to 200, and the number of points accessed by each array is limited to less than 30;
[0102] Third, the average memory access distance and maximum memory access distance of each layer are limited to less than 10.
[0103] In addition, the present invention takes into account the hardware platform resources and GPU parallel characteristics, and needs to limit the combination of problem scale and block size. The single-layer maximum value of the problem scale is set to 512, and the single-layer minimum value and value interval are set to 128. Therefore, the optional values of the single-layer problem scale are (128, 256, 384, 512) four, and a total of 64 optional combinations are included for the complete problem. For the block size, according to the parallel characteristics of the GPU, the single-layer minimum value and value interval are set to 4, and the maximum value depends on the area of the entire block, for a total of 110 block combinations.
[0104] According to the above limitations, the present invention artificially synthesized 60 programs, each of which generated 7040 data, and then obtained a training set with a data size of about 420,000 data. To ensure the effectiveness of TSS model verification, the data collected in the training set have excluded artificially synthesized programs with the same eigenvalue vector as the experimental test set.
[0105] S6. Model training process.
[0106] Based on the ensemble learning method LCE, the present invention proposes a block size selection model TSS_LCE based on LCE, and selects the mean square error (MSE) calculated according to formula (3) as the evaluation index. The smaller the MSE value, the better the prediction effect of the model.
[0107]
[0108] In addition, the present invention selects the most appropriate parameters as the final parameters of the model through a grid search method and a five-fold cross validation method.
[0109] In another embodiment of the present invention, a template calculation program block size prediction system based on LCE machine learning is provided. The system can be used to implement the above-mentioned template calculation program block size prediction method based on LCE machine learning. Specifically, the template calculation program block size prediction system based on LCE machine learning includes a data module, a processing module, a selection module, an extraction module and a prediction module.
[0110] Among them, the data module, for single time step template calculation, generates training data through artificially synthesized template calculation procedures with different feature values;
[0111] The processing module restricts and collects the training data obtained by the data module based on the characteristics of the actual application, hardware platform resources, and GPU parallel characteristics;
[0112] The module is selected, and the training data obtained by the processing module is used as the training set of the template calculation program to predict the block size of the TSS_LCE model. The template calculation program is used as the test set to pre-train the TSS_LCE model, and the optimal TSS_LCE model parameters are selected through the grid search method and five-fold cross validation;
[0113] The extraction module extracts the overall features and fine-grained features of the template calculation program as the input of the machine learning model;
[0114] In the prediction module, the machine learning model uses the calculation rate of the template calculation program as the output of the TSS_LCE model, and performs corresponding preprocessing operations on the TSS_LCE model output to obtain the optimal block size.
[0115] In another embodiment of the present invention, a terminal device is provided, the terminal device includes a processor and a memory, the memory is used to store a computer program, the computer program includes program instructions, and the processor is used to execute the program instructions stored in the computer storage medium. The processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc., which are the computing core and control core of the terminal, which are suitable for implementing one or more instructions, and are specifically suitable for loading and executing one or more instructions to implement corresponding method processes or corresponding functions; the processor described in the embodiment of the present invention can be used for the operation of the template calculation program block size prediction method based on LCE machine learning, including:
[0116] For single time step template calculation, training data is generated by artificially synthesizing template calculation programs with different eigenvalues; the obtained training data is restricted and collected in combination with the characteristics of actual applications as well as the hardware platform resources and GPU parallel features; the obtained training data is used as the training set of the TSS_LCE model for predicting the block size of the template calculation program, and the template calculation program is used as the test set to pre-train the TSS_LCE model, and the optimal TSS_LCE model parameters are selected through grid search method and five-fold cross validation; the template calculation program is subjected to feature extraction of overall features and fine-grained features as the input of the machine learning model; the machine learning model uses the calculation rate of the template calculation program as the output of the TSS_LCE model, and performs corresponding preprocessing operations on the TSS_LCE model output to obtain the optimal block size.
[0117] See also Figure 7 , the terminal device is a computer device. The computer device 60 of this embodiment includes: a processor 61, a memory 62, and a computer program 63 stored in the memory 62 and executable on the processor 61. When the computer program 63 is executed by the processor 61, the method for calculating the fluid composition in the reservoir transformation wellbore in the embodiment is implemented. To avoid repetition, it is not described one by one here. Alternatively, when the computer program 63 is executed by the processor 61, the functions of each model / unit in the template calculation program block size prediction system based on LCE machine learning in the embodiment are implemented. To avoid repetition, it is not described one by one here.
[0118] The computer device 60 may be a computing device such as a desktop computer, a notebook, a PDA, or a cloud server. The computer device 60 may include, but is not limited to, a processor 61 and a memory 62. Those skilled in the art will appreciate that Figure 7 This is only an example of the computer device 60 and does not constitute a limitation of the computer device 60. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the computer device may also include input and output devices, network access devices, buses, etc.
[0119] The processor 61 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0120] The memory 62 may be an internal storage unit of the computer device 60, such as a hard disk or memory of the computer device 60. The memory 62 may also be an external storage device of the computer device 60, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc., equipped on the computer device 60.
[0121] Furthermore, the memory 62 may include both an internal storage unit of the computer device 60 and an external storage device. The memory 62 is used to store computer programs and other programs and data required by the computer device. The memory 62 may also be used to temporarily store data that has been output or is to be output.
[0122] See also Figure 8 , the terminal device is a chip, and the chip 600 of this embodiment includes a processor 622, which may be one or more, and a memory 632 for storing a computer program executable by the processor 622. The computer program stored in the memory 632 may include one or more modules, each corresponding to a set of instructions. In addition, the processor 622 may be configured to execute the computer program to execute the above-mentioned template calculation program block size prediction method based on LCE machine learning.
[0123] In addition, the chip 600 may further include a power supply component 626 and a communication component 650, wherein the power supply component 626 may be configured to perform power management of the chip 600, and the communication component 650 may be configured to implement communication, for example, wired or wireless communication, of the chip 600. In addition, the chip 600 may further include an input / output interface 658. The chip 600 may operate based on an operating system stored in the memory 632.
[0124] In another embodiment of the present invention, the present invention also provides a storage medium, specifically a computer-readable storage medium, which is a memory device in a terminal device for storing programs and data. It can be understood that the computer-readable storage medium here can include both the built-in storage medium in the terminal device and the extended storage medium supported by the terminal device. The computer-readable storage medium provides a storage space, which stores the operating system of the terminal. In addition, one or more instructions suitable for being loaded and executed by the processor are also stored in the storage space, and these instructions can be one or more computer programs. It should be noted that the computer-readable storage medium here can be a high-speed RAM memory, or a non-volatile memory (Non-VolatileMemory), such as at least one disk memory.
[0125] The processor may load and execute one or more instructions stored in a computer-readable storage medium to implement the corresponding steps of the template calculation program block size prediction method based on LCE machine learning in the above embodiment; the processor may load and execute the following steps:
[0126] For single time step template calculation, training data is generated by artificially synthesizing template calculation programs with different eigenvalues; the obtained training data is restricted and collected in combination with the characteristics of actual applications as well as the hardware platform resources and GPU parallel features; the obtained training data is used as the training set of the TSS_LCE model for predicting the block size of the template calculation program, and the template calculation program is used as the test set to pre-train the TSS_LCE model, and the optimal TSS_LCE model parameters are selected through grid search method and five-fold cross validation; the template calculation program is subjected to feature extraction of overall features and fine-grained features as the input of the machine learning model; the machine learning model uses the calculation rate of the template calculation program as the output of the TSS_LCE model, and performs corresponding preprocessing operations on the TSS_LCE model output to obtain the optimal block size.
[0127] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all of the embodiments. The components of the embodiments of the present invention described and shown in the drawings here can usually be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present invention provided in the drawings is not intended to limit the scope of the claimed invention, but merely represents selected embodiments of the present invention. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0128] Application Examples
[0129] In the experimental environment where the CPU is Intel(R) Xeon(R) Gold 6248@2.5GHz, the GPU is Titan V (memory 12GB), the operating system is Linux 3.10.0, the CUDA version is 11.1.74, and the Tesla V100 (memory 32GB), the operating system is Ubuntu 20.04, the CUDA version is 11.7.99, and the Python version is 3.7, the effectiveness of the block size selection model TSS_LCE for single time step template calculation is verified in the following three aspects:
[0130] First, as Figure 2 As shown in the experimental results, in order to prove that the LCE algorithm selected by the present invention has better applicability in the selection of block size, five representative machine learning algorithms, namely, multivariate linear regression algorithm (MLP), XGBoost algorithm (xgb), random forest algorithm (rf), ridge regression algorithm (ridge) and Lasso regression algorithm (lasso), are selected for comparison with the LCE algorithm, and are trained on the data set obtained in S5 respectively, and then predicted on 7 test samples, and the mean square error loss (MSE) is calculated. The ordinate in the figure is the value after the normalization of the mean square error obtained by the LCE algorithm. Since the mean square error of some algorithms is too large relative to LCE, the ordinate is logarithmically transformed. When the value is greater than 0.1, it means that the MSE is greater than the LCE algorithm. At this time, the prediction effect of the algorithm is worse than that of the LCE algorithm, otherwise it is better than the LCE algorithm.
[0131] By comparing the algorithms, it can be seen that the overall prediction effect of the LCE algorithm is better than the other five machine learning algorithms mentioned above. Therefore, the present invention finally selects the LCE algorithm as the core of the block size selection model.
[0132] Second, if Figure 3 , 4As shown in the experimental results, this part evaluates the performance of the single time step template calculation block size selection model TSS_LCE proposed in this paper compared with the current most recent single time step template calculation block size selection model AutoSTA-pro by recording the performance of the cyclic block code of the selected block size. At the same time, the present invention uses a global search method on 7 test samples to normalize the performance of the optimal block size obtained by the two prediction methods to predict the block size. Whether in actual applications or in artificially synthesized complex samples, the TSS_LCE model proposed in the present invention can predict the block size more accurately, and the prediction effect under different problem scales can remain relatively stable at more than 95%.
[0133] In addition, the TSS_LCE model can achieve the same effect as the global search method in most cases. However, compared with the global search method, which requires a time-consuming search process every time to find the optimal block, the TSS_LCE model proposed in the present invention, with the help of a machine learning algorithm, only needs to perform a relatively time-consuming data collection and training process on a specific platform, and then the optimal block size can be quickly predicted. This method is more conducive to practical use.
[0134] Third, the present invention tests the scalability performance of the TSS_LCE model under random problem scale (problem scale outside the training sample). Since the performance difference between the artificially synthesized complex template and the actual extracted template calculation program is not large, the experiments are mainly carried out on 5 samples extracted from actual applications (6 groups of problem scales are randomly selected for each sample, including 3 groups of relatively regular problem scales and 3 groups of numerically random problem scales). The experimental results are shown in the figure. Figure 5 As shown in the figure, the vertical axis represents the normalized result of the optimal block performance obtained by global search, the horizontal axis represents the combination of different problem scales, and the last group is the average value of each sample.
[0135] On the whole, the prediction model proposed in the present invention can ensure that the block size performance of all samples is stable at more than 96% of the optimal block performance on these random problem scales. This proves that the block size selection model proposed in the present invention can achieve good results on any problem scale.
[0136] Fourth, the present invention compares the performance of the TSS_LCE model with that of the automatic optimization framework ARTEMIS for optimizing single time step template calculations. The test samples selected in this section are consistent with those in the third section, and the best performance obtained by the model of the present invention is normalized to the performance of the ARTEMIS optimization code. The experimental results are shown in Figure 6 shown.
[0137] The results show that the single time step template calculation block size selection model proposed in the present invention shows performance close to ARTEMIS in Case 1 and Case 2, with an average performance of 98.5% and 99.8% of ARTEMIS, while its performance in the other three samples exceeds ARTEMIS. Compared with ARTEMIS, the average performance of TSS_LCE proposed in the present invention is improved by 1%, 21% and 37% respectively. However, ARTEMIS is an automatic optimization framework that includes multiple optimization combinations, but the optimization methods in these optimization combinations sometimes cause negative optimization due to GPU resource limitations, and therefore may not be as good as a single block optimization method. However, if a global search is performed to obtain the optimal optimization combination, its very large search space is not conducive to practical use.
[0138] In summary, the present invention provides a method and system for predicting the block size of a template calculation program based on LCE machine learning, which provides users with a fast solution to the block size selection strategy for the problem of single-time-step Jacobi-type template calculation on a GPU architecture, thereby improving program parallelism and data locality and achieving improved template calculation efficiency.
[0139] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.
[0140] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0141] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed in the present invention can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0142] In the embodiments provided by the present invention, it should be understood that the disclosed devices / terminals and methods can be implemented in other ways. For example, the device / terminal embodiments described above are only schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0143] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0144] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0145] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present invention implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium, etc. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.
[0146] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices, and computer program products according to the embodiments of the present application. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0147] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0148] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0149] The above contents are only for explaining the technical idea of the present invention and cannot be used to limit the protection scope of the present invention. Any changes made on the basis of the technical solution in accordance with the technical idea proposed by the present invention shall fall within the protection scope of the claims of the present invention.
Claims
1. A template calculation program block size prediction method based on LCE machine learning, characterized in that: The following steps are involved: S1. For single time step template calculation, training data is generated by artificially synthesizing template calculation programs with different feature values; S2, limiting and collecting the training data obtained in step S1 in combination with the characteristics of actual applications, hardware platform resources, and GPU parallel features; S3, using the training data obtained in step S2 as the training set of the template calculation program for predicting the block size of the TSS_LCE model, and the template calculation program as the test set to pre-train the TSS_LCE model, and select the optimal TSS_LCE model parameters through grid search method and five-fold cross validation; S4, extracting overall features and fine-grained features from the template calculation program as input to the machine learning model; S5. The machine learning model uses the calculation rate of the template calculation program as the output of the TSS_LCE model, and performs corresponding preprocessing operations on the TSS_LCE model output to obtain the optimal block size.
2. The template calculation program block size prediction method based on LCE machine learning according to claim 1 is characterized in that: The overall features include: A set of problem size vectors of the form (N, M, L) of the upper limit size of the loop layer from the outside to the inside; A set of grid number vectors of the form (I, O) of the template calculation input grid and output grid number, and the number of data P that the template calculation needs to access in a single iteration; Fine-grained features include: Such as the average value of the access distance of all layers of all input grids (avg_di, avg_dj, avg_dk) and the maximum value of the access distance of all layers of all input grids (max_di, max_dj, max_dk); The size of the recurrent chunks is taken as a set of features as input to the model.
3. The template calculation program block size prediction method based on LCE machine learning according to claim 1 is characterized in that: In step S2, for a set of (N, M, L) vectors, the rate S is calculated as: Among them, SUM is the total number of iterations, time is the execution time of the program, and N, M, and L represent the upper limit of the vector loop layer respectively.
4. The template calculation program block size prediction method based on LCE machine learning according to claim 1 is characterized in that: The post-processing of step S3 is specifically as follows: Traverse all the block sizes of the prediction space and predict the calculation rate of the program after the block; Group the problems according to their size, find the best computing rate in each group, and obtain the corresponding index; According to the obtained index, the corresponding feature vector is obtained in reverse order, and the corresponding block size is extracted, that is, the optimal block size under each problem scale is obtained.
5. The template calculation program block size prediction method based on LCE machine learning according to claim 1 is characterized in that: In step S4, the calculation kernel includes the number of grids, the memory access distance of each input array, and the total number of points.
6. The template calculation program block size prediction method based on LCE machine learning according to claim 5 is characterized in that: The training data is generated by using a template calculation program with different artificial synthetic feature values as follows: Generate the number of points for each input array based on the total number of points; Generate a satisfying subscript for each input array according to the memory access distance and store it in the collection; Store each set into the kernel and finally output it according to the format.
7. The template calculation program block size prediction method based on LCE machine learning according to claim 1 is characterized in that: In step S5, the feature vector of the generated template calculation kernel is restricted, including: Limit the number of grids to 2 to 12; The total number of points is limited to 7 to 200, and the number of points accessed by each array is limited to less than 30; The average memory access distance and maximum memory access distance of each layer are limited to less than 10.
8. The template calculation program block size prediction method based on LCE machine learning according to claim 7 is characterized in that: The number of input and output grids ranges from 2 to 12, the single-layer maximum value of the problem scale is set to 512, the single-layer minimum value and the value interval are set to 128, so the optional values of the single-layer problem scale are 128, 256, 384, 512, and a total of 64 optional combinations for the complete problem; the maximum access distance of each layer is 0 to 10; the total number of points is 7 to 200; for the block size, the single-layer minimum value and the value interval are set to 4, the maximum value is 64, and a total of 110 block combinations are included.
9. The template calculation program block size prediction method based on LCE machine learning according to claim 1 is characterized in that: In step S6, the mean square error MSE is specifically: Where n is the number of samples, y i is the true value, is the predicted value.
10. A template calculation program block size prediction system based on LCE machine learning, characterized in that: include: The data module generates training data for single time step template calculation by artificially synthesizing template calculation programs with different feature values; The processing module restricts and collects the training data obtained by the data module based on the characteristics of the actual application, the hardware platform resources, and the parallel characteristics of the GPU; The module is selected, and the training data obtained by the processing module is used as the training set of the template calculation program to predict the block size of the TSS_LCE model. The template calculation program is used as the test set to pre-train the TSS_LCE model, and the optimal TSS_LCE model parameters are selected through the grid search method and five-fold cross validation; The extraction module extracts the overall features and fine-grained features of the template calculation program as the input of the machine learning model; In the prediction module, the machine learning model uses the calculation rate of the template calculation program as the output of the TSS_LCE model, and performs corresponding preprocessing operations on the TSS_LCE model output to obtain the optimal block size.
Citation Information
Patent Citations
A machine learning-based loop tile size selection method
CN106990995A
Dynamic hybrid partitioning method and system for template calculation program on GPU (Graphics Processing Unit)
CN118467462A
