Data backward reading method and device, electronic equipment and storage medium
By configuring task information data blocks and worker thread pools, asynchronous non-blocking data copying and recursive readback are achieved, solving the problems of page-locked memory fragmentation and insufficient allocation, and improving the efficiency and stability of data interaction between the CPU and GPU.
Patent Information
- Application Number
- CN202511085195.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-04
- Publication Date
- 2025-11-18
AI Technical Summary
In heterogeneous computing architectures, traditional data readback methods lead to page-locked memory fragmentation and insufficient allocation, affecting the efficiency of data interaction between the CPU and GPU, especially introducing unpredictable latency fluctuations in high real-time application scenarios.
By obtaining reference information of the data to be read back, configuring task information data blocks, using a worker thread pool for asynchronous non-blocking data copying, and combining recursive readback tasks, dynamically managing page-locked memory resources, avoiding frequent allocation and release, and optimizing the data copying process.
It improves the stability and efficiency of data readback interaction, solves the problems of fragmentation and insufficient allocation of page-locked memory, and enhances the data interaction performance between CPU and GPU.
Smart Images

Figure CN120973550A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of memory management technology, and in particular to a data readback method, apparatus, electronic device, and storage medium. Background Technology
[0002] In heterogeneous computing architectures, the efficiency of data exchange between the Graphics Processing Unit (GPU) and the Central Processing Unit (CPU) directly impacts the system performance of critical applications such as physics simulation, scientific computing, and real-time rendering. Especially in scenarios requiring the transfer of processing results from GPU memory back to the host CPU memory, traditional data readback methods generally employ a synchronous blocking transfer mode. This mode directly executes the data copy from GPU memory to CPU memory using the cudaMemcpy function (memory copy function) of the Compute Unified Device Architecture (CUDA) runtime application programming interface, forcing CPU threads into a blocked waiting state during the transfer, resulting in idle computing resources. Traditional asynchronous memory copy APIs can only copy GPU memory data to page-locked memory on the host side. If data needs to be read back to ordinary CPU physical memory, it must first be copied to page-locked memory as an intermediary before a second copy is performed to the specified memory address. However, since the physical address of pageable memory is not fixed, the driver needs to perform additional temporary page locking operations to establish a direct memory access (DMA) transfer channel, which introduces unpredictable latency fluctuations, usually on the order of tens of microseconds, which seriously restricts high real-time application scenarios.
[0003] In related technologies, the industry has attempted to improve transmission efficiency through page-locked memory pre-allocation strategies. These methods, by pre-fixing physical memory pages, avoid the address remapping overhead of each transmission, allowing the theoretical bandwidth utilization of the PCIe channel to increase to over 85%. However, due to the prevalent use of static memory allocation mechanisms, memory fragmentation is prone to occur during long-term operation, leading to a continuous decline in available system memory resources. Furthermore, due to memory fragmentation and other factors, the size of page-locked memory that can be mapped at one time is limited. If the amount of data to be read back or copied is too large, insufficient intermediate page-locked memory may occur, resulting in copy failure. Therefore, how to effectively manage page locking during data readback from video memory to avoid memory fragmentation and insufficient page-locked memory allocation due to excessive data readback is an urgent problem that needs to be researched and solved. Summary of the Invention
[0004] This invention provides a data readback method, apparatus, electronic device, and storage medium to solve the technical problems of memory fragmentation during data readback and insufficient page-locked memory allocation caused by excessive data readback volume.
[0005] This invention provides a data readback method, the method comprising: obtaining reference information of data to be read back, the reference information including storage attribute information of the data to be read back and host-side calling information, the calling information including the subsequent operation type of the data to be read back; configuring task information of the data to be read back according to the reference information to obtain a task information data block, the task information data block including the starting address pointer of at least one page-locked memory object; submitting a data copy task to a worker task thread pool based on the task information data block, so as to call the first worker thread to perform an initial data copy operation on the data to be read back, and submitting a recursive readback task to the worker task thread pool, the data copy operation being used to copy the data to be read back to the intermediate page-locked memory corresponding to the page-locked memory object; executing the recursive readback task through the next worker thread, wherein the recursive readback task is used to copy the remaining data to be read back, and / or to perform post-processing on the copied data corresponding to the previous worker thread according to the subsequent operation type, so as to end the data readback or recursively submit a new recursive readback task to the worker task thread pool.
[0006] In one embodiment of the present invention, the recursive readback task is executed by the next worker thread, comprising: if the remaining readback data is greater than the maximum number of bytes of the page-locked memory object, then the copied data is post-processed according to the first parameter information, the storage flag information in the task information data block is updated, the remaining data to be read back is copied based on the updated task information data block, and a new recursive readback task is submitted to the worker task thread pool so that the new recursive readback task is executed by the new worker thread; if the remaining readback data is less than or equal to the maximum number of bytes of the page-locked memory object, then the copied data is post-processed according to the second parameter information, and the task information data block is released; wherein, the first parameter information includes the subsequent operation type, the maximum number of bytes, and the starting address pointer of the page-locked memory object, and the second parameter information includes the subsequent operation type, the remaining readback data, and the starting address pointer of the page-locked memory object, and the first parameter information and the second parameter information are obtained based on the task information data block.
[0007] In one embodiment of the present invention, resource release of the task information data block includes: invoking a task termination signal transmitter and sending a task termination signal to a task termination signal receiver, so as to send a task completion signal to the host according to the task termination signal receiver; eliminating the corresponding page-locked memory object according to a first linked list iterator; and eliminating the task information data block based on a second linked list iterator; wherein, the first linked list iterator is used to characterize the storage location of the page-locked memory object on a preset memory object linked list, the second linked list iterator is used to characterize the storage location of the task information data block on a preset data block linked list, and the task information data block includes the task termination signal transmitter, the task termination signal receiver, the first linked list iterator, and the second linked list iterator.
[0008] In one embodiment of the present invention, copying the data to be read back to the intermediate page-locked memory corresponding to the page-locked memory object includes: determining the starting address pointer of the page-locked memory object as the target location for copying the data; determining the source of the data source for copying based on the stored data pointer and the data block byte offset; if the remaining amount of data to be read back is greater than or equal to the maximum number of bytes of the page-locked memory object, then determining the maximum number of bytes of the page-locked memory object as the amount of data to be copied; if the remaining amount of data to be read back is less than the maximum number of bytes of the page-locked memory object, then determining the remaining amount of data to be read back as the amount of data to be copied; copying the data to be read back to the intermediate page-locked memory corresponding to the page-locked memory object based on the target location for copying the data, the source of the data source for copying the data, and the amount of data to be copied; wherein, the task information data block includes the stored data pointer, the starting address pointer of the page-locked memory object, and the data block byte offset, the data block byte offset being used to characterize the amount of data already copied in the data to be read back, and the stored data pointer being used to characterize the storage address of the data to be read back at the corresponding data generation end.
[0009] In one embodiment of the present invention, the recursive readback task and the data copy task are submitted to the working task thread pool via a task submission thread. The task submission thread is driven by the data generation end corresponding to the data to be read back. The submission of the data copy task includes: passing the task information data block as a parameter to the task submission thread, starting the task submission thread, and submitting the data copy task to the working task thread pool. The submission of the recursive readback task includes: the first working thread submitting the recursive readback task to the task submission thread, and the task submission thread submitting the recursive readback task to the working task thread pool.
[0010] In one embodiment of the present invention, configuring task information for the data to be read back according to the reference information includes: creating an initial information data block corresponding to the subsequent operation type; filling the initial information data block with the corresponding subsequent task parameters according to the calling information, wherein the calling information further includes operation address information; and filling the initial information data block with the corresponding common content according to the storage attribute information, wherein the common content includes storage flag information and task execution flag information.
[0011] In one embodiment of the present invention, filling in the storage flag information includes: requesting a transfer memory object from a page-locked memory object container according to the storage attribute information to obtain at least one starting address pointer of the page-locked memory object; adding at least one page-locked memory object to a preset memory object linked list to obtain a first linked list iterator; storing the block pointer corresponding to the initial information data block into a preset data block linked list to obtain a second linked list iterator; setting the remaining readback data volume, the stored data pointer, and the data block byte offset according to the storage attribute information; filling the first linked list iterator, the second linked list iterator, the remaining readback data volume, the stored data pointer, the data block byte offset, and at least one starting address pointer into the initial information data block; wherein, the stored data pointer is used to represent the storage address corresponding to the data to be read back at the data generation end, and the data block byte offset is used to represent the amount of data that has been copied from the data to be read back.
[0012] This invention provides a data readback device, comprising: an information acquisition module for acquiring reference information of data to be read back, the reference information including storage attribute information of the data to be read back and host-side calling information, the calling information including the subsequent operation type of the data to be read back; a task information configuration module for configuring task information of the data to be read back according to the reference information to obtain a task information data block, the task information data block including the starting address pointer of at least one page-locked memory object; and an initial copy module for submitting a data copy task to a worker task thread pool based on the task information data block, so as to call... The first worker thread performs an initial data copy operation on the data to be read back and submits a recursive readback task to the worker task thread pool. The data copy operation is used to copy the data to be read back to the intermediate page-locked memory corresponding to the page-locked memory object. The recursive readback module is used to execute the recursive readback task through the next worker thread. The recursive readback task is used to copy the remaining data to be read back and / or to post-process the copied data corresponding to the previous worker thread according to the subsequent operation type, so as to end the data readback or recursively submit a new recursive readback task to the worker task thread pool.
[0013] The present invention provides an electronic device, the electronic device comprising: one or more processors; and a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the electronic device enables the data readback method as described in any of the above embodiments.
[0014] The present invention also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a computer processor, causes the computer to perform the data readback method described in any of the above embodiments.
[0015] The beneficial effects of the present invention are as follows: The data readback method, device, electronic device and storage medium proposed in this invention realize a multi-threaded asynchronous non-blocking data readback mode by using page-locked memory objects, data copying tasks and recursively submitted recursive readback tasks. This solves the problems of fragmented allocation of page-locked memory, frequent allocation and release and insufficient memory allocation during data readback, thereby effectively improving the interactive stability and readback efficiency during data readback. Attached Figure Description
[0016] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application. It is obvious that the drawings described below are merely some embodiments of this application, and those skilled in the art can obtain other drawings based on these drawings without any inventive effort.
[0017] In the attached diagram:
[0018] Figure 1 A schematic diagram of an exemplary system architecture provided in an embodiment of the present invention;
[0019] Figure 2 This is a flowchart illustrating a data readback method provided in one embodiment of the present invention;
[0020] Figure 3 This is a flowchart illustrating a recursive readback task provided in one embodiment of the present invention;
[0021] Figure 4 This is a schematic diagram of multi-threaded task execution provided in one embodiment of the present invention;
[0022] Figure 5 This is a schematic diagram of a data readback system provided in one embodiment of the present invention;
[0023] Figure 6 This is a block diagram of a data readback device provided in one embodiment of the present invention;
[0024] Figure 7 This is a schematic diagram of the structure of a computer system for an electronic device provided in one embodiment of the present invention. Detailed Implementation
[0025] The following specific examples illustrate the implementation of the present invention. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments. Various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of the present invention. In the absence of conflict, the following embodiments and features in the embodiments can be combined with each other.
[0026] It should be noted that the illustrations provided in the following embodiments are only schematic representations of the basic concept of the present invention. The drawings only show the components related to the present invention and are not drawn according to the actual number, shape and size of the components in the actual implementation. In the actual implementation, the form, quantity and proportion of each component can be arbitrarily changed, and the layout of the components may also be more complex.
[0027] In the following description, numerous details are explored to provide a more thorough explanation of embodiments of the invention. However, it will be apparent to those skilled in the art that embodiments of the invention may be practiced without these specific details. In other embodiments, well-known structures and devices are shown in block diagram form rather than in detail to avoid obscuring embodiments of the invention.
[0028] Please see Figure 1 , Figure 1 This is a schematic diagram of an exemplary system architecture provided in an embodiment of the present invention. Figure 1 As shown, the system architecture may include a data generation end 110 and a host end 120. The data generation end 110 includes a graphics processing unit (GPU), and the host end 120 includes a central processing unit (CPU) to read back the data to be read from the GPU's video memory to the corresponding page-locked memory on the CPU side.
[0029] For example, the process involves obtaining reference information for the data to be read back, including storage attribute information and host-side call information. The call information includes the subsequent operation type for the data to be read back. Based on the reference information, task information is configured for the data to be read back, resulting in a task information data block. This task information data block includes the starting address pointer of at least one page-locked memory object. A data copy task is submitted to the worker task thread pool based on the task information data block, invoking the first worker thread to perform the initial data copy operation on the data to be read back, and submitting a recursive readback task to the worker task thread pool. The data copy operation is used to copy the data to be read back to the intermediate page-locked memory corresponding to the page-locked memory object. The next worker thread executes the recursive readback task, which is used to copy the remaining data to be read back and / or post-process the copied data corresponding to the previous worker thread according to the subsequent operation type, to end the data readback or recursively submit a new recursive readback task to the worker task thread pool.
[0030] In related technologies, memory fragmentation occurs during data readback, and excessive data readback volume leads to insufficient page-locked memory allocation.
[0031] To address the aforementioned technical problems, this invention provides a data readback method, apparatus, electronic device, and storage medium. The implementation details of the technical solutions of the embodiments of this invention are described in detail below.
[0032] Please see Figure 2 , Figure 2 This is a flowchart illustrating a data readback method provided in one embodiment of the present invention. Figure 2 As shown, in an exemplary embodiment, the data readback method includes at least steps S210 to S240, which are described in detail below:
[0033] Step S210: Obtain reference information for the data to be read back.
[0034] The reference information includes the storage attribute information of the data to be read back and the calling information on the host side. The calling information includes the subsequent operation type of the data to be read back.
[0035] In one embodiment of the present invention, the data to be read back includes data generated by the GPU.
[0036] Step S220: Configure task information for the data to be read back based on the reference information to obtain the task information data block.
[0037] The task information data block includes a pointer to the starting address of at least one page-locked memory object.
[0038] In one embodiment of the present invention, the task information configuration of the data to be read back according to the reference information includes: creating an initial information data block corresponding to the subsequent operation type; filling the initial information data block with the corresponding subsequent task parameters according to the calling information, the calling information also including operation address information; and filling the initial information data block with the corresponding common content according to the storage attribute information, the common content including storage flag information and task execution flag information.
[0039] In one embodiment of the present invention, filling in the storage flag information includes: requesting a transfer memory object from the page-locked memory object container according to the storage attribute information to obtain at least one page-locked memory object's starting address pointer; adding at least one page-locked memory object to a preset memory object linked list to obtain a first linked list iterator; storing the block pointer corresponding to the initial information data block into a preset data block linked list to obtain a second linked list iterator; setting the remaining readback data volume, the stored data pointer, and the data block byte offset according to the storage attribute information; and filling the first linked list iterator, the second linked list iterator, the remaining readback data volume, the stored data pointer, the data block byte offset, and at least one starting address pointer into the initial information data block; wherein, the stored data pointer is used to characterize the storage address of the data to be read back at the corresponding data generation end, and the data block byte offset is used to characterize the amount of data that has been copied for the data to be read back.
[0040] In one embodiment of the present invention, a copy context object (memcpyContext) is created for the data to be read back. The copy context object includes the polymorphic memory resources (pPMR) required by the underlying page-locked memory pool, a page-locked memory object container (tempBufferContainer) for managing page-locked memory resources, a preset data block linked list (listDataBlock) for operations after data read back, a preset memory object linked list (reqObjList) for storing page-locked memory objects, a worker task thread pool (taskThreadPool) for executing specific tasks, and mutexes (muxReqObjList, muxDataBlockList) to ensure thread safety when accessing the above two linked lists.
[0041] In one embodiment of the present invention, there is a correspondence between page-locked memory objects and page-locked memory resources. A page-locked memory object container is used to manage page-locked memory objects.
[0042] In one embodiment of the present invention, the page-locked memory object container that manages page-locked memory resources is initialized by adopting a pre-allocation strategy to pre-allocate a certain number of page-locked memory resources to the page-locked memory object container, so as to reduce the frequent allocation and release of page-locked memory. The actual creation of page-locked memory resources is completed by the underlying page-locked memory pool to ensure dynamic allocation of actual memory and reduce memory fragmentation problems.
[0043] In one embodiment of the present invention, when data readback is performed frequently and for a long period of time, the aforementioned page-locked memory object container will detect the number of page-locked memory objects it manages in real time. If the number of page-locked memory objects is too redundant or insufficient, the allocation and release of page-locked memory objects will be dynamically performed in real time. The specific memory allocation and release issues are handled by the underlying page-locked memory pool, which solves the fragmentation problem when dynamically allocating and releasing page-locked memory in real time and improves security and efficiency.
[0044] In one embodiment of the present invention, based on the different types of subsequent operations performed after the data to be read back from the data generation end to the host end, an initial information data block corresponding to the subsequent operation type is created, and the non-common task information required for the corresponding subsequent operation type is filled into the initial information data block. The non-common task information is the subsequent task parameters. The initial information data block with the non-common task information filled in is then passed to the task submission function for the next step of execution.
[0045] In one embodiment of the present invention, the corresponding subsequent task parameters are filled into the initial information data block according to the calling information, including: if the subsequent operation type is copying data to the general memory on the host side, the starting address of the general memory is filled into the initial information data block; if the subsequent operation type is copying data to a file, the file path and copy mode are filled into the initial information data block; if the subsequent operation type is sending data through a network interface, the receiving end address corresponding to the network interface is filled into the initial information data block.
[0046] In one embodiment of the present invention, the task execution flag information includes a task termination signal transmitter and a task termination signal receiver to send and receive a task termination signal.
[0047] In one embodiment of the present invention, the stored data pointer includes a video memory data pointer.
[0048] In one embodiment of the present invention, the common content of the initial information data block is filled in the task submission function. A task termination signal receiver (singalReceiver) and a task termination signal transmitter (finishSignal) are created, and the task termination signal transmitter is filled into the initial information data block; a transfer memory object (reqObj) is requested from the page-locked memory object container (tempBufferContainer), and the transfer memory object is stored in a global preset memory object linked list (reqObjList), and a preset first iterator (objIter) for that storage location is obtained. Linked list access operations require a corresponding mutex lock. The preset first iterator is then stored in the initial information data block; the video memory is... The pointer (pResource), the remaining readback data (bufferLeftSize), and the pointer to the first address of the requested intermediate memory object (pTempBuffer) are filled into the initial information data block, and the data block byte offset (offset) is initialized to 0. The block pointer of the initial information data block is stored in the global preset data block linked list (listDataBlock), and the second linked list iterator (blockIter) of the storage location in the preset data block linked list after storage is obtained. The linked list access operation requires the corresponding mutex lock. The second linked list iterator is stored in the initial information data block.
[0049] Step S230: Submit a data copy task to the worker task thread pool based on the task information data block, so as to call the first worker thread to perform the first data copy operation on the data to be read back, and submit a recursive read back task to the worker task thread pool.
[0050] The data copy operation is used to copy the data to be read back to the intermediate page-locked memory corresponding to the page-locked memory object.
[0051] In one embodiment of the present invention, copying the data to be read back to the intermediate page-locked memory corresponding to the page-locked memory object includes: determining the starting address pointer of the page-locked memory object as the target location for copying the data; determining the source of the data source for copying based on the stored data pointer and the data block byte offset; if the remaining amount of data to be read back is greater than or equal to the maximum number of bytes of the page-locked memory object, then determining the maximum number of bytes of the page-locked memory object as the amount of data to be copied; if the remaining amount of data to be read back is less than the maximum number of bytes of the page-locked memory object, then determining the remaining amount of data to be read back as the amount of data to be copied; and copying the data to be read back to the intermediate page-locked memory corresponding to the page-locked memory object based on the target location for copying the data, the source of the data source for copying the data, and the amount of data to be copied; wherein, the task information data block includes the stored data pointer, the starting address pointer of the page-locked memory object, and the data block byte offset, the data block byte offset being used to characterize the amount of data already copied in the data to be read back, and the stored data pointer being used to characterize the storage address of the data to be read back at the corresponding data generation end.
[0052] In one embodiment of the present invention, a recursive readback task and a data copy task are submitted to a worker task thread pool via a task submission thread. The task submission thread is driven by the data generation end corresponding to the data to be read back. The submission of the data copy task includes: passing the task information data block as a parameter to the task submission thread, starting the task submission thread, and submitting the data copy task to the worker task thread pool. The submission of the recursive readback task includes: the first worker thread submits the recursive readback task to the task submission thread, and the task submission thread submits the recursive readback task to the worker task thread pool.
[0053] In one embodiment of the present invention, the task information data block has been prepared, and the task submission thread driven by the data generation end is started to execute the task submission function, and the task information data block is passed as a parameter to the task submission function.
[0054] In one embodiment of the present invention, on the task submission thread, the task addition function of the worker task thread pool (taskThreadPool) is called to submit a data copy task to the worker thread.
[0055] In one embodiment of the present invention, the first data copy operation is initiated by a data copy task executed on a worker thread. The data source for copying is the address of the existing data pointer in the task information data block plus the data block byte offset; the data destination for copying is the starting address pointer of the page-locked memory object requested by this data copy task. The starting address pointer can also be accessed by the first linked list iterator of the preset memory object linked list stored in the task information data block; the size of the data to be copied needs to be determined. If the remaining readback data stored in the task information data block is less than the maximum number of bytes of the page-locked memory object, then the data to be copied is the remaining readback data; otherwise, it is the maximum number of bytes of the page-locked memory object, thus performing the first data copy operation; finally, a recursive readback task is submitted to the task submission thread.
[0056] In one embodiment of the present invention, on the task submission thread, the task addition function of the worker task thread pool is called so that the worker thread in the worker task thread pool is the one that actually executes the recursive readback task.
[0057] Step S240: The next worker thread executes a recursive readback task, which is used to copy the remaining data to be read back and / or to post-process the copied data corresponding to the previous worker thread according to the subsequent operation type, so as to end the data readback or recursively submit a new recursive readback task to the worker task thread pool.
[0058] In one embodiment of the present invention, the recursive readback task is executed by the next worker thread, including: if the remaining readback data is greater than the maximum number of bytes of the page-locked memory object, then the copied data is post-processed according to the first parameter information, the storage flag information in the task information data block is updated, the remaining data to be read back is copied based on the updated task information data block, and a new recursive readback task is submitted to the worker task thread pool so that the new recursive readback task is executed by the new worker thread; if the remaining readback data is less than or equal to the maximum number of bytes of the page-locked memory object, then the copied data is post-processed according to the second parameter information, and the task information data block is released; wherein, the first parameter information includes the subsequent operation type, the maximum number of bytes, and the starting address pointer of the page-locked memory object, and the second parameter information includes the subsequent operation type, the remaining readback data, and the starting address pointer of the page-locked memory object, and the first parameter information and the second parameter information are obtained based on the task information data block.
[0059] In one embodiment of the present invention, post-processing of copied data is achieved through a data readback post-processing function (OperationFunc), and the input parameters are obtained based on the first parameter information or the second parameter information.
[0060] In one embodiment of the present invention, updating the storage flag information in the task information data block includes: determining the difference between the remaining readback data amount and the maximum number of bytes as the new remaining readback data amount; determining the sum of the data block byte offset and the maximum number of bytes as the new data block byte offset; wherein the updated storage flag information includes the new data block byte offset and the new remaining readback data amount.
[0061] In one embodiment of the present invention, resource release of the task information data block includes: calling a task termination signal transmitter and sending a task termination signal to a task termination signal receiver, so as to send a task completion signal to the host according to the task termination signal receiver; eliminating the corresponding page-locked memory object according to a first linked list iterator; and eliminating the task information data block based on a second linked list iterator; wherein, the first linked list iterator is used to characterize the storage location of the page-locked memory object on a preset memory object linked list, and the second linked list iterator is used to characterize the storage location of the task information data block on a preset data block linked list, and the task information data block includes a task termination signal transmitter, a first linked list iterator, and a second linked list iterator.
[0062] In one embodiment of the invention, a task termination signal receiver is used to provide necessary task status synchronization operations to the user. A task termination signal transmitter is used to wake up the task termination signal receiver when the task ends.
[0063] In one embodiment of the present invention, the data readback processing function in the task information data block adopts the pattern of inheritance and virtual functions to ensure the extensiveness of data readback processing.
[0064] In one embodiment of the present invention, please refer to Figure 3 , Figure 3 This is a flowchart illustrating a recursive readback task provided in one embodiment of the present invention. Figure 3As shown, in step S310, determine whether the remaining readback data amount stored in the task information data block is greater than the maximum number of bytes of the page-locked memory object. If so, proceed to step S320; otherwise, proceed to step S350. In step S320, call the data readback post-processing function of the task information data block, passing in the starting address pointer of the page-locked memory object and the maximum number of bytes of the page-locked memory object as parameters, and proceed to step S330. In step S330, subtract the maximum number of bytes of the page-locked memory object from the remaining readback data amount in the task information data block, add the maximum number of bytes of the page-locked memory object to the data block byte offset in the task information data block, and proceed to step S340. In step S340, initiate this data copy operation and submit a recursive readback task to the task submission thread: initiate this data copy operation. The operation involves copying the data source from the address of the stored data pointer in the task information data block plus the data block byte offset, copying the data destination to the address of the page-locked memory object requested by this task, and copying the data amount to the maximum number of bytes of the page-locked memory object. A recursive readback task is then submitted to the task submission thread, which is equivalent to returning to step S310. In step S350, the data readback post-processing function of the task information data block is called, with the address of the page-locked memory object and the remaining readback data amount in the task information data block as parameters, and step S360 is executed. In step S360, the task termination signal sender in the task information data block is called to send a task termination signal, the corresponding page-locked memory object is removed from the global preset memory object linked list, and the object itself is removed from the global preset data block linked list.
[0065] In one embodiment of the present invention, please refer to Figure 4 , Figure 4 This is a schematic diagram illustrating the execution of a multi-threaded task according to an embodiment of the present invention. Figure 4 As shown, Figure 4 As shown, the CPU main thread initiates a memory readback task, which is implemented through a data copy task and at least one recursive readback task. In the task submission thread of the GPU driver, the recursive readback task is executed by worker threads in the worker task thread pool. The recursive readback task is implemented by executing a recursive copy algorithm on the worker threads. The first asynchronous GPU copy is executed in the first worker thread, and the recursive copy algorithm is executed in the second worker thread to perform the second asynchronous GPU copy and the data processing after the first asynchronous GPU copy, or the data processing after the first asynchronous GPU copy, so as to initiate the next recursive readback task in batches or end the memory readback task.
[0066] In one embodiment of the present invention, please refer to Figure 5 , Figure 5 This is a schematic diagram of a data readback system provided in one embodiment of the present invention. Figure 5As shown, the data readback system includes a memory access and task information configuration module, a multi-threaded asynchronous task execution module, and a recursive data readback algorithm and its interface module. The main component of the memory access and task information configuration module is a page-locked memory object, which connects downstream to a page-locked memory pool. Upstream, its lifecycle is controlled by a page-locked memory object container, and it includes a linked list of page-locked memory objects and their mutexes that provide temporary access and storage to the outside world. This linked list of page-locked memory objects is also the preset memory object linked list. The system also includes task information data blocks and their corresponding global task information data block linked lists and mutexes. The task information data block linked list is also the preset data block linked list. The task information data blocks are designed using inheritance and virtual functions to ensure the breadth of post-readback processing. The multi-threaded asynchronous task execution module consists of worker threads that execute specific tasks. Downstream is a lock-free queue used to receive and store tasks and ensure thread safety during task retrieval and placement. Upstream is a worker thread pool that manages multiple worker threads, coordinating and allocating tasks to individual worker threads and ensuring load balancing among them. It also includes a task termination signal receiver and a task termination signal transmitter. The receiver allows users to perform necessary task status synchronization, while the transmitter sends a termination signal to wake up the receiver when a task ends. The recursive data readback algorithm and its interface module, primarily a batch-based recursive data readback algorithm (also known as a recursive copy algorithm), is the main logic module of the system. It interfaces with the previous two modules to complete the data readback task and provides users with corresponding system interfaces for use; external calls are made on the host side.
[0067] In one embodiment of the present invention, the invention addresses the problems of fragmented page-locked memory allocation, frequent allocation and release, and insufficient memory allocation during GPU memory readback. The present invention provides a systematic solution to these problems, thereby significantly improving the stability and readback efficiency of data interaction between the CPU and GPU.
[0068] Please see Figure 6 , Figure 6 This is a block diagram of a data readback device provided in one embodiment of the present invention. This device can be applied to… Figure 1 The implementation environment shown is not limited to this embodiment. This device can also be applied to other exemplary implementation environments and specifically configured in other devices. This embodiment does not limit the implementation environment to which the device is applicable.
[0069] like Figure 6 As shown, a data readback device 600 according to an embodiment of the present invention includes: an information acquisition module 610, a task information configuration module 620, an initial copy module 630, and a recursive readback module 640.
[0070] Among them, the information acquisition module 610 acquires reference information of the data to be read back. The reference information includes the storage attribute information of the data to be read back and the calling information of the host. The calling information includes the subsequent operation type of the data to be read back.
[0071] The task information configuration module 620 is used to configure the task information of the data to be read back according to the reference information to obtain a task information data block. The task information data block includes the starting address pointer of at least one page-locked memory object.
[0072] The first copy module 630 is used to submit a data copy task to the working task thread pool based on the task information data block, so as to call the first working thread to perform the first data copy operation on the data to be read back, and submit the recursive read back task to the working task thread pool. The data copy operation is used to copy the data to be read back to the intermediate page lock memory corresponding to the page lock memory object.
[0073] The recursive readback module 640 is used to execute recursive readback tasks through the next worker thread. The recursive readback task is used to copy the remaining data to be read back, and / or to post-process the copied data corresponding to the previous worker thread according to the subsequent operation type, so as to end the data readback or recursively submit a new recursive readback task to the worker task thread pool.
[0074] It should be noted that the data readback device and the data readback method provided in the above embodiments belong to the same concept. The specific operation methods of each module and unit have been described in detail in the method embodiments and will not be repeated here. In practical applications, the data readback device provided in the above embodiments can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. This is not a limitation here.
[0075] Embodiments of the present invention also provide an electronic device, including: one or more processors; and a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the electronic device enables the data readback method provided in the above embodiments.
[0076] Please see Figure 7 , Figure 7 This is a schematic diagram of the structure of a computer system for an electronic device provided in one embodiment of the present invention. Figure 7 The computer system 700 of the illustrated electronic device is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of the present invention.
[0077] like Figure 7As shown, the computer system 700 includes a central processing unit 701, which can perform various appropriate actions and processes based on a program stored in a read-only memory 702 or a program loaded from a storage section 708 into a random access memory 703, such as executing the methods described in the above embodiments. The random access memory 703 also stores various programs and data required for system operation. The central processing unit 701, the read-only memory 702, and the random access memory 703 are interconnected via a bus 704. An input / output interface 705 is also connected to the bus 704.
[0078] The following components are connected to the input / output interface 705: an input section 706 including a keyboard, mouse, etc.; an output section 707 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 708 including a hard disk, etc.; and a communication section 709 including a network interface card such as a LAN (Local Area Network) card, modem, etc. The communication section 709 performs communication processing via a network such as the Internet. A drive 710 is also connected to the input / output interface 705 as needed. A removable medium 711, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on the drive 710 as needed so that computer programs read from it can be installed into the storage section 708 as needed.
[0079] In particular, according to embodiments of the present invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of the present invention include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing computer programs for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 709, and / or installed from removable medium 711. When the computer program is executed by central processing unit 701, it performs various functions defined in the system of the present invention.
[0080] The computer-readable medium shown in the embodiments of the present invention can be a computer-readable signal medium, a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, a random access memory, a read-only memory, an erasable programmable read-only memory (EPROM), flash memory, an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present invention, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying a computer-readable computer program. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device. Computer programs contained on computer-readable media can be transmitted using any suitable medium, including but not limited to wireless, wired, etc., or any suitable combination thereof.
[0081] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present invention. Each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0082] The units described in the embodiments of the present invention can be implemented in software or hardware, and the described units can also be located in a processor. The names of these units do not necessarily limit the specific unit itself. Therefore, the technical solutions according to the embodiments of the present invention can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (such as a CD-ROM, USB flash drive, portable hard drive, etc.) or on a network, including several instructions to cause a computing device (such as a personal computer, server, touch terminal, or network device, etc.) to execute the method according to the embodiments of the present invention.
[0083] Another aspect of the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a computer's processor, causes the computer to perform the data readback method provided in the various embodiments described above. This computer-readable storage medium may be included in the electronic device described in the above embodiments, or it may exist independently and not assembled into the electronic device.
[0084] In the above embodiments, unless otherwise specified, the use of ordinal numbers such as "first" and "second" to describe common objects only indicates that they refer to different instances of the same object, rather than indicating that the objects being described must be in a given order, whether temporally, spatially, sequentially, or in any other way.
[0085] The above embodiments are merely illustrative of the principles and effects of the present invention and are not intended to limit the invention. Any person skilled in the art can modify or alter the above embodiments without departing from the spirit and scope of the present invention. Therefore, all equivalent modifications or alterations made by those skilled in the art without departing from the spirit and technical concept disclosed in the present invention should still be covered by the claims of the present invention.
Claims
1. A data readback method, characterized in that, The method includes: Obtain reference information for the data to be read back, the reference information including storage attribute information of the data to be read back and calling information on the host side, the calling information including the subsequent operation type of the data to be read back; Based on the reference information, the task information of the data to be read back is configured to obtain a task information data block, wherein the task information data block includes at least one page-locked memory object's starting address pointer. Based on the task information data block, a data copy task is submitted to the worker task thread pool to call the first worker thread to perform the first data copy operation on the data to be read back, and a recursive read back task is submitted to the worker task thread pool. The data copy operation is used to copy the data to be read back to the intermediate page-locked memory corresponding to the page-locked memory object. The recursive readback task is executed by the next worker thread, wherein the recursive readback task is used to copy the remaining data to be read back, and / or to post-process the copied data corresponding to the previous worker thread according to the subsequent operation type, so as to end the data readback or recursively submit a new recursive readback task to the worker task thread pool.
2. The data readback method according to claim 1, characterized in that, The recursive readback task is executed by the next worker thread, including: If the remaining amount of readback data is greater than the maximum number of bytes of the page-locked memory object, then the copied data is post-processed according to the first parameter information, the storage flag information in the task information data block is updated, the remaining data to be readback is copied based on the updated task information data block, and a new recursive readback task is submitted to the worker task thread pool so that the new recursive readback task can be executed by the new worker thread. If the remaining readback data is less than or equal to the maximum number of bytes of the page-locked memory object, then the copied data is post-processed according to the second parameter information, and the task information data block is released. The first parameter information includes the subsequent operation type, the maximum number of bytes, and the starting address pointer of the page-locked memory object; the second parameter information includes the subsequent operation type, the remaining readback data amount, and the starting address pointer of the page-locked memory object; the first parameter information and the second parameter information are obtained based on the task information data block.
3. The data readback method according to claim 2, characterized in that, Releasing resources from the task information data block includes: Invoke the task termination signal transmitter and send a task termination signal to the task termination signal receiver, so as to send a task completion signal to the host according to the task termination signal receiver; Eliminate the corresponding page-locked memory object based on the first linked list iterator; Eliminate the task information data block based on the second linked list iterator; Wherein, the first linked list iterator is used to characterize the storage location of the page-locked memory object on the preset memory object linked list, and the second linked list iterator is used to characterize the storage location of the task information data block on the preset data block linked list. The task information data block includes the task termination signal transmitter, the task termination signal receiver, the first linked list iterator, and the second linked list iterator.
4. The data readback method according to claim 2, characterized in that, Copying the data to be read back to the intermediate page-locked memory corresponding to the page-locked memory object includes: The starting address pointer of the page-locked memory object is determined as the target location for copying data; The data source header for copying is determined based on the existing data pointer and the data block byte offset; If the remaining readback data is greater than or equal to the maximum number of bytes of the page-locked memory object, then the maximum number of bytes of the page-locked memory object is determined as the amount of data to be copied. If the remaining readback data is less than the maximum number of bytes of the page-locked memory object, then the remaining readback data is determined as the amount of data to be copied. Based on the target location of the copied data, the source of the copied data, and the amount of copied data, the data to be read back is copied to the intermediate page-locked memory corresponding to the page-locked memory object; The task information data block includes the stored data pointer, the starting address pointer of the page-locked memory object, and the data block byte offset. The data block byte offset is used to represent the amount of data copied in the data to be read back, and the stored data pointer is used to represent the storage address of the data to be read back at the corresponding data generation end.
5. The data readback method according to claim 1, characterized in that, The recursive readback task and the data copy task are submitted to the worker task thread pool through the task submission thread, which is driven by the data generation end corresponding to the data to be read back. The submission of the data copy task includes: The task information data block is passed to the task submission thread, the task submission thread is started, and the data copy task is submitted to the worker task thread pool. The submission of the recursive readback task includes: The first worker thread submits the recursive readback task to the task submission thread, and the task submission thread submits the recursive readback task to the worker task thread pool.
6. The data readback method according to any one of claims 1-5, characterized in that, Configure task information for the data to be read back based on the reference information, including: Create the initial information data block corresponding to the subsequent operation type; The corresponding subsequent task parameters are filled into the initial information data block according to the calling information, and the calling information also includes operation address information; The corresponding common content is filled into the initial information data block according to the storage attribute information. The common content includes storage flag information and task execution flag information.
7. The data readback method according to claim 6, characterized in that, The filling of the storage flag information includes: Based on the storage attribute information, request a transfer memory object from the page-locked memory object container to obtain at least one of the starting address pointers of the page-locked memory objects; Add at least one of the page-locked memory objects to a preset memory object linked list to obtain a first linked list iterator; Store the block pointer corresponding to the initial information data block into a preset data block linked list to obtain a second linked list iterator; The remaining readback data amount, stored data pointer, and data block byte offset are set according to the storage attribute information; The first linked list iterator, the second linked list iterator, the remaining readback data, the stored data pointer, the data block byte offset, and at least one of the first address pointers are filled into the initial information data block; The stored data pointer is used to represent the storage address of the data to be read back at the data generation end, and the data block byte offset is used to represent the amount of data that has been copied to the data to be read back.
8. A data readback device, characterized in that, The device includes: The information acquisition module acquires reference information of the data to be read back. The reference information includes the storage attribute information of the data to be read back and the calling information of the host. The calling information includes the subsequent operation type of the data to be read back. The task information configuration module is used to configure the task information of the data to be read back according to the reference information to obtain a task information data block, wherein the task information data block includes at least one page-locked memory object's starting address pointer. The initial copy module is used to submit a data copy task to the working task thread pool based on the task information data block, so as to call the first working thread to perform the initial data copy operation on the data to be read back, and submit a recursive read back task to the working task thread pool. The data copy operation is used to copy the data to be read back to the intermediate page-locked memory corresponding to the page-locked memory object. The recursive readback module is used to execute the recursive readback task through the next worker thread, wherein the recursive readback task is used to copy the remaining data to be read back, and / or to post-process the copied data corresponding to the previous worker thread according to the subsequent operation type, so as to end the data readback or recursively submit a new recursive readback task to the worker task thread pool.
9. An electronic device, characterized in that, The electronic device includes: One or more processors; A storage device for storing one or more programs, which, when executed by one or more processors, cause the electronic device to implement the data readback method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, It stores a computer program that, when executed by the computer's processor, causes the computer to perform the data readback method according to any one of claims 1 to 7.