Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lower pow(x,1) to x #3774

Merged
merged 4 commits into from
Jan 30, 2025
Merged

lower pow(x,1) to x #3774

merged 4 commits into from
Jan 30, 2025

Conversation

liqiangxl
Copy link
Collaborator

Partially solve #3629

Currently, genPowerWithMul() only handles case with factor of 2 & 3, for y = pow(x, 1.0), it should be lowered to y = x which is much faster than the power version.

@liqiangxl
Copy link
Collaborator Author

!test --pybench

Copy link

github-actions bot commented Jan 28, 2025

PR Reviewer Guide 🔍

(Review updated until commit 0b51ec7)

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
⚡ Recommended focus areas for review

Code Duplication

The new code has duplicated logic for handling different values of exponent. This could be simplified and made more efficient.

  for (int i = 0; i < exponent; ++i) {
    if (i != 0) {
      code_ << " * ";
    }
    code_ << lhs;
  }
} else {
  indent() << gen(bop->out());
  if (bop->out()->isScalar()) {
    for (int i = 0; i < exponent; ++i) {
      if (i == 0) {
        code_ << " = " << lhs;
      } else {
        code_ << " * " << lhs;
      }
    }
  } else {
    for (int i = 0; i < exponent; ++i) {
      if (i == 0) {
        code_ << "\n";
        indent() << kTab << "= " << lhs;
      } else {
        indent() << "\n" << kTab << "* " << lhs;
      }
    }
  }
}
Missing Comments

The new code lacks comments explaining the purpose of the changes and the logic behind them.

// Only **1, **2 and **3 are considered
if (!(exponent == 1 || exponent == 2 || exponent == 3)) {
  return false;
}

auto lhs = gen(bop->lhs());

if (print_inline_) {
  for (int i = 0; i < exponent; ++i) {
    if (i != 0) {
      code_ << " * ";
    }
    code_ << lhs;
  }
} else {
  indent() << gen(bop->out());
  if (bop->out()->isScalar()) {
    for (int i = 0; i < exponent; ++i) {
      if (i == 0) {
        code_ << " = " << lhs;
      } else {
        code_ << " * " << lhs;
      }
    }
  } else {
    for (int i = 0; i < exponent; ++i) {
      if (i == 0) {
        code_ << "\n";
        indent() << kTab << "= " << lhs;
      } else {
        indent() << "\n" << kTab << "* " << lhs;
      }
    }
  }
}

Copy link
Collaborator

@naoyam naoyam left a comment

Choose a reason for hiding this comment

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

Code duplication is a bit concerning. Can't you do some simplification? Something like:

for (int i = 0; i < exponent; ++I) {
  if (i != 0) {
    code_ << " * ";
  }
   code_ << lhs;
}

@liqiangxl
Copy link
Collaborator Author

@Priya2698 do you know how to run thunder benchmark? I didn't find any thunder benchmark results in dashboard generated from this PR using !test --pybench

Copy link
Collaborator

@naoyam naoyam left a comment

Choose a reason for hiding this comment

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

LGTM

@liqiangxl
Copy link
Collaborator Author

!test --pybench --dev

@liqiangxl
Copy link
Collaborator Author

!build

@liqiangxl liqiangxl merged commit 765a165 into main Jan 30, 2025
18 checks passed
@liqiangxl liqiangxl deleted the llu/lower_pow_1 branch January 30, 2025 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants