Code optimization method for heterogeneous HPC platform and related device

By using tuning agents on the heterogeneous HPC platform, dynamically obtaining memory access features and generating memory access strategies through reinforcement learning, the problem of insufficient multifunctionality and flexibility of the model is solved, and efficient and precise code generation and adaptability improvement is achieved.

CN119917107AActive Publication Date: 2025-05-02XI AN JIAOTONG UNIV

Patent Information

Application Number
CN202510102918.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-22
Publication Date
2025-05-02
Estimated Expiration
2045-01-22

AI Technical Summary

Technical Problem

In heterogeneous HPC platforms, fine-tuning for specific tasks in the prior art can easily limit the versatility of the model, making it difficult to adapt to other tasks, resulting in poor adaptability and flexibility.

Method used

The tuning agent is adopted, including the memory access feature acquisition module, the memory access strategy generation module and the optimized code generation module. Through dynamic memory access feature acquisition, reinforcement learning, generation of the memory access strategy and insert it into the source code to generate optimization code.

Benefits of technology

Efficient and precise code generation is achieved, meeting the unique needs of the HPC environment, and improving the flexibility and adaptability of the model without extensive retraining of large-scale datasets.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119917107A_ABST
    Figure CN119917107A_ABST
Patent Text Reader

Abstract

The invention belongs to the technical field of code optimization, and discloses a code optimization method and related device for a heterogeneous HPC platform, and the method comprises the steps: obtaining a to-be-optimized source code, and determining an instrumentation cue word and a strategy cue word; inputting the to-be-optimized source code, the instrumentation cue word and the strategy cue word into an adjusting and optimizing agent, and performing memory access optimization on the to-be-optimized source code by utilizing the adjusting and optimizing agent to obtain an optimized code; wherein the tuning agent comprises a memory access feature acquisition module, a memory access strategy generation module and an optimization code generation module; in the memory access feature acquisition module and the optimization code generation module, on the basis of the instrumentation cue word and the strategy cue word, source code modification based on cue guidance is realized, the optimization process is simplified, and wide retraining on a large-scale data set is not needed; the human intention is combined with the capacity of a large language model, efficient and accurate code generation is promoted, and the unique requirement of the HPC environment is met.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of code optimization, and in particular relates to a code optimization method and related devices for a heterogeneous HPC platform. Background Art

[0002] In recent years, Large Language Models (LLMs) have been increasingly used in programming-related tasks, and their predictive capabilities have significantly improved the software development process. By training on a large number of open source code bases, LLMs have learned complex coding patterns and structures, thereby significantly improving performance and applicability in various programming fields.

[0003] However, in the specialized field of heterogeneous High Performance Computing (HPC) code optimization, traditional methods rely heavily on hardware characteristics and require manual tuning, which is time-consuming and error-prone. For example, developing automatic code optimization using traditional abstract tree lighting technology may take up to eight months and face compilation errors caused by code differences. In contrast, using LLMs, the same task can be completed with high accuracy in just two weeks.

[0004] In heterogeneous HPC platforms, training data is significantly limited compared to general programming. Specifically, HPC codes have complex memory access patterns, parallelism, and platform-specific optimizations, which makes open source HPC codes scarce and domain-complex. In addition, there is a lack of necessary domain-specific knowledge to optimize HPC applications, which poses a major challenge to LLMs. Currently, LLMs usually need to be fine-tuned for specific tasks. However, fine-tuning for specific tasks can easily limit the versatility of the model, making it difficult to adapt to other tasks, resulting in poor adaptability and flexibility. Summary of the invention

[0005] In view of the technical problems existing in the prior art, the present invention provides a code optimization method and related devices for a heterogeneous HPC platform to solve the technical problem that fine-tuning for specific tasks can easily limit the versatility of the model, making it difficult to adapt to other tasks, resulting in poor adaptability and flexibility.

[0006] In order to achieve the above object, the technical solution adopted by the present invention is: The present invention provides a code optimization method for a heterogeneous HPC platform, comprising: Obtain the source code to be optimized and determine the instrumentation prompt words and strategy prompt words; Inputting the source code to be optimized, the plugging prompt word and the strategy prompt word into the tuning agent, so as to optimize the memory access of the source code to be optimized by using the tuning agent to obtain the optimized code; The tuning agent includes a memory access feature acquisition module, a memory access strategy generation module and an optimization code generation module; The memory access feature acquisition module is used to dynamically insert measurement code into the source code to be optimized based on the instrumentation prompt word and the instrumentation tool guided by the large language model to obtain the instrumentation code; run the instrumentation code to obtain dynamic memory access features; The memory access strategy generation module is used to generate a memory access strategy through reinforcement learning according to the dynamic memory access characteristics; The optimized code generation module is used to insert the optimal memory access strategy into the source code to be optimized according to the strategy prompt word and based on the large language model to generate optimized code.

[0007] Furthermore, the dynamic memory access characteristics include a memory access step, a probability of each memory access step, and a size of a data block; wherein a data block is a continuous memory area occupied by an array variable referenced in a kernel function.

[0008] Furthermore, according to the instrumentation prompt word, an instrumentation tool guided by a large language model dynamically inserts measurement code into the source code to be optimized to obtain the instrumentation code, including: Inputting the source code to be optimized into the large language model, analyzing the context of the source code to be identified based on the plugging hint words, and obtaining the location where the source code needs to be plugged; According to the plugging prompt word and the position of the source code that needs to be plugged, the measurement code is dynamically inserted into the source code to be optimized using the plugging tool to obtain the plugging code.

[0009] Furthermore, the process of generating a memory access strategy through reinforcement learning according to the dynamic memory access feature includes: A pre-trained reinforcement learning module is used to perform reinforcement learning on dynamic memory access features to generate a memory access strategy; wherein the pre-trained reinforcement learning module is a reinforcement learning module trained using a preset data set, and the preset data set includes memory access behaviors, performance indicators, and on-chip cache utilization of different programs in a heterogeneous HPC platform.

[0010] Furthermore, a mixed reward function is introduced into the pre-trained reinforcement learning module; wherein the mixed reward function is:

[0011]

[0012]

[0013] in, is the mixed reward function; is the weight of the performance acceleration ratio; is the performance acceleration ratio; is the weight of cache hit rate; is the cache hit ratio.

[0014] Furthermore, according to the strategy prompt word, the memory access strategy is inserted into the source code to be optimized based on a large language model to generate an optimized code, including: Inputting the source code to be optimized, the strategy prompt words and the memory access strategy into a large language model to generate an optimal memory access strategy; According to the optimal memory access strategy, the preset code is inserted or modified in the source code to be optimized to generate the optimized code.

[0015] The present invention also provides a code optimization system for a heterogeneous HPC platform, comprising: An acquisition module is used to acquire the source code to be optimized and determine the instrumentation prompt words and strategy prompt words; An optimization module, used for inputting the source code to be optimized, the plugging prompt word and the strategy prompt word into the tuning agent, so as to use the tuning agent to perform memory access optimization on the source code to be optimized to obtain optimized code; The tuning agent includes a memory access feature acquisition module, a memory access strategy generation module and an optimization code generation module; The memory access feature acquisition module is used to dynamically insert measurement code into the source code to be optimized based on the instrumentation prompt word and the instrumentation tool guided by the large language model to obtain the instrumentation code; run the instrumentation code to obtain dynamic memory access features; A memory access strategy generation module, used to generate a memory access strategy through reinforcement learning according to the dynamic memory access characteristics; The optimized code generation module is used to insert the optimal memory access strategy into the source code to be optimized according to the strategy prompt word and based on the large language model to generate optimized code.

[0016] The present invention also provides a code optimization device for a heterogeneous HPC platform, comprising: a processor suitable for executing a computer program; A computer-readable storage medium, wherein a computer program is stored in the computer-readable storage medium, and when the computer program is executed by the processor, the code optimization method for a heterogeneous HPC platform is executed.

[0017] The present invention also provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the code optimization method for a heterogeneous HPC platform is implemented.

[0018] The present invention also provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the code optimization method for a heterogeneous HPC platform is implemented.

[0019] Compared with the prior art, the present invention has the following beneficial effects: The present invention provides a code optimization method for a heterogeneous HPC platform, which performs dynamic memory access feature acquisition, memory access strategy generation and optimized code generation by tuning a memory access feature acquisition module, a memory access strategy generation module and an optimized code generation module in an intelligent agent; wherein, in the memory access feature acquisition module and the optimized code generation module, prompt-based guidance for modifying source code is implemented based on plug-in prompt words and strategy prompt words, thereby simplifying the optimization process and eliminating the need for extensive retraining of large-scale data sets; the present invention promotes efficient and accurate code generation by combining human intentions with the capabilities of large language models to optimize memory access in an HPC environment, thereby meeting the unique needs of the HPC environment and ensuring flexibility and adaptability.

[0020] The code optimization system for a heterogeneous HPC platform, the code optimization device for a heterogeneous HPC platform, the computer-readable storage medium and the computer program product provided by the present invention have all the advantages of the above-mentioned code optimization method for a heterogeneous HPC platform. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] Figure 1 A flowchart of a code optimization method for a heterogeneous HPC platform provided in Example 1; Figure 2 This is an example diagram of obtaining the DAXPY operator by using the memory access feature acquisition module in Example 1; Figure 3 This is an example diagram of generating optimized code for the DAXPY operator using the optimized code generation module in Example 1; Figure 4 This is a code generation performance result diagram of the code optimization method for heterogeneous HPC platform described in Example 1 on the HumanevalDSP data set; Figure 5 This is a code generation performance result diagram of the code optimization method for heterogeneous HPC platform described in Example 1 on DspStandard; Figure 6 This is a graph showing the acceleration ratio results of the code optimization method for a heterogeneous HPC platform described in Example 1; Figure 7 A structural block diagram of a code optimization system for a heterogeneous HPC platform provided in Example 2; Figure 8This is a structural block diagram of a code optimization device for a heterogeneous HPC platform provided in Example 3. DETAILED DESCRIPTION

[0022] In order to make the technical problems, technical solutions and beneficial effects solved by the present invention more clearly understood, the present invention is further described in detail in the following specific embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.

[0023] Example 1 As attached Figure 1 As shown, this embodiment 1 provides a code optimization method for a heterogeneous HPC platform, comprising the following steps: Step 1: Obtain source code to be optimized and determine instrumentation prompt words and strategy prompt words. The source code to be optimized is a heterogeneous HPC (High-Performance Computing) code; the instrumentation prompt words and strategy prompt words are both natural languages.

[0024] Step 2: Input the source code to be optimized, the plugging prompt word and the strategy prompt word into the optimization agent (OptiAgent), so as to use the optimization agent to optimize the memory access of the source code to be optimized to obtain the optimized code. The optimization agent includes a memory access feature acquisition module, a memory access strategy generation module and an optimization code generation module.

[0025] Step 3: output the optimized code.

[0026] In this embodiment 1, the memory access feature acquisition module is used to dynamically insert measurement code into the source code to be optimized based on the instrumentation prompt word and the instrumentation tool guided by the large language model to obtain the instrumentation code; run the instrumentation code to obtain dynamic memory access features. Specifically, the following steps are included: Step 211: input the source code to be optimized into a large language model, analyze the context of the source code to be identified based on the plugging hint words, and obtain the location of the source code that needs to be plugged.

[0027] Step 212: According to the instrumentation prompt word and the position of the source code that needs to be instrumented, use an instrumentation tool to dynamically insert measurement code into the source code to be optimized to obtain instrumentation code.

[0028] Step 213, run the stub code to obtain dynamic memory access characteristics; wherein the dynamic memory access characteristics include a memory access step, a probability of each memory access step, and a size of a data block; wherein a data block is a continuous memory area occupied by an array variable referenced in a kernel function.

[0029] It should be noted that, in the memory access feature acquisition module, an instrumentation agent is created and deployed to dynamically insert measurement code into the source code to be optimized based on predetermined instrumentation prompt words; wherein the instrumentation agent is driven by a large language model, and generates instrumentation suggestions based on the instrumentation prompt words and the results of source code analysis to guide the instrumentation tool to dynamically insert the measurement code into the source code to be optimized, thereby collecting dynamic memory access features in real time.

[0030] It should also be noted that the instrumented agent is provided with prompt information, which encapsulates predetermined logic and interfaces to ensure that the instrumented agent can effectively run in different HPC environments; once deployed, the instrumented agent can be seamlessly integrated into the target application and collect detailed information about memory access patterns, that is, to obtain dynamic memory access characteristics; among which, detailed information about memory access patterns is crucial to understanding how data is accessed during execution.

[0031] An instrumented agent is used to continuously monitor and analyze the collected dynamic memory access features, identify common access patterns and their statistical characteristics, and provide real-time feedback to LLMs, so that the optimization strategy can be dynamically adjusted according to the observed memory access features; the memory access pattern is defined as a stream, and the instrumented agent is able to analyze the step size distribution in the stream, which helps to identify patterns that are critical to optimizing cache usage and reducing memory latency; wherein each stream represents a subsequence of memory access elements, and the distance between adjacent elements in the stream is defined as the step size; the dynamic access features are used as the basic input of the access strategy module, so that the access strategy module can fine-tune the memory access strategy parameters, thereby improving the performance and efficiency of memory access.

[0032] The concept of a stream as a subsequence of memory access elements and the distance between any two adjacent elements is called the stride provide a framework for analyzing and classifying the characteristics of memory access behavior; assuming that the stream The step size that appears in is a discrete random variable , all possible different step lengths are , ; The probability of occurrence of different step lengths is recorded as , the sum of all probabilities is equal to 1 and each probability is non-negative, that is, it satisfies:

[0033] As attached Figure 2 As shown, attached Figure 2 The following is an example of how to use the memory access feature acquisition module to obtain the DAXPY operator's plug-in diagram; Figure 2 As can be seen in the figure, by using the instrumented agent, real-time analysis of data access methods in device-side code is achieved, providing a basis for optimizing code performance.

[0034] In this embodiment 1, the memory access strategy generation module is used to generate a memory access strategy through reinforcement learning according to the dynamic memory access characteristics; specifically, a pre-trained reinforcement learning module is used to perform reinforcement learning on the dynamic memory access characteristics to generate a memory access strategy; wherein the pre-trained reinforcement learning module is a reinforcement learning module trained using a preset data set, and the preset data set includes memory access behaviors, performance indicators, and on-chip cache utilization of different programs in a heterogeneous HPC platform.

[0035] In the memory access strategy generation module, runtime data is collected from the HPC platform, including detailed memory access characteristics, program speedup, and cache hit rate, and a reinforcement learning (RL) method is used to optimize the cache management strategy. A hybrid reward function is used to combine the program speedup and cache hit rate to make more intelligent and adaptive policy decisions.

[0036] Selecting the memory access strategy and its related parameters can be viewed as a discrete decision problem, which is suitable for applying reinforcement learning techniques. Specifically, the above discrete decision problem is modeled as an RL task, in which the agent learns to select the optimal cache strategy and parameters based on the observed runtime data. The hybrid reward function guides the agent to strike a balance between maximizing program performance and improving cache efficiency.

[0037] It should be noted that in order to train an effective reinforcement learning module, a data set is collected in advance. The collected data set captures the memory access behavior, performance indicators and on-chip cache (SM) utilization of different programs; the performance improvement brought by the optimized cache management is evaluated by measuring the speedup ratio, and the cache hit rate is monitored to evaluate the efficiency of serving memory requests.

[0038] Secondly, a hybrid reward function is introduced into the pre-trained reinforcement learning module to select the optimal cache strategy and parameters; when designing the hybrid reward function, the weights of the performance acceleration ratio (P) and the cache hit rate (C) are dynamically adjusted according to the system load to respond to different application requirements; under high system load, the focus shifts to performance, because this situation usually means resource competition and concurrent execution of multiple tasks; enhancing the program execution speed can reduce task queuing time, reduce the average response time of the system, and ultimately improve user experience and overall system throughput; therefore, in the above situation, the focus of optimization is to improve performance, even at the expense of some cache efficiency; that is, the reward function is allowed to adaptively prioritize performance or cache efficiency according to the current system load to ensure optimal resource utilization and performance.

[0039] Specifically, the mixed reward function is:

[0040]

[0041]

[0042] in, is the mixed reward function; is the weight of the performance acceleration ratio; is the performance speedup ratio, that is, the ratio of the optimized execution time to the unoptimized execution time. Indicates improved performance; is the weight of cache hit rate; is the cache hit rate, which is the proportion of cache accesses that are successfully served by the cache. This means better cache efficiency.

[0043] In the first embodiment, the optimized code generation module is used to insert the optimal memory access strategy into the source code to be optimized based on the large language model according to the strategy prompt word to generate the optimized code; specifically, the source code to be optimized, the strategy prompt word and the memory access strategy are input into the large language model to generate the optimal memory access strategy; according to the optimal memory access strategy, the preset code is inserted or modified in the source code to be optimized to generate the optimized code.

[0044] In the optimized code generation module, in order to optimize the performance of LLMs in the context of memory access and code generation, an optimization agent equipped with domain-specific strategies is used to generate optimized code, which can effectively combine programmer tuning experience with automated improvements to enhance the ability of LLMs to generate efficient code.

[0045] The optimization agent is provided with strategic prompts and unoptimized benchmark codes; wherein the strategic prompts are prompts with predictive strategies, which are embedded with domain-specific memory access optimization strategies to guide the optimization agent to generate code that complies with memory efficiency best practices to ensure consistency with the performance goals of the task; the unoptimized benchmark codes are used as reference points in the optimization process, allowing the optimization agent to measure the improvement effect.

[0046] After the initial input, a reinforcement learning (RL) strategy is used to further improve the LLM's ability to optimize memory access patterns; strategy Through extensive experiments and adjustments, the model is able to adjust its code generation according to the optimal memory access strategy; this process can be expressed mathematically as follows:

[0047] in, is a performance indicator, such as speedup; A set of memory access strategies to improve code efficiency.

[0048] It should be noted that the optimization agent interacts with a preset strategy tool, which provides advanced optimization techniques and feedback to help the tuning agent identify and apply the most efficient memory access pattern and further refine the generated code; Figure 3 As shown, attached Figure 3 An example diagram of using the optimized code generation module to generate optimized code for DAXPY operators is given in Figure .

[0049] In this embodiment 1, the large language model is one of GPT-4, Qwen2.5-Coder and GLM-4-Plus.

[0050] Experimental Evaluation (1) Correctness of code generation Code generation experiments are conducted using three large language models: GPT-4, Qwen2.5-Coder, and GLM-4-Plus; downstream tasks involve memory access feature acquisition and memory access optimized code generation, and are evaluated on the DspStandard dataset and the HumanevalDSP dataset.

[0051] As attached Figure 4-5 As shown, attached Figure 4 The code generation performance results of the code optimization method for heterogeneous HPC platforms on the HumanevalDSP dataset are given in the appendix. Figure 5 The code generation performance results of the code optimization method for heterogeneous HPC platforms on DspStandard are given in FIG. Figure 4 , 5 The average pass@k rate of the code generation test in Figure 4-5 As can be seen in the figure, GPT-4's excellent pass@k rate highlights the outstanding effectiveness of the tuned agent in generating correct and optimized memory access performance code; among them, the results of the HumanevalDSP dataset further confirm that the tuned agent maintains a high standard of correctness in the generated code in different fields, and its consistency proves the robustness of our method, which can ensure reliable and accurate code generation both in specialized high-performance computing (HPC) applications and in a wider range of programming tasks.

[0052] (2) Code generation speedup In order to evaluate the effect of code generation of the tuning agent on the HumanevalDSP dataset, a comprehensive performance analysis was conducted using an on-chip memory management strategy. Specifically, the performance of the generated code with and without optimization was compared by running each version 100 times and calculating the average speedup. Figure 6 As shown, attached Figure 6The speedup results of the code optimization method for heterogeneous HPC platforms are given in the figure; Figure 6 As can be seen, significant performance improvements were achieved in all test cases; the speedup ratio values ​​were always greater than 1, indicating that the generated code not only reached the baseline performance, but also exceeded the baseline performance. This continued superior performance highlights the framework's ability to generate efficient code.

[0053] As shown in Table 1 below, Table 1 shows the average speedup ratio of the code optimization method for heterogeneous HPC platform on different data sets; as can be seen from Table 1 below, a clear comparison of the average speedup ratio achieved by the tuning agent on the HumanevalDSP and DspStandard data sets is shown, and the results highlight the effectiveness of the tuning agent in generating optimized code.

[0054] Table 1 Average speedup ratio on different datasets

[0055] In this embodiment 1, two datasets are developed to evaluate OptiAgent: DspStandard, a dataset of common scientific computing operations tailored for DSP; and Humaneval-DSP, a ported version of the Humaneval benchmark dataset. Experiments show that OptiAgent achieves an average × 3 . An average speedup of 35% was achieved on Humaneval-DSP × 1 . The average speedup of OptiAgent was improved by 24% and the performance was improved by 6.7% in molecular dynamics simulations. In addition, OptiAgent achieved a 1.39-fold speedup in image convolution tasks. OptiAgent also achieved a pass@1 rate of 97.63% on Humaneval-DSP and a pass@1 rate of 99.00% on DspStandard. The above results show the role of OptiAgent in simplifying the development and maintenance of complex parallel applications while significantly enhancing their performance.

[0056] The code method for heterogeneous HPC platform described in this embodiment 1 introduces a tuning agent, which is a scalable framework for enhancing memory access performance based on a large language model. The tuning agent uses large language models (LLMs) to optimize memory access in a heterogeneous DSP architecture. OptiAgent dynamically adjusts its strategy by continuously analyzing runtime conditions to ensure optimal performance. It converts the memory access characteristics of the program into an efficient memory management strategy to generate code that can meet specific goals.

[0057] Example 2 As attached Figure 7 As shown, this embodiment 2 provides a code optimization system for a heterogeneous HPC platform, including an acquisition module, an optimization module and an output module.

[0058] An acquisition module is used to acquire the source code to be optimized and determine the insertion prompt words and the strategy prompt words; an optimization module is used to input the source code to be optimized, the insertion prompt words and the strategy prompt words into the tuning agent, so as to use the tuning agent to perform memory access optimization on the source code to be optimized to obtain the optimized code; an output module is used to output the optimized code.

[0059] The tuning agent includes a memory access feature acquisition module, a memory access strategy generation module and an optimization code generation module.

[0060] The memory access feature acquisition module is used to dynamically insert measurement code into the source code to be optimized based on the instrumentation tool guided by the large language model according to the instrumentation prompt word to obtain the instrumentation code; run the instrumentation code to obtain dynamic memory access features; the memory access strategy generation module is used to generate a memory access strategy through reinforcement learning according to the dynamic memory access features; the optimized code generation module is used to insert the optimal memory access strategy into the source code to be optimized based on the large language model according to the strategy prompt word to generate optimized code.

[0061] Example 3 As attached Figure 3 As shown, this embodiment 3 provides a code optimization device for a heterogeneous HPC platform, including: a memory for storing a computer program; a processor for implementing the steps of a code optimization method for a heterogeneous HPC platform when executing the computer program.

[0062] When the processor executes the computer program, the steps of the above-mentioned code optimization method for a heterogeneous HPC platform are implemented, for example: The source code to be optimized is obtained, and the insertion prompt words and the strategy prompt words are determined; the source code to be optimized, the insertion prompt words and the strategy prompt words are input into the tuning agent, so as to use the tuning agent to perform memory access optimization on the source code to be optimized to obtain the optimized code; and the optimized code is output.

[0063] The tuning agent includes a memory access feature acquisition module, a memory access strategy generation module and an optimization code generation module.

[0064] The memory access feature acquisition module is used to dynamically insert measurement code into the source code to be optimized based on the instrumentation tool guided by the large language model according to the instrumentation prompt word to obtain the instrumentation code; run the instrumentation code to obtain dynamic memory access features; the memory access strategy generation module is used to generate a memory access strategy through reinforcement learning according to the dynamic memory access features; the optimized code generation module is used to insert the optimal memory access strategy into the source code to be optimized based on the large language model according to the strategy prompt word to generate optimized code.

[0065] Alternatively, when the processor executes the computer program, the functions of each module in the above-mentioned code optimization system for heterogeneous HPC platforms are implemented, for example: An acquisition module is used to acquire the source code to be optimized and determine the insertion prompt words and the strategy prompt words; an optimization module is used to input the source code to be optimized, the insertion prompt words and the strategy prompt words into the tuning agent, so as to use the tuning agent to perform memory access optimization on the source code to be optimized to obtain the optimized code; an output module is used to output the optimized code.

[0066] The tuning agent includes a memory access feature acquisition module, a memory access strategy generation module and an optimization code generation module.

[0067] The memory access feature acquisition module is used to dynamically insert measurement code into the source code to be optimized based on the instrumentation tool guided by the large language model according to the instrumentation prompt word to obtain the instrumentation code; run the instrumentation code to obtain dynamic memory access features; the memory access strategy generation module is used to generate a memory access strategy through reinforcement learning according to the dynamic memory access features; the optimized code generation module is used to insert the optimal memory access strategy into the source code to be optimized based on the large language model according to the strategy prompt word to generate optimized code.

[0068] Exemplarily, the computer program may be divided into one or more modules / units, which are stored in the memory and executed by the processor to complete the present invention. The one or more modules / units may be a series of computer program instruction segments capable of completing preset functions, and the instruction segments are used to describe the execution process of the computer program in the code optimization device for heterogeneous HPC platforms.

[0069] The code optimization device for the heterogeneous HPC platform may be a computing device such as a desktop computer, a notebook, a PDA, and a cloud server. The code optimization device for the heterogeneous HPC platform may include, but is not limited to, a processor and a memory. Those skilled in the art will appreciate that the above is an example of a code optimization device for a heterogeneous HPC platform and does not constitute a limitation on the code optimization device for a heterogeneous HPC platform. It may include more components than the above, or a combination of certain components, or different components. For example, the code optimization device for the heterogeneous HPC platform may also include input and output devices, network access devices, buses, etc.

[0070] 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 gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or the processor may be any conventional processor, etc. The processor is the control center of the code optimization device for heterogeneous HPC platforms, and uses various interfaces and lines to connect various parts of the entire code optimization device for heterogeneous HPC platforms.

[0071] The memory may be used to store the computer program and / or module, and the processor implements various functions of the code optimization device for a heterogeneous HPC platform by running or executing the computer program and / or module stored in the memory and calling the data stored in the memory.

[0072] The memory may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area may store data created according to the use of the mobile phone (such as audio data, a phone book, etc.), etc. In addition, the memory may include a high-speed random access memory, and may also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (SmartMediaCard, SMC), a secure digital (SecureDigital, SD) card, a flash card (FlashCard), at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.

[0073] Example 4 This embodiment 4 also provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps of the code optimization method for a heterogeneous HPC platform are implemented.

[0074] If the module / unit of the code optimization system integration for heterogeneous HPC platforms 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.

[0075] Based on such understanding, the present invention implements all or part of the processes in the above-mentioned code optimization method for heterogeneous HPC platforms, and can also be completed by instructing related hardware through a computer program, and the computer program can be stored in a computer-readable storage medium, and when the computer program is executed by a processor, the steps of the above-mentioned code optimization method for heterogeneous HPC platforms can be implemented. 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 preset intermediate form, etc.

[0076] The computer-readable storage medium may include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signal, telecommunication signal and software distribution medium, etc.

[0077] It should be noted that the content contained in the computer-readable storage 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 storage media do not include electrical carrier signals and telecommunication signals.

[0078] Example 5 This embodiment 5 provides a computer product, which includes a computer program, and the computer program is stored in a computer-readable storage medium; a processor of a code optimization device for a heterogeneous HPC platform reads the computer program from the computer-readable storage medium, and the processor executes the computer program, so that the code optimization device for a heterogeneous HPC platform can execute the code optimization method for a heterogeneous HPC platform described in embodiment 1, which will not be repeated here.

[0079] It should be noted that a person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing related hardware through a computer program. The program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods.

[0080] The code optimization method for heterogeneous HPC platforms described in the present invention is divided into three key stages: dynamic memory access feature acquisition, memory access strategy generation and optimized code generation; wherein, in both the dynamic memory access feature acquisition and optimized code generation stages, sophisticated intelligent agent technology aligned with human needs is used to guide large language models (LLMs) to complete the optimization process without fine-tuning the large model, thereby ensuring flexibility and adaptability.

[0081] In the present invention, the optimization process is simplified by modifying the source code based on prompt guidance by the tuning agent, without the need for extensive retraining of large-scale data sets; at the same time, it is able to combine human intentions with LLM capabilities, promote efficient and accurate code generation, and meet the unique needs of the HPC environment; wherein, the tuning agent is a framework for optimizing memory access of heterogeneous high-performance computing (HPC) platforms, which effectively combines the advantages of pre-trained LLMs with dynamic learning capabilities, and adopts a small number of sample context learning (ICL), that is, the tuning agent learns from a few examples in the input context, which enhances the predictive performance of the model and makes it closer to the human learning process, making the interaction more explainable and adaptable; by integrating ICL, OptiAgent can quickly and robustly adapt to new tasks, and can remain efficient even in the face of changing application requirements; secondly, the use of natural language prompts allows flexible and transparent interactions, making it easy to integrate human expertise into the optimization process.

[0082] The above embodiment is only one of the implementation methods that can realize the technical solution of the present invention. The scope of protection claimed by the present invention is not limited only to this embodiment, but also includes changes, replacements and other implementation methods that can be easily thought of by any technician familiar with the technical field within the technical scope disclosed by the present invention.

Claims

1. A code optimization method for a heterogeneous HPC platform, characterized in that: include: Obtain the source code to be optimized and determine the instrumentation prompt words and strategy prompt words; Inputting the source code to be optimized, the plugging prompt word and the strategy prompt word into the tuning agent, so as to optimize the memory access of the source code to be optimized by using the tuning agent to obtain the optimized code; The tuning agent includes a memory access feature acquisition module, a memory access strategy generation module and an optimization code generation module; The memory access feature acquisition module is used to dynamically insert measurement code into the source code to be optimized based on the instrumentation prompt word and the instrumentation tool guided by the large language model to obtain the instrumentation code; run the instrumentation code to obtain dynamic memory access features; The memory access strategy generation module is used to generate a memory access strategy through reinforcement learning according to the dynamic memory access characteristics; The optimized code generation module is used to insert the optimal memory access strategy into the source code to be optimized according to the strategy prompt word and based on the large language model to generate optimized code.

2. A code optimization method for a heterogeneous HPC platform according to claim 1, characterized in that: The dynamic memory access characteristics include a memory access step length, a probability of each memory access step length, and a size of a data block; wherein a data block is a continuous memory area occupied by an array variable referenced in a kernel function.

3. A code optimization method for a heterogeneous HPC platform according to claim 1, characterized in that: According to the instrumentation prompt word, an instrumentation tool guided by a large language model dynamically inserts measurement code into the source code to be optimized to obtain the instrumentation code, including: Inputting the source code to be optimized into the large language model, analyzing the context of the source code to be identified based on the plugging hint words, and obtaining the location where the source code needs to be plugged; According to the plugging prompt word and the position of the source code that needs to be plugged, the measurement code is dynamically inserted into the source code to be optimized using the plugging tool to obtain the plugging code.

4. A code optimization method for a heterogeneous HPC platform according to claim 1, characterized in that: The process of generating a memory access strategy through reinforcement learning according to the dynamic memory access characteristics includes: A pre-trained reinforcement learning module is used to perform reinforcement learning on dynamic memory access features to generate a memory access strategy; wherein the pre-trained reinforcement learning module is a reinforcement learning module trained using a preset data set, and the preset data set includes memory access behaviors, performance indicators, and on-chip cache utilization of different programs in a heterogeneous HPC platform.

5. A code optimization method for a heterogeneous HPC platform according to claim 4, characterized in that: A mixed reward function is introduced into the pre-trained reinforcement learning module; wherein the mixed reward function is: in, is the mixed reward function; is the weight of the performance acceleration ratio; is the performance acceleration ratio; is the weight of cache hit rate; is the cache hit rate.

6. A code optimization method for a heterogeneous HPC platform according to claim 1, characterized in that: The process of inserting the memory access strategy into the source code to be optimized based on the large language model according to the strategy prompt word to generate the optimized code includes: Inputting the source code to be optimized, the strategy prompt words and the memory access strategy into a large language model to generate an optimal memory access strategy; According to the optimal memory access strategy, the preset code is inserted or modified in the source code to be optimized to generate the optimized code.

7. A code optimization system for a heterogeneous HPC platform, characterized in that: include: An acquisition module is used to acquire the source code to be optimized and determine the instrumentation prompt words and strategy prompt words; An optimization module, used for inputting the source code to be optimized, the plugging prompt word and the strategy prompt word into the tuning agent, so as to use the tuning agent to perform memory access optimization on the source code to be optimized to obtain optimized code; The tuning agent includes a memory access feature acquisition module, a memory access strategy generation module and an optimization code generation module; The memory access feature acquisition module is used to dynamically insert measurement code into the source code to be optimized based on the instrumentation prompt word and the instrumentation tool guided by the large language model to obtain the instrumentation code; run the instrumentation code to obtain dynamic memory access features; A memory access strategy generation module, used to generate a memory access strategy through reinforcement learning according to the dynamic memory access characteristics; The optimized code generation module is used to insert the optimal memory access strategy into the source code to be optimized according to the strategy prompt word and based on the large language model to generate optimized code.

8. A code optimization device for a heterogeneous HPC platform, characterized in that: include: a processor suitable for executing a computer program; A computer-readable storage medium, wherein a computer program is stored in the computer-readable storage medium, and when the computer program is executed by the processor, the code optimization method for a heterogeneous HPC platform according to any one of claims 1 to 6 is executed.

9. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the code optimization method for a heterogeneous HPC platform according to any one of claims 1 to 6 is implemented.

10. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the code optimization method for a heterogeneous HPC platform is implemented as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Progressive intelligent backtracking vectorization code tuning method

    CN103207786A

  • Memory access instruction instrumentation optimization method in multi-thread application scene

    CN110187884A

  • Automated code optimization techniques for high-performance computing

    IN202441055759A

Cited By

  • Code optimization method and device, electronic equipment, storage medium and computer product

    CN120335819A