Docsity

Memory Management for High Performance Computing: GPU Architecture and Memory Hierarchy - , Study notes of Computer Science

Partial preview of the text

Download Memory Management for High Performance Computing: GPU Architecture and Memory Hierarchy - and more Study notes Computer Science in PDF only on Docsity!

Memory management for

performance

Ramani Duraiswami

Several slides from Wen-Mei Hwu and David Kirk’s course

Hierarchical Organization

-^

GPU -> Grids^ – Multiprocessors

-> Blocks, Warps

-^

Thread Processor

-> Threads

-^

Global Memory^ – Shared Memory

-^

Registers

  • Cached global memory (Texture and Constant) -^

Parallel programming^ – dividing job in to pieces correctly and optimize the utilizing of

available processing and memory resources

  • Do it correctly so that -^

Use results only when computations are complete

-^

No simultaneous writes, etc.

-^

Avoid serialization^ – If compiler cannot determine if things are correct it will serialize– Can also happen because of hardware limitations

-^

Two techniques^ – Coalescing -> global memory reads and writes– Bank Conflicts -> multiprocessors accesses to shared memory

Parallel Memory Sharing

-^

Local Memory:

per-thread

–^

Private per thread

-^

Auto variables, register spill

-^

Shared Memory:

per-Block

–^

Shared by threads of the sameblock

-^

Inter-thread communication

-^

Global Memory:

per-application

–^

Shared by all threads

-^

Inter-Grid communication

-^

Results; Host communication

Thread

Local Memory

Grid 0

...

GlobalMemory

...

Grid 1

SequentialGridsin Time

Block

SharedMemory

SM Memory Architecture

-^

Threads in a block share data &results^ –

In Memory and Shared Memory

-^

Synchronize at barrier instruction

-^

Per-Block Shared MemoryAllocation^ –

Keeps data close to processor

-^

Minimize trips to global Memory

-^

Shared Memory is

dynamically

allocated

to blocks, one of the

limiting resources

t0 t1 t2 … tm^ Blocks

Texture L MT IU SP SharedMemory

MT IU SP SharedMemory

TF

L

Memory

t0 t1 t2 … tm

Blocks

SM 1

SM 0

Courtesy:John Nicols, NVIDIA

Matrix Multiplication Example

-^

If each Block has 16×16 threads and each thread uses10 registers, how many threads can run on each SM?^ – Each block requires 10*256 = 2560 registers– 8192 =

^3

* 2560 + change

  • So, three blocks can run on an SM as far as registers are

concerned

-^

How about if each thread increases the use of registersby 1?^ – Each Block now requires 11*256 = 2816 registers– 8192 < 2816 *3– Only two Blocks can now fit on the SM,–

1/3 reduction of parallelism

More on Dynamic Partitioning

-^

Dynamic partitioning gives more flexibility tocompilers/programmers^ – One can run a smaller number of threads that require many

registers each or a large number of threads that require fewregisters each

  • This allows for finer grain threading than traditional CPU threading

models.

  • The compiler can tradeoff between improving performance

via instruction-level parallelism or via thread levelparallelism

Global Memory

-^

global memory space is not cached

-^

important to follow the right access pattern to getmaximum memory bandwidth

-^

access is costly – 400-600 clock cycles

-^

For efficiency the access must result in fewerinstructions, and fewer address computations

-^

Device can read 32-bit, 64-bit, or 128-bit words fromglobal memory into registers in a single instruction.

-^

Structures and arrays must align on these byteboundaries to minimize number of instructions.

Example

-^

To ensure that it generates the minimum number ofinstructions, such structures should be defined with align(16)

, such as

struct align(16) {float a;float b;float c;float d;float e;};

-^

compiles into two 128-bit load instructions instead of five 32-bit load instructions.

Examples of CoalescedGlobal Memory Access

-^

Left: coalesced

float

memory access,resulting in a singlememory transaction.

-^

Right: coalesced

float

memory access(divergent warp),resulting in a singlememory transaction.

Noncoalesced access •^

Left: non-sequential float

memory access,

resulting in 16memory transactions.

-^

Right: access with amisaligned startingaddress, resulting in16 memorytransactions.

-^

In newer machinesthis is fixed

M

2,

M

1, M

1,

M

0, M

0,

M

3,

M

2,

M

3,

Memory Layout of a Matrix in C^ M

2,

M

1,

M

0,

M

3,

M

1,

M

0,

M

2,

M

3,

M

1,

M

0,

M

2,

M

3,

M

1,

M

0,

M

2,

M

3,

M

1,

M

0,

M

2,

M

3,

M

1,

M

0,

M

2,

M

3,

M

Memory Coalescing

-^

When accessing global memory, peak performanceutilization occurs when all threads in a half warpaccess continuous memory locations.

Md

Nd

WIDTH

WIDTH

Thread 1Thread 2

Not coalesced

coalesced

Shared Memory

-^

Each SM has 16 kB of Shared Memory^ –

banks

of 32 bit words

-^

Shared Memory is visible to allthreads in a thread block^ –

read and write access

I$L MultithreadedInstruction Buffer RF

C$L

SharedMem

Operand Select MAD

SFU

Parallel Memory Architecture

-^

In a parallel machine, many threads access memory^ –

Therefore, memory is divided into

banks

Essential to achieve high bandwidthsince the bandwidth per “wire” is limited

-^

Each bank can service one address per cycle^ –

A memory can service as many simultaneousaccesses as it has banks

-^

Multiple simultaneous accesses to a bankresult in a

bank conflict

Conflicting accesses are serialized

Bank 0 Bank 1 Bank 2 Bank 3 Bank 4 Bank 5 Bank 6 Bank 7 Bank 15