An Example of Physical Reality Behind CUDA. GeForce Speedup of Applications Why Massively Parallel Processor.

Similar documents
ECE/CS 757: Advanced Computer Architecture II GPGPUs

Nvidia G80 Architecture and CUDA Programming

Threading Hardware in G80

EE382N (20): Computer Architecture - Parallelism and Locality Fall 2011 Lecture 18 GPUs (III)

Mattan Erez. The University of Texas at Austin

CS8803SC Software and Hardware Cooperative Computing GPGPU. Prof. Hyesoon Kim School of Computer Science Georgia Institute of Technology

Introduction to CUDA (1 of n*)

Intro to GPU s for Parallel Computing

ECE/ME/EMA/CS 759 High Performance Computing for Engineering Applications

CIS 665: GPU Programming. Lecture 2: The CUDA Programming Model

Core/Many-Core Architectures and Programming. Prof. Huiyang Zhou

General Purpose GPU programming (GP-GPU) with Nvidia CUDA. Libby Shoop

Performance Insights on Executing Non-Graphics Applications on CUDA on the NVIDIA GeForce 8800 GTX

CS 668 Parallel Computing Spring 2011

Introduction to CUDA Algoritmi e Calcolo Parallelo. Daniele Loiacono

Introduction to CUDA Algoritmi e Calcolo Parallelo. Daniele Loiacono

ME964 High Performance Computing for Engineering Applications

Lecture 1: Introduction

CS427 Multicore Architecture and Parallel Computing

GPGPU. Lecture 2: CUDA

GPU Computation CSCI 4239/5239 Advanced Computer Graphics Spring 2014

CUDA (Compute Unified Device Architecture)

Programming in CUDA. Malik M Khan

Data Parallel Execution Model

This is a draft chapter from an upcoming CUDA textbook by David Kirk from NVIDIA and Prof. Wen-mei Hwu from UIUC.

GPU Computing with CUDA

Spring Prof. Hyesoon Kim

GPU Computing with CUDA

Portland State University ECE 588/688. Graphics Processors

GPU Programming. Lecture 2: CUDA C Basics. Miaoqing Huang University of Arkansas 1 / 34

Advanced Computing for Engineering Applications

Lecture 2: CUDA Programming

Lecture 15: Introduction to GPU programming. Lecture 15: Introduction to GPU programming p. 1

1/26/09. Administrative. L4: Hardware Execution Model and Overview. Recall Execution Model. Outline. First assignment out, due Friday at 5PM

Introduction to GPU programming. Introduction to GPU programming p. 1/17

What is GPU? CS 590: High Performance Computing. GPU Architectures and CUDA Concepts/Terms

EE382N (20): Computer Architecture - Parallelism and Locality Spring 2015 Lecture 09 GPUs (II) Mattan Erez. The University of Texas at Austin

CSE 591: GPU Programming. Programmer Interface. Klaus Mueller. Computer Science Department Stony Brook University

CUDA programming model. N. Cardoso & P. Bicudo. Física Computacional (FC5)

Computation to Core Mapping Lessons learned from a simple application

1/19/11. Administrative. L2: Hardware Execution Model and Overview. What is an Execution Model? Parallel programming model. Outline.

Lessons learned from a simple application

CE 431 Parallel Computer Architecture Spring Graphics Processor Units (GPU) Architecture

L18: Introduction to CUDA

CS 193G. Lecture 1: Introduction to Massively Parallel Computing

Matrix Multiplication in CUDA. A case study

Using The CUDA Programming Model

Tesla Architecture, CUDA and Optimization Strategies

Lecture 1: Introduction and Computational Thinking

CUDA Programming Model

EE382N (20): Computer Architecture - Parallelism and Locality Fall 2011 Lecture 22 CUDA

ME964 High Performance Computing for Engineering Applications

Master Informatics Eng.

Introduction to CUDA (1 of n*)

CS 677: Parallel Programming for Many-core Processors Lecture 1

Massively Parallel Architectures

ME964 High Performance Computing for Engineering Applications

This is a draft chapter from an upcoming CUDA textbook by David Kirk from NVIDIA and Prof. Wen-mei Hwu from UIUC.

Many-core Processors Lecture 1. Instructor: Philippos Mordohai Webpage:

Optimization Principles and Application Performance Evaluation of a Multithreaded GPU Using CUDA

L17: CUDA, cont. 11/3/10. Final Project Purpose: October 28, Next Wednesday, November 3. Example Projects

Parallel Programming Principle and Practice. Lecture 9 Introduction to GPGPUs and CUDA Programming Model

CS516 Programming Languages and Compilers II

Lecture 5. Performance Programming with CUDA

L14: CUDA, cont. Execution Model and Memory Hierarchy"

High Performance Computing

CUDA Memory Model. Monday, 21 February Some material David Kirk, NVIDIA and Wen-mei W. Hwu, (used with permission)

1/25/12. Administrative

Convolution, Constant Memory and Constant Caching

GPGPU/CUDA/C Workshop 2012

CSE 160 Lecture 24. Graphical Processing Units

GPU Programming. Lecture 1: Introduction. Miaoqing Huang University of Arkansas 1 / 27

Module 2: Introduction to CUDA C

Introduction to CUDA

Lecture 7. Overlap Using Shared Memory Performance programming the memory hierarchy

GPU programming. Dr. Bernhard Kainz

CS 179: GPU Computing LECTURE 4: GPU MEMORY SYSTEMS

Fundamental CUDA Optimization. NVIDIA Corporation

Fundamental CUDA Optimization. NVIDIA Corporation

Module 3: CUDA Execution Model -I. Objective

Overview: Graphics Processing Units

CUDA PROGRAMMING MODEL Chaithanya Gadiyam Swapnil S Jadhav

B. Tech. Project Second Stage Report on

From Brook to CUDA. GPU Technology Conference

Parallel Computing. Lecture 19: CUDA - I

NVIDIA GTX200: TeraFLOPS Visual Computing. August 26, 2008 John Tynefield

HPC COMPUTING WITH CUDA AND TESLA HARDWARE. Timothy Lanfear, NVIDIA

CUDA Performance Considerations (2 of 2)

GPU Computing with CUDA

COMP 605: Introduction to Parallel Computing Lecture : GPU Architecture

CS179 GPU Programming Introduction to CUDA. Lecture originally by Luke Durant and Tamas Szalay

ECE 498AL. Lecture 12: Application Lessons. When the tires hit the road

Spring 2009 Prof. Hyesoon Kim

Introduction to GPU (Graphics Processing Unit) Architecture & Programming

Computer Architecture

Lecture 3: Introduction to CUDA

CUDA Optimizations WS Intelligent Robotics Seminar. Universität Hamburg WS Intelligent Robotics Seminar Praveen Kulkarni

Spring 2011 Prof. Hyesoon Kim

Lecture 7. Using Shared Memory Performance programming and the memory hierarchy

GPU Programming. Performance Considerations. Miaoqing Huang University of Arkansas Fall / 60

Transcription:

Fall 007 Illinois ECE 498AL1 Programming Massively Parallel Processors Why Massively Parallel Processor A quiet revolution and potential build-up Calculation: 367 GFLOPS vs. 3 GFLOPS Bandwidth: 86.4 GB/s vs. 8.4 GB/s Until last year, programmed through graphics API Wen-mei Hwu, Prof. of ECE David Kirk, Chief Scientist, NVIDIA and Professor of ECE http://courses.ece.uiuc.edu/ece498al1 Excepts by Mark D. Hill, March 008 GFLOPS GPU in every PC and workstation massive volume and potential impact G80 = GeForce 8800 GTX G71 = GeForce 7900 GTX G70 = GeForce 7800 GTX NV40 = GeForce 6800 Ultra NV35 = GeForce FX 5950 Ultra NV30 = GeForce FX 5800 An Example of Physical Reality Behind CUDA CPU (host) GPU w/ local DRAM (device) 16 highly threaded SM s, >18 FPU s, 367 GFLOPS, 768 MB DRAM, 86.4 GB/S Mem BW, 4GB/S BW to CPU Input Assembler Execution Manager GeForce 8800 Load/store Load/store Load/store Load/store Load/store Load/store Previous Projects Application Description Source % time H.64 EC 06 version, change in guess vector 34,811 194 35% EC 06 version, change to single precision LBM and print fewer reports 1,481 85 >99% RC5-7 Distributed.net RC5-7 challenge client code 1,979 18 >99% Finite element modeling, simulation of 3D FEM graded materials 1,874 146 99% Rye Polynomial Equation Solver, quantum RPES chem, -electron repulsion 1,104 81 99% PNS Petri Net simulation of a distributed system 3 160 >99% Single-precision implementation of saxpy, SAXPY used in Linpack s Gaussian elim. routine 95 31 >99% TRACF Two Point Angular Correlation Function 536 98 96% Finite-Difference Time Domain analysis of FDTD D electromagnetic wave propagation 1,365 93 16% Computing a matrix Q, a scanner s MRI-Q David Kirk/NVIDIA configuration and Wen-mei W. in Hwu, MRI 007 reconstruction 490 33 >99% GPU Speedup Relative to CPU Speedup of Applications 10 79 457 431 316 63 60 50 40 Application 30 0 10 0 H.64 LBM RC5-7 FEM RPES PNS SAXPY TPACF FDTD MRI-Q MRI- GeForce 8800 GTX vs..ghz Opteron 48 FHD 10 speedup in a kernel is typical, as long as the kernel can occupy enough parallel threads 5 to 400 speedup if the function s data requirements and control flow suit the GPU and the application is optimized Keep in mind that the speedup also reflects how suitable the CPU is for executing the kernel 1

ECE 498AL Single-Program Multiple-Data (MD) CUDA integrated CPU + GPU application C program Serial C code executes on CPU Parallel C code executes on GPU thread blocks Lectures 7: ing Hardware in G80 CPU Serial Code GPU Parallel A<<< nblk, ntid >>>(args);... Grid 0 CPU Serial Code GPU Parallel B<<< nblk, ntid >>>(args);... Grids and s: CUDA Review A kernel is executed as a grid of thread blocks All threads share data memory space A thread block is a batch of threads that can cooperate with each other by: Synchronizing their execution For hazard-free shared memory accesses Efficiently sharing data through a low latency shared memory Two threads from two different blocks cannot cooperate 1 (0, ) Device (1, ) Grid (, ) (3, 0) (3, 1) (3, ) Courtesy: NVIDIA (4, 0) (4, 1) (4, ) CUDA : Review Programmer declares () : size 1 to 51 concurrent threads shape 1D, D, or 3D dimensions in threads All threads in a execute the same thread program s have thread id numbers within s share data and synchronize while doing their share of the work program uses thread id to select work and address shared data CUDA Id #: 0 1 3 m program Courtesy: John Nickolls, NVIDIA GeForce-8 Series HW Overview Streaming Processor Array TPC TPC TPC TPC TPC TPC Processor Cluster Streaming Multiprocessor Instruction L1 Data L1 Instruction Fetch/Dispatch SM TEX SM CUDA Processor Terminology A Streaming Processor Array (variable across GeForce 8-series, 8 in GeForce8800) TPC Processor Cluster ( SM + TEX) SM Streaming Multiprocessor (8 ) Multi-threaded processor core Fundamental processing unit for CUDA thread block Streaming Processor Scalar ALU for a single CUDA thread

Streaming Multiprocessor (SM) Streaming Multiprocessor (SM) 8 Streaming Processors () Super Function Units () Multi-threaded instruction dispatch 1 to 51 threads active instruction fetch per 3 threads Cover latency of texture/memory loads 0+ GFLOPS 16 KB shared memory DRAM texture and memory access Streaming Multiprocessor Instruction L1 Data L1 Instruction Fetch/Dispatch Life Cycle in HW Grid is launched on the A s are serially distributed to all the SM s Potentially >1 per SM Each SM launches Warps of s levels of parallelism SM schedules and executes Warps that are ready to run As Warps and s complete, resources are freed A can distribute more s 1 Device Grid (3, 0) (3, 1) (4, 0) (4, 1) (0, ) (1, ) (, ) (3, ) (4, ) t0 t1 t tm s SM 0 SM 1 MT IU TF SM Executes s MT IU L1 L t0 t1 t tm s s are assigned to SMs in granularity Up to 8 s to each SM as resource allows SM in G80 can take up to 768 threads Could be 56 (threads/block) * 3 blocks Or 18 (threads/block) * 6 blocks, etc. s run concurrently SM assigns/maintains thread id #s SM manages/schedules thread execution Scheduling/Execution Each s is divided in 3- thread Warps This is an implementation decision, not part of the CUDA programming model Warps are scheduling units in SM If 3 blocks are assigned to an SM and each has 56 threads, how many Warps are there in an SM? Each is divided into 56/3 = 8 Warps There are 8 * 3 = 4 Warps At any point in time, only one of the 4 Warps will be selected for instruction fetch and execution. 1 Warps t0 t1 t t31 Warps t0 t1 t t31 Streaming Multiprocessor Instruction L1 Data L1 Instruction Fetch/Dispatch SM multithreaded Warp scheduler time warp 8 instruction 11 warp 1 instruction 4 warp 3 instruction 95. warp 8 instruction 1 warp 3 instruction 96 SM Warp Scheduling SM hardware implements zerooverhead Warp scheduling Warps whose next instruction has its operands ready for consumption are eligible for execution Eligible Warps are selected for execution on a prioritized scheduling policy All threads in a Warp execute the same instruction when selected 4 clock cycles needed to dispatch the same instruction for all threads in a Warp in G80 If one global memory access is needed for every 4 instructions A minimal of 13 Warps are needed to fully tolerate 00-cycle memory latency SM Instruction Buffer Warp Scheduling Fetch one warp instruction/cycle from instruction L1 cache into any instruction buffer slot Issue one ready-to-go warp instruction/cycle from any warp - instruction buffer slot operand scoreboarding used to prevent hazards Issue selection based on round-robin/age of warp SM broadcasts the same instruction to 3 s of a Warp I$ L1 Multithreaded Instruction Buffer R C$ F L1 Mem Operand Select MAD 3

Scoreboarding All register operands of all instructions in the Instruction Buffer are scoreboarded Status becomes ready after the needed values are deposited prevents hazards cleared instructions are eligible for issue Decoupled /Processor pipelines any thread can continue to issue instructions until scoreboarding prevents issue allows /Processor ops to proceed in shadow of /Processor ops ECE 498AL Lectures 8: Hardware in G80 CUDA Device Space: Review Each thread can: R/W per-thread registers R/W per-thread local memory R/W per-block shared memory R/W per-grid global memory Read only per-grid constant memory Read only per-grid texture memory The host can R/W global, constant, and texture memories (Device) Grid Constant, Constant, and Memories (Long Latency Accesses) memory Main means of communicating R/W Data between host and device Contents visible to all threads and Constant Memories Constants initialized by host Contents visible to all threads (Device) Grid Constant Courtesy: NDVIA Grid 0 Parallel Sharing : per-thread Private per thread Auto variables, register spill : per- by threads of the same block Inter-thread communication : per-application by all threads Inter-Grid communication SM Register File Register File (RF) 3 KB Provides 4 operands/clock TEX pipe can also read/write RF SMs share 1 TEX Load/Store pipe can also read/write RF I$ L1 Multithreaded Instruction Buffer R C$ F L1 Mem Operand Select...... Sequential Grids in Time MAD 4

Programmer View of Register File 4 blocks There are 819 registers in 3 blocks each SM in G80 This is an implementation decision, not part of CUDA are dynamically partitioned ii across all lls assigned to the SM Once assigned to a, the register is NOT accessible by threads in other s Each thread in the same only access registers assigned to itself Constants Immediate address constants Indexed address constants Constants stored in DRAM, and cached on chip L1 per SM A constant value can be broadcast to all threads in a Warp Extremely efficient way of accessing a value that is common for all threads in a! I$ L1 Multithreaded Instruction Buffer R C$ F L1 Mem Operand Select MAD Each SM has 16 KB of 16 banks of 3bit words CUDA uses as shared storage visible to all threads in a thread block read and write access Not used explicitly for pixel shader programs we dislike pixels talking to each other I$ L1 Multithreaded Instruction Buffer R C$ F L1 Mem Operand Select MAD Parallel Architecture In a parallel machine, many threads access memory Therefore, memory is divided into banks Essential to achieve high bandwidth Bank 0 Bank 1 Bank Each bank can service one address per cycle Bank 3 A memory can service as many simultaneous accesses as it has banks Multiple simultaneous accesses to a bank result in a bank conflict Conflicting accesses are serialized Bank 4 Bank 5 Bank 6 Bank 7 Bank 15 Bank Addressing Examples No Bank Conflicts Linear addressing stride == 1 0 1 3 4 5 6 7 Bank 0 Bank 1 Bank Bank 3 Bank 4 Bank 5 Bank 6 Bank 7 No Bank Conflicts Random 1:1 Permutation 0 1 3 4 5 6 7 Bank 0 Bank 1 Bank Bank 3 Bank 4 Bank 5 Bank 6 Bank 7 ECE 498AL Lecture : The CUDA Programming Model 15 Bank 15 15 Bank 15 5

What is GPGPU? General Purpose computation using GPU in applications other than 3D graphics GPU accelerates critical path of application Data parallel algorithms leverage GPU attributes Large data arrays, streaming throughput Fine-grain SIMD parallelism Low-latency floating point (FP) computation Applications see //GPGPU.org Game effects (FX) physics, image processing Physical modeling, computational engineering, matrix algebra, convolution, correlation, sorting Previous GPGPU Constraints Dealing with graphics API Working with the corner cases of the graphics API Addressing modes Limited texture size/dimension Shader capabilities Limited outputs Instruction sets Lack of Integer & bit ops Communication limited Between pixels Scatter a[i] = p Input Fragment Program Output FB Constants per thread per Shader per Context Temp Declspecs global, device, shared, local, constant Keywords threadidx, blockidx Intrinsics syncthreads Runtime API, symbol, execution management Extended C device float filter[n]; global void convolve (float *image) shared float region[m];... region[threadidx] = image[i]; syncthreads()... image[j] = result; // Allocate GPU memory void *myimage = cudamalloc(bytes) Extended C Integrated source (foo.cu) cudacc EDG C/C++ frontend Open64 Optimizer GPU Assembly CPU Code foo.s foo.cpp OCG gcc / cl Function launch // 100 blocks, 10 threads per block convolve<<<100, 10>>> (myimage); G80 SASS foo.sass CUDA Programming Model: A Highly Multithreaded Coprocessor The GPU is viewed as a compute device that: Is a coprocessor to the CPU or host Has its own DRAM (device memory) Runs many threads in parallel Data-parallel portions of an application are executed on the device as kernels which run in parallel on many threads Differences between GPU and CPU threads GPU threads are extremely lightweight Very little creation overhead GPU needs 1000s of threads for full efficiency Multi-core CPU needs only a few Batching: Grids and s A kernel is executed as a grid of thread blocks All threads share data memory space A thread block is a batch of threads that can cooperate with each other by: Synchronizing their execution For hazard-free shared memory accesses Efficiently sharing data through a low latency shared memory Two threads from two different blocks cannot cooperate 1 (0, ) Device (1, ) Grid (, ) (3, 0) (3, 1) (3, ) Courtesy: NDVIA (4, 0) (4, 1) (4, ) 6

and IDs s and blocks have IDs So each thread can decide what data to work on ID: 1D or D ID: 1D, D, or 3D Simplifies memory addressing when processing multidimensional data Image processing Solving PDEs on volumes Device (0, ) (1, ) (, ) (3, 0) (3, 1) (3, ) (4, 0) (4, 1) (4, ) Courtesy: NDVIA CUDA Device Space Overview Each thread can: R/W per-thread registers R/W per-thread local memory R/W per-block shared memory R/W per-grid global memory Read only per-grid constant memory Read only per-grid texture memory The host can R/W global, constant, and texture memories (Device) Grid Constant, Constant, and Memories (Long Latency Accesses) memory Main means of communicating R/W Data between host and device Contents visible to all threads and Constant Memories Constants initialized by host Contents visible to all threads (Device) Grid Constant Courtesy: NDVIA A Simple Running Example Matrix Multiplication A straightforward matrix multiplication example that illustrates the basic features of memory and thread management in CUDA programs Leave shared memory usage until later, register usage ID usage data transfer API between host and device Programming Model: Square Matrix Multiplication Example P = M * N of size x Without tiling: One thread handles one element of P M and N are loaded times from global memory M N P Step 1: Matrix Data Transfers // Allocate the device memory where we will copy M to Matrix Md; Md.width = ; Md.height = ; Md.pitch = ; int size = * * sizeof(float); cudamalloc((void**)&md.elements, size); // Copy M from the host to the device cudamemcpy(md.elements, M.elements, size, cudamemcpytodevice); // Read M from the device to the host into P cudamemcpy(p.elements, Md.elements, size, cudamemcpydeviceto);... // Free device memory cudafree(md.elements); 7

M a t r i x M = A l l o c a t e M a t r i x ( B L O C K _ S I Z M a t r i x N = A l l o c a t e M a t r i x ( B L O C K M a t r i x P = A l l o c a t e M a t r i x ( B L O C K M a t r i x D P h = A l l o c a t e M a t r i x D ( B L O C Step : Matrix Multiplication A Simple Code in C // Matrix multiplication on the (CPU) host in double precision // for simplicity, we will assume that all dimensions are equal void MatrixMulOn(const Matrix M, const Matrix N, Matrix P) for (int i = 0; i < M.height; ++i) for (int j = 0; j < N.width; ++j) double sum = 0; for (int k = 0; k < M.width; ++k) double a = M.elements[i * M.width + k]; double b = N.elements[k * N.width + j]; sum += a * b; P.elements[i * N.width + j] = sum; Multiply Using One One of threads compute matrix P Each thread computes one element of P Each thread Loads a row of matrix M Loads a column of matrix N Perform one multiply and addition for each pair of M and N elements Compute to off-chip memory access ratio close to 1:1 (not very high) Size of matrix limited by the number of threads allowed in a thread block 1 (, ) N 3 5 4 48 BLOCK_SIZE M P 4 6 Step 3: Matrix Multiplication -side Main Program Code int main(void) // Allocate and initialize the matrices Matrix M = AllocateMatrix(,, 1); Matrix N = AllocateMatrix(,, 1); Matrix P = AllocateMatrix(,, 0); // M * N on the device MatrixMulOnDevice(M, N, P); // Free matrices FreeMatrix(M); FreeMatrix(N); FreeMatrix(P); return 0; Step 3: Matrix Multiplication -side code // Matrix multiplication on the device void MatrixMulOnDevice(const Matrix M, const Matrix N, Matrix P) // Load M and N to the device Matrix Md = AllocateDeviceMatrix(M); CopyToDeviceMatrix(Md, M); Matrix Nd = AllocateDeviceMatrix(N); CopyToDeviceMatrix(Nd, N); // Allocate P on the device Matrix Pd = AllocateDeviceMatrix(P); CopyToDeviceMatrix(Pd, P); // Clear memory Step 3: Matrix Multiplication -side Code (cont.) // Setup the execution configuration dim3 dim(, ); dim3 dimgrid; // Launch the device computation threads! MatrixMul<<<dimGrid, dim>>>(md, Nd, Pd); // Read P from the device CopyFromDeviceMatrix(P, Pd); // Free device matrices FreeDeviceMatrix(Md); FreeDeviceMatrix(Nd); FreeDeviceMatrix(Pd); Step 4: Matrix Multiplication Device-side Function // Matrix multiplication kernel thread specification global void MatrixMul(Matrix M, Matrix N, Matrix P) // D ID int tx = threadidx.x; int ty = threadidx.y; // Pvalue is used to store the element of the matrix // that is computed by the thread float Pvalue = 0; 8

Step 4: Matrix Multiplication Device-Side Function (cont.) for (int k = 0; k < M.width; ++k) float Melement = M.elements[ty * M.pitch + k]; float Nelement = Nd.elements[k * N.pitch + tx]; Pvalue += Melement * Nelement; // Write the matrix to device M memory; P // each thread writes one element P.elements[ty * P.pitch + tx] = Pvalue; N tx ty Step 5: Some Loose Ends // Allocate a device matrix of same size as M. Matrix AllocateDeviceMatrix(const Matrix M) Matrix Mdevice = M; int size = M.width * M.height * sizeof(float); cudamalloc((void**)&mdevice.elements, size); return Mdevice; // Free a device matrix. void FreeDeviceMatrix(Matrix M) cudafree(m.elements); void FreeMatrix(Matrix M) free(m.elements); Step 5: Some Loose Ends (cont.) // Copy a host matrix to a device matrix. void CopyToDeviceMatrix(Matrix Mdevice, const Matrix Mhost) int size = Mhost.width * Mhost.height * sizeof(float); cudamemcpy(mdevice.elements, Mhost.elements, size, cudamemcpytodevice); // Copy a device matrix to a host matrix. void CopyFromDeviceMatrix(Matrix Mhost, const Matrix Mdevice) int size = Mdevice.width * Mdevice.height * sizeof(float); cudamemcpy(mhost.elements, Mdevice.elements, size, cudamemcpydeviceto); Granularity Considerations For Matrix Multiplication, should I use 8X8, 16X16 or 3X3 tiles? For 8X8, we have 64 threads per. Since each SM can take up to 768 threads, it can take up to 1 s. However, each SM can only take up to 8 s, only 51 threads will go into each SM! For 16X16, we have 56 threads per. Since each SM can take up to 768 threads, it can take up to 3 s and achieve full capacity unless other resource considerations overrule. For 3X3, we have 104 threads per. Not even one can fit into an SM! 9