Src/GPUPerfAPIHSA/GPUPerfAPIHSA.cpp
// Extract hardware info from GPA_HSA_Context which is passed in as context.
Extract hardware info from GPA_HSA_Context which is passed in as context.
Extract hardware info from GPA_HSA_Context which is passed in as context .
GPA_Status GPA_IMP_GetHWInfo(void* pContext, GPA_HWInfo* pHwInfo)
{
    if (nullptr == pContext)
    {
        GPA_LogError("Parameter 'pContext' is NULL.");
        return GPA_STATUS_ERROR_NULL_POINTER;
    }
    if (nullptr == pHwInfo)
    {
        GPA_LogError("Parameter 'pHwInfo' is NULL.");
        return GPA_STATUS_ERROR_NULL_POINTER;
    }
    GPA_HSA_Context* pHSAContext = nullptr;
    GPA_HSA_Context localHSAContext;
    if (HSAGlobalFlags::Instance()->m_wasInitializeCalled)
    {
        pHSAContext = &localHSAContext;
        hsa_queue_t* pQueue = static_cast<hsa_queue_t*>(pContext);
        pHSAContext->m_pQueue = pQueue;
        pHSAContext->m_pAgent = &HSAGlobalFlags::Instance()->m_queueAgentMap[pQueue];
    }
    else
    {
        pHSAContext = static_cast<GPA_HSA_Context*>(pContext);
    }
    if (nullptr == pHSAContext->m_pAgent)
    {
        GPA_LogError("Invalid context.");
        return GPA_STATUS_ERROR_NULL_POINTER;
    }
    HSAModule* pHsaModule = HSARTModuleLoader::Instance()->GetAPIRTModule();
    if (nullptr == pHsaModule || !pHsaModule->IsModuleLoaded())
    {
        GPA_LogError("HSA runtime module is NULL.");
        return GPA_STATUS_ERROR_FAILED;
    }
    const hsa_agent_t device = *pHSAContext->m_pAgent;
    hsa_device_type_t deviceType;
    hsa_status_t status = pHsaModule->agent_get_info(device, HSA_AGENT_INFO_DEVICE, &deviceType);
    if (HSA_STATUS_SUCCESS != status || HSA_DEVICE_TYPE_GPU != deviceType)
    {
        GPA_LogError("The device is not a GPU device.");
        return GPA_STATUS_ERROR_HARDWARE_NOT_SUPPORTED;
    }
    pHwInfo->SetVendorID(AMD_VENDOR_ID);
    uint32_t deviceId;
    status = pHsaModule->agent_get_info(device, static_cast<hsa_agent_info_t>(HSA_AMD_AGENT_INFO_CHIP_ID), &deviceId);
    if (HSA_STATUS_SUCCESS != status)
    {
        GPA_LogError("Unable to get device id.");
        return GPA_STATUS_ERROR_HARDWARE_NOT_SUPPORTED;
    }
    char deviceName[64];
    status = pHsaModule->agent_get_info(device, HSA_AGENT_INFO_NAME, &deviceName);
    if (HSA_STATUS_SUCCESS != status)
    {
        GPA_LogError("Unable to get device name.");
        return GPA_STATUS_ERROR_HARDWARE_NOT_SUPPORTED;
    }
    GDT_GfxCardInfo cardInfo;
    bool bSupported = false;
    if (AMDTDeviceInfoUtils::Instance()->GetDeviceInfo(deviceId, REVISION_ID_ANY, cardInfo))
    {
        if (static_cast<unsigned int>(cardInfo.m_generation) >= static_cast<unsigned int>(GDT_HW_GENERATION_SEAISLAND))
        {
            pHwInfo->SetDeviceName(cardInfo.m_szCALName);
            pHwInfo->SetDeviceID(static_cast<gpa_uint32>(cardInfo.m_deviceID));
            pHwInfo->SetRevisionID(static_cast<gpa_uint32>(cardInfo.m_revID));
            bSupported = true;
            std::stringstream message;
            message << "Vendor ID: 0x" << hex << AMD_VENDOR_ID << ", ";
            message << "Device ID: 0x" << hex << cardInfo.m_deviceID << ", ";
            message << "Rev ID: 0x" << hex << cardInfo.m_revID << ", ";
            message << "Device Name: " << cardInfo.m_szCALName << ", ";
            message << "HSA RT Device Name: " << deviceName << ".";
            GPA_LogDebugMessage(message.str().c_str());
        }
    }
    if (!bSupported)
    {
        GPA_LogError("Unsupported device.");
        return GPA_STATUS_ERROR_HARDWARE_NOT_SUPPORTED;
    }
    return GPA_STATUS_OK;
}
GPA_Status GPA_IMP_GetHWInfo ( void * pContext , GPA_HWInfo * pHwInfo ) { if ( nullptr == pContext ) { GPA_LogError ( " " ) ; return GPA_STATUS_ERROR_NULL_POINTER ; } if ( nullptr == pHwInfo ) { GPA_LogError ( " " ) ; return GPA_STATUS_ERROR_NULL_POINTER ; } GPA_HSA_Context * pHSAContext = nullptr ; GPA_HSA_Context localHSAContext ; if ( HSAGlobalFlags :: Instance ( ) -> m_wasInitializeCalled ) { pHSAContext = & localHSAContext ; hsa_queue_t * pQueue = static_cast < hsa_queue_t * > ( pContext ) ; pHSAContext -> m_pQueue = pQueue ; pHSAContext -> m_pAgent = & HSAGlobalFlags :: Instance ( ) -> m_queueAgentMap [ pQueue ] ; } else { pHSAContext = static_cast < GPA_HSA_Context * > ( pContext ) ; } if ( nullptr == pHSAContext -> m_pAgent ) { GPA_LogError ( " " ) ; return GPA_STATUS_ERROR_NULL_POINTER ; } HSAModule * pHsaModule = HSARTModuleLoader :: Instance ( ) -> GetAPIRTModule ( ) ; if ( nullptr == pHsaModule || ! pHsaModule -> IsModuleLoaded ( ) ) { GPA_LogError ( " " ) ; return GPA_STATUS_ERROR_FAILED ; } const hsa_agent_t device = * pHSAContext -> m_pAgent ; hsa_device_type_t deviceType ; hsa_status_t status = pHsaModule -> agent_get_info ( device , HSA_AGENT_INFO_DEVICE , & deviceType ) ; if ( HSA_STATUS_SUCCESS != status || HSA_DEVICE_TYPE_GPU != deviceType ) { GPA_LogError ( " " ) ; return GPA_STATUS_ERROR_HARDWARE_NOT_SUPPORTED ; } pHwInfo -> SetVendorID ( AMD_VENDOR_ID ) ; uint32_t deviceId ; status = pHsaModule -> agent_get_info ( device , static_cast < hsa_agent_info_t > ( HSA_AMD_AGENT_INFO_CHIP_ID ) , & deviceId ) ; if ( HSA_STATUS_SUCCESS != status ) { GPA_LogError ( " " ) ; return GPA_STATUS_ERROR_HARDWARE_NOT_SUPPORTED ; } char deviceName [ 64 ] ; status = pHsaModule -> agent_get_info ( device , HSA_AGENT_INFO_NAME , & deviceName ) ; if ( HSA_STATUS_SUCCESS != status ) { GPA_LogError ( " " ) ; return GPA_STATUS_ERROR_HARDWARE_NOT_SUPPORTED ; } GDT_GfxCardInfo cardInfo ; bool bSupported = false ; if ( AMDTDeviceInfoUtils :: Instance ( ) -> GetDeviceInfo ( deviceId , REVISION_ID_ANY , cardInfo ) ) { if ( static_cast < unsigned int > ( cardInfo . m_generation ) >= static_cast < unsigned int > ( GDT_HW_GENERATION_SEAISLAND ) ) { pHwInfo -> SetDeviceName ( cardInfo . m_szCALName ) ; pHwInfo -> SetDeviceID ( static_cast < gpa_uint32 > ( cardInfo . m_deviceID ) ) ; pHwInfo -> SetRevisionID ( static_cast < gpa_uint32 > ( cardInfo . m_revID ) ) ; bSupported = true ; std :: stringstream message ; message << " " << hex << AMD_VENDOR_ID << " " ; message << " " << hex << cardInfo . m_deviceID << " " ; message << " " << hex << cardInfo . m_revID << " " ; message << " " << cardInfo . m_szCALName << " " ; message << " " << deviceName << " " ; GPA_LogDebugMessage ( message . str ( ) . c_str ( ) ) ; } } if ( ! bSupported ) { GPA_LogError ( " " ) ; return GPA_STATUS_ERROR_HARDWARE_NOT_SUPPORTED ; } return GPA_STATUS_OK ; }
Extract hardware info from GPA_HSA_Context which is passed in as context.
Extract hardware info from GPA_HSA_Context which is passed in as context .
//---------------------------------------------------- // Check device type // Set up device ID // Get device name // TODO: requested that the HSA runtime allows us to get revID -- for now hardcode to zero