{"id":27099543,"url":"https://github.com/puzzlef/vector-sum-cuda","last_synced_at":"2026-04-14T18:32:49.197Z","repository":{"id":62145393,"uuid":"558223916","full_name":"puzzlef/vector-sum-cuda","owner":"puzzlef","description":"Comparing performance of sequential vs CUDA-based vector element sum.","archived":false,"fork":false,"pushed_at":"2025-04-08T18:02:55.000Z","size":609,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-03T10:52:44.939Z","etag":null,"topics":["cuda","element","experiment","gpu","sum","vector"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/puzzlef.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-10-27T05:59:13.000Z","updated_at":"2025-04-08T18:02:58.000Z","dependencies_parsed_at":"2025-04-13T01:59:42.308Z","dependency_job_id":null,"html_url":"https://github.com/puzzlef/vector-sum-cuda","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":"puzzlef/vector-max-cuda","purl":"pkg:github/puzzlef/vector-sum-cuda","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/puzzlef%2Fvector-sum-cuda","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/puzzlef%2Fvector-sum-cuda/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/puzzlef%2Fvector-sum-cuda/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/puzzlef%2Fvector-sum-cuda/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/puzzlef","download_url":"https://codeload.github.com/puzzlef/vector-sum-cuda/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/puzzlef%2Fvector-sum-cuda/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31810737,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-14T18:05:02.291Z","status":"ssl_error","status_checked_at":"2026-04-14T18:05:01.765Z","response_time":153,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["cuda","element","experiment","gpu","sum","vector"],"created_at":"2025-04-06T12:36:12.450Z","updated_at":"2026-04-14T18:32:49.183Z","avatar_url":"https://github.com/puzzlef.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"Comparing performance of *sequential* vs *CUDA-based* **vector element sum**.\n\nWe take a floating-point vector `x`, with number of *elements* ranging from\n`1E+6` to `1E+9`, and sum them up using CUDA (`Σx`). We attempt each element\ncount with various approaches, running each approach 5 times to get a good time\nmeasure. Sum here represents any `reduce()` operation that processes several\nvalues to a single value. I thank the guidance from [Prof. Kishore Kothapalli] and\n[Prof. Dip Sankar Banerjee].\n\n\u003cbr\u003e\n\n\n### Adjusting launch config for Memcpy approach\n\nIn this experiment ([memcpy-adust-launch]), we compare various *launch configs*\nfor *CUDA-based* vector element sum, using the **memcpy** approach. We attempt\ndifferent element counts with various *CUDA launch configs*.\n\nThis sum uses *memcpy* to transfer partial results to CPU, where the final sum\nis calculated. If the result can be used within GPU itself, it *might* be faster\nto calculate complete sum [in-place] instead of transferring to CPU. Results\nindicate that a **grid_limit** of `1024` and a **block_size** of `128/256` is\nsuitable for **float** datatype, and a **grid_limit** of `1024` and a\n**block_size** of `256` is suitable for **double** datatype. Thus, using a\n**grid_limit** of `1024` and a **block_size** of `256` could be a decent choice.\nInterestingly, the *sequential sum* suffers from **precision issue** when using\nthe **float** datatype, while the *CUDA based sum* does not.\n\n[memcpy-adust-launch]: https://github.com/puzzlef/vector-sum-cuda/tree/memcpy-adjust-launch\n\n\u003cbr\u003e\n\n\n### Adjust per-thread duty for Memcpy approach\n\nIn this experiment ([memcpy-adjust-duty]), we compare various *per-thread duty*\n*numbers* for **CUDA based vector element sum (memcpy)**. Here, we attempt each\nelement count with various **CUDA launch configs**, and **per-thread-duties**.\nRest of the experimental setup is similar to the [memcpy-adjust-launch]\nexperiment. Results indicate no significant difference between\n[memcpy launch][memcpy-adust-launch] approach, and this one.\n\n[memcpy-adjust-duty]: https://github.com/puzzlef/vector-sum-cuda/tree/memcpy-adjust-duty\n\n\u003cbr\u003e\n\n\n### Adjusting launch config for Inplace approach\n\nIn this experiment ([inplace-adjust-launch]), we compare various *launch*\n*configs* for CUDA based **vector element sum** (**in-place**) (in-place). We\nattempt different element counts with various **CUDA** **launch configs**. This\nis an in-place sum, meaning the single sum values is calculated entirely by the\nGPU. This is done using 2 kernel calls.\n\nA number of possible optimizations including *multiple reads per loop*\n*iteration*, *loop unrolled reduce*, *atomic adds*, and *multiple kernels*\nprovided no benefit (see [branches]). A simple **one read per loop iteration**\nand **standard reduce loop** (minimizing warp divergence) is both **shorter**\nand **works best**. For **float**, a **grid_limit** of `1024` and a\n**block_size** of `128` is a decent choice. For **double**, a **grid_limit** of\n`1024` and a **block_size** of `256` is a decent choice. Interestingly, the\n*sequential sum* suffers from **precision issue** when using the **float**\ndatatype, while the *CUDA based sum* does not (just like with\n[memcpy sum][memcpy-adust-launch]).\n\n[inplace-adjust-launch]: https://github.com/puzzlef/vector-sum-cuda/tree/inplace-adjust-launch\n\n\u003cbr\u003e\n\n\n### Comparison of Memcpy and Inplace approach\n\nIn this experiment ([memcpy-vs-inplace]), we compare the performance of\n[memcpy][memcpy-adust-launch] vs [in-place][inplace-adjust-launch] based CUDA\nbased **vector element sum**. It appears **both** **approaches** have\n**similar** performance.\n\n[memcpy-vs-inplace]: https://github.com/puzzlef/vector-sum-cuda/tree/memcpy-vs-inplace\n\n\u003cbr\u003e\n\n\n### Comparison with Sequential approach\n\nIn this experiment ([compare-sequential], [main]), we compare the performance\nbetween finding `sum(x)` using a single thread (**sequential**) and **CUDA**\n(*not power-of-2* and *power-of-2* reduce). Here `x` is a 32-bit integer vector.\nWe attempt the approaches on a number of vector sizes. Note that time taken to\ncopy data back and forth from the GPU is not measured, and the sequential\napproach does not make use of *SIMD instructions*.\n\nWhile it might seem that **CUDA** approach would be a clear winner, the results\nindicate it is dependent upon the workload. Results indicate that **from 10^5**\n**elements, CUDA approach performs better** than sequential. Both CUDA\napproaches (*not power-of-2*/*power-of-2* reduce) seem to have similar\nperformance. All outputs are saved in a [gist]. Some [charts] are also included\nbelow, generated from [sheets].\n\n[![](https://i.imgur.com/WAY6rGl.png)][sheetp]\n\n[compare-sequential]: https://github.com/puzzlef/vector-sum-cuda/tree/compare-sequential\n[main]: https://github.com/puzzlef/vector-sum-cuda\n\n\u003cbr\u003e\n\u003cbr\u003e\n\n\n## References\n\n- [CUDA by Example :: Jason Sanders, Edward Kandrot](https://gist.github.com/wolfram77/72c51e494eaaea1c21a9c4021ad0f320)\n- [Managed memory vs cudaHostAlloc - TK1](https://forums.developer.nvidia.com/t/managed-memory-vs-cudahostalloc-tk1/34281)\n- [How to enable C++17 code generation in VS2019 CUDA project](https://stackoverflow.com/a/63057409/1413259)\n- [\"More than one operator + matches these operands\" error](https://stackoverflow.com/a/10343618/1413259)\n- [How to import VSCode keybindings into Visual Studio?](https://stackoverflow.com/a/62417446/1413259)\n- [Explicit conversion constructors (C++ only)](https://www.ibm.com/docs/en/i/7.3?topic=only-explicit-conversion-constructors-c)\n- [Configure X11 Forwarding with PuTTY and Xming](https://www.centlinux.com/2019/01/configure-x11-forwarding-putty-xming-windows.html)\n- [code-server setup and configuration](https://coder.com/docs/code-server/latest/guide)\n- [Installing snap on CentOS](https://snapcraft.io/docs/installing-snap-on-centos)\n- [Git pulling a branch from another repository?](https://stackoverflow.com/a/46289324/1413259)\n\n\u003cbr\u003e\n\u003cbr\u003e\n\n\n[![](https://i.imgur.com/MOJPoM0.jpg)](https://www.youtube.com/watch?v=E0_Ic1P-Hzg)\u003cbr\u003e\n[![ORG](https://img.shields.io/badge/org-puzzlef-green?logo=Org)](https://puzzlef.github.io)\n[![DOI](https://zenodo.org/badge/558223916.svg)](https://zenodo.org/badge/latestdoi/558223916)\n![](https://ga-beacon.deno.dev/G-KD28SG54JQ:hbAybl6nQFOtmVxW4if3xw/github.com/puzzlef/vector-sum-cuda)\n\n[Prof. Dip Sankar Banerjee]: https://sites.google.com/site/dipsankarban/\n[Prof. Kishore Kothapalli]: https://faculty.iiit.ac.in/~kkishore/\n[branches]: https://github.com/puzzlef/vector-sum-cuda/branches\n[gist]: https://gist.github.com/wolfram77/44465db42bf17b0464159331388da526\n[charts]: https://imgur.com/a/bnRHipj\n[sheets]: https://docs.google.com/spreadsheets/d/19hBlJQv7JwEuoA2X0aw5IS0_MghifQfr3TG_WgmoSww/edit?usp=sharing\n[sheetp]: https://docs.google.com/spreadsheets/d/e/2PACX-1vTwzwsCzU25d7YEo6kVST5tRVSWKESczT7Wo51ML_tghIrBlOa4e9IrCgeG5c5_lOM5Ojzu8Txq8xjQ/pubhtml\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpuzzlef%2Fvector-sum-cuda","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpuzzlef%2Fvector-sum-cuda","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpuzzlef%2Fvector-sum-cuda/lists"}