Context management#

enum rocprofiler_synchronize_context_flags_t#

Flags controlling the behavior of context synchronization.

Values:

enumerator ROCPROFILER_SYNCHRONIZE_CONTEXT_NONE#
enumerator ROCPROFILER_SYNCHRONIZE_CONTEXT_NOHANG#

report what is outstanding without waiting for it

enumerator ROCPROFILER_SYNCHRONIZE_CONTEXT_NOFLUSH#

donotflushbuffer(s)associatedwithcontext

enumerator ROCPROFILER_SYNCHRONIZE_CONTEXT_LAST#
rocprofiler_status_t rocprofiler_create_context(rocprofiler_context_id_t *context_id)#

Create context.

Parameters:

context_id – [out] Context identifier

Returns:

rocprofiler_status_t

rocprofiler_status_t rocprofiler_start_context(rocprofiler_context_id_t context_id)#

Start context.

Parameters:

context_id – [in] Identifier for context to be activated

Returns:

rocprofiler_status_t

rocprofiler_status_t rocprofiler_stop_context(rocprofiler_context_id_t context_id)#

Stop context.

Parameters:

context_id – [in] Identifier for context to be deactivated

Returns:

rocprofiler_status_t

rocprofiler_status_t rocprofiler_context_is_active(rocprofiler_context_id_t context_id, int *status)#

Query whether context is currently active.

Parameters:
  • context_id – [in] Context identifier for the query

  • status – [out] If context is active, this will be a nonzero value

Return values:
  • ROCPROFILER_STATUS_SUCCESS – The input context id identified a registered context

  • ROCPROFILER_STATUS_ERROR_CONTEXT_NOT_FOUND – The input context id did not identify a registered context

Returns:

rocprofiler_status_t

rocprofiler_status_t rocprofiler_context_is_valid(rocprofiler_context_id_t context_id, int *status)#

Query whether the context is valid.

Parameters:
  • context_id – [in] Context identifier for the query

  • status – [out] If context is invalid, this will be a nonzero value

Returns:

rocprofiler_status_t

rocprofiler_status_t rocprofiler_synchronize_context(rocprofiler_context_id_t context, const rocprofiler_synchronize_context_options_t *options, rocprofiler_synchronize_context_result_t *result)#

(experimental) Wait until records have been written for already-submitted GPU operations.

Records for asynchronous operations are written on runtime-owned threads after the operation retires, so a flush issued straight after a device synchronize can return nothing for work that has finished. This waits for them to be written and subsequently performs a flush to make all records visible.

Covers kernel dispatch, memory copy, HIP event tracing, dispatch and device counter collection, signal-less dispatch, and services extracted inline at dispatch completion; PC sampling agent buffers are flushed for the clients owning context. Records written by the calling thread, such as API tracing, never need it. Free-running sources are not covered.

ROCPROFILER_SYNCHRONIZE_CONTEXT_NOHANG skips the wait but not the flush, so combining it with ROCPROFILER_SYNCHRONIZE_CONTEXT_NOFLUSH is the only way to poll without side effects.

The wait spans record production process-wide, since the threads producing records are not partitioned by context; only the flush is scoped to context, which is flushed buffer by buffer. The flush runs even when the wait timed out, so the records that did land are still delivered and the status reports the shortfall.

Warning

Expensive, and it slows tracing while it runs: it blocks until record production catches up and stalls queue creation and destruction. Call it once before reading a buffer, never per dispatch or on a hot path. Calling it from a buffer or record callback deadlocks: those run on the threads it waits for.

Parameters:
  • context – [in] Context whose records the caller needs written; must be owned by the caller

  • options – [in] Options controlling the behavior of synchronization. May be NULL, which selects no flags and leaves each wait to its own internal budget.

  • result – [out] Filled with the outcome of the synchronization attempt. May be NULL unless ROCPROFILER_SYNCHRONIZE_CONTEXT_NOHANG is set. Its counts are zeroed before any work is done, so they are readable on every status except ROCPROFILER_STATUS_ERROR_CONTEXT_NOT_FOUND and ROCPROFILER_STATUS_ERROR_INCOMPATIBLE_ABI, which both return before touching it.

Return values:
  • ROCPROFILER_STATUS_SUCCESS – Record writing is caught up for the covered kinds, or nothing was waited for because ROCPROFILER_SYNCHRONIZE_CONTEXT_NOHANG was set or finalization had already run these drains

  • ROCPROFILER_STATUS_ERROR_CONTEXT_NOT_FOUND – context does not exist

  • ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT – result is NULL while ROCPROFILER_SYNCHRONIZE_CONTEXT_NOHANG is set, which would leave nothing to return

  • ROCPROFILER_STATUS_ERROR_INCOMPATIBLE_ABI – The size of options or result does not equal the size of that struct in this build of rocprofiler-sdk, so its layout cannot be read or written safely

  • ROCPROFILER_STATUS_ERROR_TIMEOUT – The operation timed out before all records were written. Nothing was discarded, result reports the estimated shortfall, and the call may be retried.

  • * – Any status from rocprofiler_flush_buffer, if a buffer failed to flush and the synchronization itself succeeded

Returns:

rocprofiler_status_t

ROCPROFILER_CONTEXT_NONE#

The NULL Context handle.

struct rocprofiler_synchronize_context_options_t#
#include <rocprofiler-sdk/experimental/synchronize_contexts.h>

Options set by the user.

struct rocprofiler_synchronize_context_result_t#
#include <rocprofiler-sdk/experimental/synchronize_contexts.h>

Result returned by the runtime after attempting to synchronize a context.