{"id":13809641,"url":"https://github.com/Narsil/bindgen_cuda","last_synced_at":"2025-05-14T08:33:14.275Z","repository":{"id":215830358,"uuid":"739825116","full_name":"Narsil/bindgen_cuda","owner":"Narsil","description":null,"archived":false,"fork":false,"pushed_at":"2024-07-11T19:20:56.000Z","size":16,"stargazers_count":19,"open_issues_count":10,"forks_count":7,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-17T15:09:28.821Z","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/Narsil.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":"2024-01-06T16:56:20.000Z","updated_at":"2024-11-11T11:17:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"677635d1-0022-41da-879f-9b1d9cb2c3d5","html_url":"https://github.com/Narsil/bindgen_cuda","commit_stats":null,"previous_names":["narsil/bindgen_cuda"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Narsil%2Fbindgen_cuda","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Narsil%2Fbindgen_cuda/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Narsil%2Fbindgen_cuda/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Narsil%2Fbindgen_cuda/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Narsil","download_url":"https://codeload.github.com/Narsil/bindgen_cuda/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225053871,"owners_count":17413676,"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:33.463Z","updated_at":"2024-11-19T02:31:03.056Z","avatar_url":"https://github.com/Narsil.png","language":"Rust","funding_links":[],"categories":["Frameworks","GPU Programming"],"sub_categories":[],"readme":"# Bindgen Cuda\n\n[![Latest version](https://img.shields.io/crates/v/bindgen_cuda.svg)](https://crates.io/crates/bindgen_cuda)\n[![Documentation](https://docs.rs/bindgen_cuda/badge.svg)](https://docs.rs/bindgen_cuda)\n![License](https://img.shields.io/crates/l/bindgen_cuda.svg)\n\nSimilar crate than [bindgen](https://github.com/rust-lang/rust-bindgen) in philosophy.\nIt will help create automatic bindgen to cuda kernels source files and make them easier to use\ndirectly from Rust.\n\n\n## PTX inclusion\nLet's say you have a file\n\n`src/cuda.cu`\n```cuda\n__global__ void cuda_hello(){\n    printf(\"Hello World from GPU!\\n\");\n}\n```\n\nYou can add `bindgen_cuda` as a build dependency:\n\n```bash\ncargo add --build bindgen_cuda\n```\n\nAnd then create this `build.rs`\n\n```no_run\nfn main() {\n    let builder = bindgen_cuda::Builder::default();\n    let bindings = builder.build_ptx().unwrap();\n    bindings.write(\"src/lib.rs\");\n}\n```\n\nThis will create a src file containing the following code:\n\n```ignore\npub const CUDA: \u0026str = include_str!(concat!(env!(\"OUT_DIR\"), \"/cuda.ptx\"));\n```\n\nYou can then use the PTX directly in your rust code with a library like [cudarc](https://github.com/coreylowman/cudarc/).\n\n## Raw cuda calls\nAlternatively you can build a static library that you can link against in build.rs in order to call cuda directly with the c code.\n\n`src/cuda.cu`\n\n```cuda\n__global__ void cuda_hello(){\n    printf(\"Hello World from GPU!\\n\");\n}\n\nint run() {\n    cuda_hello\u003c\u003c\u003c1,1\u003e\u003e\u003e(); \n    return 0;\n}\n```\n\n\nThen write the `build.rs`:\n\n```no_run\nfn main() {\n    let builder = bindgen_cuda::Builder::default();\n    builder.build_lib(\"libcuda.a\");\n    println!(\"cargo:rustc-link-lib=cuda\");\n}\n```\n\nWhich you can then interface through FFI in `src/lib.rs`:\n\n\n```no_run\nextern \"C\" {\n    fn cuda_hello();\n}\nfn main(){\n    unsafe{ cuda_hello();}\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNarsil%2Fbindgen_cuda","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FNarsil%2Fbindgen_cuda","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNarsil%2Fbindgen_cuda/lists"}