pub struct GraphBuilder { /* private fields */ }Expand description
Builds a ComputeGraph via a fluent API.
The builder accumulates nodes, buffers, and explicit dependency edges.
Calling build finalises the graph and optionally
infers data-flow edges from buffer read/write relationships.
Implementations§
Source§impl GraphBuilder
impl GraphBuilder
Sourcepub fn with_auto_infer_edges(self, v: bool) -> Self
pub fn with_auto_infer_edges(self, v: bool) -> Self
Configures whether buffer-based data-flow edges are inferred on build.
Default: true.
Sourcepub fn alloc_buffer(&mut self, name: &str, size_bytes: usize) -> BufferId
pub fn alloc_buffer(&mut self, name: &str, size_bytes: usize) -> BufferId
Allocates a named device buffer and returns its BufferId.
Sourcepub fn alloc_external_buffer(
&mut self,
name: &str,
size_bytes: usize,
) -> BufferId
pub fn alloc_external_buffer( &mut self, name: &str, size_bytes: usize, ) -> BufferId
Allocates an external (caller-managed) buffer.
Sourcepub fn add_kernel(
&mut self,
name: &str,
num_blocks: u32,
threads_per_block: u32,
shared_mem: u32,
) -> KernelNodeBuilder<'_>
pub fn add_kernel( &mut self, name: &str, num_blocks: u32, threads_per_block: u32, shared_mem: u32, ) -> KernelNodeBuilder<'_>
Starts a fluent kernel-node configuration.
Call .finish() on the returned builder to register the node.
Sourcepub fn add_kernel_3d(
&mut self,
name: &str,
grid: (u32, u32, u32),
block: (u32, u32, u32),
shared_mem: u32,
) -> NodeId
pub fn add_kernel_3d( &mut self, name: &str, grid: (u32, u32, u32), block: (u32, u32, u32), shared_mem: u32, ) -> NodeId
Adds a kernel launch node with the given function name and 3-D grid/block.
Sourcepub fn add_memcpy(
&mut self,
name: &str,
dir: MemcpyDir,
size_bytes: usize,
) -> NodeId
pub fn add_memcpy( &mut self, name: &str, dir: MemcpyDir, size_bytes: usize, ) -> NodeId
Adds a host-to-device or device-to-host memcpy node.
Sourcepub fn add_memset(&mut self, name: &str, size_bytes: usize, value: u8) -> NodeId
pub fn add_memset(&mut self, name: &str, size_bytes: usize, value: u8) -> NodeId
Adds a memset node.
Sourcepub fn add_event_record(&mut self, name: &str) -> NodeId
pub fn add_event_record(&mut self, name: &str) -> NodeId
Adds an event-record node.
Sourcepub fn add_event_wait(&mut self, name: &str) -> NodeId
pub fn add_event_wait(&mut self, name: &str) -> NodeId
Adds an event-wait node.
Sourcepub fn add_barrier(&mut self, name: &str) -> NodeId
pub fn add_barrier(&mut self, name: &str) -> NodeId
Adds a barrier (no-op synchronisation) node.
Sourcepub fn add_host_callback(&mut self, name: &str) -> NodeId
pub fn add_host_callback(&mut self, name: &str) -> NodeId
Adds a host-callback node.
Sourcepub fn add_raw(&mut self, node: GraphNode) -> NodeId
pub fn add_raw(&mut self, node: GraphNode) -> NodeId
Adds a raw GraphNode (full control over the node).
Sourcepub fn set_inputs(
&mut self,
node: NodeId,
inputs: impl IntoIterator<Item = BufferId>,
) -> &mut Self
pub fn set_inputs( &mut self, node: NodeId, inputs: impl IntoIterator<Item = BufferId>, ) -> &mut Self
Attaches input buffers to an existing node.
Returns self for chaining.
Sourcepub fn set_outputs(
&mut self,
node: NodeId,
outputs: impl IntoIterator<Item = BufferId>,
) -> &mut Self
pub fn set_outputs( &mut self, node: NodeId, outputs: impl IntoIterator<Item = BufferId>, ) -> &mut Self
Attaches output buffers to an existing node.
Sourcepub fn dep(&mut self, from: NodeId, to: NodeId) -> &mut Self
pub fn dep(&mut self, from: NodeId, to: NodeId) -> &mut Self
Adds a dependency edge from → to.
Returns &mut self for chaining. On error, the builder records the
error and build() will propagate it.
Sourcepub fn chain(&mut self, nodes: &[NodeId]) -> &mut Self
pub fn chain(&mut self, nodes: &[NodeId]) -> &mut Self
Adds a linear dependency chain: nodes[0] → nodes[1] → … → nodes[n-1].
Sourcepub fn fan_in(&mut self, predecessors: &[NodeId], join: NodeId) -> &mut Self
pub fn fan_in(&mut self, predecessors: &[NodeId], join: NodeId) -> &mut Self
Adds “fan-in” edges: all predecessors must complete before join.
Sourcepub fn fan_out(&mut self, fork: NodeId, successors: &[NodeId]) -> &mut Self
pub fn fan_out(&mut self, fork: NodeId, successors: &[NodeId]) -> &mut Self
Adds “fan-out” edges: fork must complete before all successors start.
Sourcepub fn build(self) -> GraphResult<ComputeGraph>
pub fn build(self) -> GraphResult<ComputeGraph>
Finalises the builder and returns the assembled ComputeGraph.
If auto_infer_edges is true (the default), data-flow dependency
edges are inferred from buffer input/output annotations before
returning.
§Errors
Propagates any GraphError accumulated during the build process
(e.g., cycles introduced by data-flow edge inference).