This application is directed, in general, to parallel processors and, more specifically, to a system and method for allocating memory of differing properties to shared data objects.
As those skilled in the pertinent art are aware, applications may be executed in parallel to increase their performance. Data parallel applications carry out the same process concurrently on different data. Task parallel applications carry out different processes concurrently on the same data. Static parallel applications are applications having a degree of parallelism that can be determined before they execute. In contrast, the parallelism achievable by dynamic parallel applications can only be determined as they are executing. Whether the application is data or task parallel, or static or dynamic parallel, it may be executed in a pipeline which is often the case for graphics applications.
Certain computing systems, such as a single-instruction, multiple-data (SIMD) processor, are particularly adept at executing data parallel applications. A pipeline control unit in the SIMD processor creates groups of threads of execution and schedules them for execution, during which all threads in the group execute the same instruction concurrently. In one particular processor, each group has 32 threads, corresponding to 32 execution pipelines, or lanes, in the SIMD processor.
Consider a fork-join parallel programming model such as OpenMP or OpenACC implemented on a parallel processing computing system. In this model, some parts of a program's code are executed by only one thread (a “master” thread) while other parts are executed by multiple threads in parallel (“worker” threads). Execution starts with only the master thread active. At a work creation construct, execution is forked when the master thread activates worker threads and assigns each worker an “execution task,” such as a certain number of iterations of a loop. Worker threads then typically execute their assigned tasks in parallel. Once the worker threads are finished, they deactivate, and execution is joined when the master thread resumes execution of the remainder of the program code. The period of program execution when only one thread is active will be referred to herein as the sequential region or phase, and the period of program execution when more than one thread is active will be referred to herein as the parallel region or phase.
In many fork-join models, including OpenMP and OpenACC, data objects allocated in the sequential region can be accessed in the parallel region. Accordingly, parallel processor architectures provide memory for storing the data objects to which multiple threads may gain access during their execution. This memory may be characterized by many properties, including size, latency, volatility and others and their accompanying advantages and disadvantages.
One aspect provides a system for allocating shared memory of differing properties to shared data objects and a hybrid stack data structure. In one embodiment, the system includes: (1) a hybrid stack creator configured to create, in the shared memory, a hybrid stack data structure having a lower portion having a more favorable property and a higher portion having a less favorable property and (2) a data object allocator associated with the hybrid stack creator and configured to allocate storage for shared data object in the lower portion if the lower portion has a sufficient remaining capacity to contain the shared data object and alternatively allocate storage for the shared data object in the higher portion if the lower portion has an insufficient remaining capacity to contain the shared data object.
Another aspect provides a method of allocating shared memory of differing properties to shared data objects. In one embodiment, the method includes: (1) creating a hybrid stack data structure in the shared memory, the data structure having a lower portion having a more favorable property and a higher portion having a less favorable property, (2) when a thread requires a shared data object, (2a) allocating storage for the shared data object in the lower portion if the lower portion has a sufficient remaining capacity to contain the shared data object and (2b) alternatively allocating storage for the shared data object in the higher portion if the lower portion has an insufficient remaining capacity to contain the shared data object and (3) when no thread further requires the shared data object, deallocating the storage.
Yet another aspect provides a hybrid stack data structure. In one embodiment, the data structure includes: (1) a lower portion in a shared memory having a more favorable property and (2) a higher portion in the shared memory having a less favorable property.
Reference is now made to the following descriptions taken in conjunction with the accompanying drawings, in which:
As stated above, parallel processor architectures characterize by many properties. For example, memory may be stratified into larger memory having a higher latency and smaller (perhaps by an order of magnitude) memory having a lower latency. Architectures often include several memory blocks having various properties and purposes. Multiple threads often need to gain access to this memory to share data objects.
In many fork-join programming models, data objects allocated in the sequential region can be accessed in the parallel region. However, on some execution platforms, thread-local memory is not accessible by other threads. For example, in some commercially available graphics processing units (GPUs), data objects resident in one thread's local memory are not accessible to a different thread. Hence a compiler or runtime system that translates a software program into executable form is tasked with the responsibility of allocating memory to potentially shared objects such that they are accessible by threads active in the parallel region.
Data objects allocated during the sequential region, that are local to a function, can be conveniently placed on a stack data structure. However, it is realized herein that implementing a stack data structure for shared data objects in only one type of memory (e.g., only global-shared memory, or only block-shared memory) has disadvantages. If the stack data structure were to be placed entirely in block-shared memory, which tends to be smaller, the stack could easily overflow, and the program would need to terminate. On the other hand, if the stack data structure were to be placed entirely in global-shared memory, which tends to be of higher latency, the performance of the program would degrade if access to the shared objects was heavy, since average access latency would increase. This could be particularly deleterious were a program to have only a few small shared objects.
Introduced herein are various embodiments of a system and method for allocating memory of differing properties to shared data objects. The system and method embodiments are generally directed to construct a hybrid stack data structure, that is, a stack data structure implemented with multiple types of physical memories. The system and method embodiments take advantage of the strengths of each type of memory, resulting in a mechanism that is less restrictive and achieves higher performance than possible when using only one type of memory. For example, in certain embodiments the hybrid stack affords the latency advantage of using block-shared memory when relatively few objects are allocated on the stack, which is often the case. However, a hybrid stack affords robustness if many large objects are allocated on the stack, by gracefully “falling back” to using higher latency global-shared memory.
Various embodiments of the system and method are employable in any conventional or later-developed parallel programming system where shared objects are accessed by multiple threads and the execution substrate provides multiple physical memories with differing resource limits and performance characteristics.
In some embodiments, the memory segments are configurable, e.g., as a compile-time or run-time parameter. This allows users to decide how best to balance memory resource usage and program performance. For instance, allocating more objects in the block-shared memory segment typically reduces average access latency and thereby increases program performance. Similarly, in certain embodiments, the size of each layer of the hybrid stack is configurable, the lowest layer being smallest, the next layer being larger, and the highest layer being largest yet.
Several embodiments will be illustrated and described below. Many of the illustrated and described embodiments may appear to be specific to hybrid stacks having segments located in two different memories. However, those skilled in the pertinent art will understand that many of these, together with other embodiments, are directed to hybrid stacks having more than two segments and therefore located in more than two memories. The invention is not limited in terms of the number of different memories that a hybrid stack can accommodate.
Before describing certain embodiments of the system and method, a parallel processor operable to contain or carry out a system and method for allocating memory of differing properties to shared data objects will be described.
Parallel processor 100 further includes a pipeline control unit 108, block-shared memory 110 and an array of local memory 112-1 through 112-J associated with thread groups 104-1 through 104-J. Pipeline control unit 108 distributes tasks to the various thread groups 104-1 through 104-J over a data bus 114. Cores 106 within a thread group 106-j execute in parallel with each other. Thread groups 104-1 through 104-J communicate with block-shared memory 110 over a memory bus 116. Thread groups 104-1 through 104-J respectively communicate with local memory 112-1 through 112-J over local buses 118-1 through 118-J. For example, a thread group 104-J utilizes local memory 112-J by communicating over a local bus 118-J. Certain embodiments of parallel processor 100 allocate a shared portion of block-shared memory 110 to each thread block 102 and allow access to shared portions of block-shared memory 110 by all thread groups 104 within a thread block 102. Certain embodiments include thread groups 104 that use only local memory 112. Many other embodiments include thread groups 104 that balance use of local memory 112 and block-shared memory 110.
The embodiment of
In the following example, and without loss of generality, a GPU commercially available from Nvidia Corporation of Santa Clara, Calif., will be used as an execution platform and OpenACC will be used as a fork-join parallel programming model for programs. As described earlier, the Nvidia GPU provides global and shared memories that are both accessible by all threads that are part of the same thread block. Global-shared memory access latency is more than an order of magnitude higher than block-shared memory access latency. The size of global-shared memory is more than an order of magnitude larger than the size of block-shared memory. Table 1, below, sets forth an example of an OpenACC program in which threads in the parallel region access shared variables allocated in the sequential region.
In the example program of Table 1, the fork and join parallel constructs are “pragma acc loop worker” and “pragma acc parallel,” and the shared data variables are “arr” and “scalar.”
The “pragma acc parallel” construct activates one master thread per “group,” and the “pragma acc loop” activates other worker threads in a group. Before the other threads in a group are activated, only one thread of the group is active (master thread). Function “foo” is called by the master thread. The address of the variables function local variables “arr” and “scalar” is passed to function “bar”, which activates the worker threads. The worker threads access the “arr” and “scalar” objects.
For correct execution, variables “arr” and “scalar” should be allocated in a memory area that is accessible by the worker threads. In this example, the variables are allocated on a hybrid data stack. The hybrid data stack is implemented using two pre-allocated buffers: one in block-shared memory and one in global-shared memory. A variable is allocated in the block-shared memory segment if there is space at the time of allocation to the hybrid stack. Otherwise it is allocated in the global-shared memory. Housekeeping information is maintained about the maximum sizes of the two segments, the currently active segment and the location within the active segment where the next stack allocation should be attempted.
Allocations are first made to stack bottom 206, in lower portion 202. As allocations increase, the lower portion fills until a maximum allocation in lower portion 210 is reached. Maximum allocation in lower portion 210 is essentially the boundary between the lower and higher, or in certain embodiments, the block-shared and global-shared, segments of the hybrid stack. In alternate embodiments the maximum allocation in in lower portion 210 is specified at run-time; and in others at compile-time. This specification is made by sizing the lower portion memory segments and higher portion memory segments to strike an appropriate balance of stack properties and performance, such as capacity and stack latency.
In certain embodiments employing memory of varying size and latency, it is often the case the hybrid stack 200 will not exceed the maximum allocation in lower portion 210; certain programs simply do not employ large enough amounts of data shared between threads to fill the smaller, lower-latency memory segment of the hybrid stack 200. When the lower portion 202 of hybrid stack 200 is filled, the next allocation to hybrid stack 200 is allocated in the lowest address of the higher portion 204. The term “lowest” refers to the position on hybrid stack 200 just above the maximum allocation in lower portion 210. As allocations continue to increase, the higher portion 204 fills and the overall latency of hybrid stack 200 climbs. As memory is deallocated from hybrid stack 200, the deallocations come first from the higher portion 204, the higher-latency global-shared memory segment. As memory continues to be deallocated, latency declines, the global-shared memory segment empties, eventually reaching the maximum allocation in lower portion 210, once again. Further deallocations then come from the lower portion 202, the block-shared memory.
Table 2, below, sets forth an implementation of a hybrid stack with a specific set of housekeeping variables. The pseudo-code for allocating and de-allocating variables from the hybrid stack is also given. The annotations “_shared_” and “_device_” indicate that the variable should be allocated in shared and global GPU memories, respectively. Note that this simplified implementation does not consider alignment requirements for the object being allocated on the stack.
In Table 2, “shared_mem_top” and “global_mem_top” indicate the position in the shared and global-shared memory segments where allocation should be attempted, respectively. “Using_shared_mem_segment” is a Boolean flag that indicates whether the block-shared memory segment should be used for allocation.
“Allocate_on_hybrid_stack” allocates memory in the block-shared memory segment if there is enough space in the block-shared memory segment; otherwise the object is allocated in the global-shared memory segment.
“Deallocate_from_hybrid_stack” adjusts the stack pointer in the appropriate memory segment and may switch back to using the block-shared memory segment if the global-shared memory segment is completely empty (i.e., no objects are presently allocated in that segment).
The allocation and deallocation of the block-shared memory from the hybrid stack happens only during the sequential region of the program, so there are no thread-safety issues during the allocation and deallocation.
Data object allocator 304 operates on shared data objects 306 to store shared data objects 306 in hybrid stack 200. In certain embodiments data object allocator 304 operates at compile-time, while in others data object allocator 304 operates at run-time. Data object allocator 304 favors allocating to block-shared memory segment 308. At the time of allocation, data object allocator 304 checks whether block-shared memory segment 308 has available capacity to store a data object. If capacity exists in block-shared memory segment 308, the data object is stored in block-shared memory segment 308. If no capacity exists in block-shared memory segment 308, the data object is stored in global-shared memory segment 310.
Those skilled in the art to which this application relates will appreciate that other and further additions, deletions, substitutions and modifications may be made to the described embodiments.
This application claims the benefit of U.S. Provisional Application Ser. No. 61/722,661, filed by Lin, et al., on Nov. 5, 2012, entitled “Executing Sequential Code Using a Group of Threads,” commonly assigned with this application and incorporated herein by reference.
Number | Name | Date | Kind |
---|---|---|---|
5875464 | Kirk | Feb 1999 | A |
6088770 | Tarui | Jul 2000 | A |
6609193 | Douglas et al. | Aug 2003 | B1 |
7086063 | Ousterhout | Aug 2006 | B1 |
7856541 | Kaneda | Dec 2010 | B2 |
8095782 | Danskin | Jan 2012 | B1 |
8250555 | Lee et al. | Aug 2012 | B1 |
8335892 | Minkin | Dec 2012 | B1 |
8397013 | Rosenband | Mar 2013 | B1 |
8516483 | Chinya et al. | Aug 2013 | B2 |
8547385 | Jiao | Oct 2013 | B2 |
8615646 | Nickolls et al. | Dec 2013 | B2 |
8683132 | Danilak | Mar 2014 | B1 |
8812771 | Yim | Aug 2014 | B2 |
20020029357 | Charnell et al. | Mar 2002 | A1 |
20030018684 | Ohsawa et al. | Jan 2003 | A1 |
20050125774 | Barsness et al. | Jun 2005 | A1 |
20050149903 | Archambault | Jul 2005 | A1 |
20060095675 | Yang | May 2006 | A1 |
20070136523 | Bonella | Jun 2007 | A1 |
20070143582 | Coon et al. | Jun 2007 | A1 |
20070192541 | Balasubramonian | Aug 2007 | A1 |
20070294512 | Crutchfield et al. | Dec 2007 | A1 |
20080052466 | Zulauf | Feb 2008 | A1 |
20080126716 | Daniels | May 2008 | A1 |
20080158958 | Sokolov | Jul 2008 | A1 |
20090006758 | Chung | Jan 2009 | A1 |
20090013323 | May et al. | Jan 2009 | A1 |
20090031290 | Feng et al. | Jan 2009 | A1 |
20090100244 | Chang | Apr 2009 | A1 |
20090259799 | Wong | Oct 2009 | A1 |
20100079454 | Legakis et al. | Apr 2010 | A1 |
20100169540 | Sinclair | Jul 2010 | A1 |
20100281230 | Rabii | Nov 2010 | A1 |
20110022672 | Chang et al. | Jan 2011 | A1 |
20110072214 | Li | Mar 2011 | A1 |
20110072438 | Fiyak et al. | Mar 2011 | A1 |
20110125974 | Anderson | May 2011 | A1 |
20110191522 | Condict | Aug 2011 | A1 |
20110265068 | Elnozahy et al. | Oct 2011 | A1 |
20110320804 | Chan | Dec 2011 | A1 |
20120072652 | Celis | Mar 2012 | A1 |
20120089792 | Fahs et al. | Apr 2012 | A1 |
20120131309 | Johnson et al. | May 2012 | A1 |
20120137055 | Lee | May 2012 | A1 |
20120137099 | Shibayama | May 2012 | A1 |
20120151179 | Gaertner | Jun 2012 | A1 |
20120191953 | Eichenberger et al. | Jul 2012 | A1 |
20120204065 | Tsafrir et al. | Aug 2012 | A1 |
20120254530 | Tagaya | Oct 2012 | A1 |
20130128671 | Shin | May 2013 | A1 |
20130263153 | Gschwind | Oct 2013 | A1 |
20140007114 | Wang et al. | Jan 2014 | A1 |
20140059277 | Chung | Feb 2014 | A1 |
20140068383 | Cheng | Mar 2014 | A1 |
20140129812 | Chakrabarti et al. | May 2014 | A1 |
20140130021 | Lin et al. | May 2014 | A1 |
20140130052 | Lin et al. | May 2014 | A1 |
Number | Date | Country |
---|---|---|
1725176 | Jan 2006 | CN |
101176066 | May 2008 | CN |
101819675 | Sep 2010 | CN |
201140447 | Nov 2011 | TW |
201220246 | May 2012 | TW |
Entry |
---|
McCarthy Thomas, The Very Basic of Garbage Collection. Aug. 26, 2008. |
Chen Dehao, Tree Partition based Parallel Frequent Pattern mining on Shared Memory Systems, Apr. 25, 2006, IEEE. |
McCarthy, The Very Basic of Garbage Collection, Aug. 26, 2008. |
Steffen, Michael, et al., “Improving SIMT Efficiency of Global Rendering Algorithms with Architectural Support for Dynamic Micro-Kernels”, 2010, 43rd Annual IEEE/ACM International Symposium on Microarchitecture, 12 pages. |
Meng, Jiayuan, et al., “Dynamic Warp Subdivision for Integrated Branch and Memory Divergence Tolerance”, Jun. 2010, 12 pages. |
Reyes, Ruyman, et al., “accULL: An OpenACC Implementation with CUDA and OpenCL Support”, 2012, 12 pages. |
Number | Date | Country | |
---|---|---|---|
20140129783 A1 | May 2014 | US |
Number | Date | Country | |
---|---|---|---|
61722661 | Nov 2012 | US |