cuda::experimental::places::get_device_from_stream#
- inline int cuda::experimental::places::get_device_from_stream(
- cudaStream_t stream
Computes the CUDA device in which the stream was created.
The device is read from the stream’s context through the driver API: the context is looked up with
cuStreamGetCtx, made current, and asked for its device withcuCtxGetDevice. This is the pathstream_and_event::insert_dependencyhas always run on captured streams, and it is accepted during thread-local, relaxed and global capture without invalidating it (verified on drivers 580 and 595).cudaStreamGetDevice/cuStreamGetDeviceare deliberately not used: whether they are permitted during capture depends on the driver, not on the toolkit (rejected withcudaErrorStreamCaptureUnsupportedby cudart 12.9 on driver 595 and by cudart 13.0 on driver 580, accepted on driver 615), and a rejection invalidates the capture, so there is no way to try them first.The context lookup is
cuda::stream_ref’s:cuStreamGetCtx_v2on drivers 12.5 and newer, since the originalcuStreamGetCtxreturnsCUDA_ERROR_NOT_SUPPORTEDfor green-context streams on CUDA 12 drivers, and the original query on older drivers, which have no such streams.Answering from a guess (the current device) instead of a query is what put transient events in the wrong device’s context on multi-GPU systems (
cudaErrorInvalidResourceHandleat event-record time).