class dnnl::graph::graph¶
Overview¶
A graph object. More…
#include <dnnl_graph.hpp> class graph: public graph_handle { public: // construction graph(engine::kind engine_kind); graph(engine::kind engine_kind, fpmath_mode mode); // methods void set_fpmath_mode(fpmath_mode mode, bool apply_to_int = false); void get_fpmath_mode(fpmath_mode& mode, bool& apply_to_int) const; status add_op(const op& op, bool allow_exception = true); void finalize(); bool is_finalized() const; std::vector<partition> get_partitions(partition::policy policy = partition::policy::fusion); };
Detailed Documentation¶
A graph object.
Construction¶
graph(engine::kind engine_kind)
Constructs a graph with an engine kind.
Parameters:
engine_kind |
Engine kind. |
graph(engine::kind engine_kind, fpmath_mode mode)
Creates a new empty graph with an engine kind and a floating-point math mode.
All partitions returned from the graph will inherit the engine kind and floating-point math mode.
Setting the floating-point math mode enables automatic down-conversion of inputs for the given graph, promoting speedup by using lower-precision data types when available.
Parameters:
engine_kind |
Engine kind. |
mode |
Floating-point math mode. |
Methods¶
void set_fpmath_mode(fpmath_mode mode, bool apply_to_int = false)
Set the floating point math mode for a graph.
Users can enforce the graph to comply with the mode by specifying a boolean flag with the setter function.
Parameters:
mode |
The floating-point math mode. |
apply_to_int |
The flag that controls whether to use floating-point arithmetic for integral operations. |
void get_fpmath_mode(fpmath_mode& mode, bool& apply_to_int) const
Get the floating point math mode and the boolean flag that specifies whether the graph will be enforced to comply the mode.
Parameters:
mode |
The floating-point math mode. |
apply_to_int |
The flag that controls whether to use floating-point arithmetic for integral operations. |
status add_op(const op& op, bool allow_exception = true)
Adds an op into the graph to construct a computational DAG.
The API will return failure if the operator has already been added to the graph or the operation cannot pass the schema check in the library (eg. input and output numbers and data types, the attributes of the operation, etc.).
Parameters:
op |
An operation to be added. |
allow_exception |
A flag indicating whether the method is allowed to throw an exception if it fails to add the op to the graph. |
Returns:
status::success or a status describing the error otherwise.
void finalize()
Finalizes a graph.
It means users have finished adding operations into the graph and the graph is ready for partitioning. Adding a new operation into a finalized graph will return failures. Similarly, partitioning on a un-finalized graph will also return failures.
bool is_finalized() const
Checks if a graph is finalized.
Returns:
True if the graph is finalized or false if the graph is not finalized.
std::vector<partition> get_partitions(partition::policy policy = partition::policy::fusion)
Gets filtered partitions from a graph.
Partitions will be claimed internally according to the capability of the library, the engine kind of the graph, and the policy.
Parameters:
policy |
Partition policy, defaults to policy dnnl::graph::partition::policy::fusion. |
Returns:
A vector storing the partitions.