public class HostMemoryBuffer extends MemoryBuffer
MemoryBuffer.EventHandler, MemoryBuffer.MemoryBufferCleaner| Modifier and Type | Method and Description |
|---|---|
static HostMemoryBuffer |
allocate(long bytes)
Allocate memory, but be sure to close the returned buffer to avoid memory leaks.
|
static HostMemoryBuffer |
allocate(long bytes,
boolean preferPinned)
Allocate memory, but be sure to close the returned buffer to avoid memory leaks.
|
ByteBuffer |
asByteBuffer()
Return a ByteBuffer that provides access to the underlying memory.
|
ByteBuffer |
asByteBuffer(long offset,
int length)
Return a ByteBuffer that provides access to the underlying memory.
|
void |
copyFromDeviceBuffer(BaseDeviceMemoryBuffer deviceMemoryBuffer)
Synchronously copy from a DeviceMemoryBuffer to a HostMemoryBuffer
|
void |
copyFromDeviceBuffer(BaseDeviceMemoryBuffer deviceMemoryBuffer,
Cuda.Stream stream)
Copy from a DeviceMemoryBuffer to a HostMemoryBuffer using the specified stream.
|
void |
copyFromDeviceBufferAsync(BaseDeviceMemoryBuffer deviceMemoryBuffer,
Cuda.Stream stream)
Copy from a DeviceMemoryBuffer to a HostMemoryBuffer using the specified stream.
|
void |
copyFromHostBuffer(long destOffset,
HostMemoryBuffer srcData,
long srcOffset,
long length)
Copy the contents of the given buffer to this buffer
|
boolean |
getBoolean(long offset)
Returns the Boolean value at that offset
|
byte |
getByte(long offset)
Returns the byte value at that offset
|
void |
getBytes(byte[] dst,
long dstOffset,
long srcOffset,
long len)
Copy a set of bytes to an array from the buffer starting at offset.
|
double |
getDouble(long offset)
Returns the Double value at that offset
|
float |
getFloat(long offset)
Returns the Float value at that offset
|
int |
getInt(long offset)
Returns the Integer value at that offset
|
long |
getLong(long offset)
Returns the Long value at that offset
|
void |
getLongs(long[] dst,
long dstIndex,
long srcOffset,
int count)
Copy a set of longs to an array from the buffer starting at offset.
|
short |
getShort(long offset)
Returns the Short value at that offset
|
static HostMemoryBuffer |
mapFile(File path,
FileChannel.MapMode mode,
long offset,
long length)
Create a host buffer that is memory-mapped to a file.
|
void |
printBuffer()
WARNING: Debug only method to print buffer.
|
void |
printBuffer(int wordsPerRow)
WARNING: Debug only method to print buffer.
|
void |
setBoolean(long offset,
boolean value)
Sets the Boolean value at that offset
|
void |
setByte(long offset,
byte value)
Sets the byte value at that offset
|
void |
setBytes(long offset,
byte[] data,
long srcOffset,
long len)
Copy a set of bytes from an array into the buffer at offset.
|
void |
setDouble(long offset,
double value)
Sets the Double value at that offset
|
void |
setDoubles(long offset,
double[] data,
long srcOffset,
long len)
Copy a set of doubles from an array into the buffer at offset.
|
void |
setFloat(long offset,
float value)
Sets the Float value at that offset
|
void |
setFloats(long offset,
float[] data,
long srcOffset,
long len)
Copy a set of floats from an array into the buffer at offset.
|
void |
setInt(long offset,
int value)
Sets the Integer value at that offset
|
void |
setInts(long offset,
int[] data,
long srcOffset,
long len)
Copy a set of ints from an array into the buffer at offset.
|
void |
setLong(long offset,
long value)
Sets the Long value at that offset
|
void |
setLongs(long offset,
long[] data,
long srcOffset,
long len)
Copy a set of longs from an array into the buffer at offset.
|
void |
setMemory(long offset,
long length,
byte value)
Sets the values in this buffer repeatedly
|
void |
setShort(long offset,
short value)
Sets the Short value at that offset
|
void |
setShorts(long offset,
short[] data,
long srcOffset,
long len)
Copy a set of shorts from an array into the buffer at offset.
|
HostMemoryBuffer |
slice(long offset,
long len)
Slice off a part of the host buffer.
|
HostMemoryBuffer |
sliceWithCopy(long offset,
long len)
Slice off a part of the host buffer, actually making a copy of the data.
|
addressOutOfBoundsCheck, close, copyFromMemoryBuffer, copyFromMemoryBufferAsync, getAddress, getEventHandler, getLength, getRefCount, incRefCount, noWarnLeakExpected, setEventHandler, toStringpublic static HostMemoryBuffer allocate(long bytes, boolean preferPinned)
bytes - size in bytes to allocatepreferPinned - If set to true, the pinned memory pool will be used if possible with a
fallback to off-heap memory. If set to false, the allocation will always
be from off-heap memory.public static HostMemoryBuffer allocate(long bytes)
bytes - size in bytes to allocatepublic static HostMemoryBuffer mapFile(File path, FileChannel.MapMode mode, long offset, long length) throws IOException
path - path to the file to map into host memorymode - mapping typeoffset - file offset where the map will startlength - the number of bytes to mapIOExceptionpublic final ByteBuffer asByteBuffer()
public final ByteBuffer asByteBuffer(long offset, int length)
offset - the offset to start atlength - how many bytes to include.public final void copyFromHostBuffer(long destOffset,
HostMemoryBuffer srcData,
long srcOffset,
long length)
destOffset - offset in bytes in this buffer to start copying tosrcData - Buffer to be copied fromsrcOffset - offset in bytes to start copying from in srcDatalength - number of bytes to copypublic final byte getByte(long offset)
offset - - offset from the addresspublic final void setByte(long offset,
byte value)
offset - - offset from the addressvalue - - value to be setpublic final void getBytes(byte[] dst,
long dstOffset,
long srcOffset,
long len)
dst - destination byte arraydstOffset - starting offset within the destination arraysrcOffset - starting offset within this bufferlen - number of bytes to copypublic final void setBytes(long offset,
byte[] data,
long srcOffset,
long len)
offset - the offset from the address to start copying todata - the data to be copied.public final short getShort(long offset)
offset - - offset from the addresspublic final void setShort(long offset,
short value)
offset - - offset from the addressvalue - - value to be setpublic final void setShorts(long offset,
short[] data,
long srcOffset,
long len)
offset - the offset from the address to start copying todata - the data to be copied.srcOffset - index in data to start at.public final int getInt(long offset)
offset - - offset from the addresspublic final void setInt(long offset,
int value)
offset - - offset from the addressvalue - - value to be setpublic final void setInts(long offset,
int[] data,
long srcOffset,
long len)
offset - the offset from the address to start copying todata - the data to be copied.srcOffset - index into data to start atpublic final long getLong(long offset)
offset - - offset from the addresspublic final void setLong(long offset,
long value)
offset - - offset from the addressvalue - - value to be setpublic final void getLongs(long[] dst,
long dstIndex,
long srcOffset,
int count)
dst - destination long arraydstIndex - starting index within the destination arraysrcOffset - starting offset within this buffercount - number of longs to copypublic final void setLongs(long offset,
long[] data,
long srcOffset,
long len)
offset - the offset from the address to start copying todata - the data to be copied.srcOffset - index into data to start at.public final float getFloat(long offset)
offset - - offset from the addresspublic final void setFloat(long offset,
float value)
offset - - offset from the addressvalue - - value to be setpublic final void setFloats(long offset,
float[] data,
long srcOffset,
long len)
offset - the offset from the address to start copying todata - the data to be copied.srcOffset - index into data to start atpublic final double getDouble(long offset)
offset - - offset from the addresspublic final void setDouble(long offset,
double value)
offset - - offset from the addressvalue - - value to be setpublic final void setDoubles(long offset,
double[] data,
long srcOffset,
long len)
offset - the offset from the address to start copying todata - the data to be copied.srcOffset - index into data to start atpublic final boolean getBoolean(long offset)
offset - - offset from the addresspublic final void setBoolean(long offset,
boolean value)
offset - - offset from the addressvalue - - value to be setpublic final void setMemory(long offset,
long length,
byte value)
offset - - offset from the addresslength - - number of bytes to setvalue - - value to be setpublic final void copyFromDeviceBuffer(BaseDeviceMemoryBuffer deviceMemoryBuffer)
deviceMemoryBuffer - buffer to copy data frompublic final void copyFromDeviceBuffer(BaseDeviceMemoryBuffer deviceMemoryBuffer, Cuda.Stream stream)
deviceMemoryBuffer - buffer to copy data fromstream - CUDA stream to usepublic final void copyFromDeviceBufferAsync(BaseDeviceMemoryBuffer deviceMemoryBuffer, Cuda.Stream stream)
deviceMemoryBuffer - buffer to copy data fromstream - CUDA stream to usepublic final HostMemoryBuffer slice(long offset, long len)
slice in class MemoryBufferoffset - where to start the slice at.len - how many bytes to slicepublic final HostMemoryBuffer sliceWithCopy(long offset, long len)
offset - where to start the slice at.len - how many bytes to slicepublic void printBuffer()
public void printBuffer(int wordsPerRow)
wordsPerRow - the number of 32 bit works to print per row.Copyright © 2024. All rights reserved.