Software-guided hardware prefetcher for nested streams

WO2024197643A1PCT designated stage expired Publication Date: 2024-10-03HUAWEI TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2023/084716
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Filing Date
2023-03-29
Publication Date
2024-10-03

Smart Images

  • Figure CN2023084716_03102024_PF_FP_ABST
    Figure CN2023084716_03102024_PF_FP_ABST
Patent Text Reader

Abstract

A system includes a memory for storing data, at least one cache for storing data copied from the memory to the cache, a processor for executing software code and, based on the software code, reading data from the cache or the memory, and a prefetcher for generating prefetch requests to prefetch data from the memory and store copies of the prefetched data in the cache. The prefetcher is configured, while processing a data stream generated by compiling of the software code, to: identify, based on the processing of the data stream, a scalable vector processing instruction in the software code executed by the processor; identify, based on the scalable vector processing instruction, a number of data elements that have been processed by the processor; and generate one or more prefetch requests for prefetching, from the memory, a number of data elements corresponding to the identified number of data elements, and for storing a copy of the prefetched number of data elements in the cache.
Need to check novelty before this filing date? Find Prior Art

Description

SOFTWARE-GUIDED HARDWARE PREFETCHER FOR NESTED STREAMSTECHNICAL FIELD

[0001] The present disclosure relates to computer processing and in particular to a software-guided hardware prefetcher for nested streams.BACKGROUND

[0002] In modern computer systems, retrieving data from the main memory takes longer than processing the retrieved data. For example, it may take 150 nanoseconds to retrieve data but only a few nanoseconds to process the data. The random-access time for retrieving data from the main memory has generally not kept up with increases in processor speed. If data retrieval from the main memory and processing of the data are done in series, then the processor becomes underutilized and will spend most of its time waiting for data.

[0003] The standard technique for solving the main memory access time issue is adding memory caches. A hierarchy of faster, smaller memories are added between the processor and the main memory. The processor hardware keeps temporary copies of data or instructions in these caches. A processor can load data that it has recently stored from the cache without waiting for the data to be loaded from the main memory. While this works well for data that requires extensive processing, it generally does not work well for data streams in which each data element only requires a small amount of processing. This problem is especially pronounced in high-performance system which can process a data element very quickly.

[0004] For algorithms that use data streams, software or hardware prefetchers with memory caches are a common solution. A copy of the data is fetched from the main memory and is kept in one of the cache levels before the data is needed by the processor. When the processor needs the data, the load process is very quick. The data is said to be prefetched into the memory cache.

[0005] High-performance Central Processing Units (CPUs) often use hardware-based prefetchers. These devices use training algorithms that analyze the data retrieval pattern of the processor and use it to predict which memory locations will be used in the future. The  hardware prefetcher then prefetches the data from those memory locations and stores it into the cache system. For this reason, hardware prefetchers work very well for direct streams that are packed densely in the main memory. However, the training algorithm may get confused by the irregular memory patterns generated by nested loops with master and indirect streams. In this scenario, a training processor may prefetch the wrong data and reduce performance.

[0006] Software prefetchers use special prefetch instructions that are inserted into the code by either application-level software or the compiler. The instructions directly trigger cache fill events. Software-based prefetchers work well for direct streams and nested loops if there are no master streams. For indirect streams or subordinate nested loops, they do not perform well. In these scenarios, a software prefetcher must bring data from memory into the processor and perform calculations to get the memory addresses for those streams. Memory address calculations are performed twice, once for the prefetcher and once for the normal program flow. This may reduce software performance. A software prefetcher works best if it optimized for the hardware parameters of the cache system such as the cache line size. However, when software is optimized for the hardware parameters of the system, it loses the flexibility to run well on other hardware systems.

[0007] SUMMARY

[0008] According to a first aspect of the disclosure, there is provided a system comprising: a memory for storing data; at least one cache for storing data copied from the memory to the cache; a processor for executing software code and, based on the software code, reading data from the cache or the memory; and a prefetcher for generating prefetch requests to prefetch data from the memory and store copies of the prefetched data in the cache, wherein the prefetcher is configured, while processing a data stream generated by compiling of the software code, to: identify, based on the processing of the data stream, a scalable vector processing instruction in the software code executed by the processor; identify, based on the scalable vector processing instruction, a number of data elements that have been processed by the processor; and generate one or more prefetch requests for prefetching, from the memory, a number of data elements corresponding to the identified number of data elements, and for storing a copy of the prefetched number of data elements in the cache.

[0009] Therefore, prefetchers according to embodiments of the disclosure may process scalable vector instructions in which software does not know how many vector elements are  processed per instruction. This may allow prefetching for high-performance computing technologies.

[0010] The data stream may comprise at least one inner loop nested within at least one outer loop.

[0011] The prefetcher may be enabled to generate the one or more prefetch requests by one or more of: a compiler for compiling the software code; and the software code.

[0012] The prefetcher may be further configured to: determine that a pending prefetch request has been discarded; and re-generate the discarded prefetch request.

[0013] The prefetcher may be further configured to: determine that a first prefetch request and a second prefetch request map to a common cache line in the cache, wherein the second prefetch request is for data that is not in a master stream and not in a parent stream of the data stream; and in response to determining that the first prefetch request and the second prefetch request map to the common cache line, discard the second prefetch request. Therefore, the prefetcher may recognize that completion of the first prefetch request means that the second prefetch request is also complete.

[0014] The prefetcher may be further configured to: determine that a first prefetch request and a second prefetch request map to a common cache line in the cache, wherein the first prefetch request is for data in a master stream or a parent stream of the data stream; and in response to determining that the first prefetch request and the second prefetch request map to the common cache line, delay execution of the second prefetch request.

[0015] The prefetcher may be further configured to: delay execution of the second prefetch request until each data element prefetched by the first prefetch request is processed in the master stream or the parent stream. Therefore, the prefetcher may recognize that the second prefetch request can only be completed after completion of the first prefetch request.

[0016] The prefetcher may be further configured to: determine that data copied from the memory to the cache has been evicted; and generate a prefetch request for prefetching the evicted data from the memory and storing a copy of the evicted data in the cache.

[0017] The prefetcher may be further configured to: for each of one or more prefetch requests: determine whether the prefetch request is for data in the inner loop or the outer loop; and assign, based on the determination, a priority to the prefetch request. Therefore, different prefetches may be executed in different orders according to their assigned priorities.

[0018] The prefetcher may be further configured to: execute, based on each assigned priority, the one or more prefetch requests.

[0019] The prefetcher may be further configured to: determine whether the prefetcher is at risk of generating a prefetch request for data that is not yet needed, or no longer needed, by the processor; and control, based on the determination, the processing of the data stream by the prefetcher. Therefore, the prefetcher may ensure that prefetch requests are generated before the data is needed by the software. This may also allow the prefetcher to recover from scenarios where the prefetcher is at risk of falling behind the main program flow.

[0020] The prefetcher may be configured to determine whether the prefetcher is at risk of generating a prefetch request for data that is not yet needed, or no longer needed, by the processor, by: comparing, based on the data stream, an induction stream associated with the processor to an induction stream associated with the prefetcher.

[0021] The prefetcher may be further configured to: determine that the processing of the data stream by the prefetcher is ahead of the execution of the software code by the processor; and in response to the determination, pause processing by the prefetcher of one or more loops in the data stream. This may prevent the processing by the prefetcher to move too far ahead of the processing by the software.

[0022] The prefetcher may be further configured to control the processing of the data stream by:delaying the generation of one or more prefetch requests.

[0023] The prefetcher may be further configured to control the processing of the data stream by:discarding one or more pending prefetch requests; or skipping execution of one or more prefetch requests whose execution has not yet begun.

[0024] The one or more prefetch requests may be for data that, based on the execution of the software code by the processor, is currently not needed by the processor.

[0025] The one or more prefetch requests may be for data in one or more non-master loops of the data stream.

[0026] The prefetcher may be further configured to control the processing of the data stream by: skipping one or more iterations of one or more loops in the data stream.

[0027] The one or more loops may correspond to instructions that have already been executed by the processor.

[0028] The at least one cache may comprise a first cache and a second cache. The prefetcher may be configured to control the processing of the data stream by: modifying a pending prefetch request targeting the first cache so that the pending prefetch request targets the second cache.

[0029] Data stored in the memory may comprise one or more instructions. Therefore, the prefetcher may issue prefetch requests for data as well as instructions to be performed on data.

[0030] According to a further aspect of the disclosure, there is provided a computer-implemented method of using a prefetcher for prefetching data from a memory, comprising: identifying with the prefetcher, based on a data stream being processed by the prefetcher, a scalable vector processing instruction in software code executed by a processor, wherein the data stream is generated by compiling of the software code; identifying with the prefetcher, based on the scalable vector processing instruction, a number of data elements that have been processed by the processor; generating with the prefetcher one or more prefetch requests; and using the one or more prefetch requests to prefetch, from the memory, a number of data elements corresponding to the identified number of data elements, and to store a copy of the prefetched number of data elements in a cache for retrieval by the processor.

[0031] This summary does not necessarily describe the entire scope of all aspects. Other aspects, features, and advantages will be apparent to those of ordinary skill in the art upon review of the following description of specific embodiments.BRIEF DESCRIPTION OF THE DRAWINGS

[0032] Embodiments of the disclosure will now be described in detail in conjunction with the accompanying drawings of which:

[0033] FIG. 1 is a schematic diagram of a software-guided hardware prefetcher according to an embodiment of the disclosure;

[0034] FIG. 2 is a schematic diagram of a software-guided hardware prefetcher being used with a High-Performance Compute (HPC) server CPU, according to an embodiment of the disclosure;

[0035] FIG. 3 is a schematic diagram of a software-guided hardware prefetcher being used with a server CPU, according to an embodiment of the disclosure;

[0036] FIG. 4 is a schematic diagram of an L3 cache operating with other components the context of the architecture shown in FIG. 2, according to an embodiment of the disclosure;

[0037] FIG. 5 is a schematic diagram of a software-guided hardware prefetcher being used with a Graphical Processing Unit (GPU) system such as a video card or a GPU server, according to an embodiment of the disclosure; and

[0038] FIG. 6 is a schematic diagram of a software-guided hardware prefetcher being used with a Neural Processing Unit (NPU) system, according to an embodiment of the disclosure.DETAILED DESCRIPTION

[0039] The present disclosure relates to a software-guided hardware prefetcher for nested streams. While various embodiments of the disclosure are described below, the disclosure is not limited to these embodiments, and variations of these embodiments may well fall within the scope of the disclosure which is to be limited only by the appended claims.

[0040] Generally, the following definitions may apply to certain terms used throughout the disclosure:

[0041] Main Memory: A medium-term storage device such as Dynamic Random-Access Memory (DRAM) used to store instructions or data. Main memory is random-access and each location is specified by a memory address that can be used directly by software instructions.

[0042] Cache: A short-term storage device used to temporarily store data and instructions used by a software program. A cache is smaller and faster than the main memory, but the processor cannot directly reference data locations in the cache. A cache contains a temporary image of the instructions or data stored in the main memory and is referenced by software with the same memory address. The temporary image in a cache is maintained by hardware. Typically, a computer system will have a hierarchy of caches with the fastest and smallest cache closest to the processor and the largest and slowest cache closest to the main memory.

[0043] Load: A processor operation that reads data from the main memory.

[0044] Store: A processor operation that writes data to the main memory.

[0045] Stream: A repeating sequence of data elements used by a software algorithm.

[0046] Typically, software executes a loop and performs the same compute operations on each data element in the stream. A stream is either loaded from the main memory or stored to the main memory. Higher-level software will assume that data elements are  processed in series, but the compiler may use vector instructions that process stream elements in parallel.

[0047] Induction Stream: A loop counter used to control other types of streams. An induction stream is generated by the processor rather than being stored in the main memory.

[0048] Direct Stream: A stream of data elements in which the memory address of each data element can be calculated solely through induction streams or constants. The induction stream is referred to as the parent stream of the direct stream.

[0049] Indirect Stream: A stream of data elements in which the memory address of each data element requires a data element obtained from a direct or indirect stream. An indirect stream may also use constants. The parent stream of an indirect stream is the direct or indirect stream which provides the memory data element used in the address calculation. Each data element of an indirect stream requires a data element of the parent stream.

[0050] Dependent Stream: A direct or indirect stream.

[0051] Nested Loops: A hierarchical control structure in which one loop, the outer loop, contains another loop, the inner loop. For every iteration of the outer loop, the inner loop is executed for all its iterations. There may be any number of hierarchical levels in a nested loop. An outer loop may contain an inner loop, but that inner loop may also contain an inner loop. The induction stream of the outer loop is referred to as the master stream and the induction stream of the inner loop is referred to as the subordinate stream.

[0052] Master Dependent Stream: A dependent stream of data contained in the outer loop of a nested pair that controls constants of the inner loop. Constants may include, but are not limited to, the initial, final, or increment values of an induction stream or constants used for the address calculation of dependent streams.

[0053] Subordinate Stream: An induction or dependent stream that has a master stream.

[0054] Parent Stream: An induction stream or dependent stream which has a child stream. Each data element of the parent stream is used to generate the memory address for a child stream data element.

[0055] Child Stream: A dependent stream that has a parent stream.

[0056] Example Streams: The following C-language code illustrates examples of each stream type.

[0057] Induction Streams: i, j

[0058] Direct Streams: B, D, F, H, L, M

[0059] Indirect Streams: N

[0060] Master Streams: i, B, D, F, H, L

[0061] Subordinate Streams: j, M, N

[0062] Compiler: A software program that translates software written in a high-level language, such as C++, to low-level machine code instructions that are executed by a processor.

[0063] Processor: A hardware device that executes software instructions. In this document, “processor” may refer to a CPU designed for general-purpose computing, a GPU designed for graphics processing, or an NPU designed for machine-learning applications. A distinguishing feature is that a processor executes software instructions stored in memory and these instructions to process data which may be stored in memory or internally in the processor.

[0064] Vector Instruction: A vector instruction is a single instruction that performs the same compute operation on multiple pieces of data. Each item is referred to as an  element of the vector. Typically, a compiler uses a vector instruction to execute multiple iterations of a loop at the same time.

[0065] Scalable Vector Instruction: A vector instruction which is agnostic to the number of data elements in a vector. The number of elements in the vector is known by the processor hardware, but not known by the software instruction. The instruction simply indicates which compute operation should be processed on each element of data in the vector.

[0066] According to a first embodiment of the disclosure, there is shown in FIG. 1 a schematic diagram of a software-guided hardware prefetcher 100. Prefetcher 100 comprises the following logical units, and is configured to perform the following functionalities:

[0067] 1. A mechanism for software to program prefetcher 100 with the nested stream configuration parameters and their linkages. Prefetcher 100 stores this information in a Nested Stream Configuration block 40 before software begins processing the streams. The software commands that are used to program prefetcher 100 may include, but are not limited to, custom CPU instructions, custom CPU registers, or device memory registers.

[0068] 2. A mechanism to bind relative instruction addresses as seen by the compiler to absolute memory addresses used by hardware. This allows prefetcher 100 to monitor the progress of stream processing by software.

[0069] 3. A Prefetch Generator block 30 autonomously generates prefetches for all streams in all loops without subsequent intervention by software until the loops are complete. Prefetch Generator 30 creates the same memory fetch pattern that will be used by software. Prefetch Generator 30 contains counters that are equivalent to the induction streams in software. The counters use the same initial, final, and increment values as the instruction streams in software. Prefetcher 100 will increment the counters before software to ensure that the Prefetch Generator 30 issues prefetch requests before the stream data is needed by software.

[0070] 4. Software-only or software-guided hardware prefetchers may cause congestion of the memory cache system (i.e. the main memory and the caches) by issuing many prefetches that map to the same hardware cache line. Caches deal with  large chucks of memory that are much larger than the data processed by a software instruction. For example, a cache line may be 64 or 128 bytes wide, but software may process data elements that are 4 or 8 bytes wide. A software-only or software-guided hardware prefetcher may therefore generate redundant cache fill requests unless it is optimized for the cache line width supported by the cache system hardware.

[0071] Therefore, a Prefetch Request and Tracking block 60 is used to request prefetches to the memory cache system and track the status of outstanding prefetch requests. Prefetch Request and Tracking 60 also:

[0072] a. Re-request prefetches if the memory cache system has discarded them.

[0073] b. Detect when different prefetch requests map to the same cache line and can be merged into the same prefetch request to the memory cache system.

[0074] c. Re-requests prefetches if the memory cache system has evicted a previous prefetch and moved the data to a different cache level.

[0075] 5. A mechanism for prefetcher 100 to automatically load data from the memory cache after the prefetch is complete. This includes tracking scenarios where multiple prefetch requests were merged into one memory cache prefetch, but that cache prefetch contains the master or parent data for multiple streams. Multiple data elements may be loaded from a single cache request.

[0076] 6. A hardware buffer 50 to store master data and parent data from the memory cache until the data is needed. This prevents the inner loop from being blocked by the outer loop. Multiple data elements for each stream can be stored in the buffer.

[0077] 7. A hardware mechanism to reconfigure the inner streams with buffered master data when needed. Master data changes the loop parameters configured by software. This may be accomplished through several mechanisms such as but not limited to directly changing Nested Stream Configuration 40 or by maintaining a separate current stream parameter table.

[0078] 8. Hardware mechanism to use buffered parent data to generate indirect prefetches. The Prefetch Generator uses parent stream data stored in the hardware buffer.  Parent data is used to generate indirect prefetches, but is not part of the stream configuration. Each prefetch in an indirect stream requires a new parent data value. This mechanism may or may not allow reordering of the data elements in an indirect stream.

[0079] 9. As described above, software-only or software-guided prefetchers generally have difficulty with scalable vector processing instructions which are hardware vector length agnostic. The hardware vector length indicates the number of data elements processed by each instruction. The instructions may be Single Instruction, Multiple Data (SIMD) . Software is written independently of the hardware capacity of the CPU. High-level software is written in loops that process one element at a time, but the compiler generates instructions that process one vector at a time. The processor (e.g. processor 200 in FIG. 2) processes vectors which represent multiple loop iterations at the same time. Without scalable vector processing instructions, software must be manually optimized for each hardware platform.

[0080] Therefore, a hardware-based Program Monitor 10 is used to track execution of instructions in each loop by software. Program Monitor 10 can automatically detect scalable vector processing instructions and measure the number of vector elements processed by each instruction. Program Monitor 10 maps physical vector processing instructions to software agnostic loop parameters such as induction variables.

[0081] 10. A mechanism throughout prefetcher 100 to differentiate between master loop prefetches and subordinate loop prefetches, and to assign a priority to each. Prefetch priority may trigger, but is not limited to, selective discard or prefetch reordering.

[0082] 11. As described above, hardware-only prefetchers use training algorithms to predict the next required data, but they can make mistakes and fetch data that was never needed. Software-only or software-guided hardware prefetchers do not make mistakes, but they can fall behind the main program flow. If a software-only or software-guided hardware prefetcher falls behind the program flow, the prefetcher may request cache fills for memory locations that have  already been processed by the main program. This may cause congestion in the memory cache system and lower the overall performance.

[0083] Therefore, an Adaptive Prefetch Rate Control block 20 controls the prefetch request rate to ensure that prefetches are requested before the data is needed by software. Adaptive Prefetch Rate Control 20 prevents prefetches from being requested too far in the future and can recover from scenarios where software is catching up to the prefetcher. Adaptive Prefetch Rate Control can also recover from a scenario where software has passed the prefetcher. Flow control mechanisms may include, but are not limited to:

[0084] a. Stalling prefetch generator 30 while waiting for the processor to catch up.

[0085] b. Stalling individual streams from generating prefetches.

[0086] c. Discarding prefetches that are no longer needed because software has passed the prefetcher 100.

[0087] d. Skipping loop iterations that have already been executed by software.

[0088] e. Proactively skipping loop iterations when prefetcher 100 has not fallen behind, but is at risk of failing behind software.

[0089] f. Proactively discarding non-master prefetches if prefetcher 100 is at risk of falling behind software.

[0090] g. Changing the cache level to which a prefetch is targeted.

[0091] 12. A method of resuming prefetching after a process thread content switch save and restore cycle. The mechanism may use, but it not limited to, allowing software to read and write the internal state of prefetcher 100. Software may freeze prefetcher 100 and read out its internal state and configuration. Later, software may restore prefetcher 100to its previous state and resume where it left off. This will work even if another software thread was using prefetcher 100 between the save and restore events.

[0092] Turning to FIG. 2, there is shown the use of prefetcher 100 in a High-Performance Compute (HPC) server CPU, according to an embodiment of the disclosure.

[0093] In this example, there are two processors 200, each of which has its own L1 cache 210, L2 cache 220, and prefetcher 100. Both processors 200 share an L3 cache 230 that it  connected directly to the main memory 240 of the system. Main memory 240 could be an internal memory on the same integrated circuit as processors 200, or an external memory cache system such as Double Data Rate (DDR) DRAM. This is an illustrative example. In a real server system, there are typically many more processors or even multiple L3 caches. There may or may not be sharing of the L1 or L2 level caches. Since prefetchers 100 are only connected to processors 200 and L1 caches 210, the exact hierarchy of the caches and main memory beyond L1 are not important. If prefetchers 100 prefetch to L2 cache 220 to reduce L1 cache 210 congestion, then prefetchers 100 need to know that there is an L2 cache, but the exact configuration is not important.

[0094] The caches contain temporary copies of the data that is located in main memory 240. Each cache represents a sub-set of main memory 240. In a server CPU system, there will be coherent, set-associative caches. Typically, caches are configured so that those closest to processors 200 are smaller and faster. Caches closer to main memory 240 are typically larger and slower, with main memory 240 being the largest and slowest.

[0095] There is one prefetcher 100 for each processor 200. Each prefetcher 100 is connected to a processor 200 and an L1 cache 210. Software programs prefetchers 100, and each prefetcher 100 begins sending prefetch requests to an L1 cache 210. Each prefetcher 100 loads data out of an L1 cache 210 as needed to process master streams and indirect streams. Prefetchers 100 monitor the software flow inside processors 200 and execute flow control operations as needed.

[0096] Referring to FIG. 3, according to an embodiment of the disclosure, prefetcher 100 may also be used in a traditional cloud server CPU or a specialized, high-performance server CPU.

[0097] The server CPU contains many L3 clusters arranged in a ring. Each L3 cluster contains one L3 memory cache 330 and several processor clusters 350. The L3 clusters are connected in a ring structure with main memory blocks 340 inserted in the ring at various points. When an L3 cache 330 needs to access main memory 340, the request is routed through each L3 cluster 330 until the correct main memory 340 is reached. Alternatively, a server CPU could connect the L3 clusters in a star configuration. There could be fewer cache levels or more. Prefetcher 100 will work with any memory cache configuration as long as there is at least one cache level.

[0098] The composition of the L3 cluster is shown below, in FIG. 4. As mentioned above, each L3 cluster contains several processor clusters 350. Each processor cluster 350 contains an L2 memory cache 320 and one or more processors 300 with L1 memory caches 310. There is one prefetcher 100 for each processor 300. Prefetcher 100 is connected to both processor 300 and L1 cache 310. The diagram does not consider instruction caching because prefetcher 100 is only connected to the data cache closest to processor 300. A system may share caches for instructions and data or have separate instruction and data caches. There may also be different schemes at different levels (e.g. separate L1 caches for instructions and data with combined L2 caches that contain both instructions and data) .

[0099] A standard, coherent memory caching scheme is used. Processor 300 issues load and store instructions to L1 cache 310 which either loads data from main memory 340 or stores new data to main memory 340. If the memory location for a load operation is not contained in L1 cache 310, then a data fill request is triggered to copy the data into L1 cache 310. The data fill request propagates through all the cache levels until a copy of the data is found. As an example, if the data was found in L2 cache 320, then L2 cache 320 returns the data to L1 cache 310. If it was not found in L2 cache 320, then the request is propagated to L3 cache 330 or even main memory 340 to obtain the data. Stores to main memory 340 use the same procedure. Typically, a data store operation writes data that is smaller than a full cache line. During a store operation, the memory cache system first performs a cache fill request to load the cache line into L1 cache 310. After the cache line is written in L1 cache 310, the store operation proceeds to overwrite part of the cache line. The modified cache line is returned to main memory 340.

[0100] Prefetcher 100 also issues data fill requests to L1 cache 310 and loads data from L1 cache 310. If prefetcher 100 issues a fill request to L1 cache 310 and that data is already in L1 cache 310 then no further action is required. Prefetcher 100 will not load data for each stream type. Prefetcher 100 only needs to load data for the master and parent streams of indirect streams. In an alternative implementation, prefetcher 100 maintains a list of data locations stored in L1 cache 310. In such an implementation, prefetcher 100 would only send cache fill requests for memory locations that are not already stored in L1 cache 310.

[0101] Each prefetcher 100 has three interfaces with its processor 300. The first interface (config) is a configuration interface used by software to program the nested loop stream configurations and their linkages. The second interface (monitor) allows prefetcher 100 to monitor which instructions are executed by processor 300. Prefetcher 100 uses the monitor  interface to track the progress of software and determine when flow control events are required. The third interface (read) is a read data interface that is used by processor 300 to read the configuration and internal state data of prefetcher 100. It is used to save the internal state of prefetcher 100 during context switch save and restore cycles. The first interface (config) is also used to restore the internal state of prefetcher 100 during content switch restore events.

[0102] The general flow in a server application is described below.

[0103] 1. Software running on processor 300 configures prefetcher 100 with the stream parameters and their linkages. When complete, processor 300 starts prefetcher 100 and begins execution the nested loop.

[0104] 2. Prefetcher 100 begins processing the streams and generating fill requests to L1 cache 310. The logic in Prefetch Generator 30 in prefetcher 100 emulates the nested loop structure of the main software program. Prefetcher 100 maintains counters that emulate the induction streams used to control the loops. Prefetcher 100 increments the emulated induction streams with the same initial values, increment values, and final values that are used by software. Even though prefetcher 100 processes the same streams as software, each step is first performed by prefetcher 100.

[0105] 3. L1 cache 310 processes the fill data requests and, if needed, propagates the requests to other levels of cache or main memory 340. If the request was propagated beyond L1 cache 310, then the fill data is eventually returned back through the cache hierarchy to L1 cache 310.

[0106] 4. Prefetcher 100 loads data for master streams and dependent streams with indirect child streams from L1 cache 310 for the further processing. Prefetcher 100 monitors the returning data to L1 cache 310 to know when data is available in L1 cache 310. If a stream is not a master or parent stream then prefetcher 100 does not need to track when the fetch requests are completed.

[0107] 5. Prefetcher 100 monitors the instructions executed by software and performs flow control operations as needed. The flow control operations prevent prefetcher 100 from being too far ahead of software or allow  prefetcher 100 to recover from scenarios in which it is falling behind software.

[0108] Flows #2 to #5 are continuous and interleaved throughout different iterations of the nested loop streams. Whenever an induction stream counter is changed, all the dependent streams use the new value to generate the direct prefetch requests. Whenever the prefetch requests for dependent parent streams are complete, prefetcher 100 loads the parent data into buffer 50. When parent data is available in buffer 50, indirect streams generate prefetch requests. Whenever an inner loop induction stream reaches its final value, the outer loop induction stream moves to the next value. When all the master stream values are loaded into buffer 50, the inner stream configuration parameters are updated.

[0109] To improve performance, prefetcher 100 may request master stream values before they are needed by the inner loop and store them in buffer 50. When an inner loop completes, new master values are taken from buffer 50 and used by the next iteration of the inner loop. When master values are removed from buffer 50, the outer loop may request a new set of master loops. The master streams may operate several iterations ahead of the values used by the inner loop. This prevents the inner loop from being stalled while waiting for the outer loop.

[0110] Due to different delays throughout the cache and memory cache system, the cache fill requests may be reordered by the memory cache system. Induction and direct stream prefetch requests operate in the exact same order as in the software flow. Indirect streams may be issued in an order that is approximately the same as the program flow. Indirect streams depend on loading data from dependent streams, but the memory cache system may return cache fills in a different order than they were requested. The flow control mechanism will make sure that they are approximately in program order.

[0111] The previous description has assumed that processor 300 is single-threaded and only runs one software program at a time. High-performance processors may execute more than one thread at the same time (typically two) . Prefetcher 100 supports multi-thread processors with either of the following two options:

[0112] 1. Each running thread contains a different prefetcher block. To prevent security leaks, each thread can only see one prefetcher block.

[0113] 2. Prefetcher 100 contains a different Nested Stream Configuration table 40 for each thread. Prefetch Generator 30 processes each thread either serially or in  parallel. To prevent a security risk, each thread can only see one Nested Stream Configuration table 40 and can only read the internal state for its own set of streams.

[0114] FIG. 5 shows prefetcher 100 used in a GPU system such as a video card or a GPU server, according to an embodiment of the disclosure. Mobile handsets often employ small GPUs directly in the processor chip. A GPU system is designed for wide vector calculations with very high memory bandwidth. It is ideal for graphics processing algorithms, but may also be used for machine learning algorithms.

[0115] The GPU contains arrays 560 of small Processor Units (PR) 500. A processor array 560 acts as a vector processor with each PR 500 processing one element of a vector. An Instruction Unit 570 broadcasts the same instruction to each PR 500 in the array 560 processing a Single Instruction, Multiple Data (SIMD) vector calculation. Processor array 560 acts as a scalable vector processor with the number of PR units 500 in the array 560 determining the maximum vector length. Each processor array 560 in the diagram has an L1 memory cache 510. A cluster 550 of processor arrays 560 share an L2 cache 520. Topology parameters such as the number of PR units per array or processor arrays per cluster 550 are not important. The topology in FIG. 5 serves as an example only. In addition, in FIG. 5, multiple processor clusters 550 share the same main memory 540. In different implementations, there may also be more or fewer cache levels. The exact topology of the memory hierarchy is not important, and each prefetcher 100 will operate as long as there is at least one cache level.

[0116] In a GPU application, the operation of prefetcher 100 is essentially the same as in a server CPU application. There is one prefetcher 100 for processor array 560. Prefetcher 100 is configured by higher-level software and monitors instruction unit 570 to perform prefetching flow control. Prefetcher 100 issues prefetch commands and data loads to L1 cache 510. For dependent streams without children, the prefetches may be requested to fill either L1 cache 510 or a different level. Master streams or dependent streams that are parents of other streams must be fetched to L1 cache 510 and loaded for further processing. The operation of prefetcher 100 is the same as a server application.

[0117] Because a GPU supports very wide vectors, the vector support features in prefetcher 100 are important. The GPU may also support very wide cache lines. For wide cache lines, the ability of prefetcher 100 to merge prefetches into single cache line fill requests is also  important. Traditional graphics applications work well with dense matrix calculations, but many newer Artificial Intelligence (AI) or Machine Learning (ML) applications use sparse matrix calculations. This makes prefetcher 100 very useful when a GPU is used for AI and ML applications.

[0118] For example:

[0119] for (j=0; j<10000; j=j+8)

[0120] A = B [j]

[0121] C = B [j+1]

[0122] D = B [j+2]

[0123] for (k = C; k < D; k=k+1)

[0124] ….

[0125] In this example, A, C, and D will all use the same cache line. C and D are master streams that control the inner loop but A is not. The prefetch A is first and sends the cache fill request. C and D wait for A because they need the same memory fill request that A already sent. In that sense, the memory fill requests for A, C, and D have been merged.

[0126] When the data is written into the cache, nothing is done for A. Only C and D need to copy data from the cache. B [j+1] is copied for C and B [j+2] is copied for D.

[0127] FIG. 6 shows an embodiment of prefetcher 100 in a Neural Processing Unit (NPU) system. An NPU system is optimized for Artificial Intelligence (AI) and Machine Learning (ML) applications and may be used in a large server system or on a handheld mobile device.

[0128] The NPU 620 is a specialized processor for performing matrix calculations or other calculations common in machine learning algorithms. It contains an array 610 of processors 600 that are optimized to perform a small number of computations such as Multiply-and-Accumulate (MAC) operations. NPU 620 performs many calculations per cycle. This requires that large amounts of data be loaded from main memory 640 and cached in data buffer 660. NPU 620 is similar to a GPU but only supports a limited number of instructions and computation types. Note that this example is an illustrative example of an NPU 620 that only supports MAC operations. A particular NPU implementation may support more complicated instructions, but the exact number and type is not important.

[0129] MAC array 610 acts as a vector processor and data buffer 660 acts as a single level cache. A traditional NPU has a Direct Memory Access (DMA) engine that fills data buffer 660 with data elements from main memory 640 at a very high data rate. A typical NPU DMA engine performs very well with dense matrices, but has difficulty with sparse matrices and the irregular data patterns that they generate.

[0130] If an NPU can handle sparse matrices then prefetcher 100 acts as an accelerator to prefill data buffer 660 before it is needed. To do this, NPU 620 requires complex instructions to extract the sparse data pattern and fill data buffer 660 with the correct data. If NPU 620 does not contain the correct complex instructions to extract sparse data, then prefetcher 100 can be used as the DMA engine for NPU 620. In this embodiment, the operation of prefetcher 100 is slightly different than the CPU embodiment. When prefetcher 100 performs as a DMA engine, then processor array 610 will wait for prefetcher 100 to fill the required data before starting its calculations. Processor array 610 will monitor the progress of prefetcher 100 to make sure that the data is ready. This means that prefetcher 100 never needs to use flow control to get ahead of software. Prefetcher 100 will fetch all data without skipping or discarding data stream elements. Prefetcher 100 will use flow control to prevent the data from getting too far ahead of software, but can never fall behind software. The control logic of NPU 620 will need to check the internal state of prefetcher 100 to know when the data is ready.

[0131] Prefetcher 100 can also be used to fetch dense matrices as well as sparse ones. Prefetcher 100 can fetch dense matrices at the same rate as a normal DMA engine, but prefetcher 100 is much better than a DMA engine when fetching sparse matrices. A dense matrix will have no indirect streams.

[0132] An NPU embodiment might also be implemented using a Field Programmable Gate Array (FPGA) . In an FPGA embodiment, MAC array 610, MAC controller 630, DMA controller 650, and prefetcher 100 would be implemented in an FPGA device. Data buffer 660could be implemented in either FPGA internal memory or using a fast, external memory. The advantage of an FPGA embodiment is that MAC processors 600 can be customized to fit the requirements of the application. A system might even substitute MAC processors 600 for a different type of processer that performs a different type of data processing. An FPGA embodiment may be reconfigured differently for each new software application that is loaded into the system.

[0133] Generally, prefetchers according to embodiments of the disclosure may process scalable vector instructions in which software does not know how many vector elements are processed per instruction. This may allow prefetching for high-performance computing technologies such as CPUs with ARM SVE, CPUs with Intel AVX-512, Graphics Processing Units, and Neural Processing Units.

[0134] Furthermore, prefetchers according to embodiments of the disclosure may use sophisticated adaptive control mechanisms to recover from situations where prefetching has fallen behind software or is in danger of falling behind. This may include skipping loop iterations and discarding prefetches in progress. This may allow the prefetcher to only prefetch data which is beneficial to software and prevents situations where the prefetcher reduces performance by congesting the memory cache system with unnecessary requests.

[0135] For instance, consider the following example:

[0136] for (j=0; j<10000; j=j+8)

[0137] A = B [j]

[0138] C = B [j+1]

[0139] D = B [j+2]

[0140] for (k = C; k < D; k=k+1)

[0141] E=F [k]

[0142] G=H [E]

[0143] Everything is controlled by the counters (induction streams) j and k. There are actually four counters j_software, k_software, j_prefetcher, and k_prefetcher. The prefetcher counters are maintained inside the prefetcher and are used to generate prefetches. The software counters are used by the real software for data processing. Program Monitor 10 measures the software counters by examining the program flow. For proper prefetching, the prefetcher must be executing processes before software, i.e. j_prefetcher > j_software and k_prefetcher > k_software.

[0144] Adaptive Prefetch Rate Control 20 performs various flow control actions to maintain optimal run ahead values, run_ahead_j = j_prefetcher –j_software and run_ahead_k =k_prefetcher –k_software.

[0145] If k_prefetcher < k_software then the prefetcher for stream k has fallen behind software. There is no point using the current value of k_prefetcher. That data is no longer needed and any prefetch requests for E and G are not needed. A new value of k_prefetcher must be picked to restore the prefetcher to a proper state and in-progress prefetches for E and G should be discarded.

[0146] If j_prefetcher < j_software then the prefetcher has really fallen behind. Both the inner and outer loops are behind. In that scenario, everything in progress by the prefetcher is no longer needed and should be discarded.

[0147] If run_ahead_k is less than zero then the prefetcher has fallen behind software. If run_ahead_k is steadily decreasing and far from the optimal value then the prefetcher is at risk of falling behind software.

[0148] Furthermore, prefetchers according to embodiments of the disclosure may assigns different priorities to different types of streams based on their relationship to other streams in the nested loop hierarchy. This may prevents performance issues with head of line blocking. In a nested loop, delays in master stream prefetches will block many iterations of the inner loop. Delays in inner loop streams which are not parent streams do not block other streams.

[0149] Furthermore, prefetchers according to embodiments of the disclosure may merge prefetches to the same cache line into a single fill request and then split them into multiple data load operations if they are needed as master or parent streams for the generation of other prefetches. This may minimize the number of fill requests in the memory cache hierarchy to reduce congestion and power. This also allows software to configure the prefetcher without knowledge of the underlying cache line size.

[0150] Furthermore, prefetchers according to embodiments of the disclosure can be used to prefetch data record structures stored in memory that are connected by linked-lists. In a linked-list data structure, each data structure contains a set of data fields. One of those fields is a pointer to the next data structure in the list. To trace the linked-list, an indirect stream must be its own parent. The indirect stream fetches data from memory and that data contains the location of the next data record in the list. The indirect linked-list stream needs a starting location, but after that it continuously issues a prefetch, loads the prefetched data, and calculates the next prefetched location in the list. The initial value could be configured by software or it could come from a master stream. Other data in the record are indirect streams that have the linked-list stream as their parent stream. A processor using this system could  automatically traverse a linked-list and prefetch the data contained in that list. Example software for tracing linked-listed is shown below.

[0151] A = InitialValue

[0152] for (j = 0; j < 1000; j = j+1) {

[0153] B = A [j]

[0154] C = A [j+1]

[0155] D = A [j+2]

[0156] A = A [j+3]

[0157] }

[0158] Streams B, C, and D contain the data fields associated with each record. Stream A is the memory address where each record is located.

[0159] Optionally, the indirect linked-list stream could have a final value stored in the configuration or a master stream. When the prefetched data equals the final value, the stream is complete.

[0160] In addition, the prefetcher could be modified to perform instruction prefetching. Take the following software code as an example:

[0161] In this software, the value of the data M determines which software function is used to process data N. In addition to prefetching all the data elements, a modified prefetcher could be used to prefetch the correct instructions into the cache. It would need a new Function Table that contains the function base addresses for FunctionCall0 to FunctionCall4. Prefetch Generator 30 checks which condition is true. Using the result of the condition check, the Prefetch Generator 30 generates an instruction prefetch by looking up the correct address in the Function Table. The prefetcher may generate both data and instruction space prefetches.

[0162] The terms “a” or “an” when used in conjunction with the terms “comprising” or “including” in the claims and / or the specification can mean “one” but it is also consistent with the meaning of “one or more” , “at least one” , and “one or more than one” unless the content clearly dictates otherwise. Similarly, the word “another” may mean at least a second or more, unless the content clearly dictates otherwise.

[0163] As used herein, reference to “about” or “approximately” a number or “substantially” is equal to a number means within + / -10%of the number.

[0164] While the disclosure has been described in connection with specific embodiments, it is to be understood that the disclosure is not limited to these embodiments, and that alterations, modifications, and variations of these embodiments may be carried out by the skilled person without departing from the scope of the disclosure.

[0165] It is furthermore contemplated that any part of any aspect or embodiment discussed in this specification can be implemented or combined with any part of any other aspect or embodiment discussed in this specification.

Claims

1.A system comprising:a memory for storing data;at least one cache for storing data copied from the memory to the cache;a processor for executing software code and, based on the software code, reading data from the cache or the memory; anda prefetcher for generating prefetch requests to prefetch data from the memory and store copies of the prefetched data in the cache,wherein the prefetcher is configured, while processing a data stream generated by compiling of the software code, to:identify, based on the processing of the data stream, a scalable vector processing instruction in the software code executed by the processor;identify, based on the scalable vector processing instruction, a number of data elements that have been processed by the processor; andgenerate one or more prefetch requests for prefetching, from the memory, a number of data elements corresponding to the identified number of data elements, and for storing a copy of the prefetched number of data elements in the cache.2.The system of claim 1, wherein the data stream comprises at least one inner loop nested within at least one outer loop.3.The system of claim 1 or 2, wherein the prefetcher is enabled to generate the one or more prefetch requests by one or more of:a compiler for compiling the software code; andthe software code.4.The system of any one of claims 1 to 3, wherein the prefetcher is further configured to:determine that a pending prefetch request has been discarded; andre-generate the discarded prefetch request.5.The system of any one of claims 1 to 4, wherein the prefetcher is further configured to:determine that a first prefetch request and a second prefetch request map to a common cache line in the cache, wherein the second prefetch request is for data that is not in a master stream and not in a parent stream of the data stream; andin response to determining that the first prefetch request and the second prefetch request map to the common cache line, discard the second prefetch request.6.The system of any one of claims 1 to 5, wherein the prefetcher is further configured to:determine that a first prefetch request and a second prefetch request map to a common cache line in the cache, wherein the first prefetch request is for data in a master stream or a parent stream of the data stream; andin response to determining that the first prefetch request and the second prefetch request map to the common cache line, delay execution of the second prefetch request.7.The system of claim 6, wherein the prefetcher is further configured to:delay execution of the second prefetch request until each data element prefetched by the first prefetch request is processed in the master stream or the parent stream.8.The system of any one of claims 1 to 7, wherein the prefetcher is further configured to:determine that data copied from the memory to the cache has been evicted; andgenerate a prefetch request for prefetching the evicted data from the memory and storing a copy of the evicted data in the cache.9.The system of any one of claims 1 to 8, wherein the prefetcher is further configured to:for each of one or more prefetch requests:determine whether the prefetch request is for data in the inner loop or the outer loop; andassign, based on the determination, a priority to the prefetch request.10.The system of claim 9, wherein the prefetcher is further configured to:execute, based on each assigned priority, the one or more prefetch requests.11.The system of any one of claims 1 to 10, wherein the prefetcher is further configured to:determine whether the prefetcher is at risk of generating a prefetch request for data that is not yet needed, or no longer needed, by the processor; andcontrol, based on the determination, the processing of the data stream by the prefetcher.12.The system of claim 11, wherein the prefetcher is configured to determine whether the prefetcher is at risk of generating a prefetch request for data that is not yet needed, or no longer needed, by the processor, by:comparing, based on the data stream, an induction stream associated with the processor to an induction stream associated with the prefetcher.13.The system of claim 11 or 12, wherein the prefetcher is further configured to:determine that the processing of the data stream by the prefetcher is ahead of the execution of the software code by the processor; andin response to the determination, pause processing by the prefetcher of one or more loops in the data stream.14.The system of any one of claims 11 to 13, wherein the prefetcher is further configured to control the processing of the data stream by:delaying the generation of one or more prefetch requests.15.The system of any one of claims 11 to 14, wherein the prefetcher is further configured to control the processing of the data stream by:discarding one or more pending prefetch requests; orskipping execution of one or more prefetch requests whose execution has not yet begun.16.The system of claim 15, wherein the one or more prefetch requests are for data that, based on the execution of the software code by the processor, is currently not needed by the processor.17.The system of claim 15 or 16, wherein the one or more prefetch requests are for data in one or more non-master loops of the data stream.18.The system of any one of claims 11 to 17, wherein the prefetcher is further configured to control the processing of the data stream by:skipping one or more iterations of one or more loops in the data stream.19.The system of claim 18, wherein the one or more loops correspond to instructions that have already been executed by the processor.20.The system of any one of claims 11 to 19, wherein:the at least one cache comprises a first cache and a second cache; andthe prefetcher is configured to control the processing of the data stream by:modifying a pending prefetch request targeting the first cache so that the pending prefetch request targets the second cache.21.The system of any one of claims 11 to 20, wherein data stored in the memory comprises one or more instructions.22.A computer-implemented method of using a prefetcher for prefetching data from a memory, comprising:identifying with the prefetcher, based on a data stream being processed by the prefetcher, a scalable vector processing instruction in software code executed by a processor, wherein the data stream is generated by compiling of the software code;identifying with the prefetcher, based on the scalable vector processing instruction, a number of data elements that have been processed by the processor;generating with the prefetcher one or more prefetch requests; andusing the one or more prefetch requests to prefetch, from the memory, a number of data elements corresponding to the identified number of data elements, and to store a copy of the prefetched number of data elements in a cache for retrieval by the processor.

Citation Information

Patent Citations

  • Event triggered programmable prefetcher

    CN108463808A

  • Adaptive instruction prefetching and fetching memory system apparatus and method for microprocessor system

    US20140115569A1

  • Method and apparatus for remote prefetches of variable size

    US20170353576A1