A code optimization method for a heterogeneous HPC platform and related apparatus
By tuning the intelligent agent to dynamically obtain memory access characteristics and generate optimized code on a heterogeneous HPC platform, the problem of limited model versatility in existing technologies is solved, efficient and accurate code optimization is achieved, and the flexibility and adaptability of the model are improved.
Patent Information
- Application Number
- CN202510102918.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-22
- Publication Date
- 2025-10-10
- Estimated Expiration
- 2045-01-22
AI Technical Summary
On heterogeneous HPC platforms, the fine-tuning of existing technologies 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.
A tuning agent is used, including a memory access feature acquisition module, a memory access strategy generation module, and an optimized code generation module. It uses a large language model and reinforcement learning to dynamically obtain memory access features and generate optimized code, and guides code optimization through instrumentation tools and strategy prompts.
It achieves efficient and accurate code optimization on heterogeneous HPC platforms, simplifies the optimization process, improves the flexibility and adaptability of the model, and meets the unique needs of the HPC environment.
Smart Images

Figure CN119917107B_ABST
Abstract
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, significantly improving the software development process by leveraging their predictive capabilities. 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 can 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-purpose programming. Specifically, HPC code has complex memory access patterns, parallelism, and platform-specific optimizations, making open source HPC code scarce and domain-complex. This, combined with the lack of necessary domain-specific knowledge to optimize HPC applications, poses a significant challenge to LLMs. Currently, LLMs typically 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 and resulting in poor adaptability and flexibility. Summary of the Invention
[0005] In response to the technical problems existing in the prior art, the present invention provides a code optimization method and related devices for heterogeneous HPC platforms 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:
[0007] The present invention provides a code optimization method for a heterogeneous HPC platform, comprising:
[0008] Obtain the source code to be optimized and determine the instrumentation prompt words and strategy prompt words;
[0009] Inputting the source code to be optimized, the instrumentation 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 the tuning agent to obtain optimized code;
[0010] The optimization agent includes a memory access feature acquisition module, a memory access strategy generation module and an optimization code generation module;
[0011] The memory access feature acquisition module is configured 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 instrumentation code; and run the instrumentation code to obtain dynamic memory access features;
[0012] The memory access strategy generation module is used to generate a memory access strategy through reinforcement learning according to the dynamic memory access characteristics;
[0013] The optimized code generation module is used to insert the optimal memory access strategy into the source code to be optimized based on the strategy prompt word and a large language model to generate optimized code.
[0014] 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.
[0015] 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:
[0016] Inputting the source code to be optimized into a large language model, analyzing the context of the source code to be identified based on the instrumentation hint words, and obtaining the location where the source code needs to be instrumented;
[0017] According to the instrumentation hint word and the position of the source code that needs to be instrumented, an instrumentation tool is used to dynamically insert measurement code into the source code to be optimized to obtain instrumentation code.
[0018] Furthermore, the process of generating a memory access strategy through reinforcement learning based on the dynamic memory access characteristics includes:
[0019] A pre-trained reinforcement learning module is used to perform reinforcement learning on dynamic memory access features to generate a memory access strategy. The pre-trained reinforcement learning module is trained using a preset dataset, which includes the memory access behavior, performance indicators, and on-chip cache utilization of different programs in a heterogeneous HPC platform.
[0020] Furthermore, a hybrid reward function is introduced into the pre-trained reinforcement learning module; wherein the hybrid reward function is:
[0021]
[0022]
[0023]
[0024] 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.
[0025] Furthermore, according to the strategy hint words, the memory access strategy is inserted into the source code to be optimized based on a large language model to generate optimized code, including:
[0026] Inputting the source code to be optimized, the strategy hint words and the memory access strategy into a large language model to generate an optimal memory access strategy;
[0027] According to the optimal memory access strategy, the preset code is inserted or modified in the source code to be optimized to generate optimized code.
[0028] The present invention also provides a code optimization system for a heterogeneous HPC platform, comprising:
[0029] The acquisition module is used to obtain the source code to be optimized and determine the instrumentation prompt words and strategy prompt words;
[0030] an optimization module, configured to input the source code to be optimized, the instrumentation prompt word, and the strategy prompt word into a tuning agent, so as to optimize memory access of the source code to be optimized by the tuning agent to obtain optimized code;
[0031] The optimization agent includes a memory access feature acquisition module, a memory access strategy generation module and an optimization code generation module;
[0032] The memory access feature acquisition module is configured 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 instrumentation code; and run the instrumentation code to obtain dynamic memory access features;
[0033] A memory access strategy generation module, configured to generate a memory access strategy through reinforcement learning based on the dynamic memory access characteristics;
[0034] The optimized code generation module is used to insert the optimal memory access strategy into the source code to be optimized based on the strategy prompt word and a large language model to generate optimized code.
[0035] The present invention also provides a code optimization device for a heterogeneous HPC platform, comprising:
[0036] a processor suitable for executing a computer program;
[0037] A computer-readable storage medium stores a computer program, and when the computer program is executed by the processor, the code optimization method for a heterogeneous HPC platform is executed.
[0038] The present invention also provides a computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the code optimization method for a heterogeneous HPC platform.
[0039] The present invention also provides a computer program product, which includes a computer program. When the computer program is executed by a processor, it implements the code optimization method for a heterogeneous HPC platform.
[0040] Compared with the prior art, the present invention has the following beneficial effects:
[0041] 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. In the memory access feature acquisition module and the optimized code generation module, prompt-based guidance for source code modification is implemented based on instrumentation prompts and strategy prompts, simplifying the optimization process without the need for extensive retraining of large-scale data sets. By combining human intent with the capabilities of large language models, the present invention promotes efficient and accurate code generation to optimize memory access in an HPC environment, meeting the unique needs of the HPC environment and ensuring flexibility and adaptability.
[0042] 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
[0043] Figure 1 Flowchart of the code optimization method for a heterogeneous HPC platform provided in Example 1;
[0044] Figure 2 This is an example diagram of the instrumentation of the DAXPY operator using the memory access feature acquisition module in Example 1;
[0045] Figure 3 This is an example diagram of generating optimized code for the DAXPY operator using the optimized code generation module in Example 1;
[0046] Figure 4 This is a graph showing the code generation performance results of the code optimization method for heterogeneous HPC platforms described in Example 1 on the HumanevalDSP dataset;
[0047] Figure 5 This is a graph showing the code generation performance results of the code optimization method for a heterogeneous HPC platform described in Example 1 on DspStandard;
[0048] 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;
[0049] Figure 7 This is a structural block diagram of the code optimization system for a heterogeneous HPC platform provided in Example 2;
[0050] Figure 8 This is a structural block diagram of the code optimization device for a heterogeneous HPC platform provided in Example 3. DETAILED DESCRIPTION
[0051] 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 intended to limit the present invention.
[0052] Example 1
[0053] As attached Figure 1 As shown, this embodiment 1 provides a code optimization method for a heterogeneous HPC platform, including the following steps:
[0054] Step 1: Obtain the source code to be optimized and determine the instrumentation prompt words and strategy prompt words. The source code to be optimized is heterogeneous HPC (High-Performance Computing) code; the instrumentation prompt words and strategy prompt words are both natural language.
[0055] Step 2: Input the source code to be optimized, the instrumentation hint, and the strategy hint into an optimization agent (OptiAgent), so that the optimization agent can perform memory access optimization on the source code to obtain optimized code. The optimization agent includes a memory access feature acquisition module, a memory access strategy generation module, and an optimized code generation module.
[0056] Step 3: Output the optimized code.
[0057] 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 instrumentation code; and run the instrumentation code to obtain dynamic memory access features. Specifically, the following steps are included:
[0058] 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 instrumentation hint words, and obtain the location of the source code that needs instrumentation.
[0059] 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.
[0060] Step 213: Run the instrumentation code to obtain dynamic memory access characteristics; wherein the dynamic memory access characteristics include memory access step length, the probability of each memory access step length, and the size of the data block; wherein the data block is the continuous memory area occupied by the array variable referenced in the kernel function.
[0061] It should be noted that in the memory access feature acquisition module, by creating and deploying an instrumentation agent, measurement code is dynamically inserted 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.
[0062] 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 run effectively in different HPC environments; once deployed, the instrumented agent can be seamlessly integrated into the target application to collect detailed information about memory access patterns, that is, to obtain dynamic memory access characteristics; among them, detailed information about memory access patterns is crucial for understanding how data is accessed during execution.
[0063] 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 for optimizing cache usage and reducing memory latency. 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 serve 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.
[0064] The concept of stream as a subsequence of memory access elements and the distance between any two adjacent elements is called 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 length values are , ; The probability of occurrence of different step lengths is recorded as , satisfying that the sum of all probabilities is equal to 1 and each probability is non-negative, that is, satisfying:
[0065]
[0066] As attached Figure 2 As shown, attached Figure 2 The following example shows how to use the memory access feature acquisition module to obtain DAXPY operators; Figure 2 As can be seen from 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.
[0067] In this embodiment 1, the memory access strategy generation module is used to generate a memory access strategy through reinforcement learning based on 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 behavior, performance indicators, and on-chip cache utilization of different programs in a heterogeneous HPC platform.
[0068] In the memory access policy 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 policy. A hybrid reward function is used to combine program speedup and cache hit rate to make more intelligent and adaptive policy decisions.
[0069] 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.
[0070] It should be noted that in order to train an effective reinforcement learning module, a dataset is collected in advance. The collected dataset 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.
[0071] Secondly, a hybrid reward function is introduced into the pre-trained reinforcement learning module to select the optimal caching 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 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.
[0072] Specifically, the hybrid reward function is:
[0073]
[0074]
[0075]
[0076] in, is the mixed reward function; is the weight of the performance acceleration ratio; is the performance speedup ratio, which is the ratio of the optimized execution time to the unoptimized execution time. Indicates improved performance; is the weight of cache hit rate; The cache hit rate is the proportion of cache accesses successfully served by the cache. This means better cache efficiency.
[0077] In this embodiment 1, the optimized code generation module is used to insert the optimal memory access strategy into the source code to be optimized based on the strategy prompt word and a large language model to generate 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. Based on the optimal memory access strategy, the preset code is inserted or modified in the source code to be optimized to generate optimized code.
[0078] 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.
[0079] The optimization agent is provided with strategic prompts and unoptimized benchmark code; 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 conforms to memory efficiency best practices to ensure consistency with the performance goals of the task; the unoptimized benchmark code is used as a reference point in the optimization process, allowing the optimization agent to measure the improvement effect.
[0080] After the initial input, a reinforcement learning (RL) strategy is used to further improve the LLM's ability to optimize memory access patterns; the strategy Extensive experimentation and tuning enabled the model to adjust its code generation based on the optimal memory access strategy; this process can be expressed mathematically as follows:
[0081]
[0082] in, is a performance metric, such as speedup; A set of memory access strategies to improve code efficiency.
[0083] 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 patterns and further refine the generated code; as shown in the attached 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 2.
[0084] In this embodiment 1, the large language model is one of GPT-4, Qwen2.5-Coder and GLM-4-Plus.
[0085] Experimental evaluation
[0086] (1) Correctness of code generation
[0087] 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.
[0088] 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 platform on DspStandard are given in the figure; Figure 4 、 5 The average pass@k rate of code generation test in the 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 domains. 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.
[0089] (2) Code generation speedup
[0090] In order to evaluate the code generation effect of the tuning agent on the HumanevalDSP dataset, a comprehensive performance analysis was conducted using the 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 6 The speedup results of the code optimization method for heterogeneous HPC platforms are given in the attached figure. Figure 6 As can be seen, significant performance improvements were achieved in all test cases; the speedup values were always above 1, indicating that the generated code not only reached the baseline performance but also exceeded it. This continued superior performance highlights the framework’s ability to generate efficient code.
[0091] As shown in Table 1 below, the average speedup ratios of the code optimization method for heterogeneous HPC platforms on different data sets are given. As can be seen from Table 1 below, a clear comparison of the average speedup ratios 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.
[0092] Table 1 Average speedup on different datasets
[0093]
[0094] In this Example 1, two datasets were 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 performance of × 3 . An average speedup of 35% was achieved on Humaneval-DSP. × 1 . The results show that OptiAgent can significantly improve the performance of parallel applications by simplifying the development and maintenance of complex parallel applications while significantly enhancing their performance.
[0095] The code method for a heterogeneous HPC platform described in Example 1 introduces a tuning agent, which serves as a scalable framework for enhancing memory access performance based on large language models. The tuning agent utilizes large language models (LLMs) to optimize memory access in a heterogeneous DSP architecture. The OptiAgent dynamically adjusts its strategy by continuously analyzing runtime conditions to ensure optimal performance. The OptiAgent converts the program's memory access characteristics into an efficient memory management strategy to generate code that meets specific goals.
[0096] Example 2
[0097] 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.
[0098] An acquisition module is used to obtain the source code to be optimized and determine the instrumentation prompt words and strategy prompt words; an optimization module is used to input the source code to be optimized, the instrumentation prompt words and strategy prompt words into the tuning agent, so as to use the tuning agent to optimize the memory access of the source code to be optimized to obtain optimized code; and an output module is used to output the optimized code.
[0099] The tuning agent includes a memory access feature acquisition module, a memory access strategy generation module and an optimization code generation module.
[0100] 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 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 based on 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.
[0101] Example 3
[0102] 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.
[0103] 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:
[0104] Obtain source code to be optimized, and determine an instrumentation prompt word and a strategy prompt word; input the source code to be optimized, the instrumentation prompt word and the strategy prompt word into a tuning agent, so as to use the tuning agent to perform memory access optimization on the source code to be optimized to obtain an optimized code; and output the optimized code.
[0105] The tuning agent includes a memory access feature acquisition module, a memory access strategy generation module and an optimization code generation module.
[0106] 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 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 based on 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.
[0107] 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:
[0108] An acquisition module is used to obtain the source code to be optimized and determine the instrumentation prompt words and strategy prompt words; an optimization module is used to input the source code to be optimized, the instrumentation prompt words and strategy prompt words into the tuning agent, so as to use the tuning agent to optimize the memory access of the source code to be optimized to obtain optimized code; and an output module is used to output the optimized code.
[0109] Among them, the tuning agent includes a memory access feature acquisition module, a memory access strategy generation module and an optimization code generation module.
[0110] 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 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 based on 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.
[0111] 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 implement the present invention. The one or more modules / units may be a series of computer program instruction segments capable of implementing preset functions, and the instruction segments are used to describe the execution process of the computer program in the code optimization device for a heterogeneous HPC platform.
[0112] The code optimization device for a heterogeneous HPC platform can be a computing device such as a desktop computer, a notebook, a palm computer, and a cloud server. The code optimization device for a heterogeneous HPC platform can include, but is not limited to, a processor, a memory. Those skilled in the art can understand that the above is an example of the code optimization device for a heterogeneous HPC platform, and does not constitute a limitation on the code optimization device for a heterogeneous HPC platform, and can include more components than the above, or combine certain components, or different components, for example, the code optimization device for a heterogeneous HPC platform can also include an input and output device, a network access device, a bus, and the like.
[0113] The processor can be a central processing unit (CPU), and can also be other general-purpose processors, a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware component, and the like. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, and the like. The processor is a control center of the code optimization device for a heterogeneous HPC platform, and connects various parts of the code optimization device for a heterogeneous HPC platform through various interfaces and lines.
[0114] The memory can be used to store the computer program and / or module, and the processor realizes 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.
[0115] The memory can mainly include a program storage area and a data storage area. The program storage area can store an operating system, at least one application required by a function (such as a sound playing function, an image playing function, and the like), and the like. The data storage area can store data created according to the use of the mobile phone (such as audio data, a phone book, and the like), and the like. In addition, the memory can include a high-speed random access memory, and can also include a non-volatile memory, for example, a hard disk, a memory, a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, at least one disk storage device, a flash memory device, or other volatile solid-state memory device.
[0116] Embodiment 4
[0117] This embodiment 4 further 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.
[0118] If the module / unit for 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.
[0119] Based on this understanding, the present invention implements all or part of the process of the above-mentioned code optimization method for heterogeneous HPC platforms, and can also be completed by using a computer program to instruct related hardware. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by a processor, it can implement the steps of the above-mentioned code optimization method for heterogeneous HPC platforms. The computer program includes computer program code, which can be in source code form, object code form, executable file, or a preset intermediate form.
[0120] The computer-readable storage medium may include: any entity or device that can carry 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.
[0121] 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 practices in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practices, computer-readable storage media do not include electrical carrier signals and telecommunication signals.
[0122] Example 5
[0123] This embodiment 5 provides a computer product, which includes a computer program product, which 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.
[0124] It should be noted that a person skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing the relevant 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.
[0125] 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. In both the dynamic memory access feature acquisition and optimized code generation stages, sophisticated intelligent agent technology aligned with human needs is utilized to guide large language models (LLMs) to complete the optimization process without fine-tuning the large models, thereby ensuring flexibility and adaptability.
[0126] In the present invention, the optimization process is simplified by modifying the source code based on prompt guidance by the tuning agent, eliminating the need for extensive retraining of large-scale datasets. 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 HPC environments. Among them, the tuning agent is a framework for optimizing memory access on heterogeneous high-performance computing (HPC) platforms. It effectively combines the advantages of pre-trained LLMs with dynamic learning capabilities. It enhances the predictive performance of the model by adopting a small amount of sample context learning (ICL), that is, the tuning agent learns from a few examples in the input context, and makes it closer to the human learning process, making the interaction more explainable and adaptable. By integrating ICL, OptiAgent can adapt to new tasks quickly and robustly, and remain efficient even in the face of changing application requirements. Secondly, the use of natural language prompts allows flexible and transparent interaction, making it easy to integrate human expertise into the optimization process.
[0127] 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 this technical field within the technical scope disclosed by the present invention.
Claims
1. A code optimization method for a heterogeneous HPC platform, wherein the heterogeneous HPC platform is a heterogeneous high-performance computing 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 instrumentation 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 the tuning agent to obtain optimized code; The optimization 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 configured 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 instrumentation code; and 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 input the source code to be optimized, the strategy prompt word and the memory access strategy into the large language model to generate the optimal memory access strategy; according to the optimal memory access strategy, insert or modify the preset code in the source code to be optimized to generate the optimized code; The dynamic memory access characteristics include the memory access step length, the probability of each memory access step length, and the size of the data block; wherein the data block is the continuous memory area occupied by the array variable referenced in the kernel function; The process of generating a memory access strategy through reinforcement learning based on 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. The pre-trained reinforcement learning module is trained using a preset dataset, which includes the memory access behavior, performance indicators, and on-chip cache utilization of different programs in a heterogeneous HPC platform.
2. 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 a large language model, analyzing the context of the source code to be identified based on the instrumentation hint words, and obtaining the location where the source code needs to be instrumented; According to the instrumentation hint word and the position of the source code that needs to be instrumented, an instrumentation tool is used to dynamically insert measurement code into the source code to be optimized to obtain instrumentation code.
3. The code optimization method for a heterogeneous HPC platform according to claim 1, 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 ratio; On-chip cache.
4. A code optimization system for a heterogeneous HPC platform, wherein the heterogeneous HPC platform is a heterogeneous high-performance computing platform, characterized in that: include: The acquisition module is used to obtain the source code to be optimized and determine the instrumentation prompt words and strategy prompt words; an optimization module, configured to input the source code to be optimized, the instrumentation prompt word, and the strategy prompt word into a tuning agent, so as to optimize memory access of the source code to be optimized by the tuning agent to obtain optimized code; The optimization 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 configured 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 instrumentation code; and run the instrumentation code to obtain dynamic memory access features; A memory access strategy generation module, configured to generate a memory access strategy through reinforcement learning based on the dynamic memory access characteristics; The optimized code generation module is used to input the source code to be optimized, the strategy prompt word and the memory access strategy into the large language model to generate the optimal memory access strategy; according to the optimal memory access strategy, insert or modify the preset code in the source code to be optimized to generate the optimized code; The dynamic memory access characteristics include the memory access step length, the probability of each memory access step length, and the size of the data block; wherein the data block is the continuous memory area occupied by the array variable referenced in the kernel function; The process of generating a memory access strategy through reinforcement learning based on 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. The pre-trained reinforcement learning module is trained using a preset dataset, which includes the memory access behavior, performance indicators, and on-chip cache utilization of different programs in a heterogeneous HPC platform.
5. 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 having a computer program stored therein, wherein 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 3 is executed.
6. 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 3 is implemented.
7. A computer program product, characterized in that The computer program product includes a computer program, and 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 3 is implemented.
Citation Information
Patent Citations
Progressive intelligent backtracking vectorization code tuning method
CN103207786A
Memory access instruction instrumentation optimization method in multi-thread application scene
CN110187884A