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
Show file tree
Hide file tree
Changes from 2 commits
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
34 changes: 20 additions & 14 deletions csrc/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -990,32 +990,38 @@ 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;
for (int i = 0; i < exponent; ++i) {
if (i != 0) {
code_ << " * ";
}
code_ << lhs;
}
} else {
indent() << gen(bop->out());
if (bop->out()->isScalar()) {
code_ << " = " << lhs << " * " << lhs;
if (exponent == 3) {
code_ << " * " << lhs;
for (int i = 0; i < exponent; ++i) {
if (i == 0) {
code_ << " = " << lhs;
} else {
code_ << " * " << lhs;
}
}
} else {
code_ << "\n";
indent() << kTab << "= " << lhs << "\n";
indent() << kTab << "* " << lhs;
if (exponent == 3) {
code_ << "\n";
indent() << kTab << "* " << lhs;
for (int i = 0; i < exponent; ++i) {
if (i == 0) {
code_ << "\n";
indent() << kTab << "= " << lhs;
} else {
indent() << "\n" << kTab << "* " << lhs;
}
}
}
}
Expand Down
59 changes: 59 additions & 0 deletions tests/cpp/test_gpu3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9413,6 +9413,65 @@ TEST_F(NVFuserTest, RegisteredExactMappingWithExtentReplacment) {
}
}


TEST_F(NVFuserTest, RegisteredExactMappingWithExtentReplacment) {
Fusion fusion;
FusionGuard fg(&fusion);

auto tv0 = makeConcreteTensor({16, 32});
fusion.addInput(tv0);
auto tv1 = makeSymbolicTensor(2);
fusion.addInput(tv1);
auto tv2 = makeSymbolicTensor(1);
fusion.addInput(tv2);

auto tv3 = set(tv2);
auto tv4 = broadcast(tv3, {false, true});
auto tv5 = add(tv1, tv4);
auto tv6 = add(tv0, tv5);
fusion.addOutput(tv6);

// Make the loop domains of tv3 and tv4 exact mapped with tv1's loop
// domain
scheduler_tools::scheduleLoopDomainsLike({tv3, tv4}, tv1->getLoopDomain());

EXPECT_TRUE(fusion.hasRegisteredExactMappings());

// tv3 and tv4 should have new cloned IDs that are exact mapped with
// tv1
auto registered_mappings = fusion.registeredExactMappings();
auto registered_mappings_it = registered_mappings.find(tv3->axis(1));
EXPECT_NE(registered_mappings_it, registered_mappings.end());
const auto& registered_ids = registered_mappings_it->second;
EXPECT_TRUE(registered_ids->has(tv4->axis(1)));
EXPECT_TRUE(registered_ids->has(tv1->axis(1)));

{
IdModel id_model(&fusion, /*build_graphs=*/false);
const auto& exact_graph = id_model.buildExactGraph();
for (auto tv : {tv3, tv4}) {
EXPECT_EQ(
exact_graph.toGroups(tv->getLoopDomain()),
exact_graph.toGroups(tv1->getLoopDomain()));
}
}

// tv0 and tv1 are exact mapped. Since tv0 has static extents,
// replaceSymbolicSizes will replace the symbolic extents of tv1 and tv2
// with the static extents of tv0.
replaceSymbolicSizes(&fusion);

// Check if the exact mapping is still alive
{
IdModel id_model(&fusion, /*build_graphs=*/false);
const auto& exact_graph = id_model.buildExactGraph();
for (auto tv : {tv3, tv4}) {
EXPECT_EQ(
exact_graph.toGroups(tv->getLoopDomain()),
exact_graph.toGroups(tv1->getLoopDomain()));
}
}
}
// Test file size should be up to 10K LoC. Create a new file for more tests.

} // namespace nvfuser
Loading