-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: liurenjie1024 <[email protected]>
- Loading branch information
1 parent
2aa3348
commit 3164564
Showing
12 changed files
with
1,286 additions
and
7 deletions.
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
67 changes: 67 additions & 0 deletions
67
src/main/java/com/nvidia/spark/rapids/jni/kudo/ColumnOffsetInfo.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,67 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package com.nvidia.spark.rapids.jni.kudo; | ||
|
||
import java.util.OptionalLong; | ||
|
||
import static com.nvidia.spark.rapids.jni.Preconditions.ensure; | ||
import static com.nvidia.spark.rapids.jni.Preconditions.ensureNonNegative; | ||
|
||
/** | ||
* This class is used to store the offsets of the buffer of a column in the serialized data. | ||
*/ | ||
class ColumnOffsetInfo { | ||
private static final long INVALID_OFFSET = -1L; | ||
private final long validity; | ||
private final long offset; | ||
private final long data; | ||
private final long dataLen; | ||
|
||
public ColumnOffsetInfo(long validity, long offset, long data, long dataLen) { | ||
ensure(dataLen >= 0, () -> "dataLen must be non-negative, but was " + dataLen); | ||
this.validity = validity; | ||
this.offset = offset; | ||
this.data = data; | ||
this.dataLen = dataLen; | ||
} | ||
|
||
public OptionalLong getValidity() { | ||
return (validity == INVALID_OFFSET) ? OptionalLong.empty() : OptionalLong.of(validity); | ||
} | ||
|
||
public OptionalLong getOffset() { | ||
return (offset == INVALID_OFFSET) ? OptionalLong.empty() : OptionalLong.of(offset); | ||
} | ||
|
||
public OptionalLong getData() { | ||
return (data == INVALID_OFFSET) ? OptionalLong.empty() : OptionalLong.of(data); | ||
} | ||
|
||
public long getDataLen() { | ||
return dataLen; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ColumnOffsets{" + | ||
"validity=" + validity + | ||
", offset=" + offset + | ||
", data=" + data + | ||
", dataLen=" + dataLen + | ||
'}'; | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
src/main/java/com/nvidia/spark/rapids/jni/kudo/ColumnViewInfo.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,74 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package com.nvidia.spark.rapids.jni.kudo; | ||
|
||
import ai.rapids.cudf.ColumnView; | ||
import ai.rapids.cudf.DType; | ||
import ai.rapids.cudf.DeviceMemoryBuffer; | ||
|
||
import static java.lang.Math.toIntExact; | ||
|
||
class ColumnViewInfo { | ||
private final DType dtype; | ||
private final ColumnOffsetInfo offsetInfo; | ||
private final long nullCount; | ||
private final long rowCount; | ||
|
||
public ColumnViewInfo(DType dtype, ColumnOffsetInfo offsetInfo, | ||
long nullCount, long rowCount) { | ||
this.dtype = dtype; | ||
this.offsetInfo = offsetInfo; | ||
this.nullCount = nullCount; | ||
this.rowCount = rowCount; | ||
} | ||
|
||
public long buildColumnView(DeviceMemoryBuffer buffer, long[] childrenView) { | ||
long bufferAddress = buffer.getAddress(); | ||
|
||
long dataAddress = 0; | ||
if (offsetInfo.getData().isPresent()) { | ||
dataAddress = buffer.getAddress() + offsetInfo.getData().getAsLong(); | ||
} | ||
|
||
long validityAddress = 0; | ||
if (offsetInfo.getValidity().isPresent()) { | ||
validityAddress = offsetInfo.getValidity().getAsLong() + bufferAddress; | ||
} | ||
|
||
long offsetsAddress = 0; | ||
if (offsetInfo.getOffset().isPresent()) { | ||
offsetsAddress = offsetInfo.getOffset().getAsLong() + bufferAddress; | ||
} | ||
|
||
return ColumnView.makeCudfColumnView( | ||
dtype.getTypeId().getNativeId(), dtype.getScale(), | ||
dataAddress, offsetInfo.getDataLen(), | ||
offsetsAddress, validityAddress, | ||
toIntExact(nullCount), toIntExact(rowCount), | ||
childrenView); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ColumnViewInfo{" + | ||
"dtype=" + dtype + | ||
", offsetInfo=" + offsetInfo + | ||
", nullCount=" + nullCount + | ||
", rowCount=" + rowCount + | ||
'}'; | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
src/main/java/com/nvidia/spark/rapids/jni/kudo/KudoHostMergeResult.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,75 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package com.nvidia.spark.rapids.jni.kudo; | ||
|
||
import ai.rapids.cudf.*; | ||
import com.nvidia.spark.rapids.jni.Arms; | ||
import com.nvidia.spark.rapids.jni.schema.Visitors; | ||
|
||
import java.util.List; | ||
|
||
import static com.nvidia.spark.rapids.jni.Preconditions.ensure; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
/** | ||
* The result of merging several kudo tables into one contiguous table on the host. | ||
*/ | ||
public class KudoHostMergeResult implements AutoCloseable { | ||
private final Schema schema; | ||
private final List<ColumnViewInfo> columnInfoList; | ||
private final HostMemoryBuffer hostBuf; | ||
|
||
KudoHostMergeResult(Schema schema, HostMemoryBuffer hostBuf, List<ColumnViewInfo> columnInfoList) { | ||
requireNonNull(schema, "schema is null"); | ||
requireNonNull(columnInfoList, "columnOffsets is null"); | ||
ensure(schema.getFlattenedColumnNames().length == columnInfoList.size(), () -> | ||
"Column offsets size does not match flattened schema size, column offsets size: " + columnInfoList.size() + | ||
", flattened schema size: " + schema.getFlattenedColumnNames().length); | ||
this.schema = schema; | ||
this.columnInfoList = columnInfoList; | ||
this.hostBuf = requireNonNull(hostBuf, "hostBuf is null") ; | ||
} | ||
|
||
@Override | ||
public void close() throws Exception { | ||
if (hostBuf != null) { | ||
hostBuf.close(); | ||
} | ||
} | ||
|
||
public ContiguousTable toContiguousTable() { | ||
return Arms.closeIfException(DeviceMemoryBuffer.allocate(hostBuf.getLength()), | ||
deviceMemBuf -> { | ||
if (hostBuf.getLength() > 0) { | ||
deviceMemBuf.copyFromHostBuffer(hostBuf); | ||
} | ||
|
||
TableBuilder builder = new TableBuilder(columnInfoList, deviceMemBuf); | ||
Table t = Visitors.visitSchema(schema, builder); | ||
|
||
return new ContiguousTable(t, deviceMemBuf); | ||
}); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "HostMergeResult{" + | ||
"columnOffsets=" + columnInfoList + | ||
", hostBuf length =" + hostBuf.getLength() + | ||
'}'; | ||
} | ||
} |
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.