L iK%TddlZddlZddlmZeej ds>edej j d<edej j d<Gddej jZGddeZ Gd d ej jZ y) N) _dummy_type_CudaStreamBase_CudaEventBaseceZdZdZd fd ZddZddZddZdeffd Z dfd Z e d Z deffd Z d Zd ZxZS)StreamaWrapper around a CUDA stream. A CUDA stream is a linear sequence of execution that belongs to a specific device, independent from other streams. It supports with statement as a context manager to ensure the operators within the with block are running on the corresponding stream. See :ref:`cuda-semantics` for details. Args: device(torch.device or int, optional): a device on which to allocate the stream. If :attr:`device` is ``None`` (default) or a negative integer, this will use the current device. priority(int, optional): priority of the stream, which can be positive, 0, or negative. A lower number indicates a higher priority. By default, the priority is set to 0. If the value falls outside of the allowed priority range, it will automatically be mapped to the nearest valid priority (lowest for large positive numbers or highest for large negative numbers). c |d|vrd|vrt||fd|i|Stjj |5t||fd|i|cdddS#1swYyxYw)N stream_id device_indexpriority)super__new__torchcudadevice)clsrr kwargs __class__s X/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/torch/cuda/streams.pyr zStream.__new__"sp >kV3&8P7?3DDVD D""6* IwsHXHH I I Is AA"returnc&|j|y)aMake all future work submitted to the stream wait for an event. Args: event (torch.cuda.Event): an event to wait for. .. note:: This is a wrapper around ``cudaStreamWaitEvent()``: see `CUDA Stream documentation`_ for more info. This function returns without waiting for :attr:`event`: only future operations are affected. .. _CUDA Stream documentation: https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__STREAM.html N)waitselfevents r wait_eventzStream.wait_event*s  4cB|j|jy)aSynchronize with another stream. All future work submitted to this stream will wait until all kernels submitted to a given stream at the time of call complete. Args: stream (Stream): a stream to synchronize. .. note:: This function returns without waiting for currently enqueued kernels in :attr:`stream`: only future operations are affected. N)r record_event)rstreams r wait_streamzStream.wait_stream;s ++-.rc@| t}|j||S)zRecord an event. Args: event (torch.cuda.Event, optional): event to record. If not given, a new one will be allocated. Returns: Recorded event. )Eventrecordrs rrzStream.record_eventIs! =GE T rc t|S)zCheck if all the work submitted has been completed. Returns: A boolean indicating if all kernels in this stream are completed. r queryrrs rr&z Stream.queryXs w}rc"t|y)zWait for all the kernels in this stream to complete. .. note:: This is a wrapper around ``cudaStreamSynchronize()``: see `CUDA Stream documentation`_ for more info. Nr synchronizer's rr*zStream.synchronize`s rc@tj|jSN)ctypesc_void_p cuda_streamrs r_as_parameter_zStream._as_parameter_hst//00rcDt|trt| |Sy)NF) isinstancerr __eq__)rors rr4z Stream.__eq__ls a 7>!$ $rcDt|j|jfSr,)hashr/rr0s r__hash__zStream.__hash__qsT%%t{{344rc>d|jd|jddS)Nz)rr/r0s r__repr__zStream.__repr__ts&+DKK= dFVFVWYEZZ[\\r)NrrNr,)__name__ __module__ __qualname____doc__r rr rboolr&r*propertyr1r4r8r< __classcell__rs@rrrsY&I" / t114 5]rrc$eZdZdZdfd ZxZS)ExternalStreamaWrapper around an externally allocated CUDA stream. This class is used to wrap streams allocated in other libraries in order to facilitate data exchange and multi-library interactions. .. note:: This class doesn't manage the stream life-cycle, it is the user responsibility to keep the referenced stream alive while this class is being used. Args: stream_ptr(int): Integer representation of the `cudaStream_t` value. allocated externally. device(torch.device or int, optional): the device where the stream was originally allocated. If device is specified incorrectly, subsequent launches using this stream may fail. c tjj|5t||fd|i|cdddS#1swYyxYw)N stream_ptr)rrrr r )rrIrrrs rr zExternalStream.__new__sD ZZ  v & I7?3H:HH I I Is =Ar,)r>r?r@rAr rDrEs@rrGrGxs"IIrrGceZdZdZ d fd ZefdZdfd Zddfd ZfdZ fdZ dfd Z fd Z e d Zdefd ZxZS)r"aWrapper around a CUDA event. CUDA events are synchronization markers that can be used to monitor the device's progress, to accurately measure timing, and to synchronize CUDA streams. The underlying CUDA events are lazily initialized when the event is first recorded or exported to another process. After creation, only streams on the same device may record the event. However, streams on any device can wait on the event. Args: enable_timing (bool, optional): indicates if the event should measure time (default: ``False``) blocking (bool, optional): if ``True``, :meth:`wait` will be blocking (default: ``False``) interprocess (bool): if ``True``, the event can be shared between processes (default: ``False``) external (bool, optional): indicates whether this event should create event record and event wait nodes, or create an internal cross-stream dependency, when captured in a cuda graph. See `cross-stream dependencies `_, `cudaEventRecordExternal `_, and `cudaEventWaitExternal `_ for more information about internal vs. external events. (default: ``False``) .. _CUDA Event Documentation: https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__EVENT.html c,t||||||S)N) enable_timingblocking interprocessexternal)r r )rrLrMrNrOrs rr z Event.__new__s*w '%   rc$t|||S)zZZ..0F vrrcd|tjj}t||y)aMake all future work submitted to the given stream wait for this event. Use ``torch.cuda.current_stream()`` if no stream is specified. .. note:: This is a wrapper around ``cudaStreamWaitEvent()``: see `CUDA Event documentation`_ for more info. N)rrrTr rrUs rrz Event.waits( >ZZ..0F  Vrc t|S)zCheck if all work currently captured by event has completed. Returns: A boolean indicating if all work currently captured by event has completed. r%r's rr&z Event.querysw}rc"t||S)zReturn the time elapsed. Time reported in milliseconds after the event was recorded and before the end_event was recorded. )r elapsed_time)r end_eventrs rrYzEvent.elapsed_times w#I..rc"t|y)aNWait for the event to complete. Waits until the completion of all work currently captured in this event. This prevents the CPU thread from proceeding until the event completes. .. note:: This is a wrapper around ``cudaEventSynchronize()``: see `CUDA Event documentation`_ for more info. Nr)r's rr*zEvent.synchronizes rc t|S)zqReturn an IPC handle of this event. If not recorded yet, the event will use the current device. )r ipc_handler's rr]zEvent.ipc_handles w!##rc@tj|jSr,)r-r. cuda_eventr0s rr1zEvent._as_parameter_st//rcR|jrd|jjddSy)Nz)r_r1valuer0s rr<zEvent.__repr__s* ??'(;(;(A(A"'EQG G5r)FFFFr,r=)r>r?r@rAr classmethodrQr#rr&rYr*r]rCr1strr<rDrEs@rr"r"sf0PU  77 / $006#6rr") r-r torch._utilsrhasattr_C__dict__rrrGrr"rrris $uxx*++67H+IEHH'(*56F*GEHH&'g]UXX % %g]TIVI.i6EHH # #i6r