Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lawrence Livermore National Laboratory Automated Extraction of Skeleton Apps from Apps February 2012 Daniel Quinlan (LLNL) Matt Sottile (Galois), Aaron.

Similar presentations


Presentation on theme: "Lawrence Livermore National Laboratory Automated Extraction of Skeleton Apps from Apps February 2012 Daniel Quinlan (LLNL) Matt Sottile (Galois), Aaron."— Presentation transcript:

1 Lawrence Livermore National Laboratory Automated Extraction of Skeleton Apps from Apps February 2012 Daniel Quinlan (LLNL) Matt Sottile (Galois), Aaron Tomb (Galois) Lawrence Livermore National Laboratory, P. O. Box 808, Livermore, CA Operated by Lawrence Livermore National Security, LLC, or the U.S. Department of Energy, National Nuclear Security Administration under Contract DE-AC52-07NA27344

2 2 What is a Skeleton and why you want one  A skeleton is a reduced size version of an application that focuses on one or more aspects of the behavior of the full original application. Examples include: MPI usage, message passing patterns; memory traversal; I/O demands  This is important for Exascale: Provides inputs to simulators for evaluation of expected Exascale architectures and features (e.g. SST/macro) Provides smaller applications for independent study  A skeleton program will not get the same answer as the original application  There is prior work in this area…  I think we are the only ones with a distributed tool for this…

3 3 CoDesign Tool Flow Automatic Generation of Skeletons for Rapid Analysis 3 This talk is about these arrows

4 4 We can generate many skeletons from an App  Many skeletons could be generated from a single application  The process can work on full applications or smaller compact applications Single App with many files Aspect A Aspect B Aspect X Skeleton A Skeleton B Skeleton X Many Skeleton Apps each with maybe many files

5 5 An Automated or Semi-Automated Process  We treat this as a compiler research problem  We are building tools to automate the generation of skeletons, but some questions are difficult to resolve May require dynamic analysis to identify important values May require some user annotations to define some behavior  We start with the original application and transform it to modify and remove code to define an automated process; this is a source-to-source solution

6 6 We are using the ROSE Source-To-Source Compiler to support this work Science & Technology: Computation Directorate Source Code Fortran/C/C++ OpenMP Transformed Source Code ROSE IR Analyses/ Transformation/ Optimizations System-dependency Sliced-system- dependency Control- Flow Control dependency Control flow Unparser ROSE Frontend ROSE-based Skeleton Generation Tool

7 7 A Non-trivial problem to Automate  Different aspects are related (they are not actually orthogonal) Example: inter-message timings are a function of the computational work that an app does.  Static analysis is not always precise, and dynamic analysis is not always complete  We are focused on using static analysis and formal methods to generate plausible, realistic skeletons is the focus of our research work.

8 8 Example of Automated Skeleton Code Generation: Before/After do { if (rank < size - 1) MPI_Send( xlocal[maxn/size], maxn, MPI_DOUBLE, rank + 1, 0, MPI_COMM_WORLD ); if (rank > 0) MPI_Recv( xlocal[0], maxn, MPI_DOUBLE, rank - 1, 0, MPI_COMM_WORLD, &status ); if (rank > 0) MPI_Send( xlocal[1], maxn, MPI_DOUBLE, rank - 1, 1, MPI_COMM_WORLD ); if (rank < size - 1) MPI_Recv( xlocal[maxn/size+1], maxn, MPI_DOUBLE, rank + 1, 1, MPI_COMM_WORLD, &status ); itcnt ++; diffnorm = 0.0; for (i=i_first; i<=i_last; i++) for (j=1; j 1.0e-2 && itcnt < 100); do { if (rank < size - 1) MPI_Send( xlocal[maxn / size], maxn, MPI_DOUBLE, rank + 1, 0, MPI_COMM_WORLD ) if (rank > 0) MPI_Recv( xlocal[0], maxn, MPI_DOUBLE, rank - 1, 0, MPI_COMM_WORLD, &status ); if (rank > 0) MPI_Send( xlocal[1], maxn, MPI_DOUBLE, rank - 1, 1, MPI_COMM_WORLD ); if (rank < size - 1) MPI_Recv( xlocal[maxn/size+1], maxn, MPI_DOUBLE, rank + 1, 1, MPI_COMM_WORLD, &status ); itcnt ++; MPI_Allreduce( &diffnorm, &gdiffnorm, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD ); } while (gdiffnorm > 1.0e-2 && itcnt < 100); Before After

9 9 Example of Automated Skeleton Code Generation: Larger example  Source-to-source transformation  Def-use analysis of variables leading to MPI calls  Future work will explore use of: System Dependence Graph (SDG) Data flow framework and defined concepts of dead-code elimination. Can be supplemented with dynamic information Can be applied to abstract other things than MPI use #include #include "mpi.h" /* This example handles a 12 x 12 mesh, on 4 processors only. */ #define maxn 12 int main( argc, argv ) int argc; char **argv; { int rank, size, i, j, itcnt; int i_first, i_last; MPI_Status status; double diffnorm, gdiffnorm; double xlocal[(12/4)+2][12]; double xnew[(12/3)+2][12]; MPI_Init( &argc, &argv ); MPI_Comm_rank( MPI_COMM_WORLD, &rank ); MPI_Comm_size( MPI_COMM_WORLD, &size ); if (size != 4) MPI_Abort( MPI_COMM_WORLD, 1 ); /* xlocal[][0] is lower ghostpoints, xlocal[][maxn+2] is upper */ /* Note that top and bottom processes have one less row of interior points */ i_first = 1; i_last = maxn/size; if (rank == 0) i_first++; if (rank == size - 1) i_last--; /* Fill the data as specified */ for (i=1; i<=maxn/size; i++) for (j=0; j 0) MPI_Recv( xlocal[0], maxn, MPI_DOUBLE, rank - 1, 0, MPI_COMM_WORLD, &status ); /* Send down unless I'm at the bottom */ if (rank > 0) MPI_Send( xlocal[1], maxn, MPI_DOUBLE, rank - 1, 1, MPI_COMM_WORLD ); if (rank < size - 1) MPI_Recv( xlocal[maxn/size+1], maxn, MPI_DOUBLE, rank + 1, 1, MPI_COMM_WORLD, &status ); /* Compute new values (but not on boundary) */ itcnt ++; diffnorm = 0.0; for (i=i_first; i<=i_last; i++) for (j=1; j 1.0e-2 && itcnt < 100); MPI_Finalize( ); return 0; } #include #include "mpi.h" /* This example handles a 12 x 12 mesh, on 4 processors only. */ #define maxn 12 int main( argc, argv ) int argc; char **argv; { int rank, size, i, j, itcnt; int i_first, i_last; MPI_Status status; double diffnorm, gdiffnorm; double xlocal[(12/4)+2][12]; double xnew[(12/3)+2][12]; MPI_Init( &argc, &argv ); MPI_Comm_rank( MPI_COMM_WORLD, &rank ); MPI_Comm_size( MPI_COMM_WORLD, &size ); if (size != 4) MPI_Abort( MPI_COMM_WORLD, 1 ); /* xlocal[][0] is lower ghostpoints, xlocal[][maxn+2] is upper */ /* Note that top and bottom processes have one less row of interior points */ i_first = 1; i_last = maxn/size; if (rank == 0) i_first++; if (rank == size - 1) i_last--; /* Fill the data as specified */ for (i=1; i<=maxn/size; i++) for (j=0; j 0) MPI_Recv( xlocal[0], maxn, MPI_DOUBLE, rank - 1, 0, MPI_COMM_WORLD, &status ); /* Send down unless I'm at the bottom */ if (rank > 0) MPI_Send( xlocal[1], maxn, MPI_DOUBLE, rank - 1, 1, MPI_COMM_WORLD ); if (rank < size - 1) MPI_Recv( xlocal[maxn/size+1], maxn, MPI_DOUBLE, rank + 1, 1, MPI_COMM_WORLD, &status ); /* Compute new values (but not on boundary) */ itcnt ++; diffnorm = 0.0; for (i=i_first; i<=i_last; i++) for (j=1; j 1.0e-2 && itcnt < 100); MPI_Finalize( ); return 0; } Generated Skeleton Code: rank(int iteration) Original Source Code: rank(int iteration) void rank( int iteration ) { INT_TYPE i, k; INT_TYPE shift = MAX_KEY_LOG_2 - NUM_BUCKETS_LOG_2; INT_TYPE key; INT_TYPE2 bucket_sum_accumulator, j, m; INT_TYPE local_bucket_sum_accumulator; INT_TYPE min_key_val, max_key_val; INT_TYPE *key_buff_ptr; TIMER_START( T_RANK ); /* Iteration alteration of keys */ if(my_rank == 0 ) { key_array[iteration] = iteration; key_array[iteration+MAX_ITERATIONS] = MAX_KEY - iteration; } /* Initialize */ for( i=0; i> shift]++; /* Accumulative bucket sizes are the bucket pointers */ bucket_ptrs[0] = 0; for( i=1; i< NUM_BUCKETS; i++ ) bucket_ptrs[i] = bucket_ptrs[i-1] + bucket_size[i-1]; /* Sort into appropriate bucket */ for( i=0; i> shift]++] = key; } TIMER_STOP( T_RANK ); TIMER_START( T_RCOMM ); /* Get the bucket size totals for the entire problem. These will be used to determine the redistribution of keys */ MPI_Allreduce( bucket_size, bucket_size_totals, NUM_BUCKETS+TEST_ARRAY_SIZE, MP_KEY_TYPE, MPI_SUM, MPI_COMM_WORLD ); TIMER_STOP( T_RCOMM ); TIMER_START( T_RANK ); /* Determine Redistibution of keys: accumulate the bucket size totals till this number surpasses NUM_KEYS (which the average number of keys per processor). Then all keys in these buckets go to processor 0. Continue accumulating again until supassing 2*NUM_KEYS. All keys in these buckets go to processor 1, etc. This algorithm guarantees that all processors have work ranking; no processors are left idle. The optimum number of buckets, however, does not result in as high a degree of load balancing (as even a distribution of keys as is possible) as is obtained from increasing the number of buckets, but more buckets results in more computation per processor so that the optimum number of buckets turns out to be 1024 for machines tested. Note that process_bucket_distrib_ptr1 and..._ptr2 hold the bucket number of first and last bucket which each processor will have after the redistribution is done. */ bucket_sum_accumulator = 0; local_bucket_sum_accumulator = 0; send_displ[0] = 0; process_bucket_distrib_ptr1[0] = 0; for( i=0, j=0; i= (j+1)*NUM_KEYS ) { send_count[j] = local_bucket_sum_accumulator; if( j != 0 ) { send_displ[j] = send_displ[j-1] + send_count[j-1]; process_bucket_distrib_ptr1[j] = process_bucket_distrib_ptr2[j-1]+1; } process_bucket_distrib_ptr2[j++] = i; local_bucket_sum_accumulator = 0; } /* When NUM_PROCS approaching NUM_BUCKETS, it is highly possible that the last few processors don't get any buckets. So, we need to set counts properly in this case to avoid any fallouts. */ while( j < comm_size ) { send_count[j] = 0; process_bucket_distrib_ptr1[j] = 1; j++; } TIMER_STOP( T_RANK ); TIMER_START( T_RCOMM ); /* This is the redistribution section: first find out how many keys each processor will send to every other processor: */ MPI_Alltoall( send_count, 1, MPI_INT, recv_count, 1, MPI_INT, MPI_COMM_WORLD ); /* Determine the receive array displacements for the buckets */ recv_displ[0] = 0; for( i=1; i

10 10 Static Analysis Drives Skeleton Generation  First prototype: Generate skeleton representing message passing via static analysis (using the use- def analysis in ROSE)  Basic concept, where MPI is the target aspect: Identify message passing (MPI) operations. Preserve MPI operations and code that they depend on, removing superfluous code. Aim to remove large blocks of computational code, replacing it with surrogate code that is simpler to produce skeleton of app that contains essential message passing structure without the actual work.  Our research approach has been to explore four different forms of analysis to drive the skeleton generation: 1)Use-def analysis (to generate a form of program slice), works on the AST directly, not directly using the inter-procedural control flow graph (CFG) 2)Program slicing using ROSE’s System Dependence graph (SDG) which captures the def-use analysis and more on the inter-procedural control flow graph in ROSE 3)A new Data-Flow Framework in ROSE; another form of analysis using the interprocedural control flow graph in ROSE 4)Connections to Formal methods

11 11 Static Analysis: Program Slicing int returnMe (int me) { return me; } int main (int argc, char ** argv) { int a = 1; int b; returnMe(a); b = returnMe(a); #pragma SliceTarget return b; }  System (Inter-procedural) Dependence Analysis  A sequence of directed edges define a slice  Can be used for Model extraction

12 12 Data Flow as an alternative approach to Drive Skeleton Generation  Future work will explore the use of a new Data Flow Framework in ROSE to support analysis required to generate skeletons May be an easier way (for users) to specify aspects It is related to slicing in that it uses the same inter- procedural control flow graph internally  Each form of analysis (Use-def, SDG, and Data-Flow) are an orthogonal direction of work which share the common infrastructure we have built for skeleton generation.  The analysis and infrastructure in implemented using ROSE

13 13 A Generic API for Skeletonization  Generalized skeletonization target APIs Original work focused on skeletonizing relative to the MPI API. Current code extended to allow skeletons against any API (e.g., Visualization and Data Analysis, I/O and Storage, use of domain-specific abstractions, etc.) Important for building skeletons to probe different aspects of program behavior – IO, message passing, threading, app- specific libraries

14 14 Annotation guided skeletonization  Annotation guided skeletonization Previous work focused on purely dependency-based slicing. This led to problems:  Removal of computational code could cause loops to cease to converge (iterate forever).  Branching patterns no longer meaningful with computational code gone. Annotations let the user guide skeletonization to add semantics the skeleton that is impossible/difficult to statically infer.  Loop iteration counts ; branching probabilities ; variable initialization values.

15 15 Use of an Annotation Before/After int main() { int x = 0; int i; // execute exactly 10 times #pragma skel loopIterate 10 for (i = 0; x < 100 ; i++) { if (x % 2) x += 5; } return x; } int main() { int x = 0; int i; // execute exactly 10 times #pragma skel loopIterate 10 int k = 0; for (i = 0; k < 10; k++) {{ if ((x % 2) != 0) x += 5; } rose_label__1: i++; } return x; } Before After

16 16 User Work Flow for Skeletonization Science & Technology: Computation Directorate Original Application Program Dynamic Measurements Of Program Annotated Application Program Skeleton Program Skeleton Extraction Tool Observe Behavior Of Skeleton Satisfactory Behavior Keep Skeleton Unsatisfactory behavior: modify or add annotations to tune skeleton generator - Branch probabilities - Average loop iteration counts - Legitimate data values

17 17 Future work  SDG version of analysis for skeletonization  Using the new Data Flow framework in ROSE for skeletonization  Galois will be working on adding formal-methods-based analysis to the skeleton generator to analyze regions of code to remove. Floating point range analysis. Symbolic execution.  Formal methods will aim to answer questions to aid skeleton generation such as: What range of values do we expect a complex computation to produce?  Allows us to automatically select surrogate values for populating data structures  Know when specific values are critical Under specific input conditions, what code is reachable or not reachable?  Allows us to build skeletons for specific input circumstances, instead of generic skeletons  This is a connection to path feasibility analysis currently being developed in ROSE

18 18 Front-End Back-End AST Builder API High Level IRs (AST) IR Extension API (ROSETTA) High Level Analysis & Optimization Framework Exascale Architecture Mid-End Low Level Analysis & Optimization Low Level IR (LLVM) Unparser Existing LLVM Analysis & Optimization Exascale Vendor Compiler Infrastructures LLVM Backend Code Generation Exascale Vendor Compilers General Purpose Languages used within DOE Python C & C++Fortran (F77-F2003) UPC 1.1 OpenMP 3.0 CUDA ROSE Compiler Design


Download ppt "Lawrence Livermore National Laboratory Automated Extraction of Skeleton Apps from Apps February 2012 Daniel Quinlan (LLNL) Matt Sottile (Galois), Aaron."

Similar presentations


Ads by Google