Skip to main content

GraphBuilder

Struct GraphBuilder 

Source
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

Source

pub fn new() -> Self

Creates a new empty builder.

Source

pub fn with_auto_infer_edges(self, v: bool) -> Self

Configures whether buffer-based data-flow edges are inferred on build.

Default: true.

Source

pub fn alloc_buffer(&mut self, name: &str, size_bytes: usize) -> BufferId

Allocates a named device buffer and returns its BufferId.

Source

pub fn alloc_external_buffer( &mut self, name: &str, size_bytes: usize, ) -> BufferId

Allocates an external (caller-managed) buffer.

Source

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.

Source

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.

Source

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.

Source

pub fn add_memset(&mut self, name: &str, size_bytes: usize, value: u8) -> NodeId

Adds a memset node.

Source

pub fn add_event_record(&mut self, name: &str) -> NodeId

Adds an event-record node.

Source

pub fn add_event_wait(&mut self, name: &str) -> NodeId

Adds an event-wait node.

Source

pub fn add_barrier(&mut self, name: &str) -> NodeId

Adds a barrier (no-op synchronisation) node.

Source

pub fn add_host_callback(&mut self, name: &str) -> NodeId

Adds a host-callback node.

Source

pub fn add_raw(&mut self, node: GraphNode) -> NodeId

Adds a raw GraphNode (full control over the node).

Source

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.

Source

pub fn set_outputs( &mut self, node: NodeId, outputs: impl IntoIterator<Item = BufferId>, ) -> &mut Self

Attaches output buffers to an existing node.

Source

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.

Source

pub fn chain(&mut self, nodes: &[NodeId]) -> &mut Self

Adds a linear dependency chain: nodes[0] → nodes[1] → … → nodes[n-1].

Source

pub fn fan_in(&mut self, predecessors: &[NodeId], join: NodeId) -> &mut Self

Adds “fan-in” edges: all predecessors must complete before join.

Source

pub fn fan_out(&mut self, fork: NodeId, successors: &[NodeId]) -> &mut Self

Adds “fan-out” edges: fork must complete before all successors start.

Source

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).

Trait Implementations§

Source§

impl Debug for GraphBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for GraphBuilder

Source§

fn default() -> GraphBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more