Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ case class BroadcastHashJoinExecTransformer(
} else {
logInfo(s"Using executor-side broadcast hash table build for $buildBroadcastTableId")
}
VeloxBroadcastBuildSideRDD(sparkContext, broadcast, context)
VeloxBroadcastBuildSideRDD(sparkContext, broadcast, context, cudfEnabled = offloadCuda)

case unsafe: UnsafeColumnarBuildSideRelation =>
joinParamsForMetrics.foreach(_.usesDriverSideSerializedHashTable = false)
Expand All @@ -235,15 +235,15 @@ case class BroadcastHashJoinExecTransformer(
} else {
logInfo(s"Using executor-side broadcast hash table build for $buildBroadcastTableId")
}
VeloxBroadcastBuildSideRDD(sparkContext, broadcast, context)
VeloxBroadcastBuildSideRDD(sparkContext, broadcast, context, cudfEnabled = offloadCuda)

case other =>
joinParamsForMetrics.foreach(_.usesDriverSideSerializedHashTable = false)
// Fallback for unknown types
logWarning(
s"Unknown broadcast relation type: ${other.getClass.getName}, " +
"using executor-side build")
VeloxBroadcastBuildSideRDD(sparkContext, broadcast, context)
VeloxBroadcastBuildSideRDD(sparkContext, broadcast, context, cudfEnabled = offloadCuda)
}

// FIXME: Do we have to make build side a RDD?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ case class VeloxBroadcastBuildSideRDD(
@transient private val sc: SparkContext,
broadcasted: broadcast.Broadcast[BuildSideRelation],
broadcastContext: BroadcastHashJoinContext,
isBNL: Boolean = false)
isBNL: Boolean = false,
cudfEnabled: Boolean = false)
extends BroadcastBuildSideRDD(sc, broadcasted) {

override def genBroadcastBuildSideIterator(): Iterator[ColumnarBatch] = {
Expand All @@ -48,8 +49,17 @@ case class VeloxBroadcastBuildSideRDD(
// reusable table and a CPU-fallback join builds from this stream as usual.
val output = if (isBNL || !offload || GlutenConfig.get.enableColumnarCudf) {
val relation = broadcasted.value.asReadOnlyCopy()
// cudfEnabled is the consuming stage's own tag (TransformSupport#offloadCuda).
val batches = relation match {
case columnar: ColumnarBuildSideRelation =>
columnar.deserialized(cudfEnabled)
case unsafe: UnsafeColumnarBuildSideRelation =>
unsafe.deserialized(cudfEnabled)
case other =>
other.deserialized
}
Iterators
.wrap(relation.deserialized)
.wrap(batches)
.recyclePayload(batch => batch.close())
.create()
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ case class VeloxBroadcastNestedLoopJoinExecTransformer(
override def columnarInputRDDs: Seq[RDD[ColumnarBatch]] = {
val streamedRDD = getColumnarInputRDDs(streamedPlan)
val broadcast = buildPlan.executeBroadcast[BuildSideRelation]()
val broadcastRDD = VeloxBroadcastBuildSideRDD(sparkContext, broadcast, null, true)
val broadcastRDD =
VeloxBroadcastBuildSideRDD(
sparkContext,
broadcast,
null,
isBNL = true,
cudfEnabled = offloadCuda)
// FIXME: Do we have to make build side a RDD?
streamedRDD :+ broadcastRDD
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package org.apache.spark.sql.execution

import org.apache.gluten.backendsapi.BackendsApiManager
import org.apache.gluten.columnarbatch.ColumnarBatches
import org.apache.gluten.config.GlutenConfig
import org.apache.gluten.execution.BroadcastHashJoinContext
import org.apache.gluten.expression.ConverterUtils
import org.apache.gluten.iterator.Iterators
Expand All @@ -40,6 +41,8 @@ import org.apache.spark.util.KnownSizeEstimation

import org.apache.arrow.c.ArrowSchema

import java.util.Collections

import scala.collection.JavaConverters._
import scala.collection.JavaConverters.asScalaIteratorConverter
import scala.collection.mutable.{ArrayBuffer, Map}
Expand Down Expand Up @@ -110,9 +113,20 @@ case class ColumnarBuildSideRelation(
}
}

override def deserialized: Iterator[ColumnarBatch] = {
/** Host-resident deserialization, for CPU consumers. */
override def deserialized: Iterator[ColumnarBatch] = deserialized(cudfEnabled = false)

/**
* Residency follows the consuming stage: a cuDF-offloaded stage sources from CudfValueStream and
* needs device batches, a non-offloaded stage from RowVectorStream and needs host batches.
*/
def deserialized(cudfEnabled: Boolean): Iterator[ColumnarBatch] = {
val runtime =
Runtimes.contextInstance(BackendsApiManager.getBackendName, "BuildSideRelation#deserialized")
Runtimes.contextInstance(
BackendsApiManager.getBackendName,
"BuildSideRelation#deserialized",
Collections.singletonMap(GlutenConfig.COLUMNAR_CUDF_ENABLED.key, cudfEnabled.toString)
)
val jniWrapper = ColumnarBatchSerializerJniWrapper.create(runtime)
val serializeHandle: Long = {
val allocator = ArrowBufferAllocators.contextInstance()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package org.apache.spark.sql.execution.unsafe

import org.apache.gluten.backendsapi.BackendsApiManager
import org.apache.gluten.columnarbatch.ColumnarBatches
import org.apache.gluten.config.GlutenConfig
import org.apache.gluten.execution.BroadcastHashJoinContext
import org.apache.gluten.expression.ConverterUtils
import org.apache.gluten.iterator.Iterators
Expand Down Expand Up @@ -45,6 +46,7 @@ import com.esotericsoftware.kryo.io.{Input, Output}
import org.apache.arrow.c.ArrowSchema

import java.io.{Externalizable, ObjectInput, ObjectOutput}
import java.util.Collections

import scala.collection.JavaConverters._
import scala.collection.JavaConverters.asScalaIteratorConverter
Expand Down Expand Up @@ -372,11 +374,20 @@ class UnsafeColumnarBuildSideRelation(
}
}

override def deserialized: Iterator[ColumnarBatch] = {
/** Host-resident deserialization, for CPU consumers. */
override def deserialized: Iterator[ColumnarBatch] = deserialized(cudfEnabled = false)

/**
* Residency follows the consuming stage: a cuDF-offloaded stage sources from CudfValueStream and
* needs device batches, a non-offloaded stage from RowVectorStream and needs host batches.
*/
def deserialized(cudfEnabled: Boolean): Iterator[ColumnarBatch] = {
val runtime =
Runtimes.contextInstance(
BackendsApiManager.getBackendName,
"UnsafeBuildSideRelation#deserialize")
"UnsafeBuildSideRelation#deserialize",
Collections.singletonMap(GlutenConfig.COLUMNAR_CUDF_ENABLED.key, cudfEnabled.toString)
)
val jniWrapper = ColumnarBatchSerializerJniWrapper.create(runtime)
val serializerHandle: Long = {
val allocator = ArrowBufferAllocators.contextInstance()
Expand Down