Skip to main content

gpu_bfs

Function gpu_bfs 

Source
pub async fn gpu_bfs(
    device: &GpuDevice,
    buffers: &GpuCsrBuffers,
    source: NodeId,
) -> Result<GpuBfsResult>
Expand description

Run GPU BFS from source node

§Errors

Returns error if:

  • GPU shader compilation fails
  • Buffer creation fails
  • Shader dispatch fails
  • Result readback fails

§Example

let device = GpuDevice::new().await?;
let mut graph = CsrGraph::new();
graph.add_edge(NodeId(0), NodeId(1), 1.0)?;
graph.add_edge(NodeId(1), NodeId(2), 1.0)?;

let buffers = GpuCsrBuffers::from_csr_graph(&device, &graph)?;
let result = gpu_bfs(&device, &buffers, NodeId(0)).await?;

assert_eq!(result.distance(NodeId(0)), Some(0));
assert_eq!(result.distance(NodeId(1)), Some(1));
assert_eq!(result.distance(NodeId(2)), Some(2));