{"id":13809664,"url":"https://github.com/tmrob2/cuda2rust_sandpit","last_synced_at":"2025-05-14T08:33:27.329Z","repository":{"id":120005284,"uuid":"554532966","full_name":"tmrob2/cuda2rust_sandpit","owner":"tmrob2","description":"Minimal examples to get CUDA linear algebra programs working with Rust using CC \u0026 FFI.","archived":false,"fork":false,"pushed_at":"2022-10-23T03:12:33.000Z","size":14,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-08-04T02:06:44.660Z","etag":null,"topics":["cc","clang","cublas","cuda","cusparse","rust"],"latest_commit_sha":null,"homepage":"","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/tmrob2.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}},"created_at":"2022-10-20T01:04:29.000Z","updated_at":"2024-02-18T08:55:47.000Z","dependencies_parsed_at":"2023-06-14T16:45:29.026Z","dependency_job_id":null,"html_url":"https://github.com/tmrob2/cuda2rust_sandpit","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmrob2%2Fcuda2rust_sandpit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmrob2%2Fcuda2rust_sandpit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmrob2%2Fcuda2rust_sandpit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmrob2%2Fcuda2rust_sandpit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tmrob2","download_url":"https://codeload.github.com/tmrob2/cuda2rust_sandpit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225282535,"owners_count":17449526,"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":["cc","clang","cublas","cuda","cusparse","rust"],"created_at":"2024-08-04T02:00:33.943Z","updated_at":"2024-11-19T02:31:05.115Z","avatar_url":"https://github.com/tmrob2.png","language":"Rust","funding_links":[],"categories":["Frameworks","GPU Programming"],"sub_categories":[],"readme":"# cuda2rust_sandpit\n\nSimplest configuration and testing of Rust sparse matrix\ndata structures for sparse matrix linear algebra on CUDA. \n\nFirst, define a `build.rs` which configures the linking of\ncuda libs necessary for computation. Then `C` libraries are\ncreated under `myclib` which creates the most basic interface for controlling cuBlas and cuSparse linalg routines. \n\nA very simple FFI is constructed in `lib.rs` which references functions in `myclib`, and `build.rs` manages the construction of the dynamic shared library using:\n```Rust\ncc::Build::new()\n        .file(\"myclib/mycfuncs.c\")\n        .file(\"myclib/test_cublas.c\")\n        .file(\"myclib/test_cusparse.c\")\n        .file(\"myclib/sparse_funcs.c\")\n        .cuda(true)\n        .compile(\"mycfuncs\");\n```\n\nThe idea is to manage memory using Rust, bue still leverage the low level power of CUDA which is most conveniently accessed via a custom `C` library. \n\n## Why not use `cuBlas` FFI?\n\nI don't see any point in using a monolithic FFI for CUDA libs when it is clear that CUDA interfaces will not be natively written in `Rust` any time soon. Further, there is no FFI for `cuSparse` which is arguably the more important CUDA library. \n\nIt is much easier to write a small implementation using the `cuSparse` header and then create a small FFI related to a `Rust` project, which is playing to the strengths of both languages.\n\n## Implementation Notes\n\nA quick note on `build.rs` linking ordering. For `cargo test` to work the linked libraries need to go after `cc::Build::new()` otherwise a linking error will be generated, i.e.:\n\n```Rust\ncc::Build::new()\n    .file(\"myclib/mycfuncs.c\")\n    .file(\"myclib/test_cublas.c\")\n    .file(\"myclib/test_cusparse.c\")\n    .cuda(true)\n    .compile(\"mycfuncs\");\n    \nprintln!(\"cargo:rustc-link-lib=dylib=cublas\");\n```\n\n## Tests\n\nRun lib tests with `cargo test`.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftmrob2%2Fcuda2rust_sandpit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftmrob2%2Fcuda2rust_sandpit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftmrob2%2Fcuda2rust_sandpit/lists"}