cuda.bindings._v2.driver.stream_get_ctx#

cuda.bindings._v2.driver.stream_get_ctx(intptr_t h_stream) → intptr_t#

Query the context associated with a stream.

Returns the CUDA context that the stream is associated with. If the stream was created via the API cuGreenCtxStreamCreate, the returned context is equivalent to the one returned by ctx_from_green_ctx() on the green context associated with the stream at creation time. The stream handle h_stream can refer to any of the following:.

  • a stream created via any of the CUDA driver APIs such as cuStreamCreate and cuStreamCreateWithPriority, or their runtime API equivalents such as cudaStreamCreate, cudaStreamCreateWithFlags and cudaStreamCreateWithPriority. The returned context is the context that was active in the calling thread when the stream was created. Passing an invalid handle will result in undefined behavior.

  • any of the special streams such as the NULL stream, CU_STREAM_LEGACY and CU_STREAM_PER_THREAD. The runtime API equivalents of these are also accepted, which are NULL, cudaStreamLegacy and cudaStreamPerThread respectively. Specifying any of the special handles will return the context current to the calling thread. If no context is current to the calling thread, CUDA_ERROR_INVALID_CONTEXT is returned.

Parameters:

h_stream (intptr_t) – Handle to the stream to be queried.

Returns:

Returned context associated with the stream.

Return type:

intptr_t

See also

cuStreamGetCtx