{"id":13809671,"url":"https://github.com/cszach/rust-cuda-template","last_synced_at":"2025-05-14T08:33:01.858Z","repository":{"id":212547922,"uuid":"731761399","full_name":"cszach/rust-cuda-template","owner":"cszach","description":"A Rust CUDA template with detailed instructions.","archived":false,"fork":false,"pushed_at":"2023-12-14T20:33:08.000Z","size":7,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-19T02:38:54.541Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","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/cszach.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}},"created_at":"2023-12-14T20:20:34.000Z","updated_at":"2024-10-05T15:00:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"5769d66d-a5ef-45c7-bb90-b626baeb6bfa","html_url":"https://github.com/cszach/rust-cuda-template","commit_stats":null,"previous_names":["cszach/rust-cuda-template"],"tags_count":0,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cszach%2Frust-cuda-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cszach%2Frust-cuda-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cszach%2Frust-cuda-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cszach%2Frust-cuda-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cszach","download_url":"https://codeload.github.com/cszach/rust-cuda-template/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254104887,"owners_count":22015558,"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","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":[],"created_at":"2024-08-04T02:00:34.145Z","updated_at":"2025-05-14T08:32:56.850Z","avatar_url":"https://github.com/cszach.png","language":"Rust","funding_links":[],"categories":["Frameworks","GPU Programming"],"sub_categories":[],"readme":"# Rust CUDA template\n\nThis is a template that you can use for your own Rust CUDA projects. It took me\na while to set this up so my goal is to compile every problem I've come across\nto help others save time. An example `add` package is included so you can verify\nthe setup.\n\n## Table of content\n\n1. [My system](#my-system)\n2. [Project structure](#project-structure)\n   - [`add` package](#add-package)\n3. [Build prerequisites](#build-prerequisites)\n   - [Installing multiple CUDA versions](#installing-multiple-cuda-versions)\n   - [Installing GCC](#installing-gcc)\n4. [Environment](#environment)\n5. [Build](#build)\n\n## My system\n\n- OS: Fedora 39\n- CUDA version: 11.8 (GCC 11.2)\n- LLVM version: 7.0.1\n\n## Project structure\n\n- `cpu/`: contains CPU packages, each in its own directory. CPU packages do\n  stuff on the CPU like I/O and launching the GPU kernel;\n- `gpu/`: contains GPU packages, which contains GPU kernels;\n- `resources/`: where the compiled PTX files are created. This directory is\n  initially empty.\n\nAll child folders in `cpu/` and `gpu/` are the project's virtual workspace\nmembers (see [`Cargo.toml`](Cargo.toml)). You may want to add a root package.\n\n### `add` package\n\nThe `add` package is included as a simple Rust CUDA hello world. It adds two\narrays of 2 to the power of 20 (about 1 million) items each, with one array\nholding all 1's and the other all 2's. The result should be an array of all 3's.\n\n## Build prerequisites\n\n[1]: https://github.com/Rust-GPU/Rust-CUDA/blob/master/guide/src/guide/getting_started.md\n[2]: #installing-multiple-cuda-versions\n[3]: https://gist.github.com/ax3l/9489132\n[4]: #installing-gcc\n\nThere are prerequisites documented by the Rust CUDA project (see [here][1]), but\nI think it is incomplete. I will document what I needed to install on my system\nbelow.\n\n- The CUDA SDK, version 11.2 **to 11.8**. CUDA 12.0+ won't work at the moment.\n  Also, see _[Installing multiple CUDA versions][2]_ below if you need.\n  - When installing CUDA, you might also need the appropriate GCC version (or\n    clang, but I use GCC). See [this compatibility table][3] and the\n    _[Installing GCC][4]_ section below.\n- LLVM 7.0-7.4. For this, I installed `llvm7.0-devel` and `llvm7.0-static` from\n  the repositories.\n  - At first, I only installed `llvm7.0-devel`, but build errors complained that\n    my environment was missing some static LLVM libraries, hence\n    `llvm7.0-static`. You might or might not need to install the latter.\n\n### Installing multiple CUDA versions\n\n[5]: https://blog.kovalevskyi.com/multiple-version-of-cuda-libraries-on-the-same-machine-b9502d50ae77\n\nMany thanks to [this blog post][5] by Viacheslav.\n\nWhen downloading CUDA, you need to select the \"runfile (local)\" installer type.\nTo run the installer, use the command below:\n\n```shell\nsudo sh cuda_11.8.0_520.61.05_linux.run --silent --toolkit --toolkitpath=/usr/local/cuda-11.8\n```\n\n- Be sure to replace the paths.\n- If the installer says there is not enough space in `/tmp`, append the option\n  `--tmpdir=/path/to/tmp`, replacing `/path/to/tmp` with a temporary folder that\n  you created (e.g. in your home directory, like `/home/zach/tmp`).\n- The installer will set the link `/usr/local/cuda` to point to the version that\n  you just installed. You can make it point back to another version if you like.\n\n### Installing GCC\n\n[6]: https://gcc.gnu.org/mirrors.html\n\nI couldn't find the version of GCC I needed in the Fedora DNF repositories, so\nI had to build GCC myself (Rest. In. Peace). You might be able to find it in the\nrepositories; if not, here are the steps to build GCC.\n\n1. Select from one of [the mirror sites][6]. Go to `/releases`, select the\n   appropriate version of GCC, then download the archive (`.xz` for faster\n   download);\n2. Extract the folder, then `cd` into it;\n3. Download the prerequisites: `./contrib/download_prerequisites`;\n4. Create a build directory and `cd` into it: `mkdir build \u0026\u0026 cd build`;\n5. Configure the build:\n    ```shell\n    ../configure --enable-languages=c,c++ --disable-multilib --program-suffix=-11.2\n    ```\n    Replace the program suffix with a string you like (usually `-` followed by\n    the GCC version that is being installed). You may also want to adjust the\n    `--prefix`; the default installation directory will be `/usr/local/`.\n6. `make \u0026\u0026 sudo make install`. The `make` step might take a couple of hours, so\n   sit back, relax, and enjoy. You can use the `-j` option for parallel builds;\n7. When using the runfile installer to install CUDA (like in the above section),\n   the installer will use `/usr/bin/gcc` and there is no option to change this\n   path. As such, you might need to create a temporary symbolic link:\n    ```shell\n    sudo mv /usr/bin/gcc /usr/bin/gcc.backup # If /usr/bin/gcc is a binary\n    sudo ln -s /usr/local/bin/gcc-11.2 /usr/bin/gcc\n    sudo sh cuda… # Install CUDA as documented in the previous section\n    sudo mv /usr/bin/gcc.backup /usr/bin/gcc # Restore /usr/bin/gcc\n    ```\n   …or use `update-alternatives`, if `/usr/bin/gcc` does not exist.\n\n#### Double declared enum in `libsanitizer`\n\n[7]: https://github.com/gcc-mirror/gcc/commit/d2356ebb0084a0d80dbfe33040c9afe938c15d19\n\nWhen running `make` to build GCC 11.2, I encountered an error about an enum that\nwas already declared in `libsanitizer`. I edited the file\n`libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cpp` according to\n[this commit][7] and that solved the problem.\n\n## Environment\n\nAfter having the prerequisites installed, we need to set some environment\nvariables before building Rust CUDA projects. The environment variables needed\nare:\n\n1. `CUDA_HOME`: CUDA installation directory e.g. `/usr/local/cuda-11.8`;\n2. `LLVM_CONFIG`: path to the `llvm-config` binary e.g.\n   `/usr/lib64/llvm7.0/bin/llvm-config`. Might be redundant if\n   running `llvm-config --version` outputs `7.x.x`;\n3. `LD_LIBRARY_PATH`: set to the parent directory of `libnvvm.so` e.g.\n   `/usr/local/cuda-11.8/nvvm/lib64`.\n\nYou may use the `locate` Linux command to locate where files are.\n\n## Build\n\n[8]: https://github.com/Rust-GPU/Rust-CUDA/issues/7#issuecomment-979426844\n\nTry to build the [`add`](cpu/add) package:\n\n```shell\ncargo build -p add\n```\n\nIf you get an `undefined symbol: setupterm` error, build with\n`LLVM_LINK_SHARED=1` ([source][8]):\n\n```shell\nLLVM_LINK_SHARED=1 cargo build -p add\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcszach%2Frust-cuda-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcszach%2Frust-cuda-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcszach%2Frust-cuda-template/lists"}