Memory allocation method and device, medium and equipment
By obtaining and iteratively adjusting the memory resources of the computing unit in real time in the terminal device, and using the running loss function and optimization algorithm, the computational efficiency problem caused by uneven memory allocation is solved, and the optimal allocation of memory resources and the improvement of resource utilization is achieved.
Patent Information
- Application Number
- CN202510558251.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-28
- Publication Date
- 2025-08-12
AI Technical Summary
In the environment where multiple computing units work together, existing terminal devices cannot achieve optimal allocation of memory resources, resulting in serious impact on the overall computing efficiency.
By obtaining the current memory of multiple computing units in real time, substituting the preset running loss function, and using the optimization algorithm to iterate until the iteration termination condition is met, the optimal memory allocation scheme is determined.
The optimal allocation of memory resources among each computing unit is realized, memory fragmentation and resource waste are reduced, and overall computing efficiency of terminal devices is improved.
Smart Images

Figure CN120469804A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a memory allocation method, device, medium and equipment. Background Art
[0002] Existing terminal devices usually integrate multiple different types of computing units, such as a central processing unit (CPU), a graphics processing unit (GPU), a neural network processing unit (NPU), etc. In a computing environment where multiple computing units work together, the current mainstream technical solutions often rely on static configuration or manual adjustment in terms of memory resource allocation. However, the above conventional memory resource configuration methods are difficult to accurately adapt to complex and changeable real-time computing needs. This will make it impossible to achieve optimal allocation of memory resources among the various computing units, which will seriously affect the overall computing efficiency of the terminal device. Summary of the Invention
[0003] Based on this, it is necessary to provide memory allocation methods, devices, media and equipment to solve the problem that memory resources cannot be optimally allocated among various computing units, thereby seriously affecting the overall computing efficiency of the terminal device.
[0004] In a first aspect, an embodiment of the present application provides a memory allocation method, the method comprising:
[0005] Get the current memory used by multiple computing units;
[0006] Substituting the currently used memory into a preset running loss function, and iteratively adjusting the currently used memory through a preset optimization algorithm;
[0007] When the running loss function satisfies a preset iteration termination condition, the currently used memory of the running loss function is obtained as a first allocated memory, and memory is allocated to the multiple computing units based on the first allocated memory.
[0008] In some embodiments of the present application, the method further includes:
[0009] After each iterative adjustment of the currently used memory, respectively calculating access conflict probabilities, bandwidth consumptions, and imbalances of the plurality of computing units according to the currently used memory;
[0010] Substituting the access conflict probability, the bandwidth consumption, and the imbalance into the operation loss function to calculate the operation losses of the plurality of computing units;
[0011] When the running loss reaches a minimum value, or when the running loss converges, it is determined that the running loss function meets a preset iteration termination condition.
[0012] In some embodiments of the present application, when calculating the access conflict probabilities of the multiple computing units, respectively calculating the access conflict probabilities, bandwidth consumption, and imbalance of the multiple computing units based on the currently used memory includes:
[0013] Obtaining a target memory of a target computing unit in the currently used memory, and obtaining overlapping memory between the target computing unit and non-target computing units; wherein the target computing unit is any one of the plurality of computing units, and the non-target computing units are computing units other than the target computing unit in the plurality of computing units;
[0014] The access conflict probability of the target computing unit is calculated based on the overlapping memory and the target memory to obtain the access conflict probability of the multiple computing units; wherein the access conflict probability is positively correlated with the overlapping memory and negatively correlated with the target memory.
[0015] In some embodiments of the present application, when calculating the bandwidth consumption of the multiple computing units, calculating the access conflict probability, bandwidth consumption, and imbalance of the multiple computing units respectively according to the currently used memory includes:
[0016] Obtaining a target memory of a target computing unit in the currently used memory, and obtaining a target memory access rate of the target computing unit; wherein the target computing unit is any one of the multiple computing units;
[0017] The bandwidth consumption of the target computing unit is calculated according to the target memory and the target memory access rate to obtain the bandwidth consumption of the multiple computing units; wherein the bandwidth consumption is positively correlated with the target memory and the target memory access rate.
[0018] In some embodiments of the present application, when calculating the imbalance of the multiple computing units, calculating the access conflict probability, bandwidth consumption, and imbalance of the multiple computing units respectively according to the currently used memory includes:
[0019] Obtaining a target memory of a target computing unit in the currently used memory; wherein the target computing unit is any one of the multiple computing units;
[0020] A normalization calculation is performed on the target memory to obtain a normalized value, and the normalized value is used as the imbalance degree of the target computing unit to obtain the imbalance degrees of the multiple computing units.
[0021] In some embodiments of the present application, the method further includes:
[0022] Obtaining historical allocated memory of the plurality of computing units;
[0023] predicting second allocated memory for the plurality of computing units based on the historical allocated memory;
[0024] The allocating memory to the plurality of computing units based on the first allocated memory includes:
[0025] The first allocated memory and the second allocated memory are weightedly calculated to obtain a third allocated memory, and memory allocation is performed on the plurality of computing units based on the third allocated memory.
[0026] In some embodiments of the present application, the method further includes:
[0027] Get the target task;
[0028] Among the multiple computing units, at least one computing unit is iteratively determined through a preset optimization algorithm so that the execution cost of the at least one computing unit in executing the target task is lowest, and the target task is executed based on the determined at least one computing unit.
[0029] In a second aspect, an embodiment of the present application further provides a memory allocation device, the memory allocation device comprising:
[0030] A memory acquisition module is used to obtain the currently used memory of multiple computing units;
[0031] an iterative adjustment module, configured to substitute the currently used memory into a preset running loss function and iteratively adjust the currently used memory using a preset optimization algorithm;
[0032] A memory allocation module is used to obtain the currently used memory of the running loss function as the first allocated memory when the running loss function meets the preset iteration termination condition, and to allocate memory to the multiple computing units based on the first allocated memory.
[0033] In a third aspect, an embodiment of the present application further provides a terminal device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, the steps in the above-mentioned memory allocation method are implemented.
[0034] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps in the above-mentioned memory allocation method are implemented.
[0035] In a fifth aspect, embodiments of the present application further provide a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the methods provided in the various optional implementations described in the embodiments of the present application.
[0036] The present invention provides a memory allocation method, apparatus, medium, and device. These methods obtain the currently used memory of multiple computing units in real time, substitute it into a preset running loss function, and perform iterative adjustments in conjunction with an optimization algorithm. Ultimately, when an iterative termination condition is met, the currently used memory is determined to be the first allocated memory, and memory allocation is performed based on this first allocated memory. The core of this solution is to iteratively adjust the currently used memory through an optimization algorithm until the running loss function meets the preset iterative termination condition, ensuring that memory resources are optimally allocated across the computing units. This effectively reduces memory fragmentation and resource waste, and improves the overall computing efficiency of the terminal device. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0038] in:
[0039] Figure 1 A flowchart of the memory allocation method provided in the first embodiment of the present application;
[0040] Figure 2 A flowchart for determining whether the iteration termination condition is met;
[0041] Figure 3 A flowchart of a memory allocation method provided in the second embodiment of the present application;
[0042] Figure 4 A flowchart for assigning target tasks;
[0043] Figure 5 It is a structural diagram of a memory allocation device;
[0044] Figure 6 This is the structural block diagram of the terminal equipment. DETAILED DESCRIPTION
[0045] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without making any creative efforts shall fall within the scope of protection of the present invention.
[0046] The terms "first," "second," and the like in the specification and claims of this application and the accompanying drawings are used to distinguish between different objects, not to describe a particular order. Furthermore, the terms "including," "having," and any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or apparatus comprising a series of steps or elements is not limited to the listed steps or elements but may optionally include steps or elements not listed, or may optionally include other steps or elements inherent to the process, method, product, or apparatus.
[0047] References herein to "embodiments" mean that a particular feature, structure, or characteristic described in connection with the embodiments may be included in at least one embodiment of the present application. The appearance of this phrase in various places in the specification does not necessarily refer to the same embodiment, nor does it constitute an independent or alternative embodiment that is mutually exclusive of other embodiments. It is understood, both explicitly and implicitly, by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0048] See also Figure 1 , Figure 1 This is a flowchart of the memory allocation method provided in the first embodiment of the present application. Although the logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than shown in the accompanying drawings. Specifically, the specific process of the memory allocation method provided in the first embodiment is as follows:
[0049] S101, obtaining currently used memory of multiple computing units.
[0050] Computing units refer to the different types of processors integrated into terminal devices, including but not limited to central processing units (CPUs), graphics processing units (GPUs), and neural network processing units (NPUs). Current memory usage refers to the memory resources actually occupied by these multiple computing units at a given moment.
[0051] For example, a terminal device may have multiple computing units including CPU, GPU, and NPU. We can obtain the current memory usage of the CPU by calling the system API, obtain the current memory usage of the GPU through the GPU driver interface, and finally obtain the current memory usage of the NPU using the hardware monitoring function of the NPU.
[0052] For another example, in a cloud computing environment, memory allocation data of each computing unit of a virtual machine is obtained through a virtual machine monitor.
[0053] S102: Substitute the currently used memory into a preset running loss function, and iteratively adjust the currently used memory through a preset optimization algorithm.
[0054] The "running loss function" is a mathematical function used to quantify the running loss of a terminal device under the current memory usage. Running loss is an indicator used to evaluate the degree of terminal performance loss. A greater running loss indicates worse performance under the current memory usage. Because the current memory usage directly affects the running loss of the terminal device, this step iteratively adjusts the current memory usage through a preset optimization algorithm, gradually optimizing performance loss and improving the overall computing efficiency of the terminal device.
[0055] For example, the preset optimization algorithm here can be the simplex method, which is a classic algorithm for solving linear programming problems. The core idea is to start from a vertex of the feasible domain and move along the edge of the feasible domain to the adjacent vertex. Each movement ensures that the objective function value is improved until the optimal solution is found or the problem is proved to be unbounded or unsolvable.
[0056] For example, the preset optimization algorithm here could be the interior point method, a modern algorithm for solving linear programming problems. Its basic idea is to start from an initial point within the feasible region, construct a barrier function, and iterate within the feasible region to gradually approach the optimal solution. Unlike the simplex method, the interior point method does not search along the boundary, but instead searches directly within the feasible region for the optimal solution.
[0057] S103: When the running loss function satisfies a preset iteration termination condition, the currently used memory of the running loss function is obtained as a first allocated memory, and memory is allocated to a plurality of computing units based on the first allocated memory.
[0058] The "iteration termination condition" refers to a pre-set condition used to determine whether to stop the iteration during the iteration process. This can be when the number of iterations equals a pre-set iteration threshold, when the running loss output by the running loss function reaches a minimum value, or when the running loss output by the running loss function converges. Memory allocation here refers to allocating the future memory usage share to each computing unit based on the first allocated memory.
[0059] It can be understood that as the running loss function meets the preset iteration termination condition, the currently used memory is adjusted to the optimal level. At this time, using it as the first allocated memory and performing memory allocation can maximize the optimization of performance loss and thus maximize the overall computing efficiency of the terminal device.
[0060] The above-mentioned memory allocation method obtains the current memory usage of multiple computing units in real time, substitutes it into a preset running loss function, and performs iterative adjustments in combination with an optimization algorithm. Ultimately, when the iterative termination condition is met, the current memory usage is determined to be the first allocated memory, and memory allocation is performed based on this first allocated memory. The core of this solution is to iteratively adjust the current memory usage through an optimization algorithm until the running loss function meets the preset iterative termination condition, ensuring that memory resources are optimally allocated among the computing units, thereby effectively reducing memory fragmentation and resource waste, and improving the overall computing efficiency of the terminal device.
[0061] like Figure 2 As shown, in some embodiments of the present application, the step of determining whether the above iteration termination condition is met includes:
[0062] S201 , after each iterative adjustment of the currently used memory, respectively calculating the access conflict probability, bandwidth consumption and imbalance of multiple computing units according to the currently used memory.
[0063] The access conflict probability refers to the likelihood of access delays or conflicts when multiple computing units access the same memory area simultaneously. A higher access conflict probability indicates more severe memory access conflicts between devices, and therefore requires more optimization of memory allocation. Bandwidth consumption refers to the bandwidth occupied by a computing unit when reading or writing memory. Imbalance refers to the difference in memory usage between computing units. A higher imbalance indicates a more uneven distribution of memory resources across devices, and therefore requires more optimization.
[0064] In some embodiments of the present application, when calculating access conflict probabilities of multiple computing units, S201 specifically includes the following steps:
[0065] A1, obtains the target memory of the target computing unit in the currently used memory, and obtains the overlapping memory between the target computing unit and the non-target computing unit.
[0066] Among them, the target computing unit is any one of the multiple computing units, that is, these multiple computing units all use the same processing logic in the above-mentioned application embodiments, and the non-target computing unit is a computing unit other than the target computing unit in the multiple computing units. For example, the computing units include CPU, GPU and NPU. If the CPU is currently used as the target computing unit, then the corresponding GPU and NPU are used as non-target computing units; and if the GPU is currently used as the target computing unit, then the corresponding CPU and NPU are used as non-target computing units. The memory resources actually occupied by the target computing unit are the target memory. There may be a logical memory pool with common access between the target computing unit and the non-target computing unit, and the overlapping memory is the size of the overlapping access area of the target computing unit and the non-target computing unit in the logical memory pool.
[0067] A2, calculating the access conflict probability of the target computing unit according to the overlapping memory and the target memory to obtain the access conflict probability of multiple computing units.
[0068] Among them, the access conflict probability is positively correlated with the overlapping memory and negatively correlated with the target memory.
[0069] For example, the system has N computing units, and the target memory of the target computing unit i at time t is U i (t), then the access conflict probability of the target computing unit conflict(U i )=can be defined as:
[0070]
[0071] In the above formula, U i ∩U j Indicates the overlapping memory accessed between target compute unit i and non-target compute unit j (unit: MB).
[0072] It is understandable that by performing the above steps A1-A2 on all target computing units in the same manner, the access conflict probabilities of these multiple computing units can be obtained.
[0073] The above embodiment achieves a quantitative evaluation of memory access conflicts when multiple computing units are executed concurrently by calculating the access conflict probability using the current memory, thereby providing a basis for subsequent optimization of memory allocation and task scheduling.
[0074] In some embodiments of the present application, when calculating bandwidth consumption of multiple computing units, S201 specifically includes the following steps:
[0075] B1, obtain the target memory of the target computing unit in the currently used memory, and obtain the target memory access rate of the target computing unit.
[0076] The target computing unit is any one of the plurality of computing units, that is, the plurality of computing units all use the same processing logic in the above-mentioned application embodiments. The target memory access rate refers to the rate at which the target computing unit reads and writes the target memory per unit time.
[0077] B2, calculating the bandwidth consumption of the target computing unit according to the target memory and the target memory access rate to obtain the bandwidth consumption of multiple computing units.
[0078] Among them, bandwidth consumption is positively correlated with target memory and target memory access rate.
[0079] For example, the bandwidth consumption of the target computing unit bandwidth (U i ) can be defined as:
[0080] bandwidth(U i )=ρ i ·U i
[0081] In the above formula, ρ i Indicates the target memory access rate of target computing unit i (unit: MB / s). This value can be obtained through system monitoring.
[0082] It is understandable that by performing the above steps B1-B2 on all target computing units in the same manner, the bandwidth consumption of these multiple computing units can be obtained.
[0083] The above embodiment calculates bandwidth consumption by using the current memory, thereby achieving a quantitative evaluation of bandwidth consumption during concurrent execution of multiple computing units, and providing a basis for subsequent optimization of memory allocation and task scheduling.
[0084] In some embodiments of the present application, when calculating the imbalance of multiple computing units, S201 specifically includes the following steps:
[0085] C1, obtains the target memory of the target computing unit in the currently used memory.
[0086] The target computing unit is any one of the multiple computing units.
[0087] C2 performs normalization calculation on the target memory to obtain a normalized value, and uses the normalized value as the imbalance degree of the target computing unit to obtain the imbalance degrees of multiple computing units.
[0088] For example, the target computing unit's imbalance load_imbalance (U i ) can be defined as:
[0089]
[0090]
[0091] It is understandable that by performing the above steps C1-C2 on all target computing units in the same manner, the imbalance degree of these multiple computing units can be obtained.
[0092] The above embodiment achieves a quantitative evaluation of the imbalance degree when multiple computing units are executed concurrently by calculating the imbalance degree using the current memory, thereby providing a basis for subsequent optimization of memory allocation and task scheduling.
[0093] S202 , substituting the access conflict probability, bandwidth consumption, and imbalance into an operation loss function to calculate the operation losses of the plurality of computing units.
[0094] Among them, operating loss is an indicator for evaluating the degree of terminal performance loss.
[0095] For example, the running loss function here can be defined as:
[0096]
[0097] In the above formula, S represents the operating loss, conflict (U i ) represents the access conflict probability of the target computing unit i, bandwidth(U i ) represents the bandwidth consumption of target computing unit i, load_imbalance(U i ) represents the imbalance degree of the target computing unit i, α i , β i , γ i is the weight coefficient, which reflects the importance of different factors.
[0098] S203: When the running loss reaches a minimum value or converges, it is determined that the running loss function meets a preset iteration termination condition.
[0099] It is understood that when the running loss reaches its minimum value, or when the running loss converges, it indicates that the terminal device has reached an optimal or near-optimal resource configuration state. Further iterations will not significantly improve system performance, so it is determined that the current running loss function meets the preset iteration termination condition.
[0100] The above embodiment, through this dynamic optimization mechanism, achieves the optimal allocation of memory resources among various computing units, effectively solves the access conflicts, bandwidth overload and load imbalance problems caused by uneven memory allocation, thereby significantly improving the overall computing efficiency and resource utilization of the system.
[0101] See also Figure 3 , Figure 3This is a flowchart of a memory allocation method provided in the second embodiment of the present application. Although a logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in an order different from that shown in the accompanying drawings. Specifically, the specific process of the memory allocation method provided in the second embodiment is as follows:
[0102] S301, obtaining currently used memory of multiple computing units.
[0103] S302: Substitute the currently used memory into a preset running loss function, and iteratively adjust the currently used memory through a preset optimization algorithm.
[0104] S303: When the running loss function satisfies a preset iteration termination condition, the currently used memory of the running loss function is obtained as the first allocated memory.
[0105] In some embodiments of the present application, the principles of steps S301-S303 of the second embodiment are basically the same as those of steps S101-S103 of the first embodiment, and therefore are not described in detail.
[0106] S304: Obtain historical allocated memory of multiple computing units.
[0107] The historical allocated memory refers to the memory capacity actually allocated by multiple computing units in the past (for example, every minute, every hour, etc.), which can be represented by time series data to reflect the dynamic changes in memory usage.
[0108] S305 , predicting second allocated memory of the plurality of computing units according to the historical allocated memory.
[0109] The second allocated memory refers to the memory capacity required to be allocated to multiple computing units in a future period predicted based on historical allocated memory data, and is used to guide the pre-allocation or dynamic adjustment of memory resources.
[0110] For example, the prediction method here can record the historical memory allocation of multiple computing units every minute over the past 24 hours to form a time series dataset. Then, the seasonal autoregressive integrated moving average (SARIMA) model is used to analyze the periodicity and trend of memory usage and predict the second memory allocation of multiple computing units in the next 10 minutes.
[0111] For example, the prediction method here could collect the hourly historical memory allocations of multiple computing units over the past week, noting peak memory usage during peak task processing periods and valley memory usage during low task processing periods. Then, a Long Short-Term Memory (LSTM) neural network model is used to capture the nonlinear characteristics and long-term dependencies of memory usage and predict the next hour's allocated memory for multiple computing units.
[0112] S306 , performing weighted calculation on the first allocated memory and the second allocated memory to obtain a third allocated memory, and performing memory allocation on a plurality of computing units based on the third allocated memory.
[0113] As you can understand, due to the varying requirements for real-time performance and forecast accuracy in different business scenarios, the weighting coefficients can be adjusted dynamically. For example, in scenarios with high real-time requirements (such as high-frequency trading systems), the first allocation of memory will be given a higher weight; in scenarios with significant periodicity (such as batch data processing), the second allocation of memory will be given a higher weight. This dynamic adjustment can adapt to diverse resource management needs.
[0114] In some embodiments of the present application, after the third allocated memory is calculated, the third allocated memory must also meet the following conditions:
[0115]
[0116] In the above formula, Indicates the upper limit of the target compute unit's memory capacity. This prevents allocations from being inoperable.
[0117] The above embodiment achieves the coordinated optimization of real-time resource status and long-term prediction trend by weighted calculation of the first allocated memory and the second allocated memory, thereby avoiding allocation deviation caused by a single data source.
[0118] In some embodiments of this application, see Figure 4 , the above memory allocation method further performs the following steps:
[0119] S401, obtaining the target task.
[0120] The target task refers to a specific task that needs to be performed by the computing unit, such as image processing, data calculation, or machine learning reasoning.
[0121] S402, iteratively determine at least one computing unit among multiple computing units through a preset optimization algorithm so that the execution cost of the at least one computing unit in executing the target task is lowest, and execute the target task based on the determined at least one computing unit.
[0122] Similarly, the preset optimization algorithm here can be the simplex method. The simplex method is a classic algorithm for solving linear programming problems. Its core idea is to start from a vertex of the feasible domain and move along the edge of the feasible domain to the adjacent vertex. Each movement ensures that the objective function value is improved until the optimal solution is found or the problem is proved to be unbounded or unsolvable.
[0123] For example, the preset optimization algorithm here could be the interior point method, a modern algorithm for solving linear programming problems. Its basic idea is to start from an initial point within the feasible region, construct a barrier function, and iterate within the feasible region to gradually approach the optimal solution. Unlike the simplex method, the interior point method does not search along the boundary, but instead searches directly within the feasible region for the optimal solution.
[0124] The execution cost here refers to the resource consumption required to execute the target task on the computing unit, including time cost, energy cost, or hardware resource occupation cost. The optimization process of this execution cost can be simply described as:
[0125] Schedule(T j )=argmin i∈{1,2,...,N} (cost(T j ,U i ))
[0126] Among them, cost(T j ,U i ) represents task T j The execution cost on device i.
[0127] In the above embodiment, through task scheduling and reasonable allocation of memory resources, the system can achieve load balancing and further improve the efficiency of collaborative computing between devices.
[0128] In summary, the above memory allocation method, through iterative adjustments combined with an optimization algorithm, dynamically optimizes memory allocation, ensuring optimal allocation of memory resources across computing units. This effectively reduces memory fragmentation and resource waste, improving the overall computing efficiency of the terminal device. Furthermore, by weighting the first and second allocated memory, it achieves coordinated optimization of real-time resource status and long-term forecast trends, avoiding allocation bias caused by a single data source.
[0129] To facilitate better implementation of the memory allocation method of the present application, the present application also provides a memory allocation device based on the above memory allocation method. The meanings of the terms are the same as those in the above memory allocation method, and the specific implementation details can be referred to the description in the method embodiment.
[0130] See also Figure 5 , Figure 5This is a schematic diagram of the structure of the memory allocation device provided in an embodiment of the present application, which may specifically include:
[0131] A memory acquisition module 501 is used to acquire the currently used memory of multiple computing units;
[0132] Iterative adjustment module 502, used to substitute the currently used memory into a preset running loss function and iteratively adjust the currently used memory using a preset optimization algorithm;
[0133] The memory allocation module 503 is used to obtain the current used memory of the running loss function as the first allocated memory when the running loss function meets the preset iteration termination condition, and allocate memory to multiple computing units based on the first allocated memory.
[0134] In the above-mentioned memory allocation device, the memory acquisition module 501 is used to obtain the currently used memory of multiple computing units in real time, the iterative adjustment module 502 is used to substitute the currently used memory into the preset running loss function and perform iterative adjustment in combination with the optimization algorithm, and the memory allocation module 503 is used to determine that the currently used memory at this time is the first allocated memory when the iteration termination condition is met, and perform memory allocation based on the first allocated memory. The core of this solution is to iteratively adjust the currently used memory through the optimization algorithm until the running loss function meets the preset iteration termination condition, ensuring that memory resources are optimally allocated among the computing units, thereby effectively reducing memory fragmentation and resource waste, and improving the overall computing efficiency of the terminal device.
[0135] In some embodiments of the present application, the memory allocation device is also used to: calculate the access conflict probability, bandwidth consumption and imbalance of multiple computing units according to the currently used memory after each iterative adjustment of the currently used memory; substitute the access conflict probability, bandwidth consumption and imbalance into the running loss function to calculate the running loss of multiple computing units; when the running loss reaches the minimum value, or when the running loss converges, it is determined that the running loss function meets the preset iteration termination condition.
[0136] In some embodiments of the present application, when calculating the access conflict probability of multiple computing units, the memory allocation device is also used to: obtain the target memory of the target computing unit in the currently used memory, and obtain the overlapping memory between the target computing unit and the non-target computing unit; wherein, the target computing unit is any one of the multiple computing units, and the non-target computing unit is a computing unit other than the target computing unit in the multiple computing units; calculate the access conflict probability of the target computing unit based on the overlapping memory and the target memory to obtain the access conflict probability of multiple computing units; wherein, the access conflict probability is positively correlated with the overlapping memory, and negatively correlated with the target memory.
[0137] In some embodiments of the present application, when calculating the bandwidth consumption of multiple computing units, the memory allocation device is also used to: obtain the target memory of the target computing unit in the currently used memory, and obtain the target memory access rate of the target computing unit; wherein, the target computing unit is any one of the multiple computing units; calculate the bandwidth consumption of the target computing unit based on the target memory and the target memory access rate to obtain the bandwidth consumption of multiple computing units; wherein, the bandwidth consumption is positively correlated with the target memory and the target memory access rate.
[0138] In some embodiments of the present application, when calculating the imbalance of multiple computing units, the memory allocation device is also used to obtain the target memory of the target computing unit in the currently used memory; wherein the target computing unit is any one of the multiple computing units; the target memory is normalized to obtain a normalized value, and the normalized value is used as the imbalance of the target computing unit to obtain the imbalance of multiple computing units.
[0139] In some embodiments of the present application, the memory allocation device is also used to obtain the historical allocated memory of multiple computing units; predict the second allocated memory of multiple computing units based on the historical allocated memory; the memory allocation module 503 is also specifically used to: weightedly calculate the first allocated memory and the second allocated memory to obtain the third allocated memory, and allocate memory to multiple computing units based on the third allocated memory.
[0140] In some embodiments of the present application, the memory allocation device is also used to obtain a target task; among multiple computing units, at least one computing unit is iteratively determined through a preset optimization algorithm so that the execution cost of the at least one computing unit to execute the target task is the lowest, and the target task is executed based on the determined at least one computing unit.
[0141] In addition, the present application also provides a terminal device, such as Figure 6 As shown, it shows a schematic diagram of the structure of the terminal device involved in this application, specifically:
[0142] The terminal device may include one or more processing core processors 601, one or more computer-readable storage media memories 602, a power supply 603, an input unit 604 and other components. Those skilled in the art will understand that Figure 6 The terminal device structure shown in the figure does not constitute a limitation on the terminal device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
[0143] in:
[0144] Processor 601 is the control center of the terminal device. It connects all components of the terminal device using various interfaces and circuits. By running or executing software programs and / or modules stored in memory 602 and accessing data stored in memory 602, it performs various terminal device functions and processes data, thereby providing overall monitoring of the terminal device. Optionally, processor 601 may include one or more processing cores. Preferably, processor 601 may integrate an application processor and a modem processor. The application processor primarily handles the operating system, user interface, and application programs, while the modem processor primarily handles wireless communications. It is understood that the modem processor may not be integrated into processor 601.
[0145] The memory 602 can be used to store software programs and modules. The processor 601 executes various functional applications and data processing by running the software programs and modules stored in the memory 602. The memory 602 may mainly include a program storage area and a data storage area. The program storage area may store an operating system, at least one application required for a function, etc.; the data storage area may store data created based on the use of the terminal device, etc. In addition, the memory 602 may include high-speed random access memory and non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device. Accordingly, the memory 602 may also include a memory controller to provide the processor 601 with access to the memory 602.
[0146] The terminal device also includes a power supply 603 for supplying power to various components. Preferably, the power supply 603 can be logically connected to the processor 601 via a power management system, thereby enabling the power management system to manage charging, discharging, and power consumption. The power supply 603 can also include one or more DC or AC power supplies, a recharging system, a power supply device debugging circuit, a power converter or inverter, a power status indicator, and other arbitrary components.
[0147] The terminal device may further include an input unit 604, which may be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control.
[0148] Although not shown, the terminal device may further include a display unit, etc., which will not be described in detail here. Specifically in this embodiment, the processor 601 in the terminal device will load the executable files corresponding to the processes of one or more applications into the memory 602 according to the following instructions, and the processor 601 will run the application stored in the memory 602, thereby implementing the steps in any memory allocation method provided in the embodiments of the present application: substituting the currently used memory into the preset running loss function, and iteratively adjusting the currently used memory through a preset optimization algorithm; when the running loss function meets the preset iterative termination condition, obtaining the currently used memory of the running loss function as the first allocated memory, and performing memory allocation on multiple computing units based on the first allocated memory.
[0149] The terminal device obtains the current memory usage of multiple computing units in real time, substitutes it into a preset running loss function, and performs iterative adjustments in conjunction with an optimization algorithm. Ultimately, when the iterative termination condition is met, the currently used memory is determined to be the first allocated memory, and memory allocation is performed based on this first allocated memory. The core of this solution is to iteratively adjust the currently used memory through an optimization algorithm until the running loss function meets the preset iterative termination condition, ensuring that memory resources are optimally allocated among the computing units, thereby effectively reducing memory fragmentation and resource waste, and improving the overall computing efficiency of the terminal device.
[0150] The specific implementation of the above operations can be found in the previous embodiments and will not be repeated here.
[0151] Those skilled in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be accomplished by instructions, or by controlling related hardware through instructions. The instructions may be stored in a computer-readable storage medium and loaded and executed by a processor.
[0152] To this end, the present application provides a computer-readable storage medium having a computer program stored thereon. The computer program can be loaded by a processor to execute the steps in any one of the memory allocation methods provided in the present application.
[0153] The specific implementation of the above operations can be found in the previous embodiments and will not be repeated here.
[0154] The computer-readable storage medium may include a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0155] Since the instructions stored in the computer-readable storage medium can execute the steps in any memory allocation method provided in this application, the beneficial effects that can be achieved by any memory allocation method provided in this application can be achieved. Please refer to the previous embodiments for details and will not be repeated here.
[0156] The above is a detailed introduction to a memory allocation method, device, terminal device and computer-readable storage medium provided by the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea; at the same time, for those skilled in the art, based on the ideas of the present invention, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.
Claims
1. A memory allocation method, characterized in that: The method comprises: Get the current memory used by multiple computing units; Substituting the currently used memory into a preset running loss function, and iteratively adjusting the currently used memory through a preset optimization algorithm; When the running loss function satisfies a preset iteration termination condition, the currently used memory of the running loss function is obtained as a first allocated memory, and memory is allocated to the multiple computing units based on the first allocated memory.
2. The memory allocation method according to claim 1, wherein: The method further comprises: After each iterative adjustment of the currently used memory, respectively calculating access conflict probabilities, bandwidth consumptions, and imbalances of the plurality of computing units according to the currently used memory; Substituting the access conflict probability, the bandwidth consumption, and the imbalance into the operation loss function to calculate the operation losses of the plurality of computing units; When the running loss reaches a minimum value, or when the running loss converges, it is determined that the running loss function meets a preset iteration termination condition.
3. The memory allocation method according to claim 2, wherein: When calculating the access conflict probabilities of the plurality of computing units, respectively calculating the access conflict probabilities, bandwidth consumption, and imbalance of the plurality of computing units according to the currently used memory includes: Obtaining a target memory of a target computing unit in the currently used memory, and obtaining overlapping memory between the target computing unit and non-target computing units; wherein the target computing unit is any one of the plurality of computing units, and the non-target computing units are computing units other than the target computing unit in the plurality of computing units; The access conflict probability of the target computing unit is calculated based on the overlapping memory and the target memory to obtain the access conflict probability of the multiple computing units; wherein the access conflict probability is positively correlated with the overlapping memory and negatively correlated with the target memory.
4. The memory allocation method according to claim 2, wherein: When calculating the bandwidth consumption of the plurality of computing units, respectively calculating the access conflict probability, bandwidth consumption, and imbalance of the plurality of computing units according to the currently used memory includes: Obtaining a target memory of a target computing unit in the currently used memory, and obtaining a target memory access rate of the target computing unit; wherein the target computing unit is any one of the multiple computing units; The bandwidth consumption of the target computing unit is calculated according to the target memory and the target memory access rate to obtain the bandwidth consumption of the multiple computing units; wherein the bandwidth consumption is positively correlated with the target memory and the target memory access rate.
5. The memory allocation method according to claim 2, wherein: When calculating the imbalance of the plurality of computing units, respectively calculating the access conflict probability, bandwidth consumption, and imbalance of the plurality of computing units according to the currently used memory includes: Obtaining a target memory of a target computing unit in the currently used memory; wherein the target computing unit is any one of the multiple computing units; A normalization calculation is performed on the target memory to obtain a normalized value, and the normalized value is used as the imbalance degree of the target computing unit to obtain the imbalance degrees of the multiple computing units.
6. The memory allocation method according to claim 1, wherein: The method further comprises: Obtaining historical allocated memory of the plurality of computing units; predicting second allocated memory for the plurality of computing units based on the historical allocated memory; The allocating memory to the plurality of computing units based on the first allocated memory includes: The first allocated memory and the second allocated memory are weightedly calculated to obtain a third allocated memory, and memory allocation is performed on the plurality of computing units based on the third allocated memory.
7. The memory allocation method according to claim 1, wherein: The method further comprises: Get the target task; Among the multiple computing units, at least one computing unit is iteratively determined through a preset optimization algorithm so that the execution cost of the at least one computing unit in executing the target task is lowest, and the target task is executed based on the determined at least one computing unit.
8. A memory allocation device, characterized in that: The memory allocation device comprises: A memory acquisition module is used to obtain the currently used memory of multiple computing units; an iterative adjustment module, configured to substitute the currently used memory into a preset running loss function and iteratively adjust the currently used memory using a preset optimization algorithm; A memory allocation module is used to obtain the currently used memory of the running loss function as the first allocated memory when the running loss function meets the preset iteration termination condition, and to allocate memory to the multiple computing units based on the first allocated memory.
9. A computer-readable storage medium, characterized in that A computer program is stored, and when the computer program is executed by a processor, the processor is caused to perform the steps of the method according to any one of claims 1 to 7.
10. A terminal device, characterized in that: The method comprises a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of the method according to any one of claims 1 to 7.