CUDA Programming and GPU Kernels Review

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/56

encourage image

There's no tags or description

Looks like no tags are added yet.

57 Terms

1
New cards

What CUDA function allocates memory on the GPU?

cudaMalloc()

2
New cards

What CUDA function copies data between CPU and GPU memory?

cudaMemcpy()

3
New cards

What CUDA function frees GPU memory?

cudaFree()

4
New cards

What keyword identifies a CUDA kernel?

global

5
New cards

What CUDA variable identifies the thread within a block?

threadIdx.x

6
New cards

What CUDA variable identifies the block?

blockIdx.x

7
New cards

What CUDA variable gives the number of threads per block?

blockDim.x

8
New cards

What does __syncthreads() do?

Synchronizes threads within a block.

9
New cards

What does vector addition primarily depend on: memory bandwidth or computation?

Memory bandwidth

10
New cards

What CUDA function waits for previously launched GPU work to finish?

cudaDeviceSynchronize()

11
New cards

How many threads are in each CUDA block in the vadd program?

512512

12
New cards

What is the name of the GPU kernel for vector addition?

vadd

13
New cards

What keyword indicates that vadd is a GPU kernel?

global

14
New cards

How is the global thread index calculated in the vadd kernel?

threadIdx.x+blockIdx.x×blockDim.xthreadIdx.x + blockIdx.x \times blockDim.x

15
New cards

What does each GPU thread compute in vadd?

One element: c[i]=a[i]+b[i]c[i] = a[i] + b[i]

16
New cards

Why does the vadd kernel check if (i < elems)?

To prevent out-of-bounds access.

17
New cards

How many GPU arrays are allocated in the vadd program?

33: d_a, d_b, d_c

18
New cards

What function checks for CUDA errors?

CheckCuda

19
New cards

What is the expected value of c[i] in the vector addition test?

2 * i +1

20
New cards

Does the reported compute time for vadd include copying results back to the CPU?

No, only the kernel launch and wait.

21
New cards

Why is cudaMemcpy(d_c, c, …) optional before launching the vadd kernel?

Every valid output element is overwritten by the kernel.

22
New cards

What is the name of the CUDA kernel that computes the fractal image?

fractal

23
New cards

How many threads per block are used in the fractal program?

512512

24
New cards

What type of loop performs the fractal iterations?

do-while

25
New cards

What is the maximum number of iterations per pixel in the fractal program?

256256

26
New cards

How many pixels does each GPU thread calculate in the fractal program?

11

27
New cards

How many pixels are in an image of width w?

w×ww \times w

28
New cards

What data type is used in fractal_cuda.cu?

double

29
New cards

What data type is used in fractal_float.cu?

float

30
New cards

Which variable identifies the pixel's column in the fractal program?

col=i mod widthcol = i \bmod width

31
New cards

Which variable identifies the pixel's row in the fractal program?

row=i/widthrow = i / width

32
New cards

What is the minimum allowed image width in the fractal program?

1010

33
New cards

What condition stops the iteration in the fractal program?

count≤0count \le 0 or z_re2+z_im2≥5.0z\_re2 + z\_im2 \ge 5.0

34
New cards

What is the output array's data type in the fractal program?

unsigned char

35
New cards

Which function saves the BMP image in the fractal program?

bmp.save()

36
New cards

When does the fractal program generate a BMP file?

When width<1000width < 1000

37
New cards

Which CUDA function allocates GPU image memory in the fractal program?

cudaMalloc()

38
New cards

Which function copies the image from GPU to CPU in the fractal program?

cudaMemcpy()

39
New cards

Does the measured compute time include saving the BMP image in the fractal program?

No

40
New cards

What is the name of the CUDA kernel for matrix multiplication?

multiply

41
New cards

How many threads per block are used in the matrix multiplication program?

512512

42
New cards

How many matrix elements does each GPU thread calculate in matrix multiplication?

11

43
New cards

What is the data type of the matrices in the matrix multiplication program?

float

44
New cards

What is the minimum allowed matrix size in the matrix multiplication program?

1010

45
New cards

What function initializes the matrices in the matrix multiplication program?

init

46
New cards

What type of matrix is mat1 initialized as?

Identity matrix

47
New cards

What does multiplying mat1 by mat2 produce?

mat2

48
New cards

How is the global thread index calculated in the matrix multiplication kernel?

blockIdx.x×blockDim.x+threadIdx.xblockIdx.x \times blockDim.x + threadIdx.x

49
New cards

How is the row index calculated in the matrix multiplication kernel?

i=idx/sizei = idx / size

50
New cards

How is the column index calculated in the matrix multiplication kernel?

j=idx mod sizej = idx \bmod size

51
New cards

What type of loop is inside the matrix multiplication CUDA kernel?

for loop

52
New cards

How many iterations does the matrix multiplication kernel's loop perform per output element?

sizesize

53
New cards

How many GPU arrays are allocated in the matrix multiplication program?

33

54
New cards

Does the matrix multiplication kernel use shared memory?

No

55
New cards

Which function copies the matrix multiplication result back to the CPU?

cudaMemcpy

56
New cards

How does the program verify the matrix multiplication result?

Checks whether mat2[i]==mat3[i]mat2[i] == mat3[i]

57
New cards

What function frees GPU memory in the matrix multiplication program?

cudaFree