Communication method, device and equipment based on GPU data zero copy and medium

By receiving the read and write instructions from the sender and the shared memory information table, the read and write conditions of the GPU memory block are determined, which solves the problems of low efficiency, high delay and low bandwidth of cross-process GPU data communication, and realizes zero-copy communication of GPU data. and memory management, significantly improving data transfer performance.

CN118708382AInactive Publication Date: 2024-09-27大卓智能科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410852628.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-27
Publication Date
2024-09-27
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

The existing technology lacks effective cross-process GPU data communication technology, resulting in low communication efficiency, high latency, and low bandwidth. Especially in GPU inference scenarios in the fields of autonomous driving and artificial intelligence, CPU memory and performance consumption are large.

Method used

By receiving the read and write instructions from the sender, the target memory block is determined based on the preset shared memory information table, and its read and write conditions are determined to achieve zero-copy communication of GPU data, reduce CPU memory and performance consumption, and improve data communication bandwidth.

Benefits of technology

It implements the GPU data zero-copy communication method and memory management mechanism, reduces latency, increases data communication bandwidth, improves memory management efficiency, and reduces CPU performance consumption.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118708382A
    Figure CN118708382A
Patent Text Reader

Abstract

The invention relates to the technical field of data communication, in particular to a communication method and device based on GPU data zero copy, equipment and a medium, and the method comprises the steps: receiving a read-write instruction of a sender, and determining an identifier of to-be-processed data according to the read-write instruction; based on the identifier of the to-be-processed data, obtaining a target to-be-allocated memory block through a plurality of preset shared memory information tables, and judging whether the target to-be-allocated memory block meets a preset read-write condition or not; and if the target to-be-allocated memory block meets the preset readable and writable condition, writing or reading the to-be-processed data based on the read-write instruction and the target to-be-allocated memory block. Therefore, the problems of low efficiency, high time delay, low bandwidth and the like of GPU data communication among processes are solved, and a GPU data zero-copy communication mode, a GPU memory management mechanism and a message read-write synchronization mechanism of GPU shared memory communication are realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data communication technology, and in particular to a communication method, device, equipment and medium based on GPU data zero copy. Background Art

[0002] In the current field of autonomous driving and artificial intelligence, the basic architecture of software is generally a multi-process communication software architecture, and a large amount of data communication is involved between processes, including data transmission between CPUMemory and GPUMemory, with data transmission bandwidth ranging from Mb / s to Gb / s; cross-process communication requires efficient data communication and reduces the generation of data copies, especially in scenarios involving the extensive use of GPU inference and the exchange of CPU (Central Processing Unit) data and GPU (Graphics Processing Unit) data. Therefore, it is very important to achieve efficient, low-latency, and high-bandwidth cross-process communication.

[0003] Autonomous driving vehicles generally use a lot of sensors, such as lidar, cameras, etc. The data from these sensors is very large and has a high frame rate. Some data is distributed in the address space of the memory, some is distributed continuously in block memory, and some is sparsely and non-continuously. They are also very sensitive to data delays, and data exchange between multiple processes is very frequent. Therefore, in order to reduce frequent data copying, shared memory technology is widely used in autonomous driving and assisted driving systems.

[0004] In the related technology, a zero-copy communication device between multiple processes for sensor data includes read-write synchronization process control, shared memory management and process exit processing mechanism. The shared memory management includes a ring message buffer design and an active mapping relationship design between message numbers and message space addresses. In the process of reading and writing shared memory, no memory copy of any message data will be generated, thereby reducing data copy overhead.

[0005] There is also a related technology that allows only one publisher to have write permission to the second shared memory, while the subscriber only has read permission, thereby improving the security of communication based on the second shared memory and achieving lock-free zero-copy communication. Combined with the feedback notification from the subscriber, it can effectively avoid the problem of the publisher's memory being unable to be released due to subscriber exceptions.

[0006] However, the related technologies mainly focus on the read-write synchronization problem of shared memory, the allocation problem of shared memory, etc., and they mainly focus on the communication of shared memory of CPU Memory. At present, there is a lack of communication technology based on GPU shared memory, which needs to be solved urgently. Summary of the invention

[0007] The present application provides a communication method, apparatus, device and medium based on GPU data zero copy to solve the problems of low efficiency, high latency and low bandwidth of GPU data communication across processes, and realizes a GPU data zero copy communication mode, a GPU memory management mechanism and a message read and write synchronization mechanism for GPU shared memory communication, which greatly reduces the consumption of CPU memory and CPU performance, reduces latency, increases data communication bandwidth and makes memory management more efficient.

[0008] The first aspect of the present application provides a communication method based on GPU data zero copy, comprising the following steps:

[0009] receiving a read / write instruction from a sender, and determining an identifier of the data to be processed according to the read / write instruction;

[0010] Based on the identifier of the data to be processed, a target memory block to be allocated is obtained through a plurality of preset shared memory information tables, and it is determined whether the target memory block to be allocated meets a preset readable and writable condition;

[0011] If the target memory block to be allocated meets the preset readable and writable condition, a write or read operation is performed on the data to be processed based on the read and write instructions and the target memory block to be allocated.

[0012] Optionally, in some embodiments, before receiving the read / write instruction from the sender, the method further includes:

[0013] Dividing the preset shared memory pool to obtain a plurality of memory blocks, an atomic lock corresponding to each memory block, and status information corresponding to each memory block;

[0014] Establishing the plurality of preset shared memory information tables according to the plurality of memory blocks, the atomic lock corresponding to each memory block, and the state information corresponding to each memory block;

[0015] Based on each preset shared memory information table, an identifier corresponding to each memory block is derived.

[0016] Optionally, in some embodiments, after receiving the read / write instruction from the sender, the method further includes:

[0017] Determining the size of the data to be processed;

[0018] The target memory block to be allocated is obtained according to the size of the data to be processed, the identifier of the data to be processed and the identifier corresponding to each memory block.

[0019] Optionally, in some embodiments, the determining whether the target memory block to be allocated satisfies the preset readable and writable condition includes:

[0020] Determine whether the atomic lock state of the target memory block to be allocated is an empty state;

[0021] If the atomic lock state of the target memory block to be allocated is the empty state, it is determined that the target memory block to be allocated meets the preset readable and writable condition, and the atomic lock state of the target memory block to be allocated is updated to a non-empty state.

[0022] Optionally, in some embodiments, after determining whether the atomic lock state of the target memory block to be allocated is the empty state, the method further includes:

[0023] Determine the number of times the target memory block to be allocated is acquired;

[0024] Determine whether the acquisition times reaches a preset threshold;

[0025] If the number of acquisitions reaches the preset threshold, it is determined that the atomic lock state of the target memory block to be allocated is a non-empty state, and an abnormal reminder is issued.

[0026] A second aspect of the present application provides a communication device based on GPU data zero copy, including:

[0027] A receiving module, used to receive a read / write instruction from a sender, and determine an identifier of the data to be processed according to the read / write instruction;

[0028] A judgment module, configured to obtain a target memory block to be allocated through a plurality of preset shared memory information tables based on an identifier of the data to be processed, and to judge whether the target memory block to be allocated satisfies a preset readable and writable condition;

[0029] The communication module is used to write or read the data to be processed based on the read / write instruction and the target memory block to be allocated when the target memory block to be allocated meets the preset readable and writable condition.

[0030] Optionally, in some embodiments, before receiving the read / write instruction from the sender, the receiving module is further configured to:

[0031] Dividing the preset shared memory pool to obtain a plurality of memory blocks, an atomic lock corresponding to each memory block, and status information corresponding to each memory block;

[0032] Establishing the plurality of preset shared memory information tables according to the plurality of memory blocks, the atomic lock corresponding to each memory block, and the state information corresponding to each memory block;

[0033] Based on each preset shared memory information table, an identifier corresponding to each memory block is derived.

[0034] Optionally, in some embodiments, after receiving the read / write instruction from the sender, the receiving module is specifically configured to:

[0035] Determining the size of the data to be processed;

[0036] The target memory block to be allocated is obtained according to the size of the data to be processed, the identifier of the data to be processed and the identifier corresponding to each memory block.

[0037] Optionally, in some embodiments, the judgment module is specifically used to:

[0038] Determine whether the atomic lock state of the target memory block to be allocated is an empty state;

[0039] When the atomic lock state of the target memory block to be allocated is the empty state, it is determined that the target memory block to be allocated meets the preset readable and writable condition, and the atomic lock state of the target memory block to be allocated is updated to a non-empty state.

[0040] Optionally, in some embodiments, after determining whether the atomic lock state of the target memory block to be allocated is the empty state, the determination module is further configured to:

[0041] Determine the number of times the target memory block to be allocated is acquired;

[0042] Determine whether the acquisition times reaches a preset threshold;

[0043] When the number of acquisitions reaches the preset threshold, it is determined that the atomic lock state of the target memory block to be allocated is a non-empty state, and an abnormal reminder is issued.

[0044] The third aspect of the present application provides an electronic device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the communication method based on GPU data zero copy as described in the above embodiment.

[0045] The fourth aspect of the present application provides a computer-readable storage medium having a computer program stored thereon, which is executed by a processor to implement the communication method based on GPU data zero copy as described in the above embodiment.

[0046] Therefore, the present application receives the read-write instruction of the sender, determines the identifier of the data to be processed according to the read-write instruction, obtains the target memory block to be allocated through multiple preset shared memory information tables based on the identifier of the data to be processed, and determines whether the target memory block to be allocated meets the preset readable and writable conditions. If the target memory block to be allocated meets the preset readable and writable conditions, the data to be processed is written or read based on the read-write instruction and the target memory block to be allocated. Thus, the problems of low efficiency, high latency, and low bandwidth of GPU data communication between processes are solved, and the communication mode of GPU data zero copy, GPU memory management mechanism, and message read-write synchronization mechanism of GPU shared memory communication are realized, which greatly reduces the consumption of CPU memory and CPU performance, reduces latency, makes data communication bandwidth higher, and makes memory management more efficient.

[0047] Additional aspects and advantages of the present application will be given in part in the description below, and in part will become apparent from the description below, or will be learned through the practice of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0048] The above and / or additional aspects and advantages of the present application will become apparent and easily understood from the following description of the embodiments in conjunction with the accompanying drawings, in which:

[0049] Figure 1 A schematic diagram of a basic framework of cross-process communication according to a specific embodiment of the present application;

[0050] Figure 2 A flowchart of a communication method based on GPU data zero copy provided according to an embodiment of the present application;

[0051] Figure 3 A schematic diagram of GPU memory management according to a specific embodiment of the present application;

[0052] Figure 4 A schematic diagram of GPU data exchange according to a specific embodiment of the present application;

[0053] Figure 5 A schematic diagram of a memory synchronous writing mechanism according to a specific embodiment of the present application;

[0054] Figure 6 A schematic diagram of a memory synchronous reading mechanism according to a specific embodiment of the present application;

[0055] Figure 7 A schematic diagram of GPU general memory allocation according to a specific embodiment of the present application;

[0056] Figure 8 A schematic diagram of GPU general memory release according to a specific embodiment of the present application;

[0057] Fig. 9 A block diagram of a communication device based on GPU data zero copy according to an embodiment of the present application;

[0058] Fig.10 A block diagram of an electronic device provided according to an embodiment of the present application. DETAILED DESCRIPTION

[0059] Embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to be used to explain the present application, and should not be construed as limiting the present application.

[0060] The following describes the communication method, device, equipment and medium based on GPU data zero copy of the embodiment of the present application with reference to the accompanying drawings. In view of the problems of low efficiency, high latency and low bandwidth of GPU data communication between processes mentioned in the above background technology, the present application provides a communication method based on GPU data zero copy, in which the read and write instructions of the sender are received, and the identifier of the data to be processed is determined according to the read and write instructions; based on the identifier of the data to be processed, the target memory block to be allocated is obtained through multiple preset shared memory information tables, and it is determined whether the target memory block to be allocated meets the preset readable and writable conditions; if the target memory block to be allocated meets the preset readable and writable conditions, the data to be processed is written or read based on the read and write instructions and the target memory block to be allocated. Thus, the problems of low efficiency, high latency and low bandwidth of GPU data communication between processes are solved, and the communication mode of GPU data zero copy, GPU memory management mechanism and message read and write synchronization mechanism of GPU shared memory communication are realized, which greatly reduces the consumption of CPU memory and CPU performance, reduces latency, makes data communication bandwidth higher, and makes memory management more efficient.

[0061] Before introducing the communication method based on GPU data zero copy according to the embodiment of the present application, the overall framework of the cross-process communication according to the embodiment of the present application is first explained.

[0062] It is understandable that there are many ways of cross-process communication, such as shared memory, SOCKET, pipes, message queues, signals, semaphores, etc. Among them, shared memory communication is the most efficient for big data communication, and CPU shared memory is a more commonly used efficient communication method in related technologies, while GPU shared memory is relatively less used.

[0063] Specifically, Figure 1 A schematic diagram of a basic framework of cross-process communication in a specific embodiment of the present application is shown as follows: Figure 1As shown in the figure, shared memory communication is an effective way of cross-process data communication. Memory sharing between processes is generally based on CPU memory sharing. It is necessary to establish a memory pool of sufficient size and a table describing memory allocation information for the memory pool. Then, a shared memory cache queue for data sharing or transmission is established. Data and information are circulated in a table and multiple memory queues respectively.

[0064] The memory sharing management of the GPU memory in the embodiment of the present application is to establish a table of memory information based on the CPU shared memory, then establish a data GPU memory queue for data sharing or transmission, and then export the ShareHandle (memory handle) or FD (File Descriptor) of each GPU memory buffer (cache). However, the acquisition of GPU ShareHandle and FD may vary on chip platforms with different architectures. Therefore, the embodiment of the present application adopts a special communication method to address this difference, which is compatible with both the traditional shared CPU memory information Table and the special UnixDomain communication method. Whether it is a shared CPU memory information table or Unix Domin, they are both shared memory communication methods. In essence, multiple copies of data are not implemented. Data and information are circulated in a Table or Unix Domin and multiple memory queues respectively.

[0065] Next, the process of the communication method based on GPU data zero copy in the embodiment of the present application is introduced.

[0066] Specifically, Figure 2 A flowchart of a communication method based on GPU data zero copy provided in an embodiment of the present application.

[0067] like Figure 2 As shown, the communication method based on GPU data zero copy includes the following steps:

[0068] In step S201, a read / write instruction from a sender is received, and an identifier of the data to be processed is determined according to the read / write instruction.

[0069] It can be understood that the exchange of GPU data includes data reading operations and data writing operations. Therefore, the embodiment of the present application needs to obtain the read and write instructions of the sender, determine whether the current instruction is data reading or data writing, and then obtain the data to be processed in order to perform GPU data communication according to the read and write instructions of the sender.

[0070] Among them, the identifier of the embodiment of the present application includes ShareHandle (memory handle) or FD (file descriptor). Since the embodiment of the present application transmits the handle or file descriptor of the GPU memory block through shared memory to achieve zero-copy communication, after receiving the read and write instructions from the sender, it is necessary to determine the ShareHandle and FD of the data to be processed according to the read and write instructions of the sender.

[0071] Optionally, in some embodiments, before receiving the read and write instructions from the sender, it also includes: dividing the preset shared memory pool to obtain multiple memory blocks, the atomic lock corresponding to each memory block, and the status information corresponding to each memory block; establishing multiple preset shared memory information tables according to the multiple memory blocks, the atomic lock corresponding to each memory block, and the status information corresponding to each memory block; and exporting an identifier corresponding to each memory block based on each preset shared memory information table.

[0072] Among them, the shared memory pool preset in the embodiment of the present application is a pre-allocated shared memory pool block established in advance; the status information corresponding to each memory block in the embodiment of the present application includes the ID (Identity document, account) number of the memory block, the message count, the address of the memory block, the address of the data cache, the serial number of the GPU cache address, etc.; the shared memory information table preset in the embodiment of the present application is stored in the CPU memory, and contains information about the GPU memory buffer, that is, the status information corresponding to each of the above memory blocks. Through the preset shared memory information table, different processes or threads can access this table to understand which GPU memories are available and which are being used.

[0073] Specifically, Figure 3 This is a schematic diagram of GPU memory management according to a specific embodiment of the present application. Figure 3 A shared memory information table dynamically created in an embodiment of the present application is shown, such as Figure 3 As shown, the embodiment of the present application adopts static memory distribution for small messages below 1M, and adopts dynamic mode for large messages, that is, when the sender sends data, the required memory information table and GPU memory cache queue are sequentially constructed. In other words, the embodiment of the present application maintains the allocation information of GPU memory by establishing a CPU memory information table. The CPU memory information table mainly describes the memory queue information of each chunk. Each chunk includes multiple blocks, and the number of blocks of each chunk can be set as needed. Generally speaking, the larger the message data, the fewer the number of allocated blocks. Each block information contains the information of GPU virtual memory and actual physical memory, as well as the FD of GPU memory or the handle of memory.

[0074] For example, Figure 3 As shown, the embodiment of the present application dynamically establishes 8 memory chunks according to the size of the sent data, and the sizes of the memory chunks are 1M, 2M, 4M, 8M, 16M, 32M, 64M and 128M respectively. The description information of each chunk is shown in Table 1, which is the chunk data composition table of the embodiment of the present application.

[0075] Table 1

[0076]

[0077] Each chunk includes multiple blocks. The number of each block can be dynamically configured. The composition of the block is shown in Table 2, which is a block data composition table of an embodiment of the present application.

[0078] Table 2

[0079]

[0080] Therefore, the present application optimizes the transmission and processing of messages of different sizes by sharing a memory information table. This method combines static and dynamic memory allocation to accommodate messages of different sizes, while using a central memory information table to track and manage GPU memory resources. Therefore, the memory management of the embodiment of the present application is more efficient, so that the memory management area is created when needed, and the memory area is not created when it is not applicable.

[0081] Those skilled in the art can understand that shared memory communication is suitable for intra-process and inter-process communication. No matter it is shared memory communication of CPU memory or shared memory communication of GPU memory, it is necessary to establish a pre-allocated shared memory pool block in advance and divide the memory allocation information of each chunk (memory block). Each shared memory information stores the address information of the GPU data queue. By finding the appropriate unused GPU cache memory address through the memory allocation information table, the data is written or read, thus realizing shared memory communication.

[0082] Specifically, the embodiment of the present application needs to pre-allocate a large enough shared memory pool, that is, the preset shared memory pool of the embodiment of the present application, which can be accessed by multiple processes or threads, and the shared memory pool can be part of the physical memory, or it can be mapped to the physical memory through a virtual memory mechanism. The shared memory pool memory is divided into multiple memory chunks, and the size and purpose of each memory chunk can be defined as needed. These memory chunks can be used to store address information of GPU data queues, references or descriptors of GPU memory buffers, etc.

[0083] Furthermore, in order to effectively manage these memory blocks, the embodiment of the present application needs to establish and maintain a shared memory information table, that is, multiple preset shared memory information tables in the embodiment of the present application. The shared memory information table records the status of each memory block (such as whether it has been used, size, location, etc.) and the address information of the GPU data queue, and the shared memory information table usually resides in the CPU memory, but can be accessed by multiple processes or threads.

[0084] It is understandable that on the GPU, virtual memory is allocated to manage data, and virtual memory addresses are mapped to physical memory addresses to ensure that data can be read and written correctly on the GPU. At the same time, the serial number or memory handle (such as ShareHandle or FD) of each physical GPU memory is exported for use in other processes or threads.

[0085] Specifically, Figure 4 A schematic diagram of GPU data exchange according to a specific embodiment of the present application is shown in FIG. Figure 4 As shown in the figure, the allocation of GPU memory is achieved by allocating a series of GPU virtual memory and physical memory, MAP (Memory Mapping) the allocated virtual memory to the allocated physical memory, and exporting the serial number or memory handle of each physical GPU memory; after the data sender allocates the physical memory, it can cyclically use the GPU's physical memory to write and read data; the receiver can sequentially find the appropriate GPU memory address where the data has been written through the memory information table.

[0086] The communication method based on GPU memory sharing proposed in this application expands the application scope of shared memory communication and the conceptual scope of memory sharing. Shared memory communication includes real CPU memory sharing, GPU memory sharing, physical links including shared memory, and also using Unix Domain Socket to transmit the shared handle and file descriptor FD of the CPU and GPU memory.

[0087] Therefore, when the sender sends data, the system will sequentially build the required memory information table and GPU memory cache queue, and the system will dynamically allocate and manage GPU memory resources according to the size and number of messages. In this way, the system can use GPU memory resources more efficiently while avoiding unnecessary memory waste. Therefore, this application can not only improve the efficiency of memory use, but also better adapt to the transmission and processing requirements of messages of different sizes, and data communication has lower latency because zero copy of data is achieved, so that no redundant data copies are generated between producers and multiple consumers.

[0088] In step S202, based on the identifier of the data to be processed, a target memory block to be allocated is obtained through a plurality of preset shared memory information tables, and it is determined whether the target memory block to be allocated meets a preset readable and writable condition.

[0089] Based on the above embodiments, it can be understood that after constructing the CPU memory information table and GPU memory pool for shared memory communication, the embodiments of the present application design a memory synchronization access mechanism based on atomic operations to ensure the security of memory access. That is, when the GPU memory block is being written to data, other read operations are prohibited, and when the GPU memory block is being read from data, other write operations are prohibited.

[0090] The embodiment of the present application takes into account the situation of concurrent reading and writing, and proposes to use atomic_lock to synchronize memory access. When multiple processes or threads try to access the same GPU memory, atomic_lock is used to indicate the state of the memory, ensure data consistency and avoid race conditions.

[0091] Optionally, in some embodiments, determining whether the target memory block to be allocated satisfies a preset readable and writable condition includes: determining whether the atomic lock state of the target memory block to be allocated is an empty state; if the atomic lock state of the target memory block to be allocated is an empty state, determining that the target memory block to be allocated satisfies the preset readable and writable condition, and updating the atomic lock state of the target memory block to be allocated to a non-empty state.

[0092] It can be understood that the atomic lock in the embodiment of the present application is an integer variable used to indicate the usage status of the memory block. In the initial state, when the memory block is not used, the atomic lock atomic_lock is set to 0, and when the memory block is used by a thread or process, the atomic lock atomic_lock is set to -1.

[0093] Specifically, when the sender needs to send data at a certain frequency, it is necessary to obtain free memory addresses from the memory information table and the GPU cache queue at a fixed frequency to write data. The memory synchronization mechanism based on atomic locks in the embodiment of the present application: an atomic lock atomic_lock is designed for each GPU block data memory. When atomic_lock=-1, it means that the memory is in use. When the receiver needs to receive data, it will compete to read the data in a certain block of memory according to the notification information sent by the sender. For a certain block of memory, there may be multiple processes or threads to read, and there may be other processes writing data in this memory block. Therefore, it is necessary to judge that when atomic_lock=-1, it means that the memory block is writing data and cannot be read; when atomic_lock=0, it means that the data in the memory can be read.

[0094] Therefore, the preset readable and writable condition in the embodiment of the present application is atomic lock atomic_lock=0, and the corresponding target memory block to be allocated can be read or written. If the target memory block to be allocated does not meet the preset readable and writable condition, that is, atomic_lock=-1, the target memory block to be allocated is being used and cannot be read or written.

[0095] In step S203, if the target memory block to be allocated meets the preset readable and writable conditions, a write or read operation is performed on the data to be processed based on the read / write instruction and the target memory block to be allocated.

[0096] Optionally, in some embodiments, after determining whether the atomic lock state of the target memory block to be allocated is in an empty state, it also includes: determining the number of times the target memory block to be allocated is acquired; determining whether the number of times the target memory block is acquired reaches a preset threshold; if the number of times the target memory block is acquired reaches the preset threshold, determining that the atomic lock state of the target memory block to be allocated is in a non-empty state, and issuing an abnormal reminder.

[0097] Among them, the embodiment of the present application designs a maximum number of attempts to obtain the target memory block to be allocated, TryMaxCnts, that is, the preset threshold of the embodiment of the present application. If TryMaxCnts attempts are made, then the memory block may be abnormal, and it can be forcibly recovered, the memory information table can be updated, and an abnormal reminder can be issued.

[0098] In some embodiments, Figure 5 This is a schematic diagram of a memory synchronization write mechanism of a specific embodiment of the present application, such as Figure 5 As shown, when the sender needs to send data, it will try to obtain a free memory block, which is completed by checking the value of atomic_lock. If atomic_lock is equal to 0, it means that the memory block is free. The sender can set atomic_lock to -1 and start writing data. After the data is written, the sender will set atomic_lock back to 0, indicating that the memory block is now free and can be used by other threads or processes. The embodiment of the present application sets a maximum number of attempts to obtain (TryMaxCnts) to control the number of attempts to obtain a memory block before giving up. If the sender still cannot obtain a free memory block after trying TryMaxCnts times (that is, atomic_lock is always -1), this may mean that an abnormal situation has occurred (such as a memory leak or other processes occupying all the memory). In this case, the sender can force the memory block to be reclaimed and mark it as available from the memory information table. Then, it can continue to try to obtain other memory blocks to send data.

[0099] In some embodiments, Figure 6 This is a schematic diagram of a memory synchronous reading mechanism of a specific embodiment of the present application, such as Figure 6 As shown, the receiver receives a notification from the sender, and the receiver knows that it needs to read the data in a certain block of memory. At this time, the receiver checks the atomic_lock value of the target memory block. If atomic_lock = -1, it means that the memory is being written, and the receiver needs to wait or try to read other memory blocks; if atomic_lock = 0, it means that the memory is readable, and the receiver can proceed to the next step. The receiver attempts to read the data in the memory block. If the read is successful, the data is processed and the reading process ends. If the read fails (possibly because other processes or threads are trying to read or write at the same time), the receiver will try kMaxTryLockTimes times to read the data. If the data is successfully read within kMaxTryLockTimes attempts, the data is processed and the reading process ends. If it still fails after kMaxTryLockTimes attempts, the read failure information is returned.

[0100] It should be noted that the shared memory lock-free data distribution and access mechanism of the embodiment of the present application makes cross-process data distribution and acquisition more efficient, greatly reducing the consumption of data distribution and acquisition performance by ordinary locks. The release mechanism of the shared memory under abnormal conditions of the embodiment of the present application sets an access count for the abnormal memory. When the number of accesses reaches the access count threshold in an abnormal situation, the abnormal memory will be forcibly released to prevent the leakage of memory space.

[0101] Therefore, this application manages concurrent access to GPU memory in an efficient, flexible and reliable manner through a memory synchronization mechanism based on atomic locks, and meets the needs of various application scenarios by reasonably setting parameters and exception handling strategies. In addition, this application can ensure safe access to GPU memory in a concurrent environment, and at the same time provide a certain fault tolerance mechanism to handle read failures.

[0102] In order to enable those skilled in the art to further understand the communication method based on GPU data zero copy of the present application, the following examples are listed to illustrate the principles of GPU general memory allocation and release in the embodiments of the present application.

[0103] Specifically, Figure 7 This is a schematic diagram of GPU general memory allocation for a specific embodiment of the present application, such as Figure 7As shown, the embodiment of the present application constructs the data cache queue of the GPU by allocating a large GPU memory pool, and constructs GPU memory buffers of different queue sizes of different chunks based on the GPU memory pool. For these GPU cache memory blocks, the Handle or file descriptor of the GPU cache memory block can be exported. When data is transmitted through shared memory, the GPU Handle or file descriptor is transmitted to different processes, and the data receiving process obtains the GPU memory buffer where the real data is located through the GPU Handle and file descriptor, thereby realizing zero-copy communication of GPU data across processes.

[0104] Figure 8 This is a schematic diagram of GPU general memory release according to a specific embodiment of the present application, as shown in FIG. Figure 8 As shown, when all processes exit, the pre-dynamically allocated CPU and GPU memory cache pools need to be released. The release process is exactly the opposite of the allocation process. To avoid redundancy, this application will not go into details here.

[0105] Therefore, based on the CPU shared memory communication in this application, a communication technology based on GPU shared memory is proposed to solve the problems of high efficiency, low latency and high bandwidth of GPU pipeline data communication between processes. At the same time, a GPU-level memory communication mechanism is designed, including GPU shared memory management and GPU shared memory read and write synchronization. It is mainly to solve the problem of efficient data transmission in the fields of artificial intelligence and autonomous driving where a lot of GPU memory data is used, to achieve true zero copy between CPU and GPU, greatly reduce the consumption of CPU memory and CPU performance, and significantly improve the performance of data transmission and processing.

[0106] According to the communication method based on GPU data zero copy proposed in the embodiment of the present application, by receiving the read and write instructions of the sender, and determining the identifier of the data to be processed according to the read and write instructions, based on the identifier of the data to be processed, the target memory block to be allocated is obtained through multiple preset shared memory information tables, and it is determined whether the target memory block to be allocated meets the preset readable and writable conditions. If the target memory block to be allocated meets the preset readable and writable conditions, based on the read and write instructions and the target memory block to be allocated, the data to be processed is written or read. Thus, the problems of low efficiency, high latency, and low bandwidth of GPU data communication between processes are solved, and the communication method of GPU data zero copy, GPU memory management mechanism, and message read and write synchronization mechanism of GPU shared memory communication are realized, which greatly reduces the consumption of CPU memory and CPU performance, reduces latency, makes data communication bandwidth higher, and makes memory management more efficient.

[0107] Next, a communication device based on GPU data zero copy proposed in accordance with an embodiment of the present application is described with reference to the accompanying drawings.

[0108] Fig. 9 It is a block diagram of a communication device based on GPU data zero copy according to an embodiment of the present application.

[0109] like Fig. 9 As shown, the communication device 10 based on GPU data zero copy includes: a receiving module 100, a judging module 200 and a communication module 300.

[0110] Specifically, the receiving module 100 is used to receive the read and write instructions of the sender, and determine the identifier of the data to be processed according to the read and write instructions; the judging module 200 is used to obtain the target memory block to be allocated through multiple preset shared memory information tables based on the identifier of the data to be processed, and judge whether the target memory block to be allocated meets the preset readable and writable conditions; the communication module 300 is used to write or read the data to be processed based on the read and write instructions and the target memory block to be allocated when the target memory block to be allocated meets the preset readable and writable conditions.

[0111] Optionally, in some embodiments, before receiving the read and write instructions from the sender, the receiving module 100 is also used to: divide the preset shared memory pool to obtain multiple memory blocks, the atomic lock corresponding to each memory block, and the status information corresponding to each memory block; establish multiple preset shared memory information tables according to the multiple memory blocks, the atomic lock corresponding to each memory block, and the status information corresponding to each memory block; and export an identifier corresponding to each memory block based on each preset shared memory information table.

[0112] Optionally, in some embodiments, after receiving the read and write instructions from the sender, the receiving module 100 is specifically used to: determine the size of the data to be processed; and obtain the target memory block to be allocated according to the size of the data to be processed, the identifier of the data to be processed and the identifier corresponding to each memory block.

[0113] Optionally, in some embodiments, the judgment module 200 is specifically used to: judge whether the atomic lock state of the target memory block to be allocated is an empty state; when the atomic lock state of the target memory block to be allocated is an empty state, determine that the target memory block to be allocated meets a preset readable and writable condition, and update the atomic lock state of the target memory block to be allocated to a non-empty state.

[0114] Optionally, in some embodiments, after determining whether the atomic lock state of the target memory block to be allocated is in an empty state, the judgment module 200 is also used to: determine the number of times the target memory block to be allocated is acquired; determine whether the number of times the target memory block is acquired reaches a preset threshold; if the number of times the target memory block is acquired reaches the preset threshold, determine that the atomic lock state of the target memory block to be allocated is in a non-empty state, and issue an abnormal reminder.

[0115] It should be noted that the aforementioned explanation of the embodiment of the communication method based on GPU data zero copy is also applicable to the communication device based on GPU data zero copy of this embodiment, and will not be repeated here.

[0116] According to the communication device based on GPU data zero copy proposed in the embodiment of the present application, by receiving the read and write instructions of the sender, and determining the identifier of the data to be processed according to the read and write instructions, based on the identifier of the data to be processed, the target memory block to be allocated is obtained through multiple preset shared memory information tables, and it is determined whether the target memory block to be allocated meets the preset readable and writable conditions. If the target memory block to be allocated meets the preset readable and writable conditions, based on the read and write instructions and the target memory block to be allocated, the data to be processed is written or read. Thus, the problems of low efficiency, high latency, and low bandwidth of GPU data communication between processes are solved, and the communication mode of GPU data zero copy, GPU memory management mechanism, and message read and write synchronization mechanism of GPU shared memory communication are realized, which greatly reduces the consumption of CPU memory and CPU performance, reduces latency, makes data communication bandwidth higher, and makes memory management more efficient.

[0117] Fig.10 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. The electronic device may include:

[0118] A memory 1001 , a processor 1002 , and a computer program stored in the memory 1001 and executable on the processor 1002 .

[0119] When the processor 1002 executes the program, the communication method based on GPU data zero copy provided in the above embodiment is implemented.

[0120] Furthermore, the electronic device further comprises:

[0121] The communication interface 1003 is used for communication between the memory 1001 and the processor 1002 .

[0122] The memory 1001 is used to store computer programs that can be executed on the processor 1002 .

[0123] The memory 1001 may include a high-speed RAM (Random Access Memory) memory, and may also include a non-volatile memory, such as at least one disk memory.

[0124] If the memory 1001, the processor 1002 and the communication interface 1003 are implemented independently, the communication interface 1003, the memory 1001 and the processor 1002 can be connected to each other through a bus and communicate with each other. The bus can be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Fig.10 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0125] Optionally, in a specific implementation, if the memory 1001, the processor 1002 and the communication interface 1003 are integrated on a chip, the memory 1001, the processor 1002 and the communication interface 1003 can communicate with each other through an internal interface.

[0126] The processor 1002 may be a CPU (Central Processing Unit), or an ASIC (Application Specific Integrated Circuit), or one or more integrated circuits configured to implement the embodiments of the present application.

[0127] An embodiment of the present application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the above-mentioned communication method based on GPU data zero copy.

[0128] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. In this specification, the schematic representations of the above terms are not necessarily directed to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or N embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples, without contradiction.

[0129] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include at least one of the features. In the description of this application, "N" means at least two, such as two, three, etc., unless otherwise clearly and specifically defined.

[0130] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, fragment or portion of code comprising one or N executable instructions for implementing the steps of a custom logical function or process, and the scope of the preferred embodiments of the present application includes alternative implementations in which functions may not be performed in the order shown or discussed, including performing functions in a substantially simultaneous manner or in reverse order depending on the functions involved, which should be understood by technicians in the technical field to which the embodiments of the present application belong.

[0131] It should be understood that the various parts of the present application can be implemented by hardware, software, firmware or a combination thereof. In the above embodiment, the N steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one or a combination of multiple of the following technologies known in the art: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array, a field programmable gate array, etc.

[0132] A person skilled in the art may understand that all or part of the steps in the method for implementing the above-mentioned embodiment may be completed by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, which, when executed, includes one or a combination of the steps of the method embodiment.

[0133] Although the embodiments of the present application have been shown and described above, it can be understood that the above embodiments are exemplary and cannot be understood as limitations on the present application. Ordinary technicians in the field can change, modify, replace and modify the above embodiments within the scope of the present application.

Claims

1. A communication method based on GPU data zero copy, characterized in that: The following steps are involved: receiving a read / write instruction from a sender, and determining an identifier of the data to be processed according to the read / write instruction; Based on the identifier of the data to be processed, a target memory block to be allocated is obtained through a plurality of preset shared memory information tables, and it is determined whether the target memory block to be allocated meets a preset readable and writable condition; If the target memory block to be allocated meets the preset readable and writable condition, a write or read operation is performed on the data to be processed based on the read and write instructions and the target memory block to be allocated.

2. The method according to claim 1, characterized in that Before receiving the read / write instruction from the sender, the method further includes: Dividing the preset shared memory pool to obtain a plurality of memory blocks, an atomic lock corresponding to each memory block, and status information corresponding to each memory block; Establishing the plurality of preset shared memory information tables according to the plurality of memory blocks, the atomic lock corresponding to each memory block, and the state information corresponding to each memory block; Based on each preset shared memory information table, an identifier corresponding to each memory block is derived.

3. The method according to claim 2, characterized in that After receiving the read / write instruction from the sender, the method further comprises: Determining the size of the data to be processed; The target memory block to be allocated is obtained according to the size of the data to be processed, the identifier of the data to be processed and the identifier corresponding to each memory block.

4. The method according to claim 2, characterized in that: The determining whether the target memory block to be allocated satisfies the preset readable and writable condition includes: Determine whether the atomic lock state of the target memory block to be allocated is an empty state; If the atomic lock state of the target memory block to be allocated is the empty state, it is determined that the target memory block to be allocated meets the preset readable and writable condition, and the atomic lock state of the target memory block to be allocated is updated to a non-empty state.

5. The method according to claim 4, characterized in that After determining whether the atomic lock state of the target memory block to be allocated is the empty state, the method further includes: Determine the number of times the target memory block to be allocated is acquired; Determine whether the acquisition times reaches a preset threshold; If the number of acquisitions reaches the preset threshold, it is determined that the atomic lock state of the target memory block to be allocated is a non-empty state, and an abnormal reminder is issued.

6. A communication device based on GPU data zero copy, characterized in that: include: A receiving module, used to receive a read / write instruction from a sender, and determine an identifier of the data to be processed according to the read / write instruction; A judgment module, configured to obtain a target memory block to be allocated through a plurality of preset shared memory information tables based on an identifier of the data to be processed, and to judge whether the target memory block to be allocated satisfies a preset readable and writable condition; The communication module is used to write or read the data to be processed based on the read / write instruction and the target memory block to be allocated when the target memory block to be allocated meets the preset readable and writable condition.

7. The device according to claim 6, characterized in that Before receiving the read / write instruction from the sender, the receiving module is further configured to: Dividing the preset shared memory pool to obtain a plurality of memory blocks, an atomic lock corresponding to each memory block, and status information corresponding to each memory block; Establishing the plurality of preset shared memory information tables according to the plurality of memory blocks, the atomic lock corresponding to each memory block, and the state information corresponding to each memory block; Based on each preset shared memory information table, an identifier corresponding to each memory block is derived.

8. The device according to claim 7, characterized in that After receiving the read / write instruction from the sender, the receiving module is specifically configured to: Determining the size of the data to be processed; The target memory block to be allocated is obtained according to the size of the data to be processed, the identifier of the data to be processed and the identifier corresponding to each memory block.

9. An electronic device, characterized in that: include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the GPU data zero-copy communication method according to any one of claims 1 to 5.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: The program is executed by a processor to implement the communication method based on GPU data zero copy as described in any one of claims 1 to 5.