graph LR subgraph Graph["Input Graph"] direction LR V["Vertices V"] E["Edges E"] W["Weights w"] end Graph --> CONVERT["Convert to flat arrays\nedges[n_edgesร2] i32\nweights[n_vertices] f32\nseeds[n_trials] i32"] CONVERT --> DEVICE["Upload to GPU"] subgraph GPU["GPU Execution"] direction LR T0["Thread 0\nTrial 0"] T1["Thread 1\nTrial 1"] T2["..."] TN["Thread N-1\nTrial N-1"] end DEVICE --> T0 DEVICE --> T1 DEVICE --> T2 DEVICE --> TN T0 --> MERGE["argmin costs"] T1 --> MERGE T2 --> MERGE TN --> MERGE MERGE --> RESULT["Best Cover"] style Graph fill:#c8e6c9,stroke:#2e7d32,stroke-width:3px style GPU fill:#f3e5f5,stroke:#7b1fa2,stroke-width:3px style MERGE fill:#fff3e0,stroke:#e65100,stroke-width:3px style RESULT fill:#c8e6c9,stroke:#2e7d32,stroke-width:3px
graph TB subgraph cudarc["cudarc v0.12.1"] DRV["driver\nCudaDevice, CudaSlice\nCudaFunction, LaunchConfig"] NVRTC["nvrtc\ncompile_ptx()\nCUDA C โ PTX"] end subgraph Our["rand_cover_gpu.rs"] KERN["PITT_KERNEL_CUDA\n(const &str)"] EXEC["try_gpu_execution()\n-#[cfg(feature = cuda)]"] HOST["rand_vertex_cover_gpu()\npublic API"] end KERN --> NVRTC NVRTC --> EXEC DRV --> EXEC HOST --> EXEC style cudarc fill:#e3f2fd,stroke:#1565c0,stroke-width:3px style Our fill:#fff3e0,stroke:#e65100,stroke-width:3px style KERN fill:#f3e5f5,stroke:#7b1fa2,stroke-width:3px
sequenceDiagram participant R as Rust Host participant N as NVRTC participant D as CUDA Driver participant G as GPU R->>R: Convert Graph โ flat arrays R->>D: CudaDevice::new(0) R->>N: compile_ptx(PITT_KERNEL_CUDA) N->>R: Ptx object R->>D: load_ptx(ptx, "mod", &["pitt_kernel"]) R->>D: get_func("mod", "pitt_kernel") D->>R: CudaFunction R->>D: htod_copy(edges, weights, covers, seeds) D->>G: Copy HโD R->>G: launch(func, config, args) loop Each Thread G->>G: Pitt's algorithm end R->>D: synchronize() R->>D: dtoh_sync_copy(covers, costs) D->>R: Copy DโH R->>R: Find best trial (argmin)
graph LR subgraph Features D["default = []"] --> CPU["CPU sequential"] CUDA["cuda"] --> GPU["GPU via cudarc"] R["rayon"] --> CPU end GPU --> CUDA_COMB["cuda + rayon"] CPU --> CUDA_COMB style D fill:#f5f5f5,stroke:#212121,stroke-width:3px style CUDA fill:#f3e5f5,stroke:#7b1fa2,stroke-width:3px style R fill:#e3f2fd,stroke:#1565c0,stroke-width:3px style GPU fill:#c8e6c9,stroke:#2e7d32,stroke-width:3px style CUDA_COMB fill:#fff3e0,stroke:#e65100,stroke-width:3px
graph LR NV["NVIDIA Control Panel"] --> DEV["Developer\nsection"] DEV --> COUNTERS["Manage GPU\nPerformance Counters"] COUNTERS --> ALLOW["Allow access for\nall users"] ALLOW --> REBOOT["Reboot ๐"] style NV fill:#f3e5f5,stroke:#7b1fa2,stroke-width:3px style DEV fill:#e3f2fd,stroke:#1565c0,stroke-width:3px style COUNTERS fill:#fff3e0,stroke:#e65100,stroke-width:3px style ALLOW fill:#c8e6c9,stroke:#2e7d32,stroke-width:3px style REBOOT fill:#ffcdd2,stroke:#c62828,stroke-width:3px
graph TB subgraph Host["Host Memory"] HF["edges_flat: Vec<i32>\n[n_edges ร 2]"] HFW["weights_flat: Vec<f32>\n[n_vertices]"] HFS["seeds: Vec<u64>\n[num_trials]"] HFC["covers_host: Vec<u32>\n[num_trials ร num_words]"] HFC2["costs_host: Vec<f32>\n[num_trials]"] end subgraph Device["Device Memory"] DF["d_edges: CudaSlice<i32>"] DFW["d_weights: CudaSlice<f32>"] DFS["d_seeds: CudaSlice<u64>"] DFC["d_covers: CudaSlice<u32>"] DFC2["d_costs: CudaSlice<f32>"] end HF -->|"htod_copy()"| DF HFW -->|"htod_copy()"| DFW HFS -->|"htod_copy()"| DFS HFC -->|"htod_copy()"| DFC DFC2 -.->|"alloc_zeros()"| Device DFC -->|"dtoh_sync_copy()"| HFC DFC2 -->|"dtoh_sync_copy()"| HFC2 style Host fill:#c8e6c9,stroke:#2e7d32,stroke-width:3px style Device fill:#f3e5f5,stroke:#7b1fa2,stroke-width:3px
graph LR P["๐ Python\nNumba CUDA\nrand_cover_gpu.py"] R["๐ฆ Rust\ncudarc\nrand_cover_gpu.rs"] CUDA["๐ฎ CUDA C\npitt_kernel\n(embedded &str)"] NVRTC["๐ NVRTC\ncompile_ptx()"] PROFILE["๐ ncu\nNsight Compute"] TEST["โ 6 GPU tests\npassing"] P -->|"port"| R R --> CUDA CUDA --> NVRTC NVRTC --> PROFILE PROFILE --> TEST style P fill:#c8e6c9,stroke:#2e7d32,stroke-width:3px,color:#2e3440 style R fill:#e3f2fd,stroke:#1565c0,stroke-width:3px,color:#2e3440 style CUDA fill:#f3e5f5,stroke:#7b1fa2,stroke-width:3px,color:#2e3440 style NVRTC fill:#fff3e0,stroke:#e65100,stroke-width:3px,color:#2e3440 style PROFILE fill:#e0f7fa,stroke:#00838f,stroke-width:3px,color:#2e3440 style TEST fill:#c8e6c9,stroke:#2e7d32,stroke-width:3px,color:#2e3440