Movatterモバイル変換


[0]ホーム

URL:


NVIDIACUDA Toolkit Documentation
Search In:
< Previous |Next >
CUDA Runtime API (PDF) - v13.0.2 (older) - Last updated October 9, 2025 -Send Feedback

6.5. Event Management

This section describes the event management functions of the CUDA runtime application programming interface.

Functions

__host__cudaError_t cudaEventCreate (cudaEvent_t* event )
Creates an event object.
__host____device__cudaError_t cudaEventCreateWithFlags (cudaEvent_t* event, unsigned int flags )
Creates an event object with the specified flags.
__host____device__cudaError_t cudaEventDestroy (cudaEvent_t event )
Destroys an event object.
__host__cudaError_t cudaEventElapsedTime ( float* ms,cudaEvent_t start,cudaEvent_t end )
Computes the elapsed time between events.
__host__cudaError_t cudaEventQuery (cudaEvent_t event )
Queries an event's status.
__host____device__cudaError_t cudaEventRecord (cudaEvent_t event,cudaStream_t stream =0 )
Records an event.
__host__cudaError_t cudaEventRecordWithFlags (cudaEvent_t event,cudaStream_t stream =0, unsigned int flags =0 )
Records an event.
__host__cudaError_t cudaEventSynchronize (cudaEvent_t event )
Waits for an event to complete.

Functions

__host__cudaError_t cudaEventCreate (cudaEvent_t* event )
Creates an event object.
Parameters
event
- Newly created event
Description

Creates an event object for the current device usingcudaEventDefault.

Note:

See also:

cudaEventCreate ( C++ API),cudaEventCreateWithFlags,cudaEventRecord,cudaEventQuery,cudaEventSynchronize,cudaEventDestroy,cudaEventElapsedTime,cudaStreamWaitEvent,cuEventCreate

__host____device__cudaError_t cudaEventCreateWithFlags (cudaEvent_t* event, unsigned int flags )
Creates an event object with the specified flags.
Parameters
event
- Newly created event
flags
- Flags for new event
Description

Creates an event object for the current device with the specified flags. Valid flags include:

Note:

See also:

cudaEventCreate ( C API),cudaEventSynchronize,cudaEventDestroy,cudaEventElapsedTime,cudaStreamWaitEvent,cuEventCreate

__host____device__cudaError_t cudaEventDestroy (cudaEvent_t event )
Destroys an event object.
Parameters
event
- Event to destroy
Description

Destroys the event specified byevent.

An event may be destroyed before it is complete (i.e., whilecudaEventQuery() would returncudaErrorNotReady). In this case, the call does not block on completion of the event, and any associated resources will automatically be released asynchronously at completion.

Note:

See also:

cudaEventCreate ( C API),cudaEventCreateWithFlags,cudaEventQuery,cudaEventSynchronize,cudaEventRecord,cudaEventElapsedTime,cuEventDestroy

__host__cudaError_t cudaEventElapsedTime ( float* ms,cudaEvent_t start,cudaEvent_t end )
Computes the elapsed time between events.
Parameters
ms
- Time betweenstart andend in ms
start
- Starting event
end
- Ending event
Description

Computes the elapsed time between two events (in milliseconds with a resolution of around 0.5 microseconds). Note this API is not guaranteed to return the latest errors for pending work. As such this API is intended to serve as a elapsed time calculation only and polling for completion on the events to be compared should be done withcudaEventQuery instead.

If either event was last recorded in a non-NULL stream, the resulting time may be greater than expected (even if both used the same stream handle). This happens because thecudaEventRecord() operation takes place asynchronously and there is no guarantee that the measured latency is actually just between the two events. Any number of other different stream operations could execute in between the two measured events, thus altering the timing in a significant way.

IfcudaEventRecord() has not been called on either event, thencudaErrorInvalidResourceHandle is returned. IfcudaEventRecord() has been called on both events but one or both of them has not yet been completed (that is,cudaEventQuery() would returncudaErrorNotReady on at least one of the events),cudaErrorNotReady is returned. If either event was created with thecudaEventDisableTiming flag, then this function will returncudaErrorInvalidResourceHandle.

Note:

See also:

cudaEventCreate ( C API),cudaEventCreateWithFlags,cudaEventQuery,cudaEventSynchronize,cudaEventDestroy,cudaEventRecord,cuEventElapsedTime

__host__cudaError_t cudaEventQuery (cudaEvent_t event )
Queries an event's status.
Parameters
event
- Event to query
Description

Queries the status of all work currently captured byevent. SeecudaEventRecord() for details on what is captured by an event.

ReturnscudaSuccess if all captured work has been completed, orcudaErrorNotReady if any captured work is incomplete.

For the purposes of Unified Memory, a return value ofcudaSuccess is equivalent to having calledcudaEventSynchronize().

Note:

See also:

cudaEventCreate ( C API),cudaEventCreateWithFlags,cudaEventRecord,cudaEventSynchronize,cudaEventDestroy,cudaEventElapsedTime,cuEventQuery

__host____device__cudaError_t cudaEventRecord (cudaEvent_t event,cudaStream_t stream =0 )
Records an event.
Parameters
event
- Event to record
stream
- Stream in which to record event
Description

Captures inevent the contents ofstream at the time of this call.event andstream must be on the same CUDA context. Calls such ascudaEventQuery() orcudaStreamWaitEvent() will then examine or wait for completion of the work that was captured. Uses ofstream after this call do not modifyevent. See note on default stream behavior for what is captured in the default case.

cudaEventRecord() can be called multiple times on the same event and will overwrite the previously captured state. Other APIs such ascudaStreamWaitEvent() use the most recently captured state at the time of the API call, and are not affected by later calls tocudaEventRecord(). Before the first call tocudaEventRecord(), an event represents an empty set of work, so for examplecudaEventQuery() would returncudaSuccess.

Note:

See also:

cudaEventCreate ( C API),cudaEventCreateWithFlags,cudaEventQuery,cudaEventSynchronize,cudaEventDestroy,cudaEventElapsedTime,cudaStreamWaitEvent,cudaEventRecordWithFlags,cuEventRecord

__host__cudaError_t cudaEventRecordWithFlags (cudaEvent_t event,cudaStream_t stream =0, unsigned int flags =0 )
Records an event.
Parameters
event
- Event to record
stream
- Stream in which to record event
flags
- Parameters for the operation(See above)
Description

Captures inevent the contents ofstream at the time of this call.event andstream must be on the same CUDA context. Calls such ascudaEventQuery() orcudaStreamWaitEvent() will then examine or wait for completion of the work that was captured. Uses ofstream after this call do not modifyevent. See note on default stream behavior for what is captured in the default case.

cudaEventRecordWithFlags() can be called multiple times on the same event and will overwrite the previously captured state. Other APIs such ascudaStreamWaitEvent() use the most recently captured state at the time of the API call, and are not affected by later calls tocudaEventRecordWithFlags(). Before the first call tocudaEventRecordWithFlags(), an event represents an empty set of work, so for examplecudaEventQuery() would returncudaSuccess.

flags include:

Note:

See also:

cudaEventCreate ( C API),cudaEventCreateWithFlags,cudaEventQuery,cudaEventSynchronize,cudaEventDestroy,cudaEventElapsedTime,cudaStreamWaitEvent,cudaEventRecord,cuEventRecord,

__host__cudaError_t cudaEventSynchronize (cudaEvent_t event )
Waits for an event to complete.
Parameters
event
- Event to wait for
Description

Waits until the completion of all work currently captured inevent. SeecudaEventRecord() for details on what is captured by an event.

Waiting for an event that was created with thecudaEventBlockingSync flag will cause the calling CPU thread to block until the event has been completed by the device. If thecudaEventBlockingSync flag has not been set, then the CPU thread will busy-wait until the event has been completed by the device.

Note:

See also:

cudaEventCreate ( C API),cudaEventCreateWithFlags,cudaEventRecord,cudaEventQuery,cudaEventDestroy,cudaEventElapsedTime,cuEventSynchronize



[8]ページ先頭

©2009-2025 Movatter.jp