1.18k likes | 1.41k Views
Programming with GRID superscalar. Rosa M. Badia Toni Cortes Pieter Bellens, Vasilis Dialinos, Jesús Labarta, Josep M. Pérez, Raül Sirvent. Tutorial Detailed Description. Introduction to GRID superscalar (55%) 9:00AM-10:30AM GRID superscalar objective Framework overview
E N D
Programming with GRID superscalar Rosa M. Badia Toni Cortes Pieter Bellens, Vasilis Dialinos, Jesús Labarta, Josep M. Pérez, Raül Sirvent CLUSTER 2005 Tutorial Boston, 26th September 2005
Tutorial Detailed Description Introduction to GRID superscalar (55%) 9:00AM-10:30AM • GRID superscalar objective • Framework overview • A sample GRID superscalar code • Code generation: gsstubgen • Automatic configuration and compilation: Deployment center • Runtime library features Break 10:30-10:45am Programming with GRID superscalar (45%) 10:45AM-Noon • Users interface: • The IDL file • GRID superscalar API • User resource constraints and performance cost • Configuration files • Use of checkpointing • Use of the Deployment center • Programming Examples CLUSTER 2005 Tutorial Boston, 26th September 2005
Introduction to GRID superscalar • GRID superscalar objective • Framework overview • A sample GRID superscalar code • Code generation: gsstubgen • Automatic configuration and compilation: Deployment center • Runtime library features CLUSTER 2005 Tutorial Boston, 26th September 2005
Grid 1. GRID superscalar Objective • Ease the programming of GRID applications • Basic idea: ns seconds/minutes/hours CLUSTER 2005 Tutorial Boston, 26th September 2005
1. GRID superscalar Objective • Reduce the development complexity of Grid applications to the minimum • writing an application for a computational Grid may be as easy as writing a sequential application • Target applications: composed of tasks, most of them repetitive • Granularity of the tasks of the level of simulations or programs • Data objects are files CLUSTER 2005 Tutorial Boston, 26th September 2005
2. Framework overview • Behavior description • Elements of the framework CLUSTER 2005 Tutorial Boston, 26th September 2005
2.1 Behavior description for (int i = 0; i < MAXITER; i++) { newBWd = GenerateRandom(); subst (referenceCFG, newBWd, newCFG); dimemas (newCFG, traceFile, DimemasOUT); post (newBWd, DimemasOUT, FinalOUT); if(i % 3 == 0) Display(FinalOUT); } fd = GS_Open(FinalOUT, R); printf("Results file:\n"); present (fd); GS_Close(fd); Input/output files CLUSTER 2005 Tutorial Boston, 26th September 2005
Subst Subst Subst DIMEMAS Subst DIMEMAS Subst Subst DIMEMAS EXTRACT DIMEMAS EXTRACT … DIMEMAS DIMEMAS EXTRACT EXTRACT EXTRACT EXTRACT Display CIRI Grid Display Subst DIMEMAS GS_open EXTRACT 2.1 Behavior description CLUSTER 2005 Tutorial Boston, 26th September 2005
CIRI Grid 2.1 Behavior description Subst Subst Subst DIMEMAS Subst DIMEMAS Subst Subst DIMEMAS Subst EXTRACT DIMEMAS EXTRACT … DIMEMAS DIMEMAS EXTRACT DIMEMAS EXTRACT EXTRACT EXTRACT EXTRACT Display Display GS_open CLUSTER 2005 Tutorial Boston, 26th September 2005
2.2 Elements of the framework • Users interface • Code generation: gsstubgen • Deployment center • Runtime library CLUSTER 2005 Tutorial Boston, 26th September 2005
2.2 Elements of the framework • Users interface • Assembly language for the GRID • Well defined operations and operands • Simple sequential programming on top of it (C/C++, Perl, …) • Three components: • Main program • Subroutines/functions • Interface Definition Language (IDL) file CLUSTER 2005 Tutorial Boston, 26th September 2005
2.2 Elements of the framework 2. Code generation: gsstubgen • Generates the code necessary to build a Grid application from a sequential application • Function stubs (master side) • Main program (worker side) CLUSTER 2005 Tutorial Boston, 26th September 2005
2.2 Elements of the framework 3. Deployment center • Designed for helping user • Grid configuration setting • Deployment of applications in local and remote servers CLUSTER 2005 Tutorial Boston, 26th September 2005
2.2 Elements of the framework 4. Runtime library • Transparent access to the Grid • Automatic parallelization between operations at run-time • Uses architectural concepts from microprocessor design • Instruction window (DAG), Dependence analysis, scheduling, locality, renaming, forwarding, prediction, speculation,… CLUSTER 2005 Tutorial Boston, 26th September 2005
3. A sample GRID superscalar code • Three components: • Main program • Subroutines/functions • Interface Definition Language (IDL) file • Programming languages: • C/C++, Perl • Prototype version for Java and shell script CLUSTER 2005 Tutorial Boston, 26th September 2005
3. A sample GRID superscalar code • Main program: A Typical sequential program for (int i = 0; i < MAXITER; i++) { newBWd = GenerateRandom(); subst (referenceCFG, newBWd, newCFG); dimemas (newCFG, traceFile, DimemasOUT); post (newBWd, DimemasOUT, FinalOUT); if(i % 3 == 0) Display(FinalOUT); } fd = GS_Open(FinalOUT, R); printf("Results file:\n"); present (fd); GS_Close(fd); CLUSTER 2005 Tutorial Boston, 26th September 2005
3. A sample GRID superscalar code • Subroutines/functions void dimemas(in File newCFG, in File traceFile, out File DimemasOUT) { char command[500]; putenv("DIMEMAS_HOME=/usr/local/cepba-tools"); sprintf(command, "/usr/local/cepba-tools/bin/Dimemas -o %s %s", DimemasOUT, newCFG ); GS_System(command); } void display(in File toplot) { char command[500]; sprintf(command, "./display.sh %s", toplot); GS_System(command); } CLUSTER 2005 Tutorial Boston, 26th September 2005
3. A sample GRID superscalar code • Interface Definition Language (IDL) file • CORBA-IDL Like Interface: • In/Out/InOut files • Scalar values (in or out) • The subroutines/functions listed in this file will be executed in a remote server in the Grid. interface MC { void subst(in File referenceCFG, in double newBW, out File newCFG); void dimemas(in File newCFG, in File traceFile, out File DimemasOUT); void post(in File newCFG, in File DimemasOUT, inout File FinalOUT); void display(in File toplot) }; CLUSTER 2005 Tutorial Boston, 26th September 2005
3. A sample GRID superscalar code • GRID superscalar programming requirements • Main program (master side): • Begin/finish with calls GS_On, GS_Off • Open/close files with: GS_FOpen, GS_Open, GS_FClose, GS_Close • Possibility of explicit synchronization: GS_Barrier • Possibility of declaration of speculative areas: GS_Speculative_End(func) • Subroutines/functions (worker side): • Temporal files on local directory or ensure uniqueness of name per subroutine invocation • GS_System instead of system • All input/output files required must be passed as arguments • Possibility of throwing exceptions: GS_Throw CLUSTER 2005 Tutorial Boston, 26th September 2005
client server 4. Code generation: gsstubgen app.idl gsstubgen app-stubs.c app.h app.c app-worker.c app-functions.c app_constraints.cc app_constraints_wrapper.cc app_constraints.h CLUSTER 2005 Tutorial Boston, 26th September 2005
4. Code generation: gsstubgen app-stubs.c IDL function stubs app.h IDL functions headers app_constraints.cc User resource constraints and perfomance cost app_constraints.h app_constraints_wrapper.cc app-worker.c Main program for the worker side (calls to user functions) CLUSTER 2005 Tutorial Boston, 26th September 2005
4. Code generation: gsstubgen Sample stubs file #include <stdio.h> … int gs_result; void Subst(file referenceCFG, double seed, file newCFG) { /* Marshalling/Demarshalling buffers */ char *buff_seed; /* Allocate buffers */ buff_seed = (char *)malloc(atoi(getenv("GS_GENLENGTH"))+1); /* Parameter marshalling */ sprintf(buff_seed, "%.20g", seed); Execute(SubstOp, 1, 1, 1, 0, referenceCFG, buff_seed, newCFG); /* Deallocate buffers */ free(buff_seed); } … CLUSTER 2005 Tutorial Boston, 26th September 2005
4. Code generation: gsstubgen Sample worker main file #include <stdio.h> … int main(int argc, char **argv) { enum operationCode opCod = (enum operationCode)atoi(argv[2]); IniWorker(argc, argv); switch(opCod) { case SubstOp: { double seed; seed = strtod(argv[4], NULL); Subst(argv[3], seed, argv[5]); } break; … } EndWorker(gs_result, argc, argv); return 0; } CLUSTER 2005 Tutorial Boston, 26th September 2005
4. Code generation: gsstubgen Sample constraints skeleton file #include "mcarlo_constraints.h" #include "user_provided_functions.h" string Subst_constraints(file referenceCFG, double seed, file newCFG) { string constraints = ""; return constraints; } double Subst_cost(file referenceCFG, double seed, file newCFG) { return 1.0; } … CLUSTER 2005 Tutorial Boston, 26th September 2005
4. Code generation: gsstubgen Sample constraints wrapper file (1) #include <stdio.h> … typedef ClassAd (*constraints_wrapper) (char **_parameters); typedef double (*cost_wrapper) (char **_parameters); // Prototypes ClassAd Subst_constraints_wrapper(char **_parameters); double Subst_cost_wrapper(char **_parameters); … // Function tables constraints_wrapper constraints_functions[4] = { Subst_constraints_wrapper, … }; cost_wrapper cost_functions[4] = { Subst_cost_wrapper, … }; CLUSTER 2005 Tutorial Boston, 26th September 2005
4. Code generation: gsstubgen Sample constraints wrapper file (2) ClassAd Subst_constraints_wrapper(char **_parameters) { char **_argp; // Generic buffers char *buff_referenceCFG; char *buff_seed; // Real parameters char *referenceCFG; double seed; // Read parameters _argp = _parameters; buff_referenceCFG = *(_argp++); buff_seed = *(_argp++); //Datatype conversion referenceCFG = buff_referenceCFG; seed = strtod(buff_seed, NULL); string _constraints = Subst_constraints(referenceCFG, seed); ClassAd _ad; ClassAdParser _parser; _ad.Insert("Requirements", _parser.ParseExpression(_constraints)); // Free buffers return _ad; } CLUSTER 2005 Tutorial Boston, 26th September 2005
4. Code generation: gsstubgen Sample constraints wrapper file (3) double Subst_cost_wrapper(char **_parameters) { char **_argp; // Generic buffers char *buff_referenceCFG; char *buff_referenceCFG; char *buff_seed; // Real parameters char *referenceCFG; double seed; // Allocate buffers // Read parameters _argp = _parameters; buff_referenceCFG = *(_argp++); buff_seed = *(_argp++); //Datatype conversion referenceCFG = buff_referenceCFG; seed = strtod(buff_seed, NULL); double _cost = Subst_cost(referenceCFG, seed); // Free buffers return _cost; } … CLUSTER 2005 Tutorial Boston, 26th September 2005
app-worker.c app-worker.c app-functions.c app-functions.c serveri serveri 4. Code generation: gsstubgen Binary building app.c app_constraints_wrapper.cc app_constraints.cc . . . app-stubs.c GRID superscalar runtime GT2 client Globus services: gsiftp, gram CLUSTER 2005 Tutorial Boston, 26th September 2005
4. Code generation: gsstubgen Putting all together: involved files User provided files app.idl app-functions.c app.c Files generated from IDL app-stubs.c app.h app-worker.c app_constraints.cc app_constraints_wrapper.cc app_constraints.h Files generated by deployer config.xml (projectname).xml CLUSTER 2005 Tutorial Boston, 26th September 2005
4. Code generation: gsstubgen GRID superscalar applications architecture CLUSTER 2005 Tutorial Boston, 26th September 2005
5. Deployment center • Java based GUI. Allows: • Specification of grid computation resources: host details, libraries location… • Allows selection of Grid configuration • Grid configuration checking process: • Aliveness of host (ping) • Globus service is checked by submitting a simple test • Sends a remote job that copies the code needed in the worker, and compiles it • Automatic deployment • sends and compiles code in the remote workers and the master • Configuration files generation CLUSTER 2005 Tutorial Boston, 26th September 2005
5. Deployment center Automatic deployment CLUSTER 2005 Tutorial Boston, 26th September 2005
6. Runtime library features • Initial prototype over Condor and MW • Current version over Globus 2.4, Globus 4.0, ssh/scp, Ninf-G2 • File transfer, security and other features provided by the middleware (Globus, …) CLUSTER 2005 Tutorial Boston, 26th September 2005
Data dependence analysis File Renaming Task scheduling Resource brokering Shared disks management and file transfer policy Scalar results collection Checkpointing at task level API functions implementation 6. Runtime library features CLUSTER 2005 Tutorial Boston, 26th September 2005
Subst Subst Subst DIMEMAS Subst DIMEMAS DIMEMAS EXTRACT EXTRACT EXTRACT Display 6.1 Data-dependence analysis • Data dependence analysis • Detects RaW, WaR, WaW dependencies based on file parameters • Oriented to simulations, FET solvers, bioinformatic applications • Main parameters are data files • Tasks’ Directed Acyclic Graph is built based on these dependencies CLUSTER 2005 Tutorial Boston, 26th September 2005
6.2 File renaming While (!end_condition()) { T1 (…,…, “f1”); T2 (“f1”, …, …); T3 (…,…,…); } WaR • WaW and WaR dependencies are avoidable with renaming T1_1 T1_2 T1_N “f1_2” “f1_1” “f1” “f1” “f1” … WaW T2_1 T2_2 T1_N T3_1 T3_2 T1_N CLUSTER 2005 Tutorial Boston, 26th September 2005
6.3 Task scheduling • Distributed between the Execute call, the callback function and the GS_Barrier call • Possibilities • The task can be submitted immediately after being created • Task waiting for resource • Task waiting for data dependency • Task submission composed of • File transfer • Task submission • All specified in Globus RSL (for Globus case) CLUSTER 2005 Tutorial Boston, 26th September 2005
6.3 Task scheduling • Temporal directory created in the server working directory for each task • Calls to globus: • globus_gram_client_job_request • globus_gram_client_callback_allow • globus_poll_blocking • End of task notification: Asynchronous state-change callbacks monitoring system • globus_gram_client_callback_allow() • callback_func function • Data structures update in Execute function, GRID superscalar primitives and GS_Barrier • GS_Barrier primitive before ending the program that waits for all tasks (performed inside GS_Off) CLUSTER 2005 Tutorial Boston, 26th September 2005
6.4 Resource brokering • When a task is ready for execution, the scheduler tries to allocate a resource • Broker receives a request • The classAd library is used to match resource ClassAds with task ClassAds • If more than one resources fulfils the constraint, the resource which minimizes this formula is selected: • FT = File transfer time to resource r • ET = Execution time of task t on resource r (using user provided cost function) CLUSTER 2005 Tutorial Boston, 26th September 2005
6.5 Shared disks management and file transfer policy File transfers policy f1 T1 Working directories f1 f4 f4 (temp.) T1 T2 server1 f7 f1 f7 f4 f7 T2 client server2 CLUSTER 2005 Tutorial Boston, 26th September 2005
6.5 Shared disks management and file transfer policy Shared working directories (NFS) Working directories T1 f1 server1 f7 f7 f1 f4 client T2 server2 CLUSTER 2005 Tutorial Boston, 26th September 2005
6.5 Shared disks management and file transfer policy Shared input disks Input directories server1 client server2 CLUSTER 2005 Tutorial Boston, 26th September 2005
6.6 Scalar results collection • Collection of output parameters which are not files • Main code cannot continue until the scalar result value is obtained • Partial barrier synchronization … grid_task_1 (“file1.txt”, “file2.cfg”, var_x); if (var_x>10){ … • Socket and file mechanisms provided output variable CLUSTER 2005 Tutorial Boston, 26th September 2005
6.7 Task level checkpointing • Inter-task checkpointing • Recovers sequential consistency in the out-of-order execution of tasks 0 1 2 3 3 4 5 6 Completed Successful execution Running Committed CLUSTER 2005 Tutorial Boston, 26th September 2005
6.7 Task level checkpointing • Inter-task checkpointing • Recovers sequential consistency in the out-of-order execution of tasks 0 1 2 3 3 4 5 6 Finished correctly Completed Failing execution Running Cancel Committed Failing CLUSTER 2005 Tutorial Boston, 26th September 2005
6.7 Task level checkpointing • Inter-task checkpointing • Recovers sequential consistency in the out-of-order execution of tasks 0 1 2 3 3 4 5 6 Finished correctly Completed Restart execution Running Committed Execution continues normally! Failing CLUSTER 2005 Tutorial Boston, 26th September 2005
6.7 Task level checkpointing • On fail: from N versions of a file to one version (last committed version) • Transparent to application developer CLUSTER 2005 Tutorial Boston, 26th September 2005
6.8 API functions implementation • Master side • GS_On • GS_Off • GS_Barrier • GS_FOpen • GS_FClose • GS_Open • GS_Close • GS_Speculative_End(func) • Worker side • GS_System • GS_Throw CLUSTER 2005 Tutorial Boston, 26th September 2005
6.8 API functions implementation • Implicit task synchronization – GS_Barrier • Inserted in the user main program when required • Main program execution is blocked • globus_poll_blocking() called • Once all tasks are finished the program may resume CLUSTER 2005 Tutorial Boston, 26th September 2005
6.8 API functions implementation • GRID superscalar file management API primitives: • GS_FOpen • GS_FClose • GS_Open • GS_Close • Mandatory for file management operations in main program • Opening a file with write option • Data dependence analysis • Renaming is applied • Opening a file with read option • Partial barrier until the task that is generating that file as output file finishes • Internally file management functions are handled as local tasks • Task node inserted • Data-dependence analysis • Function locally executed • Future work: offer a C library with GS semantic (source code with typical calls could be used) CLUSTER 2005 Tutorial Boston, 26th September 2005