CN-121996575-A - Method and device for processing prefetch request, electronic equipment and readable storage medium
Abstract
The application discloses a method, a device, equipment and a medium for processing a prefetch request. Firstly, a prefetch request is initiated to an external memory according to a storage read pointer, a first prefetch request identification is allocated to the prefetch request in a prefetch request identification resource pool, and state information of the prefetch request is updated in response to a target event and used for representing validity of prefetch data requested by the prefetch request. And then determining corresponding state information in the resource pool according to a second prefetch request identifier carried by the prefetch data. And finally, determining whether the prefetched data is valid according to the state information, and executing write-in caching operation on the valid prefetched data. The state of each prefetch request is uniquely identified and tracked in the whole process through the prefetch request identification and the state information, and the write-in caching operation is controlled according to the validity information when the prefetch data is returned, so that invalid data is identified and discarded, cache pollution is avoided, only valid data is ensured to be stored in a cache, the occupation of the cache space by the invalid data is avoided, and the cache utilization rate is improved.
Inventors
- Request for anonymity
Assignees
- 摩尔线程智能科技(北京)股份有限公司
Dates
- Publication Date
- 20260508
- Application Date
- 20251226
Claims (16)
- 1. A method of processing a prefetch request, the method comprising: Initiating a prefetch request to an external memory according to an address indicated by a storage read pointer, and distributing a first prefetch request identifier for the prefetch request in a prefetch request identifier resource pool; Updating state information of the prefetch request in response to the detected target event, wherein the state information is used for representing the validity of prefetch data requested by the prefetch request; inquiring a first prefetch request identifier matched with a second prefetch request identifier in the prefetch request identifier resource pool according to a second prefetch request identifier carried by prefetch data returned by the external memory, and determining corresponding state information according to an inquiry result; and determining whether the prefetched data is valid or not according to the state information, and executing write-in caching operation on the valid prefetched data.
- 2. The method of claim 1, wherein the status information includes validity information indicating the validity of the prefetch data requested by the prefetch request, and a cache start position indicating a position in the cache where the prefetch data starts writing; The determining whether the prefetched data is valid according to the state information, and executing the write cache operation on the valid prefetched data includes: Determining that the prefetched data is valid or invalid according to the validity information; and aiming at the effective prefetched data, executing the write-in caching operation in the annular cache according to the cache starting position and the return sequence number carried by the prefetched data.
- 3. The method of claim 2, wherein the validity information includes a valid start position and a valid end position, and wherein the determining that the prefetch data is valid or invalid based on the validity information further includes: determining a position to be written of the prefetched data according to the cache starting position and the return sequence number; determining that the prefetched data is valid or invalid according to a matching result of a position to be written of the prefetched data and an effective interval, wherein the effective interval is determined according to an effective starting position and an effective ending position; the method further comprises the steps of: and if the position to be written falls outside the range from the effective starting position to the effective ending position, executing the refusing writing operation.
- 4. A method according to claim 3, wherein the target event comprises an update event storing a write pointer, and wherein the updating the state information of the prefetch request in response to the detected target event comprises: detecting an update event of the stored write pointer; Determining a target prefetch request identifier of a storage write pointer before updating and target state information corresponding to the target prefetch request identifier in the prefetch request identifier resource pool, wherein the target state information comprises target validity information; And updating the effective mark or the effective ending position in the target validity information according to the effective starting position and the effective ending position in the target validity information.
- 5. The method of claim 4, wherein updating the validity flag in the target validity information based on the valid start position and the valid end position in the target validity information comprises: And if the valid starting position in the target validity information is equal to the valid ending position, changing the value of the valid mark in the target validity information into invalid.
- 6. The method of claim 4, wherein updating the valid end position in the target validity information based on the valid start position and the valid end position in the target validity information comprises: If the effective starting position in the target effectiveness information is not equal to the effective ending position, subtracting a preset value from the value of the effective ending position in the target effectiveness information; and subtracting the preset value from the cache write pointer.
- 7. The method of claim 3, wherein the target event comprises a jump event, and wherein the updating state information of the prefetch request in response to the detected target event comprises: Acquiring a read request for reading data from the ring cache; And updating the effective mark or the effective starting position of the prefetch request influenced by the jump event according to the read request with the jump event, the in-use prefetch request mark in the prefetch request mark resource pool, and the effective starting position and the effective ending position corresponding to the in-use prefetch request mark.
- 8. The method of claim 7, wherein the updating the valid flag of the prefetch request affected by the jump event based on the read request with the jump event, the prefetch request identification in use in the resource pool, and the valid start position and the valid end position corresponding to the prefetch request identification in use, further comprises: determining the whole skipped prefetching request according to the reading request with the jumping event, the in-use prefetching request identifier in the prefetching request identifier resource pool, and the effective starting position and the effective ending position corresponding to the in-use prefetching request identifier; And changing the value of the valid flag corresponding to the whole skipped prefetch request into invalid.
- 9. The method of claim 7, wherein the updating the valid starting location of the prefetch request affected by the jump event based on the read request with the jump event, the prefetch request identification in use in the resource pool, and the valid starting location and the valid ending location corresponding to the prefetch request identification in use, further comprises: Determining a partially skipped prefetch request and an updated effective starting position according to a read request with a skip event, an in-use prefetch request identifier in the prefetch request identifier resource pool, and an effective starting position and an effective ending position corresponding to the in-use prefetch request identifier; changing the value of the effective starting position corresponding to the partially skipped prefetch request into the updated effective starting position; the buffer read pointer is updated in response to a read request in which a jump event occurs.
- 10. The method of any one of claims 1-9, wherein the status information further comprises a count of data that has not been returned, the method further comprising: and updating the data count which is not returned every time the external memory returns prefetched data.
- 11. The method according to claim 10, wherein the method further comprises: And when the data count which is not returned is reduced to zero, releasing the first prefetch request identification from the prefetch request identification resource pool.
- 12. The method according to any of claims 1-9, wherein the initiating a prefetch request to an external memory according to an address indicated by a storage read pointer and allocating a first prefetch request identification for the prefetch request in a prefetch request identification resource pool comprises: Determining an address space to be prefetched as a continuous cache line according to the storage read pointer; Generating a burst prefetch request for acquiring a plurality of continuous cache lines at one time according to the address pointed by the storage read pointer, and distributing available first prefetch request identifiers for the burst prefetch request in the prefetch request identifier resource pool; the burst prefetch request is issued to the external memory.
- 13. The method of claim 12, wherein generating a burst prefetch request for fetching a plurality of consecutive cache lines at a time based on the address pointed to by the storage read pointer comprises: Determining the free capacity of the buffer according to the buffer read pointer and the buffer write pointer; When the buffer memory spare capacity reaches a preset threshold value, selecting a minimum value from the buffer memory spare capacity, the maximum burst length of a data bus and the upper limit of the data quantity to be prefetched in the external memory as the burst length; Modifying a cache write pointer to a value after increasing the burst length; and generating the burst prefetch request according to the address pointed by the storage read pointer and the burst length.
- 14. An apparatus for processing a prefetch request, the apparatus comprising: The request initiating module is used for initiating a prefetch request to an external memory according to an address indicated by a storage read pointer, and distributing a first prefetch request identifier for the prefetch request in a prefetch request identifier resource pool; the information updating module is used for responding to the detected target event and updating the state information of the prefetch request, wherein the state information is used for representing the validity of the prefetch data requested by the prefetch request; The state determining module is used for inquiring a first prefetch request identifier matched with the second prefetch request identifier in the prefetch request identifier resource pool according to a second prefetch request identifier carried by prefetch data returned by the external memory, and determining corresponding state information according to an inquiry result; and the writing control module is used for determining whether the prefetched data is valid according to the state information and executing writing cache operation on the valid prefetched data.
- 15. An electronic device comprising a processor, a memory and a program or instruction stored on the memory and executable on the processor, the program or instruction when executed by the processor implementing the steps of the method of processing a prefetch request according to any one of claims 1 to 13.
- 16. A readable storage medium, wherein a program or instructions are stored on the readable storage medium, which when executed by a processor, implement the steps of the method of processing a prefetch request according to any one of claims 1-13.
Description
Method and device for processing prefetch request, electronic equipment and readable storage medium Technical Field The present application relates to a method for processing a prefetch request, a device for processing a prefetch request, an electronic apparatus, and a readable storage medium, and more particularly, to the field of computer architecture. Background Instruction or data prefetching is a key technique in the field of computer architecture, particularly high performance GPU (Central Processing Unit )/CPU (Graphics Processing Unit, graphics processor) designs, to hide memory access latency and improve processor performance. The basic idea is to predict future access needs of the processor and fetch data into the cache in advance from a low-speed external memory, such as a main memory or a low-level cache. Conventional prefetch processes typically involve the prefetch controller initiating a prefetch request according to a program counter or sequence of address streams, and when the external memory returns the prefetch data, the cache controller writing the returned data to a cache location pointed to by a cache write pointer and advancing the write pointer. However, this conventional prefetch approach exposes inherent drawbacks in handling complex modern computational loads, such as lack of management of prefetch requests, that may fail due to branch mispredictions, dynamic updates of code segments, etc., after the prefetch request is issued, before the prefetch data is returned, and the stale data is also written into the cache, resulting in a low cache operating efficiency. Disclosure of Invention An object of an embodiment of the present application is to provide a method for processing a prefetch request, a device for processing a prefetch request, an electronic device, and a readable storage medium, which can solve the problem that the cache operation efficiency is low because the prefetch request is not managed, and after the prefetch request is issued and before the prefetch data is returned, the request is invalid, and the invalid data is written into the cache. In order to solve the technical problems, the application is realized as follows: in a first aspect, an embodiment of the present application provides a method for processing a prefetch request, where the method includes: Initiating a prefetch request to an external memory according to an address indicated by a storage read pointer, and distributing a first prefetch request identifier for the prefetch request in a prefetch request identifier resource pool; Updating state information of the prefetch request in response to the detected target event, wherein the state information is used for representing the validity of prefetch data requested by the prefetch request; inquiring a first prefetch request identifier matched with a second prefetch request identifier in the prefetch request identifier resource pool according to a second prefetch request identifier carried by prefetch data returned by the external memory, and determining corresponding state information according to an inquiry result; and determining whether the prefetched data is valid or not according to the state information, and executing write-in caching operation on the valid prefetched data. In a second aspect, an embodiment of the present application provides a processing apparatus for a prefetch request, where the apparatus includes: The request initiating module is used for initiating a prefetch request to an external memory according to an address indicated by a storage read pointer, and distributing a first prefetch request identifier for the prefetch request in a prefetch request identifier resource pool; the information updating module is used for responding to the detected target event and updating the state information of the prefetch request, wherein the state information is used for representing the validity of the prefetch data requested by the prefetch request; The state determining module is used for inquiring a first prefetch request identifier matched with the second prefetch request identifier in the prefetch request identifier resource pool according to a second prefetch request identifier carried by prefetch data returned by the external memory, and determining corresponding state information according to an inquiry result; and the writing control module is used for determining whether the prefetched data is valid according to the state information and executing writing cache operation on the valid prefetched data. In a third aspect, an embodiment of the present application provides an electronic device, including a processor, a memory, and a program or instruction stored on the memory and executable on the processor, the program or instruction implementing the steps of the method according to the first aspect when executed by the processor. In a fourth aspect, embodiments of the present application provide a readable storage medium having stored