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.
- Host: GitHub
- URL: https://github.com/architj6/gpu-parallel-computing
- Owner: ArchitJ6
- Created: 2026-05-04T14:22:23.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2026-05-04T16:26:32.000Z (3 months ago)
- Last Synced: 2026-05-04T17:33:46.567Z (3 months ago)
- Topics: cpp, cuda, docker, gpgpu, gpu, gpu-programming, high-performance-computing, hip, hpc, nvidia, parallel-computing, rocm
- Language: C++
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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.โ