Docsity

SOLUTIONS MANUAL FOR MULTICORE AND GPU PROGRAMMING EVALUATION MASTER STUDY GUIDE WITH SOLV, Exams of Quantitative Techniques

Toggle sidebar
bg1
SOLUTIONS MANUAL FOR MULTICORE AND GPU PROGRAMMING
EVALUATION MASTER STUDY GUIDE WITH SOLVED QUESTIONS
Question 1.
What is inside a "CUDA core" (high level)?
Answer: CUDA cores are a cluster of units including INT, FP32/FP64, Tensor, and
special function units.
Question 2.
CUDA core vs CPU core (functionality mapping)
Answer: A CUDA core is like an execution unit on a CPU core; one SM (collection
of CUDA cores) is like one CPU core.
Question 3.
How CPU vs GPU parallelism is measured
Answer: CPU parallelism is often measured by number of CPU cores; GPU
parallelism is often measured by (# CUDA cores × # SMs).
Question 4.
CUDA parallelization model hierarchy
Answer: CUDA uses a two- level hierarchy: a Grid (collection of thread blocks)
and Thread Blocks (groups of threads).
Question 5.
Grid (definition)
Answer: A grid is a collection of threads grouped into thread blocks; deploying a
function on GPU deploys the job on a grid.
Question 6.
Thread block (definition)
Answer: A thread block is a group of threads inside one grid; all blocks in the
same grid must have the same thread layout/size.
Question 7.
Thread (definition)
Answer: A thread is the smallest execution unit ("the hard worker").
Question 8.
Two key quantities when requesting a grid
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17

Partial preview of the text

Download SOLUTIONS MANUAL FOR MULTICORE AND GPU PROGRAMMING EVALUATION MASTER STUDY GUIDE WITH SOLV and more Exams Quantitative Techniques in PDF only on Docsity!

SOLUTIONS MANUAL FOR MULTICORE AND GPU PROGRAMMING

EVALUATION MASTER STUDY GUIDE WITH SOLVED QUESTIONS

Question 1.

What is inside a "CUDA core" (high level)?

Answer: CUDA cores are a cluster of units including INT, FP32/FP64, Tensor, and special function units.

Question 2.

CUDA core vs CPU core (functionality mapping)

Answer: A CUDA core is like an execution unit on a CPU core; one SM (collection of CUDA cores) is like one CPU core.

Question 3.

How CPU vs GPU parallelism is measured

Answer: CPU parallelism is often measured by number of CPU cores; GPU parallelism is often measured by (# CUDA cores × # SMs).

Question 4.

CUDA parallelization model hierarchy

Answer: CUDA uses a two- level hierarchy: a Grid (collection of thread blocks) and Thread Blocks (groups of threads).

Question 5.

Grid (definition)

Answer: A grid is a collection of threads grouped into thread blocks; deploying a function on GPU deploys the job on a grid.

Question 6.

Thread block (definition)

Answer: A thread block is a group of threads inside one grid; all blocks in the same grid must have the same thread layout/size.

Question 7.

Thread (definition)

Answer: A thread is the smallest execution unit ("the hard worker").

Question 8.

Two key quantities when requesting a grid

Answer: (1) Number of threads per thread block, and (2) Number of thread blocks.

Question 9.

Grid/block organization dimensions

Answer: Both grids and thread blocks can be organized as 1D, 2D, or 3D (and they can differ in dimensionality).

Question 10.

TB→SM mapping rule (core rule)

Answer: A thread block (TB) is mapped to a single SM and cannot be split across multiple SMs.

Question 11.

TB lifecycle on an SM

Answer: Thread blocks stay on their assigned SMs for their entire lifecycle (from assignment to completion).

Question 12.

When do thread blocks share the same SM?

Answer: When there are too many TBs and an SM has enough resources to handle more than one TB's resource needs.

Question 13.

CUDA built-in indexing variables

Answer: threadIdx.(x,y,z), blockDim.(x,y,z), blockIdx.(x,y,z), gridDim.(x,y,z) are available inside kernels (in Python: prefix with cuda.).

Question 14.

Global thread index formula (1D grid of 1D blocks)

Answer: i = blockIdx.x * blockDim.x + threadIdx.x

Question 15.

CUDA cores contain what units?

Answer: CUDA cores are a cluster of units including INT, FP32/FP64, Tensor, and special function units.

Question 16.

CUDA core vs CPU core (functionality)

Question 25.

What if there are more TBs than can run at once?

Answer: At most NK TBs run; the remaining TBs are put on hold (waitlist) until resources free up.

Question 26.

When do "on hold" TBs run?

Answer: When active TBs finish and release SM resources, TBs on the waitlist get assigned to available SMs.

Question 27.

Why prefer multi-block over single-block (same total threads)?

Answer: Because each TB maps to an SM, so multi-block uses multiple SMs in parallel.

Question 28.

Kernel launch idea

Answer: Launching a kernel is like calling a function, except you must specify grid/block dimensions.

Question 29.

Kernel launch syntax (C)

Answer: kernel_name<<<# of blocks, # of threads per block>>>(...)

Question 30.

Kernel launch syntax (Python)

Answer: kernel_name# of blocks, # of threads per block

Question 31.

of blocks means what?

Answer: # of blocks is the grid dimension.

Question 32.

of threads per block means what?

Answer: # of threads per block is the block dimension.

Question 33.

Two ways to specify dimensional parameters

Answer: Use scalars for 1D; use tuple-like objects for multi-dimensional structures.

Question 34.

Scalar example: <<<1, 2>>>

Answer: 1D grid of a 1D block of 2 threads.

Question 35.

Scalar example: <<<4, 10>>>

Answer: 1D grid of 4 blocks of 10 threads.

Question 36.

C multi-dim coordinate type for kernel params

Answer: Use dimX types (often dim3) like dim3(x_value, y_value, z_value).

Question 37.

dim3 argument type note

Answer: dim3 arguments are unsigned integers; be mindful when calculating values.

Question 38.

Python multi-dim kernel params

Answer: In Python, a simple tuple (x, y, z) works for multi-dimensional settings.

Question 39.

Built-in CUDA indexing variables

Answer: threadIdx.(x,y,z), blockDim.(x,y,z), blockIdx.(x,y,z), gridDim.(x,y,z)

Question 40.

Built-ins in Python access

Answer: In Python, use cuda.threadIdx.x etc. (prefix with cuda.)

Question 41.

Matrix linear index formula (x,y) in MxN

Answer: y * N + x

Question 51.

3D grid shape

Answer: (N, M, K)

Question 52.

CPU and GPU memory sharing

Answer: GPU and CPU cannot share memory.

Question 53.

What must be done before sending CPU data to GPU?

Answer: Allocate GPU memory of the same size, then copy data from CPU memory to GPU memory.

Question 54.

After GPU work, how do you access results on CPU?

Answer: Copy results from GPU memory back to CPU memory.

Question 55.

Why synchronize in CUDA?

Answer: To ensure all threads are done processing before collecting results.

Question 56.

Where does synchronize go in C?

Answer: In C, the synchronize call appears after the kernel launch line.

Question 57.

Where does synchronize go in Python?

Answer: In Python, the synchronize call appears at the end of the kernel function.

Question 58.

CUDA memory cleanup (C)

Answer: In C, CUDA memory must be cleaned manually (in addition to normal C memory cleaning).

Question 59.

What if you allocate more threads than needed?

Answer: Pass a memory bound to the kernel and check inside the kernel whether the mapped index exceeds the bound before doing work.

Question 60.

What is mem_bound (1D)?

Answer: mem_bound is the size of the array.

Question 61.

Extra threads in 2D case (bounds)

Answer: In 2D, the bounds are the sizes of the original 2D array.

Question 62.

GPU Hardware Model (hierarchy)

Answer: A GPU has a two-level hierarchy: GPU chip → multiple Streaming Multiprocessors (SMs) → each SM has multiple (non-identical) "CUDA cores".

Question 63.

Streaming Multiprocessor (SM)

Answer: An SM is a major processing unit on a GPU chip; each GPU chip contains multiple SMs.

Question 64.

CUDA core (in the GPU model)

Answer: A CUDA core is a processing/execution unit within an SM; CUDA cores in an SM can be non-identical.

Question 65.

What units make up CUDA cores?

Answer: CUDA cores are a cluster of units: INT, FP32 & FP64, Tensor, and Special function units.

Question 66.

INT unit (inside CUDA cores)

Answer: Integer arithmetic/operations hardware inside a CUDA core.

Question 67.

FP32 unit (inside CUDA cores)

Answer: Floating-point (32-bit) arithmetic/operations hardware inside a CUDA core.

Answer: Small, fast storage locations within a CPU core (as shown in the diagram).

Question 76.

Program Counter (CPU core)

Answer: CPU core component that tracks the next instruction to execute (as shown in the diagram).

Question 77.

MMU (CPU core)

Answer: Memory Management Unit; handles memory address translation/management (as shown in the diagram).

Question 78.

Prefetch Buffer (CPU core)

Answer: CPU core buffer that preloads upcoming instructions/data (as shown in the diagram).

Question 79.

Instruction Decoder (CPU core)

Answer: CPU core component that decodes instructions into control signals/operations (as shown in the diagram).

Question 80.

Branch Predictor (CPU core)

Answer: CPU core component that predicts branches to improve control-flow performance (as shown in the diagram).

Question 81.

SM vs CPU core (functionality)

Answer: One SM (a collection of "CUDA cores") is like one CPU core.

Question 82.

CPU parallelism measurement

Answer: CPU parallelism is commonly measured by the number of CPU cores.

Question 83.

GPU parallelism measurement

Answer: GPU parallelism is commonly measured by (# of CUDA cores) × (# of SMs).

Question 84.

Why GPU tends to have more "cores" than CPU

Answer: Compared to a CPU, a GPU has more execution units ("CUDA cores").

Question 85.

Cost per execution unit (GPU vs CPU)

Answer: On average, each GPU execution unit ("CUDA core") costs less than a CPU execution unit.

Question 86.

CPU vs GPU tasks (high level)

Answer: CPU is sequential & complex; GPU is parallel & simple.

Question 87.

Why "use GPU" in application code?

Answer: To parallelize work: keep sequential/complex parts on CPU and offload parallel/simple parts to GPU.

Question 88.

Ampere A100 (context on slide)

Answer: A named example GPU architecture/model referenced in the lecture slide: "Ampere A100".

Question 89.

Deploying a function on GPU means what?

Answer: Each time we deploy a function on the GPU, we deploy the job on a grid.

Question 90.

Why request a grid before running GPU work?

Answer: You must request a grid with the right amount of threads before deploying the job.

Question 91.

Thread block uniformity rule

Answer: All thread blocks on the same grid must contain the same number of threads and be organized in the same way.

Question 100.

Organization example: Thread block 1 with Grid 2

Answer: Thread block stays (x=8, y=1, z=1) while grid is (x=4, y=2, z=1).

Question 101.

Organization example: Grid 3 (x,y,z)

Answer: Grid 3: (x=4, y=2, z=4).

Question 102.

Organization example: Thread block 3 (x,y,z)

Answer: Thread block 3: (x=8, y=2, z=4).

Question 103.

Mapping rule: TB → SM

Answer: A thread block (TB) is mapped to a streaming multiprocessor (SM) by the scheduler.

Question 104.

No-splitting rule for thread blocks

Answer: One thread block cannot be split and assigned to multiple SMs.

Question 105.

TB lifecycle residency rule

Answer: Thread blocks reside on their assigned SMs for their entire lifecycle (from assignment to end of execution).

Question 106.

Can multiple thread blocks share the same SM?

Answer: Yes, multiple thread blocks may share the same SM (if resources allow).

Question 107.

TB mapping order guarantee?

Answer: There is no guaranteed order: thread blocks may be assigned to SMs in a random order; do not assume a specific mapping order.

Question 108.

Assumption to avoid about SM sharing

Answer: Do not assume how multiple thread blocks will share the same SM (or which ones will share).

Question 109.

Independent execution: start times

Answer: Thread blocks execute independently—some may start early or late depending on the scheduler.

Question 110.

Independent execution: finish times

Answer: Thread blocks execute independently—some may finish early or late depending on workload.

Question 111.

When do thread blocks share the same SM?

Answer: When (1) there are too many TBs, and (2) one SM has enough resources to handle more than one TB's resource requirements.

Question 112.

What if SM resource capacity does not meet a TB's requirement?

Answer: The job will not be launched.

Question 113.

If there are N SMs and each SM can take K TBs, how many TBs run at once?

Answer: NK thread blocks can be executed at the same time.

Question 114.

What if there are more than NK TBs on the grid?

Answer: At most NK TBs run; the remaining TBs are put on hold (waitlist).

Question 115.

When do "on hold" TBs run?

Answer: When active TBs finish and release SM resources, TBs on the waitlist are assigned to available SMs.

Question 116.

How is a multidimensional grid executed on SMs?

Answer: CUDA internally linearizes a multidimensional grid and executes it as a 1D grid.

Question 125.

Kernel-to-thread mapping

Answer: Each kernel instance is mapped to a thread.

Question 126.

Why kernels use built-in variables

Answer: Kernels use built-in variables (thread/block IDs) to find the correct data index to work on.

Question 127.

C kernel specifier

Answer: In C, a kernel function must be declared with the "global" specifier.

Question 128.

Kernel return type restriction

Answer: A kernel cannot return anything (must be void).

Question 129.

host specifier (CUDA C)

Answer: Non-kernel (CPU) functions can be marked with "host" (optional to write).

Question 130.

Helper function for a kernel (CUDA C)

Answer: A helper function used by a kernel must be declared with the "device" specifier.

Question 131.

device function return capability

Answer: A device function can return non-void data.

Question 132.

Who can call a device function?

Answer: Only kernels can call a device function.

Question 133.

Python kernel/device designation

Answer: In Python, a decorator is used to specify whether a function is a kernel or a device function.

Question 134.

Thread identification for vector addition

Answer: The first N threads handle the vector addition, where N is the vector length.

Question 135.

Built-in CUDA variables (threads)

Answer: threadIdx.x, threadIdx.y, threadIdx.z

Question 136.

Built-in CUDA variables (block dimensions)

Answer: blockDim.x, blockDim.y, blockDim.z

Question 137.

Built-in CUDA variables (block indices)

Answer: blockIdx.x, blockIdx.y, blockIdx.z

Question 138.

Built-in CUDA variables (grid dimensions)

Answer: gridDim.x, gridDim.y, gridDim.z

Question 139.

Built-in variables in Python (access)

Answer: In Python, add "cuda." before built-in variables (e.g., cuda.threadIdx.x).

Question 140.

Multidimensional indexing idea

Answer: Map (x,y) coordinates to a single linear index (like flattening a matrix).

Question 141.

Linear index of (x,y) in an M×N matrix

Answer: y * N + x

Question 142.

Index in a 1D block (in a 1D grid)

Answer: threadIdx.x: 0...N-1; threadIdx.y: 0...M-1; threadIdx.z always 0

Question 152.

threadIdx ranges in 3D block

Answer: threadIdx.x: 0...N-1; threadIdx.y: 0...M-1; threadIdx.z: 0...K-

Question 153.

blockDim values in 1D block

Answer: blockDim.x=N; blockDim.y=1; blockDim.z=

Question 154.

blockDim values in 2D block

Answer: blockDim.x=N; blockDim.y=M; blockDim.z=

Question 155.

blockDim values in 3D block

Answer: blockDim.x=N; blockDim.y=M; blockDim.z=K

Question 156.

1D grid shape

Answer: (N, 1, 1)

Question 157.

2D grid shape

Answer: (N, M, 1)

Question 158.

3D grid shape

Answer: (N, M, K)

Question 159.

blockIdx ranges in 1D grid

Answer: blockIdx.x: 0...N-1; blockIdx.y always 0; blockIdx.z always 0

Question 160.

blockIdx ranges in 2D grid

Answer: blockIdx.x: 0...N-1; blockIdx.y: 0...M-1; blockIdx.z always 0

Question 161.

blockIdx ranges in 3D grid

Answer: blockIdx.x: 0...N-1; blockIdx.y: 0...M-1; blockIdx.z: 0...K-

Question 162.

gridDim values in 1D grid

Answer: gridDim.x=N; gridDim.y=1; gridDim.z=

Question 163.

gridDim values in 2D grid

Answer: gridDim.x=N; gridDim.y=M; gridDim.z=

Question 164.

gridDim values in 3D grid

Answer: gridDim.x=N; gridDim.y=M; gridDim.z=K

Question 165.

Kernel launch concept

Answer: Launching a kernel is like calling a function, except you must specify grid/block dimensions.

Question 166.

Kernel launch syntax (C)

Answer: kernel_name<<<# of blocks, # of threads per block>>>(...)

Question 167.

Kernel launch syntax (Python)

Answer: kernel_name# of blocks, # of threads per block

Question 168.

What does "# of blocks" represent?

Answer: # of blocks is the grid dimension.

Question 169.

What does "# of threads per block" represent?

Answer: # of threads per block is the block dimension.