# Why Was CUDA Invented? — The Breakthrough That Took GPUs Beyond Graphics

*GPU Architecture — Learning Bytes | Lesson 03*

In [<u>Lesson 02</u>](https://packetsandfabrics.hashnode.dev/why-did-gpus-become-programmable-the-step-before-cuda), we discovered that programmable shaders gave developers control over graphics calculations.

But here's a puzzle.

**If GPUs were already programmable, why did NVIDIA need CUDA?**

Let's explore.

## **🧪 Imagine You're a Scientist in 2005**

You are running a simulation involving millions of mathematical operations. Your CPU can do the work, but it takes time. A GPU has many arithmetic units capable of working on data in parallel.

There's a catch: **the GPU is designed around graphics, not ordinary scientific programs.**

To use early programmable GPUs for non-graphics calculations, researchers often represented numbers as graphics textures, performed operations with shaders, and retrieved the results through graphics interfaces.

Imagine having to format a spreadsheet as an image before adding two columns of numbers.

It was possible, but awkward.

## **💡 The Breakthrough: CUDA**

NVIDIA introduced **CUDA — Compute Unified Device Architecture** in 2006, with developer tools becoming broadly available in 2007.

CUDA gave developers a general-purpose parallel computing platform and programming model. Instead of disguising scientific calculations as graphics operations, programmers could express parallel algorithms directly using a C-based programming interface.

Consider adding two arrays:

**Array A:** 1, 2, 3, 4\
**Array B:** 5, 6, 7, 8\
**Result:** 6, 8, 10, 12

A developer writes a GPU function called a **kernel**. Many GPU threads execute that kernel, with different threads working on different array elements.

**CUDA made GPU computing more practical without requiring developers to express every problem through the graphics pipeline.**

## **⚙️ Tesla: The Hardware Foundation**

CUDA didn't arrive in isolation.

In 2006, NVIDIA launched the GeForce 8800 GTX, based on the **Tesla unified shader architecture**. Earlier GPUs commonly had distinct vertex and pixel shader processing hardware. Tesla used unified programmable processors that could be allocated more flexibly to different shader workloads.

The GeForce 8800 GTX had **128 unified stream processors**, a significant departure from earlier fixed allocations of vertex and pixel processing resources.

The distinction matters:

- **Tesla:** A GPU hardware architecture with unified shader processing.
- **CUDA:** A software platform and programming model for general-purpose GPU computing.

They are related, but they are **not the same thing**.

## **🧵 How Does CUDA Organize Parallel Work?**

Think of a factory containing many teams of workers.

CUDA organizes work in a similar way:

```plaintext
GPU hardware
└── Streaming Multiprocessors (SMs)
    └── Resident thread blocks
        └── Warps
            └── 32 threads per warp

CUDA software launch
Kernel → Grid → Thread blocks → Threads
```

- **Kernel:** A function executed by GPU threads.
- **Thread:** An instance of the program working on its own data.
- **Thread block:** A group of threads scheduled to run on one SM.
- **Warp:** A scheduling group of 32 threads on NVIDIA GPUs.
- **SM:** Hardware that schedules and executes groups of threads.

For example, a launch of **1,024 threads** could use four blocks of **256 threads**. Each block contains **eight warps** of 32 threads. The GPU schedules blocks on available SMs, subject to hardware resources.

*This is a simplified model: GPU hardware doesn't necessarily execute every resident thread at the same instant.*

## **🧩 Design It: How Would You Process One Million Numbers?**

Imagine you're building a scientific application.

You have two lists, each containing **one million numbers**, and you want to add them together.

For example:

```plaintext
Array A:  10   20   30   40
Array B:   1    2    3    4
          -----------------
Result:   11   22   33   44
```

Simple, right?

But what if the arrays contain **1,048,576 numbers**?

### **Step 1 — Think Like a CPU**

A simple CPU program could process the numbers one after another:

```plaintext
Add A[0] + B[0]
Add A[1] + B[1]
Add A[2] + B[2]
...
```

This is a sequential example. Modern CPUs can also process multiple elements in parallel.

### **Step 2 — Think Like a GPU**

Notice something interesting.

**Each addition is independent.**

We don't need to wait for the first addition before calculating the second.

CUDA lets us assign different elements to different GPU threads.

```plaintext
Thread 0 → A[0] + B[0] → C[0]
Thread 1 → A[1] + B[1] → C[1]
Thread 2 → A[2] + B[2] → C[2]
Thread 3 → A[3] + B[3] → C[3]
              ...
```

Instead of writing a program that explicitly processes each element in sequence, we launch many threads that can execute the same calculation on different data.

**This is the fundamental idea behind CUDA parallel programming.**

### **Step 3 — How Does CUDA Organize the Work?**

CUDA groups threads into **blocks**.

Suppose we choose **256 threads per block**.

For 1,048,576 elements:

**1,048,576 ÷ 256 = 4,096 blocks**

Each block contains 256 threads, organized into eight groups of 32 called **warps**.

The GPU schedules these blocks across its available Streaming Multiprocessors (SMs). They do not all execute simultaneously.

### **Step 4 — The Architect's Question**

Does this mean the GPU will always finish faster than a CPU?

**Not necessarily.**

The GPU must access the input arrays and store the results. If the data starts in CPU memory, transferring it to the GPU also takes time.

For a very small calculation, these overheads might outweigh the benefit of parallel execution.

For a larger workload involving many calculations on data already in GPU memory, GPU acceleration can become much more attractive.

### **🔬 How Would We Validate This?**

Try the same array addition on a CPU and a supported CUDA GPU.

Measure three things:

- CPU execution time.
- GPU kernel execution time.
- Total GPU time, including data transfers.

Then compare the results.

**Design takeaway:** A GPU is valuable not simply because it has many threads, but because a workload has enough suitable parallel work to justify using them.

*Reference:* [*<u>NVIDIA CUDA C++ Programming Guide</u>*](https://docs.nvidia.com/cuda/cuda-c-programming-guide/)*. The array size and thread configuration are illustrative; no benchmark results are claimed.*

## **🌐 Why Does This Matter for AI Network Architects?**

CUDA helped turn GPUs into practical platforms for scientific and, later, AI workloads. Modern model training performs enormous amounts of matrix multiplication.

But as models grew, one GPU was no longer enough. Training expanded to multiple GPUs within a server and then to thousands of GPUs across clusters.

That created a new challenge: **moving data efficiently between processors**.

- **CUDA** enables GPU computation and exposes GPU memory and execution APIs.
- **NCCL** provides collective communication operations such as AllReduce.
- **PCIe, NVLink and NVSwitch** connect devices within supported systems.
- **InfiniBand or Ethernet** networks connect GPU servers using suitable transports and network adapters.

CUDA is essential to much GPU computing, but **CUDA alone is not the entire distributed-training communication stack**.

## **🎯 The One Thing to Remember**

**Programmable shaders made general-purpose GPU calculations possible. CUDA made programming GPUs for those calculations substantially more practical.**

Tesla's unified architecture helped supply the hardware foundation.

### **🤔 Think About It**

A GPU has many threads ready to run. Some threads are waiting for data from memory.

**How can the GPU keep doing useful work instead of sitting idle while memory responds?**

That's the question we'll explore in Lesson 04, when we look inside a Streaming Multiprocessor.

---

**Series:** NVIDIA GPU Architecture — Learning Bytes

**References:**

- [<u>NVIDIA — CUDA C++ Programming Guide</u>](https://docs.nvidia.com/cuda/cuda-c-programming-guide/)
- [<u>NVIDIA — GeForce 8800 GPU Architecture Technical Brief</u>](https://www.nvidia.com/content/PDF/Geforce_8800/GeForce_8800_GPU_Architecture_Technical_Brief.pdf)
- [<u>NVIDIA — CUDA Programming Model</u>](https://developer.nvidia.com/blog/cuda-refresher-cuda-programming-model/)
