Communication library optimization method and device, equipment, readable storage medium and program product
By generating a set of implementation strategies in the communication library and performing performance evaluation, the optimal strategy is selected to update the source code, thus solving the problem of insufficient accuracy of the communication library in different environments and improving communication performance and adaptability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- DAWNING INT INFORMATION IND CO LTD
- Filing Date
- 2025-12-30
- Publication Date
- 2026-05-01
AI Technical Summary
Existing communication libraries exhibit low accuracy in communication solutions under different hardware frameworks, network topologies, or data scales, thus affecting communication performance.
By generating a set of implementation strategies for communication primitives, performance evaluation is performed for each test environment, the optimal implementation strategy is selected, and the communication library source code is updated to match the real environment.
It improves communication performance, reduces the subjectivity of human experience, and enhances the adaptability and reliability of the communication library in different environments.
Smart Images

Figure CN121967403A_ABST
Abstract
Description
Communication library optimization methods, apparatus, devices, readable storage media, and program products Technical Field
[0001] This application relates to the field of communication library technology, and in particular to a communication library optimization method, apparatus, device, readable storage medium, and program product. Background Technology
[0002] With the development of artificial intelligence technology, the parameter scale of deep learning models is growing exponentially, and the computing power of a single machine or single GPU can no longer meet the training needs of ultra-large-scale models. To shorten training time and improve computational efficiency, distributed parallel training has gradually become the mainstream solution. Distributed training relies on the collaborative computing of multiple GPUs or even multiple nodes, and in this process, communication efficiency often becomes a key factor affecting overall performance. In distributed deep learning training, communication and computation are complementary. The computation part relies on the computing power of GPUs, while the communication part is responsible for transmitting and synchronizing data between different GPUs. As the model size and cluster size gradually increase, the proportion of time occupied by communication continues to rise, gradually becoming the main bottleneck affecting overall training efficiency. According to industry experience, in clusters with hundreds or even thousands of GPUs, communication overhead may account for more than half of the training time, seriously affecting parallel efficiency.
[0003] In traditional technologies, to support efficient distributed training, the industry has developed various communication libraries. These libraries provide efficient ensemble communication implementations for GPU cluster environments, enabling automatic data exchange between processes during training. These libraries are widely used in deep learning frameworks to implement efficient ensemble communication operations, which are the most critical communication primitives in distributed training, determining whether gradients and parameters can be quickly synchronized in each iteration. Communication libraries typically include multiple communication algorithms and transmission protocols, and use certain rules to select the appropriate combination of algorithms and protocols for different scenarios.
[0004] However, most current communication libraries use static weights for algorithm and protocol selection. These static weights are usually derived from experience or limited scenario testing. Under different hardware frameworks, network topologies, or data scales, the selected communication scheme may have low accuracy and affect communication performance. Summary of the Invention
[0005] Therefore, it is necessary to provide a communication library optimization method, apparatus, computer equipment, computer-readable storage medium, and computer program product that can improve communication performance in response to the above-mentioned technical problems.
[0006] On one hand, this application provides a communication library optimization method, comprising: for communication primitives in the communication library, generating an implementation strategy set corresponding to the communication primitives according to multiple communication protocols and multiple communication algorithms, wherein each implementation strategy in the implementation strategy set includes a communication protocol and a communication algorithm; for each implementation strategy in the implementation strategy set, running the implementation strategy in multiple test environments respectively to obtain a performance evaluation value of the implementation strategy in the multiple test environments; for each of the multiple test environments, selecting the optimal implementation strategy of the communication primitive in the test environment from the implementation strategy set according to the performance evaluation value; using the optimal implementation strategy of the communication primitive in each of the test environments to update the source code of the communication library to obtain updated source code of the communication library, wherein the updated source code is used to generate a communication library file, and the communication library file is used to select an implementation strategy matching the real environment from the optimal implementation strategies of the communication primitive for the communication task corresponding to the communication primitive in a real environment.
[0007] In this embodiment, for communication primitives in the communication library, a set of implementation strategies corresponding to the communication primitives is determined. The implementation strategies used to implement the communication primitives in the implementation strategy set include communication protocols and communication algorithms. For each implementation strategy in the implementation strategy set, the implementation strategy is run in multiple test environments to obtain the performance evaluation value of the implementation strategy in multiple test environments. For each test environment, the optimal implementation strategy of the communication primitive in the test environment is selected from the implementation strategy set based on the performance evaluation value. Using the optimal implementation strategy of the communication primitive in each test environment, the source code of the communication library is updated to obtain the updated source code of the communication library. The updated source code is used to generate the communication library file. Since the communication library file is used to select the implementation strategy that matches the real environment from the optimal implementation strategies of the communication primitive for the communication task corresponding to the communication primitive in the real environment, the performance of the matched implementation strategy can be guaranteed, which helps to improve communication performance.
[0008] In some embodiments, selecting the optimal implementation strategy for the communication primitive in the test environment from the set of implementation strategies based on the performance evaluation value includes: selecting the implementation strategy with the best performance from the set of implementation strategies based on the performance evaluation value; and determining the optimal implementation strategy for the communication primitive in the test environment based on the implementation strategy with the best performance.
[0009] In this embodiment, the optimal implementation strategy for communication primitives in the test environment is determined based on the best performance implementation strategy, which can guarantee the performance of the optimal implementation strategy.
[0010] In some embodiments, determining the optimal implementation strategy for the communication primitive in the test environment based on the optimal performance implementation strategy includes: determining a reference implementation strategy for the communication primitive in the test environment, and obtaining a performance evaluation value of the reference implementation strategy in the test environment, wherein the reference implementation strategy is an implementation strategy selected for the communication primitive in the test environment using the default selection method of the communication library; determining the performance improvement of the optimal implementation strategy based on the performance evaluation value of the optimal implementation strategy in the test environment and the performance evaluation value of the reference implementation strategy in the test environment; and, if the performance improvement is greater than an improvement threshold, using the optimal implementation strategy as the optimal implementation strategy for the communication primitive in the test environment.
[0011] In this embodiment, since the performance improvement is too small, it is usually due to system jitter rather than the quality of the algorithm itself. Therefore, when the performance improvement is greater than the improvement threshold, the best performance implementation strategy is taken as the optimal implementation strategy of the communication primitive in the test environment. This can effectively filter out interference, avoid the subjectivity brought about by human experience, and make the screening results objective, reliable and repeatable.
[0012] In some embodiments, each test environment includes multiple test conditions, the multiple test conditions including data scale and node scale. The step of updating the source code of the communication library using the optimal implementation strategy of the communication primitive in each test environment to obtain the updated source code of the communication library includes: generating a data scale range based on the data scale in the test environment; generating a strategy optimization record of the communication primitive in the test environment based on the data scale range, the communication primitive, the node scale of the test environment, and the optimal implementation strategy; and updating the source code of the communication library based on the strategy optimization record of the communication primitive in the test environment to obtain the updated source code of the communication library.
[0013] In this embodiment, since the strategy optimization record contains the data scale range, communication primitives, node scale of the test environment, and optimal implementation strategy, the implementation strategy can be matched based on the strategy optimization record, thus providing conditions for matching the implementation strategy.
[0014] In some embodiments, the data size of some test environments in the plurality of test environments increases according to a preset rule and the node size is consistent. The step of generating a data size range based on the data size in the test environments includes: if the optimal implementation strategy of the communication primitive is consistent in at least two test environments and the at least two test environments meet the merging condition, then a data size range is generated based on the data size in the at least two test environments; wherein, the merging condition includes: the data size increases according to the preset rule and the node size is consistent.
[0015] In this embodiment, the data size of some test environments in multiple test environments increases according to a preset rule and the node size is consistent. Therefore, the optimal implementation strategy can be determined under different data size scenarios when the node size is consistent. Since the optimal implementation strategy of the communication primitive is consistent in at least two test environments and at least two test environments meet the merging condition, it means that the optimal implementation strategy remains consistent as the data size increases. Therefore, by generating a data size range based on the data size in at least two test environments, a strategy optimization record can be generated for at least two test environments. Compared with generating a strategy optimization record for each test environment, the number of strategy optimization records is reduced, which helps to speed up the efficiency of matching implementation strategies.
[0016] In some embodiments, generating a data size range based on the data sizes in the at least two test environments includes: determining a maximum data size and a minimum data size from the data sizes in the at least two test environments; determining an upper limit for the data size based on the maximum data size and a lower limit for the data size based on the minimum data size, wherein the upper limit for the data size is greater than the maximum data size and the lower limit for the data size is less than the minimum data size; and generating a data size range based on the upper limit for the data size and the lower limit for the data size.
[0017] In this embodiment, since the data size fluctuates, the optimal implementation strategy usually remains unchanged. Therefore, by generating a data size range based on the upper and lower limits of the data size, a larger range of data size can be obtained, making it easier to match the implementation strategy.
[0018] In some embodiments, the method further includes: deploying the communication library file to a real environment, such that when a communication task corresponding to the communication primitive is triggered in the real environment, an implementation strategy matching the real environment is searched from the optimal implementation strategies of the communication primitive based on the communication library file; if a matching strategy is found, the found optimal implementation strategy is executed; if the search fails, an implementation strategy matching the real environment is selected from the implementation strategies of the communication primitive using the default selection method in the communication library, and the selected implementation strategy is executed.
[0019] In this embodiment, the implementation strategy is matched first from the optimal implementation strategies of the communication primitives, and then the implementation strategy is matched using the default selection method in the communication library. This can ensure the performance of the matched implementation strategy as much as possible.
[0020] On the other hand, this application also provides a communication library optimization apparatus, comprising: a strategy determination module, configured to generate an implementation strategy set corresponding to a communication primitive in the communication library based on multiple communication protocols and multiple communication algorithms, wherein each implementation strategy in the implementation strategy set includes a communication protocol and a communication algorithm; an evaluation value determination module, configured to run the implementation strategy in the implementation strategy set under multiple test environments to obtain a performance evaluation value of the implementation strategy under the multiple test environments; a strategy selection module, configured to select the optimal implementation strategy of the communication primitive in the test environment from the implementation strategy set for each test environment based on the performance evaluation value; and a source code update module, configured to update the source code of the communication library using the optimal implementation strategy of the communication primitive in each test environment to obtain updated source code of the communication library, wherein the updated source code is used to generate a communication library file, and the communication library file is used to select an implementation strategy matching the real environment from the optimal implementation strategies of the communication primitive for the communication task corresponding to the communication primitive in a real environment.
[0021] On the other hand, this application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above-described communication library optimization method.
[0022] On the other hand, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps in the above-described communication library optimization method.
[0023] On the other hand, this application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps in the above-described communication library optimization method.
[0024] The aforementioned communication library optimization method, apparatus, computer equipment, computer-readable storage medium, and computer program product, for communication primitives in the communication library, determine a set of implementation strategies corresponding to the communication primitives. The implementation strategies in the set include communication protocols and communication algorithms. For each implementation strategy in the set, the implementation strategy is run in multiple test environments to obtain performance evaluation values for the implementation strategy in multiple test environments. For each test environment, the optimal implementation strategy for the communication primitive in the test environment is selected from the implementation strategy set based on the performance evaluation values. Using the optimal implementation strategy for the communication primitive in each test environment, the source code of the communication library is updated to obtain updated source code for the communication library. The updated source code is used to generate a communication library file. Since the communication library file is used in a real environment for the communication task corresponding to the communication primitive, it selects an implementation strategy that matches the real environment from the optimal implementation strategies of the communication primitive, thereby ensuring the performance of the matched implementation strategy and helping to improve communication performance. Attached Figure Description
[0025] To more clearly illustrate the technical solutions in the embodiments of this application or related technologies, the drawings used in the description of the embodiments of this application or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0026] Figure 1 is an application environment diagram of the communication library optimization method in one embodiment;
[0027] Figure 2 is a flowchart illustrating a communication library optimization method in one embodiment;
[0028] Figure 3 is a flowchart illustrating the communication library optimization method in another embodiment;
[0029] Figure 4 is a comparison of the time performance of the AllReduce communication primitive in one embodiment;
[0030] Figure 5 is a comparison of the bandwidth performance of the communication primitive Reduce in one embodiment;
[0031] Figure 6 is a comparison of the bandwidth performance of the AllReduce communication primitive in one embodiment;
[0032] Figure 7 is a comparison of the bandwidth effect of the Broadcast communication primitive in one embodiment;
[0033] Figure 8 is a comparison of the bandwidth effect of the communication primitive Reduce in another embodiment;
[0034] Figure 9 is a structural block diagram of a communication library optimization device in one embodiment;
[0035] Figure 10 is an internal structure diagram of a computer device in one embodiment;
[0036] Figure 11 is an internal structural diagram of a computer device in another embodiment. Detailed Implementation
[0037] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0038] It should be noted that the terms "first," "second," etc., used in this application can be used to describe various elements, but these elements are not limited by these terms. These terms are only used to distinguish the first element from the second element. The terms "comprising" and "having," and any variations thereof, used in this application, are intended to cover non-exclusive inclusion. The term "multiple" used in this application refers to two or more. The term "and / or" used in this application refers to one of the embodiments, or any combination of multiple embodiments.
[0039] The communication library optimization method provided in this application embodiment can be applied to the application environment shown in Figure 1. This application environment includes N computing nodes, namely computing node 1 to computing node N, where N≥2. These N computing nodes form a cluster, and the computing nodes can communicate with each other. Each computing node may include an accelerator card such as a GPU (Graphics Processing Unit), and may also include at least one CPU (Central Processing Unit). Each computing node may include the same number of GPUs and the same number of CPUs. For example, each computing node includes 8 GPUs. One of the N computing nodes can be a master node, and the master node can be any computing node. The communication library optimization method provided in this application can be implemented jointly by the master node and the other computing nodes.
[0040] Specifically, for each communication primitive in the communication library, the master node generates a set of implementation strategies corresponding to the communication primitives based on multiple communication protocols and algorithms. Each implementation strategy in the set includes one communication protocol and one communication algorithm. For each implementation strategy, the master node runs the strategy in multiple test environments to obtain performance evaluation values for each strategy in those environments. For each test environment, the master node selects the optimal implementation strategy for the communication primitive from the set based on the performance evaluation values. Using the optimal implementation strategy for each test environment, the master node updates the communication library's source code to obtain updated source code, which is then used to generate the communication library file. The master node can then deploy the communication library file to a real environment. This file is used in the real environment to select the appropriate implementation strategy from the optimal implementation strategies for the communication primitives, matching the real-world requirements.
[0041] The test environment can be determined by the node size and data size; different test environments will have at least one different node size or data size. For example, each compute node contains 8 GPUs. Test environment 1 is a single machine with 8 GPUs, test environment 2 is a dual machine with 16 GPUs, test environment 3 is a triple machine with 24 GPUs, and test environment 4 is a quad machine with 32 GPUs. A single machine with 8 GPUs refers to one compute node containing 8 GPUs. A dual machine with 16 GPUs refers to two compute nodes, each containing 8 GPUs. A triple machine with 24 GPUs refers to three compute nodes, each containing 8 GPUs, and a quad machine with 32 GPUs refers to four compute nodes, each containing 8 GPUs. Data size refers to the amount of data to be transmitted; it can also be called the amount of data transmitted. The real environment can be a cluster consisting of these N compute nodes. Each of these N compute nodes deploys the communication library file, which is generated by compiling the source code of the communication library. The master node can compile the updated source code to obtain the updated communication library file, and then use this updated communication library file to update the communication library files in the compute nodes, thereby optimizing the communication library in the compute node cluster. This compute node cluster can be used for distributed training of large models, and the optimized communication library can improve the efficiency of distributed training.
[0042] Each computing node can be a server. A server can be a standalone physical server, a server cluster or distributed system consisting of multiple physical servers, or a cloud server that provides cloud computing services.
[0043] In an exemplary embodiment, as shown in Figure 2, a communication library optimization method is provided. This method can be executed by the master node, or jointly by the master node and other computing nodes. Taking the application of this method to the master node as an example, it includes the following steps:
[0044] Step 202: For the communication primitives in the communication library, generate a set of implementation strategies corresponding to the communication primitives according to multiple communication protocols and multiple communication algorithms. Each implementation strategy in the set of implementation strategies contains a communication protocol and a communication algorithm.
[0045] The communication library can be a distributed communication library, and it can be publicly available or developed internally by an enterprise or organization. It can be, but is not limited to, NVIDIA's NCCL (NVIDIA Collective Communication Library) and AMD's RCCL (Radeon Collective Communication Library). NCCL is a collective communication library provided by NVIDIA, primarily used for high-performance communication operations such as AllReduce and AllGather in GPU clusters. RCCL is a collective communication library provided by AMD, similar to NCCL, supporting high-performance collective communication on AMD GPUs.
[0046] Communication primitives are the fundamental communication operations in distributed training. These primitives can include, but are not limited to, AllReduce, AllGather, Broadcast, Reduce, and ReduceScatter, and are used for data synchronization and exchange. Communication algorithms are the specific methods for implementing these primitives, and can include, but are not limited to, Ring, Tree, and CollNet. Different algorithms exhibit different performance in terms of bandwidth and latency. Communication protocols are the mechanisms for data transmission, and can include, but are not limited to, SIMPLE, LL, and LL128, determining the sharding method, latency, and bandwidth utilization. Each implementation strategy in the implementation strategy set contains one communication protocol and one communication algorithm. In other words, an implementation strategy is a combination of one communication protocol and one communication algorithm. For example, the combination of Tree and SIMPLE constitutes one implementation strategy, as does the combination of Ring and SIMPLE.
[0047] For example, communication libraries typically include multiple communication algorithms and protocols, and the performance of different combinations varies significantly under different data sizes and topologies. To obtain the optimal implementation strategy, a two-layer loop structure can be used: the outer loop iterates through the communication algorithms, and the inner loop iterates through the communication protocols. Each combination, i.e., the implementation strategy, is tested, and the results are saved, such as performance evaluation values. It should be noted that since a combination of a communication algorithm and a communication protocol may not be suitable for a given communication primitive, inapplicable combinations can be skipped during iteration.
[0048] Step 204: For each implementation strategy in the implementation strategy set, run the implementation strategy in multiple test environments to obtain the performance evaluation value of the implementation strategy in multiple test environments.
[0049] The performance evaluation value may include, but is not limited to, runtime. Runtime is related to communication latency and bandwidth utilization. Runtime can be determined based on communication latency and bandwidth utilization.
[0050] The test environment can be determined by the number of nodes and the amount of data; different test environments will differ in at least one of these two factors. For example, each compute node contains 8 GPUs. Test environment 1 is a single machine with 8 GPUs, test environment 2 is a dual-machine system with 16 GPUs, test environment 3 is a triple-machine system with 24 GPUs, and test environment 4 is a quad-machine system with 32 GPUs. Here, a single machine with 8 GPUs refers to one compute node containing 8 GPUs. A dual-machine system with 16 GPUs refers to four compute nodes, each containing 8 GPUs. A triple-machine system with 24 GPUs refers to three compute nodes, each containing 8 GPUs, and a quad-machine system with 32 GPUs refers to four compute nodes, each containing 8 GPUs. The real-world environment can be a cluster consisting of these N compute nodes.
[0051] For example, the performance testing tool built into the communication library can be used to execute the implementation strategy in a test environment and obtain performance evaluation values. Each test environment can include multiple test conditions. The test conditions and implementation strategy can be input into the performance testing tool for testing to obtain performance evaluation values. Test conditions include node size and data size. For example, if the node size is dual machines with 16 cards and the data size is 2GB, the performance testing tool can select two compute nodes to execute the implementation strategy based on the node size and set the data size to 2GB. Of course, the node size can also be directly represented by node identifiers. For example, the node size can be identified by the node identifiers of compute node 1 and compute node 2, so the performance testing tool can directly determine which compute nodes 1 and 2 need to execute the implementation strategy based on the node size.
[0052] Step 206: For each of the multiple test environments, select the optimal implementation strategy for the communication primitive in the test environment from the set of implementation strategies based on the performance evaluation value.
[0053] For example, the implementation strategy set contains m implementation strategies, designated as implementation strategy 1 to implementation strategy m, and n different test environments, designated as test environment 1 to test environment n. The performance evaluation value of implementation strategy i in test environment j is R. ij 1≤i≤m, 1≤j≤m. Then, for test environment j, based on the performance evaluation value R... ij Select the implementation strategy with the best running performance from implementation strategy 1 to implementation strategy m, and use it as the optimal implementation strategy for the communication primitive in test environment j.
[0054] Step 208: Using the optimal implementation strategy of the communication primitive in each test environment, update the source code of the communication library to obtain the updated source code of the communication library. The updated source code is used to generate the communication library file. The communication library file is used to select the implementation strategy that matches the real environment from the optimal implementation strategies of the communication primitive for the communication task corresponding to the communication primitive in the real environment.
[0055] For example, the optimal implementation strategy can be written into the algorithm and protocol selection module of the communication library source code through an automated program to obtain updated source code. For instance, the cost model calculation results in the source code can be adjusted according to different data volumes, communication primitives, and node sizes, so that the optimal implementation strategy has a higher priority at runtime and is automatically selected and executed by the system.
[0056] For example, after writing the optimal implementation strategy into the source code to obtain updated source code, the updated source code can be compiled to generate a source code library file. The source code library file can select the required implementation strategy at runtime based on the optimal implementation strategy. Users do not need to modify any calling interfaces or scripts and can obtain better communication performance while maintaining their original usage habits.
[0057] For example, there are multiple communication primitives. For each communication primitive, the optimal implementation strategy of the communication primitive in each test environment can be determined using this embodiment. Thus, the source code of the communication library can be updated based on the optimal implementation strategy of each communication primitive in each test environment to obtain the updated source code of the communication library.
[0058] In the aforementioned communication library optimization method, for each communication primitive in the communication library, a set of implementation strategies corresponding to that primitive is determined. The implementation strategies in this set include communication protocols and algorithms. For each strategy, the implementation strategy is run in multiple test environments to obtain performance evaluation values. For each test environment, the optimal implementation strategy for the communication primitive in that environment is selected from the set based on the performance evaluation values. Using the optimal implementation strategy for each test environment, the communication library source code is updated to obtain updated source code. This updated source code is used to generate the communication library file. Since the communication library file is used in a real environment for the communication task corresponding to the primitive, selecting an implementation strategy that matches the real environment from the optimal implementation strategies of the primitive ensures the performance of the matched strategy and helps improve communication performance.
[0059] In the optimization of distributed communication libraries, the optimization methods that can be adopted usually include: (1) Automated tuning method, namely online tuning and efficient search method, which improves communication performance through optimization mechanism. For example, AutoCCL combines parameter decoupling, online tuning and efficient search algorithm to automatically find better algorithm and protocol combinations in different communication scenarios, thereby improving the communication efficiency in large-scale training process. This method realizes the dynamic optimization of communication strategy to a certain extent, so that the system can adjust the execution plan according to the task scale and data characteristics. However, it has the problem of additional runtime overhead, and there is still room for improvement in hardware universality and complex scenario adaptation. (2) Using the manual tuning function provided by the communication library itself. Taking NCCL as an example, its extended tuning module allows users to input configuration rules in advance, including communication primitive type, data size range, node scale / number of nodes and corresponding algorithm and protocol. When the actual running task matches these rules, the system will execute according to the scheme set by the user. This method can cover some special scenarios and improve performance, but it is highly dependent on the user, requires manual specification of a large number of parameters, the configuration process is complicated, and it is difficult to automatically adapt to different environments. These optimization methods often rely on specific platforms or hardware ecosystems. For example, some tools can only run on NVIDIA GPUs and are difficult to migrate to other GPUs or heterogeneous computing platforms. This is because the underlying implementation is bound to specific hardware characteristics and driver interfaces, lacking cross-platform versatility. Automated tuning methods require repeated collection of performance data and online searches during operation, incurring additional overhead and reducing overall training efficiency. Manual tuning methods require users to specify parameters such as the range of input data, number of nodes, operator type, and algorithm, which is complex and relies on human experience, making it difficult to adapt to large-scale distributed training environments. The communication library optimization method provided in this application can address the problems of communication libraries lacking adaptability, having limited performance improvement, and relying on manual configuration during algorithm and protocol selection.
[0060] In an exemplary embodiment, selecting the optimal implementation strategy for a communication primitive in a test environment from the set of implementation strategies based on performance evaluation values includes: selecting the best-performing implementation strategy from the set of implementation strategies based on performance evaluation values; and determining the optimal implementation strategy for the communication primitive in the test environment based on the best-performing implementation strategy.
[0061] The performance evaluation value includes runtime. The implementation strategy with the shortest runtime can be determined as the optimal implementation strategy in terms of performance.
[0062] For example, the best-performing implementation strategy can be used as the optimal implementation strategy for the communication primitive in the test environment.
[0063] In this embodiment, the optimal implementation strategy for communication primitives in the test environment is determined based on the best performance implementation strategy, which can guarantee the performance of the optimal implementation strategy.
[0064] In an exemplary embodiment, determining the optimal implementation strategy for a communication primitive in a test environment based on the best-performing implementation strategy includes: determining a reference implementation strategy for the communication primitive in the test environment and obtaining the performance evaluation value of the reference implementation strategy in the test environment, wherein the reference implementation strategy is the implementation strategy selected for the communication primitive in the test environment using the default selection method of the communication library; determining the performance improvement of the best-performing implementation strategy based on the performance evaluation value of the best-performing implementation strategy in the test environment and the performance evaluation value of the reference implementation strategy in the test environment; and, if the performance improvement is greater than the improvement threshold, using the best-performing implementation strategy as the optimal implementation strategy for the communication primitive in the test environment.
[0065] The communication library can contain a cost model, which is used to predict the performance of different algorithms and protocols, helping to select a suitable communication scheme. The default selection method can be to use the cost model to select the communication scheme (i.e., the combination of communication protocol and communication algorithm). When the performance improvement exceeds a threshold, the best-performing implementation strategy is chosen as the optimal implementation strategy for the communication primitive in the test environment. Therefore, the optimal implementation strategy is superior to the control strategy selected by the default selection method in the communication library. Thus, by optimizing the source code using the optimal implementation strategy, the communication library files can select the more performant implementation strategy when choosing implementation strategies for communication primitives.
[0066] For example, the difference between the performance evaluation value of the optimal implementation strategy in the test environment and the performance evaluation value of the control implementation strategy in the test environment can be calculated, and the ratio of this difference to the performance evaluation value of the control implementation strategy in the test environment can be used as the performance improvement.
[0067] For example, the lift threshold can be set according to actual needs. If the performance improvement is too small, it is usually due to system jitter rather than the quality of the algorithm itself. Therefore, when the performance improvement is less than or equal to the lift threshold, the comparison implementation strategy can be used as the optimal implementation strategy for the communication primitive in the test environment.
[0068] In this embodiment, since the performance improvement is too small, it is usually due to system jitter rather than the quality of the algorithm itself. Therefore, when the performance improvement is greater than the improvement threshold, the best performance implementation strategy is taken as the optimal implementation strategy of the communication primitive in the test environment. This can effectively filter out interference, avoid the subjectivity brought about by human experience, and make the screening results objective, reliable and repeatable.
[0069] In one exemplary embodiment, each test environment includes multiple test conditions, including data scale and node scale. The optimal implementation strategy of the communication primitives in each test environment is used to update the source code of the communication library to obtain the updated source code of the communication library. This includes: generating a data scale range based on the data scale in the test environment; generating a strategy optimization record for the communication primitives in the test environment based on the data scale range, the communication primitives, the node scale of the test environment, and the optimal implementation strategy; and updating the source code of the communication library based on the strategy optimization record for the communication primitives in the test environment to obtain the updated source code of the communication library.
[0070] Here, node size refers to the test condition other than data size among the multiple test conditions. For example, node size can be the node scale. The strategy optimization record includes the data size range, communication primitives, node size of the test environment, and the optimal implementation strategy.
[0071] For example, the data size can be reduced to obtain a lower limit, and the data size can be increased to obtain an upper limit. The range formed by the upper and lower limits is taken as the data size range. For example, a preset percentage can be used to reduce and increase the size. For example, the lower limit of the data size = (1 - preset percentage) × data size, and the upper limit of the data size = (1 + preset percentage) × data size. If size represents the data size, and the preset percentage is 1 / 4, then the lower limit of the data size = (1 - 1 / 4) × size, and the upper limit of the data size = (1 + 1 / 4) × size. Therefore, the data size range is (1 - 1 / 4) × size ~ (1 + 1 / 4) × size.
[0072] For example, based on the policy optimization record of the communication primitive in the test environment, the source code of the communication library is updated to obtain the updated source code of the communication library, including: writing the policy optimization record into the source code of the communication library.
[0073] In this embodiment, since the strategy optimization record contains the data scale range, communication primitives, node scale of the test environment, and optimal implementation strategy, the implementation strategy can be matched based on the strategy optimization record, thus providing conditions for matching the implementation strategy.
[0074] In an exemplary embodiment, the data size of some test environments in multiple test environments increases according to a preset rule and the node size is consistent. The data size range is generated based on the data size in the test environments, including: if the optimal implementation strategy of the communication primitive is consistent in at least two test environments and at least two test environments meet the merging conditions, then the data size range is generated based on the data size in at least two test environments; wherein, the merging conditions include: the data size increases according to a preset rule and the node size is consistent.
[0075] The multiple test environments are divided into multiple test environment groups. Each test environment group contains at least two test environments. The data size of the test environments within the same test environment group increases according to a preset rule, and the node size is consistent. For example, the node size is the same within the same test environment group. The preset rule could be an exponential rule, where the data size of some test environments increases exponentially.
[0076] For example, since the optimal implementation strategy of the communication primitive is consistent in at least two test environments, and at least two test environments meet the merging condition, it means that the optimal implementation strategy remains consistent as the data size increases. Therefore, by generating a data size range based on the data size in at least two test environments, a strategy optimization record can be generated for at least two test environments.
[0077] In this embodiment, the data size of some test environments in multiple test environments increases according to a preset rule and the node size is consistent. Therefore, the optimal implementation strategy can be determined under different data size scenarios when the node size is consistent. Since the optimal implementation strategy of the communication primitive is consistent in at least two test environments and at least two test environments meet the merging condition, it means that the optimal implementation strategy remains consistent as the data size increases. Therefore, by generating a data size range based on the data size in at least two test environments, a strategy optimization record can be generated for at least two test environments. Compared with generating a strategy optimization record for each test environment, the number of strategy optimization records is reduced, which helps to speed up the efficiency of matching implementation strategies.
[0078] In one exemplary embodiment, generating a data size range based on data sizes in at least two test environments includes: determining a maximum data size and a minimum data size from the data sizes in at least two test environments; determining an upper limit for the data size based on the maximum data size and a lower limit for the data size based on the minimum data size, wherein the upper limit for the data size is greater than the maximum data size and the lower limit for the data size is less than the minimum data size; and generating a data size range based on the upper limit for the data size and the lower limit for the data size.
[0079] For example, the minimum data size can be reduced to obtain the lower limit of the data size, and the maximum data size can be increased to obtain the upper limit of the data size. The range formed by the upper and lower limits of the data size is used as the data size range. For example, a preset percentage can be used to reduce and increase the size. For example, the lower limit of the data size = (1 - preset percentage) × minimum data size, and the upper limit of the data size = (1 + preset percentage) × maximum data size.
[0080] For example, if the data size of test environment 1 to test environment 5 increases according to a preset rule and the node size is the same, and the optimal implementation strategy of the communication primitive is the same in test environment 1 to test environment 5, if the data size of test environment 1 is the smallest and the data size of test environment 5 is the largest, then the data size range can be generated based on the data size of test environment 1 and the data size of test environment 5.
[0081] In this embodiment, since the data size fluctuates, the optimal implementation strategy usually remains unchanged. Therefore, by generating a data size range based on the upper and lower limits of the data size, a larger range of data size can be obtained, making it easier to match the implementation strategy.
[0082] In an exemplary embodiment, the method further includes: deploying a communication library file to a real environment, such that when a communication task corresponding to a communication primitive is triggered in the real environment, an implementation strategy matching the real environment is searched from the optimal implementation strategies of the communication primitive based on the communication library file; if a matching strategy is found, the found optimal implementation strategy is executed; if the search fails, an implementation strategy matching the real environment is selected from the implementation strategies of the communication primitive using the default selection method in the communication library, and the selected implementation strategy is executed.
[0083] For example, a real-world environment may include multiple computing nodes for distributed training. In these real-world computing nodes, when a communication task corresponding to a communication primitive is triggered, the node size and data size corresponding to that communication task are determined. The node size is the number of computing nodes involved in the communication task, and the data size is the total amount of data to be transmitted. Then, based on the node size and data size of the communication task, the optimal implementation strategy for the communication primitive under that node size and data size is searched in the communication library file. If a match is found, the optimal implementation strategy is executed to complete the communication task. If the search fails (i.e., no match is found), a matching implementation strategy is determined using the default selection method in the communication library and executed to complete the communication task.
[0084] In this embodiment, the implementation strategy is matched first from the optimal implementation strategies of the communication primitives, and then the implementation strategy is matched using the default selection method in the communication library. This can ensure the performance of the matched implementation strategy as much as possible.
[0085] In an exemplary embodiment, as shown in Figure 3, a communication library optimization method is provided. The overall idea is as follows: before formal training, a communication testing tool is used to systematically test all possible combinations of algorithms and protocols to obtain detailed performance data; then, through pruning and filtering mechanisms, the optimal strategy combination under specific conditions is identified; finally, these results are written into the weight table of the communication library source code and recompiled, so that the optimized strategy can automatically take effect at runtime. The entire process avoids the additional overhead of runtime tuning and does not require users to manually input complex configurations, exhibiting a high degree of automation and universality. The method includes:
[0086] 1. Performance benchmark testing.
[0087] Specifically, before optimization begins, the performance of the communication library under the default weight configuration can be clearly defined. For example, the performance testing tools included with the communication library (such as rccl-tests) can be run to test typical collection communication operations such as AllReduce, AllGather, Broadcast, ReduceScatter, and Reduce. During the testing process, different data sizes (from B to GB) and different node sizes (such as 8 cards on a single machine, 16 cards on dual machines, and 32 cards on four machines) should be covered. The communication latency, bandwidth utilization, and execution time (runtime) under each combination should be systematically recorded, and the combination of communication libraries selected (i.e., the implementation strategy) should be clearly defined. The combination of communication libraries selected in the performance benchmark test should be used as the "control group".
[0088] 2. Global traversal of algorithms and protocols.
[0089] Specifically, communication libraries typically incorporate multiple algorithms and protocols, and the performance of different combinations varies significantly under different data sizes and topologies. After obtaining a "control group," a double-loop structure is used to obtain the optimal configuration (i.e., the optimal implementation strategy). For example, the outer loop iterates through all communication algorithms, and the inner loop iterates through all communication protocols, testing each combination and saving the results.
[0090] The traversal not only covers different combinations of algorithms and protocols, but also different node sizes. Through implementation, multi-node tests with 32, 24, 16, and 8 cards have been achieved, ensuring the applicability and stability of the optimization results across different scales. This mechanism provides a complete performance database, encompassing performance under different communication primitives, data sizes, node sizes, and combinations of algorithms and protocols.
[0091] 3. Performance comparison and optimal selection.
[0092] Specifically, the combination of communication libraries selected in the performance benchmark test was used as the "control group." By comparing with the "control group," it is possible to intuitively determine whether other algorithm and protocol combinations can bring performance improvements. It should be noted that the collection of the "control group" was a complete and systematic process, which not only reflects the overall level of the default configuration of the communication library, but also provides a reliable reference standard for subsequent screening.
[0093] In large-scale distributed training, communication performance is influenced by a combination of factors, including node size, communication primitives, data size, and various algorithms and protocols. The differences in communication performance across different node sizes are significant. For example, the adaptability and efficiency of algorithms often differ markedly in environments with 8, 16, 24, and 32 nodes. Therefore, under fixed node size, communication primitives, and data size, the performance of different algorithms and protocols can be compared one by one, using runtime as the core metric to select the optimal combination. This approach ensures that the best-performing configuration is found under the same conditions, providing a complete and systematic basis for subsequent analysis.
[0094] In performance comparisons, runtime can be used as the core metric, and a performance improvement threshold can be introduced to ensure the significance and stability of the results. Experiments show that when the performance difference is less than 3.5%, it is often due to system jitter rather than the quality of the algorithm itself. Therefore, 3.5% is set as the judgment threshold, and results below this threshold are not accepted. This approach effectively filters out interference, avoids subjectivity arising from reliance on human experience, and ensures the objectivity and repeatability of the selection results. In this way, the performance of each communication primitive and data scale under the corresponding node scale can yield accurate and reliable comparison conclusions.
[0095] The filtered results are saved in a structured file, which not only contains numerical values of performance improvement but also explicitly records the node size, communication primitives, data size, and the corresponding optimal algorithm and protocol combination. This storage method allows subsequent programs to automatically read and utilize this information without manual intervention, ensuring efficiency and accuracy. Ultimately, a comprehensive set of optimal configurations is formed under different combinations of node and data sizes. This set provides a solid basis for subsequent automated filtering and communication optimization, and also possesses good generalization and universality, enabling distributed training to quickly achieve stable and efficient communication performance support in various environments.
[0096] 4. Source code modification.
[0097] Specifically, after the filtering is completed, the optimal result can be automatically written into the algorithm and protocol selection module of the communication library source code. For example, the cost model calculation result in the source code can be adjusted according to different data scales, communication primitives, and node scales, so that the optimized combination has a higher priority at runtime and is automatically selected by the system for execution.
[0098] 5. Recompile.
[0099] Specifically, after the code is written, the communication library source code can be recompiled to generate a new library file. The optimized version of the communication library can directly use the optimized configuration at runtime. Users do not need to modify any calling interfaces or scripts and can obtain better communication performance while maintaining their original usage habits.
[0100] The communication library optimization method provided in this application offers an automated optimization approach for distributed communication libraries, addressing the shortcomings of existing libraries such as lack of adaptability in algorithm and protocol selection, limited performance improvement, and reliance on manual configuration. A complete closed-loop optimization process is constructed through four stages: performance benchmark collection, global traversal and pruning of algorithms and protocols, performance comparison and optimal selection, and weight writing and recompilation. This process not only automates the analysis of different communication primitives and data scales but also combines the results from different node scales (32 cards, 24 cards, 16 cards, 8 cards), thereby achieving stable performance optimization results in various hardware environments and task scenarios.
[0101] The communication library optimization method provided in this application forms a closed-loop process of "benchmark acquisition—global traversal—performance filtering—source code writing—recompilation," avoiding runtime tuning overhead and achieving long-term stable optimization. This closed-loop process not only avoids the additional overhead of runtime tuning but also does not rely on manual input of complex parameters, maintaining stable performance improvements in multi-node, multi-scale, and multi-hardware environments. During large model training, it can significantly improve bandwidth utilization, reduce communication time, and improve overall training efficiency.
[0102] The communication library optimization method provided in this application can effectively improve communication performance, enhance bandwidth utilization under various communication primitives and different data scales, and demonstrate optimization potential in single-machine, multi-machine, and different scale scenarios, ensuring performance improvements across all scales, rather than being effective only at a single scale. By directly writing the optimal configuration (i.e., the optimal implementation strategy) into the source code, users do not need to perform runtime tuning or additional parameter settings, reducing system overhead. Users can directly obtain performance improvements within the existing process without modifying training scripts or interfaces; it effectively alleviates communication bottlenecks, improves throughput, shortens iteration time, and accelerates model convergence; it can be applied to different computing platforms and multi-node environments, enhancing the competitiveness of domestic communication libraries in ultra-large-scale training. As shown in Figure 4, a time performance comparison chart of the AllReduce communication primitive in a single-machine 8-card scenario is provided. It can be seen that compared to the original communication library, the optimized communication library significantly shortens the execution time (running time) as the data scale gradually increases. Here, ms (Millisecond) refers to milliseconds, and MB (Megabyte) refers to megabytes. Figure 5 shows a comparison of the bandwidth performance of the Reduce communication primitive in a single-machine 8-card scenario, in GB / s (Gigabytes per second). Figure 6 shows a comparison of the bandwidth performance of the AllReduce communication primitive in a dual-machine 16-card scenario. Figure 7 shows a comparison of the bandwidth performance of the Broadcast communication primitive in a dual-machine 16-card scenario. Figure 8 shows a comparison of the bandwidth performance of the Reduce communication primitive in a dual-machine 16-card scenario.
[0103] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages in other steps. It is understood that the steps in different embodiments can be freely combined as needed, and all non-contradictory solutions formed by such combinations are within the scope of protection of this application.
[0104] Based on the same inventive concept, this application also provides a communication library optimization apparatus for implementing the communication library optimization method described above. The solution provided by this apparatus is similar to the implementation described in the above method; therefore, the specific limitations in one or more communication library optimization apparatus embodiments provided below can be found in the limitations of the communication library optimization method described above, and will not be repeated here.
[0105] In an exemplary embodiment, as shown in FIG9, a communication library optimization device is provided, including: a strategy determination module 902, an evaluation value determination module 904, a strategy selection module 906, and a source code update module 908, wherein:
[0106] The strategy determination module 902 is used to generate a set of implementation strategies corresponding to the communication primitives in the communication library based on multiple communication protocols and multiple communication algorithms. Each implementation strategy in the set of implementation strategies contains a communication protocol and a communication algorithm.
[0107] The evaluation value determination module 904 is used to run the implementation strategy in multiple test environments for each implementation strategy in the implementation strategy set, and obtain the performance evaluation value of the implementation strategy in multiple test environments.
[0108] The strategy selection module 906 is used to select the optimal implementation strategy of the communication primitive in the test environment from the implementation strategy set based on the performance evaluation value for each test environment in multiple test environments.
[0109] The source code update module 908 is used to update the source code of the communication library by utilizing the optimal implementation strategy of the communication primitives in each test environment. The updated source code is used to generate the communication library file. The communication library file is used to select the implementation strategy that matches the real environment from the optimal implementation strategies of the communication primitives for the communication tasks corresponding to the communication primitives.
[0110] In some embodiments, the strategy selection module 906 is further configured to select the best-performing implementation strategy from the set of implementation strategies based on the performance evaluation value; and determine the optimal implementation strategy for the communication primitive in the test environment based on the best-performing implementation strategy.
[0111] In some embodiments, the strategy selection module 906 is further configured to determine a reference implementation strategy for the communication primitive in the test environment, and obtain the performance evaluation value of the reference implementation strategy in the test environment. The reference implementation strategy is the implementation strategy selected for the communication primitive in the test environment using the default selection method of the communication library. Based on the performance evaluation value of the optimal implementation strategy in the test environment and the performance evaluation value of the reference implementation strategy in the test environment, the performance improvement of the optimal implementation strategy is determined. If the performance improvement is greater than the improvement threshold, the optimal implementation strategy is taken as the optimal implementation strategy for the communication primitive in the test environment.
[0112] In some embodiments, each test environment includes multiple test conditions, including data scale and node scale. The source code update module 908 is further configured to generate a data scale range based on the data scale in the test environment; generate a strategy optimization record for the communication primitive in the test environment based on the data scale range, the communication primitive, the node scale of the test environment, and the optimal implementation strategy; and update the source code of the communication library based on the strategy optimization record of the communication primitive in the test environment to obtain the updated source code of the communication library.
[0113] In some embodiments, the data size of some test environments in multiple test environments increases according to a preset rule and the node size is consistent. The source code update module 908 is further used to generate a data size range based on the data size in at least two test environments if the optimal implementation strategy of the communication primitive is consistent in at least two test environments and at least two test environments meet the merging conditions. The merging conditions include: the data size increases according to a preset rule and the node size is consistent.
[0114] In some embodiments, the source code update module 908 is further configured to determine the maximum data size and the minimum data size from the data sizes of at least two test environments; determine the upper limit of the data size based on the maximum data size and the lower limit of the data size based on the minimum data size, wherein the upper limit of the data size is greater than the maximum data size and the lower limit of the data size is less than the minimum data size; and generate a data size range based on the upper limit of the data size and the lower limit of the data size.
[0115] In some embodiments, the apparatus is further configured to: deploy a communication library file to a real environment, such that when a communication task corresponding to a communication primitive is triggered in the real environment, an implementation strategy matching the real environment is searched from the optimal implementation strategies of the communication primitive based on the communication library file; if a matching strategy is found, the found optimal implementation strategy is executed; if the search fails, an implementation strategy matching the real environment is selected from the implementation strategies of the communication primitive using the default selection method in the communication library, and the selected implementation strategy is executed.
[0116] Each module in the aforementioned communication library optimization device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the memory of a computer device as software, so that the processor can call and execute the operations corresponding to each module.
[0117] In an exemplary embodiment, a computer device is provided, which may be a server, and its internal structure diagram is shown in Figure 10. The computer device includes a processor, memory, input / output interfaces (I / O), and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is connected to the system bus via the I / O interfaces. The processor of the computer device provides computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores an operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The database of the computer device stores at least some of the data involved in the communication library optimization method. The I / O interfaces of the computer device are used for exchanging information between the processor and external devices. The communication interface of the computer device is used for communicating with external terminals via a network connection. When the computer program is executed by the processor, it implements a communication library optimization method.
[0118] In an exemplary embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram is shown in Figure 11. The computer device includes a processor, memory, input / output interface, communication interface, display unit, and input device. The processor, memory, and input / output interface are connected via a system bus, and the communication interface, display unit, and input device are also connected to the system bus via the input / output interface. The processor of the computer device provides computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores an operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The input / output interface of the computer device is used for exchanging information between the processor and external devices. The communication interface of the computer device is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, mobile cellular networks, Near Field Communication (NFC), or other technologies. When the computer program is executed by the processor, it implements a communication library optimization method. The display unit of the computer device is used to form a visually visible image and may be a display screen, a projection device, or a virtual reality imaging device. The display screen can be an LCD screen or an e-ink screen. The input device of the computer device can be a touch layer covering the display screen, or buttons, trackballs, or touchpads set on the casing of the computer device, or external keyboards, touchpads, or mice, etc.
[0119] Those skilled in the art will understand that the structures shown in Figures 10 and 11 are merely block diagrams of some structures related to the present application and do not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than shown in the figures, or combine certain components, or have different component arrangements.
[0120] In one exemplary embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above-described method embodiments.
[0121] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the steps in the above method embodiments.
[0122] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps in the above method embodiments.
[0123] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of the relevant data must comply with relevant regulations.
[0124] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, artificial intelligence (AI) processors, etc., and are not limited to these.
[0125] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0126] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A method for optimizing a communication library, characterized in that, The method includes: for communication primitives in a communication library, generating an implementation strategy set corresponding to the communication primitives based on multiple communication protocols and multiple communication algorithms, wherein each implementation strategy in the implementation strategy set includes a communication protocol and a communication algorithm; for each implementation strategy in the implementation strategy set, running the implementation strategy in multiple test environments to obtain a performance evaluation value of the implementation strategy in the multiple test environments; for each of the multiple test environments, selecting the optimal implementation strategy of the communication primitive in the test environment from the implementation strategy set based on the performance evaluation value; using the optimal implementation strategy of the communication primitive in each of the test environments to update the source code of the communication library to obtain updated source code of the communication library, wherein the updated source code is used to generate a communication library file, and the communication library file is used to select an implementation strategy matching the real environment from the optimal implementation strategies of the communication primitive for the communication task corresponding to the communication primitive in a real environment.
2. The method according to claim 1, characterized in that, The step of selecting the optimal implementation strategy for the communication primitive in the test environment from the set of implementation strategies based on the performance evaluation value includes: selecting the implementation strategy with the best performance from the set of implementation strategies based on the performance evaluation value; and determining the optimal implementation strategy for the communication primitive in the test environment based on the implementation strategy with the best performance.
3. The method according to claim 2, characterized in that, The step of determining the optimal implementation strategy for the communication primitive in the test environment based on the optimal performance implementation strategy includes: determining a reference implementation strategy for the communication primitive in the test environment, and obtaining the performance evaluation value of the reference implementation strategy in the test environment, wherein the reference implementation strategy is the implementation strategy selected for the communication primitive in the test environment using the default selection method of the communication library; determining the performance improvement of the optimal implementation strategy based on the performance evaluation value of the optimal implementation strategy in the test environment and the performance evaluation value of the reference implementation strategy in the test environment; and, if the performance improvement is greater than an improvement threshold, taking the optimal implementation strategy as the optimal implementation strategy for the communication primitive in the test environment.
4. The method according to any one of claims 1 to 3, characterized in that, Each test environment includes multiple test conditions, including data scale and node scale. The step of updating the communication library's source code using the optimal implementation strategy of the communication primitive in each test environment to obtain the updated source code of the communication library includes: generating a data scale range based on the data scale in the test environment; generating a strategy optimization record for the communication primitive in the test environment based on the data scale range, the communication primitive, the node scale of the test environment, and the optimal implementation strategy; and updating the communication library's source code based on the strategy optimization record for the communication primitive in the test environment to obtain the updated source code of the communication library.
5. The method according to claim 4, characterized in that, The data size of some test environments in the multiple test environments increases according to a preset rule and the node size is consistent. The step of generating a data size range based on the data size in the test environments includes: if the optimal implementation strategy of the communication primitive is consistent in at least two test environments and the at least two test environments meet the merging condition, then a data size range is generated based on the data size in the at least two test environments; wherein, the merging condition includes: the data size increases according to the preset rule and the node size is consistent.
6. The method according to claim 5, characterized in that, The step of generating a data size range based on the data sizes in the at least two test environments includes: determining a maximum data size and a minimum data size from the data sizes in the at least two test environments; determining an upper limit for the data size based on the maximum data size and a lower limit for the data size based on the minimum data size, wherein the upper limit for the data size is greater than the maximum data size and the lower limit for the data size is less than the minimum data size; and generating a data size range based on the upper limit for the data size and the lower limit for the data size.
7. The method according to any one of claims 1 to 3, characterized in that, The method further includes: deploying the communication library file to a real environment, such that when a communication task corresponding to the communication primitive is triggered in the real environment, an implementation strategy matching the real environment is searched from the optimal implementation strategies of the communication primitive based on the communication library file; if a matching strategy is found, the optimal implementation strategy is executed; if the search fails, an implementation strategy matching the real environment is selected from the implementation strategies of the communication primitive using the default selection method in the communication library, and the selected implementation strategy is executed.
8. A communication library optimization device, characterized in that, The apparatus includes: a strategy determination module, configured to generate an implementation strategy set corresponding to a communication primitive in a communication library based on multiple communication protocols and multiple communication algorithms, wherein each implementation strategy in the implementation strategy set includes a communication protocol and a communication algorithm; an evaluation value determination module, configured to run each implementation strategy in the implementation strategy set under multiple test environments to obtain a performance evaluation value of the implementation strategy under the multiple test environments; a strategy selection module, configured to select the optimal implementation strategy of the communication primitive in the test environment from the implementation strategy set for each test environment based on the performance evaluation value; and a source code update module, configured to update the source code of the communication library using the optimal implementation strategy of the communication primitive in each test environment to obtain updated source code of the communication library, wherein the updated source code is used to generate a communication library file, and the communication library file is used to select an implementation strategy matching the real environment from the optimal implementation strategies of the communication primitive for the communication task corresponding to the communication primitive in a real environment.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 7.
11. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 7.