This invention relates generally to data processing systems. More particularly, this invention relates to a data processing system that processes vector data.
It is known that effects of memory access latencies in a data processing system may be mitigated by moving elements of vector data into a local, high-speed memory known as a cache. The elements are moved, or prefetched, into the cache before they are needed so that they are readily available when requested. If the elements are in a predictable order, there is no theoretical limit to how far in advance the elements may be fetched. However, since the cache has a limited size, if elements are fetched too far in advance, prior elements may be displaced from the cache before they have been used. This can lead to the phenomenon of “thrashing”, where an element is prefetched and displaced multiple times before they are used. As a consequence, the performance of the data processing system may be worse than if no cache is used.
One approach to prevent thrashing is to prefetch elements directly from memory or indirectly via a cache into a sequentially ordered storage memory or queue. Once queued, elements remain in the queue until used, thus reducing thrashing. A disadvantage of this approach is that repeated accesses to an element either within or between vectors will result in the element being duplicated in the queue as well as in the cache. Additionally, if the element is evicted from the cache before subsequent prefetches, then the element must be fetched from memory again. In the worse case, this would result in a performance similar to having no cache.
Another approach is to provide prefetch instructions and place the burden on the programmer to use them in a manner that avoids thrashing. A disadvantage of this approach is that changes in the sparseness of the vector elements, the number of vectors, the memory access latency and even cache line replacement policy can require changes in the placement of the prefetch instructions.
The novel features believed characteristic of the invention are set forth in the appended claims. The invention itself, however, as well as the preferred mode of use, and further objects and advantages thereof, will best be understood by reference to the following detailed description of an illustrative embodiment when read in conjunction with the accompanying drawing(s), wherein
While this invention is susceptible of embodiment in many different forms, there are shown in the drawings and will herein be described in detail one or more specific embodiments, with the understanding that the present disclosure is to be considered as exemplary of the principles of the invention and not intended to limit the invention to the specific embodiments shown and described. In the description below, like reference numerals are used to describe the same, similar or corresponding parts in the several views of the drawings.
An exemplary embodiment of a system of the present invention is shown in
The cache 100 includes a high speed cache memory 108, in which the data is arranged in lines. It will be obvious to those of ordinary skill in the art, that the cache memory 108 may be arranged in sub-regions of any shape. Hence, when reference is made to a line of the cache, it is to be understood that this is equivalent to a sub-region of the cache memory. Multiple data element vectors may be stored in a sub-region. The cache 100 may be shared between multiple data consumers 106. The cache includes a number of cache line counters 110 (also called, more simply, “counters”). Each cache line counter 110 is associated with a cache data line in the cache memory 108. A plurality of cache line counters may be associated with one cache data line. In operation, when a prefetch instruction is processed, a corresponding cache line counter is incremented. A prefetch instruction is an instruction to prefetch a vector data element from a memory into the cache. When a vector data element is used (also called “consumed”) by a consumer 106, the corresponding cache line counter or counters are decremented. Data elements cannot be evicted from the cache unless the corresponding cache line counter or counters indicate that all of the prefetched data has been used. In this state, the cache is described as ‘locked’.
In this embodiment, the cache data line is ‘unlocked’ when all of the associated counters are zero. This ensures data persistency, that is, data cannot be evicted from the cache before it is consumed and cache thrashing is avoided.
In one embodiment of the invention, a counter is initialized to zero and is increment by one when a prefetch instruction is processed and decremented by one when a data vector element is consumed (unless the counter is already zero). However, it will be obvious to those of ordinary skill in the art that the counters may count up or down and may start at any value without departing from the present invention. Hence the term ‘incremented’ is taken to mean the addition of a positive number or a negative number. Similarly, the term ‘decremented’ is taken to mean the subtraction of a positive number or a negative number. In an alternative embodiment, separate counters are used for counting prefetch requests and data retrievals. The difference between the counters is then used to determine if all prefetched data has been consumed, at which point the counters can be reset and the cache line unlocked.
Since the cache line counter is incremented when a prefetch instruction is processed and decremented when the element is consumed, the cache line counter indicates the excess of prefetches over consumptions. Thus, when the counter is at zero (or its initial value) all of the requested data has been consumed. When all of the counters for a particular cache line are zero it is safe to evict the data in the cache line, and the cache line is unlocked.
Data flow is controlled by one or more data controllers 112 which duplicate the prefetch order of the vector data. A data controller may be a vector stream unit, for example, that allows ordered data values in a vector to be accessed in response to a single instruction. A vector stream unit can do this by regenerating the prefetch order of the memory addresses of the elements. If more than one data controller is used, as for example in a parallel processor, each data controller may have a cache line counter for each data line. For example, referring the
In one embodiment of the invention, the order of the prefetched vector data elements is maintained by one or more reference queues 114 that store the cache locations of the prefetched vector data elements. One reference queue 114 may be used for each data controller 112. This eliminates the need to regenerate the memory addresses of elements as they are used, as well as eliminating the need for address matching hardware for elements being read from the cache. The depth of the reference queue 114 is related to the latency of memory fetches, since the reference queue is updated when a request for an element to be prefetched is made, rather than when the element becomes available in the cache memory 108.
By providing a counter 110 for each cache line and for each data controller 112, multiple vectors can share the cache line. Only when all of the counters for a cache line are zero (or have returned to their initial values) can its data be evicted. Thus, any data in a cache line that has any non-zero counters is effectively and automatically locked down and data cannot be evicted.
However, unlocked data remains until the cache line is actually reused, and therefore prefetches can reuse data that is in the cache memory 108 without the need to access the memory 102 again. Thus, when a prefetch instruction is processed, the memory 102 need not be accessed if the data element is already stored in cache memory 108.
The amount of prefetching is limited by the prefetch address generator units 104 to a predetermined number of cache lines that are allowed to be locked down per vector. Since the latency of prefetching a cache line is directly related to the memory access latency, this makes it easy to automatically tune the amount of prefetch to match the memory access latency without programmer intervention.
If no unlocked cache lines are available when a prefetch instruction is received at block 202, and the element is not already in the cache at block 204, the prefetch address generator unit 104 may be stalled at the negative branch of block 206 until a cache line becomes available. Neither the reference queue nor the cache line counter is updated until a cache line becomes available. While the prefetch address generator is stalled, the prefetch instruction is not processed.
If the requested data vector element is already in the cache memory, as indicated by the positive branch from decision block 204, flow continues to block 214 and the cache line counter associated with the cache line is incremented. This also completes a prefetch into the cache memory. At this time, the data vector element is stored in the cache ready for use, and the process terminates at block 216.
In one embodiment, a cache line may be shared between multiple AGU's. In this embodiment, a cache is allocated to a first AGU. When addresses from another AGU are covered by the same cache line, the cache line counter corresponding to that AGU is updated accordingly. In this way, only one memory access is performed to fill the cache line and the cache line is shared by multiple AGU's.
In a further embodiment, multiple vectors can share the same cache line. For example, a cache is allocated to a first AGU. When addresses from another AGU are not covered by the cache line, a further memory access is performed and the cache line counter corresponding to that AGU is updated accordingly.
The method reduces the load on the memory access unit, since multiple prefetch instructions for the same data vector element only require a memory access for the first prefetch instruction; thereafter, processing of the prefetch instruction only requires the cache line counter to be incremented.
The cache system may be used in a variety of applications, but has application to vector processors and vector co-processors.
The present invention has been described in terms of exemplary embodiments. It will be obvious to those of ordinary skill in the art that the invention may be implemented using hardware component such as special purpose hardware and/or dedicated processors. Similarly, general purpose computers, microprocessor based computers, digital signal processors, microcontrollers, dedicated processors, custom circuits, ASICS and/or dedicated hard wired logic may be used to construct alternative equivalent embodiments of the present invention.
While the invention has been described in conjunction with specific embodiments, it is evident that many alternatives, modifications, permutations and variations will become apparent to those of ordinary skill in the art in light of the foregoing description. Accordingly, it is intended that the present invention embrace all such alternatives, modifications and variations as fall within the scope of the appended claims.