cuda.bindings._v2.driver.stream_get_ctx_v2#

cuda.bindings._v2.driver.stream_get_ctx_v2(intptr_t h_stream) → tuple#

Query the contexts associated with a stream.

Returns the contexts that the stream is associated with. If the stream is associated with a green context, the API returns the green context in p_green_ctx and the primary context of the associated device in p_ctx. If the stream is associated with a regular context, the API returns the regular context in p_ctx and NULL in p_green_ctx. 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, cuStreamCreateWithPriority and cuGreenCtxStreamCreate, or their runtime API equivalents such as cudaStreamCreate, cudaStreamCreateWithFlags and cudaStreamCreateWithPriority. 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. If any of the special handles are specified, the API will operate on the context current to the calling thread. If a green context (that was converted via ctx_from_green_ctx() before setting it current) is current to the calling thread, the API will return the green context in p_green_ctx and the primary context of the associated device in p_ctx. If a regular context is current, the API returns the regular context in p_ctx and NULL in p_green_ctx. Note that specifying CU_STREAM_PER_THREAD or cudaStreamPerThread will return CUDA_ERROR_INVALID_HANDLE if a green context is 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:

  • intptr_t: Returned regular context associated with the stream.

  • intptr_t: Returned green context if the stream is associated with

    a green context or NULL if not.

Return type:

A 2-tuple containing

See also

cuStreamGetCtx_v2