> For the complete documentation index, see [llms.txt](https://notes.dizy.cc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://notes.dizy.cc/graphics-processing-units/final-exam-prep-code.md).

# Final Exam Prep: Code

## CGMA Calculation

Compute to Global Memory Access (CGMA) ratio: The number of FP calculations performed for each access to the global memory within a region in a CUDA program.

A good CGMA is in the order of 20 or 30 to overcome slow global memory access.

### 2 Elements per Thread: C\[i] = A\[i] + B\[i]

Index of the first element:

```c
i = threadIdx.x + (blockIdx.x * blockdim.x)*2;
```

Index of the second element:

```c
i + blockDim.x
```
