From a73766651556d466b9ae690784f6b1209c237059 Mon Sep 17 00:00:00 2001 From: Jingyue Wu Date: Thu, 16 Nov 2023 15:53:33 -0800 Subject: [PATCH] s/PointerCast/PointerArithmetic. With slices, the pointer address might not be the same. PointerArithmetic is more accurate. --- csrc/executor.cpp | 4 ++-- csrc/fusion.cpp | 6 +++--- csrc/fusion.h | 8 ++++---- csrc/optimization/mark_alias.cpp | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/csrc/executor.cpp b/csrc/executor.cpp index 0724d789e21..17d515cd6f5 100644 --- a/csrc/executor.cpp +++ b/csrc/executor.cpp @@ -945,14 +945,14 @@ at::Tensor allocateOutput( switch (alias_it->second.second.type) { case AliasType::InplaceUpdate: - // Unlike for `AliasType::PointerCast`, don't use + // Unlike for `AliasType::PointerArithmetic`, don't use // ExpressionEvaluator to compute the output tensor. This is because // the output tensor may hold different data from the input, e.g., an // updated running mean. `ExpressionEvaluator::evaluate(out_tv)` // would trigger non-trivial host computation. return in_tensor; - case AliasType::PointerCast: + case AliasType::PointerArithmetic: auto* in_tv = kernel->inputs()[aliased_in_index]->as(); ee.bind(in_tv, in_tensor); at::Tensor out_tensor = ee.evaluate(out_tv).as(); diff --git a/csrc/fusion.cpp b/csrc/fusion.cpp index c90e6a34e3e..5b6f790239c 100644 --- a/csrc/fusion.cpp +++ b/csrc/fusion.cpp @@ -334,14 +334,14 @@ std::vector Fusion::exprs() { namespace { -bool allOutputsArePointerCasts(Fusion* fusion) { +bool allOutputsArePointerArithmetics(Fusion* fusion) { for (Val* out : fusion->outputs()) { const auto& [in, info] = fusion->getOutputAlias(out); if (in == nullptr) { return false; } NVF_ERROR(info != nullptr); - if (info->type != AliasType::PointerCast) { + if (info->type != AliasType::PointerArithmetic) { return false; } } @@ -355,7 +355,7 @@ bool Fusion::isNoOp() { return true; } - if (allOutputsArePointerCasts(this)) { + if (allOutputsArePointerArithmetics(this)) { return true; } diff --git a/csrc/fusion.h b/csrc/fusion.h index b006bd77ffa..9fa7c5cebb2 100644 --- a/csrc/fusion.h +++ b/csrc/fusion.h @@ -90,10 +90,10 @@ enum class AliasType : int { // For example, the tensor storing BatchNorm's running mean. The output EMA is // updated in place. InplaceUpdate, - // For example, the output of a ViewOp is merely a pointer cast of the input. - // In this case, we use `ExpressionEvaluator` (instead of a kernel) to compute - // the output tensor. - PointerCast, + // For example, the output of a ViewOp is merely a pointer arithmetic of the + // input. In this case, we use `ExpressionEvaluator` (instead of a kernel) to + // cheaply compute the output tensor. + PointerArithmetic, }; struct AliasInfo { diff --git a/csrc/optimization/mark_alias.cpp b/csrc/optimization/mark_alias.cpp index 829a930a0cf..a1ad294f82b 100644 --- a/csrc/optimization/mark_alias.cpp +++ b/csrc/optimization/mark_alias.cpp @@ -29,7 +29,7 @@ void MarkAliasPass::runPass(Fusion* fusion) { out, // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast) const_cast(in), - AliasType::PointerCast); + AliasType::PointerArithmetic); if (isDebugDumpEnabled(DebugDumpOption::PreSegmenterLogging)) { debug() << "MarkAliasPass marked " << out->toString() << " as an alias of " << in->toString() << std::endl;