# 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
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://notes.dizy.cc/graphics-processing-units/final-exam-prep-code.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
