-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GLUTEN-7313][VL] Explicit Arrow transitions, part 4: explicit Arrow-…
…to-Velox transition (#7392)
- Loading branch information
1 parent
3dceeb8
commit 8cb3e70
Showing
30 changed files
with
453 additions
and
305 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
...nds-velox/src/main/java/org/apache/gluten/columnarbatch/VeloxColumnarBatchJniWrapper.java
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,41 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.gluten.columnarbatch; | ||
|
||
import org.apache.gluten.runtime.Runtime; | ||
import org.apache.gluten.runtime.RuntimeAware; | ||
|
||
public class VeloxColumnarBatchJniWrapper implements RuntimeAware { | ||
private final Runtime runtime; | ||
|
||
private VeloxColumnarBatchJniWrapper(Runtime runtime) { | ||
this.runtime = runtime; | ||
} | ||
|
||
public static VeloxColumnarBatchJniWrapper create(Runtime runtime) { | ||
return new VeloxColumnarBatchJniWrapper(runtime); | ||
} | ||
|
||
public native long from(long batch); | ||
|
||
public native long compose(long[] batches); | ||
|
||
@Override | ||
public long rtHandle() { | ||
return runtime.getHandle(); | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
backends-velox/src/main/java/org/apache/gluten/columnarbatch/VeloxColumnarBatches.java
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,85 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.gluten.columnarbatch; | ||
|
||
import org.apache.gluten.runtime.Runtime; | ||
import org.apache.gluten.runtime.Runtimes; | ||
|
||
import com.google.common.base.Preconditions; | ||
import org.apache.spark.sql.vectorized.ColumnarBatch; | ||
import org.apache.spark.sql.vectorized.SparkColumnarBatchUtil; | ||
|
||
import java.util.Arrays; | ||
import java.util.Objects; | ||
|
||
public final class VeloxColumnarBatches { | ||
public static final String COMPREHENSIVE_TYPE_VELOX = "velox"; | ||
|
||
public static void checkVeloxBatch(ColumnarBatch batch) { | ||
final String comprehensiveType = ColumnarBatches.getComprehensiveLightBatchType(batch); | ||
Preconditions.checkArgument( | ||
Objects.equals(comprehensiveType, COMPREHENSIVE_TYPE_VELOX), | ||
String.format( | ||
"Expected comprehensive batch type %s, but got %s", | ||
COMPREHENSIVE_TYPE_VELOX, comprehensiveType)); | ||
} | ||
|
||
public static void checkNonVeloxBatch(ColumnarBatch batch) { | ||
final String comprehensiveType = ColumnarBatches.getComprehensiveLightBatchType(batch); | ||
Preconditions.checkArgument( | ||
!Objects.equals(comprehensiveType, COMPREHENSIVE_TYPE_VELOX), | ||
String.format("Comprehensive batch type is already %s", COMPREHENSIVE_TYPE_VELOX)); | ||
} | ||
|
||
public static ColumnarBatch toVeloxBatch(ColumnarBatch input) { | ||
checkNonVeloxBatch(input); | ||
final Runtime runtime = Runtimes.contextInstance("VeloxColumnarBatches#toVeloxBatch"); | ||
final long handle = ColumnarBatches.getNativeHandle(input); | ||
final long outHandle = VeloxColumnarBatchJniWrapper.create(runtime).from(handle); | ||
final ColumnarBatch output = ColumnarBatches.create(outHandle); | ||
|
||
// Follow input's reference count. This might be optimized using | ||
// automatic clean-up or once the extensibility of ColumnarBatch is enriched | ||
final long refCnt = ColumnarBatches.getRefCntLight(input); | ||
final IndicatorVector giv = (IndicatorVector) output.column(0); | ||
for (long i = 0; i < (refCnt - 1); i++) { | ||
giv.retain(); | ||
} | ||
|
||
// close the input one | ||
for (long i = 0; i < refCnt; i++) { | ||
input.close(); | ||
} | ||
|
||
// Populate new vectors to input. | ||
SparkColumnarBatchUtil.transferVectors(output, input); | ||
|
||
return input; | ||
} | ||
|
||
/** | ||
* Combine multiple columnar batches horizontally, assuming each of them is already offloaded. | ||
* Otherwise {@link UnsupportedOperationException} will be thrown. | ||
*/ | ||
public static ColumnarBatch compose(ColumnarBatch... batches) { | ||
final Runtime runtime = Runtimes.contextInstance("VeloxColumnarBatches#compose"); | ||
final long[] handles = | ||
Arrays.stream(batches).mapToLong(ColumnarBatches::getNativeHandle).toArray(); | ||
final long handle = VeloxColumnarBatchJniWrapper.create(runtime).compose(handles); | ||
return ColumnarBatches.create(handle); | ||
} | ||
} |
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
36 changes: 36 additions & 0 deletions
36
...s-velox/src/main/scala/org/apache/gluten/execution/ArrowColumnarToVeloxColumnarExec.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,36 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.gluten.execution | ||
|
||
import org.apache.gluten.columnarbatch.{VeloxBatch, VeloxColumnarBatches} | ||
import org.apache.gluten.columnarbatch.ArrowBatches.ArrowNativeBatch | ||
|
||
import org.apache.spark.sql.execution.SparkPlan | ||
import org.apache.spark.sql.vectorized.ColumnarBatch | ||
|
||
case class ArrowColumnarToVeloxColumnarExec(override val child: SparkPlan) | ||
extends ColumnarToColumnarExec(ArrowNativeBatch, VeloxBatch) { | ||
override protected def mapIterator(in: Iterator[ColumnarBatch]): Iterator[ColumnarBatch] = { | ||
in.map { | ||
b => | ||
val out = VeloxColumnarBatches.toVeloxBatch(b) | ||
out | ||
} | ||
} | ||
override protected def withNewChildInternal(newChild: SparkPlan): SparkPlan = | ||
ArrowColumnarToVeloxColumnarExec(child = newChild) | ||
} |
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
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
Oops, something went wrong.