Skip to content

Conversation

@wrongtest-intellif
Copy link
Contributor

This PR add two helper class for tir expression pattern match.

  • PVarWithType works same as PVar with dtype match
  • PVecType represent a wildcard vec type placeholder same as PVar<DataType>, but with element dtype match
PVecType vec_ph(DataType::Float(32));
PVarWithType<PrimExpr, arith::PVecType> pat(vec_ph);
if (pat.Match(expr)) { ... }

// equaivalent to
PVar<PrimExpr> pat;
if (pat.Match(expr)) {
   PrimExpr x = pat.Eval();
   if (x->dtype == DataType::Float(32)) { ... }
}

@junrushao
Copy link
Member

CC @spectrometerHBH @tqchen @Hzfengsy would you guys review this patch?

Copy link
Member

@tqchen tqchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall LGTM, two minor comments on naming. Thanks @wrongtest

*/
template <typename T, typename DType,
typename = std::enable_if<std::is_base_of<T, PrimExpr>::value>>
class PVarWithType : public PVarWithCheck<PVarWithType<T, DType>, T> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great to rename to PVarWithDataType

/*!
* \brief Pattern variable container for data type with lanes.
*/
class PVecType : public PVarWithCheck<PVecType, DataType> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PVecDataType

@tqchen tqchen merged commit b2d80ce into apache:main Sep 19, 2021
@tqchen
Copy link
Member

tqchen commented Sep 19, 2021

Thanks @wrongtest ! This PR is now merged

AndrewZhaoLuo added a commit to AndrewZhaoLuo/tvm that referenced this pull request Sep 20, 2021
* main:
  [3/10] Moved TIR generation from Python to C++ for CMSIS-NN (apache#8951)
  Support match pvar with dtype constraint (apache#9016)
ylc pushed a commit to ylc/tvm that referenced this pull request Sep 29, 2021
ylc pushed a commit to ylc/tvm that referenced this pull request Jan 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants