GraphBuilder
Creating a GraphBuilder
- Function
Creates a GraphBuilder for subsequent graph construction.
- Prototype
torch_atb.GraphBuilder (graphName: string) -> torch_atb.GraphBuilder
- Parameter
Name of a graph operator. The value is of the string type.
- Return Value
GraphBuilder
- Notice
If the API fails to be called, an exception is thrown and the API stops running.
- Example
1builder = torch_atb.Builder("Graph")
Setting the Input of a Computational Graph
- Function
Sets the input of a computational graph.
- Prototype
GraphBuilder.AddInput (name: string) -> torch_atb.GraphBuilder
- Parameter
Name of the input. The value is of the string type.
- Return Value
string
- Notice
If the API fails to be called, an exception is thrown and the API stops running.
- Example
1 2
x = builder.add_input("x") y = builder.add_input("y")
Setting the Node of a Computational Graph
- Function
Sets the node of a computational graph.
- Prototype
GraphBuilder.AddNode (inputs: vector<string>, param: xxxParam) -> torch_atb.GraphBuilder
- Parameter
Name of the input, which is the parameter of the operator created using torch_atb.
- Return Value
GraphNode
- Notice
If the API fails to be called, an exception is thrown and the API stops running.
- Example
1 2 3 4
# Create and set the operator parameters. elewise_add = torch_atb.ElewiseParam() elewise_add.elewise_type = torch_atb.ElewiseParam.ElewiseType.ELEWISE_ADD layer1 = builder.add_node([x, y], elewise_add)
Setting the Output of a Computational Graph
- Function
Marks the input tensor as the output of the computational graph.
- Prototype
GraphBuilder.MarkOutput (outTensor: string) -> torch_atb.GraphBuilder
- Parameter
Name of the tensor.
- Notice
If the API fails to be called, an exception is thrown and the API stops running.
- Example
1builder.mark_output(layer2.get_output(0))
Tensor Transposition
- Function
Changes the shape of a tensor.
- Prototype
GraphBuilder.Reshape (string, std::function, string) -> torch_atb.GraphBuilder
- Parameter
Name of the tensor.
- Notice
If the API fails to be called, an exception is thrown and the API stops running.
- Example
1 2 3 4 5
layer1 = builder.add_node([x, y], elewise_add) add_out = layer1.get_output(0) builder.reshape(add_out, lambda shape: [1, shape[0] * shape[1]], "add_out_") # Use "add_out_" to bind the tensor to other nodes after transposition. layer2 = builder.add_node(["add_out_", z], elewise_mul)
Building a Computational Graph
- Function
Creates a graph op.
- Prototype
GraphBuilder.Build () -> torch_atb.GraphBuilder
- Return Value
atb::OperationWrapper
- Notice
If the API fails to be called, an exception is thrown and the API stops running.
- Example
1 2 3
builder = torch_atb.Builder("Graph") # The process of adding inputs, nodes, and marking outputs is omitted. Graph = builder.build()
Setting the Actual Execution Streams
- Function
Sets the actual execution streams.
- Prototype
GraphBuilder.SetExecuteStreams (executeStreams: std::vector<std::uintptr_t>) -> torch_atb.GraphBuilder
- Parameter
List of actual execution streams (aclStream).
- Notice
If the API fails to be called, an exception is thrown and the API stops running.
- Example
1 2 3 4 5 6 7 8 9 10 11
def create_streams(): streams = [] for i in range(2): stream, ret = acl.rt.create_stream() if ret != ACL_SUCCESS: exit(0) streams.append(stream) return streams builder = torch_atb.Builder("Graph") builder.set_execute_streams(create_streams())