















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!
















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.
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.
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).
CUDA parallelization model hierarchy
Answer: CUDA uses a two- level hierarchy: a Grid (collection of thread blocks) and Thread Blocks (groups of threads).
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.
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.
Thread (definition)
Answer: A thread is the smallest execution unit ("the hard worker").
Two key quantities when requesting a grid
Answer: (1) Number of threads per thread block, and (2) Number of thread blocks.
Grid/block organization dimensions
Answer: Both grids and thread blocks can be organized as 1D, 2D, or 3D (and they can differ in dimensionality).
TB→SM mapping rule (core rule)
Answer: A thread block (TB) is mapped to a single SM and cannot be split across multiple SMs.
TB lifecycle on an SM
Answer: Thread blocks stay on their assigned SMs for their entire lifecycle (from assignment to completion).
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.
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.).
Global thread index formula (1D grid of 1D blocks)
Answer: i = blockIdx.x * blockDim.x + threadIdx.x
CUDA cores contain what units?
Answer: CUDA cores are a cluster of units including INT, FP32/FP64, Tensor, and special function units.
CUDA core vs CPU core (functionality)
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.
When do "on hold" TBs run?
Answer: When active TBs finish and release SM resources, TBs on the waitlist get assigned to available SMs.
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.
Kernel launch idea
Answer: Launching a kernel is like calling a function, except you must specify grid/block dimensions.
Kernel launch syntax (C)
Answer: kernel_name<<<# of blocks, # of threads per block>>>(...)
Kernel launch syntax (Python)
Answer: kernel_name# of blocks, # of threads per block
Answer: # of blocks is the grid dimension.
Answer: # of threads per block is the block dimension.
Two ways to specify dimensional parameters
Answer: Use scalars for 1D; use tuple-like objects for multi-dimensional structures.
Scalar example: <<<1, 2>>>
Answer: 1D grid of a 1D block of 2 threads.
Scalar example: <<<4, 10>>>
Answer: 1D grid of 4 blocks of 10 threads.
C multi-dim coordinate type for kernel params
Answer: Use dimX types (often dim3) like dim3(x_value, y_value, z_value).
dim3 argument type note
Answer: dim3 arguments are unsigned integers; be mindful when calculating values.
Python multi-dim kernel params
Answer: In Python, a simple tuple (x, y, z) works for multi-dimensional settings.
Built-in CUDA indexing variables
Answer: threadIdx.(x,y,z), blockDim.(x,y,z), blockIdx.(x,y,z), gridDim.(x,y,z)
Built-ins in Python access
Answer: In Python, use cuda.threadIdx.x etc. (prefix with cuda.)
Matrix linear index formula (x,y) in MxN
Answer: y * N + x
3D grid shape
Answer: (N, M, K)
CPU and GPU memory sharing
Answer: GPU and CPU cannot share memory.
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.
After GPU work, how do you access results on CPU?
Answer: Copy results from GPU memory back to CPU memory.
Why synchronize in CUDA?
Answer: To ensure all threads are done processing before collecting results.
Where does synchronize go in C?
Answer: In C, the synchronize call appears after the kernel launch line.
Where does synchronize go in Python?
Answer: In Python, the synchronize call appears at the end of the kernel function.
CUDA memory cleanup (C)
Answer: In C, CUDA memory must be cleaned manually (in addition to normal C memory cleaning).
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.
What is mem_bound (1D)?
Answer: mem_bound is the size of the array.
Extra threads in 2D case (bounds)
Answer: In 2D, the bounds are the sizes of the original 2D array.
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".
Streaming Multiprocessor (SM)
Answer: An SM is a major processing unit on a GPU chip; each GPU chip contains multiple SMs.
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.
What units make up CUDA cores?
Answer: CUDA cores are a cluster of units: INT, FP32 & FP64, Tensor, and Special function units.
INT unit (inside CUDA cores)
Answer: Integer arithmetic/operations hardware inside a CUDA core.
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).
Program Counter (CPU core)
Answer: CPU core component that tracks the next instruction to execute (as shown in the diagram).
MMU (CPU core)
Answer: Memory Management Unit; handles memory address translation/management (as shown in the diagram).
Prefetch Buffer (CPU core)
Answer: CPU core buffer that preloads upcoming instructions/data (as shown in the diagram).
Instruction Decoder (CPU core)
Answer: CPU core component that decodes instructions into control signals/operations (as shown in the diagram).
Branch Predictor (CPU core)
Answer: CPU core component that predicts branches to improve control-flow performance (as shown in the diagram).
SM vs CPU core (functionality)
Answer: One SM (a collection of "CUDA cores") is like one CPU core.
CPU parallelism measurement
Answer: CPU parallelism is commonly measured by the number of CPU cores.
GPU parallelism measurement
Answer: GPU parallelism is commonly measured by (# of CUDA cores) × (# of SMs).
Why GPU tends to have more "cores" than CPU
Answer: Compared to a CPU, a GPU has more execution units ("CUDA cores").
Cost per execution unit (GPU vs CPU)
Answer: On average, each GPU execution unit ("CUDA core") costs less than a CPU execution unit.
CPU vs GPU tasks (high level)
Answer: CPU is sequential & complex; GPU is parallel & simple.
Why "use GPU" in application code?
Answer: To parallelize work: keep sequential/complex parts on CPU and offload parallel/simple parts to GPU.
Ampere A100 (context on slide)
Answer: A named example GPU architecture/model referenced in the lecture slide: "Ampere A100".
Deploying a function on GPU means what?
Answer: Each time we deploy a function on the GPU, we deploy the job on a grid.
Why request a grid before running GPU work?
Answer: You must request a grid with the right amount of threads before deploying the job.
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.
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).
Organization example: Grid 3 (x,y,z)
Answer: Grid 3: (x=4, y=2, z=4).
Organization example: Thread block 3 (x,y,z)
Answer: Thread block 3: (x=8, y=2, z=4).
Mapping rule: TB → SM
Answer: A thread block (TB) is mapped to a streaming multiprocessor (SM) by the scheduler.
No-splitting rule for thread blocks
Answer: One thread block cannot be split and assigned to multiple SMs.
TB lifecycle residency rule
Answer: Thread blocks reside on their assigned SMs for their entire lifecycle (from assignment to end of execution).
Can multiple thread blocks share the same SM?
Answer: Yes, multiple thread blocks may share the same SM (if resources allow).
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.
Assumption to avoid about SM sharing
Answer: Do not assume how multiple thread blocks will share the same SM (or which ones will share).
Independent execution: start times
Answer: Thread blocks execute independently—some may start early or late depending on the scheduler.
Independent execution: finish times
Answer: Thread blocks execute independently—some may finish early or late depending on workload.
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.
What if SM resource capacity does not meet a TB's requirement?
Answer: The job will not be launched.
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.
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).
When do "on hold" TBs run?
Answer: When active TBs finish and release SM resources, TBs on the waitlist are assigned to available SMs.
How is a multidimensional grid executed on SMs?
Answer: CUDA internally linearizes a multidimensional grid and executes it as a 1D grid.
Kernel-to-thread mapping
Answer: Each kernel instance is mapped to a thread.
Why kernels use built-in variables
Answer: Kernels use built-in variables (thread/block IDs) to find the correct data index to work on.
C kernel specifier
Answer: In C, a kernel function must be declared with the "global" specifier.
Kernel return type restriction
Answer: A kernel cannot return anything (must be void).
host specifier (CUDA C)
Answer: Non-kernel (CPU) functions can be marked with "host" (optional to write).
Helper function for a kernel (CUDA C)
Answer: A helper function used by a kernel must be declared with the "device" specifier.
device function return capability
Answer: A device function can return non-void data.
Who can call a device function?
Answer: Only kernels can call a device function.
Python kernel/device designation
Answer: In Python, a decorator is used to specify whether a function is a kernel or a device function.
Thread identification for vector addition
Answer: The first N threads handle the vector addition, where N is the vector length.
Built-in CUDA variables (threads)
Answer: threadIdx.x, threadIdx.y, threadIdx.z
Built-in CUDA variables (block dimensions)
Answer: blockDim.x, blockDim.y, blockDim.z
Built-in CUDA variables (block indices)
Answer: blockIdx.x, blockIdx.y, blockIdx.z
Built-in CUDA variables (grid dimensions)
Answer: gridDim.x, gridDim.y, gridDim.z
Built-in variables in Python (access)
Answer: In Python, add "cuda." before built-in variables (e.g., cuda.threadIdx.x).
Multidimensional indexing idea
Answer: Map (x,y) coordinates to a single linear index (like flattening a matrix).
Linear index of (x,y) in an M×N matrix
Answer: y * N + x
Index in a 1D block (in a 1D grid)
Answer: threadIdx.x: 0...N-1; threadIdx.y: 0...M-1; threadIdx.z always 0
threadIdx ranges in 3D block
Answer: threadIdx.x: 0...N-1; threadIdx.y: 0...M-1; threadIdx.z: 0...K-
blockDim values in 1D block
Answer: blockDim.x=N; blockDim.y=1; blockDim.z=
blockDim values in 2D block
Answer: blockDim.x=N; blockDim.y=M; blockDim.z=
blockDim values in 3D block
Answer: blockDim.x=N; blockDim.y=M; blockDim.z=K
1D grid shape
Answer: (N, 1, 1)
2D grid shape
Answer: (N, M, 1)
3D grid shape
Answer: (N, M, K)
blockIdx ranges in 1D grid
Answer: blockIdx.x: 0...N-1; blockIdx.y always 0; blockIdx.z always 0
blockIdx ranges in 2D grid
Answer: blockIdx.x: 0...N-1; blockIdx.y: 0...M-1; blockIdx.z always 0
blockIdx ranges in 3D grid
Answer: blockIdx.x: 0...N-1; blockIdx.y: 0...M-1; blockIdx.z: 0...K-
gridDim values in 1D grid
Answer: gridDim.x=N; gridDim.y=1; gridDim.z=
gridDim values in 2D grid
Answer: gridDim.x=N; gridDim.y=M; gridDim.z=
gridDim values in 3D grid
Answer: gridDim.x=N; gridDim.y=M; gridDim.z=K
Kernel launch concept
Answer: Launching a kernel is like calling a function, except you must specify grid/block dimensions.
Kernel launch syntax (C)
Answer: kernel_name<<<# of blocks, # of threads per block>>>(...)
Kernel launch syntax (Python)
Answer: kernel_name# of blocks, # of threads per block
What does "# of blocks" represent?
Answer: # of blocks is the grid dimension.
What does "# of threads per block" represent?
Answer: # of threads per block is the block dimension.