{"id":32659726,"url":"https://github.com/flosmume/cpp-cuda-streams-and-pinned-mem","last_synced_at":"2026-05-13T20:34:11.727Z","repository":{"id":321336623,"uuid":"1084789631","full_name":"FlosMume/cpp-cuda-streams-and-pinned-mem","owner":"FlosMume","description":"A CUDA C++ demo showing how to overlap data transfer and kernel execution using multiple streams and pinned (page-locked) host memory. This project illustrates asynchronous memcpy, event timing, and performance benefits of concurrent GPU execution — essential for building high-throughput pipelines.","archived":false,"fork":false,"pushed_at":"2025-10-29T03:57:20.000Z","size":1079,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-29T05:44:12.528Z","etag":null,"topics":["asynchronous-execution","cuda","cuda-streams","gpu","parallel-programming","performance-optimization","pinned-memory"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FlosMume.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-28T06:52:25.000Z","updated_at":"2025-10-29T03:57:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"c9e865e3-deb7-4f1c-8101-3f232b467727","html_url":"https://github.com/FlosMume/cpp-cuda-streams-and-pinned-mem","commit_stats":null,"previous_names":["flosmume/cpp-cuda-streams-and-pinned-mem"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/FlosMume/cpp-cuda-streams-and-pinned-mem","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlosMume%2Fcpp-cuda-streams-and-pinned-mem","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlosMume%2Fcpp-cuda-streams-and-pinned-mem/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlosMume%2Fcpp-cuda-streams-and-pinned-mem/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlosMume%2Fcpp-cuda-streams-and-pinned-mem/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FlosMume","download_url":"https://codeload.github.com/FlosMume/cpp-cuda-streams-and-pinned-mem/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FlosMume%2Fcpp-cuda-streams-and-pinned-mem/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":282007155,"owners_count":26598240,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-31T02:00:07.401Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asynchronous-execution","cuda","cuda-streams","gpu","parallel-programming","performance-optimization","pinned-memory"],"created_at":"2025-10-31T15:01:07.581Z","updated_at":"2026-05-13T20:34:11.722Z","avatar_url":"https://github.com/FlosMume.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CUDA Streams \u0026 Pinned Memory — Overlap Compute \u0026 Transfers\n\n## 🚀 Overview\nThis project demonstrates **how to overlap CUDA memory transfers and kernel execution** using:\n- Multiple CUDA streams  \n- Pinned (page-locked) host memory  \n- Asynchronous `cudaMemcpyAsync`  \n- A simple SAXPY-like compute (`z = a*x + b`)  \n\nThe goal is to show how **PCIe transfers**, **kernel compute**, and **host/device synchronization** can run concurrently to maximize GPU utilization.\n\n---\n\n## 📁 Project Structure\n```\nstreams-and-pinned-mem/\n│── CMakeLists.txt\n│── overlap_streams.cu\n│── README.md  ← (this file)\n│── scripts/\n│    └── check_cuda_streams_status.sh\n│── build/ (generated)\n```\n\n---\n\n## ✨ Key Concepts Demonstrated\n### 1. CUDA Streams\nEach stream executes operations **in order**, but different streams can run **in parallel**:\n- Independent **compute** and **memcpy** paths  \n- Helps hide PCIe transfer latency  \n- Enables multi-chunk pipelining  \n\n### 2. Pinned (Page-Locked) Memory\nPinned memory allows:\n- True asynchronous DMA transfers  \n- Higher PCIe bandwidth  \n- Required for overlap with kernel execution  \n\nAllocated using:\n```cpp\ncudaHostAlloc(\u0026h_x, N*sizeof(float), cudaHostAllocDefault);\n```\n\n### 3. Overlapping Execution\nThe program uses **N streams**, each responsible for a chunk:\n```\nH2D copy   →   Kernel   →   D2H copy\n```\nAll streams operate concurrently, creating a pipeline.\n\n---\n\n## 📊 Timeline Diagram (Conceptual)\n\n```\nStream 0: [H2D]----[Compute]-------[D2H]\nStream 1:        [H2D]----[Compute]-------[D2H]\nStream 2:               [H2D]----[Compute]-------[D2H]\nStream 3:                      [H2D]----[Compute]-------[D2H]\n```\n\n**Result:** PCIe transfers and kernels run **at the same time**, improving throughput.\n\n---\n\n## 🧮 Kernel Explanation\nThe compute is intentionally simple:\n```cpp\nz[i] = a * x[i] + b;\n```\nThis allows the demo to focus on **stream behavior**, not algorithm complexity.\n\n---\n\n## 🛠 Build Instructions (Clean \u0026 Simple)\n\n### **Prerequisites**\n- Linux (WSL2 Ubuntu recommended)\n- NVIDIA GPU + driver\n- CUDA Toolkit installed system-wide (`/usr/local/cuda`)\n\n### **Build**\n```bash\nrm -rf build\ncmake -S . -B build -DCMAKE_BUILD_TYPE=Release\ncmake --build build -j\n```\n\n### **Run**\n```bash\n./build/overlap_streams\n```\n\n---\n\n## ✔ Verification Script\nIncluded under `scripts/check_cuda_streams_status.sh`:\n\n- Detects `nvcc`  \n- Detects GPU compute capability  \n- Confirms pinned memory support  \n- Prints all CUDA runtime library versions  \n- Warns if conda CUDA overrides system CUDA  \n\nRun:\n```bash\nbash scripts/check_cuda_streams_status.sh\n```\n\n---\n\n## 🧪 Tips for Success\n### Avoid Conda CUDA Unless Needed\nSystem CUDA is almost always safer:\n```bash\nwhich nvcc\n# should be /usr/local/cuda/bin/nvcc\n```\n\n### Always clear hash after PATH changes\n```bash\nhash -r\n```\n\n### Measure Overlap Efficiency\nUse:\n```bash\nnvprof ./build/overlap_streams\n```\nor Nsight Systems.\n\n---\n\n## 🔗 References\n- NVIDIA CUDA Programming Guide  \n- “Streams and Concurrency” — official CUDA samples  \n- Nsight Systems Profiling Tutorials  \n\n---\n\n## 👤 Author\n**Samuel Huang**  \nGitHub: **FlosMume**\n\n---\n\n## 📝 License\nMIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflosmume%2Fcpp-cuda-streams-and-pinned-mem","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflosmume%2Fcpp-cuda-streams-and-pinned-mem","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflosmume%2Fcpp-cuda-streams-and-pinned-mem/lists"}