scieee AI-readable full text Open interactive document viewer

Coherence protocol for transparent management of scratchpad memories in shared memory manycore architectures

Álvarez Martí, Lluc,Vilanova, Lluís,Moretó Planas, Miquel,Casas, Marc,González Tallada, Marc,Martorell Bofill, Xavier,Navarro, Nacho,Ayguadé Parra, Eduard,Valero Cortés, Mateo

Abstract

The increasing number of cores in manycore architectures causes important power and scalability problems in the memory subsystem. One solution is to introduce scratchpad memories alongside the cache hierarchy, forming a hybrid memory system. Scratchpad memories are more power-efficient than caches and they do not generate coherence traffic, but they suffer from poor programmability. A good way to hide the programmability difficulties to the programmer is to give the compiler the responsibility of generating code to manage the scratchpad memories. Unfortunately, compilers do not succeed in generating this code in the presence of random memory accesses with unknown aliasing hazards. This paper proposes a coherence protocol for the hybrid memory system that allows the compiler to always generate code to manage the scratchpad memories. In coordination with the compiler, memory accesses that may access stale copies of data are identified and diverted to the valid copy of the data. The proposal allows the architecture to be exposed to the programmer as a shared memory manycore, maintaining the programming simplicity of shared memory models and preserving backwards compatibility. In a 64-core manycore, the coherence protocol adds overheads of 4% in performance, 8% in network traffic and 9% in energy consumption to enable the usage of the hybrid memory system that, compared to a cache-based system, achieves a speedup of 1.14x and reduces on-chip network traffic and energy consumption by 29% and 17%, respectively.

Full text

Coherence Protocol for Transparent Management of Scratchpad Memories in Shared Memory Manycore Architectures Lluc Alvarez†§ Lluís Vilanova†§ Miquel Moreto†Marc Casas†Marc Gonzàlez§ Xavier Martorell†§ Nacho Navarro†§ Eduard Ayguad醧 Mateo Valero†§ †Barcelona Supercomputing Center §Departament d’Arquitectura de Computadors {first.last}@bsc.es Universitat Politècnica de Catalunya Abstract The increasing number of cores in manycore architectures causes important power and scalability problems in the memory subsystem. One solution is to introduce scratchpad memories alongside the cache hierarchy, forming a hybrid memory system. Scratchpad memories are more power-efficient than caches and they do not generate coherence traffic, but they suffer from poor programmability. A good way to hide the programmability difficulties to the programmer is to give the compiler the responsibility of generating code to manage the scratchpad memories. Unfortunately, compilers do not succeed in generating this code in the presence of random memory accesses with unknown aliasing hazards. This paper proposes a coherence protocol for the hybrid memory system that allows the compiler to always generate code to manage the scratchpad memories. In coordination with the compiler, memory accesses that may access stale copies of data are identified and diverted to the valid copy of the data. The proposal allows the architecture to be exposed to the programmer as a shared memory manycore, maintaining the programming simplicity of shared memory models and preserving backwards compatibility. In a 64-core manycore, the coherence protocol adds overheads of 4% in performance, 8% in network traffic and 9% in energy consumption to enable the usage of the hybrid memory system that, compared to a cache-based system, achieves a speedup of 1.14x and reduces on-chip network traffic and energy consumption by 29% and 17%, respectively. 1. Introduction Future generations of multicore and manycore architectures are expected to include a significant number of cores. As an This paper is published in Proceedings of the 42nd Annual International Symposium on Computer Architecture (ISCA’15), 2015, pp. 720-732. The final publication is available at http://dx.doi.org/10.1145/2749469.2750411. immediate consequence, the memory system that connects these computing elements needs to be revisited in order to satisfy the inherent requirements of future chips and, at the same time, avoid the inefficiencies of current schemes when cores are replicated beyond certain levels [31, 35, 39]. Cache coherent shared memory has traditionally been the favorite memory organization for multicore chips. The major reason for the success of this approach is its high programmability, that is achieved by moving data and keeping it coherent between all the caches of the system without any intervention from the programmer. Unfortunately, the cost of performing these actions becomes an obstacle to scaling up the number of cores, being the primary concerns the power consumption originated in the caches and the increasing amount of coherence traffic in the Network on-Chip (NoC). Scratchpad memories [ 9 ] (SPMs) are a well-known alternative to cache hierarchies. The simplicity of SPMs allows them to serve memory accesses as fast as caches but in a much more power-efficient way and without originating coherence traffic. However, SPMs suffer from poor programmability as the software is responsible of explicitly transferring data and keeping different copies of the data in a coherent state. A recent trend in the High Performance Computing (HPC) domain is to combine caches and SPMs in the memory hierarchy, forming a hybrid memory system. Architectures such as the Cell B.E. [ 26 ] or GPUs [ 21 ] have successfully adopted this scheme in different forms, but always at the cost of breaking backwards compatibility and imposing complex programming and memory consistency models that move away from the shared memory paradigm. Unfortunately, this approach cannot be easily adopted by shared memory manycores, where backwards compatibility has a big importance and the wide majority of programming models heavily rely on strict memory models and cache coherence protocols [3]. Still, the characteristics of HPC applications [ 36 , 44 ] make appealing the adoption of the hybrid memory system in shared memory manycores. HPC applications are dominated by strided accesses, which are a natural fit for SPMs because they can be efficiently managed by software thanks to their predictability. Random accesses, on the other hand, are difficult to manage by software because of their unpredictability, so they greatly benefit from the ability of caches to automati- cally request data and keep it coherent. A promising solution to exploit these characteristics in shared memory manycores is to introduce the hybrid memory system and to give the compiler the responsibility of generating code to manage the SPMs, so that the added programming complexity is not exposed to the programmer. Even though compilers succeed in generating code for the SPMs when the computation is based on predictable memory access patterns [ 22 ], in the presence of unpredictable memory accesses they encounter important limitations. Due to the incoherence between the SPMs and the cache hierarchy, the compiler cannot generate code for the SPMs if it cannot ensure that there is no aliasing between two memory references that may target copies of the same data in the SPMs and in the cache hierarchy. This memory aliasing problem greatly restricts the ability of the compiler to generate code for the hybrid memory system in non-trivial cases. This paper proposes a coherence protocol for hybrid memory systems that allows the compiler to always generate code for the SPMs, even in the presence of memory aliasing hazards. In a hardware/software co-designed mechanism, the compiler identifies memory accesses that may access incoherent copies of data, and the hardware diverts these accesses to the memory that keeps the valid copy. The proposal allows the compiler to always generate correct code to manage the SPMs, so the hybrid memory system can be exposed to the programmer as a shared memory multiprocessor, maintaining the programming simplicity of shared memory models. Results show that the hybrid memory system, compared to cache hierarchies, provides an average speedup of 1.14x and reduces the network traffic and the consumed energy by respective averages of 29% and 17% in a 64-core manycore. The main contributions of this paper are: • A hardware coherence protocol for the hybrid memory system that, complemented with compiler support [ 5 , 6 ], achieves that all memory accesses are served by the cache or the SPM that keeps the valid copy of the data. This solution solves the memory aliasing problem to the compiler. • Modifications to the architecture of the hybrid memory system so that, together with the coherence protocol, it implements the memory consistency model assumed in most shared memory programming models. • A detailed evaluation of a manycore architecture with the hybrid memory system, especially focusing on performance, on-chip network traffic and energy consumption. This paper is organized as follows: Section 2 explains the architecture of the hybrid memory system together with its compiler and runtime support, the coherence problem it exposes and the compiler support for the coherence protocol. Section 3 presents the coherence protocol and the resulting memory consistency model. Section 4 summarizes the proposal and discusses the OS support to maintain backwards compatibility. Section 5 evaluates the resulting system, which is then compared with the related work in Section 6. Finally, Section 7 remarks the main conclusions of this work. Figure 1: Architecture of the hybrid memory system. Every core is extended with a SPM and a DMA controller (DMAC). 2. Background and Motivation This section explains the hybrid memory system, its main architectural details and its compiler and runtime support. Then it describes the coherence problem of the architecture and the compiler support for the proposed coherence protocol. 2.1. Hybrid Memory System Architecture The architecture of the hybrid memory system consists of extending every core of a multiprocessor with a SPM and a DMA controller (DMAC), as shown in Figure 1. The SPMs are added alongside the L1 cache of every core, and they are accessible by all the cores. The system reserves a range of the virtual and physical address spaces for each SPM of the chip, and direct-maps the virtual ranges to the physical ones, as shown in Figure 2. Every core keeps the address space mapping in eight registers, four to store the starting and the final virtual addresses of the local SPM and of the global range of the SPMs, and four to keep the physical address space of all the SPMs and of the local SPM. These registers are used to identify virtual addresses that access the SPMs and to do the virtual-to-physical address translation, allowing all the cores to access any SPM by issuing loads and stores to their virtual address ranges. At every memory instruction, before any Memory Management Unit (MMU) action takes place, a range check is performed on the virtual address. If the virtual address is in the range of some SPM, the MMU is bypassed and a physical address that points to the SPM is generated. Apart from the simplicity of the implementation, an important advantage of this way of integrating the SPMs [ 5 , 6 , 11 , 15 ] is that no pagination is used, so memory accesses to them do not need to lookup the Translation Lookaside Buffer (TLB), minimizing the energy consumption and ensuring deterministic latency. In addition, the typical size of SPMs is orders of magnitude smaller than the size of the RAM and the virtual address space of a 64-bit machine, so the virtual and physical address ranges reserved for the SPMs occupy a very minor portion of the whole address spaces. The DMACs transfer data between the SPMs and the global memory (GM, which includes caches and main memory). They support three operations: (1) dma-get transfers data Figure 2: Address space mapping for the SPMs. from the GM to a SPM, (2) dma-put transfers data from a SPM to the GM and (3) dma-synch waits for the completion of certain DMA transfers. Every DMAC exposes a set of memory-mapped I/O registers to the software so it can explicitly trigger the DMA operations. DMA transfers are integrated in the cache coherence protocol of the GM [ 10 , 29 ]. The bus requests generated by a dma-get look for the data in the caches and read the value from there if it exists, otherwise they read it from the main memory. The bus requests of a dma-put copy the data from the SPM to the main memory and invalidate the cache line in the whole cache hierarchy. 2.2. Compiler and Runtime Support The main drawback of the hybrid memory system is its programmability, since it is the software that must explicitly manage the SPMs. A good way to hide this complexity from the programmer is to give the compiler the responsibility of generating code that manages the SPMs using a runtime library. The first step is to identify data suitable to be mapped to the SPMs. In shared memory programming models the compiler uses analyses and code annotations provided by the programmer to decide how the data and the computation is distributed among the threads. Based on this distribution, it identifies array sections [ 37 ] that are sequentially traversed and private to each thread. These array sections are the preferred candidates to be mapped to the SPMs because the strided accesses used to traverse them are highly predictable and their privateness avoids costly data synchronization mechanisms on the SPMs. After identifying the array sections to be mapped to the SPMs the compiler does the code transformations, inserting calls to a runtime library that will manage the data transfers at execution time. For a computational loop the code is transformed into a two-nested loop that uses tiling to do the computation [ 19 , 20 , 22 , 41 ], as shown in Figure 3. Each iteration of the outermost loop executes three phases: (1) a control phase that maps chunks of the array sections to the SPMs, (2) a synchronization phase that waits for the completion of the DMA transfers, and (3) a work phase that performs the computation for the currently mapped chunks of data. These phases repeat until the whole iteration space is computed. Before entering the loop, the runtime divides the size of the SPM in equally-sized buffers in order to minimize complexity and overheads. One buffer is allocated for each Figure 3: Code transformation for the hybrid memory system. memory reference that is mapped to the SPM. In Figure 3, ALLOCATE_BUFFERS allocates two buffers to map chunks of aand b, and each buffer occupies half the size of the SPM. The control phase moves chunks of array sections between the SPM and the GM. At every instance of the control phase, in the MAP statement for each array section, the chunk of data for the next work phase is mapped to its corresponding SPM buffer with a dma-get, and the previously used chunk is written back to the GM if needed with a dma-put. Each call to MAP also sets a pointer to the first element of the buffer that has to be computed ( _a and _b ), updates the number of iterations that can be performed with the current mappings ( iters ) and sets the tags associated to the DMA transfers (tags). After waiting for the DMA transfers to finish in the synchronization phase, the work phase takes place. This phase does the same computation as the original loop, but with two differences. First, the memory references to the array sections ( a and b ) are substituted with their corresponding SPM mappings ( _a and _b ). Second, the iteration space of the work phase is limited to the number of iterations that can be performed with the chunks of data currently mapped to the SPM. 2.3. Coherence Problem The hybrid memory system opens the door to incoherences between copies of data in different coherence domains. When a chunk of data is mapped to some SPM, a copy of the data is created in its address space, and the coherence between the copy in the SPM and the copy in the GM has to be explicitly maintained because there is no hardware coherence between the two memory spaces. This issue restricts the compiler from performing the code transformation in non-trivial cases. Once the compiler has identified the array sections to be mapped to the SPMs, it changes the memory references in the work phase so that they access the copy in the SPM, while the rest of memory references access the GM. This causes that two incoherent copies of the same data can be accessed simultaneously during the computation, one via strided accesses to the SPM and the other via random accesses to the GM, resulting in an incorrect execution. In order to ensure the correctness of the code transformation, the compiler has to apply alias analyses [ 18 , 30 , 45 ] between the memory references that target the SPMs and the rest of memory references in the loop body and ensure there is no aliasing. In the example in Figure 3 this implies predicting if any instance of the accesses to c or ptr aliases with any instance of the accesses to a or b . This problem, that also affects compiler auto-vectorization and auto-parallelization [ 24 ], has not been solved in the general case, especially in the presence of pointers. A good way to solve the memory aliasing problem for the hybrid memory system is to adopt a lightweight hardware/software co-designed coherence protocol [ 5 , 6 ] that ensures the compiler can always generate correct and efficient code. The task of the compiler in the coherence protocol is to identify potentially incoherent accesses. A potentially incoherent access is a memory access that the compiler cannot ensure it will never access data in the GM that is mapped to some SPM. The compiler marks these accesses and the hardware, at execution time, checks if the data that is being accessed is mapped to some SPM and diverts the access to it. 2.4. Compiler Support for the Coherence Protocol The compiler support for the coherence protocol consists on identifying memory instructions that may access data in the GM that is mapped to some SPM so that the hardware diverts them to the correct copy of the data. This section gives an overview of how the compiler performs this identification. The details of all the compiler phases and analyses used in this process can be found in [5, 6]. The compiler starts by classifying the memory references of the code based on their access patterns and the possible memory aliasing hazards between them. Then, for the memory references that do not present aliasing problems, it generates memory instructions that will directly access the GM or the SPMs while, for potentially incoherent accesses, the compiler generates guarded memory instructions that will be diverted to the appropriate memory at execution time. The categorization of the memory references is: • SPM accesses are those that traverse array sections private to each thread with a strided access pattern. Normal assembly memory instructions are emitted for them, using as source operands a base pointer to a SPM buffer and an offset, so they directly access the SPMs. • GM accesses are those that do not sequentially traverse array sections and do not alias with any SPM access. Normal assembly memory instructions are emitted for them, using as source operands a base pointer to a GM address and an offset, so they directly access the GM. • Potentially incoherent accesses are those that do not sequentially traverse array sections and alias or may alias with some SPM access. Guarded memory instructions are emitted for them, using as source operands a base pointer to a GM address and an offset. When it is executed, the guarded memory instruction is identified by the hardware, that checks if the resulting GM address is mapped to some SPM and diverts the access to the corresponding memory. This paper assumes an x86_64 architecture that implements the guard for the memory instructions with an instruction prefix that can be added to any instruction that accesses memory. In the example in Figure 3 the accesses to a and b are SPM accesses because they traverse private array sections using a strided access pattern, so they are respectively emitted with a normal store and a normal load. The source operands of the instructions are the pointers to the SPM buffers ( _a and _b ) and the offset ( _i ). The computation of the address at execution time will result in an address that is in the virtual address space of the local SPM, so it will be accessed. Random accesses to c and ptr are classified as GM or potentially incoherent accesses depending on the outcome of the alias analysis. In the example, the alias analysis succeeds in ensuring that c does not alias with any SPM access, so it is categorized as a GM access and a normal store is emitted with c as a base address and the content of _b[_i] as offset, so the resulting GM address will guide the access to the L1 cache. For ptr the example assumes the alias analysis specifies it may alias with some SPM access, so it is classified as a potentially incoherent access. The compiler emits a guarded load, an increment and a guarded store. The base address of these two guarded memory instructions is ptr and the offset is the content of _a[_i] , which will result in an address in the GM virtual address space. At execution time this GM virtual address will be used to check if the chunk of data is mapped to some SPM, and will be diverted to the appropriate memory. 3. Coherence Protocol The goal of the hardware support for the coherence protocol is to check if the data accessed by a potentially incoherent access is mapped to some SPM and, in case it is, divert the access to the SPM. With this approach the architecture does not maintain the different copies of the data in a coherent state, but ensures that the valid copy of the data is always accessed. The proposed hardware design aims to exploit a key characteristic of the applications: it is extremely rare that, in the same loop, the same data is accessed at the same time using strided and random accesses. The data of a program is kept in data structures, and the internal organization of the data structures is what defines the way the data is accessed, thus defines what kind of memory accesses are used to do so. Moreover, although some data structures (e.g., arrays) can be accessed in different ways, it is unnatural to access the same data using strided and random accesses in the same computational parallel loop. This implies that SPM accesses almost never alias with potentially incoherent accesses, although the compiler is unable to ensure it. For this reason, the hardware coherence protocol is designed to not penalize the latency of potentially incoherent accesses that do not access data mapped to the SPMs, which is the most common case. Figure 4: Hardware support for the coherence protocol. Every core is extended with a SPMDir and a Filter, and a FilterDir is added to the cache directory of the cache coherence protocol. The hardware support for the coherence protocol consists on tracking what data is mapped to the SPMs and what data is known to be not mapped to the SPMs. Figure 4 shows the hardware extensions in one core and in one slice of the directory of the cache coherence protocol. Every core tracks what data is mapped to its SPM in its SPMDir, so all the data mapped to all SPMs is tracked in a distributed way. Chunks of data that are not mapped to any SPM and that have been recently accessed by guarded memory instructions are tracked in a hierarchy of filters. Every core has a filter that tracks chunks of data not mapped to any SPM and the filterDir tracks the contents of all the filters. Placing the filters and the SPMDirs close to the core allows fast access to the information needed to divert guarded accesses. The next subsections explain the implementation of these hardware structures, how they are operated in the execution of potentially incoherent accesses and how they track what data is mapped to the SPMs and what data is not mapped. 3.1. Implementation of Hardware Structures The hardware additions are implemented as follows: • The SPMDir is a CAM array that tracks the base GM address of the chunks of data mapped to the SPM of the core. • The filter is a CAM array that keeps base GM addresses not mapped to any SPM. • The filterDir is an extension of the cache directory that consists of a CAM array that keeps base GM addresses and a RAM array with a bitvector of sharer cores that tracks which cores have the address in their filters. Note that the hardware structures track data at a fixed granularity using 64-bit virtual base addresses. This can be done because, in fork-join parallelism, all threads work with the same SPM buffer size. As explained in Section 2.2, prior to the execution of a loop, the size of the SPM is divided among equally-sized SPM buffers. This buffer size is notified to the hardware, that sets the values of the Base Mask and Offset Mask internal configuration registers that are used to decompose any address into a base address and an address offset. This allows that, first, base addresses can be used to operate (a) No mapping (b) Mapping in local SPM (c) No mapping with filter miss (d) Mapping in remote SPM Figure 5: Casuistic of guarded memory accesses. all the hardware structures and, second, the SPMDir does not need a RAM array to store the SPM base addresses for every entry, since the index of the entry is equivalent to the buffer number and, thus, the base address of the SPM buffer. In other forms of parallelism (e.g, region- or task-based) different threads can simultaneously execute parts of the code that require managing the SPMs at different granularities, so range lookups would be required in the hardware structures. 3.2. Diverting Potentially Incoherent Accesses The hardware design of the coherence protocol tracks all the data that is mapped to the SPMs in the SPMDirs, and the data that has been recently accessed by potentially incoherent accesses that is not mapped to any SPM is tracked in the hierarchy of filters. The next paragraphs explain how this information is used in the execution of guarded accesses. When a guarded memory instruction is executed, the TLB and the L1 cache are accessed as in a normal memory instruction for the GM. Additionally, the GM base address is looked up in the filter and the SPMDir. Different situations can arise depending on the results of the lookups, as shown in Figure 5. In Figure 5a the data accessed by the potentially incoherent access is not mapped to any SPM, so the lookup in the SPMDir misses and the lookup in the filter hits 1 . The TLB translates the address and the L1 cache is accessed normally to serve the memory access 2 . In Figure 5b the data is mapped to the SPM of the local core. The lookup in the SPMDir hits 1 and the SPM base address corresponding to the entry that returned the hit is added to the offset of the address of the guarded instruction, resulting in the SPM address where the data is mapped. This address is used to access the SPM 2 . In addition, if the guarded instruction is a load, the result of the cache access is discarded 3 . Note that guarded store instructions always write the data in the L1 cache because, if they alias with a read-only SPM buffer, it is not guaranteed that the software will write-back the SPM buffer to the GM, so the modifications done by guarded store instructions could be lost. In Figure 5c the data is not mapped to any SPM, though the address is not cached in the filter. The lookup in the SPMDir misses and the lookup in the filter misses 1 , so the data may be mapped to a remote SPM. A request is sent to the filterDir and, if the guarded instruction is a load, the L1 cache access is buffered in the MSHR. When the filterDir receives the request it looks up the address 2 . If the lookup hits the address is not mapped to any SPM, so the directory responds to the local core. If the lookup misses the request is broadcast to all the remote cores to check if the address is in their SPMDirs 3 . The lookup misses in all the cores because the data is not mapped to any SPM, so the remote cores respond to the filterDir and this to the local core. When the local core receives the response the GM base address is inserted in the filter 4 and, if the guarded instruction is a load, the buffered cache access is used to serve the memory access 5 . In Figure 5d the data is mapped to the SPM of a remote core. Like in the previous situation, both lookups in the filter and in the SPMDir miss 1 , so the L1 cache access is buffered if it is a guarded load and a request is sent to the filterDir, which also misses 2 and broadcasts the request to all the remote cores. In this case, one of the remote cores has the data mapped to its SPM, so the lookup in its SPMDir hits 3 . The SPM address is calculated using the entry index and the offset of the remote access, and it is used to access the SPM, that serves the remote access. If the remote access is a load, the remote core sends the data to the local core while, if it is a remote store, the remote core writes the data to its SPM and responds with an ACK to the local core. When the response arrives to the local core, if it is a guarded load, the buffered cache access is discarded 4 and the data from the remote core is forwarded to the CPU. (a) Filter invalidation (b) Filter update Figure 6: Filter invalidation and update. 3.3. Tracking SPMs Contents The contents of the hardware structures of the coherence protocol are used to divert the guarded accesses. The next paragraphs explain how all the information of the contents of the SPMs is tracked in the SPMDirs, the filters and the filterDir. When a core maps data to its SPM, its SPMDir is updated and the filters are invalidated. The source GM address and the destination SPM address of the dma-get are used to calculate the GM base address and the SPM base address, and the SPMDir entry associated to the SPM base address is updated with the GM base address. Figure 6a shows how the filters are invalidated. First, an invalidation message is sent for the GM base address to the filterDir 1 , which triggers a lookup of the address. If the address is not found no core has the address in its filter, so no more actions take place. If the GM base address is in the filterDir, a filter invalidation message is sent to all the cores in the sharers list 2 . When the sharer cores receive the invalidation message they look up the address in their filter and invalidate the entry. The filters and the filterDir are updated when the execution of a potentially incoherent access triggers a lookup of a GM base address in a filter and misses (Figures 5c and 5d). The mechanism to update the filters and the filterDir is shown in Figure 6b, and is very similar to how caches operate on a cache miss. When a lookup of a GM base address misses in a filter, it has to check if the GM base address is mapped to some SPM. First, a request for the GM base address is sent to the filterDir 1 , which looks up the address. If the address is in the filterDir it means it is not mapped to any SPM, so the requestor core is added to the sharers list and an ACK is sent as a response 2 . When the requestor core receives the ACK it inserts the GM base address in its filter. If the lookup in the filterDir after 1 misses, the GM base address may be mapped to some SPM. The filterDir broadcasts a request of the address to all the cores 3 . When the cores receive the request, they lookup the address in their SPMDir 4 and respond to the filterDir with an ACK or a NACK depending if the lookup hit or missed 5 . If all the cores respond NACK, the data is not mapped to any SPM, so the filterDir inserts the GM base address, sets the local core in the sharers list and sends it a response with ACK 2 . When the local core receives the ACK it inserts the GM base address in its filter. If a remote core responds to the broadcast request with an ACK 5 it means it has the data mapped to its SPM, so the address cannot be filtered. The filterDir responds with a NACK to the local core and this does not update its filter. Note that the filter of every core and the filterDir are associative buffers with a replacement policy so, when they are updated, an older entry can be evicted. When an entry of the filter of a core is evicted, a message is sent to the filterDir to notify the eviction, and this removes the core from the sharers list. When the filterDir is updated and an older entry is evicted, an invalidation message is sent to all the sharer cores, which invalidate their filter, like in step 2 of Figure 6a. 3.4. Memory Consistency Model Another important problem that affects the ability of the compiler to generate code for the SPMs of the hybrid memory system is the memory consistency model provided by the architecture. The memory consistency model defines what is the expected behaviour of a sequence of memory operations. The vast majority of shared memory programming models rely on sequential consistency models [ 3 ] that ensure that a sequence of memory operations will happen in program order inside the same thread, while a sequence of memory operations from different threads can happen in any order. For this reason, the programmer has to use synchronization mechanisms to avoid data races between the threads, but not between the memory accesses of each thread. In order to allow the compiler to transform the code for the hybrid memory system, the memory subsystem has to ensure these conditions are fulfilled. The coherence protocol for the hybrid memory system breaks the sequential consistency rules between potentially incoherent accesses and SPM accesses of the same thread. The virtual address of potentially incoherent accesses is initially a GM address that is changed to a different SPM virtual address if the data is mapped to the SPM. This causes that, when a thread accesses the same data using strided and potentially incoherent accesses, an out-of-order core can re-order the instructions and the Load/Store Queue (LSQ) will not detect an ordering violation has happened because the virtual addresses of the two accesses are different. When the potentially incoherent access is sent to memory and its address is changed to point to the SPM it results in the same address of the strided access so, if at least one of the two accesses was a store, the re-ordering breaks the sequential consistency rules. In order to solve this problem, when a potentially incoherent access hits in the SPMDir, the new SPM address is notified to the LSQ to re-check the ordering for the new address, and the pipeline is flushed if a violation is found. Note that if the guarded access aliases with the contents of a remote SPM it is responsibility of the programmer to synchronize the accesses between the threads, just like it is done for any other type of accesses. 4. Summary and Discussion The architecture and the system organization proposed in this paper achieve that transparently managed SPMs can be added to the memory hierarchy of shared memory manycore architectures. The compiler categorizes the memory accesses of a conventional parallel loop. For strided accesses to private array sections, the compiler transforms the code so that a runtime library maps the data to the SPMs. Random accesses are served by the cache hierarchy if the compiler can ensure they do not alias with the contents of some SPM. When the compiler is unsure of the aliasing of a random access, it generates a guarded memory instruction. At execution time, the hardware support of the coherence protocol decides if these accesses are served by some SPM or by the cache hierarchy. Although the hardware support of the coherence protocol resembles the operation of a directory-based cache coherence protocol, it does not undermine the benefits of the hybrid memory system compared to a cache hierarchy. The wide majority of memory accesses in HPC applications are strided accesses to array sections, and these are served by the SPMs in a very energy efficient way, without any CAM lookup in the TLB nor in the tags of the caches nor in any hardware structure of the coherence protocol. In addition, SPM accesses do not suffer performance penalties due to cache misses, and the coherence traffic for them is reduced because accesses to the SPMs do not generate coherence traffic and the DMA transfers allow to move data in a very efficient way. Random accesses to the cache behave like in a conventional cache coherent system, without any overhead. Potentially incoherent accesses can suffer performance penalties if the filter misses, and are always a bit less power efficient due to the lookups in the filter and in the SPMDir. Since these accesses are a minority, the number of CAM lookups and the coherence traffic added by the filters are overweighted by the CAM lookups and the coherence traffic saved for the SPM accesses, preserving the benefits of the hybrid memory system. 4.1. OS Support and Backwards Compatibility The hybrid memory system can be made backwards compatible with minor operating system (OS) changes and without impacting performance. The OS process structure is extended with the fields necessary to manage the registers for the virtual- to-physical address mapping of the SPMs at context switch. By default, processes execute with this mapping disabled, so the SPMs are not accessible. Whenever a SPM-enabled application starts, the OS configures the registers for the address spaces of the SPMs and stores their values in the process structure. Whenever a process is scheduled, the registers are set to the values stored in the process structure. Since multiple concurrent applications can be using the SPMs, the OS must also save and restore the contents of the SPMs whenever a process is scheduled for execution. In order to keep these overheads low, SPM contents can be switched Table 1: Main simulator parameters. Cores 64 cores, Out-of-order, 6 instructions wide, 2GHz Pipeline 13 cycles. Branch predictor 4K selector, 4K G-share, front end 4K Bimodal. 4-way BTB 4K entries. RAS 32 entries ROB 160 entries. IQ 64 entries. LQ/SQ 48/32 entries. Execution 3 INT ALU, 3 FP ALU, 3 Ld/St units. 256/256 INT/FP RegFile. Full bypass. L1 I-cache 2 cycles, 32 KB, 4-way, pseudoLRU L1 D-cache 2 cycles, 32 KB, 4-way, pseudoLRU, stride prefetcher L2 cache Shared unified NUCA 16MB, sliced 256KB/core 15 cycles, 16-way, pseudoLRU Cache Real MOESI with blocking states, 64B line size coherence distributed 4-way cache directory 64K entries NoC Mesh, link 1 cycle, router 1 cycle SPM 2 cycles, 32 KB, 64B blocks DMAC DMA command queue 32 entries, in-order Bus request queue 512 entries, in-order SPMDir 32 entries Filter 48 entries, fully associative, pseudoLRU FilterDir Distributed 4K entries, fully associative, pseudoLRU lazily, similar to how the Linux kernel does for the floating point register file [ 1 ]. Additionally, a register that contains a single bit for each SPM in the system is added to each core. The Nth bit of this register identifies whether the Nth SPM can be accessed, and accessing a SPM without that bit set raises an exception. This mechanism allows the OS to accurately control which SPMs are available to the running processes, making possible that multiple processes that use the SPMs can be safely executed concurrently. These OS modifications provide backwards compatibility and can also be used by the OS to improve energy consumption by powering down the SPMs that are not being actively used. As a result, the only overhead when running in compatibility mode is the unused area of the SPMs, the DMACs and the hardware structures of the coherence protocol. 5. Evaluation This section evaluates the overheads of the proposed coherence protocol and then compares the resulting hybrid memory system with a cache-based system. 5.1. Experimental Framework The proposal has been evaluated with Gem5 [ 12 ], using its x86 cycle-accurate detailed out-of-order core model and its detailed memory hierarchy model. The energy consumption has been evaluated with McPAT [ 32 ] using a process technology of 22nm and the default clock gating scheme of the tool. Both simulators are extended with the SPMs, the DMACs and the hardware support for the coherence protocol. Table 1 shows the main configuration parameters of the simulators. Six representative memory intensive HPC benchmarks from the NAS benchmark suite [ 8 ] are used for the evaluation. They have been compiled using GCC 4.7.3 with the -O3 optimization flag on. The code transformations for the hybrid memory system have been done manually and the alias analysis report of GCC has been used to identify the potentially incoherent Table 2: Benchmarks and memory access characterization. Benchmark SPM refs Guarded refs Name Input Kernels # Data Size # Data Size CG ClassB 1 5 109 MB 1 600 KB EP ClassA 2 3 1 MB 1 512 KB FT ClassA 5 32 269 MB 4 1 MB IS ClassA 1 3 67 MB 2 2 MB MG ClassA 3 59 454 MB 6 64 B SP ClassA 54 497 2 MB 0 0 B accesses. For the memory references that GCC is not able to determine the aliasing, an assembly macro is added to the source code to add the x86 instruction prefix that implements the guard for potentially incoherent accesses. The runtime library that manages the SPMs is a modified version of a software cache for the Cell B.E. [ 22 ] that has been ported to the hybrid memory system and optimized. Double buffering is not used. 5.2. Benchmark Characterization Table 2 shows the main characteristics of the benchmarks. For each benchmark it is shown the input class, the number of kernels, the number of strided and potentially incoherent memory references and the sizes of the data sets accessed by each type of accesses. These benchmarks allow to study many different scenarios regarding the number of memory accesses of each type and the sizes of the data sets they access. CG and IS use few strided references to traverse big input sets and few guarded references to access a smaller data set, so the ratio of guarded accesses with respect to the total number of accesses is high. In EP the amount of references of each type is low and the data sets are small and, in addition, its kernels use many scalar temporal values that cause register spilling, so the majority of memory accesses are to the stack. FT and MG traverse big input sets with many strided references and use a few guarded references to access much smaller parts of the data set, while SP traverses a small input set in a series of 54 different kernels that only use SPM accesses. Like in real HPC applications [ 36 , 44 ], the characteristics of the benchmarks fulfill the motivation for the introduction of SPMs. In all benchmarks the number of strided memory references is higher than the number of guarded references, and the data set accessed by SPM accesses is much bigger than the one accessed by guarded accesses. Furthermore, the data sets accessed by SPM and guarded accesses are disjoint, though the compiler is unable to ensure it using alias analyses. 5.3. Coherence Protocol Overheads This section evaluates the overheads of the coherence protocol in a 64-core manycore. In the study, the proposed coherence protocol is compared with an ideal coherence protocol that diverts guarded accesses to the correct copy of the data without the need of SPMDirs, filters, the filterDir nor any traffic to maintain them. Figure 7 shows the overheads in performance, energy and network traffic of the hybrid memory system aug- CG EP FT IS MG SP 0.8 0.9 1.0 1.1 1.2 1.3 1.4 Overhead (x) Execution time Energy NoC traffic Figure 7: Overhead in execution time, energy consumption and NoC traffic added by the coherence protocol. CG EP FT IS MG SP 0 10 20 30 40 50 60 70 80 90 100 110 Hit ratio (%) Figure 8: Filter hit ratio. mented with the proposed coherence protocol with respect to the hybrid memory system with ideal coherence. The coherence protocol adds performance overheads of 1% to 11%. These overheads are caused by the increase in network traffic and by filter misses at the execution of guarded accesses. The filter hit ratio for each benchmark is shown in Figure 8. In SP the performance overhead is negligible because no guarded accesses are generated and very few DMA transfers are issued, so the filters are not used and the overhead in network traffic is only 2%. CG, EP, FT and MG present performance overheads between 2% and 7%. Although the filter hit ratio is at least 97%, the network traffic added by the coherence protocol, between 4% and 11%, slightly penalizes performance. In IS the performance overhead is 11% because the filter hit ratio is lower, 92%, which penalizes the latency of guarded accesses and adds higher overheads in network traffic, 15%. In all benchmarks the contention in the filterDir is very low due to the low rate of DMA transfers and filter misses. In addition, guarded accesses never alias with SPM accesses and the filterDir can track the whole data set accessed by guarded accesses, so filter invalidations and pipeline squashes due to ordering violations never happen. In terms of energy consumption, the overheads range from 3% to 14%. In SP the overhead is only 3% because the filters are gated off and only the SPMDirs and the filterDir consume some extra energy at every DMA transfer. In the rest of benchmarks the overheads range between 7% and 14%. Almost half of the overhead is due to static energy consumption, where SPMDirs, filters and the filterDir add overheads of less than 3% and the performance overheads add another 2% to 5% in the whole chip. In dynamic energy the SPMDirs add up to 3% overhead, while less than 2% is added by the filters and the filterDir. The extra traffic causes overheads of less than 1% in the NoC in all cases except in IS, where it adds 3%. In terms of area, the SPMDirs, the filters and the filterDir add an overhead of less than 4%. 0.0 0.2 0.4 0.6 0.8 1.0 1.2 Normalized cycles C H C H C H C H C H C H CG EP FT IS MG SP Control Sync Work Figure 9: Performance of the cache-based system (C) and the hybrid memory system (H). In conclusion, the proposed coherence protocol introduces very low overheads in performance, energy consumption and network traffic. The overheads are caused by the extra traffic added at DMA transfers, and also due to filter misses in IS. The average overheads in performance, energy consumption and network traffic are 4%, 9% and 8%, respectively. 5.4. Comparison with Cache-Based Systems The immediate result of the coherence protocol is that any computational loop can be executed on the hybrid memory system without any programming effort. In order to demonstrate the benefits of this accomplishment, in this section the hybrid memory system is compared with a cache-based system in terms of performance, energy consumption and network traffic in a 64-core manycore. The studied hybrid memory and cache-based systems have the same characteristics, shown in Table 1, but with one difference. For fairness, the L1 D-cache of the cache-based system is augmented to 64KB without affecting access latency, matching the 32KB L1 D-cache plus the 32KB SPM of the hybrid memory system. Figure 9 shows the performance of the two systems. Both bars are normalized to the cache-based system execution time and show the time spent in each execution phase. The figure shows that the hybrid memory system reduces the execution time with respect to the cache-based system for all benchmarks, achieving execution time reductions between 3% and 18% (or speedups of 1.03x to 1.22x). EP is dominated by cache accesses to the stack and a very small data set is mapped to the SPMs, so both systems have practically the same behaviour and the performance differences are negligible. In the rest of benchmarks speedups of 1.12x to 1.22x are achieved due to the ability of the hybrid memory system to serve memory accesses more efficiently than the cache-based system. In FT, MG and SP, which have a lot of strided accesses, the hybrid memory system always serves these accesses with the SPMs without performance penalties while, in the cache-based system, it is observed that cache misses happen because the prefetchers are not able to provide all the data required by all the strided references on time, and also the big amount of data brought and prefetched to the L1 caches causes conflict misses. In benchmarks that use guarded accesses, especially IS and CG but also FT and MG, performance benefits come from exploiting their temporal locality. The hybrid memory system serves most of the memory accesses with the SPMs so