Data transmission method and device, electronic equipment and storage medium
By creating a message transmission queue between the CPU and GPU, the problem of low data transmission efficiency between the CPU and GPU is solved, and efficient and stable data transmission is achieved to adapt to data transmission requirements in different scenarios.
Patent Information
- Application Number
- CN202510514609.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-23
- Publication Date
- 2025-09-19
AI Technical Summary
The existing data transmission efficiency between CPU and GPU is low, mainly because the implementation method based on programming framework and dedicated interface requires multiple data scheduling, and different programming frameworks are not universal, resulting in low transmission efficiency.
A message transmission queue is created between the CPU and GPU, including the first subqueue and the second subqueue, for one-way data transmission. Efficient data transmission is achieved through data acquisition and reception functions. Index pointers are used to store data, and the number of queues is dynamically adjusted to optimize the transmission rate.
It improves the data transmission efficiency between the CPU and GPU, alleviates the processing speed difference, avoids data transmission congestion, improves communication stability and flexibility, and adapts to data transmission needs in different scenarios.
Smart Images

Figure CN120670181A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a data transmission method, device, electronic device and storage medium. Background Art
[0002] In existing heterogeneous computing architectures, the Central Processing Unit (CPU) and Graphics Processing Unit (GPU) each have their own memory space. During task processing, especially for large AI models, data transfer between the CPU and GPU is often required.
[0003] Existing data transfer processes between CPUs and GPUs are typically based on programming frameworks and dedicated interfaces. However, these approaches require multiple data dispatches, resulting in a complex implementation process and incompatibility between different programming frameworks, leading to low data transfer efficiency between the CPU and GPU. Summary of the Invention
[0004] The present invention provides a data transmission method, device, electronic device and storage medium for improving the data transmission efficiency between a CPU and a GPU.
[0005] The present invention provides a data transmission method, comprising the following steps: receiving a data transmission task and creating a message transmission queue for the data transmission task between the CPU and the GPU, wherein the data transmission task is used for data transmission between the CPU and the GPU; Determining a data receiver and a data acquirer of the data transmission task based on a data transmission direction of the data transmission task; Calling a data acquisition function so that the data acquirer acquires the data to be transmitted corresponding to the data transmission task from the memory space of the data acquirer, and stores the data to be transmitted in the message transmission queue; The data receiving function is called so that the data receiving party obtains the data to be transmitted from the message transmission queue and transmits the data to be transmitted to the memory space of the data receiving party.
[0006] According to a data transmission method provided by the present invention, the message transmission queue includes a first sub-queue between the CPU and the GPU and a second sub-queue between the CPU and the GPU, the first sub-queue is used for unidirectional data transmission from the CPU to the GPU, and the second sub-queue is used for unidirectional data transmission from the GPU to the CPU.
[0007] According to a data transmission method provided by the present invention, the data acquisition function includes a GPU data acquisition function and a CPU data acquisition function, the data receiving function includes a GPU data receiving function and a CPU data receiving function, and after determining the data receiving party and the data acquiring party of the data transmission task based on the data transmission direction of the data transmission task, the method further includes: When it is determined that the data transmission direction is from the CPU to the GPU, a CPU data acquisition function is called to enable the CPU to acquire the data to be transmitted corresponding to the data transmission task from the memory space of the CPU and store the data to be transmitted in the first subqueue; and a GPU data reception function is called to enable the GPU to acquire the data to be transmitted from the first subqueue and transfer the data to be transmitted to the memory space of the GPU. When it is determined that the data transmission direction is from the GPU to the CPU, the GPU data acquisition function is called to obtain the data to be transmitted corresponding to the data transmission task from the memory space of the GPU, and the data to be transmitted is stored in the second sub-queue; the CPU data receiving function is called to obtain the data to be transmitted from the second sub-queue, and the data to be transmitted is transferred to the memory space of the CPU.
[0008] According to a data transmission method provided by the present invention, storing the data to be transmitted in the message transmission queue includes: The index pointer of the data to be transmitted is stored in the message transmission queue, and the index pointer is used to point to the memory space where the data to be transmitted is located.
[0009] A data transmission method provided by the present invention further includes: When the data to be transmitted is transmitted from the data acquirer to the data receiver, determining a transmission rate of the data to be transmitted based on a performance indicator of the message transmission queue; Based on the transmission rate, it is determined whether to add a message transmission queue for the data to be transmitted.
[0010] According to a data transmission method provided by the present invention, determining whether to add a new message transmission queue for the data to be transmitted based on the transmission rate further includes: When it is determined that the transmission rate is less than a preset transmission rate threshold, determining the number of message transmission queues for the data to be transmitted based on the data volume of the data to be transmitted and the transmission rate of the message transmission queue; Based on the number of message transmission queues, a new message transmission queue is added between the CPU and the GPU.
[0011] According to a data transmission method provided by the present invention, the data receiving function is determined based on the queue ID of the message transmission queue, the address for obtaining data, and the data length; The data acquisition function is determined by the queue ID of the message transmission queue, the address of the returned data, and the length of the returned data.
[0012] According to a data transmission method provided by the present invention, the first sub-queue includes a first daemon thread, and the second sub-queue includes a second daemon thread; The first daemon thread is used to manage a data transmission process from the CPU to the GPU, and the second daemon thread is used to manage a data transmission process from the GPU to the CPU.
[0013] The present invention also provides a data transmission device, comprising the following modules: a queue creation module, configured to receive a data transmission task and create a message transmission queue for the data transmission task between the CPU and the GPU, wherein the data transmission task is used for data transmission between the CPU and the GPU; A transmission determination module, configured to determine a data recipient and a data acquirer of the data transmission task based on a data transmission direction of the data transmission task; A data acquisition module, configured to call a data acquisition function so that the data acquirer acquires the data to be transmitted corresponding to the data transmission task from the memory space of the data acquirer, and stores the data to be transmitted in the message transmission queue; The data sending module is used to call the data receiving function so that the data receiving party obtains the data to be transmitted from the message transmission queue and transmits the data to be transmitted to the memory space of the data receiving party.
[0014] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and running on the processor, wherein when the processor executes the program, any of the above-mentioned data transmission methods is implemented.
[0015] The data transmission method, device, electronic device, and storage medium provided by the present invention provide an efficient intermediate storage and buffering mechanism by creating a message transmission queue for data transmission tasks between the CPU and GPU. This mechanism can mitigate the difference in CPU and GPU processing speeds and avoid data congestion during data transmission. Based on the message transmission queue between the CPU and GPU, communication issues between the CPU and GPU can be resolved in an efficient manner. The created message transmission queue can shield the differences in underlying architectures and improve the data transmission efficiency between the CPU and GPU. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the technical solutions in the present invention or the prior art, a brief introduction is given below to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0017] Figure 1 It is a flow chart of the data transmission method provided by the present invention.
[0018] Figure 2 It is a structural diagram of the message transmission queue provided by the present invention.
[0019] Figure 3 It is a structural diagram of the data transmission device provided by the present invention.
[0020] Figure 4 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0021] To make the objectives, technical solutions, and advantages of the present invention more clear, the technical solutions of the present invention will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the embodiments described are only some of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts shall fall within the scope of protection of the present invention.
[0022] Among related methods, large AI models have strict requirements for communication between the CPU and GPU, mainly because these large AI models usually need to process large amounts of data and complex computing tasks. The following are several key points in the communication process: High bandwidth requirements: Since large AI models involve large amounts of data transmission, including model weights, activation values, and gradients, high communication bandwidth is required between the CPU and GPU to ensure that data can be transmitted quickly between the two.
[0023] Low latency: To maintain efficient training and inference speeds, communication latency must be as low as possible. Any delay will affect the response time of the entire system, which is especially important in real-time applications.
[0024] Efficient data synchronization mechanism: In a parallel computing environment, it is very important to ensure that all processors (whether CPU or GPU) can access the latest data. This requires an effective synchronization mechanism to coordinate operations between different computing units.
[0025] Support for massively parallel computing: Large AI models often require highly parallel tasks such as matrix operations. This requires that the communication between the CPU and GPU be not only fast but also able to effectively support multiple computing units working simultaneously.
[0026] Memory consistency: In heterogeneous computing architectures, the CPU and GPU may have their own memory spaces. To effectively collaborate, the system needs to provide some form of memory consistency or shared memory solution so that programming does not have to worry about data consistency issues.
[0027] GPUs typically perform computing tasks by being directly programmed through specialized interfaces such as the Compute Unified Device Architecture (CUDA) and OpenCL. CUDA provides a unified memory model and streaming multiprocessor management capabilities, allowing developers to more efficiently share data and schedule tasks between the CPU and GPU. ROCm (Radeon OpenCompute) tools are similar to CUDA, providing developers with an open software stack for accessing GPU resources, including support for cross-device communication. However, the programming frameworks and specialized interface implementations provided by CUDA and OpenCL are complex and differ significantly from conventional programming methods. CUDA and OpenCL also differ significantly in that CUDA can only be used with GPUs from specific manufacturers, and neither CUDA nor OpenCL provides a simple and efficient method for communication between the CPU and GPU, resulting in inefficient data transfer between the CPU and GPU.
[0028] In view of the defects in the related methods, the present invention provides a data transmission method. Figure 1 It is a flow chart of the data transmission method provided by the present invention, such as Figure 1 As shown, the method includes the following: Step 110: Receive a data transmission task and create a message transmission queue for the data transmission task between the CPU and the GPU, wherein the data transmission task is used for data transmission between the CPU and the GPU. Step 120: determining a data receiver and a data acquirer of the data transmission task based on the data transmission direction of the data transmission task; Step 130: calling a data acquisition function so that the data acquirer acquires the data to be transmitted corresponding to the data transmission task from the memory space of the data acquirer, and stores the data to be transmitted in the message transmission queue; Step 140 : calling a data receiving function so that the data receiving party obtains the data to be transmitted from the message transmission queue and transmits the data to be transmitted to the memory space of the data receiving party.
[0029] The data transmission method provided by the present invention may be performed by an electronic device, a component thereof, an integrated circuit, or a chip. The electronic device may be a mobile electronic device or a non-mobile electronic device. For example, the mobile electronic device may be a mobile phone, tablet computer, laptop computer, PDA, ultra-mobile personal computer (UMPC), netbook, or personal digital assistant (PDA), while the non-mobile electronic device may be a server, network attached storage (NAS), or personal computer (PC), etc., although the present invention does not impose any specific limitations thereon.
[0030] The following takes a computer executing the data transmission method provided by the present invention as an example to describe the technical solution of the present invention in detail.
[0031] In step 110 , a data transmission task is received, and a message transmission queue of the data transmission task is created between the CPU and the GPU. The data transmission task is used for data transmission between the CPU and the GPU.
[0032] It's important to note that in computing systems, the CPU and GPU often need to work together to complete complex computing tasks. Data transfer tasks involve transferring data between the CPU and GPU. This can involve transferring data from the CPU's memory space to the GPU's memory space, or vice versa.
[0033] After receiving a data transfer task, a message queue is created between the CPU and GPU for data transmission. The message queue is an intermediate storage structure used to temporarily store data to be transmitted. It acts like a buffer, ensuring that data is not lost during transmission and that it is processed in a specific order.
[0034] In step 120, based on the data transmission direction of the data transmission task, a data receiver and a data acquirer of the data transmission task are determined.
[0035] Specifically, based on the analysis of the data transmission task, the data transmission direction of the data transmission task can be determined, which can be data transmission from the CPU to the GPU or data transmission from the GPU to the CPU.
[0036] In step 130, a data acquisition function is called so that the data acquirer acquires the data to be transmitted corresponding to the data transmission task from the memory space of the data acquirer and stores the data to be transmitted in the message transmission queue.
[0037] The function of the data acquisition function is to read the data to be transmitted related to the current data transmission task from the memory space of the data acquisition party (that is, the source of the data, specifically the CPU or GPU) and store it in the message transmission queue.
[0038] Specifically, the data acquisition function first needs to locate the data location in the data acquisition party's memory. Then, it reads the data from the source memory and formats it into a format suitable for storage in the message transmission queue.
[0039] The data retrieval function writes the data to be transmitted to the message transmission queue and may also update queue status information, such as the queue length or the data identifier, so that subsequent data recipients can correctly identify and read the data. Data storage in the message transmission queue can be implemented using first-in, first-out logic.
[0040] Optionally, the data acquisition function can also implement performance optimizations and synchronization mechanisms. To improve data transmission efficiency, asynchronous reading can be used, allowing the data acquirer to continue performing other tasks while reading data. Furthermore, to prevent race conditions or data corruption during data transmission, the data acquisition function may use locks or other synchronization mechanisms to ensure that data reading and writing operations are safe. Through these measures, the data acquisition function can efficiently complete the data transmission task from the data acquirer's memory to the message transmission queue, preparing for subsequent data reception and processing.
[0041] In step 140, a data receiving function is called so that the data receiver obtains the data to be transmitted from the message transmission queue and transmits the data to be transmitted to the memory space of the data receiver.
[0042] Calling the data receiving function transfers the pending data stored in the message transmission queue to the memory space of the data receiver (which can be the CPU or GPU). The data receiving function checks the status of the message transmission queue, confirms that there is pending data in the message transmission queue, and retrieves the pending data from the message transmission queue.
[0043] After the data receive function executes, the data receiver reads data from the queue and transfers it to its memory space. During this process, the data receive function must ensure data integrity and consistency to avoid data loss or corruption during transmission. To achieve efficient transmission, the data receive function may utilize DMA (Direct Memory Access) technology, allowing data to be transferred directly between memory, bypassing the CPU, thereby reducing CPU load and increasing transmission speed.
[0044] To ensure the correctness and stability of data transmission, the data receiving function can employ synchronization mechanisms, such as semaphores or mutexes, to manage access to the message transmission queue, preventing conflicts caused by multiple recipients simultaneously reading the same data. Once the data has been successfully transferred to the recipient's memory space, the data receiving function can update the queue status, delete processed data entries, or update the queue index to ensure normal operation of the queue.
[0045] The data transmission method provided by this invention provides an efficient intermediate storage and buffering mechanism by creating a message transmission queue for data transmission tasks between the CPU and GPU. This mechanism can mitigate the difference in CPU and GPU processing speeds and avoid data congestion during data transmission. Based on the message transmission queue between the CPU and GPU, communication issues between the CPU and GPU can be solved in an efficient manner. The created message transmission queue can shield the differences in underlying architectures and improve data transmission efficiency between the CPU and GPU.
[0046] In one embodiment, the message transmission queue includes a first subqueue between the CPU and the GPU and a second subqueue between the CPU and the GPU, the first subqueue being used for unidirectional data transmission from the CPU to the GPU, and the second subqueue being used for unidirectional data transmission from the GPU to the CPU.
[0047] The message transmission queue optimizes data transmission efficiency between the CPU and GPU by setting up two independent sub-queues. The first sub-queue is dedicated to unidirectional data transmission from the CPU to the GPU, while the second sub-queue is used for unidirectional data transmission from the GPU to the CPU.
[0048] The two independent sub-queues achieve bidirectional separation of data transmission, avoiding conflicts and data interference that may occur during bidirectional transmission, thereby improving the stability and efficiency of data transmission. At the same time, the use of unidirectional queues makes the direction of data transmission clear, facilitating independent optimization and management of data transmission in each direction. For example, the buffering strategy of the first sub-queue can be optimized according to the transmission requirements from the CPU to the GPU, while the synchronization mechanism of the second sub-queue can be adjusted according to the transmission characteristics from the GPU to the CPU. This separate queue design not only improves the efficiency of data transmission, but also enhances scalability and flexibility, and can better adapt to the data transmission needs in different scenarios.
[0049] In one embodiment, the data acquisition function includes a GPU data acquisition function and a CPU data acquisition function, and the data receiving function includes a GPU data receiving function and a CPU data receiving function. After determining the data transmission direction of the data transmission task and the data recipient and the data acquirer of the data transmission task, the function further includes: when it is determined that the data transmission direction is from the CPU to the GPU, calling the CPU data acquisition function so that the CPU obtains the data to be transmitted corresponding to the data transmission task from the memory space of the CPU, and stores the data to be transmitted in the first sub-queue; calling the GPU data receiving function so that the GPU obtains the data to be transmitted from the first sub-queue, and transfers the data to be transmitted to the memory space of the GPU; when it is determined that the data transmission direction is from the GPU to the CPU, calling the GPU data acquisition function, obtaining the data to be transmitted corresponding to the data transmission task from the memory space of the GPU, and storing the data to be transmitted in the second sub-queue; calling the CPU data receiving function, obtaining the data to be transmitted from the second sub-queue, and transferring the data to be transmitted to the memory space of the CPU.
[0050] During data transmission between the CPU and GPU, efficient and conflict-free data transmission can be achieved by clarifying the data transmission direction and utilizing two independent sub-queues (the first sub-queue and the second sub-queue).
[0051] When data transfer is from the CPU to the GPU, the CPU data acquisition function is called to cause the CPU to read the data to be transferred from its memory space and store this data in the first subqueue dedicated to CPU-to-GPU transfers. Subsequently, the GPU data reception function is called to cause the GPU to read this data from the first subqueue and transfer it to the GPU's memory space.
[0052] Conversely, when the data transfer direction is from the GPU to the CPU, the GPU data acquisition function is called to read the data to be transferred from the GPU memory and store it in the second subqueue dedicated to GPU-to-CPU transfers. Next, the CPU data reception function is called to read the data from the second subqueue and transfer it to the CPU memory space.
[0053] This separate queue design not only avoids conflicts and interference during bidirectional transmission, but also makes data processing in each transmission direction more independent and efficient, further optimizing the collaborative working performance between the CPU and GPU.
[0054] Among them, the structural diagram of the constructed message transmission queue can be as follows Figure 2 The structural diagram of the message transmission queue provided by the present invention is shown as follows.
[0055] This message transfer queue is different from other message queues commonly used by the CPU. It contains two virtual sub-queues. The two virtual sub-queues are directional. The first sub-queue is used by the CPU to transfer data to the GPU, and the second sub-queue is used by the GPU to transfer data to the CPU.
[0056] The queue has methods corresponding to four basic functions: the CPU data acquisition function putMq is used by the CPU to acquire and store data in the queue; the CPU data receiving function getMq is used by the CPU to obtain data from the queue; the GPU data acquisition function putMqG is used by the GPU to acquire and store data in the queue; the GPU receiving acquisition function getMqG is used by the GPU to obtain data from the queue; the methods putMq and getMqG are a pair of operations, and the methods putMqG and getMq are another pair of operations.
[0057] This message queue can run on both CUDA and OpenCL architectures, but internally, the queue shields these architecture differences. The four methods exposed to the public share the same names and parameters. This message queue is available as a C dynamic library. The four basic queue methods are all in C and can be directly called by C / C++ applications. Other programming languages, such as Java, Python, and Go, can also call them as dynamic libraries.
[0058] In one embodiment, storing the data to be transmitted in the message transmission queue includes: storing an index pointer of the data to be transmitted in the message queue.
[0059] When storing data to be transmitted in a message transmission queue, using an index pointer to store the data instead of directly storing the data itself can significantly improve the efficiency and flexibility of data transmission.
[0060] Specifically, when a data acquirer (such as a CPU or GPU) is ready to transfer data to a message queue, it calculates or obtains the index pointer (i.e., the address or location identifier) of the data to be transferred in memory. This index pointer is then stored in the message queue instead of directly copying the data itself to the queue.
[0061] This approach avoids duplicate data copies during storage, reducing memory usage and data transmission overhead. This significantly improves performance, especially for large data transfers. Furthermore, through index pointers, data recipients can directly access the original data when needed, enabling fast and efficient data access and processing. This not only optimizes data transfer efficiency but also enhances overall performance and responsiveness.
[0062] In one embodiment, the method further includes: when the data to be transmitted is transmitted from the data acquirer to the data receiver, determining the transmission rate of the data to be transmitted based on the performance indicator of the message transmission queue; and determining whether to add a new message transmission queue for the data to be transmitted based on the transmission rate.
[0063] When transmitting data, the performance metrics of the message transmission queue (such as queue length, latency, and throughput) are crucial for optimizing data transmission efficiency. By monitoring these performance metrics, the transmission rate of the data to be transmitted can be dynamically determined.
[0064] If the performance metrics of the current queue indicate a low transmission rate (e.g., a long queue length or high latency), this may indicate that the queue is overloaded and cannot efficiently handle the newly added tasks. In this case, based on the transmission rate evaluation results, you can decide whether to create a new independent message transmission queue for the data to be transmitted.
[0065] The addition of queues can distribute the load and increase the parallelism of data transmission, thereby improving overall transmission efficiency. This dynamic adjustment mechanism can flexibly optimize the data transmission process based on real-time performance and task requirements to ensure efficient operation.
[0066] In one embodiment, based on the transmission rate, determining whether to add a new message transmission queue for the data to be transmitted further includes: when it is determined that the transmission rate is less than a preset transmission rate threshold, determining the number of message transmission queues for the data to be transmitted based on the data volume of the data to be transmitted and the transmission rate of the message transmission queue; based on the number of message transmission queues, adding a new message transmission queue between the CPU and the GPU.
[0067] If the transmission rate of the data to be transmitted is determined to be less than the preset transmission rate threshold, the system can further analyze the amount of data to be transmitted and the actual transmission rates of existing message transmission queues to calculate the number of new message transmission queues that need to be added. This process is based on a comprehensive assessment of current transmission efficiency and data transmission needs.
[0068] If the existing queues' transmission rates are insufficient to efficiently transmit large amounts of data, a corresponding number of message transmission queues will be added between the CPU and GPU based on the calculation results. These additional queues distribute the data transmission load, increase parallel processing capabilities, and thus improve overall data transmission efficiency, ensuring efficient operation even in the face of high-volume data transmission tasks.
[0069] In one embodiment, the data receiving function is determined based on the queue ID of the message transmission queue, the address of obtaining data and the data length; the data obtaining function is determined by the queue ID of the message transmission queue, the address of returning data and the length of returning data.
[0070] During the data transmission process between the CPU and GPU, the calling and execution of the data receiving function and the data acquisition function depend on several key parameters. These parameters ensure that the data can be accurately transmitted between the message transmission queue and the memory.
[0071] The data receiving function needs to determine which queue to retrieve data from based on the message transmission queue ID. It also needs to specify the data address (i.e., the starting position of the data in the queue) and the data length (i.e., the amount of data to be transferred). These parameters together determine the specific location and range of data that the data receiving function reads from the message transmission queue and ensure that the data is correctly transferred to the target memory space.
[0072] The data retrieval function also relies on the message transfer queue ID to determine the target queue for data storage. It also requires specifying the address of the return data (i.e., the starting location of the data in the source memory) and the length of the return data. These parameters enable the data retrieval function to accurately read the required data from the source memory and store it in the message transfer queue.
[0073] By precisely specifying these parameters, the data receiving and retrieval functions can efficiently complete data read and write operations, ensuring data integrity and consistency during transmission. This precise parameter-based control mechanism improves data transmission reliability and allows for flexible adjustment of data transmission details based on specific needs in different data transmission tasks.
[0074] In one embodiment, the first sub-queue includes a first daemon thread, and the second sub-queue includes a second daemon thread; the first daemon thread is used to manage the data transmission process from the CPU to the GPU, and the second daemon thread is used to manage the data transmission process from the GPU to the CPU.
[0075] A first daemon thread in the first subqueue and a second daemon thread in the second subqueue are configured to manage the data transmission process. For example, they update queue status information, queue length, or data identifiers so that subsequent data recipients can correctly identify and read the data. Furthermore, they can also update queue status, delete processed data entries, or update queue indexes to ensure normal operation of the queues.
[0076] The data transmission device provided by the present invention is described below. The data transmission device described below and the data transmission method described above can be referenced to each other.
[0077] like Figure 3 As shown, the device includes: A queue creation module 310 is configured to receive a data transmission task and create a message transmission queue for the data transmission task between the CPU and the GPU, wherein the data transmission task is used for data transmission between the CPU and the GPU; A transmission determination module 320 is configured to determine a data receiver and a data acquirer of the data transmission task based on a data transmission direction of the data transmission task; A data acquisition module 330 is configured to call a data acquisition function so that the data acquirer acquires the data to be transmitted corresponding to the data transmission task from the memory space of the data acquirer and stores the data to be transmitted in the message transmission queue; The data sending module 340 is configured to call a data receiving function so that the data receiving party obtains the data to be transmitted from the message transmission queue and transmits the data to be transmitted to the memory space of the data receiving party.
[0078] The data transmission device provided by this invention provides an efficient intermediate storage and buffering mechanism by creating a message transmission queue for data transmission tasks between the CPU and GPU. This mechanism can mitigate the difference in CPU and GPU processing speeds and avoid data congestion during data transmission. Based on the message transmission queue between the CPU and GPU, communication issues between the CPU and GPU can be solved in an efficient manner. The created message transmission queue can shield the differences in underlying architectures and improve data transmission efficiency between the CPU and GPU.
[0079] In one embodiment, the queue creation module 310 is specifically configured to: Determine that the message transmission queue includes a first subqueue between the CPU and the GPU and a second subqueue between the CPU and the GPU, the first subqueue is used for unidirectional data transmission from the CPU to the GPU, and the second subqueue is used for unidirectional data transmission from the GPU to the CPU.
[0080] In one embodiment, the transmission determination module 320 is specifically configured to: The data acquisition function includes a GPU data acquisition function and a CPU data acquisition function, and the data receiving function includes a GPU data receiving function and a CPU data receiving function. After determining the data receiving party and the data acquiring party of the data transmission task based on the data transmission direction of the data transmission task, the method further includes: When it is determined that the data transmission direction is from the CPU to the GPU, a CPU data acquisition function is called to enable the CPU to acquire the data to be transmitted corresponding to the data transmission task from the memory space of the CPU and store the data to be transmitted in the first subqueue; and a GPU data reception function is called to enable the GPU to acquire the data to be transmitted from the first subqueue and transfer the data to be transmitted to the memory space of the GPU. When it is determined that the data transmission direction is from the GPU to the CPU, the GPU data acquisition function is called to obtain the data to be transmitted corresponding to the data transmission task from the memory space of the GPU, and the data to be transmitted is stored in the second sub-queue; the CPU data receiving function is called to obtain the data to be transmitted from the second sub-queue, and the data to be transmitted is transferred to the memory space of the CPU.
[0081] In one embodiment, the data acquisition module 330 is specifically configured to: Storing the data to be transmitted in the message transmission queue includes: The index pointer of the data to be transmitted is stored in the message transmission queue, and the index pointer is used to point to the memory space where the data to be transmitted is located.
[0082] In one embodiment, the queue creation module 310 is further configured to: When the data to be transmitted is transmitted from the data acquirer to the data receiver, determining a transmission rate of the data to be transmitted based on a performance indicator of the message transmission queue; Based on the transmission rate, it is determined whether to add a message transmission queue for the data to be transmitted.
[0083] In one embodiment, the queue creation module 310 is further configured to: The determining, based on the transmission rate, whether to add a new message transmission queue for the data to be transmitted further includes: When it is determined that the transmission rate is less than a preset transmission rate threshold, determining the number of message transmission queues for the data to be transmitted based on the data volume of the data to be transmitted and the transmission rate of the message transmission queue; Based on the number of message transmission queues, a new message transmission queue is added between the CPU and the GPU.
[0084] In one embodiment, the queue creation module 310 is further configured to: The data receiving function is determined based on the queue ID of the message transmission queue, the address of obtaining data and the data length; The data acquisition function is determined by the queue ID of the message transmission queue, the address of the returned data, and the length of the returned data.
[0085] In one embodiment, the queue creation module 310 is further configured to: Determining that the first sub-queue includes a first daemon thread, and the second sub-queue includes a second daemon thread; The first daemon thread is used to manage a data transmission process from the CPU to the GPU, and the second daemon thread is used to manage a data transmission process from the GPU to the CPU.
[0086] Figure 4 An example of a physical structure diagram of an electronic device is shown below. Figure 4 As shown, the electronic device may include: a processor 410, a communication interface 420, a memory 430, and a communication bus 440, wherein the processor 410, the communication interface 420, and the memory 430 communicate with each other via the communication bus 440. The processor 410 may call logic instructions in the memory 430 to execute a data transmission method, which includes: receiving a data transmission task and creating a message transmission queue for the data transmission task between the CPU and the GPU, wherein the data transmission task is used for data transmission between the CPU and the GPU; Determining a data receiver and a data acquirer of the data transmission task based on a data transmission direction of the data transmission task; Calling a data acquisition function so that the data acquirer acquires the data to be transmitted corresponding to the data transmission task from the memory space of the data acquirer, and stores the data to be transmitted in the message transmission queue; The data receiving function is called so that the data receiving party obtains the data to be transmitted from the message transmission queue and transmits the data to be transmitted to the memory space of the data receiving party.
[0087] Furthermore, the logic instructions in the aforementioned memory 430 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the portion that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product, stored in a storage medium, includes instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the methods described in various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as a USB flash drive, a mobile hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0088] On the other hand, the present invention further provides a computer program product, comprising a computer program, which may be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the data transmission method provided by each of the above methods, the method comprising: receiving a data transmission task, and creating a message transmission queue for the data transmission task between a CPU and a GPU, wherein the data transmission task is used for data transmission between the CPU and the GPU; Determining a data receiver and a data acquirer of the data transmission task based on a data transmission direction of the data transmission task; Calling a data acquisition function so that the data acquirer acquires the data to be transmitted corresponding to the data transmission task from the memory space of the data acquirer, and stores the data to be transmitted in the message transmission queue; The data receiving function is called so that the data receiving party obtains the data to be transmitted from the message transmission queue and transmits the data to be transmitted to the memory space of the data receiving party.
[0089] In another aspect, the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the computer program is implemented to perform the data transmission method provided by the above methods, the method comprising: receiving a data transmission task and creating a message transmission queue for the data transmission task between a CPU and a GPU, wherein the data transmission task is used for data transmission between the CPU and the GPU; Determining a data receiver and a data acquirer of the data transmission task based on a data transmission direction of the data transmission task; Calling a data acquisition function so that the data acquirer acquires the data to be transmitted corresponding to the data transmission task from the memory space of the data acquirer, and stores the data to be transmitted in the message transmission queue; The data receiving function is called so that the data receiving party obtains the data to be transmitted from the message transmission queue and transmits the data to be transmitted to the memory space of the data receiving party.
[0090] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, i.e., they may be located in one location or distributed across multiple network units. Some or all of the modules may be selected based on actual needs to achieve the objectives of the present embodiment. Persons of ordinary skill in the art will be able to understand and implement the present invention without inventive effort.
[0091] Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented using software plus a necessary general-purpose hardware platform, or of course, hardware. Based on this understanding, the essence of the above technical solution, or the portion that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a magnetic disk, or an optical disk, and includes a number of instructions for causing a computer device (such as a personal computer, server, or network device) to execute the methods described in each embodiment or certain portions of the embodiments.
[0092] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present invention.
Claims
1. A data transmission method, characterized in that: include: receiving a data transmission task and creating a message transmission queue for the data transmission task between the CPU and the GPU, wherein the data transmission task is used for data transmission between the CPU and the GPU; Determining a data receiver and a data acquirer of the data transmission task based on a data transmission direction of the data transmission task; Calling a data acquisition function so that the data acquirer acquires the data to be transmitted corresponding to the data transmission task from the memory space of the data acquirer, and stores the data to be transmitted in the message transmission queue; The data receiving function is called so that the data receiving party obtains the data to be transmitted from the message transmission queue and transmits the data to be transmitted to the memory space of the data receiving party.
2. The data transmission method according to claim 1, wherein: The message transmission queue includes a first subqueue between the CPU and the GPU and a second subqueue between the CPU and the GPU. The first subqueue is used for unidirectional data transmission from the CPU to the GPU, and the second subqueue is used for unidirectional data transmission from the GPU to the CPU.
3. The data transmission method according to claim 2, wherein: The data acquisition function includes a GPU data acquisition function and a CPU data acquisition function, and the data receiving function includes a GPU data receiving function and a CPU data receiving function. After determining the data receiving party and the data acquiring party of the data transmission task based on the data transmission direction of the data transmission task, the method further includes: When it is determined that the data transmission direction is from the CPU to the GPU, a CPU data acquisition function is called to enable the CPU to acquire the data to be transmitted corresponding to the data transmission task from the memory space of the CPU and store the data to be transmitted in the first subqueue; and a GPU data reception function is called to enable the GPU to acquire the data to be transmitted from the first subqueue and transfer the data to be transmitted to the memory space of the GPU. When it is determined that the data transmission direction is from the GPU to the CPU, the GPU data acquisition function is called to obtain the data to be transmitted corresponding to the data transmission task from the memory space of the GPU, and the data to be transmitted is stored in the second sub-queue; the CPU data receiving function is called to obtain the data to be transmitted from the second sub-queue, and the data to be transmitted is transferred to the memory space of the CPU.
4. The data transmission method according to claim 1, wherein: Storing the data to be transmitted in the message transmission queue includes: The index pointer of the data to be transmitted is stored in the message transmission queue, and the index pointer is used to point to the memory space where the data to be transmitted is located.
5. The data transmission method according to claim 1, wherein: Also includes: When the data to be transmitted is transmitted from the data acquirer to the data receiver, determining a transmission rate of the data to be transmitted based on a performance indicator of the message transmission queue; Based on the transmission rate, it is determined whether to add a message transmission queue for the data to be transmitted.
6. The data transmission method according to claim 5, characterized in that: The determining, based on the transmission rate, whether to add a new message transmission queue for the data to be transmitted further includes: When it is determined that the transmission rate is less than a preset transmission rate threshold, determining the number of message transmission queues for the data to be transmitted based on the data volume of the data to be transmitted and the transmission rate of the message transmission queue; Based on the number of message transmission queues, a new message transmission queue is added between the CPU and the GPU.
7. The data transmission method according to claim 1, wherein: The data receiving function is determined based on the queue ID of the message transmission queue, the address of obtaining data and the data length; The data acquisition function is determined by the queue ID of the message transmission queue, the address of the returned data, and the length of the returned data.
8. The data transmission method according to claim 2, wherein: The first sub-queue includes a first daemon thread, and the second sub-queue includes a second daemon thread; The first daemon thread is used to manage a data transmission process from the CPU to the GPU, and the second daemon thread is used to manage a data transmission process from the GPU to the CPU.
9. A data transmission device, characterized in that: include: a queue creation module, configured to receive a data transmission task and create a message transmission queue for the data transmission task between the CPU and the GPU, wherein the data transmission task is used for data transmission between the CPU and the GPU; A transmission determination module, configured to determine a data recipient and a data acquirer of the data transmission task based on a data transmission direction of the data transmission task; A data acquisition module, configured to call a data acquisition function so that the data acquirer acquires the data to be transmitted corresponding to the data transmission task from the memory space of the data acquirer, and stores the data to be transmitted in the message transmission queue; The data sending module is used to call the data receiving function so that the data receiving party obtains the data to be transmitted from the message transmission queue and transmits the data to be transmitted to the memory space of the data receiving party.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that: When the processor executes the computer program, the data transmission method according to any one of claims 1 to 8 is implemented.