Added support for Primary Context Management APIs

Change-Id: I70f91b4492e112dd8e12ecf511fdc18a27944a06


[ROCm/clr commit: 33a8cdc6d3]
This commit is contained in:
Rahul Garg
2017-03-26 23:45:54 +05:30
szülő a9a6b5e8a6
commit 8a5d4a6ab8
3 fájl változott, egészen pontosan 161 új sor hozzáadva és 0 régi sor törölve
@@ -1696,6 +1696,66 @@ hipError_t hipCtxEnablePeerAccess (hipCtx_t peerCtx, unsigned int flags);
*/
hipError_t hipCtxDisablePeerAccess (hipCtx_t peerCtx);
/**
* @brief Get the state of the primary context.
*
* @param [in] Device to get primary context flags for
* @param [out] Pointer to store flags
* @param [out] Pointer to store context state; 0 = inactive, 1 = active
*
* @returns #hipSuccess
*
* @see hipCtxCreate, hipCtxDestroy, hipCtxGetFlags, hipCtxPopCurrent, hipCtxGetCurrent, hipCtxSetCurrent, hipCtxPushCurrent, hipCtxSetCacheConfig, hipCtxSynchronize, hipCtxGetDevice
*/
hipError_t hipDevicePrimaryCtxGetState ( hipDevice_t dev, unsigned int* flags, int* active );
/**
* @brief Release the primary context on the GPU.
*
* @param [in] Device which primary context is released
*
* @returns #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.
*/
hipError_t hipDevicePrimaryCtxRelease ( hipDevice_t dev);
/**
* @brief Retain the primary context on the GPU.
*
* @param [out] Returned context handle of the new context
* @param [in] Device which primary context is released
*
* @returns #hipSuccess
*
* @see hipCtxCreate, hipCtxDestroy, hipCtxGetFlags, hipCtxPopCurrent, hipCtxGetCurrent, hipCtxSetCurrent, hipCtxPushCurrent, hipCtxSetCacheConfig, hipCtxSynchronize, hipCtxGetDevice
*/
hipError_t hipDevicePrimaryCtxRetain ( hipCtx_t* pctx, hipDevice_t dev );
/**
* @brief Resets the primary context on the GPU.
*
* @param [in] Device which primary context is reset
*
* @returns #hipSuccess
*
* @see hipCtxCreate, hipCtxDestroy, hipCtxGetFlags, hipCtxPopCurrent, hipCtxGetCurrent, hipCtxSetCurrent, hipCtxPushCurrent, hipCtxSetCacheConfig, hipCtxSynchronize, hipCtxGetDevice
*/
hipError_t hipDevicePrimaryCtxReset ( hipDevice_t dev );
/**
* @brief Set flags for the primary context.
*
* @param [in] Device for which the primary context flags are set
* @param [in] New flags for the device
*
* @returns #hipSuccess, #hipErrorContextAlreadyInUse
*
* @see hipCtxCreate, hipCtxDestroy, hipCtxGetFlags, hipCtxPopCurrent, hipCtxGetCurrent, hipCtxSetCurrent, hipCtxPushCurrent, hipCtxSetCacheConfig, hipCtxSynchronize, hipCtxGetDevice
*/
hipError_t hipDevicePrimaryCtxSetFlags ( hipDevice_t dev, unsigned int flags );
// doxygen end Context Management
/**
* @}
@@ -670,6 +670,31 @@ inline static hipError_t hipCtxEnablePeerAccess ( hipCtx_t peerCtx, unsigned in
return hipCUResultTohipError(cuCtxEnablePeerAccess(peerCtx, flags));
}
inline static hipError_t hipDevicePrimaryCtxGetState ( hipDevice_t dev, unsigned int* flags, int* active )
{
return hipCUResultTohipError(cuDevicePrimaryCtxGetState(dev, flags, active));
}
inline static hipError_t hipDevicePrimaryCtxRelease ( hipDevice_t dev)
{
return hipCUResultTohipError(cuDevicePrimaryCtxRelease(dev));
}
inline static hipError_t hipDevicePrimaryCtxRetain ( hipCtx_t* pctx, hipDevice_t dev )
{
return hipCUResultTohipError(cuDevicePrimaryCtxRetain(pctx, dev));
}
inline static hipError_t hipDevicePrimaryCtxReset ( hipDevice_t dev )
{
return hipCUResultTohipError(cuDevicePrimaryCtxReset(dev));
}
inline static hipError_t hipDevicePrimaryCtxSetFlags ( hipDevice_t dev, unsigned int flags )
{
return hipCUResultTohipError(cuDevicePrimaryCtxSetFlags(dev, flags));
}
inline static hipError_t hipMemGetAddressRange ( hipDeviceptr_t* pbase, size_t* psize, hipDeviceptr_t dptr )
{
return hipCUResultTohipError(cuMemGetAddressRange( pbase , psize , dptr));
@@ -283,3 +283,79 @@ hipError_t hipCtxGetFlags ( unsigned int* flags )
*flags = tempCtx->_ctxFlags;
return ihipLogStatus(e);
}
hipError_t hipDevicePrimaryCtxGetState ( hipDevice_t dev, unsigned int* flags, int* active )
{
HIP_INIT_API(dev, flags, active);
hipError_t e = hipSuccess;
auto deviceHandle = ihipGetDevice(dev);
if (deviceHandle == NULL) {
e = hipErrorInvalidDevice;
}
ihipCtx_t* tempCtx;
tempCtx = ihipGetTlsDefaultCtx();
ihipCtx_t* primaryCtx = deviceHandle->_primaryCtx;
if(tempCtx == primaryCtx) {
*active = 1;
*flags = tempCtx->_ctxFlags;
} else {
*active = 0;
*flags = primaryCtx->_ctxFlags;
}
return ihipLogStatus(e);
}
hipError_t hipDevicePrimaryCtxRelease ( hipDevice_t dev)
{
HIP_INIT_API(dev);
hipError_t e = hipSuccess;
auto deviceHandle = ihipGetDevice(dev);
if (deviceHandle == NULL) {
e = hipErrorInvalidDevice;
}
return ihipLogStatus(e);
}
hipError_t hipDevicePrimaryCtxRetain ( hipCtx_t* pctx, hipDevice_t dev )
{
HIP_INIT_API(pctx, dev);
hipError_t e = hipSuccess;
auto deviceHandle = ihipGetDevice(dev);
if (deviceHandle == NULL) {
e = hipErrorInvalidDevice;
}
*pctx = deviceHandle->_primaryCtx;
return ihipLogStatus(e);
}
hipError_t hipDevicePrimaryCtxReset ( hipDevice_t dev )
{
HIP_INIT_API(dev);
hipError_t e = hipSuccess;
auto deviceHandle = ihipGetDevice(dev);
if (deviceHandle == NULL) {
e = hipErrorInvalidDevice;
}
ihipCtx_t* primaryCtx = deviceHandle->_primaryCtx;
primaryCtx->locked_reset();
return ihipLogStatus(e);
}
hipError_t hipDevicePrimaryCtxSetFlags ( hipDevice_t dev, unsigned int flags )
{
HIP_INIT_API(dev, flags);
hipError_t e = hipSuccess;
auto deviceHandle = ihipGetDevice(dev);
if (deviceHandle == NULL) {
e = hipErrorInvalidDevice;
} else {
e = hipErrorContextAlreadyInUse;
}
return ihipLogStatus(e);
}