1 / 16

Using the Compiler to Improve Cache Replacement Decisions

Using the Compiler to Improve Cache Replacement Decisions. Zhenlin Wang, UMass Amherst Kathryn S. McKinley, UT Austin Arnold L. Rosenberg, UMass Amherst Charles C. Weems, UMass Amherst. Motivation and Background. LRU is not always effective

idra
Download Presentation

Using the Compiler to Improve Cache Replacement Decisions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Using the Compiler to Improve Cache Replacement Decisions Zhenlin Wang, UMass Amherst Kathryn S. McKinley, UT Austin Arnold L. Rosenberg, UMass Amherst Charles C. Weems, UMass Amherst

  2. Motivation and Background • LRU is not always effective • Optimal cache replacement must peek into the future • Compiler locality analysis determines data access pattern for numeric applications • Cache line tag bit(s) and ISA extension control cache replacement explicitly • Replacement logic augments LRU with compiler hints Improving Cache Replacement Decisions

  3. C[2]B[2] C[3]B[3] … ... … … C[128]B[128] A[3] A[128] LRU vs. Compiler Control 2-way cache with LRU SUBROUTINE TEST(N) INTEGER A[N],B[N],C[N] DO I = 1,N C[I] = A[I] + B[I] ENDDO DO I = 1,N A[I] = C[I] * 5 ENDDO END A[1] Set 1 C[1] A[1] B[1] A[2] Set 2 Set 3 Set 128 ( N=128 ) Improving Cache Replacement Decisions

  4. Compiler Locality Analysis Spatial (=,<) Spatial (=,<) Spatial (=,<) SUBROUTINE TEST(N) INTEGER A[N],B[N],C[N] DO I = 1,N C[I] = A[I] + B[I] ENDDO DO I = 1,N A[I] = C[I] * 5 ENDDO END B[I] at N1 [1:N:1] C[I] at N1 [1:N:1] A[I] at N1 [1:N:1] Cross-loop [1:N:1] Cross-loop [1:N:1] temporal temporal A[I] at N2 [1:N:1] C[I] at N2 [1:N:1] Spatial (=,<) Spatial (=,<) Locality Graph Improving Cache Replacement Decisions

  5. An Abstract Model • An optimal algorithm uses exact reuse distances • Given trace a b c d a c d e b f a, reuse distance of a is 4 • Reuse level: a range in which the next reuse will occur • [i,j] < [k,l], if j < k • For example, a reuse level of a is [3,5]. (a b c d a c d e b f a) • We combine data dependences with loop iteration point to compute reuse levels • For example, (=, <) < ( <, =) 4 Improving Cache Replacement Decisions

  6. The Architecture: Evict-Me bit • Inspired by the Alpha 21264 prefetch-and-evict-next and evict instruction • Each cache line has an extra evict-me bit • On a replacement, choose the cache line with the evict-me bit set • Use LRU policy if no evict-me bits are set • Extend ISA with load/store instructions that set the evict-me bit Improving Cache Replacement Decisions

  7. Heuristics for Setting Evict-me Bits • On a replacement, evict the cache line if its evict-me bit is set, otherwise, use the LRU bits • Compiler heuristics: • Set evict-me bit if the reuse distance of a reference is greater than cache size • Intuition: even a fully set associative cache can not exploit the reuse • Reuse level: [1, cache size], [cache size+1, ] • Volume based heuristics • Its reuse crosses nests whose data volume is greater than 2*cache size • Or reuse crosses nests of nesting level >=2 Improving Cache Replacement Decisions

  8. Algorithm for Setting Evict-me Bits • Mark evict-me bit for an array reference if • It has no temporal locality in its nest • Its reuse crosses nests whose data volume > 2*cache size • Spatial locality is resolved by run time address calculation or loop unrolling Do I = 1 : N …A(I)… ENDDO Do I = 1 : N …A(I)… …A(I+1)… …A(I+2)… …A(I+3)… ENDDO A[1] A[2] A[3] 0 1 Improving Cache Replacement Decisions

  9. A[2] 0 C[2]0 A[3] 0 C[3]0 … ... … … … … A[128] 0 C[128]0 Evict-me: An Example 2-way cache with evict-me SUBROUTINE TEST(N) INTEGER A[N],B[N],C[N] DO I = 1,N C[I] = A[I] + B[I] ENDDO DO I = 1,N A[I] = C[I] * 5 ENDDO END Set 1 A[1] 0 B[1] 1 C[1]0 Set 2 Set 3 Set 128 ( N=128 ) Nest 1 volume = 384 words < 2*256 Cache size = 256 words Improving Cache Replacement Decisions

  10. Experimental Framework • Implemented in Scale, a compiler infrastructure developed at UMass • Scale includes optimizations such as partial redundancy elimination, scalar replacement, value numbering, sparse conditional constant propagation, register allocation, etc. • Generates SPARC Assembly • Simulate the evict-Me cache with URSIM • Out of order execution • Lock up free cache • SDRAM SPARC Assembly Source code Native Assembler linker SPARC executable URSIM Scale Improving Cache Replacement Decisions

  11. Cache configurations • Both levels are lock-up free with 8 MSHRs each Size and associativity Latencies (cycles) Improving Cache Replacement Decisions

  12. Miss reduction (level 1) Improving Cache Replacement Decisions

  13. Miss reduction (level 2) Improving Cache Replacement Decisions

  14. Performance Impact of Evict-me (Conf. 2) Improving Cache Replacement Decisions

  15. Evict-me and Prefetching Combined(Conf. 3) Improving Cache Replacement Decisions

  16. Summary • Compiler can improve cache replacement decisions • Evict-me algorithm seldom degrades performance • Architectural support for evict-me is practical • Effectiveness depends on cache configuration, data set size, and access patterns Improving Cache Replacement Decisions

More Related