-
Notifications
You must be signed in to change notification settings - Fork 242
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
Fix aqe_test failures on [databricks] 14.3. #11750
Merged
mythrocks
merged 3 commits into
NVIDIA:branch-24.12
from
mythrocks:databricks-14.3-aqe-dpp
Nov 25, 2024
+171
−102
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
...park330db/scala/org/apache/spark/rapids/execution/GpuSubqueryBroadcastMeta330DBBase.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* Copyright (c) 2024, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/*** spark-rapids-shim-json-lines | ||
{"spark": "330db"} | ||
{"spark": "332db"} | ||
{"spark": "341db"} | ||
{"spark": "350db143"} | ||
{"spark": "400"} | ||
spark-rapids-shim-json-lines ***/ | ||
package org.apache.spark.sql.rapids.execution | ||
|
||
import com.nvidia.spark.rapids.{BaseExprMeta, DataFromReplacementRule, RapidsConf, RapidsMeta, SparkPlanMeta} | ||
|
||
import org.apache.spark.sql.catalyst.expressions.Expression | ||
import org.apache.spark.sql.catalyst.plans.physical.IdentityBroadcastMode | ||
import org.apache.spark.sql.execution.{SparkPlan, SubqueryBroadcastExec} | ||
import org.apache.spark.sql.execution.adaptive.{BroadcastQueryStageExec} | ||
import org.apache.spark.sql.execution.exchange.{BroadcastExchangeExec, ReusedExchangeExec} | ||
import org.apache.spark.sql.execution.joins.HashedRelationBroadcastMode | ||
|
||
abstract class GpuSubqueryBroadcastMeta330DBBase(s: SubqueryBroadcastExec, | ||
conf: RapidsConf, | ||
p: Option[RapidsMeta[_, _, _]], | ||
r: DataFromReplacementRule) extends | ||
SparkPlanMeta[SubqueryBroadcastExec](s, conf, p, r) { | ||
protected var broadcastBuilder: () => SparkPlan = _ | ||
|
||
override val childExprs: Seq[BaseExprMeta[_]] = Nil | ||
|
||
override val childPlans: Seq[SparkPlanMeta[SparkPlan]] = Nil | ||
|
||
override def tagPlanForGpu(): Unit = s.child match { | ||
// DPP: For AQE off, in this case, we handle DPP by converting the underlying | ||
// BroadcastExchangeExec to GpuBroadcastExchangeExec. | ||
// This is slightly different from the Apache Spark case, because Spark | ||
// sends the underlying plan into the plugin in advance via the PlanSubqueries rule. | ||
// Here, we have the full non-GPU subquery plan, so we convert the whole | ||
// thing. | ||
case ex @ BroadcastExchangeExec(_, child) => | ||
val exMeta = new GpuBroadcastMeta(ex.copy(child = child), conf, p, r) | ||
exMeta.tagForGpu() | ||
if (exMeta.canThisBeReplaced) { | ||
broadcastBuilder = () => exMeta.convertToGpu() | ||
} else { | ||
willNotWorkOnGpu("underlying BroadcastExchange can not run in the GPU.") | ||
} | ||
// DPP: For AQE on, we have an almost completely different scenario then before, | ||
// Databricks uses a BroadcastQueryStageExec and either: | ||
// 1) provide an underlying BroadcastExchangeExec that we will have to convert | ||
// somehow | ||
// 2) might already do the reuse work for us. The ReusedExchange is now a | ||
// part of the SubqueryBroadcast, so we send it back here as underlying the | ||
// GpuSubqueryBroadcastExchangeExec | ||
case bqse: BroadcastQueryStageExec => | ||
bqse.plan match { | ||
case ex: BroadcastExchangeExec => | ||
val exMeta = new GpuBroadcastMeta(ex, conf, p, r) | ||
exMeta.tagForGpu() | ||
if (exMeta.canThisBeReplaced) { | ||
broadcastBuilder = () => exMeta.convertToGpu() | ||
} else { | ||
willNotWorkOnGpu("underlying BroadcastExchange can not run in the GPU.") | ||
} | ||
case reuse: ReusedExchangeExec => | ||
reuse.child match { | ||
case _: GpuBroadcastExchangeExec => | ||
// A BroadcastExchange has already been replaced, so it can run on the GPU | ||
broadcastBuilder = () => reuse | ||
case _ => | ||
willNotWorkOnGpu("underlying BroadcastExchange can not run in the GPU.") | ||
} | ||
} | ||
case _ => | ||
willNotWorkOnGpu("the subquery to broadcast can not entirely run in the GPU.") | ||
} | ||
/** | ||
* Simply returns the original plan. Because its only child, BroadcastExchange, doesn't | ||
* need to change if SubqueryBroadcastExec falls back to the CPU. | ||
*/ | ||
override def convertToCpu(): SparkPlan = s | ||
|
||
/** Extract the broadcast mode key expressions if there are any. */ | ||
protected def getBroadcastModeKeyExprs: Option[Seq[Expression]] = { | ||
val broadcastMode = s.child match { | ||
case b: BroadcastExchangeExec => | ||
b.mode | ||
case bqse: BroadcastQueryStageExec => | ||
bqse.plan match { | ||
case b: BroadcastExchangeExec => | ||
b.mode | ||
case reuse: ReusedExchangeExec => | ||
reuse.child match { | ||
case g: GpuBroadcastExchangeExec => | ||
g.mode | ||
} | ||
case _ => | ||
throw new AssertionError("should not reach here") | ||
} | ||
} | ||
|
||
broadcastMode match { | ||
case HashedRelationBroadcastMode(keys, _) => Some(keys) | ||
case IdentityBroadcastMode => None | ||
case m => throw new UnsupportedOperationException(s"Unknown broadcast mode $m") | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does a collect limit show up in these queries? This scares me a bit because CollectLimitExec implies a non-deterministic result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure. DB-14.3 seems to be inserting this into the plan, albeit with a large collection limit:
I don't think it's
spark-rapids
inserting this, but I'm checking.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The above is for the query:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a really interesting optimization. Can you file an issue for us to explore this more closely. It looks like they are doing dynamic pruning. Not sure why they insert in the CollectLimit. We might want to be a bit smarter about how we are dealing with that operator in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've filed #11764 to explore this further.