Function rcudnn::cudaThreadExchangeStreamCaptureMode[][src]

pub unsafe extern "C" fn cudaThreadExchangeStreamCaptureMode(
    mode: *mut cudaStreamCaptureMode
) -> cudaError
Expand description

\brief Swaps the stream capture interaction mode for a thread

Sets the calling thread’s stream capture interaction mode to the value contained in \p *mode, and overwrites \p *mode with the previous mode for the thread. To facilitate deterministic behavior across function or module boundaries, callers are encouraged to use this API in a push-pop fashion: \code cudaStreamCaptureMode mode = desiredMode; cudaThreadExchangeStreamCaptureMode(&mode); … cudaThreadExchangeStreamCaptureMode(&mode); // restore previous mode \endcode

During stream capture (see ::cudaStreamBeginCapture), some actions, such as a call to ::cudaMalloc, may be unsafe. In the case of ::cudaMalloc, the operation is not enqueued asynchronously to a stream, and is not observed by stream capture. Therefore, if the sequence of operations captured via ::cudaStreamBeginCapture depended on the allocation being replayed whenever the graph is launched, the captured graph would be invalid.

Therefore, stream capture places restrictions on API calls that can be made within or concurrently to a ::cudaStreamBeginCapture-::cudaStreamEndCapture sequence. This behavior can be controlled via this API and flags to ::cudaStreamBeginCapture.

A thread’s mode is one of the following:

  • \p cudaStreamCaptureModeGlobal: This is the default mode. If the local thread has an ongoing capture sequence that was not initiated with \p cudaStreamCaptureModeRelaxed at \p cuStreamBeginCapture, or if any other thread has a concurrent capture sequence initiated with \p cudaStreamCaptureModeGlobal, this thread is prohibited from potentially unsafe API calls.
  • \p cudaStreamCaptureModeThreadLocal: If the local thread has an ongoing capture sequence not initiated with \p cudaStreamCaptureModeRelaxed, it is prohibited from potentially unsafe API calls. Concurrent capture sequences in other threads are ignored.
  • \p cudaStreamCaptureModeRelaxed: The local thread is not prohibited from potentially unsafe API calls. Note that the thread is still prohibited from API calls which necessarily conflict with stream capture, for example, attempting ::cudaEventQuery on an event that was last recorded inside a capture sequence.

\param mode - Pointer to mode value to swap with the current mode

\return ::cudaSuccess, ::cudaErrorInvalidValue \notefnerr

\sa ::cudaStreamBeginCapture