A remappable GPU main memory access management method and system
By dividing the main memory address space into a through pool and a mapping pool, and configuring ATU and GMMU for address mapping, the problem of low efficiency of accessing main memory by GPU is solved, and efficient access to main memory by GPU is achieved.
Patent Information
- Application Number
- CN202210071718.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-21
- Publication Date
- 2025-03-04
- Estimated Expiration
- 2042-01-21
AI Technical Summary
In the prior art, there are limitations in GPU access to the main memory, resulting in low access efficiency, especially in application scenarios where video memory is exhausted or frequent access to the main memory is required.
By dividing the main memory address space into a through pool and a mapping pool, the direct pool is preferred to allocate continuous main memory space. If it fails, it will be allocated from the mapping pool. The ATU and GMMU are configured for address mapping to achieve efficient access to the main memory by the GPU.
It improves the efficiency of GPU accessing main memory, reduces mapping complexity, improves mapping efficiency in most applications, and achieves the purpose of GPU accessing the entire main memory space.
Smart Images

Figure CN114461391B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a remappable GPU (Graphics Processing Unit, graphics processor) main memory access management method and system. Background Art
[0002] When using a GPU for graphics rendering, the rendering data is generally stored in the GPU's video memory and / or the CPU's (Central Processing Unit) main memory. During the rendering process, the CPU can send rendering instructions to the GPU. The rendering instructions include the storage addresses of the data in the video memory and the main memory. The GPU can read the corresponding stored data based on the storage address, and after rendering the data, it can obtain a rendered image. In general, the GPU uses video memory more efficiently and has faster access speeds. However, for some special application scenarios, such as video memory exhaustion, or space that requires frequent CPU operations and the GPU to access, or some special applications, such as OPENCL (Open Computing Language), the GPU needs to use main memory, or even a large amount of main memory.
[0003] For PCIE (Peripheral Component Interconnect Express) independent graphics cards, they are generally NUMA (Non-Uniform-Memory-Access) graphics cards. The GPU and CPU are heterogeneous, and their addressing spaces are also independent of each other. The GPU must be mapped by PCIE to access the main memory. Due to the limitations of PCIE mapping resources and GPU addressing space, it is impossible for the GPU to directly access all main memory. The current solution is either to map part of the main memory space directly to the GPU main memory address space via PCIE to allow the GPU to access part of the main memory, or to use IOMMU (Input / Output Memory Management Unit) to map the main memory address to the GPU main memory address space. The former solution has limitations on accessing the main memory, and the latter solution requires an additional level of mapping, which affects efficiency. Summary of the invention
[0004] In view of the defects of the prior art, the purpose of the present invention is to provide a remappable GPU main memory access management method and system, aiming to break through the limitations of GPU access to main memory and make GPU access to main memory more efficient.
[0005] To solve the above problem, according to one aspect of the present invention, a remappable GPU main memory access management method and system are provided, comprising the following steps:
[0006] (1) According to the preset range of the main memory address space required by the GPU, the main memory address space is divided into two pools, which are defined as a pass-through pool and a mapping pool;
[0007] (2) Allocate space from the pass-through pool. If the main memory address space required by the GPU is continuous and the size is less than or equal to the preset maximum continuous space threshold, go to step (3); otherwise, go to step (4);
[0008] (3) Allocate continuous main memory space and physical address to GPU. If successful, go to step (9); otherwise, go to step (4);
[0009] (4) Allocate non-contiguous main memory space and physical address linked list to the GPU. If successful, go to step (9); otherwise, go to step (5);
[0010] (5) Allocate space from the mapping pool. If the main memory address space required by the GPU is continuous, go to step (6); otherwise, go to step (7);
[0011] (6) Allocate continuous main memory space and physical address to GPU. If successful, go to step (8), otherwise the allocation fails;
[0012] (7) Allocate non-contiguous main memory space and physical address to the GPU. If successful, go to step (8), otherwise the allocation fails;
[0013] (8) Configure the ATU (Address Translation Unit) to perform mapping processing;
[0014] (9) A mapping relationship between GPU virtual address, GPU physical address and GPU physical address linked list is established through GMMU (GPU Memory Management Unit) page table.
[0015] Furthermore, the size of the pass-through pool is the size of the GPU main memory address space, and starts from address 0, and the remaining main memory space is the mapping pool.
[0016] Furthermore, in step (2) of allocating space from the direct pool, the main memory address space required by the GPU is mapped to the direct pool in an equal linear mapping manner.
[0017] Furthermore, in step (2) of allocating space from the direct pool, the CPU physical address and the GPU physical address are in a linear offset relationship.
[0018] Furthermore, in step (8), the mapping relationship between the corresponding GPU physical address and the CPU physical address is rebuilt by configuring the ATU.
[0019] Furthermore, the GMMU page table access method in step (9) is:
[0020] (a) GPU reads the GPU virtual address;
[0021] (b) According to the GPU virtual address, query the GMMU page table to calculate the GPU physical address;
[0022] (c) Check whether the GPU physical address is within the main memory address space. If so, the GPU accesses the corresponding main memory physical address through ATU mapping. Otherwise, the GPU directly accesses the video memory physical address.
[0023] According to another aspect of the present invention, a remappable GPU main memory access management system is provided, characterized in that it includes: a main memory allocator module, a GPU main memory address space management module, an ATU mapping management module and a GMMU management module;
[0024] The main memory allocator module is used to allocate continuous or non-continuous main memory in the entire main memory space, and can control whether the CPU physical address of the main memory is in the pass-through pool or the mapping pool according to the pool tag. If the continuous space is allocated successfully, the module can obtain the CPU physical address, and if the non-continuous space is allocated successfully, the module can obtain the CPU physical address linked list;
[0025] The GPU main memory address space management module is used to manage the allocation and release of GPU physical addresses in the GPU main memory address space;
[0026] The ATU mapping management module is used to maintain a mapping relationship table between GPU physical addresses and CPU physical addresses in the GPU main memory address space. When allocating space from the mapping pool, the ATU mapping management module needs to rebuild the mapping relationship between the corresponding GPU physical addresses and CPU physical addresses.
[0027] The GMMU management module is used to maintain the GMMU page table and manage the mapping relationship between the GPU virtual address and the GPU physical address.
[0028] In general, the technical solution of the present invention is used to achieve the following beneficial effects compared with the prior art:
[0029] The present invention provides a GPU main memory access management method, which preferentially uses a pass-through pool to allocate main memory space, reduces mapping complexity in most application cases, improves mapping efficiency and GPU access to main memory efficiency; in addition, a main memory access management system is provided, which flexibly performs remapping through a GMMU management module and an ATU mapping management module to achieve the purpose of GPU accessing the entire main memory space. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] Figure 1 A flowchart of a GPU main memory access management method provided by an embodiment of the present invention;
[0031] Figure 2 A schematic diagram of the address mapping relationship provided by an embodiment of the present invention;
[0032] Figure 3 A main memory allocation flow chart provided for an embodiment of the present invention;
[0033] Figure 4 A flowchart of GPU accessing main memory provided by an embodiment of the present invention;
[0034] Figure 5 This is a block diagram of the GPU main memory access management system module provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0035] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0036] like Figure 1 As shown, an embodiment of the present invention provides a remappable GPU main memory access management method, the method comprising the following steps:
[0037] First, the main memory space is divided into two pools according to the GPU main memory address space range, defined as the direct pool and the mapping pool. The direct pool size is the GPU main memory address space size and starts from address 0. The remaining main memory space is the mapping pool.
[0038] The current mainstream CPU platforms all have 64-bit address spaces, and the GPU main memory address space range is definitely less than 64 bits. For example, the GPU main memory address space range is 0x0 to 0xffffffff, a total of 4GB. Then the main memory space pass-through pool is 0x0 to 0xffffffff, that is, all 32-bit addresses. The mapping pool is all address spaces above 0xffffffff. By default, the ATU mapping management module maps the GPU main memory address space to the pass-through pool in equal linear amounts. At this time, the GPU physical address is equal to the CPU physical address, that is, the offset is 0.
[0039] like Figure 2 As shown, when allocating the main memory space that the GPU needs to access;
[0040] First, determine whether the continuous mark parameter passed by the upper layer is 1. If so, proceed to the next step. If not, proceed to the direct pool allocation non-continuous space process.
[0041] Then, the allocated space size is compared with the maximum continuous space threshold, for example, 4MB. If the allocated space is less than 4MB, the next step of the direct pool allocation continuous space process is entered; otherwise, the direct pool allocation non-contiguous space process is entered.
[0042] When allocating continuous main memory space, prioritize allocating continuous space from the pass-through pool; if the allocation fails, allocate non-contiguous space from the pass-through pool; if the allocation fails, allocate continuous space from the mapping pool; if the allocation fails, allocate non-contiguous space from the mapping pool, and if the allocation fails, the allocation of main memory space that the GPU needs to access fails. When allocating non-contiguous main memory space, prioritize allocating non-contiguous space from the pass-through pool; if the allocation fails, allocate non-contiguous space from the mapping pool, and if the allocation fails, the allocation of main memory space that the GPU needs to access fails.
[0043] If the main memory allocator successfully allocates continuous space from the pass-through pool, the CPU physical address of the allocated continuous space is obtained, that is, a 32-bit address, which is recorded as c_addr1. The allocated continuous space is recorded as S1. Then the GPU main memory address space management module allocates the GPU physical address of S1, which is recorded as g_addr1. At this time, g_addr1 = c_addr1, that is, the offset is 0. If g_addr1 is occupied, that is, the GPU main memory address space management module fails to allocate the GPU physical address of S1, then return to the main memory allocator to re-allocate continuous space from the pass-through pool and release the previously applied continuous space. If the GPU main memory address space management module successfully allocates the GPU physical address of S1, the next step is to write g_addr1 into the GMMU page table through the GMMU management module and obtain the GPU virtual address gv_addr1. At this point, the main memory is successfully allocated and the allocation process ends.
[0044] If the main memory allocator successfully allocates non-contiguous space from the pass-through pool, it obtains the CPU physical address list of the allocated non-contiguous space, which contains n continuous spaces. This address list is recorded as c_addr2[n]. The allocated non-contiguous space is recorded as S2. Then, the GPU main memory address space management module obtains the GPU physical address list of S2, which is recorded as g_addr2[n]. At this time, g_addr2[0]=c_addr2[0], g_addr2[1]=c_addr2[1], ..., g_addr2[n-1]=c_addr2[n-1]. If at least one of the address spaces in g_addr2[n] is occupied, that is, the GPU main memory address space management module fails to allocate the GPU physical address list of S2, then it returns to the main memory allocator to re-allocate continuous non-space from the pass-through pool and release the previously applied non-contiguous space. If the GPU main memory address space management module successfully allocates the GPU physical address linked list of S2, the next step is to write g_addr2[n] into the GMMU page table through the GMMU management module and obtain the GPU virtual address gv_addr2 (continuous). At this point, the main memory is allocated successfully and the allocation process ends.
[0045] If the main memory allocator successfully allocates continuous space from the mapping pool, the CPU physical address of the allocated continuous space is obtained, that is, a 64-bit address, which is recorded as c_addr3. The allocated continuous space is recorded as S3. Then, the GPU physical address of S3 is obtained through the GPU main memory address space management module, recorded as g_addr3. At this time, g_addr3 is within the 32-bit range and does not overlap with other GPU physical addresses. If the GPU main memory address space management module fails to allocate the GPU physical address of S3, it means that the GPU main memory address space has been exhausted and the main memory allocation has failed. If the GPU main memory address space management module successfully allocates the GPU physical address of S3, the next step is to establish a mapping relationship between c_addr3 and g_addr3 through the ATU mapping management module. Then, g_addr3 is written into the GMMU page table through the GMMU management module, and the GPU virtual address gv_addr3 is obtained. At this point, the main memory is allocated successfully and the allocation process ends.
[0046] If the main memory allocator successfully allocates non-contiguous space from the mapping pool, a CPU physical address list of allocated non-contiguous space is obtained. The list contains n continuous spaces. This address list is recorded as c_addr4[n], and these n addresses are all 64-bit addresses. The allocated non-contiguous space is recorded as S4. Then the GPU physical address of S4 is obtained through the GPU main memory address space management module, recorded as g_addr4. At this time, g_addr4 is within the 32-bit range and does not overlap with other GPU physical addresses. If the GPU main memory address space management module fails to allocate the GPU physical address of S4, it means that the GPU main memory address space has been exhausted and the main memory allocation has failed. If the GPU main memory address space management module successfully allocates the GPU physical address of S4, the next step is to establish a mapping relationship between c_addr4[n] and g_addr4 through the ATU mapping management module. Then, g_addr4 is written into the GMMU page table through the GMMU management module, and the GPU virtual address gv_addr4 is obtained. At this point, the main memory is successfully allocated and the allocation process ends.
[0047] like Figure 3 , 4 The process of GPU accessing main memory is shown as follows:
[0048] First, the GPU reads the GPU virtual address gv_addr for access.
[0049] Subsequently, the GPU queries the GMMU page table to calculate the GPU physical address g_addr through the virtual address gv_addr.
[0050] Subsequently, the GPU queries whether g_addr is within the main memory address space range. If so, the GPU accesses the corresponding main memory physical address c_addr through ATU mapping; if not, the GPU directly accesses the video memory physical address.
[0051] like Figure 5 As shown, the embodiment of the present invention also discloses a remappable GPU main memory access management system, which includes the following functional modules:
[0052] The main memory allocator module is used to allocate continuous or non-continuous main memory in the entire main memory space, and can control whether the CPU physical address of the main memory is in the pass-through pool or the mapping pool according to the pool tag. If the continuous space is allocated successfully, the module can obtain the CPU physical address. If the non-continuous space is allocated successfully, the module can obtain the CPU physical address linked list.
[0053] The GPU main memory address space management module manages the allocation and release of the GPU physical address of the GPU main memory address space. When the continuous space is successfully allocated from the direct pool, the module allocates the GPU physical address corresponding to the CPU physical address. At this time, the GPU physical address and the CPU physical address are in a linear offset relationship (in the embodiment, they are equal, that is, the offset is 0). If the corresponding GPU physical address has been occupied, it returns to the main memory allocator to re-allocate the continuous space from the direct pool and release the previously applied continuous space; when the non-continuous space is successfully allocated from the direct pool, the module allocates the GPU physical address linked list corresponding to the CPU physical address linked list. At this time, the GPU physical address linked list and the CPU physical address linked list are in a linear offset relationship (in the embodiment, they are equal, that is, the offset is 0). If the corresponding GPU physical address has been occupied, it returns to the main memory allocator to re-allocate the non-continuous space from the direct pool and release the previously applied non-continuous space; when the continuous or non-continuous space is successfully allocated from the mapping pool, the module allocates the corresponding GPU physical address from the free space of the GPU main memory address. If the GPU main memory address space management module fails to allocate, it means that the GPU main memory address space has been exhausted and the main memory allocation has failed. The GPU physical address generated by this module and the CPU physical address generated by the main memory allocator establish a mapping relationship through the ATU mapping management module.
[0054] The ATU mapping management module maintains the mapping relationship table between the GPU physical address and the CPU physical address of the GPU main memory address space. By default, the GPU main memory address space is mapped to the pass-through pool in an equal linear mapping manner; when space is allocated from the mapping pool, the corresponding GPU physical address and CPU physical address mapping relationship needs to be rebuilt through the ATU mapping management module.
[0055] GMMU management module: maintains the GMMU page table and manages the mapping relationship between GPU virtual addresses and GPU physical addresses.
[0056] The execution method of the remappable GPU main memory access management system provided in this embodiment is substantially the same as the above-mentioned GPU main memory access management method, so it will not be described in detail.
[0057] It will be easily understood by those skilled in the art that the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A remappable GPU main memory access management method, characterized in that: The following steps are involved: (1) According to the preset range of main memory address space required by the GPU, the main memory address space is divided into two pools, defined as the pass-through pool and the mapping pool; (2) Allocate space from the pass-through pool. If the main memory address space required by the GPU is continuous and its size is less than or equal to the preset maximum continuous space threshold, go to step (3); otherwise, go to step (4). (3) Allocate continuous main memory space and physical address to the GPU. If successful, go to step (9); otherwise, go to step (4). (4) Allocate non-contiguous main memory space and physical address linked list to the GPU. If successful, go to step (9), otherwise go to step (5); (5) Allocate space from the mapping pool. If the main memory address space required by the GPU is continuous, go to step (6); otherwise, go to step (7). (6) Allocate continuous main memory space and physical address to the GPU. If successful, go to step (8), otherwise the allocation fails; (7) Allocate non-contiguous main memory space and physical address to the GPU. If successful, go to step (8), otherwise the allocation fails; (8) Configure ATU for mapping processing; (9) Establish the mapping relationship between GPU virtual address, GPU physical address and GPU physical address linked list through GMMU page table. The pass-through pool size is the size of the GPU main memory address space, and starts from address 0, and the remaining main memory space is the mapping pool.
2. The GPU main memory access management method according to claim 1, characterized in that: In the step (2) of allocating space from the direct pool, the main memory address space required by the GPU is mapped to the direct pool in an equal linear mapping manner.
3. The GPU main memory access management method according to claim 1, characterized in that: In the step (2) of allocating space from the direct pool, the CPU physical address and the GPU physical address are in a linear offset relationship.
4. The GPU main memory access management method according to claim 1, characterized in that: In the step (8), the mapping relationship between the corresponding GPU physical address and the CPU physical address is rebuilt by configuring the ATU.
5. The GPU main memory access management method according to claim 1, characterized in that: The GMMU page table access method in step (9) is: (a) GPU reads the GPU virtual address; (b) According to the GPU virtual address, query the GMMU page table to calculate the GPU physical address; (c) Check whether the GPU physical address is within the main memory address space. If so, the GPU accesses the corresponding main memory physical address through ATU mapping. Otherwise, the GPU directly accesses the video memory physical address.
6. A remappable GPU main memory access management system, characterized in that: include: Main memory allocator module, GPU main memory address space management module, ATU mapping management module and GMMU management module; The main memory allocator module is used to allocate continuous or non-continuous main memory in the entire main memory space, and control the CPU physical address of the main memory allocation to be in the pass-through pool or the mapping pool according to the pool tag. If the continuous space allocation is successful, the module obtains the CPU physical address, and if the non-continuous space allocation is successful, the module obtains the CPU physical address linked list; The GPU main memory address space management module is used to manage the allocation and release of the GPU physical address of the GPU main memory address space. Specifically, when the continuous space is successfully allocated from the pass-through pool, the module allocates the GPU physical address corresponding to the CPU physical address. At this time, the GPU physical address and the CPU physical address are in a linear offset relationship. If the corresponding GPU physical address has been occupied, it returns to the main memory allocator to re-allocate the continuous space from the pass-through pool and release the previously applied continuous space; when the non-continuous space is successfully allocated from the pass-through pool, the module allocates the GPU physical address linked list corresponding to the CPU physical address linked list. At this time, the GPU physical address linked list and the CPU physical address linked list are in a linear offset relationship. If the corresponding GPU physical address has been occupied, it returns to the main memory allocator to re-allocate the non-continuous space from the pass-through pool and release the previously applied non-continuous space; when the continuous or non-continuous space is successfully allocated from the mapping pool, the module allocates the corresponding GPU physical address from the free space of the GPU main memory address. If the GPU main memory address space management module fails to allocate, it means that the GPU main memory address space has been exhausted and the main memory allocation has failed; The ATU mapping management module is used to maintain a mapping relationship table between GPU physical addresses and CPU physical addresses in the GPU main memory address space. When allocating space from the mapping pool, the ATU mapping management module needs to rebuild the mapping relationship between the corresponding GPU physical addresses and CPU physical addresses. The GMMU management module is used to maintain the GMMU page table and manage the mapping relationship between the GPU virtual address and the GPU physical address.
Citation Information
Patent Citations
Video memory management method and device and computer storage medium
CN110928695A
Memory access method and device, computer equipment and storage medium
CN111338988A