ONE - On-device Neural Engine
Loading...
Searching...
No Matches
loco::CanonicalShapeInferenceRule Struct Referencefinal

Shape inference rule for canonical dialect. More...

#include <CanonicalShapeInferenceRule.h>

Collaboration diagram for loco::CanonicalShapeInferenceRule:

Public Member Functions

bool support (const API &ver) const final
 Check whether a given API is available or not.
 
bool recognize (const Dialect *) const final
 Return true if this rule recognizes a given dialect.
 
bool infer (const Node *, NodeShape &) const final
 Infer node's shape.
 
void infer (const Context *, const Node *, Sink *) const final
 
- Public Member Functions inherited from loco::ShapeInferenceRule
virtual ~ShapeInferenceRule ()=default
 

Additional Inherited Members

- Public Types inherited from loco::ShapeInferenceRule
enum class  API { V1 , V2 }
 

Detailed Description

Shape inference rule for canonical dialect.

Definition at line 28 of file CanonicalShapeInferenceRule.h.

Member Function Documentation

◆ infer() [1/2]

void loco::CanonicalShapeInferenceRule::infer ( const Context ctx,
const Node node,
Sink sink 
) const
finalvirtual

Reimplemented from loco::ShapeInferenceRule.

Definition at line 763 of file CanonicalShapeInferenceRule.cpp.

764{
765 assert(node->dialect() == loco::CanonicalDialect::get());
766 assert(dynamic_cast<const loco::CanonicalNode *>(node) != nullptr);
767
768 ForwardShapeInferenceAlgorithm alg{ctx};
769 auto shape = loco::must_cast<const loco::CanonicalNode *>(node)->accept(&alg);
770
771 sink->okay(shape);
772}
static Dialect * get(void)

References loco::Node::dialect(), and loco::CanonicalDialect::get().

◆ infer() [2/2]

bool loco::CanonicalShapeInferenceRule::infer ( const Node ,
NodeShape  
) const
finalvirtual

Infer node's shape.

WARNING!!

Implementation SHOULD return true only when it succeeds in inference!

Implements loco::ShapeInferenceRule.

Definition at line 745 of file CanonicalShapeInferenceRule.cpp.

746{
747 ::compat::Context ctx;
748 ::compat::Sink sink;
749
750 infer(&ctx, node, &sink);
751
752 assert(sink.status() == ::compat::Sink::Okay or sink.status() == ::compat::Sink::Fail);
753
754 if (sink.status() == ::compat::Sink::Fail)
755 {
756 return false;
757 }
758
759 shape = sink.shape();
760 return true;
761}
Definition infer.py:1

◆ recognize()

bool loco::CanonicalShapeInferenceRule::recognize ( const Dialect ) const
finalvirtual

Return true if this rule recognizes a given dialect.

Implements loco::ShapeInferenceRule.

Definition at line 740 of file CanonicalShapeInferenceRule.cpp.

741{
742 return CanonicalDialect::get() == d;
743}

References loco::CanonicalDialect::get().

◆ support()

bool loco::CanonicalShapeInferenceRule::support ( const API api) const
finalvirtual

Check whether a given API is available or not.

Reimplemented from loco::ShapeInferenceRule.

Definition at line 735 of file CanonicalShapeInferenceRule.cpp.

References loco::ShapeInferenceRule::V1, and loco::ShapeInferenceRule::V2.


The documentation for this struct was generated from the following files: