A performance optimization method, device and electronic device for OpenMP Offload

By integrating kernel function features and dynamically allocating thread counts, the problem of low thread resource utilization rate of OpenMP Offload in heterogeneous architecture systems is solved, performance and resource utilization rate are improved, and data access efficiency is optimized.

CN117407169BActive Publication Date: 2024-11-19ZHENGZHOU UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311467813.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-11-07
Publication Date
2024-11-19
Estimated Expiration
2043-11-07

AI Technical Summary

Technical Problem

OpenMP Offload has low thread resource utilization rate and low performance in heterogeneous architecture systems. It is impossible to dynamically adjust thread allocation according to application characteristics, resulting in low resource utilization efficiency.

Method used

By determining the characteristics of the kernel function, such as cyclically calculating the upper bound, lower bound and dependency, inputting it into the preset learning model for fusion, dynamically allocating the number of threads and thread blocks, optimizing the kernel function and transferring data to shared memory to improve resource utilization Rate.

Benefits of technology

It effectively improves the performance of OpenMP Offload and the thread resource utilization rate of heterogeneous architecture systems, reduces the overhead of kernel functions, and optimizes the storage and reading time of data between GPU and memory.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117407169B_ABST
    Figure CN117407169B_ABST
Patent Text Reader

Abstract

The present invention discloses a performance optimization method, device and electronic device of OpenMP Offload, the method comprising: first determining the number of kernel functions generated by the OpenMP Offload during heterogeneous computing, and determining the characteristics of each kernel function, the characteristics specifically including the upper bound of loop computing, the lower bound of loop computing, whether there is a specification and whether there is a dependency relationship with other kernel functions; inputting the characteristics into a preset learning model, and fusing all kernel functions through the preset learning model; finally, after sending the fused kernel function to a parallel execution domain, determining the program characteristics of the to-be-executed program corresponding to the fused kernel function, and allocating the number of threads and the number of thread blocks according to the program characteristics through the preset learning model. By first reducing the number of kernel functions, and then dynamically allocating threads and thread blocks based on the characteristics of the to-be-executed program corresponding to the kernel function, the performance of OpenMP Offload and the utilization rate of thread resources of the heterogeneous architecture system are effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of computer technology, and specifically relates to a performance optimization method, apparatus and electronic device for OpenMP Offload. Background Technology

[0002] With the development of high-performance computing and artificial intelligence, processors are beginning to shift towards heterogeneous multi-core architectures. Heterogeneous architectures are typically system architectures built from general-purpose computing units (CPUs) plus dedicated computing units (GPUs) or FPGAs (Field-Programmable Gate Arrays) for acceleration. However, because the programming of hardware from different manufacturers is not standardized, heterogeneous programming is needed to unify the programming of heterogeneous architecture systems, making them easier for users to operate.

[0003] OpenMP Offload, a general-purpose parallel programming language in heterogeneous programming, reduces the difficulty and complexity of parallel programming while also offering good flexibility and portability, making it widely used. However, its thread allocation mode is relatively simple, unable to dynamically adjust threads according to the characteristics of the application, resulting in low utilization of thread resources and low performance of OpenMP Offload.

[0004] Therefore, how to improve the utilization rate of thread resources in heterogeneous architecture systems and enhance the performance of OpenMP Offload, a technical problem that needs to be solved by those skilled in the art. Summary of the Invention

[0005] The purpose of this invention is to solve the technical problems of low thread resource utilization and low performance of OpenMP Offload in heterogeneous architecture systems in the prior art.

[0006] To achieve the above technical objectives, in one aspect, the present invention provides a performance optimization method for OpenMP Offload, the method comprising:

[0007] The number of kernel functions generated by the OpenMP Offload during heterogeneous computing is determined, and the characteristics of each kernel function are determined. The specific characteristics include the upper bound of the loop computation, the lower bound of the loop computation, whether there is a reduction, and whether there is a dependency relationship with other kernel functions.

[0008] The features are input into a preset learning model, and all kernel functions are fused through the preset learning model;

[0009] After the fused kernel function is sent to the parallel execution domain, the program characteristics of the program to be executed corresponding to the fused kernel function are determined, and the number of threads and the number of thread blocks are allocated according to the program characteristics by the preset learning model.

[0010] Furthermore, the fusion of the kernel functions based on the features specifically includes:

[0011] When there are kernel functions with consistent upper bound, lower bound, and step size, no reduction, and data dependency, they are combined as the first set of kernel functions to be fused. Then, the kernel function with the first processing order in the intermediate code in the first set of kernel functions to be fused is used as the first benchmark kernel function. Finally, the kernel functions in the first set of kernel functions to be fused are reconstructed and fused.

[0012] When the upper bound, lower bound, and step size of the loop calculation are consistent, and there are no reductions or data dependencies among the kernel functions, they are combined as the second set of functions to be fused. The kernel function with the fewest instructions is selected as the second benchmark kernel function, and then the kernel functions in the second set of functions to be fused are reconstructed and fused.

[0013] When there is an inconsistency among the upper bound of loop computation, the lower bound of loop computation, and the step, and there is no reduction or data dependency among the kernel functions, they are combined as the third set of kernel functions to be fused. Then, the kernel function with the largest range of the upper and lower bounds of loop computation is used as the third benchmark kernel function, and the kernel functions in the third set of kernel functions to be fused are reconstructed and fused.

[0014] When there is an inconsistency among the upper bound of the loop calculation, the lower bound of the loop calculation, and the step, and the kernel functions have reduction and no data dependency, they are combined as the fourth set of kernel functions to be fused. Then, the kernel functions with reduction are used as the fourth benchmark kernel functions, and the kernel functions in the fourth set of kernel functions to be fused are reconstructed and fused.

[0015] Furthermore, the reconstruction and fusion specifically involves adding instructions to the intermediate code of the corresponding baseline kernel function through the compiler. These instructions specifically include a first load instruction, a first store instruction, a jump instruction, and a computation instruction for the fused kernel function.

[0016] Furthermore, the method also includes deleting all function declarations and calls of the merged kernel functions.

[0017] Furthermore, after fusing all kernel functions based on the aforementioned features, the process also includes:

[0018] Determine the data volume value for each fused kernel function;

[0019] The corresponding fused kernel function whose data value is lower than the remaining storage value in the shared memory is transferred to the shared memory.

[0020] Furthermore, the transfer process specifically includes:

[0021] Create basic data interaction blocks;

[0022] The instruction attribute in the data interaction basic block is modified to a shared memory attribute, and a second load instruction and a second store instruction are constructed so that the fused function can interact between global memory and shared memory.

[0023] Furthermore, the dynamic allocation of threads specifically includes:

[0024] The program features are input into a comparison table to determine the comparison results. The comparison results specifically include the optimal number of threads and the optimal number of thread blocks. The comparison table is specifically a table showing different program features and their corresponding optimal number of threads and optimal number of thread blocks.

[0025] The number of threads and thread blocks are allocated based on the comparison results.

[0026] Furthermore, the lookup table is determined through the preset learning model.

[0027] On the other hand, the present invention also provides a performance optimization apparatus for OpenMP Offload, the apparatus comprising:

[0028] The determination module is used to determine the number of kernel functions generated by the OpenMP Offload during heterogeneous computing, and to determine the characteristics of each kernel function. The characteristics specifically include the upper bound of the loop calculation, the lower bound of the loop calculation, whether there is a reduction, and whether there is a dependency relationship with other kernel functions.

[0029] The fusion module is used to input the features into a preset learning model and fuse all kernel functions through the preset learning model;

[0030] The allocation module is used to send the fused kernel function to the parallel execution domain, determine the program characteristics of the program to be executed corresponding to the fused kernel function, and allocate the number of threads and the number of thread blocks according to the program characteristics through the preset learning model.

[0031] In another aspect, the present invention also provides an electronic device, comprising:

[0032] processor;

[0033] Memory used to store the processor's executable instructions;

[0034] The processor is configured to perform the method described above.

[0035] This invention provides a performance optimization method, apparatus, and electronic device for OpenMP Offload. Compared with existing technologies, this method first determines the number of kernel functions generated by OpenMP Offload during heterogeneous computing and identifies the characteristics of each kernel function. These characteristics specifically include upper bounds and lower bounds for loop computation, the existence of reduction mechanisms, and dependencies with other kernel functions. The characteristics are then input into a preset learning model, which fuses all kernel functions. Finally, the fused kernel functions are sent to a parallel execution domain to determine the program characteristics of the corresponding executable program. Based on these program characteristics, the preset learning model allocates the number of threads and thread blocks. By first reducing the number of kernel functions and then dynamically allocating threads and thread blocks based on the characteristics of the executable program corresponding to each kernel function, the performance of OpenMP Offload and the utilization rate of thread resources in heterogeneous architecture systems are effectively improved. Attached Figure Description

[0036] To more clearly illustrate the technical solutions in the embodiments or prior art of this specification, the drawings used in the description of the embodiments or prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this specification. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0037] Figure 1 The diagram shown is a flowchart illustrating the performance optimization method for OpenMP Offload provided in the embodiments of this specification.

[0038] Figure 2 The diagram shown is a structural schematic of the performance optimization device for OpenMP Offload provided in the embodiments of this specification. Detailed Implementation

[0039] To enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0040] like Figure 1The diagram illustrates a performance optimization method for OpenMP Offload provided in this embodiment. While this specification provides the method operation steps or apparatus structure shown in the embodiments or figures below, based on conventional methods or without creative effort, the method or apparatus may include more or fewer operation steps or module units after partial merging. In steps or structures where there is no logically necessary causal relationship, the execution order of these steps or the module structure of the apparatus are not limited to the execution order or module structure shown in the embodiments or figures of this specification. When the method or module structure is applied in actual devices, servers, or terminal products, it can be executed sequentially or in parallel according to the method or module structure shown in the embodiments or figures (e.g., in a parallel processor or multi-threaded processing environment, or even in a distributed processing or server cluster implementation environment).

[0041] The performance optimization method for OpenMP Offload provided in this embodiment can be applied to terminal devices such as clients and servers. Figure 1 As shown, the method specifically includes the following steps:

[0042] Step S101: Determine the number of kernel functions generated by the OpenMP Offload during heterogeneous computing, and determine the characteristics of each kernel function. The characteristics specifically include the upper bound of the loop calculation, the lower bound of the loop calculation, whether there is a reduction, and whether there is a dependency relationship with other kernel functions.

[0043] Specifically, kernel functions containing reduction parameters are more structurally complex. Kernel function fusion can reduce kernel function startup overhead. Kernel function startup overhead refers to the time it takes for the kernel submitted by the host to begin execution on the device, i.e., the delay between the kernel submission completion time and the startup time. Implementing kernel function fusion optimization helps core computation fully utilize registers and caches, reducing the time spent storing and retrieving data between the GPU and memory. After kernel function fusion, the result of the previous calculation can be temporarily stored in the GPU's registers or shared memory, and the next calculation can directly read from the registers or shared memory. Kernel function fusion optimization utilizes the principle of locality of reference in memory access, reducing the number of memory read / write input / output operations, increasing the efficient reuse of on-chip memory, and improving memory access utilization.

[0044] Kernel merging in OpenMP Offload involves more than simply combining multiple kernel functions from the original program into a single "#pragma omp parallel" kernel function. It also requires considering whether the merging process will modify the semantics of the original program. To ensure that the merging does not alter the semantics, the data update order and execution order between the merged sub-threads must remain consistent with the original program. Furthermore, it's necessary to consider variable data dependencies and the handling of sequential statements between kernel functions during the merging process.

[0045] Therefore, it is necessary to first determine the number of kernel functions and the characteristics of each kernel function, including the upper bound of loop calculation, the lower bound of loop calculation, whether there is a reduction, and whether there is a dependency relationship with other kernel functions.

[0046] Step S102: Input the features into a preset learning model, and fuse all kernel functions through the preset learning model.

[0047] Specifically, to avoid modifying the semantics of the original program during kernel function fusion, and to ensure that the data update order and execution order between each sub-thread remain consistent with the original program after fusion, as well as that the variable data dependencies and the processing of serial statements between kernel functions remain consistent during the fusion process, kernel function fusion is performed in the following way:

[0048] When there are kernel functions with consistent upper bound, lower bound, and step size, no reduction, and data dependency, they are combined as the first set of kernel functions to be fused. Then, the kernel function with the first processing order in the intermediate code in the first set of kernel functions to be fused is used as the first benchmark kernel function. Finally, the kernel functions in the first set of kernel functions to be fused are reconstructed and fused.

[0049] When the upper bound, lower bound, and step size of the loop calculation are consistent, and there are no reductions or data dependencies among the kernel functions, they are combined as the second set of functions to be fused. The kernel function with the fewest instructions is selected as the second benchmark kernel function, and then the kernel functions in the second set of functions to be fused are reconstructed and fused.

[0050] When there is an inconsistency among the upper bound of loop computation, the lower bound of loop computation, and the step, and there is no reduction or data dependency among the kernel functions, they are combined as the third set of kernel functions to be fused. Then, the kernel function with the largest range of the upper and lower bounds of loop computation is used as the third benchmark kernel function, and the kernel functions in the third set of kernel functions to be fused are reconstructed and fused.

[0051] When there is an inconsistency among the upper bound of the loop calculation, the lower bound of the loop calculation, and the step, and the kernel functions have reduction and no data dependency, they are combined as the fourth set of kernel functions to be fused. Then, the kernel functions with reduction are used as the fourth benchmark kernel functions, and the kernel functions in the fourth set of kernel functions to be fused are reconstructed and fused.

[0052] Specifically, after obtaining the kernel function features, a suitable kernel function is selected as the benchmark kernel function for reconstruction and fusion using the methods described above. This effectively avoids the problem of kernel function fusion modifying the semantics of the original program, ensuring that the data update order and execution order between each sub-thread remain consistent with the original program after fusion, and that the variable data dependencies and the processing of serial statements between kernel functions remain consistent during the fusion process. The preset learning model can be the XGBoost model, which is a massively parallel boosted learning model. XGBoost, a tree-based tool, is one of the fastest and best open-source modeling tools currently available. The XGBoost model is pre-trained using a pre-defined training feature set. This feature set includes the number of kernel functions, the upper and lower bounds of loop calculations within the kernel functions, array size, data types, the number of threads and thread blocks, the number of computation engines, the number of computational units, the shared memory size, and the thread bundle size. After training, it can more accurately fuse kernel functions and handle subsequent dynamic thread allocation. The reconstruction and fusion process involves adding instructions to the intermediate code of the corresponding baseline kernel function through the compiler. These instructions include a first load instruction, a first store instruction, a jump instruction, and computation instructions for the fused kernel function. Simultaneously, adding and deleting instructions involves the construction and deletion of basic blocks. Therefore, after completion, the phi instructions need to be modified to maintain the control flow graph and dominance relationships. An example program of the kernel function before reconstruction and fusion is shown below:

[0053]

[0054] The following is an example program of the reconstructed and merged kernel function:

[0055]

[0056] The merged kernel function already possesses all computational capabilities. Therefore, it is necessary to remove redundant kernel function declarations and calls, i.e., the function declarations and calls of the merged kernel function, in order to maintain the overall dominance of the function. This also includes deleting all declarations and calls of the merged kernel function.

[0057] Furthermore, OpenMP Offload currently only supports manually declaring shared memory arrays. Staff then handle the data movement and computation from global memory to shared memory, increasing the difficulty and workload of front-end programming. Shared memory is a key hardware component on the GPU. Compared to L2 cache and global memory, shared memory is physically closer to the computation unit. As on-chip memory, it boasts fast memory access speeds. Therefore, transferring data from global memory to shared memory offers lower latency and higher access efficiency. However, on-chip memory often has limited storage capacity. Therefore, it's necessary to automatically identify the size of the fused kernel function and, after careful consideration, place appropriately sized data into shared memory to prevent memory allocation errors due to insufficient shared memory space. The specific process is as follows:

[0058] After fusing all kernel functions based on the aforementioned features, the process also includes:

[0059] Determine the data volume value for each fused kernel function;

[0060] The fused kernel function whose data volume is lower than the remaining storage value in the shared memory is moved to the shared memory. The transfer process specifically includes:

[0061] Create basic data interaction blocks;

[0062] The instruction attribute in the data interaction basic block is modified to a shared memory attribute, and a second load instruction and a second store instruction are constructed so that the fused function can interact between global memory and shared memory.

[0063] Specifically, kernel functions with data sizes smaller than the shared memory size are used as input for the optimization pass. New basic blocks are created for the kernel function structure to implement data exchange, computation, and backhaul from global memory to shared memory. First, a data exchange basic block is created before the core computation basic block. Second load and second store instructions are constructed to transfer the corresponding merged kernel function from global memory to shared memory. Then, the instruction attributes in the core computation basic block are modified to share memory attributes. Finally, a data backhaul basic block is constructed after the core computation basic block. Load and store instructions are constructed to transfer data from shared memory to global memory. After the interaction is completed, the selection of basic blocks and index values ​​in the phi instructions is modified to update the dominance relationship between basic blocks.

[0064] The following is an example of the kernel function before it is moved to shared memory after merging:

[0065] %1=getelementptr inbounds[1024x double],[1024x double]*%A,i640,i64%idxprom.i

[0066] %2 = addrspacecast double* %1 to double addrspace(1)*

[0067] %3 = load double, double addrspace(1)* %2, align 8, !tbaa!6

[0068] %4 = getelementptr inbounds [1024 x double], [1024 x double]* %B, i64 0, i64 %idxprom.i

[0069] %5 = addrspacecast double* %4 to double addrspace(1)*

[0070] %6 = load double, double addrspace(1)* %5, align 8, !tbaa!6

[0071] %7 = fadd double %3, %6

[0072] An example after the fused kernel function is transferred to shared memory is as follows:

[0073] %1 = getelementptr inbounds [1024 x double], [1024 x double] addrspace(3)* @main.A, i64 0, i64 %idxprom.i

[0074] %2 = load double, double addrspace(3)* %1, align 8, !tbaa!6

[0075] %3 = getelementptr inbounds [1024 x double], [1024 x double] addrspace(3)* @main.B, i64 0, i64 %idxprom.i

[0076] %4 = load double, double addrspace(3)* %3, align 8, !tbaa!6

[0077] %5 = fadd double %2, %4

[0078] In computations involving large arrays, heterogeneous programming languages ​​cannot directly utilize shared memory for efficient data transfer and computation. To address this issue, large arrays are divided into smaller array blocks. This means dividing the merged kernel function into smaller array blocks. Data is then moved from global memory to shared memory in batches to complete the core computation. During this process, the block coefficients are evaluated and filtered by XGBoost, and the results are fed back to LLVM (the compiler) to implement matrix block partitioning. This achieves overall optimization through combined loop partitioning and shared memory compilation optimization. XGBoost is an optimized distributed gradient boosting library that enables parallel computation, approximate tree construction, effective handling of sparse data, and memory usage optimization.

[0079] Step S103: After sending the fused kernel function to the parallel execution domain, determine the program characteristics of the program to be executed corresponding to the fused kernel function, and allocate the number of threads and the number of thread blocks according to the program characteristics.

[0080] Specifically, existing technologies allocate the number of threads and thread blocks in two ways: one is by manually adding the "num_threads" instruction to control the number of threads on a single computing unit, which requires developers to have a deep understanding of the device's hardware structure and execution architecture. The other approach is to use the compiler-based OpenMP Offload default thread allocation method, in which the execution details of threads on the GPU are controlled by the compiler. However, this strategy is relatively simplistic, only allowing calculations based on a fixed number of threads each time, and cannot flexibly allocate threads according to the characteristics of the program to be executed. This application, however, flexibly allocates the number of threads and thread blocks based on the characteristics of the program to be executed. The specific process includes:

[0081] The program features are input into a comparison table to determine the comparison results. The comparison results specifically include the optimal number of threads and the optimal number of thread blocks. The comparison table is specifically a table showing different program features and their corresponding optimal number of threads and optimal number of thread blocks.

[0082] The number of threads and thread blocks are allocated based on the comparison results.

[0083] Specifically, the first step is to train a pre-defined learning model, which can be XGBoost or other models. The training process involves associating program features with different numbers of threads and thread blocks under corresponding conditions, using this as input to XGBoost. XGBoost then identifies the relationship between the features and the number of threads and thread blocks, thereby establishing a mapping relationship between different program features and the number of threads and thread blocks. This mapping relationship is stored in the runtime library as a lookup table to provide a more reasonable and efficient basis for thread allocation.

[0084] Furthermore, this pre-defined learning model can also be used in the kernel function fusion process to optimize parameter selection. This involves converting kernel functions and hardware features into a form understandable to machine learning, and then using these features to train the XGBoost model. To avoid underfitting, overfitting, and low training efficiency, GridSearchCV is used to search for parameters, adjusting them one by one within a given parameter range at specified step sizes. Then, all possible parameter combinations are iterated to find the hyperparameter combination with the smallest validation set error. Through repeated training on large amounts of data, the model's accuracy and precision are continuously improved. Later, during code compilation, the optimal parameter values ​​predicted by this model can be used to predict new code segments using the pre-trained XGBoost model. Based on the prediction results, the parameter selection and execution order of the optimization pass are determined. This completes machine learning-guided optimization in the compiler domain, improving the compiler's code generation quality and program execution performance.

[0085] After the above processing, the performance of OpenMP Offload and the utilization rate of thread resources in heterogeneous architecture systems can be effectively improved.

[0086] Based on the above-described performance optimization method for OpenMP Offload, one or more embodiments of this specification also provide a platform or terminal for OpenMP Offload performance optimization. This platform or terminal may include devices, software, modules, plug-ins, servers, clients, etc., using the methods described in the embodiments of this specification, combined with necessary hardware implementation devices. Based on the same innovative concept, the systems in one or more embodiments provided in this specification are as described in the following embodiments. Since the implementation schemes and methods for solving the system problem are similar, the specific system implementations in the embodiments of this specification can refer to the implementation of the foregoing methods. Repeated descriptions will not be repeated. The terms "unit" or "module" used below can refer to a combination of software and / or hardware that implements a predetermined function. Although the systems described in the following embodiments are preferably implemented in software, hardware implementations, and a combination of software and hardware, are also possible and contemplated.

[0087] Specifically, Figure 2 This is a schematic diagram of the module structure of one embodiment of the performance optimization device for OpenMP Offload provided in this specification, as shown below. Figure 2 As shown, the performance optimization apparatus for OpenMP Offload provided in this specification includes:

[0088] The determination module 201 is used to determine the number of kernel functions generated by the OpenMP Offload during heterogeneous computing, and to determine the characteristics of each kernel function. The characteristics specifically include the upper bound of the loop calculation, the lower bound of the loop calculation, whether there is a reduction, and whether there is a dependency relationship with other kernel functions.

[0089] The fusion module 202 is used to input the features into a preset learning model and fuse all kernel functions through the preset learning model;

[0090] The allocation module 203 is used to send the fused kernel function to the parallel execution domain, determine the program characteristics of the program to be executed corresponding to the fused kernel function, and allocate the number of threads and the number of thread blocks according to the program characteristics through the preset learning model.

[0091] It should be noted that the system described above may include other implementation methods based on the description of the corresponding method embodiments. The specific implementation methods can be referred to the description of the corresponding method embodiments above, and will not be elaborated here.

[0092] This application also provides an electronic device, including:

[0093] processor;

[0094] Memory used to store the processor's executable instructions;

[0095] The processor is configured to perform the methods provided in the embodiments described above.

[0096] The electronic device provided in this application stores executable instructions of the processor in a memory. When the processor executes the executable instructions, it can first determine the number of kernel functions generated by the OpenMP Offload during heterogeneous computing, and determine the characteristics of each kernel function. The characteristics specifically include the upper bound of loop computation, the lower bound of loop computation, the existence of reduction, and the existence of dependencies with other kernel functions. The characteristics are input into a preset learning model, and all kernel functions are fused through the preset learning model. Finally, the fused kernel functions are sent to the parallel execution domain to determine the program characteristics of the program to be executed corresponding to the fused kernel functions. The preset learning model allocates the number of threads and thread blocks according to the program characteristics. By first reducing the number of kernel functions and then dynamically allocating threads and thread blocks based on the characteristics of the program to be executed corresponding to the kernel functions, the performance of OpenMP Offload and the utilization rate of thread resources in heterogeneous architecture systems are effectively improved.

[0097] The foregoing description of this specification describes specific embodiments. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims can be performed in an order different from that described in the embodiments and still achieve the desired results. Furthermore, the processes depicted in the accompanying drawings do not necessarily require the specific order shown or the sequential order to achieve the desired results. In certain embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0098] The methods or apparatus described in the embodiments provided in this specification can implement business logic through a computer program and record it on a storage medium. The storage medium can be read and executed by a computer to achieve the effects of the solutions described in the embodiments of this specification, such as:

[0099] The number of kernel functions generated by the OpenMP Offload during heterogeneous computing is determined, and the characteristics of each kernel function are determined. The specific characteristics include the upper bound of the loop computation, the lower bound of the loop computation, whether there is a reduction, and whether there is a dependency relationship with other kernel functions.

[0100] The features are input into a preset learning model, and all kernel functions are fused through the preset learning model;

[0101] After the fused kernel function is sent to the parallel execution domain, the program characteristics of the program to be executed corresponding to the fused kernel function are determined, and the number of threads and the number of thread blocks are allocated according to the program characteristics by the preset learning model.

[0102] The storage medium can include physical devices for storing information, typically digitizing the information and then storing it using electrical, magnetic, or optical methods. The storage medium can include: devices that store information using electrical energy, such as various types of memory, like RAM and ROM; devices that store information using magnetic energy, such as hard disks, floppy disks, magnetic tapes, magnetic core memory, bubble memory, and USB flash drives; and devices that store information using optical methods, such as CDs or DVDs. Of course, there are other readable storage media, such as quantum memories and graphene memories.

[0103] The embodiments in this specification are not limited to conforming to industry communication standards, standard computer resource data update and data storage rules, or the situations described in one or more embodiments of this specification. Slightly modified implementations based on certain industry standards or custom methods or embodiments can also achieve the same, equivalent, or similar, or predictable, implementation effects as described above. Embodiments that utilize these modified or modified methods for data acquisition, storage, judgment, and processing still fall within the scope of optional implementations of the embodiments in this specification.

[0104] The controller can be implemented in any suitable manner. For example, it can take the form of a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro)processor, logic gates, switches, application-specific integrated circuits (ASICs), programmable logic controllers, and embedded microcontrollers. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicon Labs C8051F320. A memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art will also recognize that, in addition to implementing the controller in purely computer-readable program code form, the same functionality can be achieved by logically programming the method steps to make the controller take the form of logic gates, switches, ASICs, programmable logic controllers, and embedded microcontrollers. Therefore, such a controller can be considered a hardware component, and the means included therein for implementing various functions can also be considered as structures within the hardware component. Alternatively, the means for implementing various functions can be considered as both software modules implementing the method and structures within the hardware component.

[0105] The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or plug-ins may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces, indirect coupling or communication connection between devices or units, and may be electrical, mechanical, or other forms.

[0106] These computer program instructions can also be loaded onto a computer or other programmable resource data updating device, causing a series of operational steps to be performed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable device for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0107] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, system embodiments are basically similar to method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments. In the description of this specification, the terms "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., refer to specific features, structures, materials, or characteristics described in connection with that embodiment or example, which are included in at least one embodiment or example of this specification. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described can be combined in a suitable manner in any one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification and the features of different embodiments or examples.

[0108] Those skilled in the art will recognize that the embodiments described herein are intended to help the reader understand the principles of the invention, and should be understood that the scope of protection of the invention is not limited to such specific statements and embodiments. Those skilled in the art can make various other specific modifications and combinations based on the technical teachings disclosed in this invention without departing from the spirit of the invention, and these modifications and combinations are still within the scope of protection of this invention.

Claims

1. A performance optimization method for OpenMP Offload, It is characterized in that The method comprises: Determine the number of kernel functions generated by the OpenMP Offload during heterogeneous computing, and determine the characteristics of each kernel function, wherein the characteristics specifically include a loop calculation upper bound, a loop calculation lower bound, whether there is a specification, and whether there is a dependency relationship between the kernel function and other kernel functions; Inputting the features into a preset learning model, and fusing all kernel functions through the preset learning model; After sending the fused kernel function to the parallel execution domain, program features of the to-be-executed program corresponding to the fused kernel function are determined, and the number of threads and the number of thread blocks are allocated according to the program features through the preset learning model; The fusion of all kernel functions specifically includes: When there are kernel functions whose loop calculation upper bound, loop calculation lower bound and stride are all consistent and have no convention and data dependency, they are combined as a first kernel function set to be fused, and after the kernel function with the first processing order in the intermediate code is taken as the first benchmark kernel function in the first kernel function set to be fused, the kernel functions in the first kernel function set to be fused are reconstructed and fused; When the loop calculation upper bound, loop calculation lower bound and stride are consistent, and there is no specification and no kernel function with data dependency, they are combined as the second set of functions to be fused, and the kernel function with the least number of instructions is used as the second benchmark kernel function, and then the kernel functions in the second set of functions to be fused are reconstructed and fused; When there are kernel functions that are inconsistent among at least one of the loop calculation upper bound, the loop calculation lower bound and the stride, and have no convention and no data dependency, they are combined as the third kernel function set to be fused, and then the kernel function with the largest loop calculation upper and lower bound range is used as the third benchmark kernel function, and then the kernel functions in the third kernel function set to be fused are reconstructed and fused; When there is at least one inconsistency among the loop calculation upper bound, the loop calculation lower bound and the stride, and there are kernel functions with specifications and no data dependency, they are combined as the fourth kernel function set to be fused, and then the kernel function with the specifications is used as the fourth benchmark kernel function, and then the kernel functions in the fourth kernel function set to be fused are reconstructed and fused.

2. The performance optimization method for OpenMP Offload according to claim 1, It is characterized in that The reconstruction fusion is specifically to add instructions to the intermediate code of the corresponding benchmark kernel function through the compiler, and the instructions specifically include a first load instruction, a first storage instruction, a jump instruction and a calculation instruction of the fused kernel function.

3. The performance optimization method for OpenMP Offload according to claim 2, It is characterized in that The method also includes deleting function declarations and calls of all fused kernel functions.

4. The performance optimization method for OpenMP Offload according to claim 1, It is characterized in that After fusing all kernel functions based on the features, it also includes: Determine the data value of each fused kernel function; The corresponding fused kernel functions whose data value is lower than the remaining storage value of the shared memory are transferred to the shared memory.

5. The performance optimization method for OpenMP Offload according to claim 4, It is characterized in that The transfer process specifically includes: Create basic blocks for data interaction; The instruction attribute in the data interaction basic block is modified to a shared memory attribute and a second load instruction and a second store instruction are constructed, so that the fused function can interact between the global memory and the shared memory.

6. The performance optimization method for OpenMP Offload according to claim 1, It is characterized in that The thread dynamic allocation specifically includes: Input the program features into a comparison table to determine a comparison result, wherein the comparison result specifically includes an optimal number of threads and an optimal number of thread blocks, and the comparison table specifically is a table of different program features and their corresponding optimal numbers of threads and optimal numbers of thread blocks; The number of threads and the number of thread blocks are allocated according to the comparison result.

7. The performance optimization method for OpenMP Offload according to claim 6, It is characterized in that The comparison table is determined by the preset learning model.

8. A performance optimization device for OpenMP Offload, It is characterized in that The device comprises: A determination module is used to determine the number of kernel functions generated by the OpenMP Offload during heterogeneous computing, and determine the characteristics of each kernel function, wherein the characteristics specifically include a loop calculation upper bound, a loop calculation lower bound, whether there is a specification, and whether there is a dependency relationship between the kernel function and other kernel functions; A fusion module, used for inputting the features into a preset learning model to fuse all kernel functions; An allocation module, configured to send the fused kernel function to the parallel execution domain, determine the program features of the to-be-executed program corresponding to the fused kernel function, and allocate the number of threads and the number of thread blocks according to the program features through the preset learning model; The fusion of all kernel functions specifically includes: When there are kernel functions whose loop calculation upper bound, loop calculation lower bound and stride are all consistent and have no convention and data dependency, they are combined as a first kernel function set to be fused, and after the kernel function with the first processing order in the intermediate code is taken as the first benchmark kernel function in the first kernel function set to be fused, the kernel functions in the first kernel function set to be fused are reconstructed and fused; When the loop calculation upper bound, loop calculation lower bound and stride are consistent, and there is no specification and no kernel function with data dependency, they are combined as the second set of functions to be fused, and the kernel function with the least number of instructions is used as the second benchmark kernel function, and then the kernel functions in the second set of functions to be fused are reconstructed and fused; When there are kernel functions that are inconsistent among at least one of the loop calculation upper bound, the loop calculation lower bound and the stride, and have no convention and no data dependency, they are combined as the third kernel function set to be fused, and then the kernel function with the largest loop calculation upper and lower bound range is used as the third benchmark kernel function, and then the kernel functions in the third kernel function set to be fused are reconstructed and fused; When there is at least one inconsistency among the loop calculation upper bound, the loop calculation lower bound and the stride, and there are kernel functions with specifications and no data dependency, they are combined as the fourth kernel function set to be fused, and then the kernel function with the specifications is used as the fourth benchmark kernel function, and then the kernel functions in the fourth kernel function set to be fused are reconstructed and fused.

9. An electronic device, It is characterized in that include: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the method according to any one of claims 1 to 7.