Context Management

hipCtxCreate

hipError_t hipCtxCreate(hipCtx_t *ctx, unsigned int flags, hipDevice_t device)

Create a context and set it as current/ default context.

Return

#hipSuccess

See

hipCtxDestroy, hipCtxGetFlags, hipCtxPopCurrent, hipCtxGetCurrent, hipCtxPushCurrent, hipCtxSetCacheConfig, hipCtxSynchronize, hipCtxGetDevice

Parameters
  • [out] ctx:

  • [in] flags:

  • [in] associated: device handle

hipCtxDestroy

hipError_t hipCtxDestroy(hipCtx_t ctx)

Destroy a HIP context.

Return

#hipSuccess, #hipErrorInvalidValue

See

hipCtxCreate, hipCtxGetFlags, hipCtxPopCurrent, hipCtxGetCurrent,hipCtxSetCurrent, hipCtxPushCurrent, hipCtxSetCacheConfig, hipCtxSynchronize , hipCtxGetDevice

Parameters
  • [in] ctx: Context to destroy

hipDevicePrimaryCtxGetState

hipError_t hipDevicePrimaryCtxGetState(hipDevice_t dev, unsigned int *flags, int *active)

Get the state of the primary context.

Return

#hipSuccess

See

hipCtxCreate, hipCtxDestroy, hipCtxGetFlags, hipCtxPopCurrent, hipCtxGetCurrent, hipCtxSetCurrent, hipCtxPushCurrent, hipCtxSetCacheConfig, hipCtxSynchronize, hipCtxGetDevice

Parameters
  • [in] Device: to get primary context flags for

  • [out] Pointer: to store flags

  • [out] Pointer: to store context state; 0 = inactive, 1 = active

hipDevicePrimaryCtxRelease

hipError_t hipDevicePrimaryCtxRelease(hipDevice_t dev)

Release the primary context on the GPU.

Return

#hipSuccess

See

hipCtxCreate, hipCtxDestroy, hipCtxGetFlags, hipCtxPopCurrent, hipCtxGetCurrent, hipCtxSetCurrent, hipCtxPushCurrent, hipCtxSetCacheConfig, hipCtxSynchronize, hipCtxGetDevice

Warning

This function return #hipSuccess though doesn’t release the primaryCtx by design on HIP/HCC path.

Parameters
  • [in] Device: which primary context is released

hipDevicePrimaryCtxRetain

hipError_t hipDevicePrimaryCtxRetain(hipCtx_t *pctx, hipDevice_t dev)

Retain the primary context on the GPU.

Return

#hipSuccess

See

hipCtxCreate, hipCtxDestroy, hipCtxGetFlags, hipCtxPopCurrent, hipCtxGetCurrent, hipCtxSetCurrent, hipCtxPushCurrent, hipCtxSetCacheConfig, hipCtxSynchronize, hipCtxGetDevice

Parameters
  • [out] Returned: context handle of the new context

  • [in] Device: which primary context is released

hipDevicePrimaryCtxReset

hipError_t hipDevicePrimaryCtxReset(hipDevice_t dev)

Resets the primary context on the GPU.

Return

#hipSuccess

See

hipCtxCreate, hipCtxDestroy, hipCtxGetFlags, hipCtxPopCurrent, hipCtxGetCurrent, hipCtxSetCurrent, hipCtxPushCurrent, hipCtxSetCacheConfig, hipCtxSynchronize, hipCtxGetDevice

Parameters
  • [in] Device: which primary context is reset

hipDevicePrimaryCtxSetFlags

hipError_t hipDevicePrimaryCtxSetFlags(hipDevice_t dev, unsigned int flags)

Set flags for the primary context.

Return

#hipSuccess, #hipErrorContextAlreadyInUse

See

hipCtxCreate, hipCtxDestroy, hipCtxGetFlags, hipCtxPopCurrent, hipCtxGetCurrent, hipCtxSetCurrent, hipCtxPushCurrent, hipCtxSetCacheConfig, hipCtxSynchronize, hipCtxGetDevice

Parameters
  • [in] Device: for which the primary context flags are set

  • [in] New: flags for the device