6.21. 流内存操作
本节介绍低级CUDA驱动程序应用程序编程接口的流内存操作。
可以通过CU_DEVICE_ATTRIBUTE_CAN_USE_STREAM_WAIT_VALUE_NOR_V2查询对CU_STREAM_WAIT_VALUE_NOR标志的支持情况。
支持cuStreamWriteValue64()和cuStreamWaitValue64()函数,以及CU_STREAM_MEM_OP_WAIT_VALUE_64和CU_STREAM_MEM_OP_WRITE_VALUE_64标志的功能,可以通过CU_DEVICE_ATTRIBUTE_CAN_USE_64_BIT_STREAM_MEM_OPS进行查询。
对CU_STREAM_WAIT_VALUE_FLUSH和CU_STREAM_MEM_OP_FLUSH_REMOTE_WRITES的支持需要专用平台硬件功能,可通过cuDeviceGetAttribute()和CU_DEVICE_ATTRIBUTE_CAN_FLUSH_REMOTE_WRITES进行查询。
请注意,作为参数传递给这些操作的所有内存指针都是设备指针。必要时,应获取设备指针,例如使用cuMemHostGetDevicePointer()。
所有操作均不接受指向托管内存缓冲区的指针(cuMemAllocManaged)。
警告:不当使用这些API可能导致应用程序死锁。通过这些API建立的同步顺序对CUDA不可见。被这些API(甚至间接)排序的CUDA任务,也应通过CUDA可见的依赖关系(如事件)来表达该顺序。这确保调度程序不会以不正确的顺序串行化它们。
Functions
- CUresult cuStreamBatchMemOp ( CUstream stream, unsigned int count, CUstreamBatchMemOpParams* paramArray, unsigned int flags )
- Batch operations to synchronize the stream via memory operations.
- CUresult cuStreamWaitValue32 ( CUstream stream, CUdeviceptr addr, cuuint32_t value, unsigned int flags )
- Wait on a memory location.
- CUresult cuStreamWaitValue64 ( CUstream stream, CUdeviceptr addr, cuuint64_t value, unsigned int flags )
- Wait on a memory location.
- CUresult cuStreamWriteValue32 ( CUstream stream, CUdeviceptr addr, cuuint32_t value, unsigned int flags )
- Write a value to memory.
- CUresult cuStreamWriteValue64 ( CUstream stream, CUdeviceptr addr, cuuint64_t value, unsigned int flags )
- Write a value to memory.
Functions
- CUresult cuStreamBatchMemOp ( CUstream stream, unsigned int count, CUstreamBatchMemOpParams* paramArray, unsigned int flags )
-
通过内存操作批量同步流的操作。
参数
- stream
- The stream to enqueue the operations in.
- count
- The number of operations in the array. Must be less than 256.
- paramArray
- The types and parameters of the individual operations.
- flags
- Reserved for future expansion; must be 0.
描述
这是cuStreamWaitValue32()和cuStreamWriteValue32()的批量版本。与通过单独API调用将它们添加到流中相比,批量操作可以避免API调用和设备执行中的一些性能开销。这些操作会按照它们在数组中出现的顺序入队。
查看CUstreamBatchMemOpType获取完整支持的操作集,以及cuStreamWaitValue32()、cuStreamWaitValue64()、cuStreamWriteValue32()和cuStreamWriteValue64()了解具体操作的详细信息。
有关查询特定操作支持的详细信息,请参阅相关API文档。
Note:Warning: Improper use of this API may deadlock the application. Synchronization ordering established through this API is not visible to CUDA. CUDA tasks that are (even indirectly) ordered by this API should also have that order expressed with CUDA-visible dependencies such as events. This ensures that the scheduler does not serialize them in an improper order. For more information, see the Stream Memory Operations section in the programming guide(https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html).
Note:请注意,此函数也可能返回之前异步启动的错误代码。
另请参阅:
cuStreamWaitValue32, cuStreamWaitValue64, cuStreamWriteValue32, cuStreamWriteValue64, cuMemHostRegister
- CUresult cuStreamWaitValue32 ( CUstream stream, CUdeviceptr addr, cuuint32_t value, unsigned int flags )
-
等待内存位置。
参数
- stream
- The stream to synchronize on the memory location.
- addr
- The memory location to wait on.
- value
- The value to compare with the memory location.
- flags
- See CUstreamWaitValue_flags.
描述
在给定内存位置上对数据流进行同步排队。该操作之后的工作将被阻塞,直到满足内存上的指定条件。默认情况下,条件是等待 (int32_t)(*addr - value) >= 0,即循环大于等于。其他条件类型可以通过flags参数指定。
如果内存是通过cuMemHostRegister()注册的,则应使用cuMemHostGetDevicePointer()获取设备指针。此函数不能用于托管内存(cuMemAllocManaged)。
可以通过cuDeviceGetAttribute()和CU_DEVICE_ATTRIBUTE_CAN_USE_STREAM_WAIT_VALUE_NOR_V2查询对CU_STREAM_WAIT_VALUE_NOR的支持情况。
Note:警告:不当使用此API可能导致应用程序死锁。通过此API建立的同步顺序对CUDA不可见。被此API(甚至间接)排序的CUDA任务,也应通过CUDA可见的依赖关系(如事件)来表达该顺序。这确保调度程序不会以不当顺序串行化它们。
Note:请注意,此函数也可能返回之前异步启动的错误代码。
另请参阅:
cuStreamWaitValue64, cuStreamWriteValue32, cuStreamWriteValue64, cuStreamBatchMemOp, cuMemHostRegister, cuStreamWaitEvent
- CUresult cuStreamWaitValue64 ( CUstream stream, CUdeviceptr addr, cuuint64_t value, unsigned int flags )
-
等待内存位置。
参数
- stream
- The stream to synchronize on the memory location.
- addr
- The memory location to wait on.
- value
- The value to compare with the memory location.
- flags
- See CUstreamWaitValue_flags.
描述
在给定的内存位置上对数据流进行同步排队。在此操作之后排序的工作将阻塞,直到满足内存上的给定条件。默认情况下,条件是等待 (int64_t)(*addr - value) >= 0,这是一个循环的大于或等于条件。其他条件类型可以通过flags指定。
如果内存是通过cuMemHostRegister()注册的,则应使用cuMemHostGetDevicePointer()获取设备指针。
可以通过cuDeviceGetAttribute()和CU_DEVICE_ATTRIBUTE_CAN_USE_64_BIT_STREAM_MEM_OPS查询对此功能的支持。
Note:警告:不当使用此API可能导致应用程序死锁。通过此API建立的同步顺序对CUDA不可见。被此API(甚至间接)排序的CUDA任务,也应通过CUDA可见的依赖关系(如事件)来表达该顺序。这确保调度程序不会以错误的顺序串行化它们。
Note:请注意,此函数也可能返回之前异步启动的错误代码。
另请参阅:
cuStreamWaitValue32, cuStreamWriteValue32, cuStreamWriteValue64, cuStreamBatchMemOp, cuMemHostRegister, cuStreamWaitEvent
- CUresult cuStreamWriteValue32 ( CUstream stream, CUdeviceptr addr, cuuint32_t value, unsigned int flags )
-
将值写入内存。
参数
- stream
- The stream to do the write in.
- addr
- The device address to write to.
- value
- The value to write.
- flags
- See CUstreamWriteValue_flags.
描述
将值写入内存。
如果内存是通过cuMemHostRegister()注册的,则应使用cuMemHostGetDevicePointer()获取设备指针。此函数不能用于托管内存(cuMemAllocManaged)。
Note:请注意,此函数也可能返回之前异步启动的错误代码。
另请参阅:
cuStreamWriteValue64, cuStreamWaitValue32, cuStreamWaitValue64, cuStreamBatchMemOp, cuMemHostRegister, cuEventRecord
- CUresult cuStreamWriteValue64 ( CUstream stream, CUdeviceptr addr, cuuint64_t value, unsigned int flags )
-
将值写入内存。
参数
- stream
- The stream to do the write in.
- addr
- The device address to write to.
- value
- The value to write.
- flags
- See CUstreamWriteValue_flags.
描述
将值写入内存。
如果内存是通过cuMemHostRegister()注册的,则应使用cuMemHostGetDevicePointer()获取设备指针。
可以通过cuDeviceGetAttribute()和CU_DEVICE_ATTRIBUTE_CAN_USE_64_BIT_STREAM_MEM_OPS查询对此功能的支持。
Note:请注意,此函数也可能返回之前异步启动的错误代码。
另请参阅:
cuStreamWriteValue32, cuStreamWaitValue32, cuStreamWaitValue64, cuStreamBatchMemOp, cuMemHostRegister, cuEventRecord