Computer Architecture Processor Design Single thread pipeline branch
Computer Architecture • Processor Design • Single thread → pipeline, branch prediction • Multiple threads → SMT resource allocation, threads scheduling • Ετερογενείς αρχιτεκτονικές • General Purpose Computing, Gaming, and Entertainment Devices – Intel Haswell, Broadwell, Skylake with/without Graphics (Iris Pro, HD) – AMD Fusion, AMD APUs (Jaguar in PS 4) – IBM Power 9 • Intel hybrid CPU-FPGA – 2010 Stellarton: Atom E 600 C + Altera FPGA – 2017 Skylake CPU + Aria 10 FPGA • ARM (big. LITTLE) • HSA architectures cslab@ntua 2018 -2019 2
Computer Architecture • Ιεραρχία μνήμης – – Multiple levels Cache sharing NUMA Coherence Protocols • Παράλληλα συστήματα – Coherence, Δίκτυα διασύνδεσης – Compilers, automatic parallelization – Programming Models, synchronization costs, locks, computation and communication oveheads cslab@ntua 2018 -2019 3
Τρόποι Υλοποίησης • Χρήση υπαρχόντων μηχανημάτων – Μεγάλο κόστος » Oracle SPARC Enterprise T 5120 server (2*16*8=256 threads, 512 GB mem) ~ 64 K $ (2014) » Oracle SPARC Enterprise T 8 -1 server (32*8=256 threads, 1 TB mem, 8 Data Analytics Accelerators) ~ ? ? K $ (2017) » Intel Sandy Bridge E 5 -4620 (4 * 8 cores, 64 threads) ~ 15 K $ (2013) » Intel Xeon Gold 6138 (2 * 20 cores, 80 threads, 768 GB mem) ~ 19 K $ (2018) – Αδυναμία παρέμβασης στο υλικό τους » pipeline, caches, interconnection network – Περιορισμένη δυνατότητα παρακολούθησης και μετρήσεων » performance counters → λίγοι, μικρό documentation – Περιορισμός στο σήμερα » μελλοντικές αρχιτεκτονικές (π. χ. chip με 100 ή 1000 threads) ; • Λύση : Simulation (προσομοίωση) cslab@ntua 2018 -2019 4
Simulator taxonomy Architecture simulators Functional Trace-driven Execution-driven Performance / Timing Trace-driven User code cslab@ntua 2018 -2019 Execution-driven Full system 6
Functional vs. Timing Simulators • Functional Simulators – Visible architectural state – Προσομοίωση της λειτουργικότητας των εντολών (instructions semantics and functionality), μεταβολή του state (registers, memory) – Σωστό program output – Κύριος σκοπός: Software development and/or emulation • Timing Simulators – Microarchitecture details – Λεπτομερής υλοποίηση των διαφορετικών δομών (pipeline, branch predictors, interconnection networks, memory hierarchy, etc. ) – Χρονισμός γεγονότων, προκειμένου να υπολογισθεί ο χρόνος εκτέλεσης του προγράμματος • Functional simulation πολύ πιο γρήγορο cslab@ntua 2018 -2019 7
User code vs. Full system simulators • User code Simulators – Προσομοίωση μόνο του κώδικα της εφαρμογής – System calls και I/O εκτελούνται με functional simulation – Συνήθως το functional emulation πραγματοποιείται από το host OS » host OS = target OS • Full system Simulators – Προσομοίωση της εφαρμογής – Προσομοίωση του OS – Προσομοίωση των devices (disks, network, etc. ) cslab@ntua 2018 -2019 9
Speed vs. Accuracy cslab@ntua 2018 -2019 11
Παράδειγμα χρόνων προσομοίωσης (1) • spec 2 k with gcc and small inputs Time Ratio to Native Ratio to Functional Native 1, 054 s -- -- sim-fast 2 m 47 s 158 x 1 1 h 11 m 07 s 4, 029 x 25 x 7 m 41 s 437 x 1 w/Ruby 11 h 27 m 25 s 39, 131 x 89 x w/Ruby + Opal 43 h 13 m 41 s 147, 648 x 338 x sim-outorder simics cslab@ntua 2018 -2019 12
Προσομοίωση Αρχιτεκτονικής (1) • Απαιτήσεις – Γενικότητα (Generality) » Μπορεί το εργαλείο να αναλύσει τα workloads? » Parallel Systems, Multithreading, Multiple address spaces, OS code, Network Systems, etc. – Πρακτικότητα (Practicality) » Μπορεί το εργαλείο να χρησιμοποιηθεί αποδοτικά; » Host assumptions, compiler assumptions, OS modifications, workload language assumptions – Εφαρμοσιμότητα (Applicability) » Μπορεί το εργαλείο να απαντήσει στα ερωτήματα μας; » Restricted state that can be monitored, restrictions on parameter visibility, restricted length of observations. cslab@ntua 2018 -2019 14
Τεχνικές Προσομοίωσης – Sampling (2) N instructions (total benchmark execution) • Εξετάζουμε δείγματα (samples) • Μαθηματική προσέγγιση U Actual simulator measurement – confidence margin (eg. 95%) – confidence interval (eg. +/- 2. 5) • Δυο προσεγγίσεις σχετικά με την επιλογή δειγμάτων – Systematic sampling (π. χ. sample every N instructions) – Random sampling – Non-random sampling (phase detection, simpoints) • Μεθοδολογία Προσομοίωσης: 1. Fast-forwarding 2. Warm-up (caches, branch predictors, TLBs, OS) 3. Checkpointing 4. Μέτρηση cslab@ntua 2018 -2019 23
Ενορχήστρωση - Instrumentation • Εισαγωγή επιπλέον κώδικα στην εφαρμογή με στόχο την συλλογή πληροφοριών για την εκτέλεση (cache misses, total instructions executed etc. ) – Ανάλυση προγράμματος: Performance profiling, error detection, capture & replay – Μελέτη Αρχιτεκτονικής: Processor & cache simulation, trace collection – Binary translation: Emulate unsupported instructions, modify program behavior cslab@ntua 2018 -2019 24
Source Instrumentation – Παράδειγμα (1) Αρχικό πρόγραμμα Instrumented void foo() { bool found = false; for (int i=0; i<100; ++i) { if (i==50) break; if (i==20) found=true; } char inst[5]; void foo() { bool found = false; inst[0]=1; for (int i=0; i<100; ++i) { if (i==50) {inst[1]=1; break; } if (i==20) {inst[2]=1; found=true; } inst[3]=1; } printf(“foon”); inst[4]=1; } cslab@ntua 2018 -2019 26
Binary Instrumentation – Παράδειγμα (2) Total Instructions counter++; Sub $0 xff, counter++; cmp %esi, counter++; jle <L 1> counter++; mov $0 x 1, counter++; add $0 x 10, cslab@ntua 2018 -2019 %edx %edi %eax 27
Binary Instrumentation – Παράδειγμα (3) Instruction Trace Print(ip); sub $0 xff, Print(ip); cmp %esi, Print(ip); jle <L 1> Print(ip); mov $0 x 1, Print(ip); add $0 x 10, cslab@ntua 2018 -2019 %edx %edi %eax 28
Πλεονεκτήματα Ενορχήστρωσης • Binary Instrumentation – Language independent – Machine-level view – Instrument legacy/proprietary software • Dynamic Instrumentation – Δεν χρειάζεται recompile/relink – Εντοπισμός κώδικα κατά την εκτέλεση – Δυνατότητα χειρισμού κώδικα που παράγεται δυναμικά – Δυνατότητα ενορχήστρωσης running processes cslab@ntua 2018 -2019 29
Intel’s PIN • Εργαλείο για dynamic binary instrumentation. • Αναπτύσσεται και συντηρείται από την Intel. • Περισσότερες πληροφορίες: https: //software. intel. com/en-us/articles/pin-a-dynamic-binary-instrumentation-tool • Χαρακτηριστικά/Πλεονεκτήματα – – Εύκολη ενορχήστρωση Programmable (APIs) Multiplatform (x 86, x 86 -64, Windows, Linux, OSX, Android) Robust » Real-life apps: Database, web browseres, … » Multithreaded apps » Signals – Yψηλής Απόδοσης (compiler optimizations on instrumentation code) – Ευρεία αποδοχή από την ακαδημαϊκή κοινότητα και την βιομηχανία cslab@ntua 2018 -2019 30
PIN – Χρήση Download latest version: https: //software. intel. com/en-us/articles/pintool-downloads Unzip: $ tar xvfz pin-2. 14 -71313 -gcc. 4. 4. 7 -linux. tar. gz $ cd pin-2. 14 -71313 -gcc. 4. 4. 7 -linux $ ls –a. F. /. . / doc/ extras/ ia 32/ intel 64/ LICENSE pin. sh README redist. txt source/ Execute: $. /pin. sh –t pintool – application ή $. /pin. sh –t pintool –pid 1243 cslab@ntua 2018 -2019 31
PIN – Παράδειγμα $. /pin. sh –t inscount 0. so –- /bin/ls Total instructions count pintool $ cd source/tools/Manual. Examples/ $ make inscount 0. so $ ls obj-intel 64/inscount 0. so cslab@ntua 2018 -2019 32
Pintools • Προγράμματα γραμμένα σε C++ • Χρησιμοποιούνται κατά την εκτέλεση του PIN για την ανάλυση της εφαρμογής • Χρησιμοποιούν το PIN API: » INS_Add. Instrument. Function(…); » INS_Insert. Call(…); » . . . • PIN API reference: – https: //software. intel. com/sites/landingpage/pintool/docs/55942/Pin/html/group__API__REF. html cslab@ntua 2018 -2019 33
Pintool code #include <iostream> #include “pin. h” UINT 64 icount = 0; void docount() { icount++; } analysis routine instrumentation routine void Instruction(INS ins, void *v) { INS_Insert. Call(ins, IPOINT_BEFORE, (AFUNPTR)docount, IARG_END); } void Fini(INT 32 code, void *v){ std: : cerr << “Count “ << icount << “n”; } end routine int main(int argc, char *argv[]) { PIN_Init(argc, argv); INS_Add. Instrument. Function(Instruction, 0); PIN_Add. Fini. Function(Fini, 0); PIN_Start. Program(); return 0; } cslab@ntua 2018 -2019 34
Δυνατότητες Pin & Pintools • Αντικατάσταση των application functions. • Εντοπισμός/καταγραφή/έλεγχος κάθε application instruction. • Πέρασμα παραμέτρων στο instrumentation routine • register values, register values by reference (for modification) • memory addresses read/written • full register context • Εντοπισμός syscalls και αλλαγή arguments • Εντοπισμός/έλεγχος application threads • … cslab@ntua 2018 -2019 35
- Slides: 35