-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize semaphore acquisition in GpuShuffledHashJoinExec (#4588)
* Optimize semaphore acquisition in GpuShuffledHashJoinExec Signed-off-by: Alessandro Bellina <[email protected]> * Update buildTime in the non-optimal case as well * Refactor for ease of understanding and address review concerns * Fix review nit * Remove extra comment * Update for review comments * Add utility to work with rows-only HostConcatResult objects * Apply review suggestions to HostConcatResultUtil and GpuShuffledHashJoinExec * Update copyrights * Revert copyright change * Fix unit tests * Apply review comment * Use arrays with safeMap
- Loading branch information
Showing
9 changed files
with
851 additions
and
161 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
sql-plugin/src/main/scala/ai/rapids/cudf/HostConcatResultUtil.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,57 @@ | ||
/* | ||
* Copyright (c) 2022, 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. | ||
*/ | ||
|
||
package ai.rapids.cudf | ||
|
||
import ai.rapids.cudf.JCudfSerialization.HostConcatResult | ||
import com.nvidia.spark.rapids.{Arm, GpuColumnVectorFromBuffer} | ||
|
||
import org.apache.spark.sql.types.DataType | ||
import org.apache.spark.sql.vectorized.ColumnarBatch | ||
|
||
object HostConcatResultUtil extends Arm { | ||
/** | ||
* Create a rows-only `HostConcatResult`. | ||
*/ | ||
def rowsOnlyHostConcatResult(numRows: Int): HostConcatResult = { | ||
new HostConcatResult( | ||
new JCudfSerialization.SerializedTableHeader( | ||
Array.empty, numRows, 0L), | ||
HostMemoryBuffer.allocate(0, false)) | ||
} | ||
|
||
/** | ||
* Given a `HostConcatResult` and a SparkSchema produce a `ColumnarBatch`, | ||
* handling the rows-only case. | ||
* | ||
* @note This function does not consume the `HostConcatResult`, and | ||
* callers are responsible for closing the resulting `ColumnarBatch` | ||
*/ | ||
def getColumnarBatch( | ||
hostConcatResult: HostConcatResult, | ||
sparkSchema: Array[DataType]): ColumnarBatch = { | ||
if (hostConcatResult.getTableHeader.getNumColumns == 0) { | ||
// We expect the caller to have acquired the GPU unconditionally before calling | ||
// `getColumnarBatch`, as a downstream exec may need the GPU, and the assumption is | ||
// that it is acquired in the coalesce code. | ||
new ColumnarBatch(Array.empty, hostConcatResult.getTableHeader.getNumRows) | ||
} else { | ||
withResource(hostConcatResult.toContiguousTable) { ct => | ||
GpuColumnVectorFromBuffer.from(ct, sparkSchema) | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.