.. index:: pair: class; dnnl::graph::graph .. _doxid-classdnnl_1_1graph_1_1graph: class dnnl::graph::graph ======================== .. toctree:: :hidden: Overview ~~~~~~~~ A graph object. :ref:`More...` .. ref-code-block:: cpp :class: doxyrest-overview-code-block #include class graph: public graph_handle { public: // construction :ref:`graph`(:ref:`engine::kind` engine_kind); :ref:`graph`(:ref:`engine::kind` engine_kind, :ref:`fpmath_mode` mode); // methods void :ref:`set_fpmath_mode`(:ref:`fpmath_mode` mode, bool apply_to_int = false); void :ref:`get_fpmath_mode`(:ref:`fpmath_mode`& mode, bool& apply_to_int) const; :ref:`status` :ref:`add_op`(const :ref:`op`& op, bool allow_exception = true); void :ref:`finalize`(); bool :ref:`is_finalized`() const; std::vector<:ref:`partition`> :ref:`get_partitions`(:ref:`partition::policy` policy = :ref:`partition::policy::fusion`); }; .. _details-classdnnl_1_1graph_1_1graph: Detailed Documentation ~~~~~~~~~~~~~~~~~~~~~~ A graph object. Construction ------------ .. index:: pair: function; graph .. _doxid-classdnnl_1_1graph_1_1graph_1ab9989b31612c971d723b21bce61f3812: .. ref-code-block:: cpp :class: doxyrest-title-code-block graph(:ref:`engine::kind` engine_kind) Constructs a graph with an engine kind. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - engine_kind - Engine kind. .. index:: pair: function; graph .. _doxid-classdnnl_1_1graph_1_1graph_1af26fca906c40d577ae129c635bc08039: .. ref-code-block:: cpp :class: doxyrest-title-code-block graph(:ref:`engine::kind` engine_kind, :ref:`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. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - engine_kind - Engine kind. * - mode - Floating-point math mode. Methods ------- .. index:: pair: function; set_fpmath_mode .. _doxid-classdnnl_1_1graph_1_1graph_1a19c83436928ccc4ef523e2f149a390f7: .. ref-code-block:: cpp :class: doxyrest-title-code-block void set_fpmath_mode(:ref:`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. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - mode - The floating-point math mode. * - apply_to_int - The flag that controls whether to use floating-point arithmetic for integral operations. .. index:: pair: function; get_fpmath_mode .. _doxid-classdnnl_1_1graph_1_1graph_1aa6906acb139b0d7dc59234ae22249a59: .. ref-code-block:: cpp :class: doxyrest-title-code-block void get_fpmath_mode(:ref:`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. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - mode - The floating-point math mode. * - apply_to_int - The flag that controls whether to use floating-point arithmetic for integral operations. .. index:: pair: function; add_op .. _doxid-classdnnl_1_1graph_1_1graph_1a1cdf41276f953ecc482df858408c9ff0: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`status` add_op(const :ref:`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.). .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - 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. .. rubric:: Returns: :ref:`status::success ` or a status describing the error otherwise. .. index:: pair: function; finalize .. _doxid-classdnnl_1_1graph_1_1graph_1a4454e3093a112022cd607c4c3cc66ee2: .. ref-code-block:: cpp :class: doxyrest-title-code-block 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. .. index:: pair: function; is_finalized .. _doxid-classdnnl_1_1graph_1_1graph_1ac92aaf7475714f78ed18327a9f9210bf: .. ref-code-block:: cpp :class: doxyrest-title-code-block bool is_finalized() const Checks if a graph is finalized. .. rubric:: Returns: True if the graph is finalized or false if the graph is not finalized. .. index:: pair: function; get_partitions .. _doxid-classdnnl_1_1graph_1_1graph_1a116d3552e3b0e6c739a1564329bde014: .. ref-code-block:: cpp :class: doxyrest-title-code-block std::vector<:ref:`partition`> get_partitions(:ref:`partition::policy` policy = :ref:`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. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - policy - Partition policy, defaults to policy :ref:`dnnl::graph::partition::policy::fusion `. .. rubric:: Returns: A vector storing the partitions.