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
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions csrc/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -990,32 +990,39 @@ class CudaKernelGenerator : private kir::ConstIrVisitor {
return false;
}

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

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

if (print_inline_) {
code_ << lhs << " * " << lhs;
if (exponent == 3) {
code_ << " * " << lhs;
if (exponent == 1) {
code_ << lhs;
} else if (exponent == 2) {
code_ << lhs << " * " << lhs;
} else if (exponent == 3) {
code_ << lhs << " * " << lhs << " * " << lhs;
}
} else {
indent() << gen(bop->out());
if (bop->out()->isScalar()) {
code_ << " = " << lhs << " * " << lhs;
if (exponent == 3) {
code_ << " * " << lhs;
if (exponent == 1) {
code_ << " = " << lhs;
} else if (exponent == 2) {
code_ << " = " << lhs << " * " << lhs;
} else if (exponent == 3) {
code_ << " = " << lhs << " * " << lhs << " * " << lhs;
}
} else {
code_ << "\n";
indent() << kTab << "= " << lhs << "\n";
indent() << kTab << "* " << lhs;
if (exponent == 3) {
code_ << "\n";
indent() << kTab << "* " << lhs;
if (exponent == 1) {
indent() << kTab << "= " << lhs;
} else if (exponent == 2) {
indent() << kTab << "= " << lhs << "\n * " << lhs;
} else if (exponent == 3) {
indent() << kTab << "= " << lhs << "\n * " << lhs << "\n * " << lhs;
}
}
}
Expand Down