Computer Architecture

Hasonló dokumentumok
Számítógép Architektúrák

Using the CW-Net in a user defined IP network

Construction of a cube given with its centre and a sideline

Correlation & Linear Regression in SPSS

Correlation & Linear Regression in SPSS

Miskolci Egyetem Gazdaságtudományi Kar Üzleti Információgazdálkodási és Módszertani Intézet Factor Analysis

Miskolci Egyetem Gazdaságtudományi Kar Üzleti Információgazdálkodási és Módszertani Intézet Nonparametric Tests

Phenotype. Genotype. It is like any other experiment! What is a bioinformatics experiment? Remember the Goal. Infectious Disease Paradigm

T Á J É K O Z T A T Ó. A 1108INT számú nyomtatvány a webcímen a Letöltések Nyomtatványkitöltő programok fülön érhető el.

Computer Architectures

Introduction to 8086 Assembly

Miskolci Egyetem Gazdaságtudományi Kar Üzleti Információgazdálkodási és Módszertani Intézet. Correlation & Linear. Petra Petrovics.

Abigail Norfleet James, Ph.D.

Cluster Analysis. Potyó László

Create & validate a signature

Széchenyi István Egyetem

Lexington Public Schools 146 Maple Street Lexington, Massachusetts 02420

Website review acci.hu

8. Fejezet Processzor (CPU) és memória: tervezés, implementáció, modern megoldások

Ensemble Kalman Filters Part 1: The basics

8. Fejezet Processzor (CPU) és memória: tervezés, implementáció, modern megoldások

FÖLDRAJZ ANGOL NYELVEN

Mapping Sequencing Reads to a Reference Genome

On The Number Of Slim Semimodular Lattices

ANGOL NYELV KÖZÉPSZINT SZÓBELI VIZSGA I. VIZSGÁZTATÓI PÉLDÁNY

ANGOL NYELV KÖZÉPSZINT SZÓBELI VIZSGA I. VIZSGÁZTATÓI PÉLDÁNY

Angol Középfokú Nyelvvizsgázók Bibliája: Nyelvtani összefoglalás, 30 kidolgozott szóbeli tétel, esszé és minta levelek + rendhagyó igék jelentéssel

Miskolci Egyetem Gazdaságtudományi Kar Üzleti Információgazdálkodási és Módszertani Intézet. Nonparametric Tests. Petra Petrovics.

Miskolci Egyetem Gazdaságtudományi Kar Üzleti Információgazdálkodási és Módszertani Intézet. Hypothesis Testing. Petra Petrovics.

SQL/PSM kurzorok rész

Előszó.2. Starter exercises. 3. Exercises for kids.. 9. Our comic...17

Csima Judit április 9.

Számítógépes Hálózatok GY 8.hét

Számítógép Architektúrák

Performance Modeling of Intelligent Car Parking Systems

Statistical Inference

FÖLDRAJZ ANGOL NYELVEN GEOGRAPHY

A rosszindulatú daganatos halálozás változása 1975 és 2001 között Magyarországon

USER MANUAL Guest user

7 th Iron Smelting Symposium 2010, Holland

(NGB_TA024_1) MÉRÉSI JEGYZŐKÖNYV

3. MINTAFELADATSOR KÖZÉPSZINT. Az írásbeli vizsga időtartama: 30 perc. III. Hallott szöveg értése

Cashback 2015 Deposit Promotion teljes szabályzat

Cloud computing. Cloud computing. Dr. Bakonyi Péter.

Searching in an Unsorted Database

már mindenben úgy kell eljárnunk, mint bármilyen viaszveszejtéses öntés esetén. A kapott öntvény kidolgozásánál még mindig van lehetőségünk

Lopocsi Istvánné MINTA DOLGOZATOK FELTÉTELES MONDATOK. (1 st, 2 nd, 3 rd CONDITIONAL) + ANSWER KEY PRESENT PERFECT + ANSWER KEY

Analitikai megoldások IBM Power és FlashSystem alapokon. Mosolygó Ferenc - Avnet

FÖLDRAJZ ANGOL NYELVEN

Csatlakozás a BME eduroam hálózatához Setting up the BUTE eduroam network

FOSS4G-CEE Prágra, 2012 május. Márta Gergely Sándor Csaba

A jövedelem alakulásának vizsgálata az észak-alföldi régióban az évi adatok alapján

PAST ÉS PAST PERFECT SUBJUNCTIVE (múlt idejű kötőmód)

1. Gyakorlat: Telepítés: Windows Server 2008 R2 Enterprise, Core, Windows 7

A modern e-learning lehetőségei a tűzoltók oktatásának fejlesztésében. Dicse Jenő üzletfejlesztési igazgató

Cloud computing Dr. Bakonyi Péter.

MEMÓRIA TECHNOLÓGIÁK. Számítógép-architektúrák 4. gyakorlat. Dr. Lencse Gábor. tudományos főmunkatárs BME Híradástechnikai Tanszék

Szundikáló macska Sleeping kitty

INDEXSTRUKTÚRÁK III.

A évi fizikai Nobel-díj

IBM Brings Quantum Computing to the Cloud

Választási modellek 3

OLYMPICS! SUMMER CAMP

First experiences with Gd fuel assemblies in. Tamás Parkó, Botond Beliczai AER Symposium


discosnp demo - Peterlongo Pierre 1 DISCOSNP++: Live demo

Számítógép architektúrák. Tartalom. A memória. A memória

General information for the participants of the GTG Budapest, 2017 meeting

A golyók felállítása a Pool-biliárd 8-as játékának felel meg. A golyók átmérıje 57.2 mm. 15 számozott és egy fehér golyó. Az elsı 7 egyszínő, 9-15-ig

Dense Matrix Algorithms (Chapter 8) Alexandre David B2-206

PIACI HIRDETMÉNY / MARKET NOTICE

Társasjáték az Instant Tanulókártya csomagokhoz

- eqµah ³. -ry³eblbmebjkargar³

Daloló Fülelő Halász Judit Szabó T. Anna: Tatoktatok Javasolt nyelvi szint: A2 B1 / Resommended European Language Level: A2 B1

Statistical Dependence

Hozzunk ki többet abból amink van. Fehér Lajos

Ültetési és öntözési javaslatok. Planting and watering instructions

Utasítások. Üzembe helyezés

Expansion of Red Deer and afforestation in Hungary

Manuscript Title: Identification of a thermostable fungal lytic polysaccharide monooxygenase and

Adatbázisok 1. Rekurzió a Datalogban és SQL-99

Sebastián Sáez Senior Trade Economist INTERNATIONAL TRADE DEPARTMENT WORLD BANK

The problem. Each unitary transform having eigenvector has eigenvalues in the form of. Phase ratio:

Genome 373: Hidden Markov Models I. Doug Fowler

PIACI HIRDETMÉNY / MARKET NOTICE

Office and computing machinery, equipment and supplies except furniture and software packages

Tudományos Ismeretterjesztő Társulat

Hasznos és kártevő rovarok monitorozása innovatív szenzorokkal (LIFE13 ENV/HU/001092)

Gottsegen National Institute of Cardiology. Prof. A. JÁNOSI

STUDENT LOGBOOK. 1 week general practice course for the 6 th year medical students SEMMELWEIS EGYETEM. Name of the student:

EN United in diversity EN A8-0206/419. Amendment

A vitorlázás versenyszabályai a évekre angol-magyar nyelvű kiadásának változási és hibajegyzéke

16F628A megszakítás kezelése

FÖLDRAJZ ANGOL NYELVEN GEOGRAPHY

Klaszterezés, 2. rész

EXKLUZÍV AJÁNDÉKANYAGOD A Phrasal Verb hadsereg! 2. rész

ANGOL NYELVI SZINTFELMÉRŐ 2013 A CSOPORT. on of for from in by with up to at

This document has been provided by the International Center for Not-for-Profit Law (ICNL).

GEOGRAPHICAL ECONOMICS B

Website review mozogjotthon.com

Átírás:

Computer Architecture Locality-aware programming 2016. április 27. Budapest Gábor Horváth associate professor BUTE Department of Telecommunications ghorvath@hit.bme.hu

Számítógép Architektúrák Horváth Gábor, BME Hálózati Rendszerek és Szolgáltatások Tsz. 2 The importance of locality of references How to develop slow programs? Let us refer the memory content in a random order Many cache misses Many TLB misses Many page faults DRAM row activation many times How to develop fast programs? Let us take the memory hierarchy into consideration Memory references should exhibit Spatial locality Temporal locality

Quantifying the effect of the locality of references Is it worth using memory hierarchy aware programing tricks? Számítógép Architektúrák Horváth Gábor, BME Hálózati Rendszerek és Szolgáltatások Tsz. 3

Számítógép Architektúrák Horváth Gábor, BME Hálózati Rendszerek és Szolgáltatások Tsz. 4 What to measure? The effect of temporal locality How important is it to decrease the memory used by the programs, and use the same data many times The effect of spatial locality How important is it to traverse the data in a memory continuous way?

Measuring the effect of temporal locality Measurement method: Let us take a large (N) array Array entries: pointers to further entries of the array The pointer chain includes all elements in a random-like order We measure the execution time of traversing the pointer chain: for (int i=0; i<iterations/100; i++) { p = *p; p = *p;... p = *p; } Számítógép Architektúrák Horváth Gábor, BME Hálózati Rendszerek és Szolgáltatások Tsz. 5

Measuring the effect of temporal locality Conclusion: The size of caches can be identified Message: Temporal locality does matter a lot Difference of memory access times can be up tu 200x!!! Számítógép Architektúrák Horváth Gábor, BME Hálózati Rendszerek és Szolgáltatások Tsz. 6

Measuring the effect of spatial locality Measurement method: Like before, but the chain is sequential now (rather than random) Expected results: improved memory access times Cache miss ratio decreases: If a cache block is referred to, we proceed and use all further elements of the same cache block as well If there is a cache prefetch algorithm in the CPU, it can take the advantage of sequential read operations The TLB miss ratio decreases If a page is referred to, we proceed and use all further elements of the same page, thus the same page table entry can be used for address translations Számítógép Architektúrák Horváth Gábor, BME Hálózati Rendszerek és Szolgáltatások Tsz. 7

Számítógép Architektúrák Horváth Gábor, BME Hálózati Rendszerek és Szolgáltatások Tsz. 8 Measuring the effect of spatial locality Results: Pentium 4 Core i7 ARM (raspberry pi) ARM (rk3188)

Számítógép Architektúrák Horváth Gábor, BME Hálózati Rendszerek és Szolgáltatások Tsz. 9 Measuring the effect of spatial locality Conclusion: It is worth traversing data structures in a memory continuous way In case of large arrays the difference is 40x-80x

Locality aware loops What can a C programmer do? Számítógép Architektúrák Horváth Gábor, BME Hálózati Rendszerek és Szolgáltatások Tsz. 10

Számítógép Architektúrák Horváth Gábor, BME Hálózati Rendszerek és Szolgáltatások Tsz. 11 Loop merging Original C code: b[i] = c * a[i] + x; sum = 0; sum += b[i]; d[i] = a[i] + b[i]; After loop merging: sum = 0; { b[i] = c * a[i] + x; sum += b[i]; d[i] = a[i] + b[i]; } Cache miss analysis: (assume 8 double/block, N is large) Original code: First loop: 2N references, 2N/8 cache misses Second loop: N references, N/8 misses Third loop: 3N references, 3N/8 misses Total: 6N references, 6N/8 cache misses Cache miss ratio: 1/8 = 12,5%

Számítógép Architektúrák Horváth Gábor, BME Hálózati Rendszerek és Szolgáltatások Tsz. 12 Loop merging Original C code: b[i] = c * a[i] + x; sum = 0; sum += b[i]; d[i] = a[i] + b[i]; After loop merging: sum = 0; { b[i] = c * a[i] + x; sum += b[i]; d[i] = a[i] + b[i]; } After loop merging: First line of the loop: 2N references, 2N/8 cache miss Second line: N references, 0 cache miss! Third line: 3N references, N/8 miss (due to d[i]) Total: 6N references, 3N/8 cache miss Cache miss ratio: 1/16 = 6,25%

Számítógép Architektúrák Horváth Gábor, BME Hálózati Rendszerek és Szolgáltatások Tsz. 13 Loop merging Conclusion: Traversing arrays several times should be avoided A common loop is better than multiple small loops Measurement results: N=2 22 i7-2600 p4 Rasp. Pi RK3188 Original algorithm 16,533 ms 109,974 ms 698,450 ms 115,354 ms After loop merging 8,469 ms 84,917 ms 203,755 ms 97,126 ms

Számítógép Architektúrák Horváth Gábor, BME Hálózati Rendszerek és Szolgáltatások Tsz. 14 Optimizing the order of loops Row-continuous traversal: for (j=0; j<n; j++) sum += a[i][j]; Column-continuous traversal: for (j=0; j<n; j++) sum += a[i][j]; C language: arrays are stored in a row-continuous way Assumption: 8 double/cache block, N large Cache miss analysis: With row-continuous traversal: Array is traversed in a memory-continuous way We saw how fast it is 1 cache miss for 8 memory references Cache miss ratio: 1/8 = 12,5%

Számítógép Architektúrák Horváth Gábor, BME Hálózati Rendszerek és Szolgáltatások Tsz. 15 Optimizing the order of loops Row-continuous traversal: for (j=0; j<n; j++) sum += a[i][j]; Column-continuous traversal: for (j=0; j<n; j++) sum += a[i][j]; Column-continuous traversal: N-1 elements are skipped after each memory reference If the CPU supports cache prefetch, it can adapt to this behavior and fetch the data before the first references If there is no prefetch and N > cache size: Blocks are replaced before incrementing j Each memory references imply a cache miss! Cache miss ratio: 100%

Számítógép Architektúrák Horváth Gábor, BME Hálózati Rendszerek és Szolgáltatások Tsz. 16 Optimizing the order of loops Conclusion: Data structures should be traversed in a memory-continuous way Measurement results: N=2048 i7-2600 p4 Rasp. Pi RK3188 Row-continuous 6,312 ms 8,973 ms 605,757 ms 14,879 ms Column-continuous 6,926 ms 160,78 ms 4363,13 ms 60,96 ms (Core i7 has a cache prefetch algorithm)

Loop tiling Original C code: for (j=0; j<n; j++) b[j][i] = a[i][j]; After loop tiling: for (bi=0; bi<=n BLK; bi+=blk) for (bj=0; bj<=n BLK; bj+=blk) for (i=bi; i<bi+blk; i++) for (j=bj; j<bj+blk; j++) b[j][i] = a[i][j]; Matrix transpose (image rotation, etc.) Assumptions: 8 double/cache block, N is large Cache miss analysis: Original C code: a[i][j]: row-continuous traversal, N 2 references, N 2 /8 cache misses b[j][i]: column-continuous traversal, N 2 references, N 2 cache misses Total: 2N 2 references, N 2 /8 +N 2 cache miss Cache miss ratio: 9/16 = 56,25% Számítógép Architektúrák Horváth Gábor, BME Hálózati Rendszerek és Szolgáltatások Tsz. 17

Loop tiling Original C code: for (j=0; j<n; j++) b[j][i] = a[i][j]; After loop tiling: for (bi=0; bi<=n BLK; bi+=blk) for (bj=0; bj<=n BLK; bj+=blk) for (i=bi; i<bi+blk; i++) for (j=bj; j<bj+blk; j++) b[j][i] = a[i][j]; After loop tiling: We proceed block-by-block If BLK is properly set, a BLK x BLK sized block fits into the cache a[i][j] and b[j][i] will both be in the cache! a[i][j]: row-continuous traversal, N 2 references, N 2 /8 cache miss b[j][i]: column-continuous traversal, N 2 references, N 2 /8 cache miss Total: 2N 2 references, N 2 /8 +N 2 /8 cache miss Cache miss ratio: 1/8 = 12,5% Számítógép Architektúrák Horváth Gábor, BME Hálózati Rendszerek és Szolgáltatások Tsz. 18

Számítógép Architektúrák Horváth Gábor, BME Hálózati Rendszerek és Szolgáltatások Tsz. 19 Loop tiling How to determine the optimal block size? Too small like without loop tiling Too large like without loop tiling Architecture dependent! Measurement results: N=2048 BLK from 1 to 2048

Számítógép Architektúrák Horváth Gábor, BME Hálózati Rendszerek és Szolgáltatások Tsz. 20 Results: Loop tiling Pentium 4 Core i7 ARM (raspberry pi) ARM (rk3188)