A memory allocation and management method for AI training memory access features
By analyzing the characteristics of the AI model training cycle and using the Block and Chunk structures, memory allocation is optimized, the memory fragmentation problem in AI model training is solved, and efficient utilization of memory resources is achieved.
Patent Information
- Application Number
- CN202410316902.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-20
- Publication Date
- 2025-09-16
- Estimated Expiration
- 2044-03-20
AI Technical Summary
Existing memory allocation algorithms fail to effectively utilize memory space during AI model training, resulting in memory fragmentation and resource waste, and are limited by model structure.
The sliding window and distance difference methods are used to analyze the cyclical characteristics of AI model training. Combined with the Block and Chunk data structures, they are divided into small request, regular request and temporary request areas. The double-ended allocation method is used to manage memory and optimize memory allocation and release.
By accurately analyzing memory access characteristics and flexibly managing memory space, memory fragmentation can be reduced, memory requirements during model training can be lowered, and memory usage efficiency can be improved.
Smart Images

Figure CN118210628B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of memory allocation technology, and specifically relates to a memory allocation and management method targeting memory access characteristics of AI training. Background Art
[0002] In recent years, deep learning neural networks have been widely used in various fields, and the size of datasets and neural network models has increased rapidly. However, the memory capacity of devices used to train these neural networks has been relatively slow to develop. In this context, how to efficiently utilize limited memory space for deep learning training has become a critical issue that needs to be addressed in the development of deep learning technology.
[0003] During the training process of a deep learning neural network model, the model parameters are first initialized, followed by multiple rounds of forward and backward propagation to update the model parameters. First, during the parameter initialization phase, memory space must be allocated for all parameter values in the model. Second, during the normal propagation process, data feature information is extracted, and memory is allocated for the feature data (activation values) generated during this process. Then, during the backward propagation process, the model parameter error is calculated, which involves allocating memory for the backward-generated gradient data and freeing memory for the used feature data. Finally, after the parameter update is complete, the memory allocated for other data in that training round is released, retaining only the parameter data for the next training round. Finally, after all training is complete, all memory used during the model training process is released. During model training, data release and allocation occur in parallel, and a large number of temporary data memory accesses occur with short allocation and release intervals. This memory access characteristic can easily lead to memory fragmentation, resulting in wasted memory resources during training.
[0004] To address this issue, many researchers have proposed specialized memory allocation algorithms tailored to the memory access characteristics of artificial intelligence (AI) model training. For example, the ShortcutFusion method allocates static memory space that supports rapid reuse for the residual module in a convolutional neural network model. The PagedAttention method, inspired by the concepts of virtual memory and paging, reduces memory requirements during model training by allocating multiple, discontinuous physical memory blocks to store the key-value vectors generated during large language model training. However, the effectiveness of these memory allocation algorithms is limited by the model structure.
[0005] At the same time, leading technology companies and academic institutions such as NVIDIA, Google, and Facebook are also actively exploring and developing technologies in this area. For example, NVIDIA provides a stream-ordered asynchronous memory allocator in CUDA 11 and later, allowing users to allocate and release data in stream order. In Google's TensorFlow deep learning framework, the memory allocation algorithm is the Best Fit with Coalescing (BFC) algorithm, which is based on the buddy system in Dlmalloc. The BFC algorithm maintains a list of available memory blocks to reuse memory space, enabling TensorFlow to efficiently handle memory data requests during model training. PyTorch, developed by the Facebook AI Academy, adopts a different strategy, primarily managing training device memory through a cached allocator based on the slab concept. This cached allocator operates similarly to a memory pool. When tensors are released, the memory they occupy is not immediately returned to the training device system for management, but is instead retained in a cache. New memory requests are preemptively allocated from the cached memory. This approach optimizes memory usage efficiency and reduces fragmentation. However, these current memory allocation algorithms usually only focus on the size of memory allocation requests, without considering the important feature that memory allocation and release requests are periodic during AI model training. This makes the data layout in the memory space unreasonable during AI model training, leaving a large amount of difficult-to-use memory fragments and wasting memory resources during training. Summary of the Invention
[0006] The present invention addresses the problem of memory fragmentation during neural network training, designs and implements a memory allocation and management method for AI training memory access characteristics, and is used to reduce device memory consumption during neural network training. The method manages the device's memory based on the data request memory access characteristics in the AI training task. First, the method analyzes the rules of model training memory access requests based on the sliding window and distance difference methods for AI training tasks; second, in terms of memory data management, the method uses two data management structures, Block and Chunk, to divide the memory space into a small request data area, a regular request data area, and a temporary request data area to store data with different memory access characteristics; finally, the method uses a time-sharing data management method to manage memory access requests for multiple training cycles, and uses a dual-end data allocation method to allocate memory space for data requests in a single training cycle, while reducing memory fragmentation and retaining a whole block of continuous memory space, thereby reducing memory requirements during model training.
[0007] The present invention provides a memory allocation and management method for AI training memory access features, the steps are as follows:
[0008] Step 1: Obtain memory access request characteristics during AI model training, including the cycle characteristics of AI model training and the data request characteristics within the cycle, and dynamically identify the access pattern of the request.
[0009] Sub-step 1.1: Identify the cycle characteristics of AI model training. During the AI model training process, collect and organize training memory access request data. Use sliding windows and distance difference to find the cycle characteristics of AI model training, including the starting position and length of the training cycle, to obtain the memory access request data in the AI model training cycle.
[0010] Sub-step 1.2: Analyze data request characteristics during the AI model training cycle. Based on the identified memory access request data during the AI model training cycle, compare the allocation request and release request addresses within the cycle to identify data features with temporary characteristics during the AI model training process.
[0011] Step 2: Use a multi-level data management structure to jointly manage device memory and divide the memory space into several areas based on the memory access request characteristics in AI model training.
[0012] Sub-step 2.1: Use the fixed-size Block data structure to preallocate fixed-size memory space, and use the dynamically sized Chunk as the second-level data management structure to manage the memory space in a fine-grained manner. These two-level data structures jointly manage the memory space.
[0013] Sub-step 2.2: Divide two blocks to manage memory requests of different sizes, and set the small request data area M in Block1 small Specially manage small size data, further dividing Block2 into regular request data area M reg and temporary request data area M tmp They are used to manage memory access requests with different characteristics during training. First, when processing data allocation requests, the requested data length is aligned according to the device memory line length; secondly, the parameter SMALL_REQUEST_SIZE is introduced to determine the allocation area of the memory request. For memory requests with a size less than or equal to SMALL_REQUEST_SIZE, the small request data area M in Block1 is allocated. small It is managed by Chunk. For data whose size is larger than SMALL_REQUEST_SIZE, it is managed by the regular request data area M in Block2. reg To manage.
[0014] Step 3: Manage memory space based on the size of the memory request and the cycle characteristics of AI model training.
[0015] Sub-step 3.1: Based on the AI model training cycle characteristics identified in step 1, memory access requests are divided into three phases: initialization, pattern analysis, and periodic request. During the initialization and pattern analysis phases, memory consolidation techniques are used to minimize memory usage. During the periodic request phase, memory merging techniques are used to achieve efficient memory reuse.
[0016] Sub-step 3.2: Based on the data request characteristics within the AI model training cycle analyzed in step 1, assign the non-temporary data requests in the periodic requests to the regular request data area M in the Block2 header. reg For temporary data requests in periodic requests, the temporary request data area M at the end of Block2 is allocated tmp , through double-ended allocation, the entire memory space between the two areas is reserved to reduce the generation of memory fragmentation.
[0017] The present invention has the following beneficial effects:
[0018] (1) Using the request feature analysis method to dynamically collect and identify memory access features in AI model training, it can accurately analyze the training processes of various models with periodic characteristics, greatly improving the applicability of the memory allocation management method.
[0019] (2) Introduce multiple data structures and partitioning mechanisms to jointly manage memory space, achieve flexible memory management, and finely adapt to the memory access characteristics of different training stages of the AI model.
[0020] (3) Combined with the training cycle information of the AI model, memory organization and memory merging are used to manage memory partitions, which can optimize the data layout in the memory and compress storage gaps, thereby reducing the maximum memory demand during training.
[0021] (4) For memory access request data within a cycle, a dual-end allocation method is adopted, and memory allocation management is performed from both the high address area and the low address area, effectively retaining the complete memory space and reducing the amount of memory fragmentation. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 It is the overall architecture diagram;
[0023] Figure 2 It is a schematic diagram of a cycle identification method for a request sequence;
[0024] Figure 3 It is a schematic diagram of memory space partition;
[0025] Figure 4 This is a schematic diagram showing the distinction between the memory access request stages of model training;
[0026] Figure 5It is a schematic diagram of the memory organization method;
[0027] Figure 6 This is a schematic diagram of the double-ended allocation method in the periodic request phase. DETAILED DESCRIPTION
[0028] The present invention will be further described below with reference to the accompanying drawings and specific implementation steps:
[0029] like Figure 1 A memory allocation and management method for AI training memory access features is shown, comprising the following steps:
[0030] Step 1: Obtain memory access request characteristics during AI model training, including the cycle characteristics of AI model training and the data request characteristics within the cycle, and dynamically identify the access pattern of the request.
[0031] Sub-step 1.1: Dynamically identify the cycle characteristics of AI model training while managing AI model memory access requests. Record the request sequence while processing memory access and release requests during training, including the data allocation / release identifier, request size, request allocation address information of each request, and identify the training cycle length and training cycle start index in the request sequence. Figure 2 As shown, first, two subsequences are intercepted: subset1 starts from the end of the request sequence and subset2 starts from the beginning of the request sequence and goes backwards. The initial window size is set to max_period_length. Then, the difference between sequence subset1 and sequence subset2 is compared using the distance difference method. As shown in formula (1), the request data in subset1 and subset2 are compared in turn. If the distance difference between subset1 and subset2 is not zero, subset2 slides backward to continue the comparison; if the distance difference is zero, it means that the request data in the two sequences are equal, that is, the two sequences are at the same position in the cycle. At this time, subset1 and subset2 simultaneously expand the comparison window to find the starting position of the cycle. When the distance difference between the two subsequences is non-zero again, it means that the sequence head of subset2 is the starting position of the cycle, and the data between the sequence head of subset1 and the sequence head of subset2 is the memory access request data in a model training cycle.
[0032] distance=∑ i∈subset |subset1 i -subset2 i |(1)
[0033] Finally, when a completely matching sequence cannot be found, the window size is reduced to perform finer-grained period recognition until the window size is less than min_period_length, at which point the search and recognition process is stopped.
[0034]
[0035]
[0036] Sub-step 1.2: Based on the model training cycle memory access request data found in sub-step 1.1, analyze the data request characteristics within the cycle. First, traverse the periodic memory requests, set the starting index of the request within the cycle to 0, and for the allocation request with index i, compare the request with the release request with index (i, i+TMP_DATA_ACCESS_INTERVAL]. If there is a release request with the same address as the current allocation request, it means that the data corresponding to the allocation request is temporary data generated during the training process and will be released in a short time. Once such temporary data requests are identified, the relative index position i of these requests in the model training cycle will be recorded.
[0037] Step 2: Use a multi-level data management structure to jointly manage device memory and divide the memory space into multiple areas based on the memory access request characteristics in AI model training.
[0038] Sub-step 2.1: Use Block and Chunk data structures to jointly manage memory space. First, Block is used as the first-level data management structure. Block is a fixed-size memory block used to apply for or release fixed-size memory space from the device at one time, and is used to pre-allocate fixed-size memory space. Next, Chunk is used as the second-level data management structure for memory management. Chunk can dynamically adjust its size by splitting or merging with adjacent free Chunks. Each Block contains multiple Chunks, which are responsible for further subdividing these pre-applied memories to meet memory allocation requirements of different sizes and life cycles.
[0039] Sub-step 2.2: Use the Block and Chunk data structures to divide the requested device memory into two fixed-size blocks. Block 1 contains the small requested data area M. small , Block2 contains the regular request data area M reg and temporary request data area M tmp All three areas are composed of multiple chunks. Figure 3 As shown, first, apply for a fixed-size memory space as the memory area managed by the allocation algorithm, and reserve a fixed-size Block1 at the head position of the memory area as the small request data area Msmall , multiple Chunks are used within the area to manage the allocation and release of small request data. Regular request data area M reg and temporary request data area M tmp Managed by Block2, regular request data area M reg With M small Adjacent, located at the head of Block2, consists of multiple Chunks of non-fixed size, which are connected to each other in the form of a linked list. Temporary request data area M tmp Allocated at the end of the memory pool, with M reg Similarly, this area is also composed of multiple dynamically sized chunks.
[0040] Among them, the small request data area M small Specially used to process smaller memory requests to prevent multiple small blocks of data from dividing the continuous memory space, causing subsequent memory allocation requests to be unable to be satisfied. reg and temporary request data area M tmp They are responsible for managing memory access requests with different characteristics during model training. reg It is designed to manage non-periodic data requests and request data that is stored in the cache for a long time in periodic requests, such as feature mapping data in the model training process. Temporary request data area M tmp Used to process data that will be quickly released in periodic requests, such as temporary space requested by the convolutional layer during training and data for memory optimization.
[0041] Step 3: Memory space management is performed based on the size of the memory request and the cycle characteristics of the AI model training. At the same time, for the memory access request data within the cycle, a dual-end data allocation method is used to allocate and manage the memory request data during the model training process from both ends of Block 2.
[0042] Sub-step 3.1: Divide memory access requests into three stages based on the characteristics of the AI model training cycle: initialization stage, pattern analysis stage, and periodic request stage. Apply memory organization technology and memory merging technology to manage memory in different stages.
[0043] by Figure 4 For example, Figure 4This is a data image obtained by accumulating allocation and release requests during the four rounds of training of the VGG16 model. The initialization phase refers to the first training cycle in the AI model training process. During this training cycle, a large amount of data initialization and caching processes are usually involved, which are significantly different in nature from subsequent periodic memory requests. The regularity analysis phase refers to the phase of analyzing the model's training cycle. It usually takes two AI model training cycles to identify the request cycle and analyze the request characteristics within the cycle. The periodic request phase refers to the phase where the period characteristics have been identified and regular periodic requests have begun. This phase includes all memory access requests from the start of the fourth training cycle of the model to the end of model training.
[0044] Memory merging technology refers to merging adjacent free chunks. If the chunk i It is an idle chunk, and the chunk associated with it is linked to it using a bidirectional linked list. i-1 or Chunk i+1 is also an idle Chunk, then merge the adjacent idle Chunks. i ,Chunk i+1} as an example, after merging, update Chunk according to formula (2) i The size of Chunk and update i The link relationship with the adjacent Chunk, after the update is completed, delete the Chunk i+1 . size is the size of the corresponding Chunk:
[0045] Chunk i .size=Chunk i .size+Chunk i+1 .size(2)
[0046] Memory organization technology thoroughly organizes the layout of data in space, such as Figure 5 As shown, traverse M from front to back reg Chunk linked list in, when the allocated Chunk i There is an idle chunk in front i-1 First, mark the Chunk i is used, then Chunk i Copy data to Chunk i-1 The starting address of the chunk is swapped i-1 and Chunk i Size, marked Chunk i In the idle state. When there are two adjacent chunks in the idle state, memory merging is performed to collect the memory fragments distributed in the allocated memory.
[0047] During the initialization and pattern analysis phase, memory organization technology is used to minimize memory usage. First, when processing data allocation requests, the request data length is aligned according to the device memory line length. Second, this method introduces a parameter SMALL_REQUEST_SIZE to determine the allocation area of the memory request. For memory requests with a size less than or equal to SMALL_REQUEST_SIZE, the small request data area M in Block 1 is allocated. small For data with a size larger than SMALL_REQUEST_SIZE, it is handed over to the regular request data area M in Block2. reg Next, in the regular request data area M reg When allocating memory in the memory, the method first checks whether there is a free chunk larger than the requested data size. If so, the chunk with the smallest size difference from the requested size and the lowest address is selected for allocation. If no suitable free chunk is found, the method will perform memory sorting on the chunk list in the current area. The method traverses M from front to back. reg The chunk list in the memory is sorted until the free chunk size found can meet the requested size. Before returning the allocation result, the free chunk found is split into {Chunk i ,Chunk i+1}, Chunk i Chunk is the requested size after alignment. i+1 Chunk is marked as the difference between the currently found free Chunk size and the requested size i The allocation result is returned after the usage status is reached. Finally, if the memory arrangement method still cannot find a chunk that meets the request, try to apply for a new chunk in Block2 to meet the memory request. When the remaining memory in Block2 still cannot meet the request, the allocation fails. In particular, the request allocation process is bound to the CUDA Stream to ensure that data movement and data calculation can be carried out in sequence. At the same time, to address the address change problem caused by data copying, a management mechanism is provided through the conversion of virtual addresses and real addresses. In the method, the virtual address is returned to the requester, and when actual data access is required, the real memory starting address in the corresponding chunk is provided.
[0048] In the periodic request phase, memory merging technology is used to achieve efficient memory reuse. First, the request data is aligned according to the length of the memory line. Second, the request with a size smaller than SMALL_REQUEST_SIZE is assigned to the small request data area M. smallFor management, data larger than this size is handed over to the regular request data area M reg To manage memory, in the process of memory allocation, first of all, M reg All free chunks in the area are merged, and the memory allocation is performed to determine whether there is a chunk in the merged chunks that can meet the requested size. If so, the chunk is split and returned. If not, a new chunk is allocated in Block2 to meet the memory request. If the remaining memory in Block2 still cannot meet the request, the allocation fails.
[0049] Sub-step 3.2: In the periodic request phase, first determine the data request characteristics within the AI model training cycle based on the relative coordinates of the request and the cycle start position. Figure 6 As shown, the non-temporary data request is assigned to the regular request data area M reg , and managed through memory merging technology, in the regular request data area M reg When there is no free Chunk, new Chunk blocks are gradually applied to the end of Block2, that is, the high address area in Block2; for temporary data requests in the cycle, they are allocated to the temporary request data area M tmp , which is located in the high address area of the memory pool. tmp If there is no free memory block in Block 2, it will gradually allocate memory by applying for a new Chunk block at the head of Block 2, that is, the low address area in Block 2. tmp After the Chunk blocks with medium and low addresses are used, the memory occupied by this part will be released directly. reg and temporary request data area M tmp The sizes of these two areas are not fixed, where M reg The size of M floats to the higher address. tmp The size of the floats to the lower address, and M reg and M tmp A continuous unused memory can be reserved between them, which provides operating space for memory allocation in a multi-tasking environment.
[0050] Experimental data
[0051] In order to verify the effectiveness of a memory allocation and management method for AI training memory access features, the allocation algorithm in PyTorch and TensorFlow and the present invention are used to verify the effect on the training memory request sequence of five models: VGG16, MobileNet, ResNet-50, InceptionV3 and DenseNet-121. The experiment counted the maximum memory capacity required for training on different models using input data of [32,3,224,224] with data type of float32. Among them, the small request size SMALL_REQUEST_SIZE is set to 2MB, where M small The allocation size is fixed at 10MB. The TMP_DATA_ACCESS_INTERVAL interval for temporary allocation requests is set to 2. Experimental data shows that compared to the allocation algorithms in PyTorch and TensorFlow, the memory allocation and management method for AI training memory access features proposed in this paper can complete the model training process using less memory for all tested models, achieving efficient memory space management.
[0052] Table 1 Maximum memory requirements during training of different models (unit: GB)
[0053]
[0054] The experimental results are shown in Table 1, from which it can be seen that the memory requirement of the present invention is significantly smaller than that of the other two groups of allocation algorithms during different model training processes.
Claims
1. A memory allocation and management method for AI training memory access features, characterized in that: The steps include: Step 1: Obtain memory access request characteristics during AI model training, including the AI model training cycle characteristics and data request characteristics within the cycle. The specific process is as follows: Sub-step 1.1: During AI model training, collect and organize training memory access request data. Use sliding windows and distance difference to identify the cycle characteristics of AI model training, including the start position and length of the training cycle, to obtain the memory access request data during the AI model training cycle. Sub-step 1.2: Based on the memory access request data in the identified AI model training cycle, compare the allocation request and release request addresses within the cycle to identify data request features with temporary characteristics during the AI model training process; Step 2: Use a multi-level data management structure to jointly manage device memory. Divide the memory space into several areas based on the memory access request characteristics during AI model training. The specific process is as follows: Sub-step 2.1: Use a fixed-size Block data structure to pre-allocate fixed-size memory space, and use a dynamically sized Chunk as a second-level data management structure to manage the memory space in a fine-grained manner; the two-level data structures jointly manage the memory space; Sub-step 2.2: Divide two blocks to manage memory requests of different sizes, and set the small request data area M in Block1 small Specially manage small size data and divide Block2 into regular request data area M reg and temporary request data area M tmp Manage memory access requests with different characteristics during training separately; Step 3: Manage memory space based on the size of the memory request and the cycle characteristics of AI model training.
2. The memory allocation and management method for AI training memory access features according to claim 1, characterized in that: In sub-step 2.2, first, when processing a data allocation request, the requested data length is aligned according to the device memory row length; Secondly, the parameter SMALL_REQUEST_SIZE is introduced to determine the allocation area of the memory request. For memory requests with a size less than or equal to SMALL_REQUEST_SIZE, the small request data area M in Block1 small It is managed by Chunk. For data whose size is larger than SMALL_REQUEST_SIZE, it is managed by the regular request data area M in Block2. reg To manage.
3. The memory allocation and management method for AI training memory access features according to claim 2, characterized in that: The Block is a first-level data management structure, which is a fixed-size memory block used to apply for or release fixed-size memory space from the device at one time and to pre-allocate fixed-size memory space; The Chunk is used as a second-level data management structure for memory management. The Chunk is dynamically resized by splitting or merging with adjacent free Chunks. Each Block contains multiple Chunks, which subdivide the pre-applied memory.
4. The memory allocation and management method for AI training memory access features according to claim 3, characterized in that: The small request data area M small , Regular request data area M reg and temporary request data area M tmp , are composed of multiple Chunks; first, apply for a fixed-size memory space as the memory area managed by the allocation algorithm, and reserve a fixed-size Block1 at the head position of the memory area as the small request data area M small , manage the allocation and release requests of small request data through multiple Chunks within the area; Secondly, the regular request data area M reg and temporary request data area M tmp Managed by Block2, regular request data area M reg With M small Adjacent, located at the head of Block2, composed of multiple Chunks of non-fixed size, which are connected to each other in the form of a linked list; Temporary request data area M tmp Allocated at the end of the memory pool, with M reg Similarly, this area is also composed of multiple dynamically sized chunks.
5. The memory allocation and management method for AI training memory access features according to claim 4, characterized in that: The specific process of step 3 is as follows: Sub-step 3.1: Based on the characteristics of the AI model training cycle, memory access requests are divided into three phases: initialization phase, pattern analysis phase, and periodic request phase. During the initialization and pattern analysis phases, memory consolidation technology is used to minimize memory usage. In the periodic request phase, memory merging technology is used to achieve efficient memory reuse; Sub-step 3.2: Based on the data request characteristics during the AI model training cycle, assign the non-temporary data requests in the periodic requests to the regular request data area M in the Block2 header. reg For temporary data requests in periodic requests, the temporary request data area M at the end of Block2 is allocated tmp , through double-ended allocation, the entire memory space between the two areas is reserved to reduce the generation of memory fragmentation.
6. The memory allocation and management method for AI training memory access features according to claim 5, characterized in that: The memory merging technology is to merge adjacent free chunks. If the chunk i It is an idle chunk, and the chunk associated with it is linked to it using a bidirectional linked list. i-1 or Chunk i+1 If it is also an idle Chunk, then merge the adjacent idle Chunks. After merging, update the Chunk according to formula (1) i The size of Chunk is updated i The link relationship with the adjacent Chunk, after the update is completed, delete the Chunk i+1 ; size is the size of the corresponding Chunk; Chunk i .size=Chunk i ·size+Chunk i+1 ·size (1) The memory arrangement technology arranges the layout of data in space and traverses M from front to back. reg Chunk linked list in, when the allocated Chunk i There is an idle chunk in front i-1 , first mark the Chunk i is used, and then Chunk i Copy data to Chunk i-1 The starting address of the chunk is swapped i-1 and Chunk i Size, marked Chunk i It is in an idle state; when there are two adjacent chunks in an idle state, memory merging is performed to collect the memory fragments distributed in the allocated memory.
7. The memory allocation and management method for AI training memory access features according to claim 6, characterized in that: In the initialization and regularity analysis phase, in the regular request data area M reg When allocating memory in , first check whether there is a free chunk larger than the requested data size; if so, select the chunk with the smallest size difference from the requested size and the lowest address for allocation. If no suitable free chunk is found, the chunk list of the current area will be sorted in memory; traverse M from front to back. reg The Chunk list in the memory is sorted until the free Chunk size found meets the requested size; before returning the allocation result, the free Chunk found is split into {Chunk i ,Chunk i+1 }, Chunk i Chunk is the requested size after alignment. i+1 Chunk is marked as the difference between the currently found free Chunk size and the requested size i The allocation result is returned after the state is used; finally, if the memory arrangement method still cannot find a chunk that meets the request, a new chunk is requested in Block2 to meet the memory request. When the remaining memory in Block2 still cannot meet the request, the allocation fails. The virtual address is returned to the requester, and when actual data access is performed, the real memory start address in the corresponding chunk is provided; In the periodic request phase, first, the request data is aligned according to the length of the memory row; Secondly, in the process of memory allocation, M reg All free chunks in the area are merged, and the merged chunks are checked to see if there is a chunk that meets the requested size. If so, the chunk is split and returned. If not, a new chunk is requested in Block2 to meet the memory request. If the remaining memory in Block2 still cannot meet the request, the allocation fails.
Citation Information
Patent Citations
Memory allocation method of AI processor, computer device and computer readable storage medium
CN113168349A
Method for realizing AI model training memory optimization by adopting reinforcement learning
CN117234710A