-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Introduce kudo writer Signed-off-by: liurenjie1024 <[email protected]>
- Loading branch information
1 parent
4f904c0
commit 2aa3348
Showing
12 changed files
with
1,317 additions
and
5 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
61 changes: 61 additions & 0 deletions
61
src/main/java/com/nvidia/spark/rapids/jni/kudo/DataOutputStreamWriter.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,61 @@ | ||
/* | ||
* 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.HostMemoryBuffer; | ||
|
||
import java.io.DataOutputStream; | ||
import java.io.IOException; | ||
|
||
/** | ||
* Visible for testing | ||
*/ | ||
class DataOutputStreamWriter extends DataWriter { | ||
private final byte[] arrayBuffer = new byte[1024 * 128]; | ||
private final DataOutputStream dout; | ||
|
||
public DataOutputStreamWriter(DataOutputStream dout) { | ||
this.dout = dout; | ||
} | ||
|
||
@Override | ||
public void writeInt(int i) throws IOException { | ||
dout.writeInt(i); | ||
} | ||
|
||
@Override | ||
public void copyDataFrom(HostMemoryBuffer src, long srcOffset, long len) throws IOException { | ||
long dataLeft = len; | ||
while (dataLeft > 0) { | ||
int amountToCopy = (int) Math.min(arrayBuffer.length, dataLeft); | ||
src.getBytes(arrayBuffer, 0, srcOffset, amountToCopy); | ||
dout.write(arrayBuffer, 0, amountToCopy); | ||
srcOffset += amountToCopy; | ||
dataLeft -= amountToCopy; | ||
} | ||
} | ||
|
||
@Override | ||
public void flush() throws IOException { | ||
dout.flush(); | ||
} | ||
|
||
@Override | ||
public void write(byte[] arr, int offset, int length) throws IOException { | ||
dout.write(arr, offset, length); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/com/nvidia/spark/rapids/jni/kudo/DataWriter.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,44 @@ | ||
/* | ||
* 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.HostMemoryBuffer; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Visible for testing | ||
*/ | ||
abstract class DataWriter { | ||
|
||
public abstract void writeInt(int i) throws IOException; | ||
|
||
/** | ||
* Copy data from src starting at srcOffset and going for len bytes. | ||
* | ||
* @param src where to copy from. | ||
* @param srcOffset offset to start at. | ||
* @param len amount to copy. | ||
*/ | ||
public abstract void copyDataFrom(HostMemoryBuffer src, long srcOffset, long len) throws IOException; | ||
|
||
public void flush() throws IOException { | ||
// NOOP by default | ||
} | ||
|
||
public abstract void write(byte[] arr, int offset, int length) throws IOException; | ||
} |
Oops, something went wrong.