{"id":13711628,"url":"https://github.com/akhildevelops/cudaz","last_synced_at":"2026-01-03T03:19:21.505Z","repository":{"id":209603026,"uuid":"723926041","full_name":"akhildevelops/cudaz","owner":"akhildevelops","description":"Cuda library for Zig","archived":false,"fork":false,"pushed_at":"2025-03-29T12:37:10.000Z","size":79,"stargazers_count":85,"open_issues_count":1,"forks_count":6,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-29T13:30:39.778Z","etag":null,"topics":["zig-package"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/akhildevelops.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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-11-27T03:25:51.000Z","updated_at":"2025-03-29T13:04:52.000Z","dependencies_parsed_at":"2024-05-15T18:04:33.577Z","dependency_job_id":"723324a9-2d7d-4987-aa4d-80a1497da8d2","html_url":"https://github.com/akhildevelops/cudaz","commit_stats":null,"previous_names":["akhildevelops/cudaz"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akhildevelops%2Fcudaz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akhildevelops%2Fcudaz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akhildevelops%2Fcudaz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akhildevelops%2Fcudaz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akhildevelops","download_url":"https://codeload.github.com/akhildevelops/cudaz/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252772042,"owners_count":21801838,"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":["zig-package"],"created_at":"2024-08-02T23:01:10.067Z","updated_at":"2026-01-03T03:19:21.452Z","avatar_url":"https://github.com/akhildevelops.png","language":"Zig","funding_links":[],"categories":["Multimedia \u0026 Graphics"],"sub_categories":["GPU Computing"],"readme":"![AI Generated](cuda_zig.jpeg)\n# Cuda library for Zig\nThis library helps to interact with NVIDIA GPUs from zig. Provides high level interface to communicate with GPU. It can detect cuda installation and link to a project's binary on Linux/MacOS. Check [Customization](https://github.com/akhildevelops/cudaz/tree/main#Customization) to give cuda manual path.\n\n\n## The library provides below features:\n- Memory Allocation in GPU with defined size.\n- Copying data from host to gpu and viceversa.\n- Compiling (.cu) and loading kernels (.ptx) both from file and text.\n- Running kernels with grid/blocks/threads configuration.\n- [Generate random numbers](test/rng.zig)\n\nCheck [test](./test) folder for code samples.\n\n\u003eScroll below to go through an example of incrementing each value in an array parallely using GPU.\n\n### Install\nDownload and save the library path in `build.zig.zon` file by running\n\n#### zig 0.14.0\n`zig fetch --save https://github.com/akhildevelops/cudaz/archive/0.2.0.tar.gz`\n\n#### zig 0.13.0\n`zig fetch --save https://github.com/akhildevelops/cudaz/archive/0.1.0.tar.gz`\n\n\nAdd cudaz module in your project's `build.zig` file that will link to your project's binary.\n```zig\n//build.zig\nconst std = @import(\"std\");\n\npub fn build(b: *std.Build) !void {\n    // exe points to main.zig that uses cudaz\n    const exe = b.addExecutable(.{ .name = \"main\", .root_source_file = .{ .path = \"src/main.zig\" }, .target = b.host });\n\n    // Point to cudaz dependency\n    const cudaz_dep = b.dependency(\"cudaz\", .{});\n\n    // Fetch and add the module from cudaz dependency\n    const cudaz_module = cudaz_dep.module(\"cudaz\");\n    exe.root_module.addImport(\"cudaz\", cudaz_module);\n\n    // Dynamically link to libc, cuda, nvrtc\n    exe.linkLibC();\n    exe.linkSystemLibrary(\"cuda\");\n    exe.linkSystemLibrary(\"nvrtc\");\n\n    // Run binary\n    const run = b.step(\"run\", \"Run the binary\");\n    const run_step = b.addRunArtifact(exe);\n    run.dependOn(\u0026run_step.step);\n}\n\n\n```\n\n### Increment Array using GPU\n```zig\n// src/main.zig\n\nconst std = @import(\"std\");\nconst Cuda = @import(\"cudaz\");\nconst CuDevice = Cuda.Device;\nconst CuCompile = Cuda.Compile;\nconst CuLaunchConfig = Cuda.LaunchConfig;\n\n// Cuda Kernel\nconst increment_kernel =\n    \\\\extern \"C\" __global__ void increment(float *out)\n    \\\\{\n    \\\\    int i = blockIdx.x * blockDim.x + threadIdx.x;\n    \\\\    out[i] = out[i] + 1;\n    \\\\}\n;\n\npub fn main() !void {\n    // Initialize allocator\n    var GP = std.heap.GeneralPurposeAllocator(.{}){};\n    defer _ = GP.deinit();\n    const allocator = GP.allocator();\n\n    // Initialize GPU\n    const device = try CuDevice.default();\n    defer device.free();\n\n    // Copy data from host to GPU\n    const data = [_]f32{ 1.2, 2.8, 0.123 };\n    const cu_slice = try device.htodCopy(f32, \u0026data);\n    defer cu_slice.free();\n\n    // Compile and load the Kernel\n    const ptx = try CuCompile.cudaText(increment_kernel, .{}, allocator);\n    defer allocator.free(ptx);\n    const module = try CuDevice.loadPtxText(ptx);\n    const function = try module.getFunc(\"increment\");\n\n    // Run the kernel on the data\n    try function.run(.{\u0026cu_slice.device_ptr}, CuLaunchConfig{ .block_dim = .{ 3, 1, 1 }, .grid_dim = .{ 1, 1, 1 }, .shared_mem_bytes = 0 });\n\n    // Retrieve incremented data back to the system\n    const incremented_arr = try CuDevice.syncReclaim(f32, allocator, cu_slice);\n    defer incremented_arr.deinit();\n}\n```\nFor running above code system refer to the example project: [increment](./example/increment)\n\n## Examples:\n- [Incrementing array in GPU](example/increment/)\n- [Sending Custom Types to GPU](example/custom_type/)\n\n## Customization\n- It is intelligent to identify and link to installed cuda libraries. If needed, provide cuda installation path manually by mentioning build parameter `zig build -DCUDA_PATH=\u003ccuda_folder\u003e`.\n\nInspired from Rust Cuda library: https://github.com/coreylowman/cudarc/tree/main\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakhildevelops%2Fcudaz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakhildevelops%2Fcudaz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakhildevelops%2Fcudaz/lists"}