Class CudaMemory
Managed wrapper around a device memory allocation. CUDA 设备内存分配的托管封装。
public class CudaMemory : IDisposable
- Inheritance
-
CudaMemory
- Implements
- Derived
- Inherited Members
Constructors
CudaMemory(int)
Allocates CUDA device memory. 分配 CUDA 设备内存。
public CudaMemory(int sizeInBytes)
Parameters
sizeInBytesintThe allocation size in bytes. 分配大小,单位为字节。
Properties
SizeInBytes
Gets the allocation size in bytes. 获取分配大小,单位为字节。
public int SizeInBytes { get; }
Property Value
Methods
Advise(CudaMemoryAdvice, int)
Applies a CUDA memory advice to the entire allocation. 对整个分配应用 CUDA memory advice。
public void Advise(CudaMemoryAdvice advice, int device)
Parameters
adviceCudaMemoryAdviceThe CUDA memory advice. CUDA 内存建议。
deviceintThe device ordinal associated with the advice. 与 advice 关联的设备序号。
Advise(int, CudaMemoryAdvice, int)
Applies CUDA memory advice to part of the allocation. 对分配的一部分应用 CUDA memory advice。
public void Advise(int count, CudaMemoryAdvice advice, int device)
Parameters
countintThe number of bytes covered by the advice. advice 覆盖的字节数。
adviceCudaMemoryAdviceThe CUDA memory advice. CUDA 内存建议。
deviceintThe device ordinal associated with the advice. 与 advice 关联的设备序号。
AllocateAsync(int, CudaStream)
Asynchronously allocates device memory on a CUDA stream. 在 CUDA stream 上异步分配设备内存。
public static CudaMemory AllocateAsync(int sizeInBytes, CudaStream stream)
Parameters
sizeInBytesintThe allocation size in bytes. 分配大小,单位为字节。
streamCudaStreamThe CUDA stream that orders the allocation. 用于排序分配操作的 CUDA stream。
Returns
- CudaMemory
A managed device-memory wrapper. 设备内存的托管封装。
AllocateFromPoolAsync(int, CudaMemoryPool, CudaStream)
Asynchronously allocates device memory from a specific CUDA memory pool. 从指定 CUDA memory pool 中异步分配设备内存。
public static CudaMemory AllocateFromPoolAsync(int sizeInBytes, CudaMemoryPool memoryPool, CudaStream stream)
Parameters
sizeInBytesintThe allocation size in bytes. 分配大小,单位为字节。
memoryPoolCudaMemoryPoolThe CUDA memory pool used for allocation. 用于分配的 CUDA memory pool。
streamCudaStreamThe CUDA stream that orders the allocation. 用于排序分配操作的 CUDA stream。
Returns
- CudaMemory
A managed CUDA memory wrapper. CUDA 设备内存托管封装。
CopyFrom(byte[])
Copies a byte array into device memory. 将字节数组复制到设备内存中。
public void CopyFrom(byte[] source)
Parameters
sourcebyte[]The source byte array. 源字节数组。
CopyFrom(float[])
Copies a float array into device memory. 将浮点数组复制到设备内存中。
public void CopyFrom(float[] source)
Parameters
sourcefloat[]The source float array. 源浮点数组。
CopyFromAsync(CudaPinnedMemory, CudaStream)
Asynchronously copies the full pinned-host buffer into this device allocation. 异步将整个 pinned host 缓冲区复制到当前设备内存。
public void CopyFromAsync(CudaPinnedMemory source, CudaStream stream)
Parameters
sourceCudaPinnedMemoryThe source pinned host buffer. 源 pinned host 缓冲区。
streamCudaStreamThe CUDA stream that orders the copy. 用于排序复制操作的 CUDA stream。
CopyFromAsync(CudaPinnedMemory, int, CudaStream)
Asynchronously copies a pinned host buffer into device memory. 将 pinned host 缓冲区异步复制到设备内存中。
public void CopyFromAsync(CudaPinnedMemory source, int count, CudaStream stream)
Parameters
sourceCudaPinnedMemoryThe source pinned host buffer. 源 pinned host 缓冲区。
countintThe number of bytes to copy. 要复制的字节数。
streamCudaStreamThe CUDA stream that orders the copy. 用于排序复制操作的 CUDA stream。
CopyFromAsync(CudaRegisteredHostMemory, int, CudaStream)
Asynchronously copies registered host memory into device memory. 将 registered host memory 异步复制到设备内存中。
public void CopyFromAsync(CudaRegisteredHostMemory source, int count, CudaStream stream)
Parameters
sourceCudaRegisteredHostMemoryThe source registered host buffer. 源 registered host 缓冲区。
countintThe number of bytes to copy. 要复制的字节数。
streamCudaStreamThe CUDA stream that orders the copy. 用于排序复制操作的 CUDA stream。
CopyTo(CudaMemory)
Copies bytes from this allocation to another allocation using the smaller allocation size. 按两个分配中较小的大小,将当前分配复制到另一个分配。
public void CopyTo(CudaMemory destination)
Parameters
destinationCudaMemoryThe destination device allocation. 目标设备内存分配。
CopyTo(CudaMemory, int)
Copies bytes from this allocation to another device allocation. 将当前分配中的字节复制到另一个设备分配中。
public void CopyTo(CudaMemory destination, int count)
Parameters
destinationCudaMemoryThe destination device allocation. 目标设备内存分配。
countintThe number of bytes to copy. 要复制的字节数。
CopyTo(byte[])
Copies device memory into a byte array. 将设备内存复制到字节数组中。
public void CopyTo(byte[] destination)
Parameters
destinationbyte[]The destination byte array. 目标字节数组。
CopyTo(float[])
Copies device memory into a float array. 将设备内存复制到浮点数组中。
public void CopyTo(float[] destination)
Parameters
destinationfloat[]The destination float array. 目标浮点数组。
CopyToAsync(CudaMemory, CudaStream)
Asynchronously copies bytes to another allocation using the smaller allocation size. 按两个分配中较小的大小,异步将当前分配复制到另一个分配。
public void CopyToAsync(CudaMemory destination, CudaStream stream)
Parameters
destinationCudaMemoryThe destination device allocation. 目标设备内存分配。
streamCudaStreamThe CUDA stream that orders the copy. 用于排序复制操作的 CUDA stream。
CopyToAsync(CudaMemory, int, CudaStream)
Asynchronously copies bytes to another device allocation. 异步将字节复制到另一个设备分配中。
public void CopyToAsync(CudaMemory destination, int count, CudaStream stream)
Parameters
destinationCudaMemoryThe destination device allocation. 目标设备内存分配。
countintThe number of bytes to copy. 要复制的字节数。
streamCudaStreamThe CUDA stream that orders the copy. 用于排序复制操作的 CUDA stream。
CopyToAsync(CudaPinnedMemory, CudaStream)
Asynchronously copies this allocation into a full pinned-host buffer. 异步将当前设备内存复制到整个 pinned host 缓冲区。
public void CopyToAsync(CudaPinnedMemory destination, CudaStream stream)
Parameters
destinationCudaPinnedMemoryThe destination pinned host buffer. 目标 pinned host 缓冲区。
streamCudaStreamThe CUDA stream that orders the copy. 用于排序复制操作的 CUDA stream。
CopyToAsync(CudaPinnedMemory, int, CudaStream)
Asynchronously copies device memory into a pinned host buffer. 将设备内存异步复制到 pinned host 缓冲区中。
public void CopyToAsync(CudaPinnedMemory destination, int count, CudaStream stream)
Parameters
destinationCudaPinnedMemoryThe destination pinned host buffer. 目标 pinned host 缓冲区。
countintThe number of bytes to copy. 要复制的字节数。
streamCudaStreamThe CUDA stream that orders the copy. 用于排序复制操作的 CUDA stream。
CopyToAsync(CudaRegisteredHostMemory, int, CudaStream)
Asynchronously copies device memory into registered host memory. 将设备内存异步复制到 registered host memory 中。
public void CopyToAsync(CudaRegisteredHostMemory destination, int count, CudaStream stream)
Parameters
destinationCudaRegisteredHostMemoryThe destination registered host buffer. 目标 registered host 缓冲区。
countintThe number of bytes to copy. 要复制的字节数。
streamCudaStreamThe CUDA stream that orders the copy. 用于排序复制操作的 CUDA stream。
CopyToAuto(CudaMemory, int)
Copies bytes to another CUDA allocation and lets CUDA infer the copy direction. 将字节复制到另一个 CUDA 分配,并让 CUDA 自动推断复制方向。
public void CopyToAuto(CudaMemory destination, int count)
Parameters
destinationCudaMemoryThe destination allocation. 目标设备内存分配。
countintThe number of bytes to copy. 要复制的字节数。
CopyToAutoAsync(CudaMemory, int, CudaStream)
Asynchronously copies bytes to another CUDA allocation and lets CUDA infer the copy direction. 异步将字节复制到另一个 CUDA 分配,并让 CUDA 自动推断复制方向。
public void CopyToAutoAsync(CudaMemory destination, int count, CudaStream stream)
Parameters
destinationCudaMemoryThe destination allocation. 目标设备内存分配。
countintThe number of bytes to copy. 要复制的字节数。
streamCudaStreamThe CUDA stream that orders the copy. 用于排序复制操作的 CUDA stream。
CopyToPeer(CudaMemory, int, int, int)
Copies bytes from this allocation to a destination allocation on another CUDA device. 将当前分配中的字节复制到另一个 CUDA 设备上的目标分配。
public void CopyToPeer(CudaMemory destination, int sourceDevice, int destinationDevice, int count)
Parameters
destinationCudaMemoryThe destination allocation. 目标设备内存分配。
sourceDeviceintThe CUDA device ordinal that owns this source allocation. 拥有当前源分配的 CUDA 设备序号。
destinationDeviceintThe CUDA device ordinal that owns the destination allocation. 拥有目标分配的 CUDA 设备序号。
countintThe number of bytes to copy. 要复制的字节数。
CopyToPeerAsync(CudaMemory, int, int, int, CudaStream)
Asynchronously copies bytes from this allocation to another CUDA device using a stream. 使用 stream 将当前分配中的字节异步复制到另一个 CUDA 设备。
public void CopyToPeerAsync(CudaMemory destination, int sourceDevice, int destinationDevice, int count, CudaStream stream)
Parameters
destinationCudaMemoryThe destination allocation. 目标设备内存分配。
sourceDeviceintThe CUDA device ordinal that owns this source allocation. 拥有当前源分配的 CUDA 设备序号。
destinationDeviceintThe CUDA device ordinal that owns the destination allocation. 拥有目标分配的 CUDA 设备序号。
countintThe number of bytes to copy. 要复制的字节数。
streamCudaStreamThe CUDA stream that orders the copy. 用于排序该复制操作的 CUDA stream。
Dispose()
Releases the device allocation. 释放设备内存分配。
public void Dispose()
Fill(byte)
Fills the entire allocation with a byte value. 使用一个字节值填充整个设备内存分配。
public void Fill(byte value)
Parameters
valuebyteThe fill byte value. 填充值。
Fill(byte, int)
Fills part of the allocation with a byte value. 使用一个字节值填充部分分配区域。
public void Fill(byte value, int count)
Parameters
FillAsync(byte, CudaStream)
Asynchronously fills the entire allocation with a byte value. 异步使用一个字节值填充整个设备内存分配。
public void FillAsync(byte value, CudaStream stream)
Parameters
valuebyteThe fill byte value. 填充值。
streamCudaStreamThe CUDA stream that orders the fill. 用于排序填充操作的 CUDA stream。
FillAsync(byte, int, CudaStream)
Asynchronously fills part of the allocation with a byte value. 使用一个字节值异步填充分配的一部分区域。
public void FillAsync(byte value, int count, CudaStream stream)
Parameters
valuebyteThe fill byte value. 填充值。
countintThe number of bytes to fill. 要填充的字节数。
streamCudaStreamThe CUDA stream that orders the fill. 用于排序填充操作的 CUDA stream。
FreeAsync(CudaStream)
Asynchronously frees this allocation on the supplied CUDA stream and invalidates the managed handle. 在指定 CUDA stream 上异步释放当前分配,并使托管句柄失效。
public void FreeAsync(CudaStream stream)
Parameters
streamCudaStreamThe CUDA stream that orders the free operation. 用于排序释放操作的 CUDA stream。
GetPointerAttributes()
Queries CUDA pointer attributes for this device allocation. 查询当前设备内存分配的 CUDA 指针属性。
public CudaPointerAttributes GetPointerAttributes()
Returns
- CudaPointerAttributes
Pointer metadata useful for diagnostics and deployment validation. 用于诊断和部署验证的指针元数据。
PrefetchAsync(int, CudaStream)
Asynchronously prefetches the entire allocation to a target CUDA device. 异步将整个分配预取到目标 CUDA 设备。
public void PrefetchAsync(int destinationDevice, CudaStream stream)
Parameters
destinationDeviceintThe target CUDA device ordinal. 目标 CUDA 设备序号。
streamCudaStreamThe CUDA stream that orders the prefetch. 用于排序预取操作的 CUDA stream。
PrefetchAsync(int, int, CudaStream)
Asynchronously prefetches part of the allocation to a target device. 异步将分配的一部分预取到目标设备。
public void PrefetchAsync(int count, int destinationDevice, CudaStream stream)
Parameters
countintThe number of bytes to prefetch. 要预取的字节数。
destinationDeviceintThe target CUDA device ordinal. 目标 CUDA 设备序号。
streamCudaStreamThe CUDA stream that orders the prefetch. 用于排序预取操作的 CUDA stream。
ToArray(int)
Materializes a byte array from device memory. 从设备内存中生成字节数组。
public byte[] ToArray(int count)
Parameters
countintThe number of bytes to copy. 要复制的字节数。
Returns
- byte[]
A managed byte array copy. 托管字节数组副本。
ToSingleArray(int)
Materializes a float array from device memory. 从设备内存中生成浮点数组。
public float[] ToSingleArray(int elementCount)
Parameters
elementCountintThe number of single-precision elements to copy. 要复制的单精度元素数量。
Returns
- float[]
A managed float array copy. 托管浮点数组副本。