Docsity

Optimizing Software for Multicore Architectures: A Study on CUDA GPUs, Study notes of Computer Science

Partial preview of the text

Download Optimizing Software for Multicore Architectures: A Study on CUDA GPUs and more Study notes Computer Science in PDF only on Docsity!

Yu, Xuan Dept of Computer & Information Sciences University of Delaware

Program Optimization Study on a

128-Core GPU

Shane Ryoo, Christopher I. Rodrigues, Sam S. Stone, Sara S. Baghsorkhi, Sain-Zee Ueng, and Wen-mei W. Hwu

General Idea

 Good news

 Improving programmability and generality on

GPU

 Possibility to perform a wide variety of

parallelization optimizations

 Problem

 How do you choose and control optimizations on

GPU properly

 Possible combination of optimization is very large and makes the optimization space tedious to explore  Limited local resources and global memory bandwidth makes performance sensitive to even small changes in code, unpredictable

Organization

 Architecture Overview (CUDA)

 Introduction of execution hardware and threading model  Compute Unified Device Architecture (CUDA)

 optimization space search

 Discussion of the space search process and the classifications and characteristics of the program optimizations

 Experiments

 Discuss result of the search for several applications  Matrix Multiplication  Magnetic resonance Imaging  Sums of Absolute Difference

 Conclusion

Architecture

• General Programming and compilation process

 GPU is treaded as a coprocessor that

executes data-parallel kernel functions

 The user supplies a both host (CPU) and

kernel (GPU) code

 Codes are separated and compiled by

NVIDIA’s compiler.

 Host code transfers data to GPU’s and

initialed the kernel code via API calls

Architecture

Architecture

Three Level Hierarchy:

  • Grid
  • Block
  • Thread

Each kernel creates a single grid

A grid consists of many thread

blocks.(512, on single SM)

Threads in a block are organized into warps of 32 threads. Each warp executes in SIMD fashion, issuing in four cycles on the eight SPs of an SM. When one wrap stall, SM switch to another warp

Architectural Interactions

Consider an application:

  • Uses 256 threads per block
  • 10 registers per thread
  • 4KB of shared memory per thread block. Can schedule 3 thread blocks and 768 threads on each SM. An optimization: Increases each thread's register usage from 10 to 11 (an increase of only 10%) will decrease the number of blocks per SM from 3 to 2. This decreases the number of threads on an SM by 33%. Why? 768 * 11 = 8448 > 9192

Architectural Interactions

By contrast, an optimization that increases

each thread block's shared memory usage by

1KB (an increase of 25%) does not decrease

the number of blocks per SM. Clearly, the

optimization space is inherently non-linear.

Optimization space search

Basic strategy for good performance: Reduce dynamic instruction count while maintaining high SP occupancy. Four categories of machine-level behavior to optimizae Thread-level work redistribution Instruction count reduction Intra-thread parallelism Resource balancing

Example of matrix multiplication The kernel is tiled so that each thread block computes a square 16- by-16 tile of the output matrix

Optimization space search

Optimization space search

Four categories of machine-level behavior to optimize Thread-level work redistribution Instruction count reduction Intra-thread parallelism Resource balancing Each thread compute two matrix elements instead of one, presents opportunities for eliminating redundant instructions previously distributed across threads

Four categories of machine-level behavior to optimize Thread-level work redistribution Instruction count reduction Intra-thread parallelism Resource balancing Traditional compiler optimizations such as common sub expression elimination, loop- invariant code removal, and loop unrolling.

Optimization space search

Four categories of machine-level behavior to optimize Thread-level work redistribution Instruction count reduction Intra-thread parallelism Resource balancing Trade certain resource usages, some of which may be counterintuitive, to produce a better performing application. An example of this is using shared memory to buffer data for reuse, regardless of whether it is shared with other threads. Another example is proactive register spilling by the programmer. By reducing register usage, often a critical resource, more thread blocks can be assigned to each SM.

Optimization space search

Experiments

 Architecture Overview (CUDA)

 Introduction of execution hardware and threading model  Compute Unified Device Architecture (CUDA)

 optimization space search

 Discussion of the space search process and the classifications and characteristics of the program optimizations

 Experiments

 Discuss result of the search for several applications  Matrix Multiplication  Magnetic resonance Imaging  Sums of Absolute Difference

 Conclusion