An open API service indexing awesome lists of open source software.

https://github.com/architj6/gpu-parallel-computing

A structured exploration of GPU parallel computing using HIP and CUDA, covering kernels, memory patterns, matrix operations, and Docker-based execution.
https://github.com/architj6/gpu-parallel-computing

cpp cuda docker gpgpu gpu gpu-programming high-performance-computing hip hpc nvidia parallel-computing rocm

Last synced: 1 day ago
JSON representation

A structured exploration of GPU parallel computing using HIP and CUDA, covering kernels, memory patterns, matrix operations, and Docker-based execution.

Awesome Lists containing this project

README

          

# ๐Ÿš€ GPU Parallel Computing: HIP & CUDA

> A structured, hands-on exploration of GPU programming using **HIP (portable)** and **CUDA (NVIDIA)** โ€” built from fundamentals to real-world parallel workloads.

---






---

# ๐Ÿ“Œ Overview

This repository demonstrates:

* โšก GPU parallel programming fundamentals
* ๐Ÿง  Thread hierarchy & execution model
* ๐Ÿ“Š Data-parallel algorithms
* ๐Ÿ” Reduction & synchronization
* ๐Ÿงฎ Matrix computations
* ๐Ÿง  Memory access optimization
* ๐Ÿ–ผ๏ธ Image processing on GPU
* ๐Ÿ”„ Portability from HIP โ†’ CUDA

---

# ๐Ÿ“ Project Structure

```bash
.
โ”œโ”€โ”€ 01_basics/
โ”œโ”€โ”€ 02_vector_ops/
โ”œโ”€โ”€ 03_reduction/
โ”œโ”€โ”€ 04_matrix/
โ”œโ”€โ”€ 05_memory_patterns/
โ”œโ”€โ”€ 06_image_processing/
โ”‚
โ”œโ”€โ”€ cuda_versions/
โ”‚ โ”œโ”€โ”€ (same structure as above)
โ”‚
โ”œโ”€โ”€ Dockerfile
โ”œโ”€โ”€ docker-compose.yml
```

---

# ๐Ÿง  GPU Execution Model

All programs follow this pipeline:

```text
CPU (Host)
โ†“
Memory Transfer (Host โ†’ Device)
โ†“
GPU Kernel Execution (Parallel Threads)
โ†“
Memory Transfer (Device โ†’ Host)
```

---

# ๐Ÿ“‚ Module Breakdown (with File Explanation)

## ๐Ÿ”น 01_basics/

### โœ” `hello_threads`

* Prints thread IDs from GPU
* Demonstrates **parallel execution**

### โœ” `thread_indexing`

* Displays block and thread indices
* Helps understand **thread hierarchy**

---

## ๐Ÿ”น 02_vector_ops/

### โœ” `vector_add`

* Each thread adds one element
๐Ÿ‘‰ Demonstrates **data parallelism**

### โœ” `vector_square`

* Each thread squares one value
๐Ÿ‘‰ Fully independent computation

---

## ๐Ÿ”น 03_reduction/

### โœ” `dot_product_atomic`

* Uses `atomicAdd` to accumulate results

๐Ÿ‘‰ Teaches:

* Race conditions
* Synchronization
* Reduction patterns

---

## ๐Ÿ”น 04_matrix/

### โœ” `matrix_add`

* Uses 2D thread mapping
๐Ÿ‘‰ Introduces **grid-based parallelism**

### โœ” `matrix_mul`

* Performs matrix multiplication

๐Ÿ‘‰ Core concept used in:

* Machine Learning
* Deep Learning (GEMM)

---

## ๐Ÿ”น 05_memory_patterns/

### โœ” `reverse_array`

* Demonstrates reverse indexing
๐Ÿ‘‰ Memory remapping logic

### โœ” `strided_access`

* Accesses memory with stride

๐Ÿ‘‰ Shows:

* Non-coalesced memory access
* Performance implications

---

## ๐Ÿ”น 06_image_processing/

### โœ” `grayscale`

* Converts RGB image data โ†’ grayscale

๐Ÿ‘‰ First **real-world GPU workload**

---

# ๐Ÿ”„ HIP vs CUDA

Both implementations follow the same logic:

| Concept | HIP | CUDA |
| ----------------- | -------------------- | --------------------- |
| Memory Allocation | hipMalloc | cudaMalloc |
| Memory Copy | hipMemcpy | cudaMemcpy |
| Synchronization | hipDeviceSynchronize | cudaDeviceSynchronize |
| Compiler | hipcc | nvcc |

๐Ÿ‘‰ Only API names differ โ€” execution model is identical.

---

# โš™๏ธ How to Run

## ๐ŸŸฃ HIP (AMD / Portable)

```bash
hipcc file.cpp -o output
./output
```

---

## ๐ŸŸข CUDA (NVIDIA)

```bash
nvcc file.cu -o output
./output
```

---

# ๐Ÿณ Docker Setup (CUDA Only)

This project includes Docker support for **CUDA execution using NVIDIA GPU**

## โš ๏ธ Important

* Works only with **NVIDIA GPUs**
* Uses CUDA base image
* HIP (ROCm) is **not supported in this container**

---

## โ–ถ๏ธ Start Container

```bash
docker compose up -d
```

---

## โ–ถ๏ธ Enter Container

```bash
docker compose exec cuda-dev bash
```

---

## โ–ถ๏ธ Run Example

```bash
cd cuda_versions/01_basics
nvcc hello_threads.cu -o hello
./hello
```

---

## ๐Ÿงช Verify GPU Access

```bash
docker run --rm --gpus all nvidia/cuda:12.2.0-base nvidia-smi
```

---

# ๐Ÿ“Š When GPU Helps

| Workload | CPU | GPU |
| ---------------- | ---------- | --------- |
| Vector Ops | Moderate | Fast |
| Matrix Ops | Slow | Very Fast |
| Image Processing | Sequential | Parallel |

๐Ÿ‘‰ GPU excels when:

* Work is independent
* Data size is large

---

# ๐Ÿง  Key Learnings

* GPU requires **parallel thinking**, not sequential logic
* Memory transfer can be a bottleneck
* Thread mapping impacts performance
* Memory access patterns matter

---

# ๐Ÿš€ Future Improvements

* Shared memory optimization
* CPU vs GPU benchmarking
* Real image input/output
* Multi-GPU scaling

---

# ๐Ÿ† Why This Repo Stands Out

* Structured learning progression
* Covers both HIP & CUDA
* Includes Docker-based execution
* Demonstrates real-world GPU usage

---

# โญ Final Thought

> โ€œParallel computing isnโ€™t just faster computing โ€”
> itโ€™s smarter computation at scale.โ€