Docsity

Polymorphic Processors: Programming Models, Lecture notes of Programming Languages

Toggle sidebar
bg1
EE392C: Advanced Topics in Computer Architecture Lecture #9
Polymorphic Processors
Stanford University Tuesday, May 6, 2003
Programming Models
Lecture #9: Tuesday, 29 April 2003
Lecturer: Paul W. Lee, Rebecca Schultz, Varun S. Malhotra
Scribe: Sorav Bansal, Brad Schumitsch
1 Introduction
The need for a simple, correct and general programming model cannot be over-emphasized.
A good programming model is instrumental in mapping the parallelism in the application
to the support for parallelism in the hardware. There are two perspectives to keep in
mind when designing a programming model - the perspective of the programmer and the
perspective of the compiler-writer.
From the point of view of the programmer
1. The interface should be easy and intuitive
2. The model should make it easy for the programmer to identify parallelism and
indicate it. The complexity should be hidden by the compiler.
3. The programming model should be architecture-independent
4. The programmer should not need to worry about details like locality-of-usage.
From the point of view of the Compiler-Writer
The program structure should convey some parallelism that the compiler can exploit.
This parallelism could be either ILP, TLP or ILP. Present-day programming languages
like C hide everything but ILP.
The papers we discussed ([1], [2], [3]) present three different approaches to program-
ming model design.
2 Paper Summaries
2.1 Container-Centric Approach For Parallelizing Applications
([1])
Parallelizing compilers have been successful in array based numerical applications, but
the success has been limited in other areas. To effectively parallelize applications for
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Polymorphic Processors: Programming Models and more Lecture notes Programming Languages in PDF only on Docsity!

EE392C: Advanced Topics in Computer Architecture Lecture # Polymorphic Processors Stanford University Tuesday, May 6, 2003

Programming Models

Lecture #9: Tuesday, 29 April 2003 Lecturer: Paul W. Lee, Rebecca Schultz, Varun S. Malhotra Scribe: Sorav Bansal, Brad Schumitsch

1 Introduction

The need for a simple, correct and general programming model cannot be over-emphasized. A good programming model is instrumental in mapping the parallelism in the application to the support for parallelism in the hardware. There are two perspectives to keep in mind when designing a programming model - the perspective of the programmer and the perspective of the compiler-writer.

From the point of view of the programmer

  1. The interface should be easy and intuitive
  2. The model should make it easy for the programmer to identify parallelism and indicate it. The complexity should be hidden by the compiler.
  3. The programming model should be architecture-independent
  4. The programmer should not need to worry about details like locality-of-usage.

From the point of view of the Compiler-Writer The program structure should convey some parallelism that the compiler can exploit. This parallelism could be either ILP, TLP or ILP. Present-day programming languages like C hide everything but ILP.

The papers we discussed ([1], [2], [3]) present three different approaches to program- ming model design.

2 Paper Summaries

2.1 Container-Centric Approach For Parallelizing Applications

([1])

Parallelizing compilers have been successful in array based numerical applications, but the success has been limited in other areas. To effectively parallelize applications for

Parallelism in Application

Programming Model

Support for Parallelism in Hardware

these other areas, the compiler should be aware of the attributes of a program in terms of its aggregate data structures.

This paper presents the concept of containers, any general-purpose aggregate data type such as matrices, lists, tables, graphs and I/O streams. The use of containers is very similar in most programs independent of implementation, and can be abstracted for use in data analysis and parallelization. The paper uses two of the most common containers to demonstrate its ideas. Linear containers are containers where its elements are accessed in a linear manner, such as lists, stacks and queues. Content-addressable container elements are accessed through keys. Examples of this are tables, sets, and maps.

Containers are central to the flow of data, and are a primary source of data parallelism, but conventional compilers are not aware of the structure of containers and thus cannot take advantage of the information at this level. In order to describe concrete containers to the compiler, the paper introduces abstract containers and methods. The compiler takes as input, in addition to the source code, the container description in terms of abstract containers, to perform container specific analysis and transformation to parallelize the program.

The paper discusses container-based transformation techniques such as loop paral- lelization, container privatization, and exploiting associativity. All of these transforma- tions are analogous to similar transformations on arrays. Dependency test methods are also explored. Range checks are used for linear containers, and commutativity analysis is used for content-addressable containers. Disjoint keys result in commutativity, but overlapping keys are very difficult to analyze. The pattern search-otherwise insert is suggested as a possible commutative case.

A number of Java, C++, and C applications were studied to identify possible trans- formation techniques. The applications were manually parallelized using the above- mentioned techniques, and large parts of the applications could be parallelized. The paper unfortunately does not give any results to indicate how effective these transforma- tions were in terms of performance improvement.

The paper proposes using the information at the data structure level to parallelize programs. The widespread use of containers such as C++ STL makes this approach very attractive as a way to attain higher levels of parallelization without burdening the programmer. The notion of abstract containers is useful as a specification language for

Although these contructs ensure correctness of the Jade programs but there can be some pathological situations wherein these constructs don’t exploit the inherent parallelism in the program. This motivates the need for decoupling ”positive” information (which helps in synchronisation) and ”negative” information (helps in concurrency) and other constructs that provide only positive or only negative information are discussed. Such constructs are used to reduce the enclosing task’s specified set of effects in the hope that this reduction may eliminate conflicts between the enclosing task and tasks occuring later in the sequential execution order. The paper also discusses the Jade datatype, tokens, which are helpful in matching the coarse grain tasks with the coarse pieces of data they access. Each token functions as a synchronisation data abstraction by carrying the dependence for a conceptual unit of data. The Jade implementation presented in this paper is only applicable to machines with single address space but method has been suggested for extending it to machines with separate address spaces. In order to fully utilize Jade’s capabilities, the grain size should be huge. If grain size is fine, then the overhead of the Jade’s runtime systme may override the benefits we gain from parallelizing the tasks. The main strengths of this paper is that it sticks to the sequential programming model paradigm without putting the burden of managing explicit concurrency constructs on the programmer. The authors claim that Jade achieves speedup comparable to most efficient parallel programs howver, the experiments discussed in the paper are not exhaustive to support this argument. It is not very apparent from the paper where to draw the task boundaries given a sequential program. Another problem with Jade is that it cannot express algorithms requiring bidirectional task communication since synchronization and data flow unidirectionally from tasks occurring earlier in the sequential execution order to tasks occurring later, in Jade. This is a classic example of a trade-off between ”generality” of a system and its ”efficiency”.

2.3 A Stream Compiler for Communication-Exposed Architec-

tures ([3])

StreamIt is a high level language intended for streaming applications. The language requires has a specific rigid structure, allowing the compiler to simply extract communi- cation and parallelism, and the programmer to ignore architectural details such as the granularity of the topology. The language is intended for the RAW chip-multiprocessor system but the designers state that it could be used for any parallel multiprocessor sys- tem. However, StreamIt can only be used to express a program where the filters have fixed input and output rates; it would be unable to do data compression or decompression, for example. The programming model requires the programmer to express the intended function as a series of filters to be applied to a stream of data. These filters are connected together using a set of commands expressing their structure. Each filter statement is a single input-single output block. Communication between filters is abstracted as an infinite

FIFO. Within this block, the stream data can be accessed via three methods, push, pop and peek, allowing removal, addition and inspection without removal of the stream items. The statements for connected the filter nodes together are pipeline statements, which establish a sequential series of filters, splitjoin statements, which generate parallel streams that diverge from a single stream, and feedbackloop statements, which create a cycle in the graph. The StreamIt compiler analyzes the stream graph and maps it onto the hardware. It is a three phase process. In the first phase is called the portioning phase. The compiler merges and splits the filter statements until there is a single filter for each processing element in the hardware topology and these filters are balanced to have approximately the same execution time. The second phase of the compiler is the layout phase. In this phase the compiler takes the filters from the portioning phase and chooses which pro- cessing element should execute each one. A cost function is used to represent the cost of communication latencies and a simple simulated annealing algorithm is used. The third phase is the communication scheduling phase. In this phase the compiler converts the communication between filters implicit in the stream graph into communication instruc- tions appropriate for the hardware. The compiler must be careful to avoid starvation or deadlock. The StreamIt language and compiler are appropriate for the RAW architecture for which it was designed, but despite the authors claim that it is useful for other parallel architectures, a number of features reduce the reusability of the design. For one thing the model extracts parallelism from the individual processors during the portioning phase. Once filters have been merged and split into a single filter for each processing node, the filter is executed sequentially on that processing element. There are no opportunities to extract additional parallelism at the elements. Additionally, while the implicit communi- cation model in the stream language maps well to the communication network in RAW, it may not work well on other architectures. The StreamIt programming language also has the additional weaknesses that it re- quires static rate streams. Also, sends and receives can not be interleaved, all data must be received by a filter before it can be processed. Despite some weaknesses, the program- ming model does provide a way of efficiently executing a stream program that fits its requirements on a hardware architecture with which it is compatible.

3 Discussion Notes

After studying three different programming models, the discussion time was spent in identifying the strengths and weaknesses of the three suggested approaches.

3.1 Perspectives

Why have these approaches not been widely adopted? It has been noticed that, while people have suggested various programming models, most

  • Jade: The Jade programming model tells the compiler about the data and control dependencies. It dilineates different tasks and explicitly identifies the shared data. However, it tells the compiler nothing about the memory access patterns.
  • StreamIt: The Streamit model helps identify task-level parallelism (eg. different filters), data dependencies, as well as memory access patterns (eg. FIFOs). Thus, it makes the job of the compiler writer relatively easier. The catch, however, is that the programming model caters to a very limited set of applications. It requires fixed rate streams exhibiting fixed communication patterns. Variable output rates (eg. Data compression) cannot be handled very well by the StreamIt programming model.
  • Brook: Brook is designed to program the next version of Imagine. It has support for multiple dimension streams to allow for scientific computing. In Brook, function calls to variable rate streams are allowed, thus ameliorating some of the drawbacks of StreamIt. The programming model is not tied to the number of processors in the underlying machine. However, no loop carried dependencies are allowed in a kernel. The kernels need to be data-parallel. In StreamC, the programmer had to do cluster communication herself, while in Brook communication is inferred.

3.2 Shared Memory vs Message Passing Models

The programming models for parallel programming can be broadly categorized into the Shared-Memory Model (SMP) and the Message Passing Model (MPP). The shared mem- ory model works by using fork and join to create and synchronize processes. The main difficulty in the Shared Memory model is fine-grained synchronization of shared mem- ory. The canonical ways to synchronize shared memory is through locks and barriers. Programmers often complain about the difficulty in guarding against race conditions and deadlocks in the SMP model. The Jade programming model also suffers from this lacuna since the programmer needs to explicitly provide information about shared variables.

The StreamIt model falls into the MPP category. The programmer does not need to worry about synchronization problems. However, writing the program in StreamIt may itself be quite tough.

Using containers, the programmer doesn’t have to worry about synchronization. Dif- ferent sections of the container may be executed in parallel, but this is managed by libraries and the programmer need not be concerned.

In general, message passing code is harder to write the first time, but it is easier to debug. Conversely, writing a program with locks and joins is easy to get running at the first pass. However, it is hard to debug and optimize these programs since the locks and joins hide memory transactions.

On a different note, it is interesting to see why the container approach seems promising. It has been noticed, that a small number of data structures are used over and over again in most programs. It turns out there are approximately 10-15 data structures that cover most cases: linked-lists, hash tables, etc. Hence, it makes sense to have these 10 data structures implemented in a library (such as containers) and we can expect performance gains in most cases.

3.3 How well do these models scale?

Jade scales fine only to the thread-level. Since there is not that much thread-level par- allelism, it may not scale too well to too many nodes for many applications.

StreamIt scales very well, to as many filters as your application can support. It scales as long as the application data rates scale.

Containers scale well only for data-level parallelism. They cannot scale to task-level parallelism. The scalability of the container approach depends on the size of the data structures. For example, you would need a linked list with thousands of elements for this approach to scale.

3.4 Polymorphism Opportunities

It would be good if the programming model can somehow indicate, which processor should the base architecture mimic to obtain maximum performance.

If your program is in StreamIt, it is easy for the compiler to decide to run your pro- gram on an Imagine-like architecture, since most StreamIt programs will have a lot of data-parallelism. In some sense, this is the complier choosing the configuration of the machine. However, in some sense, the decision was taken by the programmer when she chose to write the program in StreamIt. It is trivial to map threads from StreamIt code to processors. The compiler can statically build the flow graph and then assign the nodes to filters in a one-to-one manner. The communication between filters can be aided by configuring parts of the processor as hardware FIFOs.

In the container based approach, some hardware optimizations can be done to make the data structures faster. For example, a hardware FIFO could be used for a queue data structure.

In Jade, the run-time system must keep track of dependencies and it needs to sched- ule non-blocked tasks to existing processors. Threads that are blocked and switched out of a processor should be returned to the same processor due to cache warming (aka affinity

Container Jade StreamIt Programmer’s Need to identify Need to explicitly Need to explicitly viewpoint supported data manage synchronization identify streams structures and filters Compiler Exposes Memory Access Exposes task-level Exposes both task Writer’s Pattern and DLP. Does parallelism and shared level parallelism viewpoint not expose TLP. structures. No info on and memory access memory access patterns patterns Generality Helps for applications Helps for applications Suited to a very with DLP. Almost all with TLP, any program limited class of applications use with TLP can applications supported data use Jade structures. Scalability Parallelism Limited Scales only to the Scales very well as by the size of data number of independent long as the data structure. threads identified by rates scale. Limited by the programmer by number of filters Polymorphism Allows compiler to Can optimize hardware Preferred Opportunity optimize hardware for to implement runtime configuration is a data structures (e.g. support to schedule stream architecture Queue = hardware FIFO) tasks in parallel. like IMAGINE

References

[1] P. Wu, D Padua. Beyond Arrays: A Container-centric Approach on Parallelization of Real-world Symbolic Applications. Proceedings of the 11th International. Workshop of Language and Compilers for Parallel Computing, NC, August 1998.

[2] Monica S. Lam and Martin C. Rinard. Coarse-Grain Parallel Programming in Jade. In Proceedings of the Third ACM SIGPLAN Symposium on Principles and Practice of Parallel Programming, April 1991.

[3] M. Gordon, W. Thies, M. Karczmarek, J. Lin, A.S. Meli, A. Lamb, C. Leger, J. Wong, H. Hoffmann, D. Maze, S. Amarasinghe. A Stream Compiler for Communication- Exposed Architectures. In ASPLOS 2002, San Jose, CA USA, October 2002.