Skip to content

Skip compiling fusion segments when using expression evaluator#1930

Merged
Priya2698 merged 27 commits intomainfrom
pm/skip_compilation
Apr 26, 2024
Merged

Skip compiling fusion segments when using expression evaluator#1930
Priya2698 merged 27 commits intomainfrom
pm/skip_compilation

Conversation

@Priya2698
Copy link
Collaborator

@Priya2698 Priya2698 commented Mar 13, 2024

This PR resolves Issue #1812.

  1. Removes the workarounds added to support ATen evaluation for matmuls in PR Matmul default scheduling  #1775 (in predicate_elimination.cpp and validation.cpp (see comments in the PR)
  2. FusionExecutor::fusion_ is initialized only when compilation is skipped. So only one of lowered_ or fusion_ is non-null.
  3. FusionKernelRuntime/FusionExecutorCache/FusionExecutor::isCompiled() indicates whether compilation was attempted (either marked for EE or via nvFuser).

@Priya2698
Copy link
Collaborator Author

!build

1 similar comment
@Priya2698
Copy link
Collaborator Author

!build

@Priya2698 Priya2698 force-pushed the pm/skip_compilation branch 2 times, most recently from bb2b202 to b853b91 Compare April 11, 2024 00:22
@Priya2698
Copy link
Collaborator Author

!build

1 similar comment
@Priya2698
Copy link
Collaborator Author

!build

@Priya2698 Priya2698 force-pushed the pm/skip_compilation branch from 94e037c to 015f0e5 Compare April 19, 2024 21:37
@Priya2698
Copy link
Collaborator Author

!build

1 similar comment
@Priya2698
Copy link
Collaborator Author

!build

@Priya2698 Priya2698 marked this pull request as ready for review April 22, 2024 20:41
@@ -890,9 +890,7 @@ class PredicateChcker : public IterVisitor {
} // namespace

PredicateElimination::PredicateElimination(Fusion* fusion) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was a WAR. Removing now, since we are skipping compilation.

@@ -1030,12 +1030,7 @@ void validateSizeMemoryOp(LoadStoreOp* ldst) {
//! Validate data format and GPU arch compatibility of scheduled
//! mma operators on the fusion.
void validateMma(Fusion* fusion) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was a WAR. Removing now, since we are skipping compilation.

@Priya2698 Priya2698 linked an issue Apr 22, 2024 that may be closed by this pull request

// Each Fusion Executor maps to a lowered and compiled kernel.
table FusionExecutor {
is_compilation_skipped : bool;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this needed? isCompilationSkipped is a method that describes the state of the FusionExecutor. Making it a field in table FusionExecutor seems to suggest it's part of the state itself. cc @rdspring1

Copy link
Collaborator

Choose a reason for hiding this comment

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

It is a way to delineate when we're using the Aten function. Otherwise, we will recompile the fusion to create lowered_ during deserialization.

isCompilationSkipped indicates that we will use an Aten function and the specific fusion is passed to the FusionExecutor in compileFusion. You could separate the first part into a bool field.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry for the delay -- I missed the notification.

I understood how it's used here to avoid unnecessary compilation. However, can we replace that check with a check on the fusion itself instead of introducing yet another flag? If works, this can avoid an additional state that has to be consistent with some existing state of the fusion.

return std::all_of(
executors_.begin(), executors_.end(), [](const auto& executor) {
return executor.isCompiled();
return executor.isCompiled() || executor.isCompilationSkipped();
Copy link
Collaborator

Choose a reason for hiding this comment

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

nitpick: This feels a little bit confusing to me.

i.e. FusionKernelRuntime::isCompiled means something different from FusionExecutor::isCompiled. (similarly we have FusionExecutorCache::isCompiled.

We don't have to do it in this PR, but maybe another renaming PR to clean up the isCompiled vs isCompilationSkipped in FusionExecutor.

Copy link
Collaborator Author

@Priya2698 Priya2698 Apr 22, 2024

Choose a reason for hiding this comment

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

I should rename it to FusionKernelRuntime::isCompiledOrCompilationSkipped.
This function is used to check if compilation was already attempted which is true if either the executors are compiled or compilation was skipped for them.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Any other naming suggestions for this function?

Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. isCompilationSkipped() --- Returns True when we use the Aten function and FusionExecutor is never compiled.
  2. isCompiled() --- Returns False when FusionExecutor has yet to be compiled.

Maybe we should rename isCompilationSkipped() to isAtenExecuted() or isEagerModeExecutor()

Copy link
Collaborator Author

@Priya2698 Priya2698 Apr 23, 2024

Choose a reason for hiding this comment

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

I agree with @rdspring1's suggestion. We can keep isCompiled to denote if compilation was attempted -- either a kernel was compiled or we are using Aten evaluation. Additionally, isCompilationSkipped is renamed to isEagerModeExecutor.

In this naming scheme, isCompiled always means whether or not we attempted to compile a fusion. FusionExecutor::isCompiled which tests for a compiled kernel will need to be renamed though -- maybe isNvfuserExecutor?

Wdyt?

Copy link
Collaborator

Choose a reason for hiding this comment

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

When isEagerModeExecutor is false, we're using the nvfuser executor.

isCompiled implies that we have a cubin for the given fusion. There is an implicit assumption that the nvfuser executor is being used.

I'd consider renaming isCompiled to isCubinCompiled, but leaving it alone is also fine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay, so the renaming is

  1. FusionExecutor::isCompiled -> FusionExecutor::isCubinCompiled
  2. FusionExecutor::isCompilationSkipped -> FusionExecutor::isEagerModeExecutor
  3. FusionKernelRuntime/FusionExecutorCache::isCompiled -> no change. Returns true if either of the above are true indicating that compilation was attempted.

I'll go with this naming if it clears the confusion. @rdspring1 @jjsjann123

Copy link
Collaborator

Choose a reason for hiding this comment

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

sounds very reasonable to me.

@Priya2698 Priya2698 force-pushed the pm/skip_compilation branch from 2ac6cb3 to 409d6c8 Compare April 24, 2024 23:16
@Priya2698
Copy link
Collaborator Author

!build

csrc/executor.h Outdated
}

Fusion* fusion() const {
NVF_ERROR((lowered_ && !fusion_) || (!lowered_ && fusion_));
Copy link
Collaborator

Choose a reason for hiding this comment

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

wasn't this just lowered_ ^ fusion_? An error message would be nice.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, but XOR does not work on these objects.

Copy link
Collaborator

Choose a reason for hiding this comment

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

TIL. explicit operator bool()

Copy link
Collaborator

@jjsjann123 jjsjann123 left a comment

Choose a reason for hiding this comment

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

Thanks for addressing my concerns.

@Priya2698
Copy link
Collaborator Author

!build

@Priya2698 Priya2698 merged commit 8ea9064 into main Apr 26, 2024
@Priya2698 Priya2698 deleted the pm/skip_compilation branch April 26, 2024 16:57

Fusion* fusion() const {
NVF_ERROR(
(lowered_ && !fusion_) || (!lowered_ && fusion_),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's clearer to say

(lowered_ == nullptr) != (fusion_ == nullptr)

which essentially use != to do a logical xor.

int64_t group_id);

//! Check if compilation was skipped (fusion segment marked for EE).
bool isExprEval() const {
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about isExpressionEvaluated for less ambiguity?

preseg_passes::OptimizationPassGuard<preseg_passes::MarkAliasesPreparePass>
optimization_guard(false);

auto fusion_ptr = std::make_unique<Fusion>();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know you didn't add this, but since you are here, do you mind doing a minor, side refactor?

  1. Change this line to
    auto fusion = std::make_unique<Fusion>();
    
  2. Remove the next line says auto& fusion=*fusion_ptr.
  3. Change existing uses of fusion. to fusion->.

The gist is that unique_ptr comes with syntax sugar to make it as if it's a raw pointer. It's not necessary to create another variable just to hold its reference.

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.

Skip compiling fusion segments that are marked for EE

4 participants