{"id":49889271,"url":"https://github.com/santhsecurity/cudagrep","last_synced_at":"2026-05-15T20:09:14.497Z","repository":{"id":350120821,"uuid":"1205403639","full_name":"santhsecurity/cudagrep","owner":"santhsecurity","description":"Safe Rust bindings for GPUDirect Storage zero-copy NVMe-to-GPU transfers","archived":false,"fork":false,"pushed_at":"2026-04-09T00:01:32.000Z","size":76,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-09T02:13:18.547Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/santhsecurity.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":"AUDIT_REPORT.md","citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-08T23:51:53.000Z","updated_at":"2026-04-09T00:01:40.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/santhsecurity/cudagrep","commit_stats":null,"previous_names":["santhsecurity/cudagrep"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/santhsecurity/cudagrep","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/santhsecurity%2Fcudagrep","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/santhsecurity%2Fcudagrep/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/santhsecurity%2Fcudagrep/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/santhsecurity%2Fcudagrep/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/santhsecurity","download_url":"https://codeload.github.com/santhsecurity/cudagrep/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/santhsecurity%2Fcudagrep/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33078189,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-15T20:05:40.333Z","status":"ssl_error","status_checked_at":"2026-05-15T20:05:38.672Z","response_time":103,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2026-05-15T20:09:13.556Z","updated_at":"2026-05-15T20:09:14.491Z","avatar_url":"https://github.com/santhsecurity.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cudagrep\n\n[![crates.io](https://img.shields.io/crates/v/cudagrep.svg)](https://crates.io/crates/cudagrep)\n[![docs.rs](https://docs.rs/cudagrep/badge.svg)](https://docs.rs/cudagrep)\n[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)\n\nSafe Rust bindings for NVIDIA **GPUDirect Storage** (`libcufile`) — zero-copy NVMe-to-GPU transfers without kernel bouncing.\n\n## Why `cudagrep`?\n\n- **Graceful degradation**: Compiles and runs on machines without CUDA. No panics, no stubbed APIs.\n- **Airtight safety**: All `unsafe` code is confined to [`cufile`](src/cufile). The public API is 100% safe Rust.\n- **Zero-overhead caching**: File descriptor registrations are cached, avoiding ~50 µs driver round-trips on every read.\n- **Crates.io ready**: `no_std`-friendly error types, exhaustive docs, and adversarial tests.\n\n## Hardware Requirements\n\nTo use GPUDirect Storage with actual hardware:\n\n- **NVIDIA GPU**: Compute Capability 6.0+ (Pascal or newer)\n- **NVMe SSD**: Direct-attached NVMe storage (not SATA, not RAID controller)\n- **Linux Kernel**: 5.3+ with `CONFIG_NVME_FABRICS` support\n- **NVIDIA Driver**: R470+ with GPUDirect Storage support\n- **cuFile Library**: Part of NVIDIA CUDA Toolkit 11.4+ or standalone cuFile SDK\n\n### Filesystem Requirements\n\n- Files must be on a filesystem that supports `O_DIRECT` (ext4, XFS with `nobarrier`, etc.)\n- Files must not be compressed or encrypted at the filesystem level\n\n## Quick Start\n\n### Add to `Cargo.toml`\n\n```toml\n[dependencies]\ncudagrep = \"0.1\"\n\n# Or with runtime CUDA probing:\ncudagrep = { version = \"0.1\", features = [\"cuda\"] }\n```\n\n### Check Availability\n\n```rust\nuse cudagrep::{is_available, availability_report};\n\nif is_available() {\n    println!(\"GDS is available!\");\n} else {\n    let report = availability_report();\n    println!(\"GDS unavailable: {}\", report);\n    for diag in report.diagnostics() {\n        println!(\"  - {}\", diag);\n    }\n}\n```\n\n### Read to GPU Memory\n\n```rust\nuse cudagrep::{CuFileHardware, GDS_ALIGNMENT};\nuse cudagrep::cufile::DevicePointer;\nuse std::os::fd::RawFd;\n\nfn read_file_to_gpu(\n    fd: RawFd,\n    gpu_ptr: *mut std::ffi::c_void,\n) -\u003e Result\u003c(), cudagrep::CudaError\u003e {\n    let mut gds = CuFileHardware::try_init()?;\n    let device_pointer = unsafe { DevicePointer::new(gpu_ptr).unwrap() };\n\n    let bytes = gds.read_to_device(fd, device_pointer, GDS_ALIGNMENT, 0, 0)?;\n    println!(\"Transferred {} bytes\", bytes);\n\n    // All registrations and the driver session are cleaned up on drop\n    Ok(())\n}\n```\n\n### Batch Operations\n\n```rust\nuse cudagrep::{CuFileHardware, ReadOp, GDS_ALIGNMENT};\nuse cudagrep::cufile::DevicePointer;\n\nfn read_batch(\n    gds: \u0026mut CuFileHardware,\n    fd: std::os::fd::RawFd,\n    ptr: DevicePointer,\n) -\u003e Result\u003c(), cudagrep::CudaError\u003e {\n    let ops = vec![\n        ReadOp {\n            fd,\n            device_pointer: ptr,\n            size: GDS_ALIGNMENT,\n            file_offset: 0,\n            device_offset: 0,\n        },\n        ReadOp {\n            fd,\n            device_pointer: ptr,\n            size: GDS_ALIGNMENT,\n            file_offset: 4096,\n            device_offset: 4096,\n        },\n    ];\n\n    let (bytes_per_op, stats) = gds.read_batch(\u0026ops)?;\n    println!(\"Per-op bytes: {:?}\", bytes_per_op);\n    println!(\"Throughput: {:.2} GiB/s\", stats.throughput_gbps());\n\n    Ok(())\n}\n```\n\n### Pre-allocate Result Buffer\n\n```rust\nuse cudagrep::{CuFileHardware, ReadOp};\n\nfn read_batch_no_alloc(\n    gds: \u0026mut CuFileHardware,\n    ops: \u0026[ReadOp],\n) -\u003e Result\u003c(), cudagrep::CudaError\u003e {\n    let mut results = vec![0; ops.len()];\n    let stats = gds.read_batch_into(ops, \u0026mut results)?;\n    println!(\"Results: {:?}\", results);\n    println!(\"Throughput: {:.2} GiB/s\", stats.throughput_gbps());\n    Ok(())\n}\n```\n\n### Registration Cache Management\n\n```rust\nuse cudagrep::CuFileHardware;\n\nfn manage_fd(gds: \u0026mut CuFileHardware) -\u003e Result\u003c(), cudagrep::CudaError\u003e {\n    // gds.read_to_device(3, ...) would register fd=3 automatically\n\n    // Before closing the file, evict from cache to prevent stale handle reuse\n    let was_cached = gds.evict_fd(3)?;\n    if was_cached {\n        println!(\"Fd 3 deregistered from GDS cache\");\n    }\n    Ok(())\n}\n```\n\n### Alignment Validation\n\nGPUDirect Storage requires **4 KiB alignment** for all transfer parameters. Use `validate_alignment` to pre-check:\n\n```rust\nuse cudagrep::{validate_alignment, GDS_ALIGNMENT};\n\nfn validate_before_transfer(\n    file_offset: i64,\n    size: usize,\n    device_offset: i64,\n) -\u003e Result\u003c(), cudagrep::CudaError\u003e {\n    validate_alignment(file_offset, size, device_offset)?;\n    println!(\"All parameters are properly aligned\");\n    Ok(())\n}\n```\n\n## Safety Model\n\nAll `unsafe` code is confined to [`src/cufile/`](src/cufile/).\n\n- **FFI wrapping**: Dynamic loading and raw `libcufile` calls are hidden behind safe Rust methods.\n- **RAII cleanup**: Registered `cuFile` handles are deregistered automatically on drop. Errors during cleanup are logged, not swallowed.\n- **No leaks on error paths**: If `cuFileRead` fails, the temporary registration is still deregistered before the error is returned.\n- **Documented invariants**: Every `unsafe` block has a `// SAFETY:` comment explaining why the preconditions hold.\n\n## Key Concepts\n\n### GDS Alignment (4 KiB)\n\nGPUDirect Storage requires 4 KiB (4096-byte) alignment for all transfer parameters because NVMe DMA and GPU BAR memory mappings operate at page granularity:\n\n- File offsets must be 4 KiB aligned\n- Device offsets must be 4 KiB aligned\n- Transfer sizes must be multiples of 4 KiB\n\nUse [`validate_alignment`](https://docs.rs/cudagrep/latest/cudagrep/fn.validate_alignment.html) to pre-check parameters.\n\n### Registration Cache Lifecycle\n\n[`CuFileHardware`](https://docs.rs/cudagrep/latest/cudagrep/struct.CuFileHardware.html) maintains a cache of registered file descriptors:\n\n1. **Cache on first use**: File descriptors are registered with the driver on first read and cached for subsequent operations.\n2. **Eviction**: Call [`evict_fd`](https://docs.rs/cudagrep/latest/cudagrep/struct.CuFileHardware.html#method.evict_fd) before closing a file descriptor to prevent stale handle reuse.\n3. **Cleanup on Drop**: When `CuFileHardware` is dropped, all cached registrations are deregistered. Individual failures are logged but do not prevent cleanup of remaining handles.\n\n### ShortRead Error\n\nThe [`CudaError::ShortRead`](https://docs.rs/cudagrep/latest/cudagrep/enum.CudaError.html#variant.ShortRead) error indicates that the driver returned 0 bytes for a non-zero request, typically meaning EOF or a hardware fault. Without this check, the transfer loop would spin forever. The error includes both `requested` and `transferred` counts.\n\n## Features\n\n- `cuda` — Enables runtime probing and use of `libcufile.so.0`.\n\n## Development\n\n### Testing\n\nDefault CI validates the non-CUDA build:\n\n```bash\ncargo fmt --all --check\ncargo clippy --all-targets --no-default-features -- -D warnings\ncargo test --no-default-features\n```\n\nRun the legendary adversarial test suite:\n\n```bash\ncargo test --test legendary --no-default-features\n```\n\nValidate the feature-gated CUDA path without a GPU:\n\n```bash\ncargo test --no-run --features cuda\ncargo clippy --all-targets --features cuda -- -D warnings\n```\n\n### Benchmarking\n\n```bash\ncargo bench --no-default-features\n```\n\n### Documentation\n\n```bash\ncargo doc --no-deps --no-default-features\n```\n\n## License\n\nMIT License — see [LICENSE](LICENSE) for details.\n\n## Contributing\n\nSee [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsanthsecurity%2Fcudagrep","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsanthsecurity%2Fcudagrep","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsanthsecurity%2Fcudagrep/lists"}