{"id":19230117,"url":"https://github.com/changkun/gopherchina2023gogpu","last_synced_at":"2025-07-23T04:33:50.422Z","repository":{"id":173619057,"uuid":"650966401","full_name":"changkun/gopherchina2023gogpu","owner":"changkun","description":"Talk \"Go on GPU\" in GopherChina 2023","archived":false,"fork":false,"pushed_at":"2023-06-29T12:41:01.000Z","size":9205,"stargazers_count":26,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-21T03:41:23.580Z","etag":null,"topics":["go","golang","gpu","gpu-acceleration","gpu-computing"],"latest_commit_sha":null,"homepage":"https://changkun.de/s/gogpu","language":"Go","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/changkun.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2023-06-08T07:42:49.000Z","updated_at":"2025-01-26T15:56:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"9eb92498-f604-4bfe-a0ee-1849f8d5ce27","html_url":"https://github.com/changkun/gopherchina2023gogpu","commit_stats":null,"previous_names":["changkun/gopherchina2023gogpu"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/changkun/gopherchina2023gogpu","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/changkun%2Fgopherchina2023gogpu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/changkun%2Fgopherchina2023gogpu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/changkun%2Fgopherchina2023gogpu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/changkun%2Fgopherchina2023gogpu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/changkun","download_url":"https://codeload.github.com/changkun/gopherchina2023gogpu/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/changkun%2Fgopherchina2023gogpu/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266618801,"owners_count":23957273,"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-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"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":["go","golang","gpu","gpu-acceleration","gpu-computing"],"created_at":"2024-11-09T15:36:57.721Z","updated_at":"2025-07-23T04:33:50.392Z","avatar_url":"https://github.com/changkun.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GopherChina 2023 Talk \"Go on GPU\"\n\nThis repository contains source files for the GopherChina 2023 \"Go on GPU\" talk.\n\n## Abstract\n\nIn the past decade, multi-core heterogeneous computing has gradually become mainstream, forming a pattern where CPUs serve as the scheduling hub and work in conjunction with other specialized processors to handle computational tasks. Among them, thanks to the evolution and improvement of graphics computing technology, GPUs have gradually become an indispensable part of the field of general-purpose computing. Dr. Changkun Ou focuses on the practice of Go language in GPU computing, using a library that supports GPU computing as a background to explain how to interact with various pipelines of Go language and GPUs. The implementation challenges and performance challenges encountered in the practical process will be explored, and finally, an outlook will be given on the application areas within the Go language community based on GPU computing.\n\n## Slides\n\nThe slides can be found here:\n\n- [Chinese Version](./slides/ou2023gogpucn.pdf)\n- [English Version](./slides/ou2023gogpuen.pdf)\n\n## Source Code\n\n### Example 1: Matrix Multiplication\n\nThe code included in this repository demonstrates the performance improvements of using GPU to accelerate the calculation of matrix multiplication.\n\n```go\npackage gpu\n\nimport \"changkun.de/x/gogpu/math\"\n\n// Mul is a GPU version of math.Mat[T].Mul method and it multiplies\n// two matrices m1 and m2 and returns the result.\nfunc Mul[T math.Type](m1, m2 math.Mat[T]) math.Mat[T]\n```\n\nTo run the demo code:\n\n```\ngo test -v -run=TestMul\n```\n\nTo run the benchmarks:\n\n```\ngo test -v -run=none -bench=BenchmarkMul -timeout=1h | tee bench.txt\n```\n\n```\n$ benchstat bench.txt\nname                  time/op\nMul/GPU(2x2)-8         346µs ± 3%\nMul/CPU(2x2)-8         138ns ± 1%\nMul/GPU(4x4)-8         342µs ± 1%\nMul/CPU(4x4)-8         865ns ± 1%\nMul/GPU(8x8)-8         354µs ± 8%\nMul/CPU(8x8)-8        6.61µs ± 0%\nMul/GPU(16x16)-8       392µs ±11%\nMul/CPU(16x16)-8      50.4µs ± 1%\nMul/GPU(32x32)-8       396µs ± 2%\nMul/CPU(32x32)-8       388µs ± 0%\nMul/GPU(64x64)-8       456µs ± 1%\nMul/CPU(64x64)-8      3.07ms ± 0%\nMul/GPU(128x128)-8     606µs ± 4%\nMul/CPU(128x128)-8    24.3ms ± 0%\nMul/GPU(256x256)-8     829µs ± 2%\nMul/CPU(256x256)-8     194ms ± 0%\nMul/GPU(512x512)-8    2.18ms ± 2%\nMul/CPU(512x512)-8     1.55s ± 0%\nMul/GPU(1024x1024)-8  15.7ms ±15%\nMul/CPU(1024x1024)-8   12.4s ± 0%\nMul/GPU(2048x2048)-8   126ms ± 1%\nMul/CPU(2048x2048)-8    120s ± 3%\n```\n\n![](bench.png)\n\nThe benchmark shows that the GPU version of matrix multiplication is ~950x faster than the CPU version with a matrix size of 2048 x 2048.\n\nNote that the code included in this repository is a tidy version that was written in Project [PolyRed](https://github.com/polyred/polyred).\n\n### Example 2: Image Processing\n\nThe code included in this repository demonstrates the performance improvements of using GPU to accelerate image processing.\n\n```go\npackage enhance\n\n// ImageGPU is a GPU version of Image.\nfunc ImageGPU(m *image.RGBA, params Params) *image.RGBA\n```\n\nTo run the demo code:\n\n```\ngo test -v -run=TestImageEnhance\n```\n\n| Original | Enhanced(CPU) | Enhanced(GPU) |\n| -------- | ------------- | ------------- |\n| ![](testdata/1.jpg) | ![](testdata/enhanced_cpu.jpg) | ![](testdata/enhanced_gpu.jpg) |\n\nTo run the benchmarks:\n\n```\ngo test -v -run=none -bench=BenchmarkImageEnhance -timeout=1h | tee bench2.txt\n```\n\n```\n$ benchstat bench2.txt\nname                time/op\nImageEnhance/CPU-8   432ms ± 1%\nImageEnhance/GPU-8  6.39ms ± 6%\n```\n\nThe benchmark shows that the GPU version of matrix multiplication is ~64x faster than the CPU version\n\nNote that the code included in this repository is a tidy version that was written in Project [Enhance](https://github.com/changkun/enhance).\n\n## License\n\nThe slides are licensed under the [CC BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/) license, and the source code is licensed under the [MIT](https://opensource.org/licenses/MIT) license.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchangkun%2Fgopherchina2023gogpu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchangkun%2Fgopherchina2023gogpu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchangkun%2Fgopherchina2023gogpu/lists"}